aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched/cls_flower.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-03-10 16:24:03 -0500
committerDavid S. Miller <davem@davemloft.net>2016-03-10 16:24:03 -0500
commite8ab563f4b2e51849a16d962c6235b81e429c0d7 (patch)
tree293c390acdab0f7911ff42d7aba44b83c1020c8a /net/sched/cls_flower.c
parentMerge branch 'mediatek-eth' (diff)
parentnet/mlx5e: Support offload cls_flower with skbedit mark action (diff)
downloadlinux-dev-e8ab563f4b2e51849a16d962c6235b81e429c0d7.tar.xz
linux-dev-e8ab563f4b2e51849a16d962c6235b81e429c0d7.zip
Merge branch 'flower-offload'
Amir Vadai says: ==================== cls_flower hardware offload support Please see changes from V2 at the bottom. This patchset introduces cls_flower hardware offload support over ConnectX-4 driver, more hardware vendors are welcome to use it too. This patchset is based on John's infrastructure for tc offloading [2] to add hardware offload support to the flower filter. It also extends the support to an additional tc action - skbedit mark operation. NIC driver that was used is ConnectX-4. Feature is off by default and could be turned on using ethtool. Some commands to use this code: export TC=../iproute2/tc/tc export ETH=ens9 ethtool -K ens9 hw-tc-offload on $TC qdisc add dev $ETH ingress $TC filter add dev $ETH protocol ip prio 20 parent ffff: \ flower ip_proto 1 \ dst_mac 7c:fe:90:69:81:62 \ src_mac 7c:fe:90:69:81:56 \ dst_ip 11.11.11.11 \ src_ip 11.11.11.12 \ indev $ETH \ action drop $TC filter add dev $ETH protocol ip prio 30 parent ffff: \ flower ip_proto 6 \ indev $ETH \ action skbedit mark 0x1234 $TC filter add dev $ETH protocol ip prio 10 parent ffff: \ handle 0x1234 fw action pass The code was tested and applied on top of commit 3ebeac1 ("Merge branch 'cxgb4-next'") Changes from V2: - patch 1/10 ("net/flower: Introduce hardware offload support") - Remove unused variable [Dave] - Don't fail command when HW can't offload filter [John] - patch 3/10 ("net/sched: Macro instead of CONFIG_NET_CLS_ACT ifdef") - Mention in changelog that struct tc_action is now exposed out of the ifdef. - patch 4/10 ("net/act_skbedit: Utility functions for mark action") - Document clearly that is_tcf_skbedit_mark() is returning true if and only if the only action is mark [Dave] - patch 8/10 ("net/mlx5e: Introduce tc offload support") - make mlx5e_tc_add_flow() static Changes from V1: - patch 3/10 ("net/sched: Macro instead of CONFIG_NET_CLS_ACT ifdef") - fixed return value of tc_no_actions Changes from V0: - Use tc_no_actions and tc_for_each_action instead of ifdef CONFIG_NET_CLS_ACT - Replace ENOTSUPP (and some EINVAL) with EOPNOTSUPP - Name the flower command enum - fl_hw_destroy_filter() to return void - nobody uses the return value - mlx5e_tc_init() and mlx5e_tc_cleanup() to be called from the right places. - When adding HW rule fails - fail the command - Rules are added to be processed both by HW and SW unless SKIP_HW is given - Adding patch 6/10 ("net/mlx5e: Relax ndo_setup_tc handle restriction") Main changes from the RFC [1]: - API - Using ndo_setup_tc() instead of switchdev - act_skbedit, act_gact - Actions are not serialized to NIC driver, instead using access functions. - cls_flower - prevent double classification by software by not adding successfuly offloaded filters to the hashtable - Fixed some bugs in original RFC with rule delete - mlx5 - Adding flow table to kernel namespace instead of a new namespace - s/offload/tc/ in many places - no need for a special kconfig since switchdev is not used ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/sched/cls_flower.c')
-rw-r--r--net/sched/cls_flower.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c
index 95b021243233..25d87666bf1e 100644
--- a/net/sched/cls_flower.c
+++ b/net/sched/cls_flower.c
@@ -165,6 +165,51 @@ static void fl_destroy_filter(struct rcu_head *head)
kfree(f);
}
+static void fl_hw_destroy_filter(struct tcf_proto *tp, u64 cookie)
+{
+ struct net_device *dev = tp->q->dev_queue->dev;
+ struct tc_cls_flower_offload offload = {0};
+ struct tc_to_netdev tc;
+
+ if (!tc_should_offload(dev, 0))
+ return;
+
+ offload.command = TC_CLSFLOWER_DESTROY;
+ offload.cookie = cookie;
+
+ tc.type = TC_SETUP_CLSFLOWER;
+ tc.cls_flower = &offload;
+
+ dev->netdev_ops->ndo_setup_tc(dev, tp->q->handle, tp->protocol, &tc);
+}
+
+static void fl_hw_replace_filter(struct tcf_proto *tp,
+ struct flow_dissector *dissector,
+ struct fl_flow_key *mask,
+ struct fl_flow_key *key,
+ struct tcf_exts *actions,
+ u64 cookie, u32 flags)
+{
+ struct net_device *dev = tp->q->dev_queue->dev;
+ struct tc_cls_flower_offload offload = {0};
+ struct tc_to_netdev tc;
+
+ if (!tc_should_offload(dev, flags))
+ return;
+
+ offload.command = TC_CLSFLOWER_REPLACE;
+ offload.cookie = cookie;
+ offload.dissector = dissector;
+ offload.mask = mask;
+ offload.key = key;
+ offload.exts = actions;
+
+ tc.type = TC_SETUP_CLSFLOWER;
+ tc.cls_flower = &offload;
+
+ dev->netdev_ops->ndo_setup_tc(dev, tp->q->handle, tp->protocol, &tc);
+}
+
static bool fl_destroy(struct tcf_proto *tp, bool force)
{
struct cls_fl_head *head = rtnl_dereference(tp->root);
@@ -174,6 +219,7 @@ static bool fl_destroy(struct tcf_proto *tp, bool force)
return false;
list_for_each_entry_safe(f, next, &head->filters, list) {
+ fl_hw_destroy_filter(tp, (u64)f);
list_del_rcu(&f->list);
call_rcu(&f->rcu, fl_destroy_filter);
}
@@ -459,6 +505,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
struct cls_fl_filter *fnew;
struct nlattr *tb[TCA_FLOWER_MAX + 1];
struct fl_flow_mask mask = {};
+ u32 flags = 0;
int err;
if (!tca[TCA_OPTIONS])
@@ -486,6 +533,9 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
}
fnew->handle = handle;
+ if (tb[TCA_FLOWER_FLAGS])
+ flags = nla_get_u32(tb[TCA_FLOWER_FLAGS]);
+
err = fl_set_parms(net, tp, fnew, &mask, base, tb, tca[TCA_RATE], ovr);
if (err)
goto errout;
@@ -498,9 +548,20 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
head->ht_params);
if (err)
goto errout;
- if (fold)
+
+ fl_hw_replace_filter(tp,
+ &head->dissector,
+ &mask.key,
+ &fnew->key,
+ &fnew->exts,
+ (u64)fnew,
+ flags);
+
+ if (fold) {
rhashtable_remove_fast(&head->ht, &fold->ht_node,
head->ht_params);
+ fl_hw_destroy_filter(tp, (u64)fold);
+ }
*arg = (unsigned long) fnew;
@@ -527,6 +588,7 @@ static int fl_delete(struct tcf_proto *tp, unsigned long arg)
rhashtable_remove_fast(&head->ht, &f->ht_node,
head->ht_params);
list_del_rcu(&f->list);
+ fl_hw_destroy_filter(tp, (u64)f);
tcf_unbind_filter(tp, &f->res);
call_rcu(&f->rcu, fl_destroy_filter);
return 0;