OSDN Git Service

mlxsw: spectrum: qdiscs: Unite all handle checks
authorNogah Frankel <nogahf@mellanox.com>
Wed, 10 Jan 2018 14:00:03 +0000 (15:00 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 10 Jan 2018 21:07:41 +0000 (16:07 -0500)
Every qdisc op gets the qdisc handle ID as well as its location.  Each one
of them, beside replace, checks if the handle doesn't match the qdisc in
the given location, and if so, it returns without running the actual op.
Unite these checks to one comparison function and avoid sending the handle
id to these ops.

Signed-off-by: Nogah Frankel <nogahf@mellanox.com>
Reviewed-by: Yuval Mintz <yuvalm@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c

index dcf6d7c..51ac809 100644 (file)
@@ -61,6 +61,14 @@ struct mlxsw_sp_qdisc {
        } stats_base;
 };
 
+static bool
+mlxsw_sp_qdisc_compare(struct mlxsw_sp_qdisc *mlxsw_sp_qdisc, u32 handle,
+                      enum mlxsw_sp_qdisc_type type)
+{
+       return mlxsw_sp_qdisc && mlxsw_sp_qdisc->handle == handle &&
+              mlxsw_sp_qdisc->type == type;
+}
+
 static int
 mlxsw_sp_tclass_congestion_enable(struct mlxsw_sp_port *mlxsw_sp_port,
                                  int tclass_num, u32 min, u32 max,
@@ -125,14 +133,11 @@ mlxsw_sp_setup_tc_qdisc_red_clean_stats(struct mlxsw_sp_port *mlxsw_sp_port,
 }
 
 static int
-mlxsw_sp_qdisc_red_destroy(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
+mlxsw_sp_qdisc_red_destroy(struct mlxsw_sp_port *mlxsw_sp_port,
                           struct mlxsw_sp_qdisc *mlxsw_sp_qdisc)
 {
        int err;
 
-       if (mlxsw_sp_qdisc->handle != handle)
-               return 0;
-
        err = mlxsw_sp_tclass_congestion_disable(mlxsw_sp_port,
                                                 mlxsw_sp_qdisc->tclass_num);
        mlxsw_sp_qdisc->handle = TC_H_UNSPEC;
@@ -192,13 +197,12 @@ mlxsw_sp_qdisc_red_replace(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
 err_bad_param:
        err = -EINVAL;
 err_config:
-       mlxsw_sp_qdisc_red_destroy(mlxsw_sp_port, mlxsw_sp_qdisc->handle,
-                                  mlxsw_sp_qdisc);
+       mlxsw_sp_qdisc_red_destroy(mlxsw_sp_port, mlxsw_sp_qdisc);
        return err;
 }
 
 static int
-mlxsw_sp_qdisc_get_red_xstats(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
+mlxsw_sp_qdisc_get_red_xstats(struct mlxsw_sp_port *mlxsw_sp_port,
                              struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
                              struct red_stats *res)
 {
@@ -207,10 +211,6 @@ mlxsw_sp_qdisc_get_red_xstats(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
        struct mlxsw_sp_port_xstats *xstats;
        int early_drops, marks, pdrops;
 
-       if (mlxsw_sp_qdisc->handle != handle ||
-           mlxsw_sp_qdisc->type != MLXSW_SP_QDISC_RED)
-               return -EOPNOTSUPP;
-
        xstats = &mlxsw_sp_port->periodic_hw_stats.xstats;
 
        early_drops = xstats->wred_drop[tclass_num] - xstats_base->prob_drop;
@@ -228,7 +228,7 @@ mlxsw_sp_qdisc_get_red_xstats(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
 }
 
 static int
-mlxsw_sp_qdisc_get_red_stats(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
+mlxsw_sp_qdisc_get_red_stats(struct mlxsw_sp_port *mlxsw_sp_port,
                             struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
                             struct tc_qopt_offload_stats *res)
 {
@@ -238,10 +238,6 @@ mlxsw_sp_qdisc_get_red_stats(struct mlxsw_sp_port *mlxsw_sp_port, u32 handle,
        struct mlxsw_sp_port_xstats *xstats;
        struct rtnl_link_stats64 *stats;
 
-       if (mlxsw_sp_qdisc->handle != handle ||
-           mlxsw_sp_qdisc->type != MLXSW_SP_QDISC_RED)
-               return -EOPNOTSUPP;
-
        xstats = &mlxsw_sp_port->periodic_hw_stats.xstats;
        stats = &mlxsw_sp_port->periodic_hw_stats.stats;
        stats_base = &mlxsw_sp_qdisc->stats_base;
@@ -278,19 +274,24 @@ int mlxsw_sp_setup_tc_red(struct mlxsw_sp_port *mlxsw_sp_port,
 
        mlxsw_sp_qdisc = mlxsw_sp_port->root_qdisc;
 
-       switch (p->command) {
-       case TC_RED_REPLACE:
+       if (p->command == TC_RED_REPLACE)
                return mlxsw_sp_qdisc_red_replace(mlxsw_sp_port, p->handle,
                                                  mlxsw_sp_qdisc, &p->set);
+
+       if (!mlxsw_sp_qdisc_compare(mlxsw_sp_qdisc, p->handle,
+                                   MLXSW_SP_QDISC_RED))
+               return -EOPNOTSUPP;
+
+       switch (p->command) {
        case TC_RED_DESTROY:
-               return mlxsw_sp_qdisc_red_destroy(mlxsw_sp_port, p->handle,
+               return mlxsw_sp_qdisc_red_destroy(mlxsw_sp_port,
                                                  mlxsw_sp_qdisc);
        case TC_RED_XSTATS:
-               return mlxsw_sp_qdisc_get_red_xstats(mlxsw_sp_port, p->handle,
+               return mlxsw_sp_qdisc_get_red_xstats(mlxsw_sp_port,
                                                     mlxsw_sp_qdisc,
                                                     p->xstats);
        case TC_RED_STATS:
-               return mlxsw_sp_qdisc_get_red_stats(mlxsw_sp_port, p->handle,
+               return mlxsw_sp_qdisc_get_red_stats(mlxsw_sp_port,
                                                    mlxsw_sp_qdisc,
                                                    &p->stats);
        default: