add flow_rule infrastructure
Subsystems (13)
cover add flow_rule infrastructure
This patchset introduces a kernel intermediate representation (IR) to express ACL hardware offloads, this is heavily based on the existing flow dissector infrastructure and the TC actions. This IR can be used by different frontend ACL interfaces such as ethtool_rxnfc and tc to represent ACL hardware offloads. Main goal is to simplify the development of ACL hardware offloads for the existing frontend interfaces, the idea is that driver developers do not need to add one specific parser for each ACL frontend, instead each frontend can just generate this flow_rule IR and pass it to drivers to populate the hardware IR.
. ethtool_rxnfc tc
| (ioctl) (netlink)
| | | translate native
Frontend | | | interface representation
| | | to flow_rule IR
| | |
. \/ \/
. flow_rule IR
| |
Drivers | | parsing of flow_rule IR
| | to populate hardware IR
| \/
. hardware IR (driver)
For design and implementation details, please have a look at:
https://lwn.net/Articles/766695/
As an example, with this patchset, it should be possible to simplify the existing net/qede driver which already has two parsers to populate the hardware IR, one for ethtool_rxnfc interface and another for tc.
This batch is composed of 10 patches:
Patch #1 adds the flow_match structure, this includes the
flow_rule_match_key() interface to check for existing selectors that are in used in the rule and the flow_rule_match_*() functions to fetch the selector value and the mask. This also introduces the initial flow_rule structure skeleton to avoid a follow up patch that would update the same LoCs.
Patch #2 makes changes to packet edit parser of mlx5e driver, to prepare
introduction of the new flow_action to mangle packets.
Patch #3 Introduce flow_action infrastructure. This infrastructure is
based on the TC actions. Patch #8 extends it so it also supports two new actions that are only available through the ethtool_rxnfc interface.
Patch #4 Add function to translate TC action to flow_action from
cls_flower.
Patch #5 Add infrastructure to fetch statistics into container structure
and synchronize them to TC actions from cls_flower. Another preparation patch before patch #7, so we can stop exposing the TC action native layout to the drivers.
Patch #6 Use flow_action infrastructure from drivers.
Patch #7 Do not expose TC actions to drivers anymore, now that drivers
have been converted to use the flow_action infrastructure after patch #5.
Patch #8 Support to wake-up-on-lan and queue actions for the flow_action
infrastructure, two actions supported by NICs. This is used by the ethtool_rx_flow interface.
Patch #9 Add a function to translate from ethtool_rx_flow_spec structure
to the flow_action structure. This is a simple enough for its first client: the ethtool_rxnfc interface in the bcm_sf2 driver.
Patch #10 Update bcm_sf2 to use this new translator function and
update codebase to configure hardware IR using the flow_action representation. This will allow later development of cls_flower using the same codebase from the driver.
This patchset has passed here functional tests of the codepath that generates the flow_rule structure and the functions to implement the parsers that populate the hardware IR.
Thanks.
Pablo Neira Ayuso (10):
flow_dissector: add flow_rule and flow_match structures and use them net/mlx5e: support for two independent packet edit actions
flow_dissector: add flow action infrastructure
cls_api: add translator to flow_action representation
cls_flower: add statistics retrieval infrastructure and use it
drivers: net: use flow action infrastructure
cls_flower: don't expose TC actions to drivers anymore
flow_dissector: add wake-up-on-lan and queue to flow_action
flow_dissector: add basic ethtool_rx_flow_spec to flow_rule structure translator
dsa: bcm_sf2: use flow_rule infrastructure
drivers/net/dsa/bcm_sf2_cfp.c | 103 ++- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 252 +++---- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 450 ++++++------- drivers/net/ethernet/intel/i40e/i40e_main.c | 178 ++--- drivers/net/ethernet/intel/iavf/iavf_main.c | 195 +++--- drivers/net/ethernet/intel/igb/igb_main.c | 64 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 743 ++++++++++----------- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 259 ++++--- drivers/net/ethernet/netronome/nfp/flower/action.c | 196 +++--- drivers/net/ethernet/netronome/nfp/flower/match.c | 416 ++++++------ .../net/ethernet/netronome/nfp/flower/offload.c | 151 ++--- drivers/net/ethernet/qlogic/qede/qede_filter.c | 93 ++- include/net/flow_dissector.h | 185 +++++ include/net/pkt_cls.h | 23 +- net/core/flow_dissector.c | 341 ++++++++++ net/sched/cls_api.c | 113 ++++ net/sched/cls_flower.c | 42 +- 18 files changed, 2120 insertions(+), 1686 deletions(-)
Signature · 1 line
2.11.0
PATCH 2/10 net/mlx5e: support for two independent packet edit actions
This patch adds pedit_headers_action structure to store the result of parsing tc pedit actions. Then, it calls alloc_tc_pedit_action() to populate the mlx5e hardware intermediate representation once all actions have been parsed.
This patch comes in preparation for the new flow_action infrastructure, where each packet mangling comes in an separated action, ie. not packed as in tc pedit.
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 81 ++++++++++++++++++------- 1 file changed, 59 insertions(+), 22 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +59 -22
@@ -1748,6 +1748,12 @@ struct pedit_headers {struct udphdr udp; }; +struct pedit_headers_action { +struct pedit_headers vals; +struct pedit_headers masks; +u32 pedits; +}; +static int pedit_header_offsets[] = { [TCA_PEDIT_KEY_EX_HDR_TYPE_ETH ] = offsetof(struct pedit_headers , eth), [TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 ] = offsetof(struct pedit_headers , ip4),
@@ -1759,16 +1765,15 @@ static int pedit_header_offsets[] = {#define pedit_header (_ph, _htype) ((void *)(_ph) + pedit_header_offsets[_htype])static int set_pedit_val (u8 hdr_type,u32 mask,u32 val,u32 offset, -struct pedit_headers *masks, -struct pedit_headers *vals) +struct pedit_headers_action *hdrs) {u32 *curr_pmask, *curr_pval;if (hdr_type >= __PEDIT_HDR_TYPE_MAX) goto out_err; - curr_pmask = (u32 *)(pedit_header (masks, hdr_type) + offset); - curr_pval = (u32 *)(pedit_header (vals, hdr_type) + offset); + curr_pmask = (u32 *)(pedit_header (&hdrs->masks, hdr_type) + offset); + curr_pval = (u32 *)(pedit_header (&hdrs->vals, hdr_type) + offset);if (*curr_pmask & mask)/* disallow acting twice on the same location */ goto out_err;
@@ -1824,8 +1829,7 @@ static struct mlx5_fields fields[] = {* max from the SW pedit action. On success, it says how many HW actions were * actually parsed. */ -static int offload_pedit_fields (struct pedit_headers *masks, -struct pedit_headers *vals, +static int offload_pedit_fields (struct pedit_headers_action *hdrs,struct mlx5e_tc_flow_parse_attr *parse_attr,struct netlink_ext_ack *extack) {
@@ -1840,10 +1844,10 @@ static int offload_pedit_fields(struct pedit_headers *masks,__be16 mask_be16;void *action; - set_masks = &masks[TCA_PEDIT_KEY_EX_CMD_SET ]; - add_masks = &masks[TCA_PEDIT_KEY_EX_CMD_ADD ]; - set_vals = &vals[TCA_PEDIT_KEY_EX_CMD_SET ]; - add_vals = &vals[TCA_PEDIT_KEY_EX_CMD_ADD ]; + set_masks = &hdrs[TCA_PEDIT_KEY_EX_CMD_SET ].masks; + add_masks = &hdrs[TCA_PEDIT_KEY_EX_CMD_ADD ].masks; + set_vals = &hdrs[TCA_PEDIT_KEY_EX_CMD_SET ].vals; + add_vals = &hdrs[TCA_PEDIT_KEY_EX_CMD_ADD ].vals; action_size =MLX5_UN_SZ_BYTES (set_action_in_add_action_in_auto); action = parse_attr->mod_hdr_actions;
@@ -1939,12 +1943,14 @@ static int offload_pedit_fields(struct pedit_headers *masks, }static int alloc_mod_hdr_actions (struct mlx5e_priv *priv, -const struct tc_action *a,int namespace, +struct pedit_headers_action *hdrs, +int namespace,struct mlx5e_tc_flow_parse_attr *parse_attr) {int nkeys, action_size, max_actions; - nkeys =tcf_pedit_nkeys (a); + nkeys = hdrs[TCA_PEDIT_KEY_EX_CMD_SET ].pedits + + hdrs[TCA_PEDIT_KEY_EX_CMD_ADD ].pedits; action_size =MLX5_UN_SZ_BYTES (set_action_in_add_action_in_auto);if (namespace ==MLX5_FLOW_NAMESPACE_FDB )/* FDB offloading */
@@ -1968,18 +1974,15 @@ static const struct pedit_headers zero_masks = {};static int parse_tc_pedit_action (struct mlx5e_priv *priv,const struct tc_action *a,int namespace,struct mlx5e_tc_flow_parse_attr *parse_attr, +struct pedit_headers_action *hdrs,struct netlink_ext_ack *extack) { -struct pedit_headers masks[__PEDIT_CMD_MAX], vals[__PEDIT_CMD_MAX], *cmd_masks;int nkeys, i, err = -EOPNOTSUPP ;u32 mask, val, offset;u8 cmd, htype; nkeys =tcf_pedit_nkeys (a); -memset (masks,0 ,sizeof (struct pedit_headers ) * __PEDIT_CMD_MAX); -memset (vals,0 ,sizeof (struct pedit_headers ) * __PEDIT_CMD_MAX); -for (i =0 ; i < nkeys; i++) { htype =tcf_pedit_htype (a, i); cmd =tcf_pedit_cmd (a, i);
@@ -2000,21 +2003,37 @@ static int parse_tc_pedit_action(struct mlx5e_priv *priv, val =tcf_pedit_val (a, i); offset =tcf_pedit_offset (a, i); - err =set_pedit_val (htype, ~mask, val, offset, &masks[cmd], &vals[cmd]); + err =set_pedit_val (htype, ~mask, val, offset, &hdrs[cmd]);if (err) goto out_err; + + hdrs[cmd].pedits++; } - err =alloc_mod_hdr_actions (priv, a, namespace, parse_attr); +return 0 ; +out_err: +return err; +} + +static int alloc_tc_pedit_action (struct mlx5e_priv *priv,int namespace, +struct mlx5e_tc_flow_parse_attr *parse_attr, +struct pedit_headers_action *hdrs, +struct netlink_ext_ack *extack) +{ +struct pedit_headers *cmd_masks; +int err; +u8 cmd; + + err =alloc_mod_hdr_actions (priv, hdrs, namespace, parse_attr);if (err) goto out_err; - err =offload_pedit_fields (masks, vals, parse_attr, extack); + err =offload_pedit_fields (hdrs, parse_attr, extack);if (err <0 ) goto out_dealloc_parsed_actions;for (cmd =0 ; cmd < __PEDIT_CMD_MAX; cmd++) { - cmd_masks = &masks[cmd]; + cmd_masks = &hdrs[cmd].masks;if (memcmp (cmd_masks, &zero_masks,sizeof (zero_masks))) {NL_SET_ERR_MSG_MOD (extack,"attempt to offload an unsupported field" );
@@ -2156,6 +2175,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,struct mlx5e_tc_flow *flow, struct netlink_ext_ack *extack) { + struct pedit_headers_action hdrs[__PEDIT_CMD_MAX] = {};struct mlx5_nic_flow_attr *attr = flow->nic_attr;const struct tc_action *a;LIST_HEAD (actions);
@@ -2178,7 +2198,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,if (is_tcf_pedit (a)) { err =parse_tc_pedit_action (priv, a,MLX5_FLOW_NAMESPACE_KERNEL , - parse_attr, extack); + parse_attr, hdrs, extack);if (err)return err;
@@ -2232,6 +2252,14 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,return -EINVAL ; } +if (hdrs[TCA_PEDIT_KEY_EX_CMD_SET ].pedits || + hdrs[TCA_PEDIT_KEY_EX_CMD_ADD ].pedits) { + err =alloc_tc_pedit_action (priv,MLX5_FLOW_NAMESPACE_KERNEL , + parse_attr, hdrs, extack); +if (err) +return err; + } + attr->action = action;if (!actions_match_supported (priv, exts, parse_attr, flow, extack))return -EOPNOTSUPP ;
@@ -2778,6 +2806,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,struct mlx5e_tc_flow *flow, struct netlink_ext_ack *extack) { + struct pedit_headers_action hdrs[__PEDIT_CMD_MAX] = {};struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;struct mlx5_esw_flow_attr *attr = flow->esw_attr;struct mlx5e_rep_priv *rpriv = priv->ppriv;
@@ -2803,7 +2832,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,if (is_tcf_pedit (a)) { err =parse_tc_pedit_action (priv, a,MLX5_FLOW_NAMESPACE_FDB , - parse_attr, extack); + parse_attr, hdrs, extack);if (err)return err;
@@ -2909,6 +2938,14 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,return -EINVAL ; } +if (hdrs[TCA_PEDIT_KEY_EX_CMD_SET ].pedits || + hdrs[TCA_PEDIT_KEY_EX_CMD_ADD ].pedits) { + err =alloc_tc_pedit_action (priv,MLX5_FLOW_NAMESPACE_KERNEL , + parse_attr, hdrs, extack); +if (err) +return err; + } + attr->action = action;if (!actions_match_supported (priv, exts, parse_attr, flow, extack))return -EOPNOTSUPP ;
Signature · 1 line
2.11.0
PATCH 3/10 flow_dissector: add flow action infrastructure
In reply to Pablo Neira AyusoThis new infrastructure defines the nic actions that you can perform from existing network drivers. This infrastructure allows us to avoid a direct dependency with the native software TC action representation.
--- include/net/flow_dissector.h | 70 ++++++++++++++++++++++++++++++++++++++++++++ net/core/flow_dissector.c | 18 ++++++++++++ 2 files changed, 88 insertions(+)
include/net/flow_dissector.h +70 -0
@@ -402,8 +402,78 @@ void flow_rule_match_enc_keyid(const struct flow_rule *rule,void flow_rule_match_enc_opts (const struct flow_rule *rule,struct flow_match_enc_opts *out); +enum flow_action_key_id { +FLOW_ACTION_KEY_ACCEPT =0 , +FLOW_ACTION_KEY_DROP , +FLOW_ACTION_KEY_TRAP , +FLOW_ACTION_KEY_GOTO , +FLOW_ACTION_KEY_REDIRECT , +FLOW_ACTION_KEY_MIRRED , +FLOW_ACTION_KEY_VLAN_PUSH , +FLOW_ACTION_KEY_VLAN_POP , +FLOW_ACTION_KEY_VLAN_MANGLE , +FLOW_ACTION_KEY_TUNNEL_ENCAP , +FLOW_ACTION_KEY_TUNNEL_DECAP , +FLOW_ACTION_KEY_MANGLE , +FLOW_ACTION_KEY_ADD , +FLOW_ACTION_KEY_CSUM , +FLOW_ACTION_KEY_MARK , +}; + +/* This is mirroring enum pedit_header_type definition for easy mapping between +* tc pedit action. Legacy TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is mapped to +* FLOW_ACT_MANGLE_UNSPEC, which is supported by no driver. +*/ +enum flow_act_mangle_base { +FLOW_ACT_MANGLE_UNSPEC =0 , +FLOW_ACT_MANGLE_HDR_TYPE_ETH , +FLOW_ACT_MANGLE_HDR_TYPE_IP4 , +FLOW_ACT_MANGLE_HDR_TYPE_IP6 , +FLOW_ACT_MANGLE_HDR_TYPE_TCP , +FLOW_ACT_MANGLE_HDR_TYPE_UDP , +}; + +struct flow_action_key { +enum flow_action_key_id id; +union { +u32 chain_index;/* FLOW_ACTION_KEY_GOTO */ +struct net_device *dev;/* FLOW_ACTION_KEY_REDIRECT */ +struct {/* FLOW_ACTION_KEY_VLAN */ +u16 vid; +__be16 proto; +u8 prio; + } vlan; +struct {/* FLOW_ACTION_KEY_PACKET_EDIT */ +enum flow_act_mangle_base htype; +u32 offset; +u32 mask; +u32 val; + } mangle; +const struct ip_tunnel_info *tunnel;/* FLOW_ACTION_KEY_TUNNEL_ENCAP */ +u32 csum_flags;/* FLOW_ACTION_KEY_CSUM */ +u32 mark;/* FLOW_ACTION_KEY_MARK */ + }; +}; + +struct flow_action { +int num_keys; +struct flow_action_key *keys; +}; + +int flow_action_init (struct flow_action *flow_action,int num_acts); +void flow_action_free (struct flow_action *flow_action); + +static inline bool flow_action_has_keys (const struct flow_action *action) +{ +return action->num_keys; +} + +#define flow_action_for_each (__i, __act, __actions) \ + for (__i = 0, __act = &(__actions)->keys[0]; __i < (__actions)->num_keys; __act = &(__actions)->keys[++__i]) +struct flow_rule {struct flow_match match; +struct flow_action action; }; static inline bool flow_rule_match_key(const struct flow_rule *rule,
net/core/flow_dissector.c +18 -0
@@ -258,6 +258,24 @@ void flow_rule_match_enc_opts(const struct flow_rule *rule, }EXPORT_SYMBOL (flow_rule_match_enc_opts); +int flow_action_init (struct flow_action *flow_action,int num_acts) +{ + flow_action->keys =kmalloc (sizeof (struct flow_action_key ) * num_acts, +GFP_KERNEL ); +if (!flow_action->keys) +return -ENOMEM ; + + flow_action->num_keys = num_acts; +return 0 ; +} +EXPORT_SYMBOL (flow_action_init); + +void flow_action_free (struct flow_action *flow_action) +{ +kfree (flow_action->keys); +} +EXPORT_SYMBOL (flow_action_free); +/** * __skb_flow_get_ports - extract the upper layer ports and return them * @skb: sk_buff to extract the ports from
Signature · 1 line
2.11.0
PATCH 4/10 cls_api: add translator to flow_action representation
In reply to Pablo Neira AyusoThis patch implements a new function to translate from native TC action to the new flow_action representation. Moreover, this patch also updates cls_flower to use this new function.
--- include/net/pkt_cls.h | 3 ++ net/sched/cls_api.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ net/sched/cls_flower.c | 15 ++++++- 3 files changed, 130 insertions(+), 1 deletion(-)
include/net/pkt_cls.h +3 -0
@@ -619,6 +619,9 @@ tcf_match_indev(struct sk_buff *skb, int ifindex) }#endif /* CONFIG_NET_CLS_IND */ +int tc_setup_flow_action (struct flow_action *flow_action, +const struct tcf_exts *exts); +int tc_setup_cb_call (struct tcf_block *block,struct tcf_exts *exts,enum tc_setup_type type,void *type_data,bool err_stop);
net/sched/cls_api.c +113 -0
125 lines not on this page · raw message
net/sched/cls_flower.c +14 -1
@@ -101,6 +101,7 @@ struct cls_fl_filter {u32 in_hw_count;struct rcu_work rwork;struct net_device *hw_dev; +struct flow_action action; };static const struct rhashtable_params mask_ht_params = {
@@ -312,18 +313,27 @@ static int fl_hw_replace_filter(struct tcf_proto *tp, cls_flower.exts = &f->exts; cls_flower.classid = f->res.classid; +if (tc_setup_flow_action (&f->action, &f->exts) <0 ) +return -ENOMEM ; + + cls_flower.rule.action.keys = f->action.keys; + cls_flower.rule.action.num_keys = f->action.num_keys; + err =tc_setup_cb_call (block, &f->exts,TC_SETUP_CLSFLOWER , &cls_flower, skip_sw);if (err <0 ) {fl_hw_destroy_filter (tp, f,NULL ); +flow_action_free (&f->action);return err; }else if (err >0 ) { f->in_hw_count = err;tcf_block_offload_inc (block, &f->flags); } -if (skip_sw && !(f->flags &TCA_CLS_FLAGS_IN_HW )) +if (skip_sw && !(f->flags &TCA_CLS_FLAGS_IN_HW )) { +flow_action_free (&f->action);return -EINVAL ; + }return 0 ; }
@@ -350,6 +360,7 @@ static bool __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f,bool async =tcf_exts_get_net (&f->exts);bool last; +flow_action_free (&f->action);idr_remove (&head->handle_idr, f->handle);list_del_rcu (&f->list); last =fl_mask_put (head, f->mask, async);
@@ -1353,6 +1364,8 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb, cls_flower.rule.match.mask = &mask->key; cls_flower.rule.match.key = &f->mkey; cls_flower.exts = &f->exts; + cls_flower.rule.action.num_keys = f->action.num_keys; + cls_flower.rule.action.keys = f->action.keys; cls_flower.classid = f->res.classid; err =cb (TC_SETUP_CLSFLOWER , &cls_flower, cb_priv);
Signature · 1 line
2.11.0
PATCH 5/10 cls_flower: add statistics retrieval infrastructure and use it
In reply to Pablo Neira AyusoThis patch provides a tc_cls_flower_stats structure that acts as container for tc_cls_flower_offload, then we can use to restore the statistics on the existing TC actions. Hence, tcf_exts_stats_update() is not used from drivers.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 4 ++-- drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 6 +++--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c | 2 +- drivers/net/ethernet/netronome/nfp/flower/offload.c | 6 +++--- include/net/pkt_cls.h | 15 +++++++++++++++ net/sched/cls_flower.c | 4 ++++ 7 files changed, 29 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +2 -2
@@ -1366,8 +1366,8 @@ static int bnxt_tc_get_flow_stats(struct bnxt *bp, lastused = flow->lastused;spin_unlock (&flow->stats_lock); -tcf_exts_stats_update (tc_flow_cmd->exts, stats.bytes, stats.packets, - lastused); +tc_cls_flower_stats_update (tc_flow_cmd, stats.bytes, stats.packets, + lastused);return 0 ; }
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +3 -3
@@ -807,9 +807,9 @@ int cxgb4_tc_flower_stats(struct net_device *dev,if (ofld_stats->packet_count != packets) {if (ofld_stats->prev_packet_count != packets) ofld_stats->last_used = jiffies; -tcf_exts_stats_update (cls->exts, bytes - ofld_stats->byte_count, - packets - ofld_stats->packet_count, - ofld_stats->last_used); +tc_cls_flower_stats_update (cls, bytes - ofld_stats->byte_count, + packets - ofld_stats->packet_count, + ofld_stats->last_used); ofld_stats->packet_count = packets; ofld_stats->byte_count = bytes;
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +1 -1
@@ -3224,7 +3224,7 @@ int mlx5e_stats_flower(struct mlx5e_priv *priv,mlx5_fc_query_cached (counter, &bytes, &packets, &lastuse); -tcf_exts_stats_update (f->exts, bytes, packets, lastuse); +tc_cls_flower_stats_update (f, bytes, packets, lastuse);return 0 ; }
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +1 -1
@@ -460,7 +460,7 @@ int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,if (err) goto err_rule_get_stats; -tcf_exts_stats_update (f->exts, bytes, packets, lastuse); +tc_cls_flower_stats_update (f, bytes, packets, lastuse);mlxsw_sp_acl_ruleset_put (mlxsw_sp, ruleset);return 0 ;
drivers/net/ethernet/netronome/nfp/flower/offload.c +3 -3
@@ -532,9 +532,9 @@ nfp_flower_get_stats(struct nfp_app *app, struct net_device *netdev, ctx_id =be32_to_cpu (nfp_flow->meta.host_ctx_id);spin_lock_bh (&priv->stats_lock); -tcf_exts_stats_update (flow->exts, priv->stats[ctx_id].bytes, - priv->stats[ctx_id].pkts, - priv->stats[ctx_id].used); +tc_cls_flower_stats_update (flow, priv->stats[ctx_id].bytes, + priv->stats[ctx_id].pkts, + priv->stats[ctx_id].used); priv->stats[ctx_id].pkts =0 ; priv->stats[ctx_id].bytes =0 ;
include/net/pkt_cls.h +15 -0
@@ -758,6 +758,12 @@ enum tc_fl_command { TC_CLSFLOWER_TMPLT_DESTROY, }; +struct tc_cls_flower_stats { +u64 pkts; +u64 bytes; +u64 lastused; +}; +struct tc_cls_flower_offload {struct tc_cls_common_offload common;enum tc_fl_command command;
@@ -765,8 +771,17 @@ struct tc_cls_flower_offload {struct flow_rule rule;struct tcf_exts *exts;u32 classid; +struct tc_cls_flower_stats stats; }; +static inline void tc_cls_flower_stats_update (struct tc_cls_flower_offload *cls_flower, +u64 pkts,u64 bytes,u64 lastused) +{ + cls_flower->stats.pkts = pkts; + cls_flower->stats.bytes = bytes; + cls_flower->stats.lastused = lastused; +} +enum tc_matchall_command {TC_CLSMATCHALL_REPLACE ,TC_CLSMATCHALL_DESTROY ,
net/sched/cls_flower.c +4 -0
@@ -351,6 +351,10 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f)tc_setup_cb_call (block, &f->exts,TC_SETUP_CLSFLOWER , &cls_flower, false); + +tcf_exts_stats_update (&f->exts, cls_flower.stats.bytes, + cls_flower.stats.pkts, + cls_flower.stats.lastused); } static bool __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f,
Signature · 1 line
2.11.0
PATCH 7/10 cls_flower: don't expose TC actions to drivers anymore
In reply to Pablo Neira AyusoNow that drivers have been converted to use the flow action infrastructure, remove this field from the tc_cls_flower_offload structure.
--- include/net/pkt_cls.h | 1 - net/sched/cls_flower.c | 5 ----- 2 files changed, 6 deletions(-)
include/net/pkt_cls.h +0 -1
@@ -769,7 +769,6 @@ struct tc_cls_flower_offload {enum tc_fl_command command;unsigned long cookie;struct flow_rule rule; -struct tcf_exts *exts;u32 classid;struct tc_cls_flower_stats stats; };
net/sched/cls_flower.c +0 -5
@@ -310,7 +310,6 @@ static int fl_hw_replace_filter(struct tcf_proto *tp, cls_flower.rule.match.dissector = &f->mask->dissector; cls_flower.rule.match.mask = &f->mask->key; cls_flower.rule.match.key = &f->mkey; - cls_flower.exts = &f->exts; cls_flower.classid = f->res.classid;if (tc_setup_flow_action (&f->action, &f->exts) <0 )
@@ -346,7 +345,6 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f)tc_cls_common_offload_init (&cls_flower.common, tp, f->flags,NULL ); cls_flower.command =TC_CLSFLOWER_STATS ; cls_flower.cookie = (unsigned long ) f; - cls_flower.exts = &f->exts; cls_flower.classid = f->res.classid; tc_setup_cb_call(block, &f->exts, TC_SETUP_CLSFLOWER,
@@ -1367,7 +1365,6 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb, cls_flower.rule.match.dissector = &mask->dissector; cls_flower.rule.match.mask = &mask->key; cls_flower.rule.match.key = &f->mkey; - cls_flower.exts = &f->exts; cls_flower.rule.action.num_keys = f->action.num_keys; cls_flower.rule.action.keys = f->action.keys; cls_flower.classid = f->res.classid;
@@ -1392,7 +1389,6 @@ static void fl_hw_create_tmplt(struct tcf_chain *chain, {struct tc_cls_flower_offload cls_flower = {};struct tcf_block *block = chain->block; -struct tcf_exts dummy_exts = {0 , }; cls_flower.common.chain_index = chain->index; cls_flower.command =TC_CLSFLOWER_TMPLT_CREATE ;
@@ -1400,7 +1396,6 @@ static void fl_hw_create_tmplt(struct tcf_chain *chain, cls_flower.rule.match.dissector = &tmplt->dissector; cls_flower.rule.match.mask = &tmplt->mask; cls_flower.rule.match.key = &tmplt->dummy_key; - cls_flower.exts = &dummy_exts;/* We don't care if driver (any of them) fails to handle this * call. It serves just as a hint for it.
Signature · 1 line
2.11.0
PATCH 8/10 flow_dissector: add wake-up-on-lan and queue to flow_action
In reply to Pablo Neira AyusoThese actions need to be added to support bcm sf2 features available through the ethtool_rx_flow interface.
--- include/net/flow_dissector.h | 3 +++ 1 file changed, 3 insertions(+)
include/net/flow_dissector.h +3 -0
@@ -418,6 +418,8 @@ enum flow_action_key_id {FLOW_ACTION_KEY_ADD ,FLOW_ACTION_KEY_CSUM ,FLOW_ACTION_KEY_MARK , +FLOW_ACTION_KEY_WAKE , + FLOW_ACTION_KEY_QUEUE, };/* This is mirroring enum pedit_header_type definition for easy mapping between
@@ -452,6 +454,7 @@ struct flow_action_key {const struct ip_tunnel_info *tunnel;/* FLOW_ACTION_KEY_TUNNEL_ENCAP */ u32 csum_flags;/* FLOW_ACTION_KEY_CSUM */ u32 mark;/* FLOW_ACTION_KEY_MARK */ +u32 queue_index;/* FLOW_ACTION_KEY_QUEUE */ }; };
Signature · 1 line
2.11.0
PATCH 1/10 flow_dissector: add flow_rule and flow_match structures and use them
In reply to Pablo Neira AyusoThis patch wraps the dissector key and mask - that flower uses to represent the matching side - around the flow_match structure.
To avoid a follow up patch that would edit the same LoCs in the drivers, this patch also wraps this new flow match structure around the flow rule object. This new structure will also contain the flow actions in follow up patches.
This introduces two new interfaces:
bool flow_rule_match_key(rule, dissector_id)
that returns true if a given matching key is set on, and:
flow_rule_match_XYZ(rule, &match);
To fetch the matching side XYZ into the match container structure, to retrieve the key and the mask with one single call.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 174 ++++----- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 194 ++++------ drivers/net/ethernet/intel/i40e/i40e_main.c | 178 ++++----- drivers/net/ethernet/intel/iavf/iavf_main.c | 195 ++++------ drivers/net/ethernet/intel/igb/igb_main.c | 64 ++-- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 420 +++++++++------------ .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 202 +++++----- drivers/net/ethernet/netronome/nfp/flower/action.c | 11 +- drivers/net/ethernet/netronome/nfp/flower/match.c | 416 ++++++++++---------- .../net/ethernet/netronome/nfp/flower/offload.c | 145 +++---- drivers/net/ethernet/qlogic/qede/qede_filter.c | 85 ++--- include/net/flow_dissector.h | 107 ++++++ include/net/pkt_cls.h | 4 +- net/core/flow_dissector.c | 133 +++++++ net/sched/cls_flower.c | 18 +- 15 files changed, 1144 insertions(+), 1202 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +74 -100
@@ -177,18 +177,12 @@ static int bnxt_tc_parse_actions(struct bnxt *bp,return 0 ; } -#define GET_KEY (flow_cmd, key_type) \ - skb_flow_dissector_target((flow_cmd)->dissector, key_type,\ - (flow_cmd)->key) -#define GET_MASK (flow_cmd, key_type) \ - skb_flow_dissector_target((flow_cmd)->dissector, key_type,\ - (flow_cmd)->mask) -static int bnxt_tc_parse_flow (struct bnxt *bp,struct tc_cls_flower_offload *tc_flow_cmd,struct bnxt_tc_flow *flow) { -struct flow_dissector *dissector = tc_flow_cmd->dissector; +struct flow_rule *rule = &tc_flow_cmd->rule; +struct flow_dissector *dissector = rule->match.dissector;/* KEY_CONTROL and KEY_BASIC are needed for forming a meaningful key */ if ((dissector->used_keys & BIT(FLOW_DISSECTOR_KEY_CONTROL)) == 0 ||
@@ -198,140 +192,120 @@ static int bnxt_tc_parse_flow(struct bnxt *bp,return -EOPNOTSUPP ; } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_BASIC )) { -struct flow_dissector_key_basic *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_BASIC ); -struct flow_dissector_key_basic *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_BASIC ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_BASIC )) { +struct flow_match_basic match; - flow->l2_key.ether_type = key->n_proto; - flow->l2_mask.ether_type = mask->n_proto; +flow_rule_match_basic (rule, &match); + flow->l2_key.ether_type = match.key->n_proto; + flow->l2_mask.ether_type = match.mask->n_proto; -if (key->n_proto ==htons (ETH_P_IP ) || - key->n_proto ==htons (ETH_P_IPV6 )) { - flow->l4_key.ip_proto = key->ip_proto; - flow->l4_mask.ip_proto = mask->ip_proto; +if (match.key->n_proto ==htons (ETH_P_IP ) || + match.key->n_proto ==htons (ETH_P_IPV6 )) { + flow->l4_key.ip_proto = match.key->ip_proto; + flow->l4_mask.ip_proto = match.mask->ip_proto; } } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_ETH_ADDRS )) { -struct flow_dissector_key_eth_addrs *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_ETH_ADDRS ); -struct flow_dissector_key_eth_addrs *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_ETH_ADDRS ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ETH_ADDRS )) { +struct flow_match_eth_addrs match; +flow_rule_match_eth_addrs (rule, &match); flow->flags |=BNXT_TC_FLOW_FLAGS_ETH_ADDRS ; -ether_addr_copy (flow->l2_key.dmac, key->dst); -ether_addr_copy (flow->l2_mask.dmac, mask->dst); -ether_addr_copy (flow->l2_key.smac, key->src); -ether_addr_copy (flow->l2_mask.smac, mask->src); +ether_addr_copy (flow->l2_key.dmac, match.key->dst); +ether_addr_copy (flow->l2_mask.dmac, match.mask->dst); +ether_addr_copy (flow->l2_key.smac, match.key->src); +ether_addr_copy (flow->l2_mask.smac, match.mask->src); } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_VLAN )) { -struct flow_dissector_key_vlan *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_VLAN ); -struct flow_dissector_key_vlan *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_VLAN ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_VLAN )) { +struct flow_match_vlan match; +flow_rule_match_vlan (rule, &match); flow->l2_key.inner_vlan_tci = -cpu_to_be16 (VLAN_TCI (key->vlan_id, key->vlan_priority)); +cpu_to_be16 (VLAN_TCI (match.key->vlan_id, + match.key->vlan_priority)); flow->l2_mask.inner_vlan_tci = -cpu_to_be16 ((VLAN_TCI (mask->vlan_id, mask->vlan_priority))); +cpu_to_be16 ((VLAN_TCI (match.mask->vlan_id, + match.mask->vlan_priority))); flow->l2_key.inner_vlan_tpid =htons (ETH_P_8021Q ); flow->l2_mask.inner_vlan_tpid =htons (0xffff ); flow->l2_key.num_vlans =1 ; } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_IPV4_ADDRS )) { -struct flow_dissector_key_ipv4_addrs *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_IPV4_ADDRS ); -struct flow_dissector_key_ipv4_addrs *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_IPV4_ADDRS ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_IPV4_ADDRS )) { +struct flow_match_ipv4_addrs match; +flow_rule_match_ipv4_addrs (rule, &match); flow->flags |=BNXT_TC_FLOW_FLAGS_IPV4_ADDRS ; - flow->l3_key.ipv4.daddr.s_addr = key->dst; - flow->l3_mask.ipv4.daddr.s_addr = mask->dst; - flow->l3_key.ipv4.saddr.s_addr = key->src; - flow->l3_mask.ipv4.saddr.s_addr = mask->src; - }else if (dissector_uses_key (dissector, -FLOW_DISSECTOR_KEY_IPV6_ADDRS )) { -struct flow_dissector_key_ipv6_addrs *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_IPV6_ADDRS ); -struct flow_dissector_key_ipv6_addrs *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_IPV6_ADDRS ); - + flow->l3_key.ipv4.daddr.s_addr = match.key->dst; + flow->l3_mask.ipv4.daddr.s_addr = match.mask->dst; + flow->l3_key.ipv4.saddr.s_addr = match.key->src; + flow->l3_mask.ipv4.saddr.s_addr = match.mask->src; + }else if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_IPV6_ADDRS )) { +struct flow_match_ipv6_addrs match; + +flow_rule_match_ipv6_addrs (rule, &match); flow->flags |=BNXT_TC_FLOW_FLAGS_IPV6_ADDRS ; - flow->l3_key.ipv6.daddr = key->dst; - flow->l3_mask.ipv6.daddr = mask->dst; - flow->l3_key.ipv6.saddr = key->src; - flow->l3_mask.ipv6.saddr = mask->src; + flow->l3_key.ipv6.daddr = match.key->dst; + flow->l3_mask.ipv6.daddr = match.mask->dst; + flow->l3_key.ipv6.saddr = match.key->src; + flow->l3_mask.ipv6.saddr = match.mask->src; } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_PORTS )) { -struct flow_dissector_key_ports *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_PORTS ); -struct flow_dissector_key_ports *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_PORTS ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_PORTS )) { +struct flow_match_ports match; +flow_rule_match_ports (rule, &match); flow->flags |=BNXT_TC_FLOW_FLAGS_PORTS ; - flow->l4_key.ports.dport = key->dst; - flow->l4_mask.ports.dport = mask->dst; - flow->l4_key.ports.sport = key->src; - flow->l4_mask.ports.sport = mask->src; + flow->l4_key.ports.dport = match.key->dst; + flow->l4_mask.ports.dport = match.mask->dst; + flow->l4_key.ports.sport = match.key->src; + flow->l4_mask.ports.sport = match.mask->src; } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_ICMP )) { -struct flow_dissector_key_icmp *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_ICMP ); -struct flow_dissector_key_icmp *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_ICMP ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ICMP )) { +struct flow_match_icmp match; +flow_rule_match_icmp (rule, &match); flow->flags |=BNXT_TC_FLOW_FLAGS_ICMP ; - flow->l4_key.icmp.type = key->type; - flow->l4_key.icmp.code = key->code; - flow->l4_mask.icmp.type = mask->type; - flow->l4_mask.icmp.code = mask->code; + flow->l4_key.icmp.type = match.key->type; + flow->l4_key.icmp.code = match.key->code; + flow->l4_mask.icmp.type = match.mask->type; + flow->l4_mask.icmp.code = match.mask->code; } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS )) { -struct flow_dissector_key_ipv4_addrs *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS ); -struct flow_dissector_key_ipv4_addrs *mask = -GET_MASK (tc_flow_cmd, -FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS )) { +struct flow_match_ipv4_addrs match; +flow_rule_match_enc_ipv4_addrs (rule, &match); flow->flags |=BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS ; - flow->tun_key.u.ipv4.dst = key->dst; - flow->tun_mask.u.ipv4.dst = mask->dst; - flow->tun_key.u.ipv4.src = key->src; - flow->tun_mask.u.ipv4.src = mask->src; - }else if (dissector_uses_key (dissector, + flow->tun_key.u.ipv4.dst = match.key->dst; + flow->tun_mask.u.ipv4.dst = match.mask->dst; + flow->tun_key.u.ipv4.src = match.key->src; + flow->tun_mask.u.ipv4.src = match.mask->src; + }else if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS )) {return -EOPNOTSUPP ; } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_ENC_KEYID )) { -struct flow_dissector_key_keyid *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_ENC_KEYID ); -struct flow_dissector_key_keyid *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_ENC_KEYID ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ENC_KEYID )) { +struct flow_match_enc_keyid match; +flow_rule_match_enc_keyid (rule, &match); flow->flags |=BNXT_TC_FLOW_FLAGS_TUNL_ID ; - flow->tun_key.tun_id =key32_to_tunnel_id (key->keyid); - flow->tun_mask.tun_id =key32_to_tunnel_id (mask->keyid); + flow->tun_key.tun_id =key32_to_tunnel_id (match.key->keyid); + flow->tun_mask.tun_id =key32_to_tunnel_id (match.mask->keyid); } -if (dissector_uses_key (dissector,FLOW_DISSECTOR_KEY_ENC_PORTS )) { -struct flow_dissector_key_ports *key = -GET_KEY (tc_flow_cmd,FLOW_DISSECTOR_KEY_ENC_PORTS ); -struct flow_dissector_key_ports *mask = -GET_MASK (tc_flow_cmd,FLOW_DISSECTOR_KEY_ENC_PORTS ); +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_ENC_PORTS )) { +struct flow_match_ports match; +flow_rule_match_enc_ports (rule, &match); flow->flags |=BNXT_TC_FLOW_FLAGS_TUNL_PORTS ; - flow->tun_key.tp_dst = key->dst; - flow->tun_mask.tp_dst = mask->dst; - flow->tun_key.tp_src = key->src; - flow->tun_mask.tp_src = mask->src; + flow->tun_key.tp_dst = match.key->dst; + flow->tun_mask.tp_dst = match.mask->dst; + flow->tun_key.tp_src = match.key->src; + flow->tun_mask.tp_src = match.mask->src; }return bnxt_tc_parse_actions (bp, &flow->actions, tc_flow_cmd->exts);
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +79 -115
268 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_main.c +68 -110
292 lines not on this page · raw message
drivers/net/ethernet/intel/iavf/iavf_main.c +80 -115
336 lines not on this page · raw message
drivers/net/ethernet/intel/igb/igb_main.c +24 -40
111 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +177 -243
661 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +88 -114
322 lines not on this page · raw message
drivers/net/ethernet/netronome/nfp/flower/action.c +5 -6
@@ -587,6 +587,7 @@ static int nfp_fl_pedit(const struct tc_action *action, struct tc_cls_flower_offload *flow, char *nfp_action, int *a_len, u32 *csum_updated) { + struct flow_rule *rule = &flow->rule;struct nfp_fl_set_ipv6_addr set_ip6_dst, set_ip6_src;struct nfp_fl_set_ipv6_tc_hl_fl set_ip6_tc_hl_fl;struct nfp_fl_set_ip4_ttl_tos set_ip_ttl_tos;
@@ -643,13 +644,11 @@ nfp_fl_pedit(const struct tc_action *action, struct tc_cls_flower_offload *flow,return err; } -if (dissector_uses_key (flow->dissector,FLOW_DISSECTOR_KEY_BASIC )) { -struct flow_dissector_key_basic *basic; +if (flow_rule_match_key (rule,FLOW_DISSECTOR_KEY_BASIC )) { +struct flow_match_basic match; - basic =skb_flow_dissector_target (flow->dissector, -FLOW_DISSECTOR_KEY_BASIC , - flow->key); - ip_proto = basic->ip_proto; +flow_rule_match_basic (rule, &match); + ip_proto = match.key->ip_proto; }if (set_eth.head.len_lw) {
drivers/net/ethernet/netronome/nfp/flower/match.c +208 -208
548 lines not on this page · raw message
drivers/net/ethernet/netronome/nfp/flower/offload.c +55 -90
206 lines not on this page · raw message
drivers/net/ethernet/qlogic/qede/qede_filter.c +36 -49
85 lines not on this page · raw message
include/net/flow_dissector.h +107 -0
107 lines not on this page · raw message
net/core/flow_dissector.c +133 -0
133 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
PATCH 9/10 flow_dissector: add basic ethtool_rx_flow_spec to flow_rule structure translator
In reply to Pablo Neira AyusoThis patch adds a function to translate the ethtool_rx_flow_spec structure to the flow_rule representation.
This allows us to reuse code from the driver side given that both flower and ethtool_rx_flow interfaces use the same representation.
--- include/net/flow_dissector.h | 5 ++ net/core/flow_dissector.c | 190 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+)
include/net/flow_dissector.h +5 -0
@@ -485,4 +485,9 @@ static inline bool flow_rule_match_key(const struct flow_rule *rule, return dissector_uses_key(rule->match.dissector, key); } +struct ethtool_rx_flow_spec ; + +struct flow_rule *ethtool_rx_flow_rule (const struct ethtool_rx_flow_spec *fs); +void ethtool_rx_flow_rule_free (struct flow_rule *rule); +#endif
net/core/flow_dissector.c +190 -0
202 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 10/10 dsa: bcm_sf2: use flow_rule infrastructure
In reply to Pablo Neira AyusoUpdate this driver to use the flow_rule infrastructure, hence we can use the same code to populate hardware IR from ethtool_rx_flow and the cls_flower interfaces.
--- drivers/net/dsa/bcm_sf2_cfp.c | 103 ++++++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 33 deletions(-)
drivers/net/dsa/bcm_sf2_cfp.c +70 -33
@@ -257,7 +257,8 @@ static int bcm_sf2_cfp_act_pol_set(struct bcm_sf2_priv *priv, }static void bcm_sf2_cfp_slice_ipv4 (struct bcm_sf2_priv *priv, -struct ethtool_tcpip4_spec *v4_spec, +struct flow_dissector_key_ipv4_addrs *addrs, +struct flow_dissector_key_ports *ports,unsigned int slice_num,bool mask) {
@@ -278,7 +279,7 @@ static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv,* UDF_n_A6 [23:8] * UDF_n_A5 [7:0] */ - reg =be16_to_cpu (v4_spec->pdst) >>8 ; + reg =be16_to_cpu (ports->dst) >>8 ;if (mask) offset =CORE_CFP_MASK_PORT (3 );else
@@ -289,9 +290,9 @@ static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv,* UDF_n_A4 [23:8] * UDF_n_A3 [7:0] */ - reg = (be16_to_cpu (v4_spec->pdst) &0xff ) <<24 | - (u32 )be16_to_cpu (v4_spec->psrc) <<8 | - (be32_to_cpu (v4_spec->ip4dst) &0x0000ff00 ) >>8 ; + reg = (be16_to_cpu (ports->dst) &0xff ) <<24 | + (u32 )be16_to_cpu (ports->src) <<8 | + (be32_to_cpu (addrs->dst) &0x0000ff00 ) >>8 ;if (mask) offset =CORE_CFP_MASK_PORT (2 );else
@@ -302,9 +303,9 @@ static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv,* UDF_n_A2 [23:8] * UDF_n_A1 [7:0] */ - reg = (u32)(be32_to_cpu (v4_spec->ip4dst) &0xff ) <<24 | - (u32)(be32_to_cpu (v4_spec->ip4dst) >>16 ) <<8 | - (be32_to_cpu (v4_spec->ip4src) &0x0000ff00 ) >>8 ; + reg = (u32)(be32_to_cpu (addrs->dst) &0xff ) <<24 | + (u32)(be32_to_cpu (addrs->dst) >>16 ) <<8 | + (be32_to_cpu (addrs->src) &0x0000ff00 ) >>8 ;if (mask) offset =CORE_CFP_MASK_PORT (1 );else
@@ -317,8 +318,8 @@ static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv,* Slice ID [3:2] * Slice valid [1:0] */ - reg = (u32)(be32_to_cpu (v4_spec->ip4src) &0xff ) <<24 | - (u32)(be32_to_cpu (v4_spec->ip4src) >>16 ) <<8 | + reg = (u32)(be32_to_cpu (addrs->src) &0xff ) <<24 | + (u32)(be32_to_cpu (addrs->src) >>16 ) <<8 |SLICE_NUM (slice_num) |SLICE_VALID ;if (mask) offset =CORE_CFP_MASK_PORT (0 );
@@ -335,6 +336,11 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,struct ethtool_tcpip4_spec *v4_spec, *v4_m_spec;const struct cfp_udf_layout *layout;unsigned int slice_num, rule_index; +struct flow_match_ipv4_addrs ipv4; +struct flow_match_ports ports; +struct flow_match_basic basic; +struct flow_rule *flow_rule; +struct flow_match_ip ip;u8 ip_proto, ip_frag;u8 num_udf;u32 reg;
@@ -367,11 +373,22 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,if (rule_index >bcm_sf2_cfp_rule_size (priv))return -ENOSPC ; + flow_rule =ethtool_rx_flow_rule (fs); +if (!flow_rule) +return -ENOMEM ; + +flow_rule_match_ipv4_addrs (flow_rule, &ipv4); +flow_rule_match_ports (flow_rule, &ports); +flow_rule_match_basic (flow_rule, &basic); +flow_rule_match_ip (flow_rule, &ip); + layout = &udf_tcpip4_layout;/* We only use one UDF slice for now */ slice_num =bcm_sf2_get_slice_number (layout,0 ); -if (slice_num ==UDF_NUM_SLICES ) -return -EINVAL ; +if (slice_num ==UDF_NUM_SLICES ) { + ret = -EINVAL ; + goto out_err_flow_rule; + } num_udf =bcm_sf2_get_num_udf_slices (layout->udfs[slice_num].slices);
@@ -398,9 +415,10 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,* Reserved [1] * UDF_Valid[8] [0] */ -core_writel (priv, v4_spec->tos <<IPTOS_SHIFT | - ip_proto <<IPPROTO_SHIFT | ip_frag <<IP_FRAG_SHIFT | -udf_upper_bits (num_udf), +core_writel (priv, ip.key->tos <<IPTOS_SHIFT | + basic.key->n_proto <<IPPROTO_SHIFT | + ip_frag <<IP_FRAG_SHIFT | +udf_upper_bits (num_udf),CORE_CFP_DATA_PORT (6 ));/* Mask with the specific layout for IPv4 packets */
@@ -417,8 +435,8 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,core_writel (priv,udf_lower_bits (num_udf) <<24 ,CORE_CFP_MASK_PORT (5 ));/* Program the match and the mask */ -bcm_sf2_cfp_slice_ipv4 (priv, v4_spec, slice_num, false); -bcm_sf2_cfp_slice_ipv4 (priv, v4_m_spec,SLICE_NUM_MASK , true); +bcm_sf2_cfp_slice_ipv4 (priv, ipv4.key, ports.key, slice_num, false); +bcm_sf2_cfp_slice_ipv4 (priv, ipv4.mask, ports.mask,SLICE_NUM_MASK , true);/* Insert into TCAM now */ bcm_sf2_cfp_rule_addr_set (priv, rule_index);
@@ -426,14 +444,14 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port, ret =bcm_sf2_cfp_op (priv,OP_SEL_WRITE |TCAM_SEL );if (ret) {pr_err ("TCAM entry at addr %d failed\n" , rule_index); -return ret; + goto out_err_flow_rule; }/* Insert into Action and policer RAMs now */ ret =bcm_sf2_cfp_act_pol_set (priv, rule_index, port_num, queue_num, true);if (ret) -return ret; + goto out_err_flow_rule;/* Turn on CFP for this rule now */ reg =core_readl (priv,CORE_CFP_CTL_REG );
@@ -446,6 +464,10 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port, fs->location = rule_index;return 0 ; + +out_err_flow_rule: +ethtool_rx_flow_rule_free (flow_rule); +return ret; } static void bcm_sf2_cfp_slice_ipv6(struct bcm_sf2_priv *priv,
@@ -584,6 +606,10 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,struct ethtool_tcpip6_spec *v6_spec, *v6_m_spec;unsigned int slice_num, rule_index[2 ];const struct cfp_udf_layout *layout; +struct flow_match_ipv6_addrs ipv6; +struct flow_match_ports ports; +struct flow_match_basic basic; +struct flow_rule *flow_rule;u8 ip_proto, ip_frag;int ret =0 ;u8 num_udf;
@@ -645,6 +671,15 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port, goto out_err; } + flow_rule =ethtool_rx_flow_rule (fs); +if (!flow_rule) { + ret = -ENOMEM ; + goto out_err; + } +flow_rule_match_ipv6_addrs (flow_rule, &ipv6); +flow_rule_match_ports (flow_rule, &ports); +flow_rule_match_basic (flow_rule, &basic); +/* Apply the UDF layout for this filter */ bcm_sf2_cfp_udf_set (priv, layout, slice_num);
@@ -668,7 +703,7 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,* Reserved [1] * UDF_Valid[8] [0] */ - reg =1 <<L3_FRAMING_SHIFT | ip_proto <<IPPROTO_SHIFT | + reg =1 <<L3_FRAMING_SHIFT | basic.key->n_proto <<IPPROTO_SHIFT | ip_frag <<IP_FRAG_SHIFT |udf_upper_bits (num_udf);core_writel (priv, reg,CORE_CFP_DATA_PORT (6 ));
@@ -688,10 +723,10 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,core_writel (priv,udf_lower_bits (num_udf) <<24 ,CORE_CFP_MASK_PORT (5 ));/* Slice the IPv6 source address and port */ -bcm_sf2_cfp_slice_ipv6 (priv, v6_spec->ip6src, v6_spec->psrc, - slice_num, false); -bcm_sf2_cfp_slice_ipv6 (priv, v6_m_spec->ip6src, v6_m_spec->psrc, -SLICE_NUM_MASK , true); +bcm_sf2_cfp_slice_ipv6 (priv, ipv6.key->src.in6_u.u6_addr32, + ports.key->src, slice_num, false); +bcm_sf2_cfp_slice_ipv6 (priv, ipv6.mask->src.in6_u.u6_addr32, + ports.mask->src,SLICE_NUM_MASK , true);/* Insert into TCAM now because we need to insert a second rule */ bcm_sf2_cfp_rule_addr_set (priv, rule_index[0 ]);
@@ -699,20 +734,20 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port, ret =bcm_sf2_cfp_op (priv,OP_SEL_WRITE |TCAM_SEL );if (ret) {pr_err ("TCAM entry at addr %d failed\n" , rule_index[0 ]); - goto out_err; + goto out_err_flow_rule; }/* Insert into Action and policer RAMs now */ ret =bcm_sf2_cfp_act_pol_set (priv, rule_index[0 ], port_num, queue_num, false);if (ret) - goto out_err; + goto out_err_flow_rule;/* Now deal with the second slice to chain this rule */ slice_num =bcm_sf2_get_slice_number (layout, slice_num +1 );if (slice_num ==UDF_NUM_SLICES ) { ret = -EINVAL ; - goto out_err; + goto out_err_flow_rule; } num_udf =bcm_sf2_get_num_udf_slices (layout->udfs[slice_num].slices);
@@ -748,10 +783,10 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,/* Mask all */ core_writel (priv,0 ,CORE_CFP_MASK_PORT (5 )); -bcm_sf2_cfp_slice_ipv6 (priv, v6_spec->ip6dst, v6_spec->pdst, slice_num, - false); -bcm_sf2_cfp_slice_ipv6 (priv, v6_m_spec->ip6dst, v6_m_spec->pdst, -SLICE_NUM_MASK , true); +bcm_sf2_cfp_slice_ipv6 (priv, ipv6.key->dst.in6_u.u6_addr32, + ports.key->dst, slice_num, false); +bcm_sf2_cfp_slice_ipv6 (priv, ipv6.mask->dst.in6_u.u6_addr32, + ports.key->dst,SLICE_NUM_MASK , true);/* Insert into TCAM now */ bcm_sf2_cfp_rule_addr_set (priv, rule_index[1 ]);
@@ -759,7 +794,7 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port, ret =bcm_sf2_cfp_op (priv,OP_SEL_WRITE |TCAM_SEL );if (ret) {pr_err ("TCAM entry at addr %d failed\n" , rule_index[1 ]); - goto out_err; + goto out_err_flow_rule; }/* Insert into Action and policer RAMs now, set chain ID to
@@ -768,7 +803,7 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port, ret =bcm_sf2_cfp_act_pol_set (priv, rule_index[1 ], port_num, queue_num, true);if (ret) - goto out_err; + goto out_err_flow_rule;/* Turn on CFP for this rule now */ reg =core_readl (priv,CORE_CFP_CTL_REG );
@@ -784,6 +819,8 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,return ret; +out_err_flow_rule: +ethtool_rx_flow_rule_free (flow_rule); out_err:clear_bit (rule_index[1 ], priv->cfp.used);return ret;
Signature · 1 line
2.11.0
PATCH 6/10 drivers: net: use flow action infrastructure
In reply to Pablo Neira AyusoThis patch updates drivers to use the new flow action infrastructure.
--- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 74 +++--- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 250 +++++++++---------- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 266 ++++++++++----------- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 55 +++-- drivers/net/ethernet/netronome/nfp/flower/action.c | 185 +++++++------- drivers/net/ethernet/qlogic/qede/qede_filter.c | 12 +- 7 files changed, 417 insertions(+), 427 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +33 -41
@@ -61,9 +61,9 @@ static u16 bnxt_flow_get_dst_fid(struct bnxt *pf_bp, struct net_device *dev)static int bnxt_tc_parse_redir (struct bnxt *bp,struct bnxt_tc_actions *actions, -const struct tc_action *tc_act) +const struct flow_action_key *act) { -struct net_device *dev =tcf_mirred_dev (tc_act); +struct net_device *dev = act->dev;if (!dev) {netdev_info (bp->dev,"no dev in mirred action" );
@@ -77,16 +77,16 @@ static int bnxt_tc_parse_redir(struct bnxt *bp,static int bnxt_tc_parse_vlan (struct bnxt *bp,struct bnxt_tc_actions *actions, -const struct tc_action *tc_act) +const struct flow_action_key *act) { -switch (tcf_vlan_action (tc_act)) { -case TCA_VLAN_ACT_POP : +switch (act->id) { +case FLOW_ACTION_KEY_VLAN_POP : actions->flags |=BNXT_TC_ACTION_FLAG_POP_VLAN ;break ; -case TCA_VLAN_ACT_PUSH : +case FLOW_ACTION_KEY_VLAN_PUSH : actions->flags |=BNXT_TC_ACTION_FLAG_PUSH_VLAN ; - actions->push_vlan_tci =htons (tcf_vlan_push_vid (tc_act)); - actions->push_vlan_tpid =tcf_vlan_push_proto (tc_act); + actions->push_vlan_tci =htons (act->vlan.vid); + actions->push_vlan_tpid = act->vlan.proto;break ;default :return -EOPNOTSUPP ;
@@ -96,10 +96,10 @@ static int bnxt_tc_parse_vlan(struct bnxt *bp,static int bnxt_tc_parse_tunnel_set (struct bnxt *bp,struct bnxt_tc_actions *actions, -const struct tc_action *tc_act) +const struct flow_action_key *act) { -struct ip_tunnel_info *tun_info =tcf_tunnel_info (tc_act); -struct ip_tunnel_key *tun_key = &tun_info->key; +const struct ip_tunnel_info *tun_info = act->tunnel; +const struct ip_tunnel_key *tun_key = &tun_info->key;if (ip_tunnel_info_af (tun_info) !=AF_INET ) {netdev_info (bp->dev,"only IPv4 tunnel-encap is supported" );
@@ -113,51 +113,43 @@ static int bnxt_tc_parse_tunnel_set(struct bnxt *bp,static int bnxt_tc_parse_actions (struct bnxt *bp,struct bnxt_tc_actions *actions, -struct tcf_exts *tc_exts) +struct flow_action *flow_action) { -const struct tc_action *tc_act; +struct flow_action_key *act;int i, rc; -if (!tcf_exts_has_actions (tc_exts)) { +if (!flow_action_has_keys (flow_action)) {netdev_info (bp->dev,"no actions" );return -EINVAL ; } -tcf_exts_for_each_action (i, tc_act, tc_exts) { -/* Drop action */ -if (is_tcf_gact_shot (tc_act)) { +flow_action_for_each (i, act, flow_action) { +switch (act->id) { +case FLOW_ACTION_KEY_DROP : actions->flags |=BNXT_TC_ACTION_FLAG_DROP ;return 0 ;/* don't bother with other actions */ - } - -/* Redirect action */ -if (is_tcf_mirred_egress_redirect (tc_act)) { - rc =bnxt_tc_parse_redir (bp, actions, tc_act); +case FLOW_ACTION_KEY_REDIRECT : + rc =bnxt_tc_parse_redir (bp, actions, act);if (rc)return rc; -continue ; - } - -/* Push/pop VLAN */ -if (is_tcf_vlan (tc_act)) { - rc =bnxt_tc_parse_vlan (bp, actions, tc_act); +break ; +case FLOW_ACTION_KEY_VLAN_POP : +case FLOW_ACTION_KEY_VLAN_PUSH : +case FLOW_ACTION_KEY_VLAN_MANGLE : + rc =bnxt_tc_parse_vlan (bp, actions, act);if (rc)return rc; -continue ; - } - -/* Tunnel encap */ -if (is_tcf_tunnel_set (tc_act)) { - rc =bnxt_tc_parse_tunnel_set (bp, actions, tc_act); +break ; +case FLOW_ACTION_KEY_TUNNEL_ENCAP : + rc =bnxt_tc_parse_tunnel_set (bp, actions, act);if (rc)return rc; -continue ; - } - -/* Tunnel decap */ -if (is_tcf_tunnel_release (tc_act)) { +break ; +case FLOW_ACTION_KEY_TUNNEL_DECAP : actions->flags |=BNXT_TC_ACTION_FLAG_TUNNEL_DECAP ; -continue ; +break ; +default : +break ; } }
@@ -308,7 +300,7 @@ static int bnxt_tc_parse_flow(struct bnxt *bp, flow->tun_mask.tp_src = match.mask->src; } -return bnxt_tc_parse_actions (bp, &flow->actions, tc_flow_cmd->exts); +return bnxt_tc_parse_actions (bp, &flow->actions, &rule->action); }static int bnxt_hwrm_cfa_flow_free (struct bnxt *bp,__le16 flow_handle)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +127 -123
371 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +123 -143
503 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +1 -1
@@ -579,7 +579,7 @@ int mlxsw_sp_acl_rulei_act_vlan(struct mlxsw_sp *mlxsw_sp, {u8 ethertype; -if (action ==TCA_VLAN_ACT_MODIFY ) { +if (action ==FLOW_ACTION_KEY_VLAN_MANGLE ) {switch (proto) {case ETH_P_8021Q : ethertype =0 ;
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +33 -22
117 lines not on this page · raw message
drivers/net/ethernet/netronome/nfp/flower/action.c +94 -91
406 lines not on this page · raw message
drivers/net/ethernet/qlogic/qede/qede_filter.c +6 -6
@@ -2004,21 +2004,21 @@ int qede_get_arfs_filter_count(struct qede_dev *edev) }static int qede_parse_actions (struct qede_dev *edev, -struct tcf_exts *exts) +struct flow_action *flow_action) { +const struct flow_action_key *act;int rc = -EINVAL , num_act =0 , i; -const struct tc_action *a;bool is_drop = false; -if (!tcf_exts_has_actions (exts)) { +if (!flow_action_has_keys (flow_action)) {DP_NOTICE (edev,"No tc actions received\n" );return rc; } -tcf_exts_for_each_action (i, a, exts) { +flow_action_for_each (i, act, flow_action) { num_act++; -if (is_tcf_gact_shot (a)) +if (act->id ==FLOW_ACTION_KEY_DROP ) is_drop = true; }
@@ -2235,7 +2235,7 @@ int qede_add_tc_flower_fltr(struct qede_dev *edev, __be16 proto, }/* parse tc actions and get the vf_id */ -if (qede_parse_actions (edev, f->exts)) +if (qede_parse_actions (edev, &f->rule.action)) goto unlock;if (qede_flow_find_fltr (edev, &t)) {
Signature · 1 line
2.11.0
Quoted 4 lines · Pablo Neira Ayuso
This patchset introduces a kernel intermediate representation (IR) to express ACL hardware offloads, this is heavily based on the existing flow dissector infrastructure and the TC actions. This IR can be used by different frontend ACL interfaces such as
ethtool_rxnfcand tc to
any reason to keep aRFS out?
Quoted 6 lines
represent ACL hardware offloads. Main goal is to simplify the development of ACL hardware offloads for the existing frontend interfaces, the idea is that driver developers do not need to add one specific parser for each ACL frontend, instead each frontend can just generate this
flow_ruleIR and pass it to drivers to populate the hardware IR.
yeah, but we are adding one more chain (IR), today we have
kernel frontend U/API X --> kernel parser Y --> driver --> HW API kernel frontend U/API Z --> kernel parser W --> driver --> HW API
and we move to
kernel frontend U/API X --> kernel parser Y --> IR --> driver --> HW API kernel frontend U/API Z --> kernel parser W --> IR --> driver --> HW API
So instead of
Y --> HW
W --> HW
we have IR --> HW while loosing the TC semantics and spirit in the drivers.
We could have normalize all the U/APIs to use the flow dissectors and the TC actions and then have the drivers to deal with TC only.
IMHO flow dissectors and TC actions are the right approach to deal with ACLs HW offloading. They properly reflect how ACLs work in modern HW pipelines.
Quoted 15 lines
.
ethtool_rxnfctc
| (ioctl) (netlink)
| | | translate native
Frontend | | | interface representation
| | | toflow_ruleIR
| | |
. \/ \/
.flow_ruleIR
| |
Drivers | | parsing offlow_ruleIR
| | to populate hardware IR
| \/
. hardware IR (driver)
Quoted 3 lines
For design and implementation details, please have a look at:
https://lwn.net/Articles/766695/
I will further look next week, but as this is not marked as RFC (and not with net-next
on the title), can we consider this still a discussion and not final/review?
Quoted 3 lines
As an example, with this patchset, it should be possible to simplify the existing net/qede driver which already has two parsers to populate the hardware IR, one for
ethtool_rxnfcinterface and another for tc.
I think it would be fair to ask for one such driver porting to see the impact/benefit.
Or.
David Miller
maintainerRe: [PATCH 01/10] flow_dissector: add flow_rule and flow_match structures and use them
In reply to Pablo Neira AyusoFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 16 Nov 2018 02:41:30 +0100
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c static int bnxt_tc_parse_actions(struct bnxt *bp, · line 185
Quoted 7 lines
static int bnxt_tc_parse_flow(struct bnxt *bp,
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +2
-1struct tc_cls_flower_offload *tc_flow_cmd, struct bnxt_tc_flow *flow) { - struct flow_dissector *dissector = tc_flow_cmd->dissector; + struct flow_rule *rule = &tc_flow_cmd->rule; +struct flow_dissector *dissector = rule->match.dissector;
This adds a reverse christmas tree violation. Please fix this up.
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c static void cxgb4_process_flow_match(struct net_device *dev, · line 230
Quoted 8 lines
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +2
-0@@ -255,10 +224,12 @@ static void cxgb4_process_flow_match(struct net_device *dev,static int cxgb4_validate_flow_match (struct net_device *dev,struct tc_cls_flower_offload *cls) { +struct flow_rule *rule = &cls->rule; +struct flow_dissector *dissector = rule->match.dissector;u16 ethtype_mask =0 ;u16 ethtype_key =0 ;
Likewise.
drivers/net/ethernet/intel/i40e/i40e_main.c static int i40e_parse_cls_flower(struct i40e_vsi *vsi, · line 7173
Quoted 13 lines
drivers/net/ethernet/intel/i40e/i40e_main.c +2
-0@@ -7166,11 +7166,13 @@ static int i40e_parse_cls_flower(struct i40e_vsi *vsi,struct tc_cls_flower_offload *f, struct i40e_cloud_filter *filter) { + struct flow_rule *rule = &f->rule; +struct flow_dissector *dissector = rule->match.dissector;u16 n_proto_mask =0 , n_proto_key =0 , addr_type =0 ;struct i40e_pf *pf = vsi->back;u8 field_flags =0 ;
Likewise.
And so on and so forth for your entire submission.
David Miller
maintainerRe: [PATCH 10/10] dsa: bcm_sf2: use flow_rule infrastructure
In reply to Pablo Neira AyusoFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 16 Nov 2018 02:41:39 +0100
drivers/net/dsa/bcm_sf2_cfp.c static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port, · line 336
Quoted 2 lines
drivers/net/dsa/bcm_sf2_cfp.c +0
-0@@ -335,6 +336,11 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,struct ethtool_tcpip4_spec *v4_spec, *v4_m_spec;
Local variables v4_spec and v4_m_spec are now set but not used.
David Miller
maintainerFrom: Or Gerlitz <[email protected]>
Date: Fri, 16 Nov 2018 12:29:29 +0200
Quoted 2 lines
I think it would be fair to ask for one such driver porting to see the impact/benefit.
This is an absolute requirement, otherwise the claim that it helps is pure theory.
Quoted 136 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pablo Neira Ayuso
Sent: Friday, November 16, 2018 7:11 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Elior, Ariel <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH 00/10] addflow_ruleinfrastructureExternal Email
This patchset introduces a kernel intermediate representation (IR) to express ACL hardware offloads, this is heavily based on the existing flow dissector infrastructure and the TC actions. This IR can be used by different frontend ACL interfaces such as
ethtool_rxnfcand tc to represent ACL hardware offloads. Main goal is to simplify the development of ACL hardware offloads for the existing frontend interfaces, the idea is that driver developers do not need to add one specific parser for each ACL frontend, instead each frontend can just generate thisflow_ruleIR and pass it to drivers to populate the hardware IR..
ethtool_rxnfctc
| (ioctl) (netlink)
| | | translate native
Frontend | | | interface representation
| | | toflow_ruleIR
| | |
. \/ \/
.flow_ruleIR
| |
Drivers | | parsing offlow_ruleIR
| | to populate hardware IR
| \/
. hardware IR (driver)For design and implementation details, please have a look at:
https://lwn.net/Articles/766695/As an example, with this patchset, it should be possible to simplify the existing net/qede driver which already has two parsers to populate the hardware IR, one for
ethtool_rxnfcinterface and another for tc.This batch is composed of 10 patches:
Patch #1 adds the
flow_matchstructure, this includes the
flow_rule_match_key()interface to check for existing selectors that are in used in the rule and the flow_rule_match_*() functions to fetch the selector value and the mask. This also introduces the initialflow_rulestructure skeleton to avoid a follow up patch that would update the same LoCs.Patch #2 makes changes to packet edit parser of mlx5e driver, to prepare
introduction of the newflow_actionto mangle packets.Patch #3 Introduce
flow_actioninfrastructure. This infrastructure is
based on the TC actions. Patch #8 extends it so it also supports two new actions that are only available through theethtool_rxnfcinterface.Patch #4 Add function to translate TC action to
flow_actionfrom
cls_flower.Patch #5 Add infrastructure to fetch statistics into container structure
and synchronize them to TC actions fromcls_flower. Another preparation patch before patch #7, so we can stop exposing the TC action native layout to the drivers.Patch #6 Use
flow_actioninfrastructure from drivers.Patch #7 Do not expose TC actions to drivers anymore, now that drivers
have been converted to use theflow_actioninfrastructure after patch #5.Patch #8 Support to wake-up-on-lan and queue actions for the
flow_action
infrastructure, two actions supported by NICs. This is used by theethtool_rx_flowinterface.Patch #9 Add a function to translate from
ethtool_rx_flow_specstructure
to theflow_actionstructure. This is a simple enough for its first client: theethtool_rxnfcinterface in thebcm_sf2driver.Patch #10 Update
bcm_sf2to use this new translator function and
update codebase to configure hardware IR using theflow_actionrepresentation. This will allow later development ofcls_flowerusing the same codebase from the driver.This patchset has passed here functional tests of the codepath that generates the
flow_rulestructure and the functions to implement the parsers that populate the hardware IR.Thanks.
Pablo Neira Ayuso (10):
flow_dissector: addflow_ruleandflow_matchstructures and use them net/mlx5e: support for two independent packet edit actions
flow_dissector: add flow action infrastructure
cls_api: add translator toflow_actionrepresentation
cls_flower: add statistics retrieval infrastructure and use it
drivers: net: use flow action infrastructure
cls_flower: don't expose TC actions to drivers anymore
flow_dissector: add wake-up-on-lan and queue toflow_action
flow_dissector: add basicethtool_rx_flow_spectoflow_rulestructure
translator
dsa:bcm_sf2: useflow_ruleinfrastructuredrivers/net/dsa/bcm_sf2_cfp.c | 103 ++- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 252 +++---- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 450 ++++++------- drivers/net/ethernet/intel/i40e/i40e_main.c | 178 ++--- drivers/net/ethernet/intel/iavf/iavf_main.c | 195 +++--- drivers/net/ethernet/intel/igb/igb_main.c | 64 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 743 ++++++++++-------- --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 259 ++++--- drivers/net/ethernet/netronome/nfp/flower/action.c | 196 +++--- drivers/net/ethernet/netronome/nfp/flower/match.c | 416 ++++++------ .../net/ethernet/netronome/nfp/flower/offload.c | 151 ++--- drivers/net/ethernet/qlogic/qede/qede_filter.c | 93 ++- include/net/flow_dissector.h | 185 +++++ include/net/pkt_cls.h | 23 +- net/core/flow_dissector.c | 341 ++++++++++ net/sched/cls_api.c | 113 ++++ net/sched/cls_flower.c | 42 +- 18 files changed, 2120 insertions(+), 1686 deletions(-)
Quoted 2 lines
--
2.11.0
Today, we have different kernel interfaces(aRFS/ethtool/tc) to do flow offloading.
One big question arises in my mind that why we need these all different interfaces to do flow offloading and why can't they just be combined into a single kernel interface somehow.
Having these flow offloading done through various hooks makes driver implementation really complex.
Specially when looking at ethtool/tc flows most of the use cases seems common to me -
1. Drop action can be done on tuples from both tc/ethtool flows.
2. Flow redirection is done from both ethtool/tc
(May be with just slight difference ? as Ethtool does steering on PF and VF/VF-queues
but tc doesn't have redirection on queues which can be extended over tc)
3. Could be more such common cases which could be the reason to combine them through single interface ?
Thanks !!
Jiri Pirko
maintainerQuoted 144 lines · Mon, Nov 19, 2018 at 10:19:28AM CET, [email protected] wrote:
Quoted 136 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pablo Neira Ayuso
Sent: Friday, November 16, 2018 7:11 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Elior, Ariel <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH 00/10] addflow_ruleinfrastructureExternal Email
This patchset introduces a kernel intermediate representation (IR) to express ACL hardware offloads, this is heavily based on the existing flow dissector infrastructure and the TC actions. This IR can be used by different frontend ACL interfaces such as
ethtool_rxnfcand tc to represent ACL hardware offloads. Main goal is to simplify the development of ACL hardware offloads for the existing frontend interfaces, the idea is that driver developers do not need to add one specific parser for each ACL frontend, instead each frontend can just generate thisflow_ruleIR and pass it to drivers to populate the hardware IR..
ethtool_rxnfctc
| (ioctl) (netlink)
| | | translate native
Frontend | | | interface representation
| | | toflow_ruleIR
| | |
. \/ \/
.flow_ruleIR
| |
Drivers | | parsing offlow_ruleIR
| | to populate hardware IR
| \/
. hardware IR (driver)For design and implementation details, please have a look at:
https://lwn.net/Articles/766695/As an example, with this patchset, it should be possible to simplify the existing net/qede driver which already has two parsers to populate the hardware IR, one for
ethtool_rxnfcinterface and another for tc.This batch is composed of 10 patches:
Patch #1 adds the
flow_matchstructure, this includes the
flow_rule_match_key()interface to check for existing selectors that are in used in the rule and the flow_rule_match_*() functions to fetch the selector value and the mask. This also introduces the initialflow_rulestructure skeleton to avoid a follow up patch that would update the same LoCs.Patch #2 makes changes to packet edit parser of mlx5e driver, to prepare
introduction of the newflow_actionto mangle packets.Patch #3 Introduce
flow_actioninfrastructure. This infrastructure is
based on the TC actions. Patch #8 extends it so it also supports two new actions that are only available through theethtool_rxnfcinterface.Patch #4 Add function to translate TC action to
flow_actionfrom
cls_flower.Patch #5 Add infrastructure to fetch statistics into container structure
and synchronize them to TC actions fromcls_flower. Another preparation patch before patch #7, so we can stop exposing the TC action native layout to the drivers.Patch #6 Use
flow_actioninfrastructure from drivers.Patch #7 Do not expose TC actions to drivers anymore, now that drivers
have been converted to use theflow_actioninfrastructure after patch #5.Patch #8 Support to wake-up-on-lan and queue actions for the
flow_action
infrastructure, two actions supported by NICs. This is used by theethtool_rx_flowinterface.Patch #9 Add a function to translate from
ethtool_rx_flow_specstructure
to theflow_actionstructure. This is a simple enough for its first client: theethtool_rxnfcinterface in thebcm_sf2driver.Patch #10 Update
bcm_sf2to use this new translator function and
update codebase to configure hardware IR using theflow_actionrepresentation. This will allow later development ofcls_flowerusing the same codebase from the driver.This patchset has passed here functional tests of the codepath that generates the
flow_rulestructure and the functions to implement the parsers that populate the hardware IR.Thanks.
Pablo Neira Ayuso (10):
flow_dissector: addflow_ruleandflow_matchstructures and use them net/mlx5e: support for two independent packet edit actions
flow_dissector: add flow action infrastructure
cls_api: add translator toflow_actionrepresentation
cls_flower: add statistics retrieval infrastructure and use it
drivers: net: use flow action infrastructure
cls_flower: don't expose TC actions to drivers anymore
flow_dissector: add wake-up-on-lan and queue toflow_action
flow_dissector: add basicethtool_rx_flow_spectoflow_rulestructure
translator
dsa:bcm_sf2: useflow_ruleinfrastructuredrivers/net/dsa/bcm_sf2_cfp.c | 103 ++- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 252 +++---- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 450 ++++++------- drivers/net/ethernet/intel/i40e/i40e_main.c | 178 ++--- drivers/net/ethernet/intel/iavf/iavf_main.c | 195 +++--- drivers/net/ethernet/intel/igb/igb_main.c | 64 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 743 ++++++++++-------- --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 259 ++++--- drivers/net/ethernet/netronome/nfp/flower/action.c | 196 +++--- drivers/net/ethernet/netronome/nfp/flower/match.c | 416 ++++++------ .../net/ethernet/netronome/nfp/flower/offload.c | 151 ++--- drivers/net/ethernet/qlogic/qede/qede_filter.c | 93 ++- include/net/flow_dissector.h | 185 +++++ include/net/pkt_cls.h | 23 +- net/core/flow_dissector.c | 341 ++++++++++ net/sched/cls_api.c | 113 ++++ net/sched/cls_flower.c | 42 +- 18 files changed, 2120 insertions(+), 1686 deletions(-)Quoted 2 lines
--
2.11.0Today, we have different kernel interfaces(aRFS/ethtool/tc) to do flow offloading.
One big question arises in my mind that why we need these all different interfaces to do flow offloading and why can't they just be combined into a single kernel interface somehow.
Having these flow offloading done through various hooks makes driver implementation really complex.
Quoted 7 lines
Specially when looking at ethtool/tc flows most of the use cases seems common to me -
1. Drop action can be done on tuples from both tc/ethtool flows.
2. Flow redirection is done from both ethtool/tc
(May be with just slight difference ? as Ethtool does steering on PF and VF/VF-queues
but tc doesn't have redirection on queues which can be extended over tc)
3. Could be more such common cases which could be the reason to combine them through single interface ?
Sure you can make one interface feature complete. But that does not mean you can remove the others. At least not easily. You woul break UAPI.
Quoted 5 lines
Thanks !!
Quoted 145 lines · Jiri Pirko
Quoted 144 lines · Mon, Nov 19, 2018 at 10:19:28AM CET, [email protected] wrote:
Quoted 136 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pablo Neira Ayuso
Sent: Friday, November 16, 2018 7:11 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Elior, Ariel <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH 00/10] addflow_ruleinfrastructureExternal Email
This patchset introduces a kernel intermediate representation (IR) to express ACL hardware offloads, this is heavily based on the existing flow dissector infrastructure and the TC actions. This IR can be used by different frontend ACL interfaces such as
ethtool_rxnfcand tc to represent ACL hardware offloads. Main goal is to simplify the development of ACL hardware offloads for the existing frontend interfaces, the idea is that driver developers do not need to add one specific parser for each ACL frontend, instead each frontend can just generate thisflow_ruleIR and pass it to drivers to populate the hardware IR..
ethtool_rxnfctc
| (ioctl) (netlink)
| | | translate native
Frontend | | | interface representation
| | | toflow_ruleIR
| | |
. \/ \/
.flow_ruleIR
| |
Drivers | | parsing offlow_ruleIR
| | to populate hardware IR
| \/
. hardware IR (driver)For design and implementation details, please have a look at:
https://lwn.net/Articles/766695/As an example, with this patchset, it should be possible to simplify the existing net/qede driver which already has two parsers to populate the hardware IR, one for
ethtool_rxnfcinterface and another for tc.This batch is composed of 10 patches:
Patch #1 adds the
flow_matchstructure, this includes the
flow_rule_match_key()interface to check for existing selectors that are in used in the rule and the flow_rule_match_*() functions to fetch the selector value and the mask. This also introduces the initialflow_rulestructure skeleton to avoid a follow up patch that would update the same LoCs.Patch #2 makes changes to packet edit parser of mlx5e driver, to prepare
introduction of the newflow_actionto mangle packets.Patch #3 Introduce
flow_actioninfrastructure. This infrastructure is
based on the TC actions. Patch #8 extends it so it also supports two new actions that are only available through theethtool_rxnfcinterface.Patch #4 Add function to translate TC action to
flow_actionfrom
cls_flower.Patch #5 Add infrastructure to fetch statistics into container structure
and synchronize them to TC actions fromcls_flower. Another preparation patch before patch #7, so we can stop exposing the TC action native layout to the drivers.Patch #6 Use
flow_actioninfrastructure from drivers.Patch #7 Do not expose TC actions to drivers anymore, now that drivers
have been converted to use theflow_actioninfrastructure after patch #5.Patch #8 Support to wake-up-on-lan and queue actions for the
flow_action
infrastructure, two actions supported by NICs. This is used by theethtool_rx_flowinterface.Patch #9 Add a function to translate from
ethtool_rx_flow_specstructure
to theflow_actionstructure. This is a simple enough for its first client: theethtool_rxnfcinterface in thebcm_sf2driver.Patch #10 Update
bcm_sf2to use this new translator function and
update codebase to configure hardware IR using theflow_actionrepresentation. This will allow later development ofcls_flowerusing the same codebase from the driver.This patchset has passed here functional tests of the codepath that generates the
flow_rulestructure and the functions to implement the parsers that populate the hardware IR.Thanks.
Pablo Neira Ayuso (10):
flow_dissector: addflow_ruleandflow_matchstructures and use them net/mlx5e: support for two independent packet edit actions
flow_dissector: add flow action infrastructure
cls_api: add translator toflow_actionrepresentation
cls_flower: add statistics retrieval infrastructure and use it
drivers: net: use flow action infrastructure
cls_flower: don't expose TC actions to drivers anymore
flow_dissector: add wake-up-on-lan and queue toflow_action
flow_dissector: add basicethtool_rx_flow_spectoflow_rulestructure
translator
dsa:bcm_sf2: useflow_ruleinfrastructuredrivers/net/dsa/bcm_sf2_cfp.c | 103 ++- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 252 +++---- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 450 ++++++------- drivers/net/ethernet/intel/i40e/i40e_main.c | 178 ++--- drivers/net/ethernet/intel/iavf/iavf_main.c | 195 +++--- drivers/net/ethernet/intel/igb/igb_main.c | 64 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 743 ++++++++++-------- --- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 259 ++++--- drivers/net/ethernet/netronome/nfp/flower/action.c | 196 +++--- drivers/net/ethernet/netronome/nfp/flower/match.c | 416 ++++++------ .../net/ethernet/netronome/nfp/flower/offload.c | 151 ++--- drivers/net/ethernet/qlogic/qede/qede_filter.c | 93 ++- include/net/flow_dissector.h | 185 +++++ include/net/pkt_cls.h | 23 +- net/core/flow_dissector.c | 341 ++++++++++ net/sched/cls_api.c | 113 ++++ net/sched/cls_flower.c | 42 +- 18 files changed, 2120 insertions(+), 1686 deletions(-)Quoted 2 lines
--
2.11.0Today, we have different kernel interfaces(aRFS/ethtool/tc) to do flow offloading.
One big question arises in my mind that why we need these all different interfaces to do flow offloading and why can't they just be combined into a single kernel interface somehow.
Having these flow offloading done through various hooks makes driver implementation really complex.
Quoted 6 lines
Quoted 6 lines
Specially when looking at ethtool/tc flows most of the use cases seems common to me -
1. Drop action can be done on tuples from both tc/ethtool flows.
2. Flow redirection is done from both ethtool/tc
(May be with just slight difference ? as Ethtool does steering on PF and VF/VF-queues
but tc doesn't have redirection on queues which can be extended over tc)
We discussed several times before with Jiri at various conferences, and I unfortunately don't have the time to look into doing it, but if cls_flower gained support for ethtool_rx_flow_spec::location, we should be good in terms of feature parity. Pablo also identified the RX_CLS_FLOW_WAKE as something that needs to be supported, but this is a simple thing that could be implemented as a special tc action (should?)
Quoted 1 line
Quoted 1 line
3. Could be more such common cases which could be the reason to combine them through single interface ?
Main reason IMHO for going to an unified interface is that ultimately the piece of HW that implements filtering/action is shared across all programming interfaces. If they all have about roughly the same feature set, yet some slight feature deviation or semantic differences, this gets confusing for driver writers and users.
Quoted 3 lines
Sure you can make one interface feature complete. But that does not mean you can remove the others. At least not easily. You woul break UAPI.
Indeed, though we can have a couple of strategies to unify and later deprecate them:
1) Go after each application and make them use the chosen interface, e.g: the tc/cls_flower UAPI, this does not really scale well because while we can easily get mainstream reference applications converted such as ethtool, iptables, xtables, we don't know what people have designed around the UAPI interface, and usually this also does not mean bindings to different languages (e.g: ethtool python) would be converted. Because we have the application converted to the native interface, there is no loss in translation or performance penalty from going to the kernel's IR.
2) We convert the non-chosen interfaces (e.g: ethtool, *tables) from within the kernel through the chosen IR and programming interface, that way we can easily identify which applications are still using the deprecated interface and issue an appropriate warning in kernel version XZY for instance. The drawback is that you have a translation so that could mean loss of information and/or performance penalty if rule insertion/deletion is a hot path (which is unfortunately likely the case).
Signature · 1 line
Florian