net: stmmac: Fix MAC-capabilities procedure
Subsystems (5)
cover net: stmmac: Fix MAC-capabilities procedure
The series got born as a result of the discussions around the recent Yanteng' series adding the Loongson LS7A1000, LS2K1000, LS7A2000, LS2K2000 MACs support:
In particular the Yanteng' patchset needed to implement the Loongson MAC-specific constraints applied to the link speed and link duplex mode. As a result of the discussion with Russel the next preliminary patch was born:
The patch above was a temporal solution utilized by Yanteng for further developments and to move on with the on-going review. This patchset is a refactored version of that single patch with formatting required for the fixes patches.
In particular the series starts with fixing the half-duplex-less constraint currently applied for all IP-cores. In fact it's specific for the DW QoS Eth only (DW GMAC v4.x/v5.x).
The next patch fixes the MAC-capabilities setting up during the active Tx/Rx queues re-initialization procedure. Particularly the procedure missed the max-speed limit thus possibly activating speeds prohibited on the respective platforms.
Third patch fixes the incorrect MAC-capabilities initialization for DW MAC100, DW XGMAC and DW XLGMAC devices by moving the correct initialization to the IP-core specific setup() methods.
Final patch is just a cleanup moving the MAC-capabilities init/re-init to the phylink MAC-capabilities getter.
That's it for now. Thanks for review and testing in advance.
Serge Semin (4):
net: stmmac: Apply half-duplex-less constraint for DW QoS Eth only
net: stmmac: Fix max-speed being ignored on queue re-init
net: stmmac: Fix IP-cores specific MAC capabilities
net: stmmac: Move MAC caps init to phylink MAC caps getter
drivers/net/ethernet/stmicro/stmmac/common.h | 1 + .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 2 + .../ethernet/stmicro/stmmac/dwmac1000_core.c | 2 + .../ethernet/stmicro/stmmac/dwmac100_core.c | 2 + .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 7 ++- .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 18 ++++---- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 43 ++++++++----------- 7 files changed, 38 insertions(+), 37 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 net: stmmac: Apply half-duplex-less constraint for DW QoS Eth only
There are three DW MAC IP-cores which can have the multiple Tx/Rx queues enabled:
DW GMAC v3.7+ with AV feature,
DW QoS Eth v4.x/v5.x,
DW XGMAC/XLGMAC
Based on the respective HW databooks, only the DW QoS Eth IP-core doesn't support the half-duplex link mode in case if more than one queues enabled:
"In multiple queue/channel configurations, for half-duplex operation, enable only the Q0/CH0 on Tx and Rx. For single queue/channel in full-duplex operation, any queue/channel can be enabled."
The rest of the IP-cores don't have such constraint. Thus in order to have the constraint applied for the DW QoS Eth MACs only, let's move the it' implementation to the respective MAC-capabilities getter and make sure the getter is called in the queues re-init procedure.
--- .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 7 +++++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 19 +++---------------- 2 files changed, 10 insertions(+), 16 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +7 -0
@@ -71,6 +71,13 @@ static void dwmac4_core_init(struct mac_device_info *hw,static void dwmac4_phylink_get_caps (struct stmmac_priv *priv) { priv->phylink_config.mac_capabilities |=MAC_2500FD ; + +if (priv->plat->tx_queues_to_use >1 ) + priv->phylink_config.mac_capabilities &= + ~(MAC_10HD |MAC_100HD |MAC_1000HD ); +else + priv->phylink_config.mac_capabilities |= + (MAC_10HD |MAC_100HD |MAC_1000HD ); } static void dwmac4_rx_queue_enable(struct mac_device_info *hw,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -16
@@ -1198,17 +1198,6 @@ static int stmmac_init_phy(struct net_device *dev)return ret; } -static void stmmac_set_half_duplex (struct stmmac_priv *priv) -{ -/* Half-Duplex can only work with single tx queue */ -if (priv->plat->tx_queues_to_use >1 ) - priv->phylink_config.mac_capabilities &= - ~(MAC_10HD |MAC_100HD |MAC_1000HD ); -else - priv->phylink_config.mac_capabilities |= - (MAC_10HD |MAC_100HD |MAC_1000HD ); -} -static int stmmac_phy_setup (struct stmmac_priv *priv) {struct stmmac_mdio_bus_data *mdio_bus_data;
@@ -1237,10 +1226,7 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) priv->phylink_config.supported_interfaces); priv->phylink_config.mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | -MAC_10FD |MAC_100FD | -MAC_1000FD ; - -stmmac_set_half_duplex (priv); +MAC_10 |MAC_100 |MAC_1000 ;/* Get the MAC specific capabilities */ stmmac_mac_phylink_get_caps (priv);
@@ -7355,7 +7341,8 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt) priv->rss.table[i] =ethtool_rxfh_indir_default (i, rx_cnt); -stmmac_set_half_duplex (priv); +stmmac_mac_phylink_get_caps (priv); +stmmac_napi_add (dev);if (netif_running (dev))
Signature · 1 line
2.43.0
Re: [PATCH net 1/4] net: stmmac: Apply half-duplex-less constraint for DW QoS Eth only
Quoted 95 lines · Serge Semin
There are three DW MAC IP-cores which can have the multiple Tx/Rx queues enabled:
DW GMAC v3.7+ with AV feature,
DW QoS Eth v4.x/v5.x,
DW XGMAC/XLGMAC
Based on the respective HW databooks, only the DW QoS Eth IP-core doesn't support the half-duplex link mode in case if more than one queues enabled:"In multiple queue/channel configurations, for half-duplex operation, enable only the Q0/CH0 on Tx and Rx. For single queue/channel in full-duplex operation, any queue/channel can be enabled."
The rest of the IP-cores don't have such constraint. Thus in order to have the constraint applied for the DW QoS Eth MACs only, let's move the it' implementation to the respective MAC-capabilities getter and make sure the getter is called in the queues re-init procedure.
Fixes b6cfffa7ad92 ("stmmac: fix DMA channel hang in half-duplex mode")Signed-off-by Serge Semin <[email protected]>--- .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 7 +++++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 19 +++---------------- 2 files changed, 10 insertions(+), 16 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +7
-0@@ -71,6 +71,13 @@ static void dwmac4_core_init(struct mac_device_info *hw,static void dwmac4_phylink_get_caps (struct stmmac_priv *priv) { priv->phylink_config.mac_capabilities |=MAC_2500FD ; + +if (priv->plat->tx_queues_to_use >1 ) + priv->phylink_config.mac_capabilities &= + ~(MAC_10HD |MAC_100HD |MAC_1000HD ); +else + priv->phylink_config.mac_capabilities |= + (MAC_10HD |MAC_100HD |MAC_1000HD ); } static void dwmac4_rx_queue_enable(struct mac_device_info *hw,drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3
-16@@ -1198,17 +1198,6 @@ static int stmmac_init_phy(struct net_device *dev)return ret; } -static void stmmac_set_half_duplex (struct stmmac_priv *priv) -{ -/* Half-Duplex can only work with single tx queue */ -if (priv->plat->tx_queues_to_use >1 ) - priv->phylink_config.mac_capabilities &= - ~(MAC_10HD |MAC_100HD |MAC_1000HD ); -else - priv->phylink_config.mac_capabilities |= - (MAC_10HD |MAC_100HD |MAC_1000HD ); -} -static int stmmac_phy_setup (struct stmmac_priv *priv) {struct stmmac_mdio_bus_data *mdio_bus_data;@@ -1237,10 +1226,7 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) priv->phylink_config.supported_interfaces); priv->phylink_config.mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | -MAC_10FD |MAC_100FD | -MAC_1000FD ; - -stmmac_set_half_duplex (priv); +MAC_10 |MAC_100 |MAC_1000 ;/* Get the MAC specific capabilities */ stmmac_mac_phylink_get_caps (priv);@@ -7355,7 +7341,8 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt) priv->rss.table[i] =ethtool_rxfh_indir_default (i, rx_cnt); -stmmac_set_half_duplex (priv); +stmmac_mac_phylink_get_caps (priv); +stmmac_napi_add (dev);if (netif_running (dev))Signature · 7 lines
2.43.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Thanks,
Signature · 3 lines
Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 2/4 net: stmmac: Fix max-speed being ignored on queue re-init
In reply to Serge SeminIt's possible to have the maximum link speed being artificially limited on the platform-specific basis. It's done either by setting up the plat_stmmacenet_data::max_speed field or by specifying the "max-speed" DT-property. In such cases it's required that any specific MAC-capabilities re-initializations would take the limit into account. In particular the link speed capabilities may change during the number of active Tx/Rx queues re-initialization. But the currently implemented procedure doesn't take the speed limit into account.
Fix that by calling phylink_limit_mac_speed() in the stmmac_reinit_queues() method if the speed limitation was required in the same way as it's done in the stmmac_phy_setup() function.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5 -0
@@ -7328,6 +7328,7 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt) {struct stmmac_priv *priv =netdev_priv (dev);int ret =0 , i; +int max_speed;if (netif_running (dev))stmmac_release (dev);
@@ -7343,6 +7344,10 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)stmmac_mac_phylink_get_caps (priv); + max_speed = priv->plat->max_speed; +if (max_speed) +phylink_limit_mac_speed (&priv->phylink_config, max_speed); +stmmac_napi_add (dev);if (netif_running (dev))
Signature · 1 line
2.43.0
Re: [PATCH net 2/4] net: stmmac: Fix max-speed being ignored on queue re-init
Quoted 51 lines · Serge Semin
It's possible to have the maximum link speed being artificially limited on the platform-specific basis. It's done either by setting up the
plat_stmmacenet_data::max_speedfield or by specifying the "max-speed" DT-property. In such cases it's required that any specific MAC-capabilities re-initializations would take the limit into account. In particular the link speed capabilities may change during the number of active Tx/Rx queues re-initialization. But the currently implemented procedure doesn't take the speed limit into account.Fix that by calling
phylink_limit_mac_speed()in thestmmac_reinit_queues()method if the speed limitation was required in the same way as it's done in thestmmac_phy_setup()function.Fixes 95201f36f395 ("net: stmmac: update MAC capabilities when tx queues are updated")Signed-off-by Serge Semin <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +5
-0@@ -7328,6 +7328,7 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt) {struct stmmac_priv *priv =netdev_priv (dev);int ret =0 , i; +int max_speed;if (netif_running (dev))stmmac_release (dev);@@ -7343,6 +7344,10 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)stmmac_mac_phylink_get_caps (priv); + max_speed = priv->plat->max_speed; +if (max_speed) +phylink_limit_mac_speed (&priv->phylink_config, max_speed); +stmmac_napi_add (dev);if (netif_running (dev))Signature · 7 lines
2.43.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 3/4 net: stmmac: Fix IP-cores specific MAC capabilities
In reply to Serge SeminHere is the list of the MAC capabilities specific to the particular DW MAC IP-cores currently supported by the driver:
DW MAC100: MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_10 | MAC_100
DW GMAC: MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_10 | MAC_100 | MAC_1000
Allwinner sun8i MAC: MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_10 | MAC_100 | MAC_1000
DW QoS Eth: MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD
if there is more than 1 active Tx/Rx queues:
MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_10FD | MAC_100FD | MAC_1000FD | MAC_2500FDDW XGMAC: MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_1000FD | MAC_2500FD | MAC_5000FD | MAC_10000FD
DW XLGMAC: MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
MAC_1000FD | MAC_2500FD | MAC_5000FD | MAC_10000FD |
MAC_25000FD | MAC_40000FD | MAC_50000FD | MAC_100000FDAs you can see there are only two common capabilities:MAC_ASYM_PAUSE | MAC_SYM_PAUSE.
Meanwhile what is currently implemented defines 10/100/1000 link speeds for all IP-cores, which is definitely incorrect for DW MAC100, DW XGMAC and DW XLGMAC devices.
Seeing the flow-control is implemented as a callback for each MAC IP-core (see dwmac100_flow_ctrl(), dwmac1000_flow_ctrl(), sun8i_dwmac_flow_ctrl(), etc) and since the MAC-specific setup() method is supposed to be called for each available DW MAC-based device, the capabilities initialization can be freely moved to these setup() functions, thus correctly setting up the MAC-capabilities for each IP-core (including the Allwinner Sun8i). A new stmmac_link::caps field was specifically introduced for that so to have all link-specific info preserved in a single structure.
Note the suggested change fixes three earlier commits at a time. The commit 5b0d7d7da64b ("net: stmmac: Add the missing speeds that XGMAC supports") permitted the 10-100 link speeds and 1G half-duplex mode for DW XGMAC IP-core even though it doesn't support them. The commit df7699c70c1b ("net: stmmac: Do not cut down 1G modes") incorrectly added the MAC1000 capability to the DW MAC100 IP-core. Similarly to the DW XGMAC the commit 8a880936e902 ("net: stmmac: Add XLGMII support") incorrectly permitted the 10-100 link speeds and 1G half-duplex mode for DW XLGMAC IP-core.
--- drivers/net/ethernet/stmicro/stmmac/common.h | 1 + .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 2 ++ .../ethernet/stmicro/stmmac/dwmac1000_core.c | 2 ++ .../ethernet/stmicro/stmmac/dwmac100_core.c | 2 ++ .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 10 ++++------ .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 18 ++++++++---------- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ++++--- 7 files changed, 23 insertions(+), 19 deletions(-)
drivers/net/ethernet/stmicro/stmmac/common.h +1 -0
@@ -553,6 +553,7 @@ extern const struct stmmac_hwtimestamp stmmac_ptp;extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;struct mac_link { +u32 caps;u32 speed_mask;u32 speed10;u32 speed100;
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +2 -0
@@ -1096,6 +1096,8 @@ static struct mac_device_info *sun8i_dwmac_setup(void *ppriv) priv->dev->priv_flags |=IFF_UNICAST_FLT ; + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 ;/* The loopback bit seems to be re-set when link change * Simply mask it each time * Speed 10/100/1000 are set in BIT(2)/BIT(3)
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +2 -0
@@ -539,6 +539,8 @@ int dwmac1000_setup(struct stmmac_priv *priv)if (mac->multicast_filter_bins) mac->mcast_bits_log2 =ilog2 (mac->multicast_filter_bins); + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 ; mac->link.duplex =GMAC_CONTROL_DM ; mac->link.speed10 =GMAC_CONTROL_PS ; mac->link.speed100 =GMAC_CONTROL_PS |GMAC_CONTROL_FES ;
drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c +2 -0
@@ -175,6 +175,8 @@ int dwmac100_setup(struct stmmac_priv *priv)dev_info (priv->device,"\tDWMAC100\n" ); mac->pcsr = priv->ioaddr; + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 ; mac->link.duplex =MAC_CONTROL_F ; mac->link.speed10 =0 ; mac->link.speed100 =0 ;
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +4 -6
@@ -70,14 +70,10 @@ static void dwmac4_core_init(struct mac_device_info *hw,static void dwmac4_phylink_get_caps (struct stmmac_priv *priv) { - priv->phylink_config.mac_capabilities |=MAC_2500FD ; -if (priv->plat->tx_queues_to_use >1 ) - priv->phylink_config.mac_capabilities &= - ~(MAC_10HD |MAC_100HD |MAC_1000HD ); + priv->hw->link.caps &= ~(MAC_10HD |MAC_100HD |MAC_1000HD );else - priv->phylink_config.mac_capabilities |= - (MAC_10HD |MAC_100HD |MAC_1000HD ); + priv->hw->link.caps |= (MAC_10HD |MAC_100HD |MAC_1000HD ); } static void dwmac4_rx_queue_enable(struct mac_device_info *hw,
@@ -1385,6 +1381,8 @@ int dwmac4_setup(struct stmmac_priv *priv)if (mac->multicast_filter_bins) mac->mcast_bits_log2 =ilog2 (mac->multicast_filter_bins); + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 |MAC_2500FD ; mac->link.duplex =GMAC_CONFIG_DM ; mac->link.speed10 =GMAC_CONFIG_PS ; mac->link.speed100 =GMAC_CONFIG_FES |GMAC_CONFIG_PS ;
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +8 -10
@@ -47,14 +47,6 @@ static void dwxgmac2_core_init(struct mac_device_info *hw,writel (XGMAC_INT_DEFAULT_EN , ioaddr +XGMAC_INT_EN ); } -static void xgmac_phylink_get_caps (struct stmmac_priv *priv) -{ - priv->phylink_config.mac_capabilities |=MAC_2500FD |MAC_5000FD | -MAC_10000FD |MAC_25000FD | -MAC_40000FD |MAC_50000FD | -MAC_100000FD ; -} -static void dwxgmac2_set_mac (void __iomem *ioaddr,bool enable) {u32 tx =readl (ioaddr +XGMAC_TX_CONFIG );
@@ -1540,7 +1532,6 @@ static void dwxgmac3_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *const struct stmmac_ops dwxgmac210_ops = { .core_init = dwxgmac2_core_init, - .phylink_get_caps = xgmac_phylink_get_caps, .set_mac = dwxgmac2_set_mac, .rx_ipc = dwxgmac2_rx_ipc, .rx_queue_enable = dwxgmac2_rx_queue_enable,
@@ -1601,7 +1592,6 @@ static void dwxlgmac2_rx_queue_enable(struct mac_device_info *hw, u8 mode,const struct stmmac_ops dwxlgmac2_ops = { .core_init = dwxgmac2_core_init, - .phylink_get_caps = xgmac_phylink_get_caps, .set_mac = dwxgmac2_set_mac, .rx_ipc = dwxgmac2_rx_ipc, .rx_queue_enable = dwxlgmac2_rx_queue_enable,
@@ -1661,6 +1651,9 @@ int dwxgmac2_setup(struct stmmac_priv *priv)if (mac->multicast_filter_bins) mac->mcast_bits_log2 =ilog2 (mac->multicast_filter_bins); + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_1000FD |MAC_2500FD |MAC_5000FD | +MAC_10000FD ; mac->link.duplex =0 ; mac->link.speed10 =XGMAC_CONFIG_SS_10_MII ; mac->link.speed100 =XGMAC_CONFIG_SS_100_MII ;
@@ -1698,6 +1691,11 @@ int dwxlgmac2_setup(struct stmmac_priv *priv)if (mac->multicast_filter_bins) mac->mcast_bits_log2 =ilog2 (mac->multicast_filter_bins); + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_1000FD |MAC_2500FD |MAC_5000FD | +MAC_10000FD |MAC_25000FD | +MAC_40000FD |MAC_50000FD | +MAC_100000FD ; mac->link.duplex =0 ; mac->link.speed1000 =XLGMAC_CONFIG_SS_1000 ; mac->link.speed2500 =XLGMAC_CONFIG_SS_2500 ;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -3
@@ -1225,12 +1225,11 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)xpcs_get_interfaces (priv->hw->xpcs, priv->phylink_config.supported_interfaces); - priv->phylink_config.mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | -MAC_10 |MAC_100 |MAC_1000 ; -/* Get the MAC specific capabilities */ stmmac_mac_phylink_get_caps (priv); + priv->phylink_config.mac_capabilities = priv->hw->link.caps; + max_speed = priv->plat->max_speed;if (max_speed)phylink_limit_mac_speed (&priv->phylink_config, max_speed);
@@ -7344,6 +7343,8 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)stmmac_mac_phylink_get_caps (priv); + priv->phylink_config.mac_capabilities = priv->hw->link.caps; + max_speed = priv->plat->max_speed;if (max_speed)phylink_limit_mac_speed (&priv->phylink_config, max_speed);
Signature · 1 line
2.43.0
Re: [PATCH net 3/4] net: stmmac: Fix IP-cores specific MAC capabilities
Quoted 239 lines · Serge Semin
Here is the list of the MAC capabilities specific to the particular DW MAC IP-cores currently supported by the driver:
DW MAC100:
MAC_ASYM_PAUSE|MAC_SYM_PAUSE|MAC_10 | MAC_100DW GMAC:
MAC_ASYM_PAUSE|MAC_SYM_PAUSE|MAC_10 | MAC_100 | MAC_1000Allwinner sun8i MAC:
MAC_ASYM_PAUSE|MAC_SYM_PAUSE|MAC_10 | MAC_100 | MAC_1000DW QoS Eth:
MAC_ASYM_PAUSE|MAC_SYM_PAUSE|MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD if there is more than 1 active Tx/Rx queues: MAC_ASYM_PAUSE | MAC_SYM_PAUSE | MAC_10FD | MAC_100FD | MAC_1000FD | MAC_2500FDDW XGMAC:
MAC_ASYM_PAUSE|MAC_SYM_PAUSE|MAC_1000FD | MAC_2500FD | MAC_5000FD | MAC_10000FDDW XLGMAC:
MAC_ASYM_PAUSE|MAC_SYM_PAUSE|MAC_1000FD | MAC_2500FD | MAC_5000FD | MAC_10000FD | MAC_25000FD | MAC_40000FD | MAC_50000FD | MAC_100000FDAs you can see there are only two common capabilities:
MAC_ASYM_PAUSE|MAC_SYM_PAUSE.
Meanwhile what is currently implemented defines 10/100/1000 link speeds for all IP-cores, which is definitely incorrect for DW MAC100, DW XGMAC and DW XLGMAC devices.Seeing the flow-control is implemented as a callback for each MAC IP-core (see
dwmac100_flow_ctrl(),dwmac1000_flow_ctrl(),sun8i_dwmac_flow_ctrl(), etc) and since the MAC-specificsetup()method is supposed to be called for each available DW MAC-based device, the capabilities initialization can be freely moved to thesesetup()functions, thus correctly setting up the MAC-capabilities for each IP-core (including the Allwinner Sun8i). A newstmmac_link::capsfield was specifically introduced for that so to have all link-specific info preserved in a single structure.Note the suggested change fixes three earlier commits at a time. The commit
5b0d7d7da64b("net: stmmac: Add the missing speeds that XGMAC supports") permitted the 10-100 link speeds and 1G half-duplex mode for DW XGMAC IP-core even though it doesn't support them. The commitdf7699c70c1b("net: stmmac: Do not cut down 1G modes") incorrectly added the MAC1000 capability to the DW MAC100 IP-core. Similarly to the DW XGMAC the commit8a880936e902("net: stmmac: Add XLGMII support") incorrectly permitted the 10-100 link speeds and 1G half-duplex mode for DW XLGMAC IP-core.Fixes 5b0d7d7da64b ("net: stmmac: Add the missing speeds that XGMAC supports")Fixes df7699c70c1b ("net: stmmac: Do not cut down 1G modes")Fixes 8a880936e902 ("net: stmmac: Add XLGMII support")Suggested-by Russell King (Oracle) <[email protected]>Signed-off-by Serge Semin <[email protected]>--- drivers/net/ethernet/stmicro/stmmac/common.h | 1 + .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 2 ++ .../ethernet/stmicro/stmmac/dwmac1000_core.c | 2 ++ .../ethernet/stmicro/stmmac/dwmac100_core.c | 2 ++ .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 10 ++++------ .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 18 ++++++++---------- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ++++--- 7 files changed, 23 insertions(+), 19 deletions(-)drivers/net/ethernet/stmicro/stmmac/common.h +1
-0@@ -553,6 +553,7 @@ extern const struct stmmac_hwtimestamp stmmac_ptp;extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;struct mac_link { +u32 caps;u32 speed_mask;u32 speed10;u32 speed100;drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +2
-0@@ -1096,6 +1096,8 @@ static struct mac_device_info *sun8i_dwmac_setup(void *ppriv) priv->dev->priv_flags |=IFF_UNICAST_FLT ; + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 ;/* The loopback bit seems to be re-set when link change * Simply mask it each time * Speed 10/100/1000 are set in BIT(2)/BIT(3) drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +2
-0@@ -539,6 +539,8 @@ int dwmac1000_setup(struct stmmac_priv *priv)if (mac->multicast_filter_bins) mac->mcast_bits_log2 =ilog2 (mac->multicast_filter_bins); + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 ; mac->link.duplex =GMAC_CONTROL_DM ; mac->link.speed10 =GMAC_CONTROL_PS ; mac->link.speed100 =GMAC_CONTROL_PS |GMAC_CONTROL_FES ;drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c +2
-0@@ -175,6 +175,8 @@ int dwmac100_setup(struct stmmac_priv *priv)dev_info (priv->device,"\tDWMAC100\n" ); mac->pcsr = priv->ioaddr; + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 ; mac->link.duplex =MAC_CONTROL_F ; mac->link.speed10 =0 ; mac->link.speed100 =0 ;drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +4
-6@@ -70,14 +70,10 @@ static void dwmac4_core_init(struct mac_device_info *hw,static void dwmac4_phylink_get_caps (struct stmmac_priv *priv) { - priv->phylink_config.mac_capabilities |=MAC_2500FD ; -if (priv->plat->tx_queues_to_use >1 ) - priv->phylink_config.mac_capabilities &= - ~(MAC_10HD |MAC_100HD |MAC_1000HD ); + priv->hw->link.caps &= ~(MAC_10HD |MAC_100HD |MAC_1000HD );else - priv->phylink_config.mac_capabilities |= - (MAC_10HD |MAC_100HD |MAC_1000HD ); + priv->hw->link.caps |= (MAC_10HD |MAC_100HD |MAC_1000HD ); } static void dwmac4_rx_queue_enable(struct mac_device_info *hw,@@ -1385,6 +1381,8 @@ int dwmac4_setup(struct stmmac_priv *priv)if (mac->multicast_filter_bins) mac->mcast_bits_log2 =ilog2 (mac->multicast_filter_bins); + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_10 |MAC_100 |MAC_1000 |MAC_2500FD ; mac->link.duplex =GMAC_CONFIG_DM ; mac->link.speed10 =GMAC_CONFIG_PS ; mac->link.speed100 =GMAC_CONFIG_FES |GMAC_CONFIG_PS ;drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +8
-10@@ -47,14 +47,6 @@ static void dwxgmac2_core_init(struct mac_device_info *hw,writel (XGMAC_INT_DEFAULT_EN , ioaddr +XGMAC_INT_EN ); } -static void xgmac_phylink_get_caps (struct stmmac_priv *priv) -{ - priv->phylink_config.mac_capabilities |=MAC_2500FD |MAC_5000FD | -MAC_10000FD |MAC_25000FD | -MAC_40000FD |MAC_50000FD | -MAC_100000FD ; -} -static void dwxgmac2_set_mac (void __iomem *ioaddr,bool enable) {u32 tx =readl (ioaddr +XGMAC_TX_CONFIG );@@ -1540,7 +1532,6 @@ static void dwxgmac3_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *const struct stmmac_ops dwxgmac210_ops = { .core_init = dwxgmac2_core_init, - .phylink_get_caps = xgmac_phylink_get_caps, .set_mac = dwxgmac2_set_mac, .rx_ipc = dwxgmac2_rx_ipc, .rx_queue_enable = dwxgmac2_rx_queue_enable,@@ -1601,7 +1592,6 @@ static void dwxlgmac2_rx_queue_enable(struct mac_device_info *hw, u8 mode,const struct stmmac_ops dwxlgmac2_ops = { .core_init = dwxgmac2_core_init, - .phylink_get_caps = xgmac_phylink_get_caps, .set_mac = dwxgmac2_set_mac, .rx_ipc = dwxgmac2_rx_ipc, .rx_queue_enable = dwxlgmac2_rx_queue_enable,@@ -1661,6 +1651,9 @@ int dwxgmac2_setup(struct stmmac_priv *priv)if (mac->multicast_filter_bins) mac->mcast_bits_log2 =ilog2 (mac->multicast_filter_bins); + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_1000FD |MAC_2500FD |MAC_5000FD | +MAC_10000FD ; mac->link.duplex =0 ; mac->link.speed10 =XGMAC_CONFIG_SS_10_MII ; mac->link.speed100 =XGMAC_CONFIG_SS_100_MII ;@@ -1698,6 +1691,11 @@ int dwxlgmac2_setup(struct stmmac_priv *priv)if (mac->multicast_filter_bins) mac->mcast_bits_log2 =ilog2 (mac->multicast_filter_bins); + mac->link.caps =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | +MAC_1000FD |MAC_2500FD |MAC_5000FD | +MAC_10000FD |MAC_25000FD | +MAC_40000FD |MAC_50000FD | +MAC_100000FD ; mac->link.duplex =0 ; mac->link.speed1000 =XLGMAC_CONFIG_SS_1000 ; mac->link.speed2500 =XLGMAC_CONFIG_SS_2500 ;drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4
-3@@ -1225,12 +1225,11 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)xpcs_get_interfaces (priv->hw->xpcs, priv->phylink_config.supported_interfaces); - priv->phylink_config.mac_capabilities =MAC_ASYM_PAUSE |MAC_SYM_PAUSE | -MAC_10 |MAC_100 |MAC_1000 ; -/* Get the MAC specific capabilities */ stmmac_mac_phylink_get_caps (priv); + priv->phylink_config.mac_capabilities = priv->hw->link.caps; + max_speed = priv->plat->max_speed;if (max_speed)phylink_limit_mac_speed (&priv->phylink_config, max_speed);@@ -7344,6 +7343,8 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)stmmac_mac_phylink_get_caps (priv); + priv->phylink_config.mac_capabilities = priv->hw->link.caps; + max_speed = priv->plat->max_speed;if (max_speed)phylink_limit_mac_speed (&priv->phylink_config, max_speed);Signature · 7 lines
2.43.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Thanks,
Signature · 3 lines
Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH 4/4 net: stmmac: Move MAC caps init to phylink MAC caps getter
In reply to Serge SeminAfter a set of fixes the stmmac_phy_setup() and stmmac_reinit_queues() method have turned to having some duplicated code. Let's get rid from the duplication by moving the MAC-capabilities initialization to the PHYLINK MAC-capabilities getter. The getter is called during each network device interface open/close cycle. So the MAC-capabilities will be initialized in normal device functioning and in case of the Tx/Rx queues re-initialization as the original code semantics implies.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +17 -19
@@ -936,6 +936,22 @@ static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex) priv->pause, tx_cnt); } +static unsigned long stmmac_mac_get_caps (struct phylink_config *config, +phy_interface_t interface) +{ +struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); + +/* Get the MAC-specific capabilities */ +stmmac_mac_phylink_get_caps (priv); + + config->mac_capabilities = priv->hw->link.caps; + +if (priv->plat->max_speed) +phylink_limit_mac_speed (config, priv->plat->max_speed); + +return config->mac_capabilities; +} +static struct phylink_pcs *stmmac_mac_select_pcs (struct phylink_config *config,phy_interface_t interface) {
@@ -1105,6 +1121,7 @@ static void stmmac_mac_link_up(struct phylink_config *config, }static const struct phylink_mac_ops stmmac_phylink_mac_ops = { + .mac_get_caps = stmmac_mac_get_caps, .mac_select_pcs = stmmac_mac_select_pcs, .mac_config = stmmac_mac_config, .mac_link_down = stmmac_mac_link_down,
@@ -1204,7 +1221,6 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)int mode = priv->plat->phy_interface;struct fwnode_handle *fwnode;struct phylink *phylink; -int max_speed; priv->phylink_config.dev = &priv->dev->dev; priv->phylink_config.type =PHYLINK_NETDEV ;
@@ -1225,15 +1241,6 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)xpcs_get_interfaces (priv->hw->xpcs, priv->phylink_config.supported_interfaces); -/* Get the MAC specific capabilities */ -stmmac_mac_phylink_get_caps (priv); - - priv->phylink_config.mac_capabilities = priv->hw->link.caps; - - max_speed = priv->plat->max_speed; -if (max_speed) -phylink_limit_mac_speed (&priv->phylink_config, max_speed); - fwnode = priv->plat->port_node;if (!fwnode) fwnode =dev_fwnode (priv->device);
@@ -7327,7 +7334,6 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt) {struct stmmac_priv *priv =netdev_priv (dev);int ret =0 , i; -int max_speed;if (netif_running (dev))stmmac_release (dev);
@@ -7341,14 +7347,6 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt) priv->rss.table[i] =ethtool_rxfh_indir_default (i, rx_cnt); -stmmac_mac_phylink_get_caps (priv); - - priv->phylink_config.mac_capabilities = priv->hw->link.caps; - - max_speed = priv->plat->max_speed; -if (max_speed) -phylink_limit_mac_speed (&priv->phylink_config, max_speed); -stmmac_napi_add (dev);if (netif_running (dev))
Signature · 1 line
2.43.0
Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter
Hi Serge,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex) · line 945
Quoted 7 lines · Serge Semin
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7
-0+static unsigned long stmmac_mac_get_caps (struct phylink_config *config, +phy_interface_t interface) +{ +struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); + +/* Get the MAC-specific capabilities */ +stmmac_mac_phylink_get_caps (priv);
This is a bit of a nitpick, but the terminology is quite confusing between stmmac_mac_phylink_get_caps() and stmmac_mac_get_caps(). Ideally, we could just get rid of the whole stmmac_do_void_callback() complexity and just call phylink_get_caps() directly. In the meantime, maybe renaming this to stmmac_mac_core_get_caps() would be acceptable?
Please let me know what you think.
Thanks,
Signature · 3 lines
Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter
Hi Romain
Quoted 4 lines · Romain Gantois
Hi Serge,
On Fri, 12 Apr 2024, Serge Semin wrote:
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex) · line 945
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7
-0+static unsigned long stmmac_mac_get_caps (struct phylink_config *config, +phy_interface_t interface) +{ +struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); + +/* Get the MAC-specific capabilities */ +stmmac_mac_phylink_get_caps (priv);This is a bit of a nitpick, but the terminology is quite confusing between
stmmac_mac_phylink_get_caps()andstmmac_mac_get_caps().
Right, the naming turns to be ambiguous "a bit".)
Quoted 3 lines
Ideally, we could just
get rid of the wholestmmac_do_void_callback()complexity and just callphylink_get_caps()directly.
No, this isn't a good solution. The local coding convention implies using the macro-functions implemented to execute the callbacks. We can't use the macros everywhere but in this place.
Quoted 2 lines
In the meantime, maybe renaming this to
stmmac_mac_core_get_caps()would be acceptable?
The name was selected to align with the rest of the PHYLINK callbacks:
static const struct phylink_mac_ops stmmac_phylink_mac_ops = {
.mac_get_caps = stmmac_mac_get_caps, .mac_select_pcs = stmmac_mac_select_pcs, .mac_config = stmmac_mac_config, .mac_link_down = stmmac_mac_link_down, .mac_link_up = stmmac_mac_link_up,
};
So I don't think that changing it to something different would be a good alternative. What could be a better option is to rename the stmmac_ops::phylink_get_caps() callback and stmmac_mac_phylink_get_caps() macro-function to something like:
stmmac_ops::link_update_caps()stmmac_mac_link_update_caps()
especially seeing the callback no longer sets the phylink MAC capabilities directly. What do you think?
-Serge(y)
Quoted 9 lines
Please let me know what you think.
Thanks,
Signature · 3 lines
Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter
Quoted 10 lines · Serge Semin
So I don't think that changing it to something different would be a good alternative. What could be a better option is to rename the
stmmac_ops::phylink_get_caps()callback andstmmac_mac_phylink_get_caps()macro-function to something like:
stmmac_ops::link_update_caps()stmmac_mac_link_update_caps()especially seeing the callback no longer sets the phylink MAC capabilities directly. What do you think?
This seems like a good solution to me.
Thanks,
Signature · 3 lines
Romain Gantois, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter
In reply to Romain GantoisQuoted 4 lines · Romain Gantois
Hi Serge,
On Fri, 12 Apr 2024, Serge Semin wrote:
Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex) · line 945
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7
-0+static unsigned long stmmac_mac_get_caps (struct phylink_config *config, +phy_interface_t interface) +{ +struct stmmac_priv *priv =netdev_priv (to_net_dev (config->dev)); + +/* Get the MAC-specific capabilities */ +stmmac_mac_phylink_get_caps (priv);This is a bit of a nitpick, but the terminology is quite confusing between
stmmac_mac_phylink_get_caps()andstmmac_mac_get_caps(). Ideally, we could just get rid of the wholestmmac_do_void_callback()complexity and just callphylink_get_caps()directly. In the meantime, maybe renaming this tostmmac_mac_core_get_caps()would be acceptable?
I'd prefer not to do that. If the method is called mac_get_caps() then I'd much rather have method implementations called foo_mac_get_caps() which makes grep easier.
So... stmmac_core_mac_get_caps() would be acceptable to me.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Paolo Abeni
maintainerRe: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter
In reply to Serge SeminQuoted 9 lines · Serge Semin
After a set of fixes the
stmmac_phy_setup()andstmmac_reinit_queues()method have turned to having some duplicated code. Let's get rid from the duplication by moving the MAC-capabilities initialization to the PHYLINK MAC-capabilities getter. The getter is called during each network device interface open/close cycle. So the MAC-capabilities will be initialized in normal device functioning and in case of the Tx/Rx queues re-initialization as the original code semantics implies.Signed-off-by Serge Semin <[email protected]>
This is a net-next follow-up for the previous 3 patches targeting 'net', right?
If so, you should have posted this one separately after the other would have been merged back into net-next.
We can apply the first 3 to 'net', but you will have to repost 4/4 after ~Thu.
Thanks,
Paolo
Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter
Quoted 9 lines · Paolo Abeni
Quoted 8 lines · Serge Semin
After a set of fixes the
stmmac_phy_setup()andstmmac_reinit_queues()method have turned to having some duplicated code. Let's get rid from the duplication by moving the MAC-capabilities initialization to the PHYLINK MAC-capabilities getter. The getter is called during each network device interface open/close cycle. So the MAC-capabilities will be initialized in normal device functioning and in case of the Tx/Rx queues re-initialization as the original code semantics implies.
Quoted 4 lines
Quoted 1 line
Signed-off-by Serge Semin <[email protected]>This is a net-next follow-up for the previous 3 patches targeting 'net', right?
Right. The last patch in the series is a cleanup patch which gets rid from the duplicated code by moving it to the PHYLINK MAC-capability getter.
Quoted 3 lines
If so, you should have posted this one separately after the other would have been merged back into net-next.
I thought about that initially. But since this patch content is connected with the rest of patches and the maintainers/reviewers may ask to do things differently than it's provided in the initial patches, I decided to submit the entire series as is but indicating that the last patch is intended for 'net-next'.
Quoted 3 lines
We can apply the first 3 to 'net', but you will have to repost 4/4 after ~Thu.
Agreed. I'll repost 4/4 after the initial 3 patches get to be merged in.
Thanks
-Serge(y)
Quoted 5 lines
Thanks,
Paolo
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 5 lines · On Fri, 12 Apr 2024 21:03:13 +0300 you wrote:
The series got born as a result of the discussions around the recent Yanteng' series adding the Loongson LS7A1000, LS2K1000, LS7A2000, LS2K2000 MACs support:
Quoted 7 lines
In particular the Yanteng' patchset needed to implement the Loongson MAC-specific constraints applied to the link speed and link duplex mode. As a result of the discussion with Russel the next preliminary patch was born:
[...]
Here is the summary with links:
- [net,1/4] net: stmmac: Apply half-duplex-less constraint for DW QoS Eth only
https://git.kernel.org/netdev/net/c/0ebd96f5da44 - [net,2/4] net: stmmac: Fix max-speed being ignored on queue re-init https://git.kernel.org/netdev/net/c/59c3d6ca6cbd - [net,3/4] net: stmmac: Fix IP-cores specific MAC capabilities https://git.kernel.org/netdev/net/c/9cb54af214a7
- [net-next,4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html