public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jiri@mellanox.com, jhs@mojatatu.com,
	xiyou.wangcong@gmail.com, petrm@mellanox.com, mlxsw@mellanox.com,
	Ido Schimmel <idosch@mellanox.com>
Subject: [PATCH net-next 02/14] net: sched: Make TBF Qdisc offloadable
Date: Fri, 24 Jan 2020 15:23:06 +0200	[thread overview]
Message-ID: <20200124132318.712354-3-idosch@idosch.org> (raw)
In-Reply-To: <20200124132318.712354-1-idosch@idosch.org>

From: Petr Machata <petrm@mellanox.com>

Invoke ndo_setup_tc as appropriate to signal init / replacement, destroying
and dumping of TBF Qdisc.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 include/linux/netdevice.h |  1 +
 include/net/pkt_cls.h     | 22 ++++++++++++++++
 net/sched/sch_tbf.c       | 55 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 5ec3537fbdb1..11bdf6cb30bd 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -850,6 +850,7 @@ enum tc_setup_type {
 	TC_SETUP_QDISC_TAPRIO,
 	TC_SETUP_FT,
 	TC_SETUP_QDISC_ETS,
+	TC_SETUP_QDISC_TBF,
 };
 
 /* These structures hold the attributes of bpf state that are being passed
diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h
index 47b115e2012a..ce036492986a 100644
--- a/include/net/pkt_cls.h
+++ b/include/net/pkt_cls.h
@@ -854,4 +854,26 @@ struct tc_ets_qopt_offload {
 	};
 };
 
+enum tc_tbf_command {
+	TC_TBF_REPLACE,
+	TC_TBF_DESTROY,
+	TC_TBF_STATS,
+};
+
+struct tc_tbf_qopt_offload_replace_params {
+	struct psched_ratecfg rate;
+	u32 max_size;
+	struct gnet_stats_queue *qstats;
+};
+
+struct tc_tbf_qopt_offload {
+	enum tc_tbf_command command;
+	u32 handle;
+	u32 parent;
+	union {
+		struct tc_tbf_qopt_offload_replace_params replace_params;
+		struct tc_qopt_offload_stats stats;
+	};
+};
+
 #endif
diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index 7ae317958090..78e79029dc63 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -15,6 +15,7 @@
 #include <linux/skbuff.h>
 #include <net/netlink.h>
 #include <net/sch_generic.h>
+#include <net/pkt_cls.h>
 #include <net/pkt_sched.h>
 
 
@@ -137,6 +138,52 @@ static u64 psched_ns_t2l(const struct psched_ratecfg *r,
 	return len;
 }
 
+static void tbf_offload_change(struct Qdisc *sch)
+{
+	struct tbf_sched_data *q = qdisc_priv(sch);
+	struct net_device *dev = qdisc_dev(sch);
+	struct tc_tbf_qopt_offload qopt;
+
+	if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
+		return;
+
+	qopt.command = TC_TBF_REPLACE;
+	qopt.handle = sch->handle;
+	qopt.parent = sch->parent;
+	qopt.replace_params.rate = q->rate;
+	qopt.replace_params.max_size = q->max_size;
+	qopt.replace_params.qstats = &sch->qstats;
+
+	dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_TBF, &qopt);
+}
+
+static void tbf_offload_destroy(struct Qdisc *sch)
+{
+	struct net_device *dev = qdisc_dev(sch);
+	struct tc_tbf_qopt_offload qopt;
+
+	if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
+		return;
+
+	qopt.command = TC_TBF_DESTROY;
+	qopt.handle = sch->handle;
+	qopt.parent = sch->parent;
+	dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_TBF, &qopt);
+}
+
+static int tbf_offload_dump(struct Qdisc *sch)
+{
+	struct tc_tbf_qopt_offload qopt;
+
+	qopt.command = TC_TBF_STATS;
+	qopt.handle = sch->handle;
+	qopt.parent = sch->parent;
+	qopt.stats.bstats = &sch->bstats;
+	qopt.stats.qstats = &sch->qstats;
+
+	return qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_TBF, &qopt);
+}
+
 /* GSO packet is too big, segment it so that tbf can transmit
  * each segment in time
  */
