1 From 5754b3bdcd872aa229881b8f07f84a8404c7d72a Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Fri, 12 Apr 2024 16:15:34 +0100
4 Subject: [PATCH 1/5] net: dsa: mt7530: provide own phylink MAC operations
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Convert mt753x to provide its own phylink MAC operations, thus avoiding
10 the shim layer in DSA's port.c
12 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
13 Tested-by: Arınç ÜNAL <arinc.unal@arinc9.com>
14 Link: https://lore.kernel.org/r/E1rvIco-006bQu-Fq@rmk-PC.armlinux.org.uk
15 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
17 drivers/net/dsa/mt7530.c | 46 +++++++++++++++++++++++++---------------
18 1 file changed, 29 insertions(+), 17 deletions(-)
20 --- a/drivers/net/dsa/mt7530.c
21 +++ b/drivers/net/dsa/mt7530.c
22 @@ -2850,28 +2850,34 @@ mt7531_mac_config(struct dsa_switch *ds,
25 static struct phylink_pcs *
26 -mt753x_phylink_mac_select_pcs(struct dsa_switch *ds, int port,
27 +mt753x_phylink_mac_select_pcs(struct phylink_config *config,
28 phy_interface_t interface)
30 - struct mt7530_priv *priv = ds->priv;
31 + struct dsa_port *dp = dsa_phylink_to_port(config);
32 + struct mt7530_priv *priv = dp->ds->priv;
35 case PHY_INTERFACE_MODE_TRGMII:
36 - return &priv->pcs[port].pcs;
37 + return &priv->pcs[dp->index].pcs;
38 case PHY_INTERFACE_MODE_SGMII:
39 case PHY_INTERFACE_MODE_1000BASEX:
40 case PHY_INTERFACE_MODE_2500BASEX:
41 - return priv->ports[port].sgmii_pcs;
42 + return priv->ports[dp->index].sgmii_pcs;
49 -mt753x_phylink_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
50 +mt753x_phylink_mac_config(struct phylink_config *config, unsigned int mode,
51 const struct phylink_link_state *state)
53 - struct mt7530_priv *priv = ds->priv;
54 + struct dsa_port *dp = dsa_phylink_to_port(config);
55 + struct dsa_switch *ds = dp->ds;
56 + struct mt7530_priv *priv;
57 + int port = dp->index;
61 if ((port == 5 || port == 6) && priv->info->mac_port_config)
62 priv->info->mac_port_config(ds, port, mode, state->interface);
63 @@ -2881,23 +2887,25 @@ mt753x_phylink_mac_config(struct dsa_swi
64 mt7530_set(priv, MT7530_PMCR_P(port), PMCR_EXT_PHY);
67 -static void mt753x_phylink_mac_link_down(struct dsa_switch *ds, int port,
68 +static void mt753x_phylink_mac_link_down(struct phylink_config *config,
70 phy_interface_t interface)
72 - struct mt7530_priv *priv = ds->priv;
73 + struct dsa_port *dp = dsa_phylink_to_port(config);
74 + struct mt7530_priv *priv = dp->ds->priv;
76 - mt7530_clear(priv, MT7530_PMCR_P(port), PMCR_LINK_SETTINGS_MASK);
77 + mt7530_clear(priv, MT7530_PMCR_P(dp->index), PMCR_LINK_SETTINGS_MASK);
80 -static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port,
81 +static void mt753x_phylink_mac_link_up(struct phylink_config *config,
82 + struct phy_device *phydev,
84 phy_interface_t interface,
85 - struct phy_device *phydev,
86 int speed, int duplex,
87 bool tx_pause, bool rx_pause)
89 - struct mt7530_priv *priv = ds->priv;
90 + struct dsa_port *dp = dsa_phylink_to_port(config);
91 + struct mt7530_priv *priv = dp->ds->priv;
94 mcr = PMCR_RX_EN | PMCR_TX_EN | PMCR_FORCE_LNK;
95 @@ -2932,7 +2940,7 @@ static void mt753x_phylink_mac_link_up(s
99 - mt7530_set(priv, MT7530_PMCR_P(port), mcr);
100 + mt7530_set(priv, MT7530_PMCR_P(dp->index), mcr);
103 static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
104 @@ -3152,16 +3160,19 @@ const struct dsa_switch_ops mt7530_switc
105 .port_mirror_add = mt753x_port_mirror_add,
106 .port_mirror_del = mt753x_port_mirror_del,
107 .phylink_get_caps = mt753x_phylink_get_caps,
108 - .phylink_mac_select_pcs = mt753x_phylink_mac_select_pcs,
109 - .phylink_mac_config = mt753x_phylink_mac_config,
110 - .phylink_mac_link_down = mt753x_phylink_mac_link_down,
111 - .phylink_mac_link_up = mt753x_phylink_mac_link_up,
112 .get_mac_eee = mt753x_get_mac_eee,
113 .set_mac_eee = mt753x_set_mac_eee,
114 .master_state_change = mt753x_conduit_state_change,
116 EXPORT_SYMBOL_GPL(mt7530_switch_ops);
118 +static const struct phylink_mac_ops mt753x_phylink_mac_ops = {
119 + .mac_select_pcs = mt753x_phylink_mac_select_pcs,
120 + .mac_config = mt753x_phylink_mac_config,
121 + .mac_link_down = mt753x_phylink_mac_link_down,
122 + .mac_link_up = mt753x_phylink_mac_link_up,
125 const struct mt753x_info mt753x_table[] = {
128 @@ -3239,6 +3250,7 @@ mt7530_probe_common(struct mt7530_priv *
130 priv->ds->priv = priv;
131 priv->ds->ops = &mt7530_switch_ops;
132 + priv->ds->phylink_mac_ops = &mt753x_phylink_mac_ops;
133 mutex_init(&priv->reg_mutex);
134 dev_set_drvdata(dev, priv);