]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: sched: add an offload graft helper
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 8 Nov 2018 01:33:37 +0000 (17:33 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 9 Nov 2018 00:19:48 +0000 (16:19 -0800)
Qdisc graft operation of offload-capable qdiscs performs a few
extra steps which are identical among all the qdiscs.  Add
a helper to share this code.

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/net/sch_generic.h
net/sched/sch_api.c
net/sched/sch_prio.c

index af55c1c4edb1753f482d58b98cedb05b8e535123..a8dd1fc141b650e88ad771de73ed9384d34a2def 100644 (file)
@@ -582,6 +582,10 @@ void qdisc_tree_reduce_backlog(struct Qdisc *qdisc, unsigned int n,
 #ifdef CONFIG_NET_SCHED
 int qdisc_offload_dump_helper(struct Qdisc *q, enum tc_setup_type type,
                              void *type_data);
+void qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
+                               struct Qdisc *new, struct Qdisc *old,
+                               enum tc_setup_type type, void *type_data,
+                               struct netlink_ext_ack *extack);
 #else
 static inline int
 qdisc_offload_dump_helper(struct Qdisc *q, enum tc_setup_type type,
@@ -590,6 +594,14 @@ qdisc_offload_dump_helper(struct Qdisc *q, enum tc_setup_type type,
        q->flags &= ~TCQ_F_OFFLOADED;
        return 0;
 }
+
+static inline void
+qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
+                          struct Qdisc *new, struct Qdisc *old,
+                          enum tc_setup_type type, void *type_data,
+                          struct netlink_ext_ack *extack)
+{
+}
 #endif
 struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
                          const struct Qdisc_ops *ops,
index e534825d3d3aa49d9de3a46650823f25f6276970..4b3af41cc1d78a24d78dbe39555c340e355fc681 100644 (file)
@@ -831,6 +831,35 @@ int qdisc_offload_dump_helper(struct Qdisc *sch, enum tc_setup_type type,
 }
 EXPORT_SYMBOL(qdisc_offload_dump_helper);
 
+void qdisc_offload_graft_helper(struct net_device *dev, struct Qdisc *sch,
+                               struct Qdisc *new, struct Qdisc *old,
+                               enum tc_setup_type type, void *type_data,
+                               struct netlink_ext_ack *extack)
+{
+       bool any_qdisc_is_offloaded;
+       int err;
+
+       if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
+               return;
+
+       err = dev->netdev_ops->ndo_setup_tc(dev, type, type_data);
+
+       /* Don't report error if the graft is part of destroy operation. */
+       if (!err || !new || new == &noop_qdisc)
+               return;
+
+       /* Don't report error if the parent, the old child and the new
+        * one are not offloaded.
+        */
+       any_qdisc_is_offloaded = new->flags & TCQ_F_OFFLOADED;
+       any_qdisc_is_offloaded |= sch && sch->flags & TCQ_F_OFFLOADED;
+       any_qdisc_is_offloaded |= old && old->flags & TCQ_F_OFFLOADED;
+
+       if (any_qdisc_is_offloaded)
+               NL_SET_ERR_MSG(extack, "Offloading graft operation failed.");
+}
+EXPORT_SYMBOL(qdisc_offload_graft_helper);
+
 static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
                         u32 portid, u32 seq, u16 flags, int event)
 {
index 4bdd04c30eada1dacbf9322bf14ef960f27740cb..63a90c5055ee442b8b648798e46f40988ad67a97 100644 (file)
@@ -295,43 +295,22 @@ static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
 {
        struct prio_sched_data *q = qdisc_priv(sch);
        struct tc_prio_qopt_offload graft_offload;
-       struct net_device *dev = qdisc_dev(sch);
        unsigned long band = arg - 1;
-       bool any_qdisc_is_offloaded;
-       int err;
 
        if (new == NULL)
                new = &noop_qdisc;
 
        *old = qdisc_replace(sch, new, &q->queues[band]);
 
-       if (!tc_can_offload(dev))
-               return 0;
-
        graft_offload.handle = sch->handle;
        graft_offload.parent = sch->parent;
        graft_offload.graft_params.band = band;
        graft_offload.graft_params.child_handle = new->handle;
        graft_offload.command = TC_PRIO_GRAFT;
 
-       err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_PRIO,
-                                           &graft_offload);
-
-       /* Don't report error if the graft is part of destroy operation. */
-       if (err && new != &noop_qdisc) {
-               /* Don't report error if the parent, the old child and the new
-                * one are not offloaded.
-                */
-               any_qdisc_is_offloaded = sch->flags & TCQ_F_OFFLOADED;
-               any_qdisc_is_offloaded |= new->flags & TCQ_F_OFFLOADED;
-               if (*old)
-                       any_qdisc_is_offloaded |= (*old)->flags &
-                                                  TCQ_F_OFFLOADED;
-
-               if (any_qdisc_is_offloaded)
-                       NL_SET_ERR_MSG(extack, "Offloading graft operation failed.");
-       }
-
+       qdisc_offload_graft_helper(qdisc_dev(sch), sch, new, *old,
+                                  TC_SETUP_QDISC_PRIO, &graft_offload,
+                                  extack);
        return 0;
 }