@@ -407,6 +454,8 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt,
 
 	sch_tree_unlock(sch);
 	err = 0;
+
+	tbf_offload_change(sch);
 done:
 	return err;
 }
@@ -432,6 +481,7 @@ static void tbf_destroy(struct Qdisc *sch)
 	struct tbf_sched_data *q = qdisc_priv(sch);
 
 	qdisc_watchdog_cancel(&q->watchdog);
+	tbf_offload_destroy(sch);
 	qdisc_put(q->qdisc);
 }
 
@@ -440,6 +490,11 @@ static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)
 	struct tbf_sched_data *q = qdisc_priv(sch);
 	struct nlattr *nest;
 	struct tc_tbf_qopt opt;
+	int err;
+
+	err = tbf_offload_dump(sch);
+	if (err)
+		return err;
 
 	nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
 	if (nest == NULL)
-- 
2.24.1


  parent reply	other threads:[~2020-01-24 13:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24 13:23 [PATCH net-next 00/14] mlxsw: Offload TBF Ido Schimmel
2020-01-24 13:23 ` [PATCH net-next 01/14] net: sched: sch_tbf: Don't overwrite backlog before dumping Ido Schimmel
2020-01-24 13:23 ` Ido Schimmel [this message]
2020-01-24 13:23 ` [PATCH net-next 03/14] mlxsw: spectrum_qdisc: Extract a per-TC stat function Ido Schimmel
2020-01-24 14:03   ` Jiri Pirko
2020-01-24 13:23 ` [PATCH net-next 04/14] mlxsw: spectrum_qdisc: Add mlxsw_sp_qdisc_get_class_stats() Ido Schimmel
2020-01-24 14:26   ` Jiri Pirko
2020-01-24 13:23 ` [PATCH net-next 05/14] mlxsw: spectrum_qdisc: Extract a common leaf unoffload function Ido Schimmel
2020-01-24 15:04   ` Jiri Pirko
2020-01-24 13:23 ` [PATCH net-next 06/14] mlxsw: reg: Add max_shaper_bs to QoS ETS Element Configuration Ido Schimmel
2020-01-24 15:04   ` Jiri Pirko
2020-01-24 13:23 ` [PATCH net-next 07/14] mlxsw: reg: Increase MLXSW_REG_QEEC_MAS_DIS Ido Schimmel
2020-01-24 15:05   ` Jiri Pirko
2020-01-24 13:23 ` [PATCH net-next 08/14] mlxsw: spectrum: Add lowest_shaper_bs to struct mlxsw_sp Ido Schimmel
2020-01-24 15:06   ` Jiri Pirko
2020-01-24 13:23 ` [PATCH net-next 09/14] mlxsw: spectrum: Configure shaper rate and burst size together Ido Schimmel
2020-01-24 15:07   ` Jiri Pirko
2020-01-24 13:23 ` [PATCH net-next 10/14] mlxsw: spectrum_qdisc: Support offloading of TBF Qdisc Ido Schimmel
2020-01-24 15:27   ` Jiri Pirko
2020-01-24 13:23 ` [PATCH net-next 11/14] selftests: Move two functions from mlxsw's qos_lib to lib Ido Schimmel
2020-01-24 13:23 ` [PATCH net-next 12/14] selftests: forwarding: lib: Add helpers for busywaiting Ido Schimmel
2020-01-24 13:23 ` [PATCH net-next 13/14] selftests: forwarding: lib: Allow reading TC rule byte counters Ido Schimmel
2020-01-24 13:23 ` [PATCH net-next 14/14] selftests: mlxsw: Add a TBF selftest Ido Schimmel
2020-01-25 12:09 ` [PATCH net-next 00/14] mlxsw: Offload TBF David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200124132318.712354-3-idosch@idosch.org \
    --to=idosch@idosch.org \
    --cc=davem@davemloft.net \
    --cc=idosch@mellanox.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@mellanox.com \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=petrm@mellanox.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox