ca2657d57d5f185a4e7bb998e0888f8519e49cd6
[openwrt/staging/ldir.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Convert mt753x to provide its own phylink MAC operations, thus avoiding
10 the shim layer in DSA's port.c
11
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>
16 ---
17 drivers/net/dsa/mt7530.c | 46 +++++++++++++++++++++++++---------------
18 1 file changed, 29 insertions(+), 17 deletions(-)
19
20 --- a/drivers/net/dsa/mt7530.c
21 +++ b/drivers/net/dsa/mt7530.c
22 @@ -2841,28 +2841,34 @@ mt7531_mac_config(struct dsa_switch *ds,
23 }
24
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)
29 {
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;
33
34 switch (interface) {
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;
43 default:
44 return NULL;
45 }
46 }
47
48 static void
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)
52 {
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;
58 +
59 + priv = ds->priv;
60
61 if ((port == 5 || port == 6) && priv->info->mac_port_config)
62 priv->info->mac_port_config(ds, port, mode, state->interface);
63 @@ -2872,23 +2878,25 @@ mt753x_phylink_mac_config(struct dsa_swi
64 mt7530_set(priv, MT7530_PMCR_P(port), PMCR_EXT_PHY);
65 }
66
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,
69 unsigned int mode,
70 phy_interface_t interface)
71 {
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;
75
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);
78 }
79
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,
83 unsigned int mode,
84 phy_interface_t interface,
85 - struct phy_device *phydev,
86 int speed, int duplex,
87 bool tx_pause, bool rx_pause)
88 {
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;
92 u32 mcr;
93
94 mcr = PMCR_RX_EN | PMCR_TX_EN | PMCR_FORCE_LNK;
95 @@ -2923,7 +2931,7 @@ static void mt753x_phylink_mac_link_up(s
96 }
97 }
98
99 - mt7530_set(priv, MT7530_PMCR_P(port), mcr);
100 + mt7530_set(priv, MT7530_PMCR_P(dp->index), mcr);
101 }
102
103 static void mt753x_phylink_get_caps(struct dsa_switch *ds, int port,
104 @@ -3148,16 +3156,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,
115 };
116 EXPORT_SYMBOL_GPL(mt7530_switch_ops);
117
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,
123 +};
124 +
125 const struct mt753x_info mt753x_table[] = {
126 [ID_MT7621] = {
127 .id = ID_MT7621,
128 @@ -3227,6 +3238,7 @@ mt7530_probe_common(struct mt7530_priv *
129 priv->dev = dev;
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);
135