2024-04-12 18:04:17

by Serge Semin

[permalink] [raw]
Subject: [PATCH net 0/4] 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:
Link: https://lore.kernel.org/netdev/fu3f6uoakylnb6eijllakeu5i4okcyqq7sfafhp5efaocbsrwe@w74xe7gb6x7p

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:
Link: https://lore.kernel.org/netdev/df31e8bcf74b3b4ddb7ddf5a1c371390f16a2ad5.1712917541.git.siyanteng@loongson.cn

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.

Signed-off-by: Serge Semin <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: Huacai Chen <[email protected]>
Cc: Chen-Yu Tsai <[email protected]>
Cc: Jernej Skrabec <[email protected]>
Cc: Samuel Holland <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

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(-)

--
2.43.0



2024-04-12 18:04:32

by Serge Semin

[permalink] [raw]
Subject: [PATCH net 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.

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(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index cef25efbdff9..ec6a13e644b3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -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,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 24cd80490d19..dd58c21b53ee 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -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))
--
2.43.0


2024-04-12 18:04:51

by Serge Semin

[permalink] [raw]
Subject: [PATCH net 2/4] net: stmmac: Fix max-speed being ignored on queue re-init

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_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.

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(+)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index dd58c21b53ee..b8a1f02398ee 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -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))
--
2.43.0


2024-04-12 18:05:14

by Serge Semin

[permalink] [raw]
Subject: [PATCH net 3/4] net: stmmac: Fix IP-cores specific MAC capabilities

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_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_2500FD

DW 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_100000FD

As 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.

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(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index a6fefe675ef1..3b7d4ac1e7be 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -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;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
index b21d99faa2d0..e1b761dcfa1d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
@@ -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)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index 3927609abc44..8555299443f4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -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;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
index a6e8d7bd9588..7667d103cd0e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
@@ -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;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
index ec6a13e644b3..a38226d7cc6a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
@@ -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;
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
index e841e312077e..f8e7775bb633 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
@@ -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;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index b8a1f02398ee..7c6fb14b5555 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -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);
--
2.43.0


2024-04-12 18:05:23

by Serge Semin

[permalink] [raw]
Subject: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter

After 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.

Signed-off-by: Serge Semin <[email protected]>
---
.../net/ethernet/stmicro/stmmac/stmmac_main.c | 36 +++++++++----------
1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 7c6fb14b5555..cb72dd93191e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -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))
--
2.43.0


2024-04-16 07:32:52

by Romain Gantois

[permalink] [raw]
Subject: Re: [PATCH net 2/4] net: stmmac: Fix max-speed being ignored on queue re-init


On Fri, 12 Apr 2024, Serge Semin wrote:

> 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_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.
>
> 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(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index dd58c21b53ee..b8a1f02398ee 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -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))
> --
> 2.43.0
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>

Reviewed-by: Romain Gantois <[email protected]>

2024-04-16 07:38:56

by Romain Gantois

[permalink] [raw]
Subject: Re: [PATCH net 1/4] net: stmmac: Apply half-duplex-less constraint for DW QoS Eth only

On Fri, 12 Apr 2024, Serge Semin wrote:

> 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(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> index cef25efbdff9..ec6a13e644b3 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> @@ -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,
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 24cd80490d19..dd58c21b53ee 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -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))
> --
> 2.43.0
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>

Reviewed-by: Romain Gantois <[email protected]>

Thanks,

--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

2024-04-16 07:56:22

by Romain Gantois

[permalink] [raw]
Subject: Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter

Hi Serge,

On Fri, 12 Apr 2024, Serge Semin wrote:

> +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,

--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

2024-04-16 08:00:40

by Romain Gantois

[permalink] [raw]
Subject: Re: [PATCH net 3/4] net: stmmac: Fix IP-cores specific MAC capabilities

On Fri, 12 Apr 2024, Serge Semin wrote:

> 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_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_2500FD
>
> DW 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_100000FD
>
> As 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.
>
> 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(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
> index a6fefe675ef1..3b7d4ac1e7be 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/common.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/common.h
> @@ -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;
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> index b21d99faa2d0..e1b761dcfa1d 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
> @@ -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)
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
> index 3927609abc44..8555299443f4 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
> @@ -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;
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
> index a6e8d7bd9588..7667d103cd0e 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
> @@ -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;
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> index ec6a13e644b3..a38226d7cc6a 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
> @@ -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;
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> index e841e312077e..f8e7775bb633 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c
> @@ -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;
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index b8a1f02398ee..7c6fb14b5555 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -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);
> --
> 2.43.0
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>

Reviewed-by: Romain Gantois <[email protected]>

Thanks,

--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

2024-04-16 10:27:51

by Paolo Abeni

[permalink] [raw]
Subject: Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter

On Fri, 2024-04-12 at 21:03 +0300, Serge Semin wrote:
> After 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.
>
> 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


2024-04-16 11:01:33

by Serge Semin

[permalink] [raw]
Subject: Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter

On Tue, Apr 16, 2024 at 12:27:29PM +0200, Paolo Abeni wrote:
> On Fri, 2024-04-12 at 21:03 +0300, Serge Semin wrote:
> > After 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.
> >
> > 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.

>
> 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'.

>
> 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)

>
> Thanks,
>
> Paolo
>

2024-04-16 11:38:44

by Serge Semin

[permalink] [raw]
Subject: Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter

Hi Romain

On Tue, Apr 16, 2024 at 09:56:32AM +0200, Romain Gantois wrote:
> Hi Serge,
>
> On Fri, 12 Apr 2024, Serge Semin wrote:
>
> > +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().

Right, the naming turns to be ambiguous "a bit".)

> Ideally, we could just
> get rid of the whole stmmac_do_void_callback() complexity and just call
> phylink_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.

> 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)

>
> Please let me know what you think.
>
> Thanks,
>
> --
> Romain Gantois, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com

2024-04-16 12:02:04

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter

On Tue, Apr 16, 2024 at 09:56:32AM +0200, Romain Gantois wrote:
> Hi Serge,
>
> On Fri, 12 Apr 2024, Serge Semin wrote:
>
> > +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?

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.

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

2024-04-16 13:21:22

by Romain Gantois

[permalink] [raw]
Subject: Re: [PATCH net-next 4/4] net: stmmac: Move MAC caps init to phylink MAC caps getter

On Tue, 16 Apr 2024, Serge Semin wrote:

> 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?

This seems like a good solution to me.

Thanks,

--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

2024-04-16 13:33:41

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net 0/4] net: stmmac: Fix MAC-capabilities procedure

Hello:

This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

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:
> Link: https://lore.kernel.org/netdev/fu3f6uoakylnb6eijllakeu5i4okcyqq7sfafhp5efaocbsrwe@w74xe7gb6x7p
>
> 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:
> Link: https://lore.kernel.org/netdev/df31e8bcf74b3b4ddb7ddf5a1c371390f16a2ad5.1712917541.git.siyanteng@loongson.cn
>
> [...]

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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html