mlxsw: spectrum: Teach mlxsw_sp_port_vlan_set to accept any vlan range
authorJiri Pirko <jiri@mellanox.com>
Tue, 18 Apr 2017 14:55:35 +0000 (16:55 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 20 Apr 2017 19:32:30 +0000 (15:32 -0400)
So far, mlxsw_sp_port_vlan_set range is limited by
MLXSW_REG_SPVM_REC_MAX_COUNT. In spectrum_switchdev code this is
wrapped up by a helper function which actually does multiple calls
to FW for bigger ranges. Move the code into mlxsw_sp_port_vlan_set
and use it always. That allows caller not to care about the range.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c

index 6e113c325f92e2c3238bd0adc6014005f8f0447b..77b5bb38eb01b5630f2b0724677d7df565678d47 100644 (file)
@@ -1061,8 +1061,9 @@ mlxsw_sp_port_get_stats64(struct net_device *dev,
        memcpy(stats, mlxsw_sp_port->hw_stats.cache, sizeof(*stats));
 }
 
-int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
-                          u16 vid_end, bool is_member, bool untagged)
+static int __mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port,
+                                   u16 vid_begin, u16 vid_end,
+                                   bool is_member, bool untagged)
 {
        struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
        char *spvm_pl;
@@ -1079,6 +1080,26 @@ int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
        return err;
 }
 
+int mlxsw_sp_port_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid_begin,
+                          u16 vid_end, bool is_member, bool untagged)
+{
+       u16 vid, vid_e;
+       int err;
+
+       for (vid = vid_begin; vid <= vid_end;
+            vid += MLXSW_REG_SPVM_REC_MAX_COUNT) {
+               vid_e = min((u16) (vid + MLXSW_REG_SPVM_REC_MAX_COUNT - 1),
+                           vid_end);
+
+               err = __mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid_e,
+                                              is_member, untagged);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+
 static int mlxsw_sp_port_vp_mode_trans(struct mlxsw_sp_port *mlxsw_sp_port)
 {
        enum mlxsw_reg_svfa_mt mt = MLXSW_REG_SVFA_MT_PORT_VID_TO_FID;
index 05eaa15ad9d5458c9b67c64ad999eac919a4b0d9..0d8411f1f954c5668bc3bd26f721589f2ccf205d 100644 (file)
@@ -745,27 +745,6 @@ err_port_allow_untagged_set:
        return err;
 }
 
-static int __mlxsw_sp_port_vlans_set(struct mlxsw_sp_port *mlxsw_sp_port,
-                                    u16 vid_begin, u16 vid_end, bool is_member,
-                                    bool untagged)
-{
-       u16 vid, vid_e;
-       int err;
-
-       for (vid = vid_begin; vid <= vid_end;
-            vid += MLXSW_REG_SPVM_REC_MAX_COUNT) {
-               vid_e = min((u16) (vid + MLXSW_REG_SPVM_REC_MAX_COUNT - 1),
-                           vid_end);
-
-               err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid_e,
-                                            is_member, untagged);
-               if (err)
-                       return err;
-       }
-
-       return 0;
-}
-
 static int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port,
                                          u16 vid_begin, u16 vid_end,
                                          bool learn_enable)
@@ -804,8 +783,8 @@ static int __mlxsw_sp_port_vlans_add(struct mlxsw_sp_port *mlxsw_sp_port,
                return err;
        }
 
-       err = __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end,
-                                       true, flag_untagged);
+       err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid_begin, vid_end,
+                                    true, flag_untagged);
        if (err) {
                netdev_err(dev, "Unable to add VIDs %d-%d\n", vid_begin,
                           vid_end);
@@ -863,8 +842,8 @@ err_port_vid_learning_set:
        if (old_pvid != mlxsw_sp_port->pvid)
                mlxsw_sp_port_pvid_set(mlxsw_sp_port, old_pvid);
 err_port_pvid_set:
-       __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end, false,
-                                 false);
+       mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid_begin, vid_end,
+                              false, false);
 err_port_vlans_set:
        mlxsw_sp_port_fid_leave(mlxsw_sp_port, vid_begin, vid_end);
        return err;
@@ -1171,8 +1150,8 @@ static int __mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
        if (pvid >= vid_begin && pvid <= vid_end)
                mlxsw_sp_port_pvid_set(mlxsw_sp_port, 0);
 
-       __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end, false,
-                                 false);
+       mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid_begin, vid_end,
+                              false, false);
 
        mlxsw_sp_port_fid_leave(mlxsw_sp_port, vid_begin, vid_end);