Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Handling of a single switch port |
| 4 | * |
| 5 | * Copyright (c) 2017 Savoir-faire Linux Inc. |
| 6 | * Vivien Didelot <vivien.didelot@savoirfairelinux.com> |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/if_bridge.h> |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 10 | #include <linux/notifier.h> |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 11 | #include <linux/of_mdio.h> |
| 12 | #include <linux/of_net.h> |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 13 | |
| 14 | #include "dsa_priv.h" |
| 15 | |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 16 | static int dsa_port_notify(const struct dsa_port *dp, unsigned long e, void *v) |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 17 | { |
| 18 | struct raw_notifier_head *nh = &dp->ds->dst->nh; |
| 19 | int err; |
| 20 | |
| 21 | err = raw_notifier_call_chain(nh, e, v); |
| 22 | |
| 23 | return notifier_to_errno(err); |
| 24 | } |
| 25 | |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 26 | int dsa_port_set_state(struct dsa_port *dp, u8 state, |
| 27 | struct switchdev_trans *trans) |
| 28 | { |
| 29 | struct dsa_switch *ds = dp->ds; |
| 30 | int port = dp->index; |
| 31 | |
| 32 | if (switchdev_trans_ph_prepare(trans)) |
| 33 | return ds->ops->port_stp_state_set ? 0 : -EOPNOTSUPP; |
| 34 | |
| 35 | if (ds->ops->port_stp_state_set) |
| 36 | ds->ops->port_stp_state_set(ds, port, state); |
| 37 | |
| 38 | if (ds->ops->port_fast_age) { |
| 39 | /* Fast age FDB entries or flush appropriate forwarding database |
| 40 | * for the given port, if we are moving it from Learning or |
| 41 | * Forwarding state, to Disabled or Blocking or Listening state. |
| 42 | */ |
| 43 | |
| 44 | if ((dp->stp_state == BR_STATE_LEARNING || |
| 45 | dp->stp_state == BR_STATE_FORWARDING) && |
| 46 | (state == BR_STATE_DISABLED || |
| 47 | state == BR_STATE_BLOCKING || |
| 48 | state == BR_STATE_LISTENING)) |
| 49 | ds->ops->port_fast_age(ds, port); |
| 50 | } |
| 51 | |
| 52 | dp->stp_state = state; |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 57 | static void dsa_port_set_state_now(struct dsa_port *dp, u8 state) |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 58 | { |
| 59 | int err; |
| 60 | |
| 61 | err = dsa_port_set_state(dp, state, NULL); |
| 62 | if (err) |
| 63 | pr_err("DSA: failed to set STP state %u (%d)\n", state, err); |
| 64 | } |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 65 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 66 | int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy) |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 67 | { |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 68 | struct dsa_switch *ds = dp->ds; |
| 69 | int port = dp->index; |
| 70 | int err; |
| 71 | |
| 72 | if (ds->ops->port_enable) { |
| 73 | err = ds->ops->port_enable(ds, port, phy); |
| 74 | if (err) |
| 75 | return err; |
| 76 | } |
| 77 | |
Russell King | 9c2054a | 2019-02-20 10:32:52 +0000 | [diff] [blame] | 78 | if (!dp->bridge_dev) |
| 79 | dsa_port_set_state_now(dp, BR_STATE_FORWARDING); |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 80 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 81 | if (dp->pl) |
| 82 | phylink_start(dp->pl); |
| 83 | |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 87 | int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy) |
| 88 | { |
| 89 | int err; |
| 90 | |
| 91 | rtnl_lock(); |
| 92 | err = dsa_port_enable_rt(dp, phy); |
| 93 | rtnl_unlock(); |
| 94 | |
| 95 | return err; |
| 96 | } |
| 97 | |
| 98 | void dsa_port_disable_rt(struct dsa_port *dp) |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 99 | { |
| 100 | struct dsa_switch *ds = dp->ds; |
| 101 | int port = dp->index; |
| 102 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 103 | if (dp->pl) |
| 104 | phylink_stop(dp->pl); |
| 105 | |
Russell King | 9c2054a | 2019-02-20 10:32:52 +0000 | [diff] [blame] | 106 | if (!dp->bridge_dev) |
| 107 | dsa_port_set_state_now(dp, BR_STATE_DISABLED); |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 108 | |
| 109 | if (ds->ops->port_disable) |
Andrew Lunn | 75104db | 2019-02-24 20:44:43 +0100 | [diff] [blame] | 110 | ds->ops->port_disable(ds, port); |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 113 | void dsa_port_disable(struct dsa_port *dp) |
| 114 | { |
| 115 | rtnl_lock(); |
| 116 | dsa_port_disable_rt(dp); |
| 117 | rtnl_unlock(); |
| 118 | } |
| 119 | |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 120 | int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br) |
| 121 | { |
| 122 | struct dsa_notifier_bridge_info info = { |
| 123 | .sw_index = dp->ds->index, |
| 124 | .port = dp->index, |
| 125 | .br = br, |
| 126 | }; |
| 127 | int err; |
| 128 | |
Russell King | c138806 | 2019-02-20 15:35:06 -0800 | [diff] [blame] | 129 | /* Set the flooding mode before joining the port in the switch */ |
| 130 | err = dsa_port_bridge_flags(dp, BR_FLOOD | BR_MCAST_FLOOD, NULL); |
| 131 | if (err) |
| 132 | return err; |
| 133 | |
| 134 | /* Here the interface is already bridged. Reflect the current |
| 135 | * configuration so that drivers can program their chips accordingly. |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 136 | */ |
| 137 | dp->bridge_dev = br; |
| 138 | |
| 139 | err = dsa_port_notify(dp, DSA_NOTIFIER_BRIDGE_JOIN, &info); |
| 140 | |
| 141 | /* The bridging is rolled back on error */ |
Russell King | c138806 | 2019-02-20 15:35:06 -0800 | [diff] [blame] | 142 | if (err) { |
| 143 | dsa_port_bridge_flags(dp, 0, NULL); |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 144 | dp->bridge_dev = NULL; |
Russell King | c138806 | 2019-02-20 15:35:06 -0800 | [diff] [blame] | 145 | } |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 146 | |
| 147 | return err; |
| 148 | } |
| 149 | |
| 150 | void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) |
| 151 | { |
| 152 | struct dsa_notifier_bridge_info info = { |
| 153 | .sw_index = dp->ds->index, |
| 154 | .port = dp->index, |
| 155 | .br = br, |
| 156 | }; |
| 157 | int err; |
| 158 | |
| 159 | /* Here the port is already unbridged. Reflect the current configuration |
| 160 | * so that drivers can program their chips accordingly. |
| 161 | */ |
| 162 | dp->bridge_dev = NULL; |
| 163 | |
| 164 | err = dsa_port_notify(dp, DSA_NOTIFIER_BRIDGE_LEAVE, &info); |
| 165 | if (err) |
| 166 | pr_err("DSA: failed to notify DSA_NOTIFIER_BRIDGE_LEAVE\n"); |
| 167 | |
Russell King | c138806 | 2019-02-20 15:35:06 -0800 | [diff] [blame] | 168 | /* Port is leaving the bridge, disable flooding */ |
| 169 | dsa_port_bridge_flags(dp, 0, NULL); |
| 170 | |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 171 | /* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer, |
| 172 | * so allow it to be in BR_STATE_FORWARDING to be kept functional |
| 173 | */ |
| 174 | dsa_port_set_state_now(dp, BR_STATE_FORWARDING); |
| 175 | } |
Vivien Didelot | 4d61d30 | 2017-05-19 17:00:46 -0400 | [diff] [blame] | 176 | |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 177 | static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, |
| 178 | bool vlan_filtering) |
| 179 | { |
| 180 | struct dsa_switch *ds = dp->ds; |
| 181 | int i; |
| 182 | |
| 183 | if (!ds->vlan_filtering_is_global) |
| 184 | return true; |
| 185 | |
| 186 | /* For cases where enabling/disabling VLAN awareness is global to the |
| 187 | * switch, we need to handle the case where multiple bridges span |
| 188 | * different ports of the same switch device and one of them has a |
| 189 | * different setting than what is being requested. |
| 190 | */ |
| 191 | for (i = 0; i < ds->num_ports; i++) { |
| 192 | struct net_device *other_bridge; |
| 193 | |
| 194 | other_bridge = dsa_to_port(ds, i)->bridge_dev; |
| 195 | if (!other_bridge) |
| 196 | continue; |
| 197 | /* If it's the same bridge, it also has same |
| 198 | * vlan_filtering setting => no need to check |
| 199 | */ |
| 200 | if (other_bridge == dp->bridge_dev) |
| 201 | continue; |
| 202 | if (br_vlan_enabled(other_bridge) != vlan_filtering) { |
| 203 | dev_err(ds->dev, "VLAN filtering is a global setting\n"); |
| 204 | return false; |
| 205 | } |
| 206 | } |
| 207 | return true; |
| 208 | } |
| 209 | |
Vivien Didelot | 4d61d30 | 2017-05-19 17:00:46 -0400 | [diff] [blame] | 210 | int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, |
| 211 | struct switchdev_trans *trans) |
| 212 | { |
| 213 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | 33162e9 | 2019-04-28 21:45:43 +0300 | [diff] [blame] | 214 | int err; |
Vivien Didelot | 4d61d30 | 2017-05-19 17:00:46 -0400 | [diff] [blame] | 215 | |
| 216 | /* bridge skips -EOPNOTSUPP, so skip the prepare phase */ |
| 217 | if (switchdev_trans_ph_prepare(trans)) |
| 218 | return 0; |
| 219 | |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 220 | if (!ds->ops->port_vlan_filtering) |
| 221 | return 0; |
| 222 | |
| 223 | if (!dsa_port_can_apply_vlan_filtering(dp, vlan_filtering)) |
| 224 | return -EINVAL; |
| 225 | |
Vladimir Oltean | ec9121e | 2019-04-28 21:45:51 +0300 | [diff] [blame] | 226 | if (dsa_port_is_vlan_filtering(dp) == vlan_filtering) |
| 227 | return 0; |
| 228 | |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 229 | err = ds->ops->port_vlan_filtering(ds, dp->index, |
| 230 | vlan_filtering); |
| 231 | if (err) |
| 232 | return err; |
| 233 | |
Vladimir Oltean | 14574676 | 2019-04-28 21:45:48 +0300 | [diff] [blame] | 234 | if (ds->vlan_filtering_is_global) |
| 235 | ds->vlan_filtering = vlan_filtering; |
| 236 | else |
| 237 | dp->vlan_filtering = vlan_filtering; |
Vivien Didelot | 4d61d30 | 2017-05-19 17:00:46 -0400 | [diff] [blame] | 238 | return 0; |
| 239 | } |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 240 | |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 241 | int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock, |
| 242 | struct switchdev_trans *trans) |
| 243 | { |
| 244 | unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock); |
| 245 | unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies); |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 246 | struct dsa_notifier_ageing_time_info info = { |
| 247 | .ageing_time = ageing_time, |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 248 | .trans = trans, |
| 249 | }; |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 250 | |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 251 | if (switchdev_trans_ph_prepare(trans)) |
| 252 | return dsa_port_notify(dp, DSA_NOTIFIER_AGEING_TIME, &info); |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 253 | |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 254 | dp->ageing_time = ageing_time; |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 255 | |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 256 | return dsa_port_notify(dp, DSA_NOTIFIER_AGEING_TIME, &info); |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 257 | } |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 258 | |
Florian Fainelli | ea87005 | 2019-02-20 16:58:22 -0800 | [diff] [blame] | 259 | int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags, |
| 260 | struct switchdev_trans *trans) |
| 261 | { |
| 262 | struct dsa_switch *ds = dp->ds; |
| 263 | |
| 264 | if (!ds->ops->port_egress_floods || |
| 265 | (flags & ~(BR_FLOOD | BR_MCAST_FLOOD))) |
| 266 | return -EINVAL; |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
Russell King | 5765279 | 2019-02-20 15:35:04 -0800 | [diff] [blame] | 271 | int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags, |
| 272 | struct switchdev_trans *trans) |
| 273 | { |
| 274 | struct dsa_switch *ds = dp->ds; |
| 275 | int port = dp->index; |
| 276 | int err = 0; |
| 277 | |
| 278 | if (switchdev_trans_ph_prepare(trans)) |
| 279 | return 0; |
| 280 | |
| 281 | if (ds->ops->port_egress_floods) |
| 282 | err = ds->ops->port_egress_floods(ds, port, flags & BR_FLOOD, |
| 283 | flags & BR_MCAST_FLOOD); |
| 284 | |
| 285 | return err; |
| 286 | } |
| 287 | |
Vivien Didelot | 08cc83c | 2019-07-08 23:31:13 -0400 | [diff] [blame] | 288 | int dsa_port_mrouter(struct dsa_port *dp, bool mrouter, |
| 289 | struct switchdev_trans *trans) |
| 290 | { |
| 291 | struct dsa_switch *ds = dp->ds; |
| 292 | int port = dp->index; |
| 293 | |
| 294 | if (switchdev_trans_ph_prepare(trans)) |
| 295 | return ds->ops->port_egress_floods ? 0 : -EOPNOTSUPP; |
| 296 | |
| 297 | return ds->ops->port_egress_floods(ds, port, true, mrouter); |
| 298 | } |
| 299 | |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 300 | int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu, |
| 301 | bool propagate_upstream) |
| 302 | { |
| 303 | struct dsa_notifier_mtu_info info = { |
| 304 | .sw_index = dp->ds->index, |
| 305 | .propagate_upstream = propagate_upstream, |
| 306 | .port = dp->index, |
| 307 | .mtu = new_mtu, |
| 308 | }; |
| 309 | |
| 310 | return dsa_port_notify(dp, DSA_NOTIFIER_MTU, &info); |
| 311 | } |
| 312 | |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 313 | int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 314 | u16 vid) |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 315 | { |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 316 | struct dsa_notifier_fdb_info info = { |
| 317 | .sw_index = dp->ds->index, |
| 318 | .port = dp->index, |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 319 | .addr = addr, |
| 320 | .vid = vid, |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 321 | }; |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 322 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 323 | return dsa_port_notify(dp, DSA_NOTIFIER_FDB_ADD, &info); |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 326 | int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 327 | u16 vid) |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 328 | { |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 329 | struct dsa_notifier_fdb_info info = { |
| 330 | .sw_index = dp->ds->index, |
| 331 | .port = dp->index, |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 332 | .addr = addr, |
| 333 | .vid = vid, |
| 334 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 335 | }; |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 336 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 337 | return dsa_port_notify(dp, DSA_NOTIFIER_FDB_DEL, &info); |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 338 | } |
| 339 | |
Vivien Didelot | de40fc5 | 2017-09-20 19:32:14 -0400 | [diff] [blame] | 340 | int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data) |
| 341 | { |
| 342 | struct dsa_switch *ds = dp->ds; |
| 343 | int port = dp->index; |
| 344 | |
| 345 | if (!ds->ops->port_fdb_dump) |
| 346 | return -EOPNOTSUPP; |
| 347 | |
| 348 | return ds->ops->port_fdb_dump(ds, port, cb, data); |
| 349 | } |
| 350 | |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 351 | int dsa_port_mdb_add(const struct dsa_port *dp, |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 352 | const struct switchdev_obj_port_mdb *mdb, |
| 353 | struct switchdev_trans *trans) |
| 354 | { |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 355 | struct dsa_notifier_mdb_info info = { |
| 356 | .sw_index = dp->ds->index, |
| 357 | .port = dp->index, |
| 358 | .trans = trans, |
| 359 | .mdb = mdb, |
| 360 | }; |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 361 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 362 | return dsa_port_notify(dp, DSA_NOTIFIER_MDB_ADD, &info); |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 363 | } |
| 364 | |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 365 | int dsa_port_mdb_del(const struct dsa_port *dp, |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 366 | const struct switchdev_obj_port_mdb *mdb) |
| 367 | { |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 368 | struct dsa_notifier_mdb_info info = { |
| 369 | .sw_index = dp->ds->index, |
| 370 | .port = dp->index, |
| 371 | .mdb = mdb, |
| 372 | }; |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 373 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 374 | return dsa_port_notify(dp, DSA_NOTIFIER_MDB_DEL, &info); |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 375 | } |
| 376 | |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 377 | int dsa_port_vlan_add(struct dsa_port *dp, |
| 378 | const struct switchdev_obj_port_vlan *vlan, |
| 379 | struct switchdev_trans *trans) |
| 380 | { |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 381 | struct dsa_notifier_vlan_info info = { |
| 382 | .sw_index = dp->ds->index, |
| 383 | .port = dp->index, |
| 384 | .trans = trans, |
| 385 | .vlan = vlan, |
| 386 | }; |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 387 | |
Vivien Didelot | c5335d7 | 2019-08-25 13:25:18 -0400 | [diff] [blame] | 388 | return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, &info); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | int dsa_port_vlan_del(struct dsa_port *dp, |
| 392 | const struct switchdev_obj_port_vlan *vlan) |
| 393 | { |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 394 | struct dsa_notifier_vlan_info info = { |
| 395 | .sw_index = dp->ds->index, |
| 396 | .port = dp->index, |
| 397 | .vlan = vlan, |
| 398 | }; |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 399 | |
Vivien Didelot | c5335d7 | 2019-08-25 13:25:18 -0400 | [diff] [blame] | 400 | return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, &info); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 401 | } |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 402 | |
Vladimir Oltean | 314f76d | 2019-04-28 21:45:54 +0300 | [diff] [blame] | 403 | int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags) |
| 404 | { |
| 405 | struct switchdev_obj_port_vlan vlan = { |
| 406 | .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN, |
| 407 | .flags = flags, |
| 408 | .vid_begin = vid, |
| 409 | .vid_end = vid, |
| 410 | }; |
| 411 | struct switchdev_trans trans; |
| 412 | int err; |
| 413 | |
| 414 | trans.ph_prepare = true; |
| 415 | err = dsa_port_vlan_add(dp, &vlan, &trans); |
Vivien Didelot | cf36086 | 2019-08-25 13:25:16 -0400 | [diff] [blame] | 416 | if (err) |
| 417 | return err; |
Vladimir Oltean | 314f76d | 2019-04-28 21:45:54 +0300 | [diff] [blame] | 418 | |
| 419 | trans.ph_prepare = false; |
| 420 | return dsa_port_vlan_add(dp, &vlan, &trans); |
| 421 | } |
Vladimir Oltean | 146c1be | 2019-05-05 13:19:21 +0300 | [diff] [blame] | 422 | EXPORT_SYMBOL(dsa_port_vid_add); |
Vladimir Oltean | 314f76d | 2019-04-28 21:45:54 +0300 | [diff] [blame] | 423 | |
| 424 | int dsa_port_vid_del(struct dsa_port *dp, u16 vid) |
| 425 | { |
| 426 | struct switchdev_obj_port_vlan vlan = { |
| 427 | .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN, |
| 428 | .vid_begin = vid, |
| 429 | .vid_end = vid, |
| 430 | }; |
| 431 | |
| 432 | return dsa_port_vlan_del(dp, &vlan); |
| 433 | } |
Vladimir Oltean | 146c1be | 2019-05-05 13:19:21 +0300 | [diff] [blame] | 434 | EXPORT_SYMBOL(dsa_port_vid_del); |
Vladimir Oltean | 314f76d | 2019-04-28 21:45:54 +0300 | [diff] [blame] | 435 | |
Florian Fainelli | 6207a78 | 2018-04-25 12:12:51 -0700 | [diff] [blame] | 436 | static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) |
| 437 | { |
| 438 | struct device_node *phy_dn; |
| 439 | struct phy_device *phydev; |
| 440 | |
| 441 | phy_dn = of_parse_phandle(dp->dn, "phy-handle", 0); |
| 442 | if (!phy_dn) |
| 443 | return NULL; |
| 444 | |
| 445 | phydev = of_phy_find_device(phy_dn); |
| 446 | if (!phydev) { |
| 447 | of_node_put(phy_dn); |
| 448 | return ERR_PTR(-EPROBE_DEFER); |
| 449 | } |
| 450 | |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 451 | of_node_put(phy_dn); |
Florian Fainelli | 6207a78 | 2018-04-25 12:12:51 -0700 | [diff] [blame] | 452 | return phydev; |
| 453 | } |
| 454 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 455 | static void dsa_port_phylink_validate(struct phylink_config *config, |
| 456 | unsigned long *supported, |
| 457 | struct phylink_link_state *state) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 458 | { |
| 459 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
| 460 | struct dsa_switch *ds = dp->ds; |
| 461 | |
| 462 | if (!ds->ops->phylink_validate) |
| 463 | return; |
| 464 | |
| 465 | ds->ops->phylink_validate(ds, dp->index, supported, state); |
| 466 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 467 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 468 | static void dsa_port_phylink_mac_pcs_get_state(struct phylink_config *config, |
| 469 | struct phylink_link_state *state) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 470 | { |
| 471 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
| 472 | struct dsa_switch *ds = dp->ds; |
Russell King | 87615c96 | 2020-03-14 10:15:28 +0000 | [diff] [blame] | 473 | int err; |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 474 | |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 475 | /* Only called for inband modes */ |
| 476 | if (!ds->ops->phylink_mac_link_state) { |
| 477 | state->link = 0; |
| 478 | return; |
| 479 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 480 | |
Russell King | 87615c96 | 2020-03-14 10:15:28 +0000 | [diff] [blame] | 481 | err = ds->ops->phylink_mac_link_state(ds, dp->index, state); |
| 482 | if (err < 0) { |
| 483 | dev_err(ds->dev, "p%d: phylink_mac_link_state() failed: %d\n", |
| 484 | dp->index, err); |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 485 | state->link = 0; |
Russell King | 87615c96 | 2020-03-14 10:15:28 +0000 | [diff] [blame] | 486 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 487 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 488 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 489 | static void dsa_port_phylink_mac_config(struct phylink_config *config, |
| 490 | unsigned int mode, |
| 491 | const struct phylink_link_state *state) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 492 | { |
| 493 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
| 494 | struct dsa_switch *ds = dp->ds; |
| 495 | |
| 496 | if (!ds->ops->phylink_mac_config) |
| 497 | return; |
| 498 | |
| 499 | ds->ops->phylink_mac_config(ds, dp->index, mode, state); |
| 500 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 501 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 502 | static void dsa_port_phylink_mac_an_restart(struct phylink_config *config) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 503 | { |
| 504 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
| 505 | struct dsa_switch *ds = dp->ds; |
| 506 | |
| 507 | if (!ds->ops->phylink_mac_an_restart) |
| 508 | return; |
| 509 | |
| 510 | ds->ops->phylink_mac_an_restart(ds, dp->index); |
| 511 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 512 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 513 | static void dsa_port_phylink_mac_link_down(struct phylink_config *config, |
| 514 | unsigned int mode, |
| 515 | phy_interface_t interface) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 516 | { |
| 517 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 518 | struct phy_device *phydev = NULL; |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 519 | struct dsa_switch *ds = dp->ds; |
| 520 | |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 521 | if (dsa_is_user_port(ds, dp->index)) |
| 522 | phydev = dp->slave->phydev; |
| 523 | |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 524 | if (!ds->ops->phylink_mac_link_down) { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 525 | if (ds->ops->adjust_link && phydev) |
| 526 | ds->ops->adjust_link(ds, dp->index, phydev); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 527 | return; |
| 528 | } |
| 529 | |
| 530 | ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface); |
| 531 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 532 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 533 | static void dsa_port_phylink_mac_link_up(struct phylink_config *config, |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 534 | struct phy_device *phydev, |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 535 | unsigned int mode, |
| 536 | phy_interface_t interface, |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 537 | int speed, int duplex, |
| 538 | bool tx_pause, bool rx_pause) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 539 | { |
| 540 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 541 | struct dsa_switch *ds = dp->ds; |
| 542 | |
| 543 | if (!ds->ops->phylink_mac_link_up) { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 544 | if (ds->ops->adjust_link && phydev) |
| 545 | ds->ops->adjust_link(ds, dp->index, phydev); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 546 | return; |
| 547 | } |
| 548 | |
Russell King | 5b502a7 | 2020-02-26 10:23:46 +0000 | [diff] [blame] | 549 | ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev, |
| 550 | speed, duplex, tx_pause, rx_pause); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 551 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 552 | |
| 553 | const struct phylink_mac_ops dsa_port_phylink_mac_ops = { |
| 554 | .validate = dsa_port_phylink_validate, |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 555 | .mac_pcs_get_state = dsa_port_phylink_mac_pcs_get_state, |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 556 | .mac_config = dsa_port_phylink_mac_config, |
| 557 | .mac_an_restart = dsa_port_phylink_mac_an_restart, |
| 558 | .mac_link_down = dsa_port_phylink_mac_link_down, |
| 559 | .mac_link_up = dsa_port_phylink_mac_link_up, |
| 560 | }; |
| 561 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 562 | static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) |
| 563 | { |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 564 | struct dsa_switch *ds = dp->ds; |
| 565 | struct phy_device *phydev; |
| 566 | int port = dp->index; |
| 567 | int err = 0; |
| 568 | |
Florian Fainelli | 6207a78 | 2018-04-25 12:12:51 -0700 | [diff] [blame] | 569 | phydev = dsa_port_get_phy_device(dp); |
| 570 | if (!phydev) |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 571 | return 0; |
| 572 | |
Florian Fainelli | 6207a78 | 2018-04-25 12:12:51 -0700 | [diff] [blame] | 573 | if (IS_ERR(phydev)) |
| 574 | return PTR_ERR(phydev); |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 575 | |
| 576 | if (enable) { |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 577 | err = genphy_resume(phydev); |
| 578 | if (err < 0) |
| 579 | goto err_put_dev; |
| 580 | |
| 581 | err = genphy_read_status(phydev); |
| 582 | if (err < 0) |
| 583 | goto err_put_dev; |
| 584 | } else { |
| 585 | err = genphy_suspend(phydev); |
| 586 | if (err < 0) |
| 587 | goto err_put_dev; |
| 588 | } |
| 589 | |
| 590 | if (ds->ops->adjust_link) |
| 591 | ds->ops->adjust_link(ds, port, phydev); |
| 592 | |
| 593 | dev_dbg(ds->dev, "enabled port's phy: %s", phydev_name(phydev)); |
| 594 | |
| 595 | err_put_dev: |
| 596 | put_device(&phydev->mdio.dev); |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 597 | return err; |
| 598 | } |
| 599 | |
| 600 | static int dsa_port_fixed_link_register_of(struct dsa_port *dp) |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 601 | { |
| 602 | struct device_node *dn = dp->dn; |
| 603 | struct dsa_switch *ds = dp->ds; |
| 604 | struct phy_device *phydev; |
| 605 | int port = dp->index; |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 606 | phy_interface_t mode; |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 607 | int err; |
| 608 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 609 | err = of_phy_register_fixed_link(dn); |
| 610 | if (err) { |
| 611 | dev_err(ds->dev, |
| 612 | "failed to register the fixed PHY of port %d\n", |
| 613 | port); |
| 614 | return err; |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 615 | } |
| 616 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 617 | phydev = of_phy_find_device(dn); |
| 618 | |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 619 | err = of_get_phy_mode(dn, &mode); |
| 620 | if (err) |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 621 | mode = PHY_INTERFACE_MODE_NA; |
| 622 | phydev->interface = mode; |
| 623 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 624 | genphy_read_status(phydev); |
| 625 | |
| 626 | if (ds->ops->adjust_link) |
| 627 | ds->ops->adjust_link(ds, port, phydev); |
| 628 | |
| 629 | put_device(&phydev->mdio.dev); |
| 630 | |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 631 | return 0; |
| 632 | } |
| 633 | |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 634 | static int dsa_port_phylink_register(struct dsa_port *dp) |
| 635 | { |
| 636 | struct dsa_switch *ds = dp->ds; |
| 637 | struct device_node *port_dn = dp->dn; |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 638 | phy_interface_t mode; |
| 639 | int err; |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 640 | |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 641 | err = of_get_phy_mode(port_dn, &mode); |
| 642 | if (err) |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 643 | mode = PHY_INTERFACE_MODE_NA; |
| 644 | |
| 645 | dp->pl_config.dev = ds->dev; |
| 646 | dp->pl_config.type = PHYLINK_DEV; |
Vladimir Oltean | 787cac3 | 2020-01-06 03:34:12 +0200 | [diff] [blame] | 647 | dp->pl_config.pcs_poll = ds->pcs_poll; |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 648 | |
| 649 | dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), |
| 650 | mode, &dsa_port_phylink_mac_ops); |
| 651 | if (IS_ERR(dp->pl)) { |
| 652 | pr_err("error creating PHYLINK: %ld\n", PTR_ERR(dp->pl)); |
| 653 | return PTR_ERR(dp->pl); |
| 654 | } |
| 655 | |
| 656 | err = phylink_of_phy_connect(dp->pl, port_dn, 0); |
Florian Fainelli | 2131fba | 2019-06-10 12:31:49 -0700 | [diff] [blame] | 657 | if (err && err != -ENODEV) { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 658 | pr_err("could not attach to PHY: %d\n", err); |
| 659 | goto err_phy_connect; |
| 660 | } |
| 661 | |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 662 | return 0; |
| 663 | |
| 664 | err_phy_connect: |
| 665 | phylink_destroy(dp->pl); |
| 666 | return err; |
| 667 | } |
| 668 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 669 | int dsa_port_link_register_of(struct dsa_port *dp) |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 670 | { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 671 | struct dsa_switch *ds = dp->ds; |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 672 | struct device_node *phy_np; |
Andrew Lunn | 3be98b2 | 2020-04-14 02:34:39 +0200 | [diff] [blame^] | 673 | int port = dp->index; |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 674 | |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 675 | if (!ds->ops->adjust_link) { |
| 676 | phy_np = of_parse_phandle(dp->dn, "phy-handle", 0); |
Andrew Lunn | 3be98b2 | 2020-04-14 02:34:39 +0200 | [diff] [blame^] | 677 | if (of_phy_is_fixed_link(dp->dn) || phy_np) { |
| 678 | if (ds->ops->phylink_mac_link_down) |
| 679 | ds->ops->phylink_mac_link_down(ds, port, |
| 680 | MLO_AN_FIXED, PHY_INTERFACE_MODE_NA); |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 681 | return dsa_port_phylink_register(dp); |
Andrew Lunn | 3be98b2 | 2020-04-14 02:34:39 +0200 | [diff] [blame^] | 682 | } |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 683 | return 0; |
| 684 | } |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 685 | |
| 686 | dev_warn(ds->dev, |
| 687 | "Using legacy PHYLIB callbacks. Please migrate to PHYLINK!\n"); |
| 688 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 689 | if (of_phy_is_fixed_link(dp->dn)) |
| 690 | return dsa_port_fixed_link_register_of(dp); |
| 691 | else |
| 692 | return dsa_port_setup_phy_of(dp, true); |
| 693 | } |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 694 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 695 | void dsa_port_link_unregister_of(struct dsa_port *dp) |
| 696 | { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 697 | struct dsa_switch *ds = dp->ds; |
| 698 | |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 699 | if (!ds->ops->adjust_link && dp->pl) { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 700 | rtnl_lock(); |
| 701 | phylink_disconnect_phy(dp->pl); |
| 702 | rtnl_unlock(); |
| 703 | phylink_destroy(dp->pl); |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 704 | dp->pl = NULL; |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 705 | return; |
| 706 | } |
| 707 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 708 | if (of_phy_is_fixed_link(dp->dn)) |
| 709 | of_phy_deregister_fixed_link(dp->dn); |
| 710 | else |
| 711 | dsa_port_setup_phy_of(dp, false); |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 712 | } |
Florian Fainelli | cf96357 | 2018-04-25 12:12:52 -0700 | [diff] [blame] | 713 | |
| 714 | int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data) |
| 715 | { |
| 716 | struct phy_device *phydev; |
| 717 | int ret = -EOPNOTSUPP; |
| 718 | |
| 719 | if (of_phy_is_fixed_link(dp->dn)) |
| 720 | return ret; |
| 721 | |
| 722 | phydev = dsa_port_get_phy_device(dp); |
| 723 | if (IS_ERR_OR_NULL(phydev)) |
| 724 | return ret; |
| 725 | |
| 726 | ret = phy_ethtool_get_strings(phydev, data); |
| 727 | put_device(&phydev->mdio.dev); |
| 728 | |
| 729 | return ret; |
| 730 | } |
| 731 | EXPORT_SYMBOL_GPL(dsa_port_get_phy_strings); |
| 732 | |
| 733 | int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data) |
| 734 | { |
| 735 | struct phy_device *phydev; |
| 736 | int ret = -EOPNOTSUPP; |
| 737 | |
| 738 | if (of_phy_is_fixed_link(dp->dn)) |
| 739 | return ret; |
| 740 | |
| 741 | phydev = dsa_port_get_phy_device(dp); |
| 742 | if (IS_ERR_OR_NULL(phydev)) |
| 743 | return ret; |
| 744 | |
| 745 | ret = phy_ethtool_get_stats(phydev, NULL, data); |
| 746 | put_device(&phydev->mdio.dev); |
| 747 | |
| 748 | return ret; |
| 749 | } |
| 750 | EXPORT_SYMBOL_GPL(dsa_port_get_ethtool_phy_stats); |
| 751 | |
| 752 | int dsa_port_get_phy_sset_count(struct dsa_port *dp) |
| 753 | { |
| 754 | struct phy_device *phydev; |
| 755 | int ret = -EOPNOTSUPP; |
| 756 | |
| 757 | if (of_phy_is_fixed_link(dp->dn)) |
| 758 | return ret; |
| 759 | |
| 760 | phydev = dsa_port_get_phy_device(dp); |
| 761 | if (IS_ERR_OR_NULL(phydev)) |
| 762 | return ret; |
| 763 | |
| 764 | ret = phy_ethtool_get_sset_count(phydev); |
| 765 | put_device(&phydev->mdio.dev); |
| 766 | |
| 767 | return ret; |
| 768 | } |
| 769 | EXPORT_SYMBOL_GPL(dsa_port_get_phy_sset_count); |