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 | |
Vladimir Oltean | 886f8e2 | 2021-01-29 03:00:04 +0200 | [diff] [blame] | 16 | /** |
| 17 | * dsa_port_notify - Notify the switching fabric of changes to a port |
| 18 | * @dp: port on which change occurred |
| 19 | * @e: event, must be of type DSA_NOTIFIER_* |
| 20 | * @v: event-specific value. |
| 21 | * |
| 22 | * Notify all switches in the DSA tree that this port's switch belongs to, |
| 23 | * including this switch itself, of an event. Allows the other switches to |
| 24 | * reconfigure themselves for cross-chip operations. Can also be used to |
| 25 | * reconfigure ports without net_devices (CPU ports, DSA links) whenever |
| 26 | * a user port's state changes. |
| 27 | */ |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 28 | 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] | 29 | { |
Vladimir Oltean | 886f8e2 | 2021-01-29 03:00:04 +0200 | [diff] [blame] | 30 | return dsa_tree_notify(dp->ds->dst, e, v); |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 33 | int dsa_port_set_state(struct dsa_port *dp, u8 state) |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 34 | { |
| 35 | struct dsa_switch *ds = dp->ds; |
| 36 | int port = dp->index; |
| 37 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 38 | if (!ds->ops->port_stp_state_set) |
| 39 | return -EOPNOTSUPP; |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 40 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 41 | ds->ops->port_stp_state_set(ds, port, state); |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 42 | |
| 43 | if (ds->ops->port_fast_age) { |
| 44 | /* Fast age FDB entries or flush appropriate forwarding database |
| 45 | * for the given port, if we are moving it from Learning or |
| 46 | * Forwarding state, to Disabled or Blocking or Listening state. |
| 47 | */ |
| 48 | |
| 49 | if ((dp->stp_state == BR_STATE_LEARNING || |
| 50 | dp->stp_state == BR_STATE_FORWARDING) && |
| 51 | (state == BR_STATE_DISABLED || |
| 52 | state == BR_STATE_BLOCKING || |
| 53 | state == BR_STATE_LISTENING)) |
| 54 | ds->ops->port_fast_age(ds, port); |
| 55 | } |
| 56 | |
| 57 | dp->stp_state = state; |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 62 | 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] | 63 | { |
| 64 | int err; |
| 65 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 66 | err = dsa_port_set_state(dp, state); |
Vivien Didelot | a40c175 | 2017-05-19 17:00:44 -0400 | [diff] [blame] | 67 | if (err) |
| 68 | pr_err("DSA: failed to set STP state %u (%d)\n", state, err); |
| 69 | } |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 70 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 71 | 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] | 72 | { |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 73 | struct dsa_switch *ds = dp->ds; |
| 74 | int port = dp->index; |
| 75 | int err; |
| 76 | |
| 77 | if (ds->ops->port_enable) { |
| 78 | err = ds->ops->port_enable(ds, port, phy); |
| 79 | if (err) |
| 80 | return err; |
| 81 | } |
| 82 | |
Russell King | 9c2054a | 2019-02-20 10:32:52 +0000 | [diff] [blame] | 83 | if (!dp->bridge_dev) |
| 84 | dsa_port_set_state_now(dp, BR_STATE_FORWARDING); |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 85 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 86 | if (dp->pl) |
| 87 | phylink_start(dp->pl); |
| 88 | |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 92 | int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy) |
| 93 | { |
| 94 | int err; |
| 95 | |
| 96 | rtnl_lock(); |
| 97 | err = dsa_port_enable_rt(dp, phy); |
| 98 | rtnl_unlock(); |
| 99 | |
| 100 | return err; |
| 101 | } |
| 102 | |
| 103 | void dsa_port_disable_rt(struct dsa_port *dp) |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 104 | { |
| 105 | struct dsa_switch *ds = dp->ds; |
| 106 | int port = dp->index; |
| 107 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 108 | if (dp->pl) |
| 109 | phylink_stop(dp->pl); |
| 110 | |
Russell King | 9c2054a | 2019-02-20 10:32:52 +0000 | [diff] [blame] | 111 | if (!dp->bridge_dev) |
| 112 | dsa_port_set_state_now(dp, BR_STATE_DISABLED); |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 113 | |
| 114 | if (ds->ops->port_disable) |
Andrew Lunn | 75104db | 2019-02-24 20:44:43 +0100 | [diff] [blame] | 115 | ds->ops->port_disable(ds, port); |
Vivien Didelot | fb8a6a2 | 2017-09-22 19:01:56 -0400 | [diff] [blame] | 116 | } |
| 117 | |
Russell King | 8640f8d | 2020-03-03 15:01:46 +0000 | [diff] [blame] | 118 | void dsa_port_disable(struct dsa_port *dp) |
| 119 | { |
| 120 | rtnl_lock(); |
| 121 | dsa_port_disable_rt(dp); |
| 122 | rtnl_unlock(); |
| 123 | } |
| 124 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 125 | static int dsa_port_inherit_brport_flags(struct dsa_port *dp, |
| 126 | struct netlink_ext_ack *extack) |
Vladimir Oltean | 5e38c15 | 2021-02-12 17:15:54 +0200 | [diff] [blame] | 127 | { |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 128 | const unsigned long mask = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | |
| 129 | BR_BCAST_FLOOD; |
| 130 | struct net_device *brport_dev = dsa_port_to_bridge_port(dp); |
| 131 | int flag, err; |
Vladimir Oltean | 5e38c15 | 2021-02-12 17:15:54 +0200 | [diff] [blame] | 132 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 133 | for_each_set_bit(flag, &mask, 32) { |
| 134 | struct switchdev_brport_flags flags = {0}; |
Vladimir Oltean | 5e38c15 | 2021-02-12 17:15:54 +0200 | [diff] [blame] | 135 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 136 | flags.mask = BIT(flag); |
Vladimir Oltean | 5e38c15 | 2021-02-12 17:15:54 +0200 | [diff] [blame] | 137 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 138 | if (br_port_flag_is_set(brport_dev, BIT(flag))) |
| 139 | flags.val = BIT(flag); |
Vladimir Oltean | e18f4c1 | 2021-02-12 17:15:55 +0200 | [diff] [blame] | 140 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 141 | err = dsa_port_bridge_flags(dp, flags, extack); |
| 142 | if (err && err != -EOPNOTSUPP) |
| 143 | return err; |
Vladimir Oltean | 5e38c15 | 2021-02-12 17:15:54 +0200 | [diff] [blame] | 144 | } |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static void dsa_port_clear_brport_flags(struct dsa_port *dp) |
| 150 | { |
| 151 | const unsigned long val = BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD; |
| 152 | const unsigned long mask = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | |
| 153 | BR_BCAST_FLOOD; |
| 154 | int flag, err; |
| 155 | |
| 156 | for_each_set_bit(flag, &mask, 32) { |
| 157 | struct switchdev_brport_flags flags = {0}; |
| 158 | |
| 159 | flags.mask = BIT(flag); |
| 160 | flags.val = val & BIT(flag); |
| 161 | |
| 162 | err = dsa_port_bridge_flags(dp, flags, NULL); |
| 163 | if (err && err != -EOPNOTSUPP) |
| 164 | dev_err(dp->ds->dev, |
| 165 | "failed to clear bridge port flag %lu: %pe\n", |
| 166 | flags.val, ERR_PTR(err)); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | static int dsa_port_switchdev_sync(struct dsa_port *dp, |
| 171 | struct netlink_ext_ack *extack) |
| 172 | { |
Vladimir Oltean | 010e269 | 2021-03-23 01:51:50 +0200 | [diff] [blame] | 173 | struct net_device *brport_dev = dsa_port_to_bridge_port(dp); |
| 174 | struct net_device *br = dp->bridge_dev; |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 175 | int err; |
| 176 | |
| 177 | err = dsa_port_inherit_brport_flags(dp, extack); |
| 178 | if (err) |
| 179 | return err; |
| 180 | |
Vladimir Oltean | 010e269 | 2021-03-23 01:51:50 +0200 | [diff] [blame] | 181 | err = dsa_port_set_state(dp, br_port_get_stp_state(brport_dev)); |
| 182 | if (err && err != -EOPNOTSUPP) |
| 183 | return err; |
| 184 | |
| 185 | err = dsa_port_vlan_filtering(dp, br_vlan_enabled(br), extack); |
| 186 | if (err && err != -EOPNOTSUPP) |
| 187 | return err; |
| 188 | |
| 189 | err = dsa_port_mrouter(dp->cpu_dp, br_multicast_router(br), extack); |
| 190 | if (err && err != -EOPNOTSUPP) |
| 191 | return err; |
| 192 | |
| 193 | err = dsa_port_ageing_time(dp, br_get_ageing_time(br)); |
| 194 | if (err && err != -EOPNOTSUPP) |
| 195 | return err; |
| 196 | |
| 197 | err = br_mdb_replay(br, brport_dev, |
| 198 | &dsa_slave_switchdev_blocking_notifier, |
| 199 | extack); |
| 200 | if (err && err != -EOPNOTSUPP) |
| 201 | return err; |
| 202 | |
| 203 | err = br_fdb_replay(br, brport_dev, &dsa_slave_switchdev_notifier); |
| 204 | if (err && err != -EOPNOTSUPP) |
| 205 | return err; |
| 206 | |
| 207 | err = br_vlan_replay(br, brport_dev, |
| 208 | &dsa_slave_switchdev_blocking_notifier, |
| 209 | extack); |
| 210 | if (err && err != -EOPNOTSUPP) |
| 211 | return err; |
| 212 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | static void dsa_port_switchdev_unsync(struct dsa_port *dp) |
| 217 | { |
| 218 | /* Configure the port for standalone mode (no address learning, |
| 219 | * flood everything). |
| 220 | * The bridge only emits SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS events |
| 221 | * when the user requests it through netlink or sysfs, but not |
| 222 | * automatically at port join or leave, so we need to handle resetting |
| 223 | * the brport flags ourselves. But we even prefer it that way, because |
| 224 | * otherwise, some setups might never get the notification they need, |
| 225 | * for example, when a port leaves a LAG that offloads the bridge, |
| 226 | * it becomes standalone, but as far as the bridge is concerned, no |
| 227 | * port ever left. |
| 228 | */ |
| 229 | dsa_port_clear_brport_flags(dp); |
| 230 | |
| 231 | /* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer, |
| 232 | * so allow it to be in BR_STATE_FORWARDING to be kept functional |
| 233 | */ |
| 234 | dsa_port_set_state_now(dp, BR_STATE_FORWARDING); |
Vladimir Oltean | 010e269 | 2021-03-23 01:51:50 +0200 | [diff] [blame] | 235 | |
| 236 | /* VLAN filtering is handled by dsa_switch_bridge_leave */ |
| 237 | |
| 238 | /* Some drivers treat the notification for having a local multicast |
| 239 | * router by allowing multicast to be flooded to the CPU, so we should |
| 240 | * allow this in standalone mode too. |
| 241 | */ |
| 242 | dsa_port_mrouter(dp->cpu_dp, true, NULL); |
| 243 | |
| 244 | /* Ageing time may be global to the switch chip, so don't change it |
| 245 | * here because we have no good reason (or value) to change it to. |
| 246 | */ |
Vladimir Oltean | 5e38c15 | 2021-02-12 17:15:54 +0200 | [diff] [blame] | 247 | } |
| 248 | |
Vladimir Oltean | 2afc526 | 2021-03-23 01:51:48 +0200 | [diff] [blame] | 249 | int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, |
| 250 | struct netlink_ext_ack *extack) |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 251 | { |
| 252 | struct dsa_notifier_bridge_info info = { |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 253 | .tree_index = dp->ds->dst->index, |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 254 | .sw_index = dp->ds->index, |
| 255 | .port = dp->index, |
| 256 | .br = br, |
| 257 | }; |
| 258 | int err; |
| 259 | |
Russell King | c138806 | 2019-02-20 15:35:06 -0800 | [diff] [blame] | 260 | /* Here the interface is already bridged. Reflect the current |
| 261 | * configuration so that drivers can program their chips accordingly. |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 262 | */ |
| 263 | dp->bridge_dev = br; |
| 264 | |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 265 | err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info); |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 266 | if (err) |
| 267 | goto out_rollback; |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 268 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 269 | err = dsa_port_switchdev_sync(dp, extack); |
| 270 | if (err) |
| 271 | goto out_rollback_unbridge; |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 272 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 273 | return 0; |
| 274 | |
| 275 | out_rollback_unbridge: |
| 276 | dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); |
| 277 | out_rollback: |
| 278 | dp->bridge_dev = NULL; |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 279 | return err; |
| 280 | } |
| 281 | |
| 282 | void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) |
| 283 | { |
| 284 | struct dsa_notifier_bridge_info info = { |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 285 | .tree_index = dp->ds->dst->index, |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 286 | .sw_index = dp->ds->index, |
| 287 | .port = dp->index, |
| 288 | .br = br, |
| 289 | }; |
| 290 | int err; |
| 291 | |
| 292 | /* Here the port is already unbridged. Reflect the current configuration |
| 293 | * so that drivers can program their chips accordingly. |
| 294 | */ |
| 295 | dp->bridge_dev = NULL; |
| 296 | |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 297 | err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 298 | if (err) |
| 299 | pr_err("DSA: failed to notify DSA_NOTIFIER_BRIDGE_LEAVE\n"); |
| 300 | |
Vladimir Oltean | 5961d6a | 2021-03-23 01:51:49 +0200 | [diff] [blame] | 301 | dsa_port_switchdev_unsync(dp); |
Vivien Didelot | cfbed32 | 2017-05-19 17:00:45 -0400 | [diff] [blame] | 302 | } |
Vivien Didelot | 4d61d30 | 2017-05-19 17:00:46 -0400 | [diff] [blame] | 303 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 304 | int dsa_port_lag_change(struct dsa_port *dp, |
| 305 | struct netdev_lag_lower_state_info *linfo) |
| 306 | { |
| 307 | struct dsa_notifier_lag_info info = { |
| 308 | .sw_index = dp->ds->index, |
| 309 | .port = dp->index, |
| 310 | }; |
| 311 | bool tx_enabled; |
| 312 | |
| 313 | if (!dp->lag_dev) |
| 314 | return 0; |
| 315 | |
| 316 | /* On statically configured aggregates (e.g. loadbalance |
| 317 | * without LACP) ports will always be tx_enabled, even if the |
| 318 | * link is down. Thus we require both link_up and tx_enabled |
| 319 | * in order to include it in the tx set. |
| 320 | */ |
| 321 | tx_enabled = linfo->link_up && linfo->tx_enabled; |
| 322 | |
| 323 | if (tx_enabled == dp->lag_tx_enabled) |
| 324 | return 0; |
| 325 | |
| 326 | dp->lag_tx_enabled = tx_enabled; |
| 327 | |
| 328 | return dsa_port_notify(dp, DSA_NOTIFIER_LAG_CHANGE, &info); |
| 329 | } |
| 330 | |
| 331 | int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag, |
Vladimir Oltean | 2afc526 | 2021-03-23 01:51:48 +0200 | [diff] [blame] | 332 | struct netdev_lag_upper_info *uinfo, |
| 333 | struct netlink_ext_ack *extack) |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 334 | { |
| 335 | struct dsa_notifier_lag_info info = { |
| 336 | .sw_index = dp->ds->index, |
| 337 | .port = dp->index, |
| 338 | .lag = lag, |
| 339 | .info = uinfo, |
| 340 | }; |
Vladimir Oltean | 185c9a7 | 2021-03-23 01:51:47 +0200 | [diff] [blame] | 341 | struct net_device *bridge_dev; |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 342 | int err; |
| 343 | |
| 344 | dsa_lag_map(dp->ds->dst, lag); |
| 345 | dp->lag_dev = lag; |
| 346 | |
| 347 | err = dsa_port_notify(dp, DSA_NOTIFIER_LAG_JOIN, &info); |
Vladimir Oltean | 185c9a7 | 2021-03-23 01:51:47 +0200 | [diff] [blame] | 348 | if (err) |
| 349 | goto err_lag_join; |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 350 | |
Vladimir Oltean | 185c9a7 | 2021-03-23 01:51:47 +0200 | [diff] [blame] | 351 | bridge_dev = netdev_master_upper_dev_get(lag); |
| 352 | if (!bridge_dev || !netif_is_bridge_master(bridge_dev)) |
| 353 | return 0; |
| 354 | |
Vladimir Oltean | 2afc526 | 2021-03-23 01:51:48 +0200 | [diff] [blame] | 355 | err = dsa_port_bridge_join(dp, bridge_dev, extack); |
Vladimir Oltean | 185c9a7 | 2021-03-23 01:51:47 +0200 | [diff] [blame] | 356 | if (err) |
| 357 | goto err_bridge_join; |
| 358 | |
| 359 | return 0; |
| 360 | |
| 361 | err_bridge_join: |
| 362 | dsa_port_notify(dp, DSA_NOTIFIER_LAG_LEAVE, &info); |
| 363 | err_lag_join: |
| 364 | dp->lag_dev = NULL; |
| 365 | dsa_lag_unmap(dp->ds->dst, lag); |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 366 | return err; |
| 367 | } |
| 368 | |
| 369 | void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag) |
| 370 | { |
| 371 | struct dsa_notifier_lag_info info = { |
| 372 | .sw_index = dp->ds->index, |
| 373 | .port = dp->index, |
| 374 | .lag = lag, |
| 375 | }; |
| 376 | int err; |
| 377 | |
| 378 | if (!dp->lag_dev) |
| 379 | return; |
| 380 | |
| 381 | /* Port might have been part of a LAG that in turn was |
| 382 | * attached to a bridge. |
| 383 | */ |
| 384 | if (dp->bridge_dev) |
| 385 | dsa_port_bridge_leave(dp, dp->bridge_dev); |
| 386 | |
| 387 | dp->lag_tx_enabled = false; |
| 388 | dp->lag_dev = NULL; |
| 389 | |
| 390 | err = dsa_port_notify(dp, DSA_NOTIFIER_LAG_LEAVE, &info); |
| 391 | if (err) |
| 392 | pr_err("DSA: failed to notify DSA_NOTIFIER_LAG_LEAVE: %d\n", |
| 393 | err); |
| 394 | |
| 395 | dsa_lag_unmap(dp->ds->dst, lag); |
| 396 | } |
| 397 | |
Vladimir Oltean | adb256e | 2020-09-21 03:10:28 +0300 | [diff] [blame] | 398 | /* Must be called under rcu_read_lock() */ |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 399 | static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 400 | bool vlan_filtering, |
| 401 | struct netlink_ext_ack *extack) |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 402 | { |
| 403 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | adb256e | 2020-09-21 03:10:28 +0300 | [diff] [blame] | 404 | int err, i; |
| 405 | |
| 406 | /* VLAN awareness was off, so the question is "can we turn it on". |
| 407 | * We may have had 8021q uppers, those need to go. Make sure we don't |
| 408 | * enter an inconsistent state: deny changing the VLAN awareness state |
| 409 | * as long as we have 8021q uppers. |
| 410 | */ |
| 411 | if (vlan_filtering && dsa_is_user_port(ds, dp->index)) { |
| 412 | struct net_device *upper_dev, *slave = dp->slave; |
| 413 | struct net_device *br = dp->bridge_dev; |
| 414 | struct list_head *iter; |
| 415 | |
| 416 | netdev_for_each_upper_dev_rcu(slave, upper_dev, iter) { |
| 417 | struct bridge_vlan_info br_info; |
| 418 | u16 vid; |
| 419 | |
| 420 | if (!is_vlan_dev(upper_dev)) |
| 421 | continue; |
| 422 | |
| 423 | vid = vlan_dev_vlan_id(upper_dev); |
| 424 | |
| 425 | /* br_vlan_get_info() returns -EINVAL or -ENOENT if the |
| 426 | * device, respectively the VID is not found, returning |
| 427 | * 0 means success, which is a failure for us here. |
| 428 | */ |
| 429 | err = br_vlan_get_info(br, vid, &br_info); |
| 430 | if (err == 0) { |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 431 | NL_SET_ERR_MSG_MOD(extack, |
| 432 | "Must first remove VLAN uppers having VIDs also present in bridge"); |
Vladimir Oltean | adb256e | 2020-09-21 03:10:28 +0300 | [diff] [blame] | 433 | return false; |
| 434 | } |
| 435 | } |
| 436 | } |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 437 | |
| 438 | if (!ds->vlan_filtering_is_global) |
| 439 | return true; |
| 440 | |
| 441 | /* For cases where enabling/disabling VLAN awareness is global to the |
| 442 | * switch, we need to handle the case where multiple bridges span |
| 443 | * different ports of the same switch device and one of them has a |
| 444 | * different setting than what is being requested. |
| 445 | */ |
| 446 | for (i = 0; i < ds->num_ports; i++) { |
| 447 | struct net_device *other_bridge; |
| 448 | |
| 449 | other_bridge = dsa_to_port(ds, i)->bridge_dev; |
| 450 | if (!other_bridge) |
| 451 | continue; |
| 452 | /* If it's the same bridge, it also has same |
| 453 | * vlan_filtering setting => no need to check |
| 454 | */ |
| 455 | if (other_bridge == dp->bridge_dev) |
| 456 | continue; |
| 457 | if (br_vlan_enabled(other_bridge) != vlan_filtering) { |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 458 | NL_SET_ERR_MSG_MOD(extack, |
| 459 | "VLAN filtering is a global setting"); |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 460 | return false; |
| 461 | } |
| 462 | } |
| 463 | return true; |
| 464 | } |
| 465 | |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 466 | int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, |
| 467 | struct netlink_ext_ack *extack) |
Vivien Didelot | 4d61d30 | 2017-05-19 17:00:46 -0400 | [diff] [blame] | 468 | { |
| 469 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 470 | bool apply; |
Vladimir Oltean | 33162e9 | 2019-04-28 21:45:43 +0300 | [diff] [blame] | 471 | int err; |
Vivien Didelot | 4d61d30 | 2017-05-19 17:00:46 -0400 | [diff] [blame] | 472 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 473 | if (!ds->ops->port_vlan_filtering) |
| 474 | return -EOPNOTSUPP; |
Vladimir Oltean | adb256e | 2020-09-21 03:10:28 +0300 | [diff] [blame] | 475 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 476 | /* We are called from dsa_slave_switchdev_blocking_event(), |
| 477 | * which is not under rcu_read_lock(), unlike |
| 478 | * dsa_slave_switchdev_event(). |
| 479 | */ |
| 480 | rcu_read_lock(); |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 481 | apply = dsa_port_can_apply_vlan_filtering(dp, vlan_filtering, extack); |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 482 | rcu_read_unlock(); |
| 483 | if (!apply) |
| 484 | return -EINVAL; |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 485 | |
Vladimir Oltean | ec9121e | 2019-04-28 21:45:51 +0300 | [diff] [blame] | 486 | if (dsa_port_is_vlan_filtering(dp) == vlan_filtering) |
| 487 | return 0; |
| 488 | |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 489 | err = ds->ops->port_vlan_filtering(ds, dp->index, vlan_filtering, |
| 490 | extack); |
Vladimir Oltean | 8f5d16f | 2019-04-28 21:45:44 +0300 | [diff] [blame] | 491 | if (err) |
| 492 | return err; |
| 493 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 494 | if (ds->vlan_filtering_is_global) |
| 495 | ds->vlan_filtering = vlan_filtering; |
| 496 | else |
| 497 | dp->vlan_filtering = vlan_filtering; |
Vladimir Oltean | 2e554a7 | 2020-10-03 01:06:46 +0300 | [diff] [blame] | 498 | |
Vivien Didelot | 4d61d30 | 2017-05-19 17:00:46 -0400 | [diff] [blame] | 499 | return 0; |
| 500 | } |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 501 | |
Russell King | 54a0ed0 | 2020-05-12 20:20:25 +0300 | [diff] [blame] | 502 | /* This enforces legacy behavior for switch drivers which assume they can't |
| 503 | * receive VLAN configuration when enslaved to a bridge with vlan_filtering=0 |
| 504 | */ |
| 505 | bool dsa_port_skip_vlan_configuration(struct dsa_port *dp) |
| 506 | { |
| 507 | struct dsa_switch *ds = dp->ds; |
| 508 | |
| 509 | if (!dp->bridge_dev) |
| 510 | return false; |
| 511 | |
| 512 | return (!ds->configure_vlan_while_not_filtering && |
| 513 | !br_vlan_enabled(dp->bridge_dev)); |
| 514 | } |
| 515 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 516 | int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock) |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 517 | { |
| 518 | unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock); |
| 519 | unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies); |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 520 | struct dsa_notifier_ageing_time_info info; |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 521 | int err; |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 522 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 523 | info.ageing_time = ageing_time; |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 524 | |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 525 | err = dsa_port_notify(dp, DSA_NOTIFIER_AGEING_TIME, &info); |
| 526 | if (err) |
| 527 | return err; |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 528 | |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 529 | dp->ageing_time = ageing_time; |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 530 | |
Vladimir Oltean | 77b6136 | 2021-01-09 02:01:51 +0200 | [diff] [blame] | 531 | return 0; |
Vivien Didelot | d87bd94 | 2017-05-19 17:00:47 -0400 | [diff] [blame] | 532 | } |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 533 | |
Vladimir Oltean | e18f4c1 | 2021-02-12 17:15:55 +0200 | [diff] [blame] | 534 | int dsa_port_pre_bridge_flags(const struct dsa_port *dp, |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 535 | struct switchdev_brport_flags flags, |
| 536 | struct netlink_ext_ack *extack) |
Florian Fainelli | ea87005 | 2019-02-20 16:58:22 -0800 | [diff] [blame] | 537 | { |
| 538 | struct dsa_switch *ds = dp->ds; |
| 539 | |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 540 | if (!ds->ops->port_pre_bridge_flags) |
Florian Fainelli | ea87005 | 2019-02-20 16:58:22 -0800 | [diff] [blame] | 541 | return -EINVAL; |
| 542 | |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 543 | return ds->ops->port_pre_bridge_flags(ds, dp->index, flags, extack); |
Florian Fainelli | ea87005 | 2019-02-20 16:58:22 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Vladimir Oltean | e18f4c1 | 2021-02-12 17:15:55 +0200 | [diff] [blame] | 546 | int dsa_port_bridge_flags(const struct dsa_port *dp, |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 547 | struct switchdev_brport_flags flags, |
| 548 | struct netlink_ext_ack *extack) |
Russell King | 5765279 | 2019-02-20 15:35:04 -0800 | [diff] [blame] | 549 | { |
| 550 | struct dsa_switch *ds = dp->ds; |
Russell King | 5765279 | 2019-02-20 15:35:04 -0800 | [diff] [blame] | 551 | |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 552 | if (!ds->ops->port_bridge_flags) |
Oleksij Rempel | 70a7c48 | 2021-04-21 15:05:40 +0200 | [diff] [blame] | 553 | return -EOPNOTSUPP; |
Russell King | 5765279 | 2019-02-20 15:35:04 -0800 | [diff] [blame] | 554 | |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 555 | return ds->ops->port_bridge_flags(ds, dp->index, flags, extack); |
Russell King | 5765279 | 2019-02-20 15:35:04 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 558 | int dsa_port_mrouter(struct dsa_port *dp, bool mrouter, |
| 559 | struct netlink_ext_ack *extack) |
Vivien Didelot | 08cc83c | 2019-07-08 23:31:13 -0400 | [diff] [blame] | 560 | { |
| 561 | struct dsa_switch *ds = dp->ds; |
Vivien Didelot | 08cc83c | 2019-07-08 23:31:13 -0400 | [diff] [blame] | 562 | |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 563 | if (!ds->ops->port_set_mrouter) |
Vladimir Oltean | bae33f2 | 2021-01-09 02:01:50 +0200 | [diff] [blame] | 564 | return -EOPNOTSUPP; |
Vivien Didelot | 08cc83c | 2019-07-08 23:31:13 -0400 | [diff] [blame] | 565 | |
Vladimir Oltean | a8b659e | 2021-02-12 17:15:56 +0200 | [diff] [blame] | 566 | return ds->ops->port_set_mrouter(ds, dp->index, mrouter, extack); |
Vivien Didelot | 08cc83c | 2019-07-08 23:31:13 -0400 | [diff] [blame] | 567 | } |
| 568 | |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 569 | int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu, |
| 570 | bool propagate_upstream) |
| 571 | { |
| 572 | struct dsa_notifier_mtu_info info = { |
| 573 | .sw_index = dp->ds->index, |
| 574 | .propagate_upstream = propagate_upstream, |
| 575 | .port = dp->index, |
| 576 | .mtu = new_mtu, |
| 577 | }; |
| 578 | |
| 579 | return dsa_port_notify(dp, DSA_NOTIFIER_MTU, &info); |
| 580 | } |
| 581 | |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 582 | int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 583 | u16 vid) |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 584 | { |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 585 | struct dsa_notifier_fdb_info info = { |
| 586 | .sw_index = dp->ds->index, |
| 587 | .port = dp->index, |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 588 | .addr = addr, |
| 589 | .vid = vid, |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 590 | }; |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 591 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 592 | return dsa_port_notify(dp, DSA_NOTIFIER_FDB_ADD, &info); |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 595 | int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 596 | u16 vid) |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 597 | { |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 598 | struct dsa_notifier_fdb_info info = { |
| 599 | .sw_index = dp->ds->index, |
| 600 | .port = dp->index, |
Arkadi Sharshevsky | 2acf4e6 | 2017-08-06 16:15:41 +0300 | [diff] [blame] | 601 | .addr = addr, |
| 602 | .vid = vid, |
| 603 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 604 | }; |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 605 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 606 | return dsa_port_notify(dp, DSA_NOTIFIER_FDB_DEL, &info); |
Vivien Didelot | d1cffff | 2017-05-19 17:00:48 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Vivien Didelot | de40fc5 | 2017-09-20 19:32:14 -0400 | [diff] [blame] | 609 | int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data) |
| 610 | { |
| 611 | struct dsa_switch *ds = dp->ds; |
| 612 | int port = dp->index; |
| 613 | |
| 614 | if (!ds->ops->port_fdb_dump) |
| 615 | return -EOPNOTSUPP; |
| 616 | |
| 617 | return ds->ops->port_fdb_dump(ds, port, cb, data); |
| 618 | } |
| 619 | |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 620 | int dsa_port_mdb_add(const struct dsa_port *dp, |
Vladimir Oltean | ffb68fc | 2021-01-09 02:01:48 +0200 | [diff] [blame] | 621 | const struct switchdev_obj_port_mdb *mdb) |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 622 | { |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 623 | struct dsa_notifier_mdb_info info = { |
| 624 | .sw_index = dp->ds->index, |
| 625 | .port = dp->index, |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 626 | .mdb = mdb, |
| 627 | }; |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 628 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 629 | return dsa_port_notify(dp, DSA_NOTIFIER_MDB_ADD, &info); |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Andrew Lunn | bb9f60317 | 2017-11-09 23:11:01 +0100 | [diff] [blame] | 632 | int dsa_port_mdb_del(const struct dsa_port *dp, |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 633 | const struct switchdev_obj_port_mdb *mdb) |
| 634 | { |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 635 | struct dsa_notifier_mdb_info info = { |
| 636 | .sw_index = dp->ds->index, |
| 637 | .port = dp->index, |
| 638 | .mdb = mdb, |
| 639 | }; |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 640 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 641 | return dsa_port_notify(dp, DSA_NOTIFIER_MDB_DEL, &info); |
Vivien Didelot | 3a9afea | 2017-05-19 17:00:49 -0400 | [diff] [blame] | 642 | } |
| 643 | |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 644 | int dsa_port_vlan_add(struct dsa_port *dp, |
Vladimir Oltean | 31046a5 | 2021-02-13 22:43:18 +0200 | [diff] [blame] | 645 | const struct switchdev_obj_port_vlan *vlan, |
| 646 | struct netlink_ext_ack *extack) |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 647 | { |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 648 | struct dsa_notifier_vlan_info info = { |
| 649 | .sw_index = dp->ds->index, |
| 650 | .port = dp->index, |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 651 | .vlan = vlan, |
Vladimir Oltean | 31046a5 | 2021-02-13 22:43:18 +0200 | [diff] [blame] | 652 | .extack = extack, |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 653 | }; |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 654 | |
Vivien Didelot | c5335d7 | 2019-08-25 13:25:18 -0400 | [diff] [blame] | 655 | return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_ADD, &info); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | int dsa_port_vlan_del(struct dsa_port *dp, |
| 659 | const struct switchdev_obj_port_vlan *vlan) |
| 660 | { |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 661 | struct dsa_notifier_vlan_info info = { |
| 662 | .sw_index = dp->ds->index, |
| 663 | .port = dp->index, |
| 664 | .vlan = vlan, |
| 665 | }; |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 666 | |
Vivien Didelot | c5335d7 | 2019-08-25 13:25:18 -0400 | [diff] [blame] | 667 | return dsa_port_notify(dp, DSA_NOTIFIER_VLAN_DEL, &info); |
Vivien Didelot | 076e713 | 2017-05-19 17:00:50 -0400 | [diff] [blame] | 668 | } |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 669 | |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 670 | int dsa_port_mrp_add(const struct dsa_port *dp, |
| 671 | const struct switchdev_obj_mrp *mrp) |
| 672 | { |
| 673 | struct dsa_notifier_mrp_info info = { |
| 674 | .sw_index = dp->ds->index, |
| 675 | .port = dp->index, |
| 676 | .mrp = mrp, |
| 677 | }; |
| 678 | |
| 679 | return dsa_port_notify(dp, DSA_NOTIFIER_MRP_ADD, &info); |
| 680 | } |
| 681 | |
| 682 | int dsa_port_mrp_del(const struct dsa_port *dp, |
| 683 | const struct switchdev_obj_mrp *mrp) |
| 684 | { |
| 685 | struct dsa_notifier_mrp_info info = { |
| 686 | .sw_index = dp->ds->index, |
| 687 | .port = dp->index, |
| 688 | .mrp = mrp, |
| 689 | }; |
| 690 | |
| 691 | return dsa_port_notify(dp, DSA_NOTIFIER_MRP_DEL, &info); |
| 692 | } |
| 693 | |
| 694 | int dsa_port_mrp_add_ring_role(const struct dsa_port *dp, |
| 695 | const struct switchdev_obj_ring_role_mrp *mrp) |
| 696 | { |
| 697 | struct dsa_notifier_mrp_ring_role_info info = { |
| 698 | .sw_index = dp->ds->index, |
| 699 | .port = dp->index, |
| 700 | .mrp = mrp, |
| 701 | }; |
| 702 | |
| 703 | return dsa_port_notify(dp, DSA_NOTIFIER_MRP_ADD_RING_ROLE, &info); |
| 704 | } |
| 705 | |
| 706 | int dsa_port_mrp_del_ring_role(const struct dsa_port *dp, |
| 707 | const struct switchdev_obj_ring_role_mrp *mrp) |
| 708 | { |
| 709 | struct dsa_notifier_mrp_ring_role_info info = { |
| 710 | .sw_index = dp->ds->index, |
| 711 | .port = dp->index, |
| 712 | .mrp = mrp, |
| 713 | }; |
| 714 | |
| 715 | return dsa_port_notify(dp, DSA_NOTIFIER_MRP_DEL_RING_ROLE, &info); |
| 716 | } |
| 717 | |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 718 | void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, |
| 719 | const struct dsa_device_ops *tag_ops) |
| 720 | { |
| 721 | cpu_dp->filter = tag_ops->filter; |
| 722 | cpu_dp->rcv = tag_ops->rcv; |
| 723 | cpu_dp->tag_ops = tag_ops; |
| 724 | } |
| 725 | |
Florian Fainelli | 6207a78 | 2018-04-25 12:12:51 -0700 | [diff] [blame] | 726 | static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) |
| 727 | { |
| 728 | struct device_node *phy_dn; |
| 729 | struct phy_device *phydev; |
| 730 | |
| 731 | phy_dn = of_parse_phandle(dp->dn, "phy-handle", 0); |
| 732 | if (!phy_dn) |
| 733 | return NULL; |
| 734 | |
| 735 | phydev = of_phy_find_device(phy_dn); |
| 736 | if (!phydev) { |
| 737 | of_node_put(phy_dn); |
| 738 | return ERR_PTR(-EPROBE_DEFER); |
| 739 | } |
| 740 | |
Wen Yang | 9919a36 | 2019-02-25 15:22:19 +0800 | [diff] [blame] | 741 | of_node_put(phy_dn); |
Florian Fainelli | 6207a78 | 2018-04-25 12:12:51 -0700 | [diff] [blame] | 742 | return phydev; |
| 743 | } |
| 744 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 745 | static void dsa_port_phylink_validate(struct phylink_config *config, |
| 746 | unsigned long *supported, |
| 747 | struct phylink_link_state *state) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 748 | { |
| 749 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
| 750 | struct dsa_switch *ds = dp->ds; |
| 751 | |
| 752 | if (!ds->ops->phylink_validate) |
| 753 | return; |
| 754 | |
| 755 | ds->ops->phylink_validate(ds, dp->index, supported, state); |
| 756 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 757 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 758 | static void dsa_port_phylink_mac_pcs_get_state(struct phylink_config *config, |
| 759 | struct phylink_link_state *state) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 760 | { |
| 761 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
| 762 | struct dsa_switch *ds = dp->ds; |
Russell King | 87615c96 | 2020-03-14 10:15:28 +0000 | [diff] [blame] | 763 | int err; |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 764 | |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 765 | /* Only called for inband modes */ |
| 766 | if (!ds->ops->phylink_mac_link_state) { |
| 767 | state->link = 0; |
| 768 | return; |
| 769 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 770 | |
Russell King | 87615c96 | 2020-03-14 10:15:28 +0000 | [diff] [blame] | 771 | err = ds->ops->phylink_mac_link_state(ds, dp->index, state); |
| 772 | if (err < 0) { |
| 773 | dev_err(ds->dev, "p%d: phylink_mac_link_state() failed: %d\n", |
| 774 | dp->index, err); |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 775 | state->link = 0; |
Russell King | 87615c96 | 2020-03-14 10:15:28 +0000 | [diff] [blame] | 776 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 777 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 778 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 779 | static void dsa_port_phylink_mac_config(struct phylink_config *config, |
| 780 | unsigned int mode, |
| 781 | const struct phylink_link_state *state) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 782 | { |
| 783 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
| 784 | struct dsa_switch *ds = dp->ds; |
| 785 | |
| 786 | if (!ds->ops->phylink_mac_config) |
| 787 | return; |
| 788 | |
| 789 | ds->ops->phylink_mac_config(ds, dp->index, mode, state); |
| 790 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 791 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 792 | static void dsa_port_phylink_mac_an_restart(struct phylink_config *config) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 793 | { |
| 794 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
| 795 | struct dsa_switch *ds = dp->ds; |
| 796 | |
| 797 | if (!ds->ops->phylink_mac_an_restart) |
| 798 | return; |
| 799 | |
| 800 | ds->ops->phylink_mac_an_restart(ds, dp->index); |
| 801 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 802 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 803 | static void dsa_port_phylink_mac_link_down(struct phylink_config *config, |
| 804 | unsigned int mode, |
| 805 | phy_interface_t interface) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 806 | { |
| 807 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 808 | struct phy_device *phydev = NULL; |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 809 | struct dsa_switch *ds = dp->ds; |
| 810 | |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 811 | if (dsa_is_user_port(ds, dp->index)) |
| 812 | phydev = dp->slave->phydev; |
| 813 | |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 814 | if (!ds->ops->phylink_mac_link_down) { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 815 | if (ds->ops->adjust_link && phydev) |
| 816 | ds->ops->adjust_link(ds, dp->index, phydev); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 817 | return; |
| 818 | } |
| 819 | |
| 820 | ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface); |
| 821 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 822 | |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 823 | static void dsa_port_phylink_mac_link_up(struct phylink_config *config, |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 824 | struct phy_device *phydev, |
Florian Fainelli | 8ae6749 | 2019-12-16 10:32:47 -0800 | [diff] [blame] | 825 | unsigned int mode, |
| 826 | phy_interface_t interface, |
Russell King | 91a208f | 2020-02-26 10:23:41 +0000 | [diff] [blame] | 827 | int speed, int duplex, |
| 828 | bool tx_pause, bool rx_pause) |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 829 | { |
| 830 | struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 831 | struct dsa_switch *ds = dp->ds; |
| 832 | |
| 833 | if (!ds->ops->phylink_mac_link_up) { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 834 | if (ds->ops->adjust_link && phydev) |
| 835 | ds->ops->adjust_link(ds, dp->index, phydev); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 836 | return; |
| 837 | } |
| 838 | |
Russell King | 5b502a7 | 2020-02-26 10:23:46 +0000 | [diff] [blame] | 839 | ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev, |
| 840 | speed, duplex, tx_pause, rx_pause); |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 841 | } |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 842 | |
| 843 | const struct phylink_mac_ops dsa_port_phylink_mac_ops = { |
| 844 | .validate = dsa_port_phylink_validate, |
Russell King | d46b7e4 | 2019-11-21 00:36:22 +0000 | [diff] [blame] | 845 | .mac_pcs_get_state = dsa_port_phylink_mac_pcs_get_state, |
Ioana Ciornei | 77373d4 | 2019-05-28 20:38:15 +0300 | [diff] [blame] | 846 | .mac_config = dsa_port_phylink_mac_config, |
| 847 | .mac_an_restart = dsa_port_phylink_mac_an_restart, |
| 848 | .mac_link_down = dsa_port_phylink_mac_link_down, |
| 849 | .mac_link_up = dsa_port_phylink_mac_link_up, |
| 850 | }; |
| 851 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 852 | static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) |
| 853 | { |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 854 | struct dsa_switch *ds = dp->ds; |
| 855 | struct phy_device *phydev; |
| 856 | int port = dp->index; |
| 857 | int err = 0; |
| 858 | |
Florian Fainelli | 6207a78 | 2018-04-25 12:12:51 -0700 | [diff] [blame] | 859 | phydev = dsa_port_get_phy_device(dp); |
| 860 | if (!phydev) |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 861 | return 0; |
| 862 | |
Florian Fainelli | 6207a78 | 2018-04-25 12:12:51 -0700 | [diff] [blame] | 863 | if (IS_ERR(phydev)) |
| 864 | return PTR_ERR(phydev); |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 865 | |
| 866 | if (enable) { |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 867 | err = genphy_resume(phydev); |
| 868 | if (err < 0) |
| 869 | goto err_put_dev; |
| 870 | |
| 871 | err = genphy_read_status(phydev); |
| 872 | if (err < 0) |
| 873 | goto err_put_dev; |
| 874 | } else { |
| 875 | err = genphy_suspend(phydev); |
| 876 | if (err < 0) |
| 877 | goto err_put_dev; |
| 878 | } |
| 879 | |
| 880 | if (ds->ops->adjust_link) |
| 881 | ds->ops->adjust_link(ds, port, phydev); |
| 882 | |
| 883 | dev_dbg(ds->dev, "enabled port's phy: %s", phydev_name(phydev)); |
| 884 | |
| 885 | err_put_dev: |
| 886 | put_device(&phydev->mdio.dev); |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 887 | return err; |
| 888 | } |
| 889 | |
| 890 | static int dsa_port_fixed_link_register_of(struct dsa_port *dp) |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 891 | { |
| 892 | struct device_node *dn = dp->dn; |
| 893 | struct dsa_switch *ds = dp->ds; |
| 894 | struct phy_device *phydev; |
| 895 | int port = dp->index; |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 896 | phy_interface_t mode; |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 897 | int err; |
| 898 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 899 | err = of_phy_register_fixed_link(dn); |
| 900 | if (err) { |
| 901 | dev_err(ds->dev, |
| 902 | "failed to register the fixed PHY of port %d\n", |
| 903 | port); |
| 904 | return err; |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 905 | } |
| 906 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 907 | phydev = of_phy_find_device(dn); |
| 908 | |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 909 | err = of_get_phy_mode(dn, &mode); |
| 910 | if (err) |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 911 | mode = PHY_INTERFACE_MODE_NA; |
| 912 | phydev->interface = mode; |
| 913 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 914 | genphy_read_status(phydev); |
| 915 | |
| 916 | if (ds->ops->adjust_link) |
| 917 | ds->ops->adjust_link(ds, port, phydev); |
| 918 | |
| 919 | put_device(&phydev->mdio.dev); |
| 920 | |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 921 | return 0; |
| 922 | } |
| 923 | |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 924 | static int dsa_port_phylink_register(struct dsa_port *dp) |
| 925 | { |
| 926 | struct dsa_switch *ds = dp->ds; |
| 927 | struct device_node *port_dn = dp->dn; |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 928 | phy_interface_t mode; |
| 929 | int err; |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 930 | |
Andrew Lunn | 0c65b2b | 2019-11-04 02:40:33 +0100 | [diff] [blame] | 931 | err = of_get_phy_mode(port_dn, &mode); |
| 932 | if (err) |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 933 | mode = PHY_INTERFACE_MODE_NA; |
| 934 | |
| 935 | dp->pl_config.dev = ds->dev; |
| 936 | dp->pl_config.type = PHYLINK_DEV; |
Vladimir Oltean | 787cac3 | 2020-01-06 03:34:12 +0200 | [diff] [blame] | 937 | dp->pl_config.pcs_poll = ds->pcs_poll; |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 938 | |
| 939 | dp->pl = phylink_create(&dp->pl_config, of_fwnode_handle(port_dn), |
| 940 | mode, &dsa_port_phylink_mac_ops); |
| 941 | if (IS_ERR(dp->pl)) { |
| 942 | pr_err("error creating PHYLINK: %ld\n", PTR_ERR(dp->pl)); |
| 943 | return PTR_ERR(dp->pl); |
| 944 | } |
| 945 | |
| 946 | err = phylink_of_phy_connect(dp->pl, port_dn, 0); |
Florian Fainelli | 2131fba | 2019-06-10 12:31:49 -0700 | [diff] [blame] | 947 | if (err && err != -ENODEV) { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 948 | pr_err("could not attach to PHY: %d\n", err); |
| 949 | goto err_phy_connect; |
| 950 | } |
| 951 | |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 952 | return 0; |
| 953 | |
| 954 | err_phy_connect: |
| 955 | phylink_destroy(dp->pl); |
| 956 | return err; |
| 957 | } |
| 958 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 959 | int dsa_port_link_register_of(struct dsa_port *dp) |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 960 | { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 961 | struct dsa_switch *ds = dp->ds; |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 962 | struct device_node *phy_np; |
Andrew Lunn | 3be98b2 | 2020-04-14 02:34:39 +0200 | [diff] [blame] | 963 | int port = dp->index; |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 964 | |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 965 | if (!ds->ops->adjust_link) { |
| 966 | phy_np = of_parse_phandle(dp->dn, "phy-handle", 0); |
Andrew Lunn | 3be98b2 | 2020-04-14 02:34:39 +0200 | [diff] [blame] | 967 | if (of_phy_is_fixed_link(dp->dn) || phy_np) { |
| 968 | if (ds->ops->phylink_mac_link_down) |
| 969 | ds->ops->phylink_mac_link_down(ds, port, |
| 970 | MLO_AN_FIXED, PHY_INTERFACE_MODE_NA); |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 971 | return dsa_port_phylink_register(dp); |
Andrew Lunn | 3be98b2 | 2020-04-14 02:34:39 +0200 | [diff] [blame] | 972 | } |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 973 | return 0; |
| 974 | } |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 975 | |
| 976 | dev_warn(ds->dev, |
| 977 | "Using legacy PHYLIB callbacks. Please migrate to PHYLINK!\n"); |
| 978 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 979 | if (of_phy_is_fixed_link(dp->dn)) |
| 980 | return dsa_port_fixed_link_register_of(dp); |
| 981 | else |
| 982 | return dsa_port_setup_phy_of(dp, true); |
| 983 | } |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 984 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 985 | void dsa_port_link_unregister_of(struct dsa_port *dp) |
| 986 | { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 987 | struct dsa_switch *ds = dp->ds; |
| 988 | |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 989 | if (!ds->ops->adjust_link && dp->pl) { |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 990 | rtnl_lock(); |
| 991 | phylink_disconnect_phy(dp->pl); |
| 992 | rtnl_unlock(); |
| 993 | phylink_destroy(dp->pl); |
Andrew Lunn | a20f997 | 2020-03-11 16:24:24 +0100 | [diff] [blame] | 994 | dp->pl = NULL; |
Ioana Ciornei | 0e27921 | 2019-05-28 20:38:16 +0300 | [diff] [blame] | 995 | return; |
| 996 | } |
| 997 | |
Sebastian Reichel | 3361536 | 2018-01-23 16:03:46 +0100 | [diff] [blame] | 998 | if (of_phy_is_fixed_link(dp->dn)) |
| 999 | of_phy_deregister_fixed_link(dp->dn); |
| 1000 | else |
| 1001 | dsa_port_setup_phy_of(dp, false); |
Vivien Didelot | 57ab1ca | 2017-10-26 10:50:07 -0400 | [diff] [blame] | 1002 | } |
Florian Fainelli | cf96357 | 2018-04-25 12:12:52 -0700 | [diff] [blame] | 1003 | |
| 1004 | int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data) |
| 1005 | { |
| 1006 | struct phy_device *phydev; |
| 1007 | int ret = -EOPNOTSUPP; |
| 1008 | |
| 1009 | if (of_phy_is_fixed_link(dp->dn)) |
| 1010 | return ret; |
| 1011 | |
| 1012 | phydev = dsa_port_get_phy_device(dp); |
| 1013 | if (IS_ERR_OR_NULL(phydev)) |
| 1014 | return ret; |
| 1015 | |
| 1016 | ret = phy_ethtool_get_strings(phydev, data); |
| 1017 | put_device(&phydev->mdio.dev); |
| 1018 | |
| 1019 | return ret; |
| 1020 | } |
| 1021 | EXPORT_SYMBOL_GPL(dsa_port_get_phy_strings); |
| 1022 | |
| 1023 | int dsa_port_get_ethtool_phy_stats(struct dsa_port *dp, uint64_t *data) |
| 1024 | { |
| 1025 | struct phy_device *phydev; |
| 1026 | int ret = -EOPNOTSUPP; |
| 1027 | |
| 1028 | if (of_phy_is_fixed_link(dp->dn)) |
| 1029 | return ret; |
| 1030 | |
| 1031 | phydev = dsa_port_get_phy_device(dp); |
| 1032 | if (IS_ERR_OR_NULL(phydev)) |
| 1033 | return ret; |
| 1034 | |
| 1035 | ret = phy_ethtool_get_stats(phydev, NULL, data); |
| 1036 | put_device(&phydev->mdio.dev); |
| 1037 | |
| 1038 | return ret; |
| 1039 | } |
| 1040 | EXPORT_SYMBOL_GPL(dsa_port_get_ethtool_phy_stats); |
| 1041 | |
| 1042 | int dsa_port_get_phy_sset_count(struct dsa_port *dp) |
| 1043 | { |
| 1044 | struct phy_device *phydev; |
| 1045 | int ret = -EOPNOTSUPP; |
| 1046 | |
| 1047 | if (of_phy_is_fixed_link(dp->dn)) |
| 1048 | return ret; |
| 1049 | |
| 1050 | phydev = dsa_port_get_phy_device(dp); |
| 1051 | if (IS_ERR_OR_NULL(phydev)) |
| 1052 | return ret; |
| 1053 | |
| 1054 | ret = phy_ethtool_get_sset_count(phydev); |
| 1055 | put_device(&phydev->mdio.dev); |
| 1056 | |
| 1057 | return ret; |
| 1058 | } |
| 1059 | EXPORT_SYMBOL_GPL(dsa_port_get_phy_sset_count); |
George McCollister | 18596f5 | 2021-02-09 19:02:12 -0600 | [diff] [blame] | 1060 | |
| 1061 | int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr) |
| 1062 | { |
| 1063 | struct dsa_notifier_hsr_info info = { |
| 1064 | .sw_index = dp->ds->index, |
| 1065 | .port = dp->index, |
| 1066 | .hsr = hsr, |
| 1067 | }; |
| 1068 | int err; |
| 1069 | |
| 1070 | dp->hsr_dev = hsr; |
| 1071 | |
| 1072 | err = dsa_port_notify(dp, DSA_NOTIFIER_HSR_JOIN, &info); |
| 1073 | if (err) |
| 1074 | dp->hsr_dev = NULL; |
| 1075 | |
| 1076 | return err; |
| 1077 | } |
| 1078 | |
| 1079 | void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr) |
| 1080 | { |
| 1081 | struct dsa_notifier_hsr_info info = { |
| 1082 | .sw_index = dp->ds->index, |
| 1083 | .port = dp->index, |
| 1084 | .hsr = hsr, |
| 1085 | }; |
| 1086 | int err; |
| 1087 | |
| 1088 | dp->hsr_dev = NULL; |
| 1089 | |
| 1090 | err = dsa_port_notify(dp, DSA_NOTIFIER_HSR_LEAVE, &info); |
| 1091 | if (err) |
| 1092 | pr_err("DSA: failed to notify DSA_NOTIFIER_HSR_LEAVE\n"); |
| 1093 | } |