Skip to content

Commit

Permalink
generic: mtk_eth_soc: add support for flow-control settings
Browse files Browse the repository at this point in the history
Add patch implementing operations to get and set flow-control link
parameters of mtk_eth_soc to Linux 6.1 and Linux 6.6 generic patchset.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  • Loading branch information
dangowrt committed Mar 26, 2024
1 parent 2951586 commit c684039
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
From 0f4a54053f0ca66817ef492db68479b2be4dc1f4 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Tue, 26 Mar 2024 10:35:09 +0000
Subject: [PATCH] net: ethernet: mtk_eth_soc: implement .{get,set}_pauseparam
ethtool ops

Implement operations to get and set flow-control link parameters.
Use *_MCR_FORCE_{RX,TX}_FC flags to read current use of RX and TX
pause frames with the exception of the GMAC1 when used as link to the
built-in switch of MT7988 SoC, it does not support accessing XMAC_MCR.

Setting flow-control parameters is done by calling
phylink_ethtool_set_pauseparam().

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 37 ++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)

--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -4441,6 +4441,39 @@ static int mtk_set_rxnfc(struct net_devi
return ret;
}

+static void mtk_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
+{
+ struct mtk_mac *mac = netdev_priv(dev);
+ struct mtk_eth *eth = mac->hw;
+ u32 val;
+
+ if (mtk_interface_mode_is_xgmii(mac->interface)) {
+ if (mac->id == MTK_GMAC1_ID) {
+ /* always report all OFF for internal GSW */
+ pause->autoneg = 0;
+ pause->rx_pause = 0;
+ pause->tx_pause = 0;
+ return;
+ }
+ val = mtk_r32(eth, MTK_XMAC_MCR(mac->id));
+
+ pause->rx_pause = !!(val & XMAC_MCR_FORCE_RX_FC);
+ pause->tx_pause = !!(val & XMAC_MCR_FORCE_TX_FC);
+ } else {
+ val = mtk_r32(eth, MTK_MAC_MCR(mac->id));
+
+ pause->rx_pause = !!(val & MAC_MCR_FORCE_RX_FC);
+ pause->tx_pause = !!(val & MAC_MCR_FORCE_TX_FC);
+ }
+}
+
+static int mtk_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
+{
+ struct mtk_mac *mac = netdev_priv(dev);
+
+ return phylink_ethtool_set_pauseparam(mac->phylink, pause);
+}
+
static u16 mtk_select_queue(struct net_device *dev, struct sk_buff *skb,
struct net_device *sb_dev)
{
@@ -4469,8 +4502,10 @@ static const struct ethtool_ops mtk_etht
.get_strings = mtk_get_strings,
.get_sset_count = mtk_get_sset_count,
.get_ethtool_stats = mtk_get_ethtool_stats,
+ .get_pauseparam = mtk_get_pauseparam,
+ .set_pauseparam = mtk_set_pauseparam,
.get_rxnfc = mtk_get_rxnfc,
- .set_rxnfc = mtk_set_rxnfc,
+ .set_rxnfc = mtk_set_rxnfc,
};

static const struct net_device_ops mtk_netdev_ops = {
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,15 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return 0;
}

