net: sched: gred: add basic Qdisc offload
authorJakub Kicinski <jakub.kicinski@netronome.com>
Mon, 19 Nov 2018 23:21:42 +0000 (15:21 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 20 Nov 2018 02:53:45 +0000 (18:53 -0800)
Add basic offload for the GRED Qdisc.  Inform the drivers any
time Qdisc or virtual queue configuration changes.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: John Hurley <john.hurley@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
include/net/pkt_cls.h
net/sched/sch_gred.c

index 086e64d..4b4207e 100644 (file)
@@ -846,6 +846,7 @@ enum tc_setup_type {
        TC_SETUP_QDISC_MQ,
        TC_SETUP_QDISC_ETF,
        TC_SETUP_ROOT_QDISC,
+       TC_SETUP_QDISC_GRED,
 };
 
 /* These structures hold the attributes of bpf state that are being passed
index c497ada..c919879 100644 (file)
@@ -868,6 +868,42 @@ struct tc_red_qopt_offload {
        };
 };
 
+enum tc_gred_command {
+       TC_GRED_REPLACE,
+       TC_GRED_DESTROY,
+};
+
+struct tc_gred_vq_qopt_offload_params {
+       bool present;
+       u32 limit;
+       u32 prio;
+       u32 min;
+       u32 max;
+       bool is_ecn;
+       bool is_harddrop;
+       u32 probability;
+       /* Only need backlog, see struct tc_prio_qopt_offload_params */
+       u32 *backlog;
+};
+
+struct tc_gred_qopt_offload_params {
+       bool grio_on;
+       bool wred_on;
+       unsigned int dp_cnt;
+       unsigned int dp_def;
+       struct gnet_stats_queue *qstats;
+       struct tc_gred_vq_qopt_offload_params tab[MAX_DPs];
+};
+
+struct tc_gred_qopt_offload {
+       enum tc_gred_command command;
+       u32 handle;
+       u32 parent;
+       union {
+               struct tc_gred_qopt_offload_params set;
+       };
+};
+
 enum tc_prio_command {
        TC_PRIO_REPLACE,
        TC_PRIO_DESTROY,
index 8b8c325..908c9d1 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/skbuff.h>
+#include <net/pkt_cls.h>
 #include <net/pkt_sched.h>
 #include <net/red.h>
 
@@ -311,6 +312,48 @@ static void gred_reset(struct Qdisc *sch)
        }
 }
 
+static void gred_offload(struct Qdisc *sch, enum tc_gred_command command)
+{
+       struct gred_sched *table = qdisc_priv(sch);
+       struct net_device *dev = qdisc_dev(sch);
+       struct tc_gred_qopt_offload opt = {
+               .command        = command,
+               .handle         = sch->handle,
+               .parent         = sch->parent,
+       };
+
+       if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
+               return;
+
+       if (command == TC_GRED_REPLACE) {
+               unsigned int i;
+
+               opt.set.grio_on = gred_rio_mode(table);
+               opt.set.wred_on = gred_wred_mode(table);
+               opt.set.dp_cnt = table->DPs;
+               opt.set.dp_def = table->def;
+
+               for (i = 0; i < table->DPs; i++) {
+                       struct gred_sched_data *q = table->tab[i];
+
+                       if (!q)
+                               continue;
+                       opt.set.tab[i].present = true;
+                       opt.set.tab[i].limit = q->limit;
+                       opt.set.tab[i].prio = q->prio;
+                       opt.set.tab[i].min = q->parms.qth_min >> q->parms.Wlog;
+                       opt.set.tab[i].max = q->parms.qth_max >> q->parms.Wlog;
+                       opt.set.tab[i].is_ecn = gred_use_ecn(q);
+                       opt.set.tab[i].is_harddrop = gred_use_harddrop(q);
+                       opt.set.tab[i].probability = q->parms.max_P;
+                       opt.set.tab[i].backlog = &q->backlog;
+               }
+               opt.set.qstats = &sch->qstats;
+       }
+
+       dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_GRED, &opt);
+}
+
 static inline void gred_destroy_vq(struct gred_sched_data *q)
 {
        kfree(q);
@@ -385,6 +428,7 @@ static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps,
                }
        }
 
+       gred_offload(sch, TC_GRED_REPLACE);
        return 0;
 }
 
@@ -630,6 +674,8 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt,
 
        sch_tree_unlock(sch);
        kfree(prealloc);
+
+       gred_offload(sch, TC_GRED_REPLACE);
        return 0;
 
 err_unlock_free:
@@ -815,6 +861,7 @@ static void gred_destroy(struct Qdisc *sch)
                if (table->tab[i])
                        gred_destroy_vq(table->tab[i]);
        }
+       gred_offload(sch, TC_GRED_DESTROY);
 }
 
 static struct Qdisc_ops gred_qdisc_ops __read_mostly = {