e311a9314f7a8ccdcfb4d6a91c0977e9813fe402
[openwrt/staging/stintel.git] /
1 From 58670652cacb7c5752e01f29979d0ca4cdbfcc0a Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <arinc.unal@arinc9.com>
3 Date: Fri, 1 Mar 2024 12:43:00 +0200
4 Subject: [PATCH 22/30] net: dsa: mt7530: get rid of useless error returns on
5 phylink code path
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Remove error returns on the cases where they are already handled with the
11 function the mac_port_get_caps member in mt753x_table points to.
12
13 mt7531_mac_config() is also called from mt7531_cpu_port_config() outside of
14 phylink but the port and interface modes are already handled there.
15
16 Change the functions and the mac_port_config function pointer to void now
17 that there're no error returns anymore.
18
19 Remove mt753x_is_mac_port() that used to help the said error returns.
20
21 On mt7531_mac_config(), switch to if statements to simplify the code.
22
23 Remove internal phy cases from mt753x_phylink_mac_config(), there is no
24 need to check the interface mode as that's already handled with the
25 function the mac_port_get_caps member in mt753x_table points to.
26
27 Acked-by: Daniel Golle <daniel@makrotopia.org>
28 Tested-by: Daniel Golle <daniel@makrotopia.org>
29 Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
30 Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
31 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
32 ---
33 drivers/net/dsa/mt7530.c | 81 ++++++++--------------------------------
34 drivers/net/dsa/mt7530.h | 6 +--
35 2 files changed, 19 insertions(+), 68 deletions(-)
36
37 --- a/drivers/net/dsa/mt7530.c
38 +++ b/drivers/net/dsa/mt7530.c
39 @@ -2623,7 +2623,7 @@ static void mt7988_mac_port_get_caps(str
40 }
41 }
42
43 -static int
44 +static void
45 mt7530_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
46 phy_interface_t interface)
47 {
48 @@ -2633,22 +2633,14 @@ mt7530_mac_config(struct dsa_switch *ds,
49 mt7530_setup_port5(priv->ds, interface);
50 else if (port == 6)
51 mt7530_setup_port6(priv->ds, interface);
52 -
53 - return 0;
54 }
55
56 -static int mt7531_rgmii_setup(struct mt7530_priv *priv, u32 port,
57 - phy_interface_t interface,
58 - struct phy_device *phydev)
59 +static void mt7531_rgmii_setup(struct mt7530_priv *priv, u32 port,
60 + phy_interface_t interface,
61 + struct phy_device *phydev)
62 {
63 u32 val;
64
65 - if (priv->p5_sgmii) {
66 - dev_err(priv->dev, "RGMII mode is not available for port %d\n",
67 - port);
68 - return -EINVAL;
69 - }
70 -
71 val = mt7530_read(priv, MT7531_CLKGEN_CTRL);
72 val |= GP_CLK_EN;
73 val &= ~GP_MODE_MASK;
74 @@ -2676,20 +2668,14 @@ static int mt7531_rgmii_setup(struct mt7
75 case PHY_INTERFACE_MODE_RGMII_ID:
76 break;
77 default:
78 - return -EINVAL;
79 + break;
80 }
81 }
82 - mt7530_write(priv, MT7531_CLKGEN_CTRL, val);
83
84 - return 0;
85 -}
86 -
87 -static bool mt753x_is_mac_port(u32 port)
88 -{
89 - return (port == 5 || port == 6);
90 + mt7530_write(priv, MT7531_CLKGEN_CTRL, val);
91 }
92
93 -static int
94 +static void
95 mt7531_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
96 phy_interface_t interface)
97 {
98 @@ -2697,42 +2683,21 @@ mt7531_mac_config(struct dsa_switch *ds,
99 struct phy_device *phydev;
100 struct dsa_port *dp;
101
102 - if (!mt753x_is_mac_port(port)) {
103 - dev_err(priv->dev, "port %d is not a MAC port\n", port);
104 - return -EINVAL;
105 - }
106 -
107 - switch (interface) {
108 - case PHY_INTERFACE_MODE_RGMII:
109 - case PHY_INTERFACE_MODE_RGMII_ID:
110 - case PHY_INTERFACE_MODE_RGMII_RXID:
111 - case PHY_INTERFACE_MODE_RGMII_TXID:
112 + if (phy_interface_mode_is_rgmii(interface)) {
113 dp = dsa_to_port(ds, port);
114 phydev = dp->slave->phydev;
115 - return mt7531_rgmii_setup(priv, port, interface, phydev);
116 - case PHY_INTERFACE_MODE_SGMII:
117 - case PHY_INTERFACE_MODE_NA:
118 - case PHY_INTERFACE_MODE_1000BASEX:
119 - case PHY_INTERFACE_MODE_2500BASEX:
120 - /* handled in SGMII PCS driver */
121 - return 0;
122 - default:
123 - return -EINVAL;
124 + mt7531_rgmii_setup(priv, port, interface, phydev);
125 }
126 -
127 - return -EINVAL;
128 }
129
130 -static int
131 +static void
132 mt753x_mac_config(struct dsa_switch *ds, int port, unsigned int mode,
133 const struct phylink_link_state *state)
134 {
135 struct mt7530_priv *priv = ds->priv;
136
137 - if (!priv->info->mac_port_config)
138 - return 0;
139 -
140 - return priv->info->mac_port_config(ds, port, mode, state->interface);
141 + if (priv->info->mac_port_config)
142 + priv->info->mac_port_config(ds, port, mode, state->interface);
143 }
144
145 static struct phylink_pcs *
146 @@ -2761,17 +2726,11 @@ mt753x_phylink_mac_config(struct dsa_swi
147 u32 mcr_cur, mcr_new;
148
149 switch (port) {
150 - case 0 ... 4:
151 - if (state->interface != PHY_INTERFACE_MODE_GMII &&
152 - state->interface != PHY_INTERFACE_MODE_INTERNAL)
153 - goto unsupported;
154 - break;
155 case 5:
156 if (priv->p5_interface == state->interface)
157 break;
158
159 - if (mt753x_mac_config(ds, port, mode, state) < 0)
160 - goto unsupported;
161 + mt753x_mac_config(ds, port, mode, state);
162
163 if (priv->p5_intf_sel != P5_DISABLED)
164 priv->p5_interface = state->interface;
165 @@ -2780,16 +2739,10 @@ mt753x_phylink_mac_config(struct dsa_swi
166 if (priv->p6_interface == state->interface)
167 break;
168
169 - if (mt753x_mac_config(ds, port, mode, state) < 0)
170 - goto unsupported;
171 + mt753x_mac_config(ds, port, mode, state);
172
173 priv->p6_interface = state->interface;
174 break;
175 - default:
176 -unsupported:
177 - dev_err(ds->dev, "%s: unsupported %s port: %i\n",
178 - __func__, phy_modes(state->interface), port);
179 - return;
180 }
181
182 mcr_cur = mt7530_read(priv, MT7530_PMCR_P(port));
183 @@ -2872,7 +2825,6 @@ mt7531_cpu_port_config(struct dsa_switch
184 struct mt7530_priv *priv = ds->priv;
185 phy_interface_t interface;
186 int speed;
187 - int ret;
188
189 switch (port) {
190 case 5:
191 @@ -2897,9 +2849,8 @@ mt7531_cpu_port_config(struct dsa_switch
192 else
193 speed = SPEED_1000;
194
195 - ret = mt7531_mac_config(ds, port, MLO_AN_FIXED, interface);
196 - if (ret)
197 - return ret;
198 + mt7531_mac_config(ds, port, MLO_AN_FIXED, interface);
199 +
200 mt7530_write(priv, MT7530_PMCR_P(port),
201 PMCR_CPU_PORT_SETTING(priv->id));
202 mt753x_phylink_mac_link_up(ds, port, MLO_AN_FIXED, interface, NULL,
203 --- a/drivers/net/dsa/mt7530.h
204 +++ b/drivers/net/dsa/mt7530.h
205 @@ -750,9 +750,9 @@ struct mt753x_info {
206 void (*mac_port_validate)(struct dsa_switch *ds, int port,
207 phy_interface_t interface,
208 unsigned long *supported);
209 - int (*mac_port_config)(struct dsa_switch *ds, int port,
210 - unsigned int mode,
211 - phy_interface_t interface);
212 + void (*mac_port_config)(struct dsa_switch *ds, int port,
213 + unsigned int mode,
214 + phy_interface_t interface);
215 };
216
217 /* struct mt7530_priv - This is the main data structure for holding the state