@@ -4497,6 +4644,7 @@ static const struct net_device_ops mtk_n
@@ -4532,6 +4679,7 @@ static const struct net_device_ops mtk_n
static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
{
const __be32 *_id = of_get_property(np, "reg", NULL);
+ struct device_node *pcs_np;
phy_interface_t phy_mode;
struct phylink *phylink;
struct mtk_mac *mac;
@@ -4532,16 +4680,41 @@ static int mtk_add_mac(struct mtk_eth *e
@@ -4567,16 +4715,41 @@ static int mtk_add_mac(struct mtk_eth *e
mac->id = id;
mac->hw = eth;
mac->of_node = np;
Expand Down Expand Up @@ -568,7 +568,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
}

memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip));
@@ -4615,8 +4788,21 @@ static int mtk_add_mac(struct mtk_eth *e
@@ -4650,8 +4823,21 @@ static int mtk_add_mac(struct mtk_eth *e
phy_interface_zero(mac->phylink_config.supported_interfaces);
__set_bit(PHY_INTERFACE_MODE_INTERNAL,
mac->phylink_config.supported_interfaces);
Expand All @@ -590,7 +590,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
phylink = phylink_create(&mac->phylink_config,
of_fwnode_handle(mac->of_node),
phy_mode, &mtk_phylink_ops);
@@ -4661,6 +4847,26 @@ free_netdev:
@@ -4696,6 +4882,26 @@ free_netdev:
return err;
}

Expand All @@ -617,7 +617,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev)
{
struct net_device *dev, *tmp;
@@ -4804,7 +5010,8 @@ static int mtk_probe(struct platform_dev
@@ -4839,7 +5045,8 @@ static int mtk_probe(struct platform_dev
regmap_write(cci, 0, 3);
}

Expand All @@ -627,7 +627,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
err = mtk_sgmii_init(eth);

if (err)
@@ -4915,6 +5122,24 @@ static int mtk_probe(struct platform_dev
@@ -4950,6 +5157,24 @@ static int mtk_probe(struct platform_dev
}
}

Expand All @@ -652,7 +652,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT)) {
err = devm_request_irq(eth->dev, eth->irq[0],
mtk_handle_irq, 0,
@@ -5017,6 +5242,11 @@ static int mtk_remove(struct platform_de
@@ -5052,6 +5277,11 @@ static int mtk_remove(struct platform_de
mtk_stop(eth->netdev[i]);
mac = netdev_priv(eth->netdev[i]);
phylink_disconnect_phy(mac->phylink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>

--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -4963,7 +4963,10 @@ static int mtk_probe(struct platform_dev
@@ -4998,7 +4998,10 @@ static int mtk_probe(struct platform_dev
}

if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
From 0f4a54053f0ca66817ef492db68479b2be4dc1f4 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Tue, 26 Mar 2024 10:35:09 +0000
Subject: [PATCH] net: ethernet: mtk_eth_soc: implement .{get,set}_pauseparam
ethtool ops

Implement operations to get and set flow-control link parameters.
Use *_MCR_FORCE_{RX,TX}_FC flags to read current use of RX and TX
pause frames with the exception of the GMAC1 when used as link to the
built-in switch of MT7988 SoC, it does not support accessing XMAC_MCR.

Setting flow-control parameters is done by calling
phylink_ethtool_set_pauseparam().

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 37 ++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)

--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -4460,6 +4460,39 @@ static int mtk_set_rxnfc(struct net_devi
return ret;
}

+static void mtk_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
+{
+ struct mtk_mac *mac = netdev_priv(dev);
+ struct mtk_eth *eth = mac->hw;
+ u32 val;
+
+ if (mtk_interface_mode_is_xgmii(mac->interface)) {
+ if (mac->id == MTK_GMAC1_ID) {
+ /* always report all OFF for internal GSW */
+ pause->autoneg = 0;
+ pause->rx_pause = 0;
+ pause->tx_pause = 0;
+ return;
+ }
+ val = mtk_r32(eth, MTK_XMAC_MCR(mac->id));
+
+ pause->rx_pause = !!(val & XMAC_MCR_FORCE_RX_FC);
+ pause->tx_pause = !!(val & XMAC_MCR_FORCE_TX_FC);
+ } else {
+ val = mtk_r32(eth, MTK_MAC_MCR(mac->id));
+
+ pause->rx_pause = !!(val & MAC_MCR_FORCE_RX_FC);
+ pause->tx_pause = !!(val & MAC_MCR_FORCE_TX_FC);
+ }
+}
+
+static int mtk_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
+{
+ struct mtk_mac *mac = netdev_priv(dev);
+
+ return phylink_ethtool_set_pauseparam(mac->phylink, pause);
+}
+
static u16 mtk_select_queue(struct net_device *dev, struct sk_buff *skb,
struct net_device *sb_dev)
{
@@ -4488,8 +4521,10 @@ static const struct ethtool_ops mtk_etht
.get_strings = mtk_get_strings,
.get_sset_count = mtk_get_sset_count,
.get_ethtool_stats = mtk_get_ethtool_stats,
+ .get_pauseparam = mtk_get_pauseparam,
+ .set_pauseparam = mtk_set_pauseparam,
.get_rxnfc = mtk_get_rxnfc,
- .set_rxnfc = mtk_set_rxnfc,
+ .set_rxnfc = mtk_set_rxnfc,
};

static const struct net_device_ops mtk_netdev_ops = {
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,15 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return 0;
}

@@ -4516,6 +4663,7 @@ static const struct net_device_ops mtk_n
@@ -4551,6 +4698,7 @@ static const struct net_device_ops mtk_n
static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
{
const __be32 *_id = of_get_property(np, "reg", NULL);
+ struct device_node *pcs_np;
phy_interface_t phy_mode;
struct phylink *phylink;
struct mtk_mac *mac;
@@ -4552,16 +4700,41 @@ static int mtk_add_mac(struct mtk_eth *e
@@ -4587,16 +4735,41 @@ static int mtk_add_mac(struct mtk_eth *e
mac->id = id;
mac->hw = eth;
mac->of_node = np;
Expand Down Expand Up @@ -568,7 +568,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
}

memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip));
@@ -4644,8 +4817,21 @@ static int mtk_add_mac(struct mtk_eth *e
@@ -4679,8 +4852,21 @@ static int mtk_add_mac(struct mtk_eth *e
phy_interface_zero(mac->phylink_config.supported_interfaces);
__set_bit(PHY_INTERFACE_MODE_INTERNAL,
mac->phylink_config.supported_interfaces);
Expand All @@ -590,7 +590,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
phylink = phylink_create(&mac->phylink_config,
of_fwnode_handle(mac->of_node),
phy_mode, &mtk_phylink_ops);
@@ -4696,6 +4882,26 @@ free_netdev:
@@ -4731,6 +4917,26 @@ free_netdev:
return err;
}

Expand All @@ -617,7 +617,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev)
{
struct net_device *dev, *tmp;
@@ -4842,7 +5048,8 @@ static int mtk_probe(struct platform_dev
@@ -4877,7 +5083,8 @@ static int mtk_probe(struct platform_dev
regmap_write(cci, 0, 3);
}

Expand All @@ -627,7 +627,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
err = mtk_sgmii_init(eth);

if (err)
@@ -4953,6 +5160,24 @@ static int mtk_probe(struct platform_dev
@@ -4988,6 +5195,24 @@ static int mtk_probe(struct platform_dev
}
}

Expand All @@ -652,7 +652,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT)) {
err = devm_request_irq(eth->dev, eth->irq[0],
mtk_handle_irq, 0,
@@ -5055,6 +5280,11 @@ static int mtk_remove(struct platform_de
@@ -5090,6 +5315,11 @@ static int mtk_remove(struct platform_de
mtk_stop(eth->netdev[i]);
mac = netdev_priv(eth->netdev[i]);
phylink_disconnect_phy(mac->phylink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
mtk_w32(eth, 0x21021000, MTK_FE_INT_GRP);

if (mtk_is_netsys_v3_or_greater(eth)) {
@@ -5270,11 +5270,15 @@ static const struct mtk_soc_data mt2701_
@@ -5305,11 +5305,15 @@ static const struct mtk_soc_data mt2701_
.required_clks = MT7623_CLKS_BITMAP,
.required_pctl = true,
.version = 1,
Expand All @@ -368,7 +368,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
@@ -5290,11 +5294,15 @@ static const struct mtk_soc_data mt7621_
@@ -5325,11 +5329,15 @@ static const struct mtk_soc_data mt7621_
.offload_version = 1,
.hash_offset = 2,
.foe_entry_size = MTK_FOE_ENTRY_V1_SIZE,
Expand All @@ -389,7 +389,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
@@ -5312,11 +5320,15 @@ static const struct mtk_soc_data mt7622_
@@ -5347,11 +5355,15 @@ static const struct mtk_soc_data mt7622_
.hash_offset = 2,
.has_accounting = true,
.foe_entry_size = MTK_FOE_ENTRY_V1_SIZE,
Expand All @@ -410,7 +410,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
@@ -5333,11 +5345,15 @@ static const struct mtk_soc_data mt7623_
@@ -5368,11 +5380,15 @@ static const struct mtk_soc_data mt7623_
.hash_offset = 2,
.foe_entry_size = MTK_FOE_ENTRY_V1_SIZE,
.disable_pll_modes = true,
Expand All @@ -431,7 +431,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
@@ -5352,11 +5368,15 @@ static const struct mtk_soc_data mt7629_
@@ -5387,11 +5403,15 @@ static const struct mtk_soc_data mt7629_
.required_pctl = false,
.has_accounting = true,
.version = 1,
Expand All @@ -452,7 +452,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
.dma_max_len = MTK_TX_DMA_BUF_LEN,
.dma_len_offset = 16,
},
@@ -5374,11 +5394,15 @@ static const struct mtk_soc_data mt7981_
@@ -5409,11 +5429,15 @@ static const struct mtk_soc_data mt7981_
.hash_offset = 4,
.has_accounting = true,
.foe_entry_size = MTK_FOE_ENTRY_V2_SIZE,
Expand All @@ -473,7 +473,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
.dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
.dma_len_offset = 8,
},
@@ -5396,11 +5420,15 @@ static const struct mtk_soc_data mt7986_
@@ -5431,11 +5455,15 @@ static const struct mtk_soc_data mt7986_
.hash_offset = 4,
.has_accounting = true,
.foe_entry_size = MTK_FOE_ENTRY_V2_SIZE,
Expand All @@ -494,7 +494,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
.dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
.dma_len_offset = 8,
},
@@ -5418,11 +5446,15 @@ static const struct mtk_soc_data mt7988_
@@ -5453,11 +5481,15 @@ static const struct mtk_soc_data mt7988_
.hash_offset = 4,
.has_accounting = true,
.foe_entry_size = MTK_FOE_ENTRY_V3_SIZE,
Expand All @@ -515,7 +515,7 @@ Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
.dma_max_len = MTK_TX_DMA_BUF_LEN_V2,
.dma_len_offset = 8,
},
@@ -5435,11 +5467,15 @@ static const struct mtk_soc_data rt5350_
@@ -5470,11 +5502,15 @@ static const struct mtk_soc_data rt5350_
.required_clks = MT7628_CLKS_BITMAP,
.required_pctl = false,
.version = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
/* Set FE to PDMAv2 if necessary */
val = mtk_r32(eth, MTK_FE_GLO_MISC);
mtk_w32(eth, val | BIT(4), MTK_FE_GLO_MISC);
@@ -5400,11 +5400,11 @@ static const struct mtk_soc_data mt7981_
@@ -5435,11 +5435,11 @@ static const struct mtk_soc_data mt7981_
.dma_len_offset = 8,
},
.rx = {
Expand All @@ -105,7 +105,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
},
};

@@ -5426,11 +5426,11 @@ static const struct mtk_soc_data mt7986_
@@ -5461,11 +5461,11 @@ static const struct mtk_soc_data mt7986_
.dma_len_offset = 8,
},
.rx = {
Expand Down
Loading

1 comment on commit c684039

@Headcrabed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, what happened to this commit? I saw some rj45 sfp modules need it to work correctly.

Please sign in to comment.