mlxsw: spectrum: Introduce multichain TC offload
Jiri Pirko
maintainercover mlxsw: spectrum: Introduce multichain TC offload
From: Jiri Pirko <[email protected]>
This patchset introduces offloading of rules added to chain with non-zero index, which was previously forbidden. Also, goto_chain termination action is offloaded allowing to jump to processing of desired chain.
Jiri Pirko (5):
mlxsw: spectrum: Offload multichain TC rules
net: sched: add couple of goto_chain helpers
mlxsw: spectrum_acl: Allow to get group_id value for a ruleset
mlxsw: spectrum_acl: Provide helper to lookup ruleset
mlxsw: spectrum_flower: Offload goto_chain termination action
drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 3 - drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 10 ++- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 78 +++++++++++++++++----- .../ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 15 +++++ .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 28 ++++++-- include/net/tc_act/tc_gact.h | 20 ++++-- 6 files changed, 124 insertions(+), 30 deletions(-)
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH 1/5 mlxsw: spectrum: Offload multichain TC rules
From: Jiri Pirko <[email protected]>
Reflect chain index coming down from TC core and create a ruleset per chain. Note that only chain 0, being the implicit chain, is bound to the device for processing. The rest of chains have to be "jumped-to" by actions.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 3 --- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 4 ++-- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 28 +++++++++++++++------- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 5 ++-- 4 files changed, 25 insertions(+), 15 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +0 -3
@@ -1733,9 +1733,6 @@ mlxsw_sp_setup_tc_cls_flower(struct mlxsw_sp_port *mlxsw_sp_port,else return -EOPNOTSUPP ; -if (f->common.chain_index) -return -EOPNOTSUPP ; -switch (f->command) {case TC_CLSFLOWER_REPLACE :return mlxsw_sp_flower_replace (mlxsw_sp_port, ingress, f);
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +2 -2
@@ -440,8 +440,8 @@ struct mlxsw_sp_acl_ruleset;/* spectrum_acl.c */ struct mlxsw_afk *mlxsw_sp_acl_afk (struct mlxsw_sp_acl *acl);struct mlxsw_sp_acl_ruleset * -mlxsw_sp_acl_ruleset_get (struct mlxsw_sp *mlxsw_sp, -struct net_device *dev,bool ingress, +mlxsw_sp_acl_ruleset_get (struct mlxsw_sp *mlxsw_sp,struct net_device *dev, +bool ingress,u32 chain_index,enum mlxsw_sp_acl_profile profile);void mlxsw_sp_acl_ruleset_put (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_ruleset *ruleset);
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +20 -8
@@ -74,6 +74,7 @@ struct mlxsw_afk *mlxsw_sp_acl_afk(struct mlxsw_sp_acl *acl)struct mlxsw_sp_acl_ruleset_ht_key {struct net_device *dev;/* dev this ruleset is bound to */ bool ingress; +u32 chain_index;const struct mlxsw_sp_acl_profile_ops *ops; };
@@ -163,7 +164,8 @@ static void mlxsw_sp_acl_ruleset_destroy(struct mlxsw_sp *mlxsw_sp,static int mlxsw_sp_acl_ruleset_bind (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_ruleset *ruleset, -struct net_device *dev,bool ingress) +struct net_device *dev,bool ingress, +u32 chain_index) {const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops;struct mlxsw_sp_acl *acl = mlxsw_sp->acl;
@@ -171,13 +173,20 @@ static int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp, ruleset->ht_key.dev = dev; ruleset->ht_key.ingress = ingress; + ruleset->ht_key.chain_index = chain_index; err =rhashtable_insert_fast (&acl->ruleset_ht, &ruleset->ht_node, mlxsw_sp_acl_ruleset_ht_params);if (err)return err; - err = ops->ruleset_bind (mlxsw_sp, ruleset->priv, dev, ingress); -if (err) - goto err_ops_ruleset_bind; +if (!ruleset->ht_key.chain_index) { +/* We only need ruleset with chain index 0, the implicit one, +* to be directly bound to device. The rest of the rulesets +* are bound by "Goto action set". +*/ + err = ops->ruleset_bind (mlxsw_sp, ruleset->priv, dev, ingress); +if (err) + goto err_ops_ruleset_bind; + }return 0 ; err_ops_ruleset_bind:
@@ -192,7 +201,8 @@ static void mlxsw_sp_acl_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops;struct mlxsw_sp_acl *acl = mlxsw_sp->acl; - ops->ruleset_unbind (mlxsw_sp, ruleset->priv); +if (!ruleset->ht_key.chain_index) + ops->ruleset_unbind (mlxsw_sp, ruleset->priv);rhashtable_remove_fast (&acl->ruleset_ht, &ruleset->ht_node, mlxsw_sp_acl_ruleset_ht_params); }
@@ -212,8 +222,8 @@ static void mlxsw_sp_acl_ruleset_ref_dec(struct mlxsw_sp *mlxsw_sp, }struct mlxsw_sp_acl_ruleset * -mlxsw_sp_acl_ruleset_get (struct mlxsw_sp *mlxsw_sp, -struct net_device *dev,bool ingress, +mlxsw_sp_acl_ruleset_get (struct mlxsw_sp *mlxsw_sp,struct net_device *dev, +bool ingress,u32 chain_index,enum mlxsw_sp_acl_profile profile) {const struct mlxsw_sp_acl_profile_ops *ops;
@@ -229,6 +239,7 @@ mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,memset (&ht_key,0 ,sizeof (ht_key)); ht_key.dev = dev; ht_key.ingress = ingress; + ht_key.chain_index = chain_index; ht_key.ops = ops; ruleset =rhashtable_lookup_fast (&acl->ruleset_ht, &ht_key, mlxsw_sp_acl_ruleset_ht_params);
@@ -239,7 +250,8 @@ mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp, ruleset =mlxsw_sp_acl_ruleset_create (mlxsw_sp, ops);if (IS_ERR (ruleset))return ruleset; - err =mlxsw_sp_acl_ruleset_bind (mlxsw_sp, ruleset, dev, ingress); + err =mlxsw_sp_acl_ruleset_bind (mlxsw_sp, ruleset, dev, + ingress, chain_index);if (err) goto err_ruleset_bind;return ruleset;
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +3 -2
@@ -378,6 +378,7 @@ int mlxsw_sp_flower_replace(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,int err; ruleset =mlxsw_sp_acl_ruleset_get (mlxsw_sp, dev, ingress, + f->common.chain_index,MLXSW_SP_ACL_PROFILE_FLOWER );if (IS_ERR (ruleset))return PTR_ERR (ruleset);
@@ -421,7 +422,7 @@ void mlxsw_sp_flower_destroy(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,struct mlxsw_sp_acl_rule *rule; ruleset =mlxsw_sp_acl_ruleset_get (mlxsw_sp, mlxsw_sp_port->dev, - ingress, + ingress, f->common.chain_index,MLXSW_SP_ACL_PROFILE_FLOWER );if (IS_ERR (ruleset))return ;
@@ -447,7 +448,7 @@ int mlxsw_sp_flower_stats(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,int err; ruleset =mlxsw_sp_acl_ruleset_get (mlxsw_sp, mlxsw_sp_port->dev, - ingress, + ingress, f->common.chain_index,MLXSW_SP_ACL_PROFILE_FLOWER );if (WARN_ON (IS_ERR (ruleset)))return -EINVAL ;
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH 2/5 net: sched: add couple of goto_chain helpers
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Add helpers to find out if a gact instance is goto_chain termination action and to get chain index.
--- include/net/tc_act/tc_gact.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
include/net/tc_act/tc_gact.h +16 -4
@@ -15,7 +15,8 @@ struct tcf_gact { };#define to_gact (a) ((struct tcf_gact *)a) -static inline bool __is_tcf_gact_act (const struct tc_action *a,int act) +static inline bool __is_tcf_gact_act (const struct tc_action *a,int act, +bool is_ext) {#ifdef CONFIG_NET_CLS_ACT struct tcf_gact *gact;
@@ -24,7 +25,8 @@ static inline bool __is_tcf_gact_act(const struct tc_action *a, int act)return false; gact =to_gact (a); -if (gact->tcf_action == act) +if ((!is_ext && gact->tcf_action == act) || + (is_ext &&TC_ACT_EXT_CMP (gact->tcf_action, act)))return true;#endif
@@ -33,12 +35,22 @@ static inline bool __is_tcf_gact_act(const struct tc_action *a, int act)static inline bool is_tcf_gact_shot (const struct tc_action *a) { -return __is_tcf_gact_act (a,TC_ACT_SHOT ); +return __is_tcf_gact_act (a,TC_ACT_SHOT , false); }static inline bool is_tcf_gact_trap (const struct tc_action *a) { -return __is_tcf_gact_act (a,TC_ACT_TRAP ); +return __is_tcf_gact_act (a,TC_ACT_TRAP , false); +} + +static inline bool is_tcf_gact_goto_chain (const struct tc_action *a) +{ +return __is_tcf_gact_act (a,TC_ACT_GOTO_CHAIN , true); +} + +static inline u32 tcf_gact_goto_chain_index (const struct tc_action *a) +{ +return a->goto_chain->index; }#endif /* __NET_TC_GACT_H */
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH 3/5 mlxsw: spectrum_acl: Allow to get group_id value for a ruleset
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
For goto_chain action we need to know group_id of a ruleset to jump to. Provide infrastructure in order to get it.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 2 ++ drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 7 +++++++ drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 15 +++++++++++++++ 3 files changed, 24 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +2 -0
@@ -417,6 +417,7 @@ struct mlxsw_sp_acl_profile_ops {int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv,struct net_device *dev,bool ingress);void (*ruleset_unbind)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv); +u16 (*ruleset_group_id)(void *ruleset_priv);size_t rule_priv_size; int (*rule_add)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv, void *rule_priv,
@@ -445,6 +446,7 @@ mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp, struct net_device *dev, enum mlxsw_sp_acl_profile profile);void mlxsw_sp_acl_ruleset_put (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_ruleset *ruleset); +u16 mlxsw_sp_acl_ruleset_group_id (struct mlxsw_sp_acl_ruleset *ruleset);struct mlxsw_sp_acl_rule_info *mlxsw_sp_acl_rulei_create (struct mlxsw_sp_acl *acl);
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +7 -0
@@ -267,6 +267,13 @@ void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,mlxsw_sp_acl_ruleset_ref_dec (mlxsw_sp, ruleset); } +u16 mlxsw_sp_acl_ruleset_group_id (struct mlxsw_sp_acl_ruleset *ruleset) +{ +const struct mlxsw_sp_acl_profile_ops *ops = ruleset->ht_key.ops; + +return ops->ruleset_group_id (ruleset->priv); +} +static int mlxsw_sp_acl_rulei_counter_alloc (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_rule_info *rulei)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +15 -0
@@ -295,6 +295,12 @@ mlxsw_sp_acl_tcam_group_unbind(struct mlxsw_sp *mlxsw_sp,mlxsw_reg_write (mlxsw_sp->core,MLXSW_REG (ppbt), ppbt_pl); } +static u16 +mlxsw_sp_acl_tcam_group_id (struct mlxsw_sp_acl_tcam_group *group) +{ +return group->id; +} +static unsigned int mlxsw_sp_acl_tcam_region_prio (struct mlxsw_sp_acl_tcam_region *region) {
@@ -1063,6 +1069,14 @@ mlxsw_sp_acl_tcam_flower_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,mlxsw_sp_acl_tcam_group_unbind (mlxsw_sp, &ruleset->group); } +static u16 +mlxsw_sp_acl_tcam_flower_ruleset_group_id (void *ruleset_priv) +{ +struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv; + +return mlxsw_sp_acl_tcam_group_id (&ruleset->group); +} + static int mlxsw_sp_acl_tcam_flower_rule_add(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv, void *rule_priv,
@@ -1099,6 +1113,7 @@ static const struct mlxsw_sp_acl_profile_ops mlxsw_sp_acl_tcam_flower_ops = { .ruleset_del = mlxsw_sp_acl_tcam_flower_ruleset_del, .ruleset_bind = mlxsw_sp_acl_tcam_flower_ruleset_bind, .ruleset_unbind = mlxsw_sp_acl_tcam_flower_ruleset_unbind, + .ruleset_group_id = mlxsw_sp_acl_tcam_flower_ruleset_group_id, .rule_priv_size = sizeof(struct mlxsw_sp_acl_tcam_flower_rule), .rule_add = mlxsw_sp_acl_tcam_flower_rule_add, .rule_del = mlxsw_sp_acl_tcam_flower_rule_del,
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH 4/5 mlxsw: spectrum_acl: Provide helper to lookup ruleset
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
We need to lookup ruleset in order to offload goto_chain termination action. This patch adds it.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 4 ++ drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 45 ++++++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +4 -0
@@ -441,6 +441,10 @@ struct mlxsw_sp_acl_ruleset;/* spectrum_acl.c */ struct mlxsw_afk *mlxsw_sp_acl_afk (struct mlxsw_sp_acl *acl);struct mlxsw_sp_acl_ruleset * +mlxsw_sp_acl_ruleset_lookup (struct mlxsw_sp *mlxsw_sp,struct net_device *dev, +bool ingress,u32 chain_index, +enum mlxsw_sp_acl_profile profile); +struct mlxsw_sp_acl_ruleset *mlxsw_sp_acl_ruleset_get (struct mlxsw_sp *mlxsw_sp,struct net_device *dev,bool ingress,u32 chain_index,enum mlxsw_sp_acl_profile profile);
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +37 -8
63 lines not on this page · raw message
Signature · 1 line
2.9.3
Jiri Pirko
maintainerPATCH 5/5 mlxsw: spectrum_flower: Offload goto_chain termination action
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
If action is gact goto_chain, offload it to HW by jumping to another ruleset.
--- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +19 -4
@@ -45,7 +45,7 @@#include "core_acl_flex_keys.h" static int mlxsw_sp_flower_parse_actions (struct mlxsw_sp *mlxsw_sp, -struct net_device *dev, +struct net_device *dev,bool ingress,struct mlxsw_sp_acl_rule_info *rulei,struct tcf_exts *exts) {
@@ -71,6 +71,20 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp, err =mlxsw_sp_acl_rulei_act_trap (rulei);if (err)return err; + }else if (is_tcf_gact_goto_chain (a)) { +u32 chain_index =tcf_gact_goto_chain_index (a); +struct mlxsw_sp_acl_ruleset *ruleset; +u16 group_id; + + ruleset =mlxsw_sp_acl_ruleset_lookup (mlxsw_sp, dev, + ingress, + chain_index, +MLXSW_SP_ACL_PROFILE_FLOWER ); +if (IS_ERR (ruleset)) +return PTR_ERR (ruleset); + + group_id =mlxsw_sp_acl_ruleset_group_id (ruleset); +mlxsw_sp_acl_rulei_act_jump (rulei, group_id); }else if (is_tcf_mirred_egress_redirect (a)) {int ifindex =tcf_mirred_ifindex (a);struct net_device *out_dev;
@@ -246,7 +260,7 @@ static int mlxsw_sp_flower_parse_ip(struct mlxsw_sp *mlxsw_sp, }static int mlxsw_sp_flower_parse (struct mlxsw_sp *mlxsw_sp, -struct net_device *dev, +struct net_device *dev,bool ingress,struct mlxsw_sp_acl_rule_info *rulei,struct tc_cls_flower_offload *f) {
@@ -364,7 +378,8 @@ static int mlxsw_sp_flower_parse(struct mlxsw_sp *mlxsw_sp,if (err)return err; -return mlxsw_sp_flower_parse_actions (mlxsw_sp, dev, rulei, f->exts); +return mlxsw_sp_flower_parse_actions (mlxsw_sp, dev, ingress, + rulei, f->exts); } int mlxsw_sp_flower_replace(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,
@@ -390,7 +405,7 @@ int mlxsw_sp_flower_replace(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress, } rulei =mlxsw_sp_acl_rule_rulei (rule); - err =mlxsw_sp_flower_parse (mlxsw_sp, dev, rulei, f); + err =mlxsw_sp_flower_parse (mlxsw_sp, dev, ingress, rulei, f);if (err) goto err_flower_parse;
Signature · 1 line
2.9.3
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Wed, 23 Aug 2017 10:06:52 +0200
Quoted 6 lines
From: Jiri Pirko <[email protected]>
This patchset introduces offloading of rules added to chain with non-zero index, which was previously forbidden. Also,
goto_chaintermination action is offloaded allowing to jump to processing of desired chain.
Series applied, thanks Jiri.