diff options
author | Vivien Didelot <vivien.didelot@savoirfairelinux.com> | 2017-11-30 11:23:59 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-12-02 21:18:56 -0500 |
commit | 9c428c593fb7533595c439b510e5eb5e94aec65e (patch) | |
tree | ae24c2fba9fd22add3a0607e7e874778dc1f09c8 /net/dsa/switch.c | |
parent | 3709aadc8375a1b0c42da5b12e38eddf8133dd4e (diff) |
net: dsa: add switch vlan bitmap functions
This patch brings no functional changes.
It moves out the VLAN code iterating on a list of VLAN members into new
dsa_switch_vlan_{prepare,add}_bitmap() functions.
This gives us a better isolation of the two switchdev phases.
Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa/switch.c')
-rw-r--r-- | net/dsa/switch.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/net/dsa/switch.c b/net/dsa/switch.c index 5ee04e9b5796..17cd03d6bc7d 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c | |||
@@ -157,13 +157,43 @@ static int dsa_switch_mdb_del(struct dsa_switch *ds, | |||
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | 159 | ||
160 | static int | ||
161 | dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds, | ||
162 | const struct switchdev_obj_port_vlan *vlan, | ||
163 | const unsigned long *bitmap) | ||
164 | { | ||
165 | int port, err; | ||
166 | |||
167 | if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add) | ||
168 | return -EOPNOTSUPP; | ||
169 | |||
170 | for_each_set_bit(port, bitmap, ds->num_ports) { | ||
171 | err = ds->ops->port_vlan_prepare(ds, port, vlan); | ||
172 | if (err) | ||
173 | return err; | ||
174 | } | ||
175 | |||
176 | return 0; | ||
177 | } | ||
178 | |||
179 | static void | ||
180 | dsa_switch_vlan_add_bitmap(struct dsa_switch *ds, | ||
181 | const struct switchdev_obj_port_vlan *vlan, | ||
182 | const unsigned long *bitmap) | ||
183 | { | ||
184 | int port; | ||
185 | |||
186 | for_each_set_bit(port, bitmap, ds->num_ports) | ||
187 | ds->ops->port_vlan_add(ds, port, vlan); | ||
188 | } | ||
189 | |||
160 | static int dsa_switch_vlan_add(struct dsa_switch *ds, | 190 | static int dsa_switch_vlan_add(struct dsa_switch *ds, |
161 | struct dsa_notifier_vlan_info *info) | 191 | struct dsa_notifier_vlan_info *info) |
162 | { | 192 | { |
163 | const struct switchdev_obj_port_vlan *vlan = info->vlan; | 193 | const struct switchdev_obj_port_vlan *vlan = info->vlan; |
164 | struct switchdev_trans *trans = info->trans; | 194 | struct switchdev_trans *trans = info->trans; |
165 | DECLARE_BITMAP(members, ds->num_ports); | 195 | DECLARE_BITMAP(members, ds->num_ports); |
166 | int port, err; | 196 | int port; |
167 | 197 | ||
168 | /* Build a mask of VLAN members */ | 198 | /* Build a mask of VLAN members */ |
169 | bitmap_zero(members, ds->num_ports); | 199 | bitmap_zero(members, ds->num_ports); |
@@ -173,21 +203,10 @@ static int dsa_switch_vlan_add(struct dsa_switch *ds, | |||
173 | if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) | 203 | if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) |
174 | set_bit(port, members); | 204 | set_bit(port, members); |
175 | 205 | ||
176 | if (switchdev_trans_ph_prepare(trans)) { | 206 | if (switchdev_trans_ph_prepare(trans)) |
177 | if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add) | 207 | return dsa_switch_vlan_prepare_bitmap(ds, vlan, members); |
178 | return -EOPNOTSUPP; | ||
179 | 208 | ||
180 | for_each_set_bit(port, members, ds->num_ports) { | 209 | dsa_switch_vlan_add_bitmap(ds, vlan, members); |
181 | err = ds->ops->port_vlan_prepare(ds, port, vlan); | ||
182 | if (err) | ||
183 | return err; | ||
184 | } | ||
185 | |||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | for_each_set_bit(port, members, ds->num_ports) | ||
190 | ds->ops->port_vlan_add(ds, port, vlan); | ||
191 | 210 | ||
192 | return 0; | 211 | return 0; |
193 | } | 212 | } |