Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Handling of a single switch chip, part of a switch fabric |
| 4 | * |
Vivien Didelot | 4333d61 | 2017-03-28 15:10:36 -0400 | [diff] [blame] | 5 | * Copyright (c) 2017 Savoir-faire Linux Inc. |
| 6 | * Vivien Didelot <vivien.didelot@savoirfairelinux.com> |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
Vladimir Oltean | d371b7c | 2019-04-28 21:45:46 +0300 | [diff] [blame] | 9 | #include <linux/if_bridge.h> |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 10 | #include <linux/netdevice.h> |
| 11 | #include <linux/notifier.h> |
Florian Fainelli | 061f6a5 | 2019-02-20 14:35:39 -0800 | [diff] [blame] | 12 | #include <linux/if_vlan.h> |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 13 | #include <net/switchdev.h> |
Vivien Didelot | ea5dd34 | 2017-05-17 15:46:03 -0400 | [diff] [blame] | 14 | |
| 15 | #include "dsa_priv.h" |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 16 | |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 17 | static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds, |
| 18 | unsigned int ageing_time) |
| 19 | { |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 20 | struct dsa_port *dp; |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 21 | |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 22 | dsa_switch_for_each_port(dp, ds) |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 23 | if (dp->ageing_time && dp->ageing_time < ageing_time) |
| 24 | ageing_time = dp->ageing_time; |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 25 | |
| 26 | return ageing_time; |
| 27 | } |
| 28 | |
| 29 | static int dsa_switch_ageing_time(struct dsa_switch *ds, |
| 30 | struct dsa_notifier_ageing_time_info *info) |
| 31 | { |
| 32 | unsigned int ageing_time = info->ageing_time; |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 33 | |
Vladimir Oltean | 77b6136 | 2021-01-09 02:01:51 +0200 | [diff] [blame] | 34 | if (ds->ageing_time_min && ageing_time < ds->ageing_time_min) |
| 35 | return -ERANGE; |
| 36 | |
| 37 | if (ds->ageing_time_max && ageing_time > ds->ageing_time_max) |
| 38 | return -ERANGE; |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 39 | |
| 40 | /* Program the fastest ageing time in case of multiple bridges */ |
| 41 | ageing_time = dsa_switch_fastest_ageing_time(ds, ageing_time); |
| 42 | |
| 43 | if (ds->ops->set_ageing_time) |
| 44 | return ds->ops->set_ageing_time(ds, ageing_time); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 49 | static bool dsa_port_mtu_match(struct dsa_port *dp, |
| 50 | struct dsa_notifier_mtu_info *info) |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 51 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 52 | if (dp->ds->index == info->sw_index && dp->index == info->port) |
Vladimir Oltean | 88faba2 | 2021-06-21 19:42:18 +0300 | [diff] [blame] | 53 | return true; |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 54 | |
Vladimir Oltean | 88faba2 | 2021-06-21 19:42:18 +0300 | [diff] [blame] | 55 | /* Do not propagate to other switches in the tree if the notifier was |
| 56 | * targeted for a single switch. |
| 57 | */ |
| 58 | if (info->targeted_match) |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 59 | return false; |
| 60 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 61 | if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 62 | return true; |
| 63 | |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | static int dsa_switch_mtu(struct dsa_switch *ds, |
| 68 | struct dsa_notifier_mtu_info *info) |
| 69 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 70 | struct dsa_port *dp; |
| 71 | int ret; |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 72 | |
| 73 | if (!ds->ops->port_change_mtu) |
| 74 | return -EOPNOTSUPP; |
| 75 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 76 | dsa_switch_for_each_port(dp, ds) { |
| 77 | if (dsa_port_mtu_match(dp, info)) { |
| 78 | ret = ds->ops->port_change_mtu(ds, dp->index, |
| 79 | info->mtu); |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 80 | if (ret) |
| 81 | return ret; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 88 | static int dsa_switch_bridge_join(struct dsa_switch *ds, |
| 89 | struct dsa_notifier_bridge_info *info) |
| 90 | { |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 91 | struct dsa_switch_tree *dst = ds->dst; |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 92 | int err; |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 93 | |
Vladimir Oltean | 67b5fb5 | 2021-08-24 00:22:56 +0300 | [diff] [blame] | 94 | if (dst->index == info->tree_index && ds->index == info->sw_index) { |
| 95 | if (!ds->ops->port_bridge_join) |
| 96 | return -EOPNOTSUPP; |
| 97 | |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 98 | err = ds->ops->port_bridge_join(ds, info->port, info->br); |
| 99 | if (err) |
| 100 | return err; |
| 101 | } |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 102 | |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 103 | if ((dst->index != info->tree_index || ds->index != info->sw_index) && |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 104 | ds->ops->crosschip_bridge_join) { |
| 105 | err = ds->ops->crosschip_bridge_join(ds, info->tree_index, |
| 106 | info->sw_index, |
| 107 | info->port, info->br); |
| 108 | if (err) |
| 109 | return err; |
| 110 | } |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 111 | |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 112 | return dsa_tag_8021q_bridge_join(ds, info); |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static int dsa_switch_bridge_leave(struct dsa_switch *ds, |
| 116 | struct dsa_notifier_bridge_info *info) |
| 117 | { |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 118 | struct dsa_switch_tree *dst = ds->dst; |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 119 | struct netlink_ext_ack extack = {0}; |
Vladimir Oltean | 58adf9d | 2021-08-24 00:22:58 +0300 | [diff] [blame] | 120 | bool change_vlan_filtering = false; |
| 121 | bool vlan_filtering; |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 122 | struct dsa_port *dp; |
| 123 | int err; |
Vladimir Oltean | d371b7c | 2019-04-28 21:45:46 +0300 | [diff] [blame] | 124 | |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 125 | if (dst->index == info->tree_index && ds->index == info->sw_index && |
Vladimir Oltean | bcb9928 | 2021-07-13 12:40:21 +0300 | [diff] [blame] | 126 | ds->ops->port_bridge_leave) |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 127 | ds->ops->port_bridge_leave(ds, info->port, info->br); |
| 128 | |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 129 | if ((dst->index != info->tree_index || ds->index != info->sw_index) && |
Vladimir Oltean | bcb9928 | 2021-07-13 12:40:21 +0300 | [diff] [blame] | 130 | ds->ops->crosschip_bridge_leave) |
Vladimir Oltean | f66a6a6 | 2020-05-10 19:37:41 +0300 | [diff] [blame] | 131 | ds->ops->crosschip_bridge_leave(ds, info->tree_index, |
| 132 | info->sw_index, info->port, |
Vivien Didelot | 40ef2c9 | 2017-03-30 17:37:14 -0400 | [diff] [blame] | 133 | info->br); |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 134 | |
Vladimir Oltean | 58adf9d | 2021-08-24 00:22:58 +0300 | [diff] [blame] | 135 | if (ds->needs_standalone_vlan_filtering && !br_vlan_enabled(info->br)) { |
| 136 | change_vlan_filtering = true; |
| 137 | vlan_filtering = true; |
| 138 | } else if (!ds->needs_standalone_vlan_filtering && |
| 139 | br_vlan_enabled(info->br)) { |
| 140 | change_vlan_filtering = true; |
| 141 | vlan_filtering = false; |
| 142 | } |
| 143 | |
Vladimir Oltean | d371b7c | 2019-04-28 21:45:46 +0300 | [diff] [blame] | 144 | /* If the bridge was vlan_filtering, the bridge core doesn't trigger an |
| 145 | * event for changing vlan_filtering setting upon slave ports leaving |
| 146 | * it. That is a good thing, because that lets us handle it and also |
| 147 | * handle the case where the switch's vlan_filtering setting is global |
| 148 | * (not per port). When that happens, the correct moment to trigger the |
Vladimir Oltean | 479dc49 | 2021-03-24 11:56:39 +0200 | [diff] [blame] | 149 | * vlan_filtering callback is only when the last port leaves the last |
| 150 | * VLAN-aware bridge. |
Vladimir Oltean | d371b7c | 2019-04-28 21:45:46 +0300 | [diff] [blame] | 151 | */ |
Vladimir Oltean | 58adf9d | 2021-08-24 00:22:58 +0300 | [diff] [blame] | 152 | if (change_vlan_filtering && ds->vlan_filtering_is_global) { |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 153 | dsa_switch_for_each_port(dp, ds) { |
Vladimir Oltean | 479dc49 | 2021-03-24 11:56:39 +0200 | [diff] [blame] | 154 | struct net_device *bridge_dev; |
| 155 | |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 156 | bridge_dev = dp->bridge_dev; |
Vladimir Oltean | 479dc49 | 2021-03-24 11:56:39 +0200 | [diff] [blame] | 157 | |
| 158 | if (bridge_dev && br_vlan_enabled(bridge_dev)) { |
Vladimir Oltean | 58adf9d | 2021-08-24 00:22:58 +0300 | [diff] [blame] | 159 | change_vlan_filtering = false; |
Vladimir Oltean | d371b7c | 2019-04-28 21:45:46 +0300 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | } |
| 163 | } |
Vladimir Oltean | 58adf9d | 2021-08-24 00:22:58 +0300 | [diff] [blame] | 164 | |
| 165 | if (change_vlan_filtering) { |
Vladimir Oltean | 2e554a7 | 2020-10-03 01:06:46 +0300 | [diff] [blame] | 166 | err = dsa_port_vlan_filtering(dsa_to_port(ds, info->port), |
Vladimir Oltean | 58adf9d | 2021-08-24 00:22:58 +0300 | [diff] [blame] | 167 | vlan_filtering, &extack); |
Vladimir Oltean | 89153ed | 2021-02-13 22:43:19 +0200 | [diff] [blame] | 168 | if (extack._msg) |
| 169 | dev_err(ds->dev, "port %d: %s\n", info->port, |
| 170 | extack._msg); |
Alvin Å ipraga | 43a4b4d | 2021-10-12 13:27:31 +0200 | [diff] [blame] | 171 | if (err && err != -EOPNOTSUPP) |
Vladimir Oltean | d371b7c | 2019-04-28 21:45:46 +0300 | [diff] [blame] | 172 | return err; |
| 173 | } |
Vladimir Oltean | e19cc13 | 2021-07-19 20:14:51 +0300 | [diff] [blame] | 174 | |
| 175 | return dsa_tag_8021q_bridge_leave(ds, info); |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 176 | } |
| 177 | |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 178 | /* Matches for all upstream-facing ports (the CPU port and all upstream-facing |
| 179 | * DSA links) that sit between the targeted port on which the notifier was |
| 180 | * emitted and its dedicated CPU port. |
| 181 | */ |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 182 | static bool dsa_port_host_address_match(struct dsa_port *dp, |
| 183 | int info_sw_index, int info_port) |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 184 | { |
| 185 | struct dsa_port *targeted_dp, *cpu_dp; |
| 186 | struct dsa_switch *targeted_ds; |
| 187 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 188 | targeted_ds = dsa_switch_find(dp->ds->dst->index, info_sw_index); |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 189 | targeted_dp = dsa_to_port(targeted_ds, info_port); |
| 190 | cpu_dp = targeted_dp->cpu_dp; |
| 191 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 192 | if (dsa_switch_is_upstream_of(dp->ds, targeted_ds)) |
| 193 | return dp->index == dsa_towards_port(dp->ds, cpu_dp->ds->index, |
| 194 | cpu_dp->index); |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 195 | |
| 196 | return false; |
| 197 | } |
| 198 | |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 199 | static struct dsa_mac_addr *dsa_mac_addr_find(struct list_head *addr_list, |
| 200 | const unsigned char *addr, |
| 201 | u16 vid) |
| 202 | { |
| 203 | struct dsa_mac_addr *a; |
| 204 | |
| 205 | list_for_each_entry(a, addr_list, list) |
| 206 | if (ether_addr_equal(a->addr, addr) && a->vid == vid) |
| 207 | return a; |
| 208 | |
| 209 | return NULL; |
| 210 | } |
| 211 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 212 | static int dsa_port_do_mdb_add(struct dsa_port *dp, |
| 213 | const struct switchdev_obj_port_mdb *mdb) |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 214 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 215 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 216 | struct dsa_mac_addr *a; |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 217 | int port = dp->index; |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 218 | int err = 0; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 219 | |
| 220 | /* No need to bother with refcounting for user ports */ |
| 221 | if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) |
| 222 | return ds->ops->port_mdb_add(ds, port, mdb); |
| 223 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 224 | mutex_lock(&dp->addr_lists_lock); |
| 225 | |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 226 | a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid); |
| 227 | if (a) { |
| 228 | refcount_inc(&a->refcount); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 229 | goto out; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | a = kzalloc(sizeof(*a), GFP_KERNEL); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 233 | if (!a) { |
| 234 | err = -ENOMEM; |
| 235 | goto out; |
| 236 | } |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 237 | |
| 238 | err = ds->ops->port_mdb_add(ds, port, mdb); |
| 239 | if (err) { |
| 240 | kfree(a); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 241 | goto out; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | ether_addr_copy(a->addr, mdb->addr); |
| 245 | a->vid = mdb->vid; |
| 246 | refcount_set(&a->refcount, 1); |
| 247 | list_add_tail(&a->list, &dp->mdbs); |
| 248 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 249 | out: |
| 250 | mutex_unlock(&dp->addr_lists_lock); |
| 251 | |
| 252 | return err; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 253 | } |
| 254 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 255 | static int dsa_port_do_mdb_del(struct dsa_port *dp, |
| 256 | const struct switchdev_obj_port_mdb *mdb) |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 257 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 258 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 259 | struct dsa_mac_addr *a; |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 260 | int port = dp->index; |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 261 | int err = 0; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 262 | |
| 263 | /* No need to bother with refcounting for user ports */ |
| 264 | if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) |
| 265 | return ds->ops->port_mdb_del(ds, port, mdb); |
| 266 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 267 | mutex_lock(&dp->addr_lists_lock); |
| 268 | |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 269 | a = dsa_mac_addr_find(&dp->mdbs, mdb->addr, mdb->vid); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 270 | if (!a) { |
| 271 | err = -ENOENT; |
| 272 | goto out; |
| 273 | } |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 274 | |
| 275 | if (!refcount_dec_and_test(&a->refcount)) |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 276 | goto out; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 277 | |
| 278 | err = ds->ops->port_mdb_del(ds, port, mdb); |
| 279 | if (err) { |
Vladimir Oltean | 232deb3 | 2021-10-24 20:17:48 +0300 | [diff] [blame] | 280 | refcount_set(&a->refcount, 1); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 281 | goto out; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | list_del(&a->list); |
| 285 | kfree(a); |
| 286 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 287 | out: |
| 288 | mutex_unlock(&dp->addr_lists_lock); |
| 289 | |
| 290 | return err; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 291 | } |
| 292 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 293 | static int dsa_port_do_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 294 | u16 vid) |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 295 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 296 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 297 | struct dsa_mac_addr *a; |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 298 | int port = dp->index; |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 299 | int err = 0; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 300 | |
| 301 | /* No need to bother with refcounting for user ports */ |
| 302 | if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) |
| 303 | return ds->ops->port_fdb_add(ds, port, addr, vid); |
| 304 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 305 | mutex_lock(&dp->addr_lists_lock); |
| 306 | |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 307 | a = dsa_mac_addr_find(&dp->fdbs, addr, vid); |
| 308 | if (a) { |
| 309 | refcount_inc(&a->refcount); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 310 | goto out; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | a = kzalloc(sizeof(*a), GFP_KERNEL); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 314 | if (!a) { |
| 315 | err = -ENOMEM; |
| 316 | goto out; |
| 317 | } |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 318 | |
| 319 | err = ds->ops->port_fdb_add(ds, port, addr, vid); |
| 320 | if (err) { |
| 321 | kfree(a); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 322 | goto out; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | ether_addr_copy(a->addr, addr); |
| 326 | a->vid = vid; |
| 327 | refcount_set(&a->refcount, 1); |
| 328 | list_add_tail(&a->list, &dp->fdbs); |
| 329 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 330 | out: |
| 331 | mutex_unlock(&dp->addr_lists_lock); |
| 332 | |
| 333 | return err; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 334 | } |
| 335 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 336 | static int dsa_port_do_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 337 | u16 vid) |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 338 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 339 | struct dsa_switch *ds = dp->ds; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 340 | struct dsa_mac_addr *a; |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 341 | int port = dp->index; |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 342 | int err = 0; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 343 | |
| 344 | /* No need to bother with refcounting for user ports */ |
| 345 | if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) |
| 346 | return ds->ops->port_fdb_del(ds, port, addr, vid); |
| 347 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 348 | mutex_lock(&dp->addr_lists_lock); |
| 349 | |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 350 | a = dsa_mac_addr_find(&dp->fdbs, addr, vid); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 351 | if (!a) { |
| 352 | err = -ENOENT; |
| 353 | goto out; |
| 354 | } |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 355 | |
| 356 | if (!refcount_dec_and_test(&a->refcount)) |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 357 | goto out; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 358 | |
| 359 | err = ds->ops->port_fdb_del(ds, port, addr, vid); |
| 360 | if (err) { |
Vladimir Oltean | 232deb3 | 2021-10-24 20:17:48 +0300 | [diff] [blame] | 361 | refcount_set(&a->refcount, 1); |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 362 | goto out; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | list_del(&a->list); |
| 366 | kfree(a); |
| 367 | |
Vladimir Oltean | 338a3a47 | 2021-10-24 20:17:54 +0300 | [diff] [blame] | 368 | out: |
| 369 | mutex_unlock(&dp->addr_lists_lock); |
| 370 | |
| 371 | return err; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 372 | } |
| 373 | |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 374 | static int dsa_switch_host_fdb_add(struct dsa_switch *ds, |
| 375 | struct dsa_notifier_fdb_info *info) |
| 376 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 377 | struct dsa_port *dp; |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 378 | int err = 0; |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 379 | |
| 380 | if (!ds->ops->port_fdb_add) |
| 381 | return -EOPNOTSUPP; |
| 382 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 383 | dsa_switch_for_each_port(dp, ds) { |
| 384 | if (dsa_port_host_address_match(dp, info->sw_index, |
| 385 | info->port)) { |
| 386 | err = dsa_port_do_fdb_add(dp, info->addr, info->vid); |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 387 | if (err) |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | return err; |
| 393 | } |
| 394 | |
| 395 | static int dsa_switch_host_fdb_del(struct dsa_switch *ds, |
| 396 | struct dsa_notifier_fdb_info *info) |
| 397 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 398 | struct dsa_port *dp; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 399 | int err = 0; |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 400 | |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 401 | if (!ds->ops->port_fdb_del) |
| 402 | return -EOPNOTSUPP; |
| 403 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 404 | dsa_switch_for_each_port(dp, ds) { |
| 405 | if (dsa_port_host_address_match(dp, info->sw_index, |
| 406 | info->port)) { |
| 407 | err = dsa_port_do_fdb_del(dp, info->addr, info->vid); |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 408 | if (err) |
| 409 | break; |
| 410 | } |
| 411 | } |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 412 | |
Vladimir Oltean | 3f6e32f | 2021-06-29 17:06:52 +0300 | [diff] [blame] | 413 | return err; |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 414 | } |
| 415 | |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 416 | static int dsa_switch_fdb_add(struct dsa_switch *ds, |
| 417 | struct dsa_notifier_fdb_info *info) |
| 418 | { |
Vivien Didelot | 3169241 | 2017-11-30 12:56:43 -0500 | [diff] [blame] | 419 | int port = dsa_towards_port(ds, info->sw_index, info->port); |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 420 | struct dsa_port *dp = dsa_to_port(ds, port); |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 421 | |
Arkadi Sharshevsky | 1b6dd55 | 2017-08-06 16:15:40 +0300 | [diff] [blame] | 422 | if (!ds->ops->port_fdb_add) |
| 423 | return -EOPNOTSUPP; |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 424 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 425 | return dsa_port_do_fdb_add(dp, info->addr, info->vid); |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static int dsa_switch_fdb_del(struct dsa_switch *ds, |
| 429 | struct dsa_notifier_fdb_info *info) |
| 430 | { |
Vivien Didelot | 3169241 | 2017-11-30 12:56:43 -0500 | [diff] [blame] | 431 | int port = dsa_towards_port(ds, info->sw_index, info->port); |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 432 | struct dsa_port *dp = dsa_to_port(ds, port); |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 433 | |
| 434 | if (!ds->ops->port_fdb_del) |
| 435 | return -EOPNOTSUPP; |
| 436 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 437 | return dsa_port_do_fdb_del(dp, info->addr, info->vid); |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 438 | } |
| 439 | |
George McCollister | 18596f5 | 2021-02-09 19:02:12 -0600 | [diff] [blame] | 440 | static int dsa_switch_hsr_join(struct dsa_switch *ds, |
| 441 | struct dsa_notifier_hsr_info *info) |
| 442 | { |
| 443 | if (ds->index == info->sw_index && ds->ops->port_hsr_join) |
| 444 | return ds->ops->port_hsr_join(ds, info->port, info->hsr); |
| 445 | |
| 446 | return -EOPNOTSUPP; |
| 447 | } |
| 448 | |
| 449 | static int dsa_switch_hsr_leave(struct dsa_switch *ds, |
| 450 | struct dsa_notifier_hsr_info *info) |
| 451 | { |
| 452 | if (ds->index == info->sw_index && ds->ops->port_hsr_leave) |
| 453 | return ds->ops->port_hsr_leave(ds, info->port, info->hsr); |
| 454 | |
| 455 | return -EOPNOTSUPP; |
| 456 | } |
| 457 | |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 458 | static int dsa_switch_lag_change(struct dsa_switch *ds, |
| 459 | struct dsa_notifier_lag_info *info) |
| 460 | { |
| 461 | if (ds->index == info->sw_index && ds->ops->port_lag_change) |
| 462 | return ds->ops->port_lag_change(ds, info->port); |
| 463 | |
| 464 | if (ds->index != info->sw_index && ds->ops->crosschip_lag_change) |
| 465 | return ds->ops->crosschip_lag_change(ds, info->sw_index, |
| 466 | info->port); |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static int dsa_switch_lag_join(struct dsa_switch *ds, |
| 472 | struct dsa_notifier_lag_info *info) |
| 473 | { |
| 474 | if (ds->index == info->sw_index && ds->ops->port_lag_join) |
| 475 | return ds->ops->port_lag_join(ds, info->port, info->lag, |
| 476 | info->info); |
| 477 | |
| 478 | if (ds->index != info->sw_index && ds->ops->crosschip_lag_join) |
| 479 | return ds->ops->crosschip_lag_join(ds, info->sw_index, |
| 480 | info->port, info->lag, |
| 481 | info->info); |
| 482 | |
Vladimir Oltean | b71d098 | 2021-06-29 23:32:15 +0300 | [diff] [blame] | 483 | return -EOPNOTSUPP; |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static int dsa_switch_lag_leave(struct dsa_switch *ds, |
| 487 | struct dsa_notifier_lag_info *info) |
| 488 | { |
| 489 | if (ds->index == info->sw_index && ds->ops->port_lag_leave) |
| 490 | return ds->ops->port_lag_leave(ds, info->port, info->lag); |
| 491 | |
| 492 | if (ds->index != info->sw_index && ds->ops->crosschip_lag_leave) |
| 493 | return ds->ops->crosschip_lag_leave(ds, info->sw_index, |
| 494 | info->port, info->lag); |
| 495 | |
Vladimir Oltean | b71d098 | 2021-06-29 23:32:15 +0300 | [diff] [blame] | 496 | return -EOPNOTSUPP; |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Vladimir Oltean | ffb68fc | 2021-01-09 02:01:48 +0200 | [diff] [blame] | 499 | static int dsa_switch_mdb_add(struct dsa_switch *ds, |
| 500 | struct dsa_notifier_mdb_info *info) |
Vivien Didelot | e6db98d | 2017-11-30 11:24:00 -0500 | [diff] [blame] | 501 | { |
Vladimir Oltean | abd4953 | 2021-06-21 19:42:16 +0300 | [diff] [blame] | 502 | int port = dsa_towards_port(ds, info->sw_index, info->port); |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 503 | struct dsa_port *dp = dsa_to_port(ds, port); |
Vivien Didelot | e6db98d | 2017-11-30 11:24:00 -0500 | [diff] [blame] | 504 | |
Vladimir Oltean | a52b2da | 2021-01-09 02:01:52 +0200 | [diff] [blame] | 505 | if (!ds->ops->port_mdb_add) |
Vivien Didelot | e6db98d | 2017-11-30 11:24:00 -0500 | [diff] [blame] | 506 | return -EOPNOTSUPP; |
| 507 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 508 | return dsa_port_do_mdb_add(dp, info->mdb); |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static int dsa_switch_mdb_del(struct dsa_switch *ds, |
| 512 | struct dsa_notifier_mdb_info *info) |
| 513 | { |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 514 | int port = dsa_towards_port(ds, info->sw_index, info->port); |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 515 | struct dsa_port *dp = dsa_to_port(ds, port); |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 516 | |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 517 | if (!ds->ops->port_mdb_del) |
| 518 | return -EOPNOTSUPP; |
| 519 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 520 | return dsa_port_do_mdb_del(dp, info->mdb); |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 521 | } |
| 522 | |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 523 | static int dsa_switch_host_mdb_add(struct dsa_switch *ds, |
| 524 | struct dsa_notifier_mdb_info *info) |
| 525 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 526 | struct dsa_port *dp; |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 527 | int err = 0; |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 528 | |
| 529 | if (!ds->ops->port_mdb_add) |
| 530 | return -EOPNOTSUPP; |
| 531 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 532 | dsa_switch_for_each_port(dp, ds) { |
| 533 | if (dsa_port_host_address_match(dp, info->sw_index, |
| 534 | info->port)) { |
| 535 | err = dsa_port_do_mdb_add(dp, info->mdb); |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 536 | if (err) |
| 537 | break; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | return err; |
| 542 | } |
| 543 | |
| 544 | static int dsa_switch_host_mdb_del(struct dsa_switch *ds, |
| 545 | struct dsa_notifier_mdb_info *info) |
| 546 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 547 | struct dsa_port *dp; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 548 | int err = 0; |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 549 | |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 550 | if (!ds->ops->port_mdb_del) |
| 551 | return -EOPNOTSUPP; |
| 552 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 553 | dsa_switch_for_each_port(dp, ds) { |
| 554 | if (dsa_port_host_address_match(dp, info->sw_index, |
| 555 | info->port)) { |
| 556 | err = dsa_port_do_mdb_del(dp, info->mdb); |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 557 | if (err) |
| 558 | break; |
| 559 | } |
| 560 | } |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 561 | |
Vladimir Oltean | 161ca59 | 2021-06-29 17:06:50 +0300 | [diff] [blame] | 562 | return err; |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 563 | } |
| 564 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 565 | static bool dsa_port_vlan_match(struct dsa_port *dp, |
| 566 | struct dsa_notifier_vlan_info *info) |
Vivien Didelot | e65d45c | 2019-08-25 13:25:15 -0400 | [diff] [blame] | 567 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 568 | if (dp->ds->index == info->sw_index && dp->index == info->port) |
Vivien Didelot | e65d45c | 2019-08-25 13:25:15 -0400 | [diff] [blame] | 569 | return true; |
| 570 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 571 | if (dsa_port_is_dsa(dp)) |
Vivien Didelot | e65d45c | 2019-08-25 13:25:15 -0400 | [diff] [blame] | 572 | return true; |
| 573 | |
| 574 | return false; |
| 575 | } |
| 576 | |
Vladimir Oltean | ffb68fc | 2021-01-09 02:01:48 +0200 | [diff] [blame] | 577 | static int dsa_switch_vlan_add(struct dsa_switch *ds, |
| 578 | struct dsa_notifier_vlan_info *info) |
Vivien Didelot | 9c428c5 | 2017-11-30 11:23:59 -0500 | [diff] [blame] | 579 | { |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 580 | struct dsa_port *dp; |
| 581 | int err; |
Vivien Didelot | 9c428c5 | 2017-11-30 11:23:59 -0500 | [diff] [blame] | 582 | |
Vladimir Oltean | 1958d58 | 2021-01-09 02:01:53 +0200 | [diff] [blame] | 583 | if (!ds->ops->port_vlan_add) |
Vivien Didelot | 9c428c5 | 2017-11-30 11:23:59 -0500 | [diff] [blame] | 584 | return -EOPNOTSUPP; |
| 585 | |
Vladimir Oltean | fac6abd | 2021-10-20 20:49:53 +0300 | [diff] [blame] | 586 | dsa_switch_for_each_port(dp, ds) { |
| 587 | if (dsa_port_vlan_match(dp, info)) { |
| 588 | err = ds->ops->port_vlan_add(ds, dp->index, info->vlan, |
Vladimir Oltean | 31046a5 | 2021-02-13 22:43:18 +0200 | [diff] [blame] | 589 | info->extack); |
Vivien Didelot | e65d45c | 2019-08-25 13:25:15 -0400 | [diff] [blame] | 590 | if (err) |
| 591 | return err; |
| 592 | } |
Vivien Didelot | 9c428c5 | 2017-11-30 11:23:59 -0500 | [diff] [blame] | 593 | } |
| 594 | |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | static int dsa_switch_vlan_del(struct dsa_switch *ds, |
| 599 | struct dsa_notifier_vlan_info *info) |
| 600 | { |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 601 | if (!ds->ops->port_vlan_del) |
| 602 | return -EOPNOTSUPP; |
| 603 | |
Vivien Didelot | 1ca4aa9 | 2017-06-07 18:12:14 -0400 | [diff] [blame] | 604 | if (ds->index == info->sw_index) |
Vivien Didelot | e65d45c | 2019-08-25 13:25:15 -0400 | [diff] [blame] | 605 | return ds->ops->port_vlan_del(ds, info->port, info->vlan); |
Vivien Didelot | 1ca4aa9 | 2017-06-07 18:12:14 -0400 | [diff] [blame] | 606 | |
Vivien Didelot | 7e1741b | 2019-08-25 13:25:19 -0400 | [diff] [blame] | 607 | /* Do not deprogram the DSA links as they may be used as conduit |
| 608 | * for other VLAN members in the fabric. |
| 609 | */ |
Vivien Didelot | 1ca4aa9 | 2017-06-07 18:12:14 -0400 | [diff] [blame] | 610 | return 0; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 611 | } |
| 612 | |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 613 | static int dsa_switch_change_tag_proto(struct dsa_switch *ds, |
| 614 | struct dsa_notifier_tag_proto_info *info) |
| 615 | { |
| 616 | const struct dsa_device_ops *tag_ops = info->tag_ops; |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 617 | struct dsa_port *dp, *cpu_dp; |
| 618 | int err; |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 619 | |
| 620 | if (!ds->ops->change_tag_protocol) |
| 621 | return -EOPNOTSUPP; |
| 622 | |
| 623 | ASSERT_RTNL(); |
| 624 | |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 625 | dsa_switch_for_each_cpu_port(cpu_dp, ds) { |
| 626 | err = ds->ops->change_tag_protocol(ds, cpu_dp->index, |
| 627 | tag_ops->proto); |
Tobias Waldekranz | 21e0b50 | 2021-04-20 20:53:09 +0200 | [diff] [blame] | 628 | if (err) |
| 629 | return err; |
| 630 | |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 631 | dsa_port_set_tag_protocol(cpu_dp, tag_ops); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /* Now that changing the tag protocol can no longer fail, let's update |
| 635 | * the remaining bits which are "duplicated for faster access", and the |
| 636 | * bits that depend on the tagger, such as the MTU. |
| 637 | */ |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 638 | dsa_switch_for_each_user_port(dp, ds) { |
| 639 | struct net_device *slave = dp->slave; |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 640 | |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 641 | dsa_slave_setup_tagger(slave); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 642 | |
Vladimir Oltean | d0004a0 | 2021-10-20 20:49:50 +0300 | [diff] [blame] | 643 | /* rtnl_mutex is held in dsa_tree_change_tag_proto */ |
| 644 | dsa_slave_change_mtu(slave, slave->mtu); |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 650 | static int dsa_switch_mrp_add(struct dsa_switch *ds, |
| 651 | struct dsa_notifier_mrp_info *info) |
| 652 | { |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 653 | if (!ds->ops->port_mrp_add) |
| 654 | return -EOPNOTSUPP; |
| 655 | |
Vladimir Oltean | f9bcdc36 | 2021-06-21 19:42:19 +0300 | [diff] [blame] | 656 | if (ds->index == info->sw_index) |
| 657 | return ds->ops->port_mrp_add(ds, info->port, info->mrp); |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 658 | |
Vladimir Oltean | f9bcdc36 | 2021-06-21 19:42:19 +0300 | [diff] [blame] | 659 | return 0; |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static int dsa_switch_mrp_del(struct dsa_switch *ds, |
| 663 | struct dsa_notifier_mrp_info *info) |
| 664 | { |
| 665 | if (!ds->ops->port_mrp_del) |
| 666 | return -EOPNOTSUPP; |
| 667 | |
| 668 | if (ds->index == info->sw_index) |
| 669 | return ds->ops->port_mrp_del(ds, info->port, info->mrp); |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 674 | static int |
| 675 | dsa_switch_mrp_add_ring_role(struct dsa_switch *ds, |
| 676 | struct dsa_notifier_mrp_ring_role_info *info) |
| 677 | { |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 678 | if (!ds->ops->port_mrp_add) |
| 679 | return -EOPNOTSUPP; |
| 680 | |
Vladimir Oltean | f9bcdc36 | 2021-06-21 19:42:19 +0300 | [diff] [blame] | 681 | if (ds->index == info->sw_index) |
| 682 | return ds->ops->port_mrp_add_ring_role(ds, info->port, |
| 683 | info->mrp); |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 684 | |
Vladimir Oltean | f9bcdc36 | 2021-06-21 19:42:19 +0300 | [diff] [blame] | 685 | return 0; |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static int |
| 689 | dsa_switch_mrp_del_ring_role(struct dsa_switch *ds, |
| 690 | struct dsa_notifier_mrp_ring_role_info *info) |
| 691 | { |
| 692 | if (!ds->ops->port_mrp_del) |
| 693 | return -EOPNOTSUPP; |
| 694 | |
| 695 | if (ds->index == info->sw_index) |
| 696 | return ds->ops->port_mrp_del_ring_role(ds, info->port, |
| 697 | info->mrp); |
| 698 | |
| 699 | return 0; |
| 700 | } |
| 701 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 702 | static int dsa_switch_event(struct notifier_block *nb, |
| 703 | unsigned long event, void *info) |
| 704 | { |
| 705 | struct dsa_switch *ds = container_of(nb, struct dsa_switch, nb); |
| 706 | int err; |
| 707 | |
| 708 | switch (event) { |
Vivien Didelot | 1faabf7 | 2017-05-19 17:00:52 -0400 | [diff] [blame] | 709 | case DSA_NOTIFIER_AGEING_TIME: |
| 710 | err = dsa_switch_ageing_time(ds, info); |
| 711 | break; |
Vivien Didelot | 04d3a4c | 2017-02-03 13:20:21 -0500 | [diff] [blame] | 712 | case DSA_NOTIFIER_BRIDGE_JOIN: |
| 713 | err = dsa_switch_bridge_join(ds, info); |
| 714 | break; |
| 715 | case DSA_NOTIFIER_BRIDGE_LEAVE: |
| 716 | err = dsa_switch_bridge_leave(ds, info); |
| 717 | break; |
Vivien Didelot | 685fb6a | 2017-05-19 17:00:53 -0400 | [diff] [blame] | 718 | case DSA_NOTIFIER_FDB_ADD: |
| 719 | err = dsa_switch_fdb_add(ds, info); |
| 720 | break; |
| 721 | case DSA_NOTIFIER_FDB_DEL: |
| 722 | err = dsa_switch_fdb_del(ds, info); |
| 723 | break; |
Vladimir Oltean | 3dc80af | 2021-06-29 17:06:51 +0300 | [diff] [blame] | 724 | case DSA_NOTIFIER_HOST_FDB_ADD: |
| 725 | err = dsa_switch_host_fdb_add(ds, info); |
| 726 | break; |
| 727 | case DSA_NOTIFIER_HOST_FDB_DEL: |
| 728 | err = dsa_switch_host_fdb_del(ds, info); |
| 729 | break; |
George McCollister | 18596f5 | 2021-02-09 19:02:12 -0600 | [diff] [blame] | 730 | case DSA_NOTIFIER_HSR_JOIN: |
| 731 | err = dsa_switch_hsr_join(ds, info); |
| 732 | break; |
| 733 | case DSA_NOTIFIER_HSR_LEAVE: |
| 734 | err = dsa_switch_hsr_leave(ds, info); |
| 735 | break; |
Tobias Waldekranz | 058102a | 2021-01-13 09:42:53 +0100 | [diff] [blame] | 736 | case DSA_NOTIFIER_LAG_CHANGE: |
| 737 | err = dsa_switch_lag_change(ds, info); |
| 738 | break; |
| 739 | case DSA_NOTIFIER_LAG_JOIN: |
| 740 | err = dsa_switch_lag_join(ds, info); |
| 741 | break; |
| 742 | case DSA_NOTIFIER_LAG_LEAVE: |
| 743 | err = dsa_switch_lag_leave(ds, info); |
| 744 | break; |
Vivien Didelot | 8ae5bcd | 2017-05-19 17:00:54 -0400 | [diff] [blame] | 745 | case DSA_NOTIFIER_MDB_ADD: |
| 746 | err = dsa_switch_mdb_add(ds, info); |
| 747 | break; |
| 748 | case DSA_NOTIFIER_MDB_DEL: |
| 749 | err = dsa_switch_mdb_del(ds, info); |
| 750 | break; |
Vladimir Oltean | b8e997c | 2021-06-29 17:06:49 +0300 | [diff] [blame] | 751 | case DSA_NOTIFIER_HOST_MDB_ADD: |
| 752 | err = dsa_switch_host_mdb_add(ds, info); |
| 753 | break; |
| 754 | case DSA_NOTIFIER_HOST_MDB_DEL: |
| 755 | err = dsa_switch_host_mdb_del(ds, info); |
| 756 | break; |
Vivien Didelot | d0c627b | 2017-05-19 17:00:55 -0400 | [diff] [blame] | 757 | case DSA_NOTIFIER_VLAN_ADD: |
| 758 | err = dsa_switch_vlan_add(ds, info); |
| 759 | break; |
| 760 | case DSA_NOTIFIER_VLAN_DEL: |
| 761 | err = dsa_switch_vlan_del(ds, info); |
| 762 | break; |
Vladimir Oltean | bfcb813 | 2020-03-27 21:55:42 +0200 | [diff] [blame] | 763 | case DSA_NOTIFIER_MTU: |
| 764 | err = dsa_switch_mtu(ds, info); |
| 765 | break; |
Vladimir Oltean | 53da0eb | 2021-01-29 03:00:06 +0200 | [diff] [blame] | 766 | case DSA_NOTIFIER_TAG_PROTO: |
| 767 | err = dsa_switch_change_tag_proto(ds, info); |
| 768 | break; |
Horatiu Vultur | c595c43 | 2021-02-16 22:42:04 +0100 | [diff] [blame] | 769 | case DSA_NOTIFIER_MRP_ADD: |
| 770 | err = dsa_switch_mrp_add(ds, info); |
| 771 | break; |
| 772 | case DSA_NOTIFIER_MRP_DEL: |
| 773 | err = dsa_switch_mrp_del(ds, info); |
| 774 | break; |
| 775 | case DSA_NOTIFIER_MRP_ADD_RING_ROLE: |
| 776 | err = dsa_switch_mrp_add_ring_role(ds, info); |
| 777 | break; |
| 778 | case DSA_NOTIFIER_MRP_DEL_RING_ROLE: |
| 779 | err = dsa_switch_mrp_del_ring_role(ds, info); |
| 780 | break; |
Vladimir Oltean | c64b9c0 | 2021-07-19 20:14:52 +0300 | [diff] [blame] | 781 | case DSA_NOTIFIER_TAG_8021Q_VLAN_ADD: |
| 782 | err = dsa_switch_tag_8021q_vlan_add(ds, info); |
| 783 | break; |
| 784 | case DSA_NOTIFIER_TAG_8021Q_VLAN_DEL: |
| 785 | err = dsa_switch_tag_8021q_vlan_del(ds, info); |
| 786 | break; |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 787 | default: |
| 788 | err = -EOPNOTSUPP; |
| 789 | break; |
| 790 | } |
| 791 | |
Vivien Didelot | f515f19 | 2017-02-03 13:20:20 -0500 | [diff] [blame] | 792 | if (err) |
| 793 | dev_dbg(ds->dev, "breaking chain for DSA event %lu (%d)\n", |
| 794 | event, err); |
| 795 | |
| 796 | return notifier_from_errno(err); |
| 797 | } |
| 798 | |
| 799 | int dsa_switch_register_notifier(struct dsa_switch *ds) |
| 800 | { |
| 801 | ds->nb.notifier_call = dsa_switch_event; |
| 802 | |
| 803 | return raw_notifier_chain_register(&ds->dst->nh, &ds->nb); |
| 804 | } |
| 805 | |
| 806 | void dsa_switch_unregister_notifier(struct dsa_switch *ds) |
| 807 | { |
| 808 | int err; |
| 809 | |
| 810 | err = raw_notifier_chain_unregister(&ds->dst->nh, &ds->nb); |
| 811 | if (err) |
| 812 | dev_err(ds->dev, "failed to unregister notifier (%d)\n", err); |
| 813 | } |