add flow_rule infrastructure
Subsystems (13)
cover add flow_rule infrastructure
Hi,
This patchset spins over the existing kernel representation for network driver offloads based on the existing cls_flower dissector use for the rule matching side and the TC action infrastructure to represent the action side.
The proposed object that represent rules looks like this:
struct flow_rule {
struct flow_match match;
struct flow_action action;
};The flow_match structure wraps Jiri Pirko's existing representation available in cls_flower based on dissectors to represent the matching side:
struct flow_match {
struct flow_dissector *dissector;
void *mask;
void *key;
};The mask and key layouts are opaque, given the dissector object provides the used_keys flags - to check for rule selectors that are being used - and the offset to the corresponding key and mask in the opaque container structures.
Then, the actions to be performs on the matching packets is represented through the flow_action object:
struct flow_action {
int num_keys;
struct flow_action_key *keys;
};This object comes with a num_keys field that specifies the number of actions - this supports an arbitrary number of actions, the driver will impose its own restrictions on this - and the array that stores flow_action_key structures (keys). Each flow action key looks like this:
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 */
u32 queue_index; /* FLOW_ACTION_KEY_QUEUE */
};
};Possible actions in this patchset are:
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,
FLOW_ACTION_KEY_WAKE,
FLOW_ACTION_KEY_QUEUE,
};which are based on what existing drivers can do from the existing TC actions.
Common code pattern from the drivers to populate the hardware intermediate representation looks like this:
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->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;
}Then, flow action code parser should look like:
flow_action_for_each(i, act, flow_action) {
switch (act->id) {
case FLOW_ACTION_KEY_DROP:
actions->flags |= DRIVER_XYZ_ACTION_FLAG_DROP;
break;
case ...:
break;
default:
return -EOPNOTSUPP;
}
}A quick description of the patches:
Patch #1 introduces the flow_match structure and two new interfaces to
check for rule selectors that are used and to fetch the key and the mask with one single function call. This patch also introduces the flow_rule structure to avoid a follow up patch that would very much update the same LoCs.
Patch #2 Preparation patch for mlx5e driver, for the packet edit parser.
Patch #3 Introduce flow_action infrastructure, as described above.
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.
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, which are another two common actions supported by network interfaces, from 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 one, basic enough for the first client, the bcm_sf2 driver. It can be easily extended to support more selectors in case driver needs it.
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 backend code from the driver.
This patchset is adding a new layer between drivers and the existing software frontends, so it's a bit more code, but it is core infrastructure common to everyone and this comes with benefits for driver developers:
1) No need to make ad-hoc driver code for each supported front-end, one single codebase to populate the native hardware intermediate representation for each existing specific purpose packet classifiers such as TC, OVS, ethtool-rx-flow and net...
2) Independent API for drivers offloads, the use of the existing TC action infrastructure makes it slightly hard to visibilize what drivers are currently supporting in terms of features. Moreover, no more exposure of TC software representation to drivers, so future software changes to TC won't need to be propagated to drivers, which might accidentally break existing hardware offload codebase in case the software frontend gets extended with some new features.
There is still room for more future work, such as introduce more common
infrastructure: Most drivers use a hashtable to represent the hardware table indexed by the cookie, it should be possible to share this.
I made basic testing for this initial RFC, so more extensive to ensure things don't break might be needed still. That would happen in a later stage if feedback is positive.
Comments welcome as usual, thanks.
Pablo Neira Ayuso (10):
flow_dissector: add flow_rule and flow_match structures and use them net/mlx5e: allow two independent packet edit actions
flow_dissector: add flow action infrastructure
cls_flower: 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 | 311 ++++----- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 256 +++----- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 451 ++++++------- drivers/net/ethernet/intel/i40e/i40e_main.c | 178 ++--- drivers/net/ethernet/intel/i40evf/i40evf_main.c | 194 +++--- drivers/net/ethernet/intel/igb/igb_main.c | 64 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 725 ++++++++++----------- drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 260 ++++---- drivers/net/ethernet/netronome/nfp/flower/action.c | 194 +++--- drivers/net/ethernet/netronome/nfp/flower/match.c | 416 ++++++------ .../net/ethernet/netronome/nfp/flower/offload.c | 150 ++--- drivers/net/ethernet/qlogic/qede/qede_filter.c | 93 ++- include/net/flow_dissector.h | 185 ++++++ include/net/pkt_cls.h | 20 +- net/core/flow_dissector.c | 341 ++++++++++ net/sched/cls_flower.c | 151 ++++- 17 files changed, 2199 insertions(+), 1792 deletions(-)
RFC PATCH 2/10 net/mlx5e: allow two independent packet edit actions
Although the packet edit infrastructure allows an arbitrary number of packet mangling in the same action, it is still possible to define a rule with two or more packet edit instances. This would result in the last packet mangling action being applied to the mlx5e driver.
This patch adds pedit_headers_action struct that annotates the headers mangling configuration that is used to configure hardware. Then, alloc_tc_pedit_action() is called to populate the mlx5e hardware intermediate representation once all actions have been parsed.
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 77 +++++++++++++++++-------- 1 file changed, 54 insertions(+), 23 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +54 -23
@@ -1600,6 +1600,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),
@@ -1611,16 +1617,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;
@@ -1676,8 +1681,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 pedit_headers *set_masks, *add_masks, *set_vals, *add_vals;
@@ -1691,10 +1695,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;
@@ -1784,12 +1788,12 @@ 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, +u32 pedits,int namespace,struct mlx5e_tc_flow_parse_attr *parse_attr) {int nkeys, action_size, max_actions; - nkeys =tcf_pedit_nkeys (a); + nkeys = pedits; action_size =MLX5_UN_SZ_BYTES (set_action_in_add_action_in_auto);if (namespace ==MLX5_FLOW_NAMESPACE_FDB )/* FDB offloading */
@@ -1812,17 +1816,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 mlx5e_tc_flow_parse_attr *parse_attr, +struct pedit_headers_action *hdrs) { -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); + hdrs->pedits += nkeys;for (i =0 ; i < nkeys; i++) { htype =tcf_pedit_htype (a, i);
@@ -1843,21 +1845,34 @@ 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; } - 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 pedit_headers *cmd_masks; +int err; +u8 cmd; + + err =alloc_mod_hdr_actions (priv, hdrs->pedits, namespace, parse_attr);if (err) goto out_err; - err =offload_pedit_fields (masks, vals, parse_attr); + err =offload_pedit_fields (hdrs, parse_attr);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))) {netdev_warn (priv->netdev,"attempt to offload an unsupported field (cmd %d)\n" , cmd); print_hex_dump(KERN_WARNING, "mask: ", DUMP_PREFIX_ADDRESS,
@@ -1984,6 +1999,7 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,struct mlx5e_tc_flow_parse_attr *parse_attr, struct mlx5e_tc_flow *flow) { + 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);
@@ -2006,7 +2022,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); + parse_attr, hdrs);if (err)return err;
@@ -2057,6 +2073,13 @@ static int parse_tc_nic_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,return -EINVAL ; } +if (hdrs->pedits) { + err =alloc_tc_pedit_action (priv,MLX5_FLOW_NAMESPACE_KERNEL , + parse_attr, hdrs); +if (err) +return err; + } + attr->action = action;if (!actions_match_supported (priv, exts, parse_attr, flow))return -EOPNOTSUPP ;
@@ -2593,6 +2616,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,struct mlx5e_tc_flow_parse_attr *parse_attr, struct mlx5e_tc_flow *flow) { + struct pedit_headers_action hdrs[__PEDIT_CMD_MAX] = {};struct mlx5_esw_flow_attr *attr = flow->esw_attr;struct mlx5e_rep_priv *rpriv = priv->ppriv;struct ip_tunnel_info *info =NULL ;
@@ -2617,7 +2641,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); + parse_attr, hdrs);if (err)return err;
@@ -2699,6 +2723,13 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,return -EINVAL ; } +if (hdrs->pedits) { + err =alloc_tc_pedit_action (priv,MLX5_FLOW_NAMESPACE_KERNEL , + parse_attr, hdrs); +if (err) +return err; + } + attr->action = action;if (!actions_match_supported (priv, exts, parse_attr, flow))return -EOPNOTSUPP ;
Signature · 1 line
2.11.0
RFC PATCH 3/10 flow_dissector: add flow action infrastructure
In reply to Pablo Neira AyusoThis patch adds new infrastructure that defines actions that you can perform in existing network drivers. This infrastructure allows us to avoid the direct dependency with the software TC action infrastructure.
--- 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
@@ -195,6 +195,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_be16 - extract be16 entity * @skb: sk_buff to extract from
Signature · 1 line
2.11.0
RFC PATCH 4/10 cls_flower: add translator to flow_action representation
In reply to Pablo Neira AyusoThis implements TC action to flow_action translation from cls_flower.
--- net/sched/cls_flower.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-)
net/sched/cls_flower.c +123 -1
@@ -28,6 +28,14 @@#include <net/dst.h> #include <net/dst_metadata.h> +#include <net/tc_act/tc_mirred.h> +#include <net/tc_act/tc_vlan.h> +#include <net/tc_act/tc_tunnel_key.h> +#include <net/tc_act/tc_pedit.h> +#include <net/tc_act/tc_csum.h> +#include <net/tc_act/tc_gact.h> +#include <net/tc_act/tc_skbedit.h> +#include <net/tc_act/tc_mirred.h> struct fl_flow_key {int indev_ifindex;
@@ -101,6 +109,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 = {
@@ -294,6 +303,107 @@ static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f,tcf_block_offload_dec (block, &f->flags); } +static int fl_hw_setup_action (struct flow_action *flow_action, +const struct tcf_exts *exts) +{ +const struct tc_action *act; +int num_acts =0 , i, j, k; + +if (!exts) +return 0 ; + +tcf_exts_for_each_action (i, act, exts) { +if (is_tcf_pedit (act)) + num_acts +=tcf_pedit_nkeys (act); +else + num_acts++; + } + +if (!num_acts) +return 0 ; + +if (flow_action_init (flow_action, num_acts) <0 ) +return -ENOMEM ; + + j =0 ; +tcf_exts_for_each_action (i, act, exts) { +struct flow_action_key *key; + + key = &flow_action->keys[j]; +if (is_tcf_gact_ok (act)) { + key->id =FLOW_ACTION_KEY_ACCEPT ; + }else if (is_tcf_gact_shot (act)) { + key->id =FLOW_ACTION_KEY_DROP ; + }else if (is_tcf_gact_trap (act)) { + key->id =FLOW_ACTION_KEY_TRAP ; + }else if (is_tcf_gact_goto_chain (act)) { + key->id =FLOW_ACTION_KEY_GOTO ; + key->chain_index =tcf_gact_goto_chain_index (act); + }else if (is_tcf_mirred_egress_redirect (act)) { + key->id =FLOW_ACTION_KEY_REDIRECT ; + key->dev =tcf_mirred_dev (act); + }else if (is_tcf_mirred_egress_mirror (act)) { + key->id =FLOW_ACTION_KEY_MIRRED ; + key->dev =tcf_mirred_dev (act); + }else if (is_tcf_vlan (act)) { +switch (tcf_vlan_action (act)) { +case TCA_VLAN_ACT_PUSH : + key->id =FLOW_ACTION_KEY_VLAN_PUSH ; + key->vlan.vid =tcf_vlan_push_vid (act); + key->vlan.proto =tcf_vlan_push_proto (act); + key->vlan.prio =tcf_vlan_push_prio (act); +break ; +case TCA_VLAN_ACT_POP : + key->id =FLOW_ACTION_KEY_VLAN_POP ; +break ; +case TCA_VLAN_ACT_MODIFY : + key->id =FLOW_ACTION_KEY_VLAN_MANGLE ; + key->vlan.vid =tcf_vlan_push_vid (act); + key->vlan.proto =tcf_vlan_push_proto (act); + key->vlan.prio =tcf_vlan_push_prio (act); +break ; + } + }else if (is_tcf_tunnel_set (act)) { + key->id =FLOW_ACTION_KEY_TUNNEL_ENCAP ; + key->tunnel =tcf_tunnel_info (act); + }else if (is_tcf_tunnel_release (act)) { + key->id =FLOW_ACTION_KEY_TUNNEL_DECAP ; + key->tunnel =tcf_tunnel_info (act); + }else if (is_tcf_pedit (act)) { +for (k =0 ; k <tcf_pedit_nkeys (act); k++) { +switch (tcf_pedit_cmd (act, k)) { +case TCA_PEDIT_KEY_EX_CMD_SET : + key->id =FLOW_ACTION_KEY_MANGLE ; +break ; +case TCA_PEDIT_KEY_EX_CMD_ADD : + key->id =FLOW_ACTION_KEY_ADD ; +break ; +default : +WARN_ON_ONCE (1 ); +break ; + } + + key->mangle.htype =tcf_pedit_htype (act, k); + key->mangle.mask =tcf_pedit_mask (act, k); + key->mangle.val =tcf_pedit_val (act, k); + key->mangle.offset =tcf_pedit_offset (act, k); + key = &flow_action->keys[++j]; + } + }else if (is_tcf_csum (act)) { + key->id =FLOW_ACTION_KEY_CSUM ; + key->csum_flags =tcf_csum_update_flags (act); + }else if (is_tcf_skbedit_mark (act)) { + key->id =FLOW_ACTION_KEY_MARK ; + key->mark =tcf_skbedit_mark (act); + } + +if (!is_tcf_pedit (act)) + j++; + } + +return 0 ; +} +static int fl_hw_replace_filter (struct tcf_proto *tp,struct cls_fl_filter *f,struct netlink_ext_ack *extack)
@@ -312,18 +422,27 @@ static int fl_hw_replace_filter(struct tcf_proto *tp, cls_flower.exts = &f->exts; cls_flower.classid = f->res.classid; +if (fl_hw_setup_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 +469,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);
@@ -1341,6 +1461,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
RFC PATCH 5/10 cls_flower: add statistics retrieval infrastructure and use it
In reply to Pablo Neira AyusoProvide a tc_cls_flower_stats structure that acts as container for tc_cls_flower_offload, then restore stats on the 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 | 4 ++-- include/net/pkt_cls.h | 15 +++++++++++++++ net/sched/cls_flower.c | 4 ++++ 7 files changed, 28 insertions(+), 9 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +2 -2
@@ -1358,8 +1358,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
@@ -2906,7 +2906,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
@@ -461,7 +461,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 +2 -2
@@ -577,8 +577,8 @@ nfp_flower_get_stats(struct nfp_app *app, struct net_device *netdev,return 0 ;spin_lock_bh (&nfp_flow->lock); -tcf_exts_stats_update (flow->exts, nfp_flow->stats.bytes, - nfp_flow->stats.pkts, nfp_flow->stats.used); +tc_cls_flower_stats_update (flow, nfp_flow->stats.bytes, + nfp_flow->stats.pkts, nfp_flow->stats.used); nfp_flow->stats.pkts =0 ; nfp_flow->stats.bytes =0 ;
include/net/pkt_cls.h +15 -0
@@ -731,6 +731,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;
@@ -738,8 +744,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
@@ -460,6 +460,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
RFC 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
RFC 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
@@ -742,7 +742,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
@@ -419,7 +419,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 (fl_hw_setup_action (&f->action, &f->exts) <0 )
@@ -455,7 +454,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,
@@ -1464,7 +1462,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;
@@ -1489,7 +1486,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 ;
@@ -1497,7 +1493,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
RFC 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 the flower and the ethtool_rx_flow interface 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
RFC 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 the same code to populate hardware IR can be used from ethtool_rx_flow and the cls_flower interfaces.
--- drivers/net/dsa/bcm_sf2_cfp.c | 311 ++++++++++++++++++++++-------------------- 1 file changed, 166 insertions(+), 145 deletions(-)
drivers/net/dsa/bcm_sf2_cfp.c +166 -145
@@ -251,10 +251,12 @@ 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_rule *flow_rule,unsigned int slice_num,bool mask) { +struct flow_match_ipv4_addrs ipv4; +struct flow_match_ports ports;u32 reg, offset;/* C-Tag [31:24]
@@ -268,41 +270,54 @@ static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv, offset =CORE_CFP_DATA_PORT (4 );core_writel (priv, reg, offset); +flow_rule_match_ipv4_addrs (flow_rule, &ipv4); +flow_rule_match_ports (flow_rule, &ports); +/* UDF_n_A7 [31:24] * UDF_n_A6 [23:8] * UDF_n_A5 [7:0] */ - reg =be16_to_cpu (v4_spec->pdst) >>8 ; -if (mask) +if (mask) { + reg =be16_to_cpu (ports.mask->dst) >>8 ; offset =CORE_CFP_MASK_PORT (3 ); -else + }else { + reg =be16_to_cpu (ports.key->dst) >>8 ; offset =CORE_CFP_DATA_PORT (3 ); + }core_writel (priv, reg, offset);/* UDF_n_A5 [31:24] * 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 ; -if (mask) +if (mask) { + reg = (be16_to_cpu (ports.mask->dst) &0xff ) <<24 | + (u32 )be16_to_cpu (ports.mask->src) <<8 | + (be32_to_cpu (ipv4.mask->dst) &0x0000ff00 ) >>8 ; offset =CORE_CFP_MASK_PORT (2 ); -else + }else { + reg = (be16_to_cpu (ports.key->dst) &0xff ) <<24 | + (u32 )be16_to_cpu (ports.key->src) <<8 | + (be32_to_cpu (ipv4.key->dst) &0x0000ff00 ) >>8 ; offset =CORE_CFP_DATA_PORT (2 ); + }core_writel (priv, reg, offset);/* UDF_n_A3 [31:24] * 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 ; -if (mask) +if (mask) { + reg = (u32)(be32_to_cpu (ipv4.mask->dst) &0xff ) <<24 | + (u32)(be32_to_cpu (ipv4.mask->dst) >>16 ) <<8 | + (be32_to_cpu (ipv4.mask->src) &0x0000ff00 ) >>8 ; offset =CORE_CFP_MASK_PORT (1 ); -else + }else { + reg = (u32)(be32_to_cpu (ipv4.key->dst) &0xff ) <<24 | + (u32)(be32_to_cpu (ipv4.key->dst) >>16 ) <<8 | + (be32_to_cpu (ipv4.key->src) &0x0000ff00 ) >>8 ; offset =CORE_CFP_DATA_PORT (1 ); + }core_writel (priv, reg, offset);/* UDF_n_A1 [31:24]
@@ -311,56 +326,34 @@ 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 | -SLICE_NUM (slice_num) |SLICE_VALID ; -if (mask) +if (mask) { + reg = (u32)(be32_to_cpu (ipv4.mask->src) &0xff ) <<24 | + (u32)(be32_to_cpu (ipv4.mask->src) >>16 ) <<8 | +SLICE_NUM (slice_num) |SLICE_VALID ; offset =CORE_CFP_MASK_PORT (0 ); -else + }else { + reg = (u32)(be32_to_cpu (ipv4.key->src) &0xff ) <<24 | + (u32)(be32_to_cpu (ipv4.key->src) >>16 ) <<8 | +SLICE_NUM (slice_num) |SLICE_VALID ; offset =CORE_CFP_DATA_PORT (0 ); + }core_writel (priv, reg, offset); }static int bcm_sf2_cfp_ipv4_rule_set (struct bcm_sf2_priv *priv,int port,unsigned int port_num,unsigned int queue_num, -struct ethtool_rx_flow_spec *fs) +struct flow_rule *flow_rule, +unsigned int rule_index,u8 ip_frag) { -struct ethtool_tcpip4_spec *v4_spec, *v4_m_spec;const struct cfp_udf_layout *layout; -unsigned int slice_num, rule_index; -u8 ip_proto, ip_frag; +struct flow_match_basic basic; +struct flow_match_ip ip; +unsigned int slice_num;u8 num_udf;u32 reg;int ret; -switch (fs->flow_type & ~FLOW_EXT ) { -case TCP_V4_FLOW : - ip_proto =IPPROTO_TCP ; - v4_spec = &fs->h_u.tcp_ip4_spec; - v4_m_spec = &fs->m_u.tcp_ip4_spec; -break ; -case UDP_V4_FLOW : - ip_proto =IPPROTO_UDP ; - v4_spec = &fs->h_u.udp_ip4_spec; - v4_m_spec = &fs->m_u.udp_ip4_spec; -break ; -default : -return -EINVAL ; - } - - ip_frag =be32_to_cpu (fs->m_ext.data[0 ]); - -/* Locate the first rule available */ -if (fs->location ==RX_CLS_LOC_ANY ) - rule_index =find_first_zero_bit (priv->cfp.used, - priv->num_cfp_rules); -else - rule_index = fs->location; - -if (rule_index >bcm_sf2_cfp_rule_size (priv)) -return -ENOSPC ; - layout = &udf_tcpip4_layout;/* We only use one UDF slice for now */ slice_num =bcm_sf2_get_slice_number (layout,0 );
@@ -378,6 +371,9 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,/* Source port map match */ core_writel (priv,0xff ,CORE_CFP_MASK_PORT (7 )); +flow_rule_match_basic (flow_rule, &basic); +flow_rule_match_ip (flow_rule, &ip); +/* S-Tag status [31:30] * C-Tag status [29:28] * L2 framing [27:26]
@@ -392,8 +388,9 @@ 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 | +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 ));
@@ -411,8 +408,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, flow_rule, slice_num, false); +bcm_sf2_cfp_slice_ipv4 (priv, flow_rule,SLICE_NUM_MASK , true);/* Insert into TCAM now */ bcm_sf2_cfp_rule_addr_set (priv, rule_index);
@@ -437,9 +434,8 @@ static int bcm_sf2_cfp_ipv4_rule_set(struct bcm_sf2_priv *priv, int port,/* Flag the rule as being used and return it */ set_bit (rule_index, priv->cfp.used);set_bit (rule_index, priv->cfp.unique); - fs->location = rule_index; -return 0 ; +return rule_index; } static void bcm_sf2_cfp_slice_ipv6(struct bcm_sf2_priv *priv,
@@ -518,33 +514,18 @@ static void bcm_sf2_cfp_slice_ipv6(struct bcm_sf2_priv *priv,static int bcm_sf2_cfp_ipv6_rule_set (struct bcm_sf2_priv *priv,int port,unsigned int port_num,unsigned int queue_num, -struct ethtool_rx_flow_spec *fs) +struct flow_rule *flow_rule, +unsigned int *rule_index,u8 ip_frag) { -struct ethtool_tcpip6_spec *v6_spec, *v6_m_spec; -unsigned int slice_num, rule_index[2 ];const struct cfp_udf_layout *layout; -u8 ip_proto, ip_frag; +struct flow_match_ipv6_addrs ipv6; +struct flow_match_ports ports; +struct flow_match_basic basic; +unsigned int slice_num;int ret =0 ;u8 num_udf;u32 reg; -switch (fs->flow_type & ~FLOW_EXT ) { -case TCP_V6_FLOW : - ip_proto =IPPROTO_TCP ; - v6_spec = &fs->h_u.tcp_ip6_spec; - v6_m_spec = &fs->m_u.tcp_ip6_spec; -break ; -case UDP_V6_FLOW : - ip_proto =IPPROTO_UDP ; - v6_spec = &fs->h_u.udp_ip6_spec; - v6_m_spec = &fs->m_u.udp_ip6_spec; -break ; -default : -return -EINVAL ; - } - - ip_frag =be32_to_cpu (fs->m_ext.data[0 ]); - layout = &udf_tcpip6_layout; slice_num =bcm_sf2_get_slice_number (layout,0 );if (slice_num ==UDF_NUM_SLICES )
@@ -552,38 +533,6 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port, num_udf =bcm_sf2_get_num_udf_slices (layout->udfs[slice_num].slices); -/* Negotiate two indexes, one for the second half which we are chained -* from, which is what we will return to user-space, and a second one -* which is used to store its first half. That first half does not -* allow any choice of placement, so it just needs to find the next -* available bit. We return the second half as fs->location because -* that helps with the rule lookup later on since the second half is -* chained from its first half, we can easily identify IPv6 CFP rules -* by looking whether they carry a CHAIN_ID. -* -* We also want the second half to have a lower rule_index than its -* first half because the HW search is by incrementing addresses. -*/ -if (fs->location ==RX_CLS_LOC_ANY ) - rule_index[1 ] =find_first_zero_bit (priv->cfp.used, - priv->num_cfp_rules); -else - rule_index[1 ] = fs->location; -if (rule_index[1 ] >bcm_sf2_cfp_rule_size (priv)) -return -ENOSPC ; - -/* Flag it as used (cleared on error path) such that we can immediately -* obtain a second one to chain from. -*/ -set_bit (rule_index[1 ], priv->cfp.used); - - rule_index[0 ] =find_first_zero_bit (priv->cfp.used, - priv->num_cfp_rules); -if (rule_index[0 ] >bcm_sf2_cfp_rule_size (priv)) { - ret = -ENOSPC ; - goto out_err; - } -/* Apply the UDF layout for this filter */ bcm_sf2_cfp_udf_set (priv, layout, slice_num);
@@ -593,6 +542,8 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,/* Source port map match */ core_writel (priv,0xff ,CORE_CFP_MASK_PORT (7 )); +flow_rule_match_basic (flow_rule, &basic); +/* S-Tag status [31:30] * C-Tag status [29:28] * L2 framing [27:26]
@@ -607,7 +558,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 ));
@@ -626,11 +577,14 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,/* Mask all but valid UDFs */ core_writel (priv,udf_lower_bits (num_udf) <<24 ,CORE_CFP_MASK_PORT (5 )); +flow_rule_match_ipv6_addrs (flow_rule, &ipv6); +flow_rule_match_ports (flow_rule, &ports); +/* 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 ]);
@@ -638,21 +592,19 @@ 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; +return ret; }/* 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; +return ret;/* 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; - } +if (slice_num ==UDF_NUM_SLICES ) +return -EINVAL ; num_udf =bcm_sf2_get_num_udf_slices (layout->udfs[slice_num].slices);
@@ -687,10 +639,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 ]);
@@ -698,7 +650,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; +return ret; }/* Insert into Action and policer RAMs now, set chain ID to
@@ -707,7 +659,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; +return ret;/* Turn on CFP for this rule now */ reg =core_readl (priv,CORE_CFP_CTL_REG );
@@ -719,13 +671,8 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,*/ set_bit (rule_index[0 ], priv->cfp.used);set_bit (rule_index[1 ], priv->cfp.unique); - fs->location = rule_index[1 ]; - -return ret; -out_err: -clear_bit (rule_index[1 ], priv->cfp.used); -return ret; +return rule_index[1 ]; } static int bcm_sf2_cfp_rule_set(struct dsa_switch *ds, int port,
@@ -735,7 +682,10 @@ static int bcm_sf2_cfp_rule_set(struct dsa_switch *ds, int port,s8 cpu_port = ds->ports[port].cpu_dp->index;__u64 ring_cookie = fs->ring_cookie;unsigned int queue_num, port_num; +struct flow_rule *flow_rule; +unsigned int rule_index[2 ];int ret = -EINVAL ; +u8 ip_frag;/* Check for unsupported extensions */ if ((fs->flow_type & FLOW_EXT) && (fs->m_ext.vlan_etype ||
@@ -750,23 +700,38 @@ static int bcm_sf2_cfp_rule_set(struct dsa_switch *ds, int port, fs->location > bcm_sf2_cfp_rule_size(priv))return -EINVAL ; -/* This rule is a Wake-on-LAN filter and we must specifically -* target the CPU port in order for it to be working. -*/ -if (ring_cookie ==RX_CLS_FLOW_WAKE ) - ring_cookie = cpu_port *SF2_NUM_EGRESS_QUEUES ; - -/* We do not support discarding packets, check that the -* destination port is enabled and that we are within the +/* Check that the destination port is enabled and that we are within the * number of ports supported by the switch */ port_num = ring_cookie /SF2_NUM_EGRESS_QUEUES ; - -if (ring_cookie ==RX_CLS_FLOW_DISC || - !(dsa_is_user_port (ds, port_num) || +if (!(dsa_is_user_port (ds, port_num) ||dsa_is_cpu_port (ds, port_num)) || port_num >= priv->hw_params.num_ports)return -EINVAL ; + +/* User-defined data semantics depends on each driver. */ + ip_frag =be32_to_cpu (fs->m_ext.data[0 ]); + + flow_rule =ethtool_rx_flow_rule (fs); +if (!flow_rule) +return -ENOMEM ; + +switch (flow_rule->action.keys[0 ].id) { +case FLOW_ACTION_KEY_WAKE : +/* This rule is a Wake-on-LAN filter and we must specifically +* target the CPU port in order for it to be working. +*/ + ring_cookie = cpu_port *SF2_NUM_EGRESS_QUEUES ; +break ; +case FLOW_ACTION_KEY_QUEUE : + ring_cookie = flow_rule->action.keys[0 ].queue_index; +break ; +default : +/* We do not support discarding packets. */ + ret = -EINVAL ; + goto err_out; + } +/* * We have a small oddity where Port 6 just does not have a * valid bit here (so we substract by one).
@@ -778,17 +743,73 @@ static int bcm_sf2_cfp_rule_set(struct dsa_switch *ds, int port,switch (fs->flow_type & ~FLOW_EXT ) {case TCP_V4_FLOW :case UDP_V4_FLOW : +/* Locate the first rule available */ +if (fs->location ==RX_CLS_LOC_ANY ) + rule_index[0 ] =find_first_zero_bit (priv->cfp.used, + priv->num_cfp_rules); +else + rule_index[0 ] = fs->location; + +if (rule_index[0 ] >bcm_sf2_cfp_rule_size (priv)) { + ret = -ENOSPC ; + goto err_out; + } + ret =bcm_sf2_cfp_ipv4_rule_set (priv, port, port_num, - queue_num, fs); + queue_num, flow_rule, + rule_index[0 ], ip_frag);break ;case TCP_V6_FLOW :case UDP_V6_FLOW : +/* Negotiate two indexes, one for the second half which we are +* chained from, which is what we will return to user-space, and +* a second one which is used to store its first half. That +* first half does not allow any choice of placement, so it just +* needs to find the next available bit. We return the second +* half as fs->location because that helps with the rule lookup +* later on since the second half is chained from its first +* half, we can easily identify IPv6 CFP rules by looking +* whether they carry a CHAIN_ID. +* +* We also want the second half to have a lower rule_index than +* its first half because the HW search is by incrementing +* addresses. +*/ +if (fs->location ==RX_CLS_LOC_ANY ) + rule_index[1 ] =find_first_zero_bit (priv->cfp.used, + priv->num_cfp_rules); +else + rule_index[1 ] = fs->location; + +if (rule_index[1 ] >bcm_sf2_cfp_rule_size (priv)) { + ret = -ENOSPC ; + goto err_out; + } + +/* Flag it as used (cleared on error path) such that we can +* immediately obtain a second one to chain from. +*/ +set_bit (rule_index[1 ], priv->cfp.used); + + rule_index[0 ] =find_first_zero_bit (priv->cfp.used, + priv->num_cfp_rules); +if (rule_index[0 ] >bcm_sf2_cfp_rule_size (priv)) { +clear_bit (rule_index[1 ], priv->cfp.used); + ret = -ENOSPC ; + goto err_out; + } + ret =bcm_sf2_cfp_ipv6_rule_set (priv, port, port_num, - queue_num, fs); + queue_num, flow_rule, + rule_index, ip_frag);break ;default :break ; } +if (ret >=0 ) + fs->location = ret; +err_out: +ethtool_rx_flow_rule_free (flow_rule);return ret; }
Signature · 1 line
2.11.0
RFC 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 | 78 +++---- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 251 ++++++++++---------- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 252 ++++++++++----------- 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 | 183 +++++++-------- drivers/net/ethernet/qlogic/qede/qede_filter.c | 12 +- 7 files changed, 412 insertions(+), 421 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +30 -48
@@ -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" );
@@ -75,25 +75,12 @@ static int bnxt_tc_parse_redir(struct bnxt *bp,return 0 ; } -static void bnxt_tc_parse_vlan (struct bnxt *bp, -struct bnxt_tc_actions *actions, -const struct tc_action *tc_act) -{ -if (tcf_vlan_action (tc_act) ==TCA_VLAN_ACT_POP ) { - actions->flags |=BNXT_TC_ACTION_FLAG_POP_VLAN ; - }else if (tcf_vlan_action (tc_act) ==TCA_VLAN_ACT_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); - } -} -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" );
@@ -107,49 +94,44 @@ 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)) { -bnxt_tc_parse_vlan (bp, actions, tc_act); -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_VLAN_POP : + actions->flags |=BNXT_TC_ACTION_FLAG_POP_VLAN ; +break ; +case FLOW_ACTION_KEY_VLAN_PUSH : + actions->flags |=BNXT_TC_ACTION_FLAG_PUSH_VLAN ; + actions->push_vlan_tci =htons (act->vlan.vid); + actions->push_vlan_tpid = act->vlan.proto; +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 ; } }
@@ -300,7 +282,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 +128 -123
378 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +121 -131
472 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 +93 -90
404 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
RFC 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 - in 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/i40evf/i40evf_main.c | 194 ++++------ drivers/net/ethernet/intel/igb/igb_main.c | 64 ++-- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 418 +++++++++------------ .../net/ethernet/mellanox/mlxsw/spectrum_flower.c | 203 +++++----- 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 | 146 +++---- 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(+), 1201 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +74 -100
@@ -169,18 +169,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 ||
@@ -190,140 +184,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/i40evf/i40evf_main.c +79 -115
335 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 +176 -242
653 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +89 -114
323 lines not on this page · raw message
drivers/net/ethernet/netronome/nfp/flower/action.c +5 -6
@@ -535,6 +535,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_ip4_addrs set_ip_addr;struct nfp_fl_set_tport set_tport;
@@ -586,13 +587,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 +56 -90
214 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.
Re: [PATCH RFC,net-next 04/10] cls_flower: add translator to flow_action representation
In reply to Pablo Neira AyusoQuoted 35 lines · Pablo Neira Ayuso
This implements TC action to
flow_actiontranslation fromcls_flower.Signed-off-by Pablo Neira Ayuso <[email protected]>--- net/sched/cls_flower.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-)net/sched/cls_flower.c +9
-0@@ -28,6 +28,14 @@#include <net/dst.h> #include <net/dst_metadata.h> +#include <net/tc_act/tc_mirred.h> +#include <net/tc_act/tc_vlan.h> +#include <net/tc_act/tc_tunnel_key.h> +#include <net/tc_act/tc_pedit.h> +#include <net/tc_act/tc_csum.h> +#include <net/tc_act/tc_gact.h> +#include <net/tc_act/tc_skbedit.h> +#include <net/tc_act/tc_mirred.h> struct fl_flow_key {int indev_ifindex;@@ -101,6 +109,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 = {
net/sched/cls_flower.c static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f, · line 307
Quoted 5 lines
net/sched/cls_flower.c +2
-0@@ -294,6 +303,107 @@ static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f,tcf_block_offload_dec (block, &f->flags); } +static int fl_hw_setup_action (struct flow_action *flow_action, +const struct tcf_exts *exts)
The function doesn't seem very flower-specific?
Quoted 81 lines
net/sched/cls_flower.c +81
-0+{ +const struct tc_action *act; +int num_acts =0 , i, j, k; + +if (!exts) +return 0 ; + +tcf_exts_for_each_action (i, act, exts) { +if (is_tcf_pedit (act)) + num_acts +=tcf_pedit_nkeys (act); +else + num_acts++; + } + +if (!num_acts) +return 0 ; + +if (flow_action_init (flow_action, num_acts) <0 ) +return -ENOMEM ; + + j =0 ; +tcf_exts_for_each_action (i, act, exts) { +struct flow_action_key *key; + + key = &flow_action->keys[j]; +if (is_tcf_gact_ok (act)) { + key->id =FLOW_ACTION_KEY_ACCEPT ; + }else if (is_tcf_gact_shot (act)) { + key->id =FLOW_ACTION_KEY_DROP ; + }else if (is_tcf_gact_trap (act)) { + key->id =FLOW_ACTION_KEY_TRAP ; + }else if (is_tcf_gact_goto_chain (act)) { + key->id =FLOW_ACTION_KEY_GOTO ; + key->chain_index =tcf_gact_goto_chain_index (act); + }else if (is_tcf_mirred_egress_redirect (act)) { + key->id =FLOW_ACTION_KEY_REDIRECT ; + key->dev =tcf_mirred_dev (act); + }else if (is_tcf_mirred_egress_mirror (act)) { + key->id =FLOW_ACTION_KEY_MIRRED ; + key->dev =tcf_mirred_dev (act); + }else if (is_tcf_vlan (act)) { +switch (tcf_vlan_action (act)) { +case TCA_VLAN_ACT_PUSH : + key->id =FLOW_ACTION_KEY_VLAN_PUSH ; + key->vlan.vid =tcf_vlan_push_vid (act); + key->vlan.proto =tcf_vlan_push_proto (act); + key->vlan.prio =tcf_vlan_push_prio (act); +break ; +case TCA_VLAN_ACT_POP : + key->id =FLOW_ACTION_KEY_VLAN_POP ; +break ; +case TCA_VLAN_ACT_MODIFY : + key->id =FLOW_ACTION_KEY_VLAN_MANGLE ; + key->vlan.vid =tcf_vlan_push_vid (act); + key->vlan.proto =tcf_vlan_push_proto (act); + key->vlan.prio =tcf_vlan_push_prio (act); +break ; + } + }else if (is_tcf_tunnel_set (act)) { + key->id =FLOW_ACTION_KEY_TUNNEL_ENCAP ; + key->tunnel =tcf_tunnel_info (act); + }else if (is_tcf_tunnel_release (act)) { + key->id =FLOW_ACTION_KEY_TUNNEL_DECAP ; + key->tunnel =tcf_tunnel_info (act); + }else if (is_tcf_pedit (act)) { +for (k =0 ; k <tcf_pedit_nkeys (act); k++) { +switch (tcf_pedit_cmd (act, k)) { +case TCA_PEDIT_KEY_EX_CMD_SET : + key->id =FLOW_ACTION_KEY_MANGLE ; +break ; +case TCA_PEDIT_KEY_EX_CMD_ADD : + key->id =FLOW_ACTION_KEY_ADD ; +break ; +default : +WARN_ON_ONCE (1 ); +break ; + } + + key->mangle.htype =tcf_pedit_htype (act, k); + key->mangle.mask =tcf_pedit_mask (act, k); + key->mangle.val =tcf_pedit_val (act, k);
net/sched/cls_flower.c static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f, · line 398
Quoted 10 lines
net/sched/cls_flower.c +10
-0+ key->mangle.offset =tcf_pedit_offset (act, k); + key = &flow_action->keys[++j]; + } + }else if (is_tcf_csum (act)) { + key->id =FLOW_ACTION_KEY_CSUM ; + key->csum_flags =tcf_csum_update_flags (act); + }else if (is_tcf_skbedit_mark (act)) { + key->id =FLOW_ACTION_KEY_MARK ; + key->mark =tcf_skbedit_mark (act); + }
Why the permissiveness? Shouldn't we error out if we there is an unknown action?
else -EOPNOTSUPP + extack?
Quoted 11 lines
net/sched/cls_flower.c +8
-0+ +if (!is_tcf_pedit (act)) + j++; + } + +return 0 ; +} +static int fl_hw_replace_filter (struct tcf_proto *tp,struct cls_fl_filter *f,struct netlink_ext_ack *extack)
Quoted 4 lines · Pablo Neira Ayuso
This patchset is adding a new layer between drivers and the existing software frontends, so it's a bit more code, but it is core infrastructure common to everyone and this comes with benefits for driver developers:
Thanks a lot for doing this!!
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · Pablo Neira Ayuso
This patchset is adding a new layer between drivers and the existing software frontends, so it's a bit more code, but it is core infrastructure common to everyone and this comes with benefits for driver developers:
Thanks a lot for doing this!!
Yeah, this is looks great so far, thanks a lot for tackling this.
Signature · 1 line
Florian
Re: [PATCH RFC,net-next 10/10] dsa: bcm_sf2: use flow_rule infrastructure
In reply to Pablo Neira AyusoHi Pablo,
Quoted 3 lines · Pablo Neira Ayuso
Update this driver to use the
flow_ruleinfrastructure, hence the same code to populate hardware IR can be used fromethtool_rx_flowand thecls_flowerinterfaces.
Thanks for doing the conversion, I believe we could change things a little bit such that there are fewer things to audit for correctness, see below:
Quoted 35 lines
Signed-off-by Pablo Neira Ayuso <[email protected]>--- drivers/net/dsa/bcm_sf2_cfp.c | 311 ++++++++++++++++++++++-------------------- 1 file changed, 166 insertions(+), 145 deletions(-)drivers/net/dsa/bcm_sf2_cfp.c +6
-1@@ -251,10 +251,12 @@ 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_rule *flow_rule,unsigned int slice_num,bool mask) { +struct flow_match_ipv4_addrs ipv4; +struct flow_match_ports ports;u32 reg, offset;/* C-Tag [31:24] @@ -268,41 +270,54 @@ static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv, offset =CORE_CFP_DATA_PORT (4 );core_writel (priv, reg, offset); +flow_rule_match_ipv4_addrs (flow_rule, &ipv4); +flow_rule_match_ports (flow_rule, &ports); +/* UDF_n_A7 [31:24] * UDF_n_A6 [23:8] * UDF_n_A5 [7:0] */
drivers/net/dsa/bcm_sf2_cfp.c static void bcm_sf2_cfp_slice_ipv4(struct bcm_sf2_priv *priv, · line 286
Quoted 10 lines
drivers/net/dsa/bcm_sf2_cfp.c +5
-3- reg =be16_to_cpu (v4_spec->pdst) >>8 ; -if (mask) +if (mask) { + reg =be16_to_cpu (ports.mask->dst) >>8 ; offset =CORE_CFP_MASK_PORT (3 ); -else + }else { + reg =be16_to_cpu (ports.key->dst) >>8 ; offset =CORE_CFP_DATA_PORT (3 ); + }
For instance here, instead of having to assign "reg" differently, just have an intermediate struct flow_match_ports variable that either points to &ports.mask or &ports.key.
I quickly glanced through the changes, and I suspect that they are correct, but there is unfortunately way too much code movement within the functions which greatly hinders the ability to have complete confidence in the changes :)
Can you find a way to only perform the ethtool_rx_flow_spec to flow_rule conversion as close as possible from the point of use within the callee?
Thanks!
Signature · 1 line
Florian
Re: [PATCH RFC,net-next 08/10] flow_dissector: add wake-up-on-lan and queue to flow_action
In reply to Pablo Neira AyusoQuoted 4 lines · Pablo Neira Ayuso
These actions need to be added to support bcm sf2 features available through the
ethtool_rx_flowinterface.Signed-off-by Pablo Neira Ayuso <[email protected]>
Signature · 1 line
Florian