mlx5 updates 2021-02-04
Subsystems (5)
From: Saeed Mahameed <[email protected]>
Hi Jakub,
This series adds support for VF tunneling from Vlad, For more information please see tag log below.
Please pull and let me know if there is any problem.
Thanks,
Saeed.
---
The following changes since commit 4d469ec8ec05e1fa4792415de1a95b28871ff2fa:
Merge branch '1GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue (2021-02-04 21:26:28 -0800)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux.git tags/mlx5-updates-2021-02-04
for you to fetch changes up to 823d1f49cd93b04e7ac3957a35153e404201b041:
net/mlx5e: Handle FIB events to update tunnel endpoint device (2021-02-04 22:37:46 -0800)
----------------------------------------------------------------
mlx5-updates-2021-02-04
Vlad Buslov says:
=================
Implement support for VF tunneling
Abstract
Currently, mlx5 only supports configuration with tunnel endpoint IP address on uplink representor. Remove implicit and explicit assumptions of tunnel always being terminated on uplink and implement necessary infrastructure for configuring tunnels on VF representors and updating rules on such tunnels according to routing changes.
SW TC model
From TC perspective VF tunnel configuration requires two rules in both directions:
TX rules
1. Rule that redirects packets from UL to VF rep that has the tunnel endpoint IP address:
$ tc -s filter show dev enp8s0f0 ingress
filter protocol ip pref 4 flower chain 0
filter protocol ip pref 4 flower chain 0 handle 0x1
dst_mac 16:c9:a0:2d:69:2c
src_mac 0c:42:a1:58:ab:e4
eth_type ipv4
ip_flags nofrag
in_hw in_hw_count 1
action order 1: mirred (Egress Redirect to device enp8s0f0_0) stolen
index 3 ref 1 bind 1 installed 377 sec used 0 sec
Action statistics:
Sent 114096 bytes 952 pkt (dropped 0, overlimits 0 requeues 0)
Sent software 0 bytes 0 pkt
Sent hardware 114096 bytes 952 pkt
backlog 0b 0p requeues 0
cookie 878fa48d8c423fc08c3b6ca599b50a97
no_percpu
used_hw_stats delayed2. Rule that decapsulates the tunneled flow and redirects to destination VF representor:
$ tc -s filter show dev vxlan_sys_4789 ingress
filter protocol ip pref 4 flower chain 0
filter protocol ip pref 4 flower chain 0 handle 0x1
dst_mac ca:2e:a7:3f:f5:0f
src_mac 0a:40:bd:30:89:99
eth_type ipv4
enc_dst_ip 7.7.7.5
enc_src_ip 7.7.7.1
enc_key_id 98
enc_dst_port 4789
enc_tos 0
ip_flags nofrag
in_hw in_hw_count 1
action order 1: tunnel_key unset pipe
index 2 ref 1 bind 1 installed 434 sec used 434 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
used_hw_stats delayed action order 2: mirred (Egress Redirect to device enp8s0f0_1) stolen index 4 ref 1 bind 1 installed 434 sec used 0 sec
Action statistics:
Sent 129936 bytes 1082 pkt (dropped 0, overlimits 0 requeues 0) Sent software 0 bytes 0 pkt
Sent hardware 129936 bytes 1082 pkt
backlog 0b 0p requeues 0
cookie ac17cf398c4c69e4a5b2f7aabd1b88ff
no_percpu
used_hw_stats delayed
RX rules
1. Rule that encapsulates the tunneled flow and redirects packets from source VF rep to tunnel device:
$ tc -s filter show dev enp8s0f0_1 ingress
filter protocol ip pref 4 flower chain 0
filter protocol ip pref 4 flower chain 0 handle 0x1
dst_mac 0a:40:bd:30:89:99
src_mac ca:2e:a7:3f:f5:0f
eth_type ipv4
ip_tos 0/0x3
ip_flags nofrag
in_hw in_hw_count 1
action order 1: tunnel_key set
src_ip 7.7.7.5
dst_ip 7.7.7.1
key_id 98
dst_port 4789
nocsum
ttl 64 pipe
index 1 ref 1 bind 1 installed 411 sec used 411 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
no_percpu
used_hw_stats delayed action order 2: mirred (Egress Redirect to device vxlan_sys_4789) stolen index 1 ref 1 bind 1 installed 411 sec used 0 sec
Action statistics:
Sent 5615833 bytes 4028 pkt (dropped 0, overlimits 0 requeues 0) Sent software 0 bytes 0 pkt
Sent hardware 5615833 bytes 4028 pkt
backlog 0b 0p requeues 0
cookie bb406d45d343bf7ade9690ae80c7cba4
no_percpu
used_hw_stats delayed
2. Rule that redirects from tunnel device to UL rep:
$ tc -s filter show dev vxlan_sys_4789 ingress
filter protocol ip pref 4 flower chain 0
filter protocol ip pref 4 flower chain 0 handle 0x1
dst_mac ca:2e:a7:3f:f5:0f
src_mac 0a:40:bd:30:89:99
eth_type ipv4
enc_dst_ip 7.7.7.5
enc_src_ip 7.7.7.1
enc_key_id 98
enc_dst_port 4789
enc_tos 0
ip_flags nofrag
in_hw in_hw_count 1
action order 1: tunnel_key unset pipe
index 2 ref 1 bind 1 installed 434 sec used 434 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
used_hw_stats delayed action order 2: mirred (Egress Redirect to device enp8s0f0_1) stolen index 4 ref 1 bind 1 installed 434 sec used 0 sec
Action statistics:
Sent 129936 bytes 1082 pkt (dropped 0, overlimits 0 requeues 0) Sent software 0 bytes 0 pkt
Sent hardware 129936 bytes 1082 pkt
backlog 0b 0p requeues 0
cookie ac17cf398c4c69e4a5b2f7aabd1b88ff
no_percpu
used_hw_stats delayed
HW offloads model
For hardware offload the goal is to mach packet on both rules without exposing it to software on tunnel endpoint VF. In order to achieve this for tx, TC implementation marks encap rules with tunnel endpoint on mlx5 VF of same eswitch with MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE flag and adds header modification rule to overwrite packet source port to the value of tunnel VF. Eswitch code is modified to recirculate such packets after source port value is changed, which allows second tx rules to match.
For rx path indirect table infrastructure is used to allow fully processing VF tunnel traffic in hardware. To implement such pipeline driver needs to program the hardware after matching on UL rule to overwrite source vport from UL to tunnel VF and recirculate the packet to the root table to allow matching on the rule installed on tunnel VF. For this, indirect table matches all encapsulated traffic by tunnel parameters and all other IP traffic is sent to tunnel VF by the miss rule. Such configuration will cause packet to appear on VF representor instead of VF itself if packet has been matches by indirect table rule based on tunnel parameters but missed on second rule (after recirculation). Handle such case by marking packets processed by indirect table with special 0xFFF value in reg_c1 and extending slow table with additional flow group that matches on reg_c0 (source port value set by indirect tables) and reg_c1 (special 0xFFF mark). When creating offloads fdb tables, install one rule per VF vport to match on recirculated miss packets and redirect them to appropriate VF vport.
Routing events
In order to support routing changes and migration of tunnel device between different endpoint VFs, implement routing infrastructure and update it with FIB events. Routing entry table is introduced to mlx5 TC. Every rx and tx VF tunnel rule is attached to a routing entry, which is shared for rules of same tunnel. On FIB event the work is scheduled to delete/recreate all rules of affected tunnel.
Note: only vxlan tunnel type is supported by this series.
=================
----------------------------------------------------------------
Mark Bloch (1):
net/mlx5: E-Switch, Refactor setting source port
Vlad Buslov (16):
net/mlx5e: E-Switch, Maintain vhca_id to vport_num mapping net/mlx5e: Always set attr mdev pointer
net/mlx5: E-Switch, Refactor rule offload forward action processing net/mlx5e: VF tunnel TX traffic offloading
net/mlx5e: Refactor tun routing helpers
net/mlx5: E-Switch, Indirect table infrastructure net/mlx5e: Remove redundant match on tunnel destination mac net/mlx5e: VF tunnel RX traffic offloading
net/mlx5e: Refactor reg_c1 usage
net/mlx5e: Match recirculated packet miss in slow table using reg_c1 net/mlx5e: Extract tc tunnel encap/decap code to dedicated file net/mlx5e: Create route entry infrastructure
net/mlx5e: Refactor neigh update infrastructure net/mlx5e: TC preparation refactoring for routing update event net/mlx5e: Rename some encap-specific API to generic names net/mlx5e: Handle FIB events to update tunnel endpoint device
drivers/net/ethernet/mellanox/mlx5/core/Makefile | 1 + .../mellanox/mlx5/core/diag/en_rep_tracepoint.h | 4 +- .../mellanox/mlx5/core/diag/en_tc_tracepoint.h | 4 +- .../net/ethernet/mellanox/mlx5/core/en/rep/neigh.c | 16 +- .../net/ethernet/mellanox/mlx5/core/en/rep/neigh.h | 3 +- .../net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 14 +- .../net/ethernet/mellanox/mlx5/core/en/rep/tc.h | 4 +- drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 3 +- drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h | 6 +- .../net/ethernet/mellanox/mlx5/core/en/tc_priv.h | 175 +++ .../net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 499 ++++-- .../net/ethernet/mellanox/mlx5/core/en/tc_tun.h | 13 + .../ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 1653 ++++++++++++++++++++ .../ethernet/mellanox/mlx5/core/en/tc_tun_encap.h | 38 + drivers/net/ethernet/mellanox/mlx5/core/en_rep.h | 10 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 1083 +++---------- drivers/net/ethernet/mellanox/mlx5/core/en_tc.h | 40 +- .../ethernet/mellanox/mlx5/core/esw/indir_table.c | 517 ++++++ .../ethernet/mellanox/mlx5/core/esw/indir_table.h | 76 + drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 20 + drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 16 + .../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 631 +++++++- include/linux/mlx5/eswitch.h | 29 + 23 files changed, 3798 insertions(+), 1057 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.h
PATCH 1/17 net/mlx5: E-Switch, Refactor setting source port
From: Mark Bloch <[email protected]>
Setting the source port requires only the E-Switch and vport number. Refactor the function to get those parameters instead of passing the full attribute.
--- .../mellanox/mlx5/core/eswitch_offloads.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +12 -7
@@ -257,7 +257,8 @@ mlx5_eswitch_set_rule_flow_source(struct mlx5_eswitch *esw,static void mlx5_eswitch_set_rule_source_port (struct mlx5_eswitch *esw,struct mlx5_flow_spec *spec, -struct mlx5_esw_flow_attr *attr) +struct mlx5_eswitch *src_esw, +u16 vport) {void *misc2;void *misc;
@@ -268,8 +269,8 @@ mlx5_eswitch_set_rule_source_port(struct mlx5_eswitch *esw,if (mlx5_eswitch_vport_match_metadata_enabled (esw)) { misc2 =MLX5_ADDR_OF (fte_match_param, spec->match_value, misc_parameters_2);MLX5_SET (fte_match_set_misc2, misc2, metadata_reg_c_0, -mlx5_eswitch_get_vport_metadata_for_match (attr->in_mdev->priv.eswitch, - attr->in_rep->vport)); +mlx5_eswitch_get_vport_metadata_for_match (src_esw, + vport)); misc2 =MLX5_ADDR_OF (fte_match_param, spec->match_criteria, misc_parameters_2); MLX5_SET(fte_match_set_misc2, misc2, metadata_reg_c_0,
@@ -278,12 +279,12 @@ mlx5_eswitch_set_rule_source_port(struct mlx5_eswitch *esw, spec->match_criteria_enable |=MLX5_MATCH_MISC_PARAMETERS_2 ; }else { misc =MLX5_ADDR_OF (fte_match_param, spec->match_value, misc_parameters); -MLX5_SET (fte_match_set_misc, misc, source_port, attr->in_rep->vport); +MLX5_SET (fte_match_set_misc, misc, source_port, vport);if (MLX5_CAP_ESW (esw->dev, merged_eswitch))MLX5_SET (fte_match_set_misc, misc, source_eswitch_owner_vhca_id, -MLX5_CAP_GEN (attr->in_mdev, vhca_id)); +MLX5_CAP_GEN (src_esw->dev, vhca_id)); misc =MLX5_ADDR_OF (fte_match_param, spec->match_criteria, misc_parameters);MLX5_SET_TO_ONES (fte_match_set_misc, misc, source_port);
@@ -407,7 +408,9 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, fdb = attr->ft;if (!(attr->flags &MLX5_ESW_ATTR_FLAG_NO_IN_PORT )) -mlx5_eswitch_set_rule_source_port (esw, spec, esw_attr); +mlx5_eswitch_set_rule_source_port (esw, spec, + esw_attr->in_mdev->priv.eswitch, + esw_attr->in_rep->vport); }if (IS_ERR (fdb)) { rule =ERR_CAST (fdb);
@@ -487,7 +490,9 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw, dest[i].ft = fwd_fdb; i++; -mlx5_eswitch_set_rule_source_port (esw, spec, esw_attr); +mlx5_eswitch_set_rule_source_port (esw, spec, + esw_attr->in_mdev->priv.eswitch, + esw_attr->in_rep->vport);if (attr->outer_match_level !=MLX5_MATCH_NONE ) spec->match_criteria_enable |=MLX5_MATCH_OUTER_HEADERS ;
Signature · 1 line
2.29.2
PATCH 2/17 net/mlx5e: E-Switch, Maintain vhca_id to vport_num mapping
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Following patches in the series need to be able to map VF netdev to vport. Since it is trivial to obtain vhca_id from netdev, maintain mapping from vhca_id to vport_num inside eswitch offloads using xarray. Provide function mlx5_eswitch_vhca_id_to_vport() to be used by TC code in following patches to obtain the mapping.
--- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 20 +++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 6 ++ .../mellanox/mlx5/core/eswitch_offloads.c | 79 +++++++++++++++++++ 3 files changed, 105 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +20 -0
@@ -1300,6 +1300,13 @@ int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, u16 vport_num, (!vport_num && mlx5_core_is_ecpf(esw->dev))) vport->info.trusted = true; +if (!mlx5_esw_is_manager_vport (esw, vport->vport) && +MLX5_CAP_GEN (esw->dev, vhca_resource_manager)) { + ret =mlx5_esw_vport_vhca_id_set (esw, vport_num); +if (ret) + goto err_vhca_mapping; + } +esw_vport_change_handle_locked (vport); esw->enabled_vports++;
@@ -1307,6 +1314,11 @@ int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, u16 vport_num, done:mutex_unlock (&esw->state_lock);return ret; + +err_vhca_mapping: +esw_vport_cleanup (esw, vport); +mutex_unlock (&esw->state_lock); +return ret; }void mlx5_esw_vport_disable (struct mlx5_eswitch *esw,u16 vport_num)
@@ -1325,6 +1337,11 @@ void mlx5_esw_vport_disable(struct mlx5_eswitch *esw, u16 vport_num)/* Disable events from this vport */ arm_vport_context_events_cmd (esw->dev, vport->vport,0 ); + +if (!mlx5_esw_is_manager_vport (esw, vport->vport) && +MLX5_CAP_GEN (esw->dev, vhca_resource_manager)) +mlx5_esw_vport_vhca_id_clear (esw, vport_num); +/* We don't assume VFs will cleanup after themselves. * Calling vport change handler while vport is disabled will cleanup * the vport resources.
@@ -1815,6 +1832,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)mlx5e_mod_hdr_tbl_init (&esw->offloads.mod_hdr);atomic64_set (&esw->offloads.num_flows,0 );ida_init (&esw->offloads.vport_metadata_ida); +xa_init_flags (&esw->offloads.vhca_map,XA_FLAGS_ALLOC );mutex_init (&esw->state_lock);mutex_init (&esw->mode_lock);
@@ -1854,6 +1872,8 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw)esw_offloads_cleanup_reps (esw);mutex_destroy (&esw->mode_lock);mutex_destroy (&esw->state_lock); +WARN_ON (!xa_empty (&esw->offloads.vhca_map)); +xa_destroy (&esw->offloads.vhca_map);ida_destroy (&esw->offloads.vport_metadata_ida);mlx5e_mod_hdr_tbl_destroy (&esw->offloads.mod_hdr);mutex_destroy (&esw->offloads.encap_tbl_lock);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +6 -0
@@ -36,6 +36,7 @@#include <linux/if_ether.h> #include <linux/if_link.h> #include <linux/atomic.h> +#include <linux/xarray.h> #include <net/devlink.h> #include <linux/mlx5/device.h> #include <linux/mlx5/eswitch.h>
@@ -212,6 +213,7 @@ struct mlx5_esw_offload {struct mod_hdr_tbl mod_hdr;DECLARE_HASHTABLE (termtbl_tbl,8 );struct mutex termtbl_mutex;/* protects termtbl hash */ +struct xarray vhca_map;const struct mlx5_eswitch_rep_ops *rep_ops[NUM_REP_TYPES ];u8 inline_mode;atomic64_t num_flows;
@@ -734,6 +736,10 @@ int mlx5_esw_offloads_sf_vport_enable(struct mlx5_eswitch *esw, struct devlink_p u16 vport_num, u32 sfnum);void mlx5_esw_offloads_sf_vport_disable (struct mlx5_eswitch *esw,u16 vport_num); +int mlx5_esw_vport_vhca_id_set (struct mlx5_eswitch *esw,u16 vport_num); +void mlx5_esw_vport_vhca_id_clear (struct mlx5_eswitch *esw,u16 vport_num); +int mlx5_eswitch_vhca_id_to_vport (struct mlx5_eswitch *esw,u16 vhca_id,u16 *vport_num); +/** * mlx5_esw_event_info - Indicates eswitch mode changed/changing. *
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +79 -0
82 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH 3/17 net/mlx5e: Always set attr mdev pointer
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Eswitch offloads extensions in following patches in the series require attr->esw_attr->in_mdev pointer to always be set. This is already the case for all code paths except mlx5_tc_ct_entry_add_rule() function. Fix the function to assign mdev pointer with priv->mdev value.
--- drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +2 -0
@@ -711,6 +711,8 @@ mlx5_tc_ct_entry_add_rule(struct mlx5_tc_ct_priv *ct_priv, attr->outer_match_level =MLX5_MATCH_L4 ; attr->counter = entry->counter->counter; attr->flags |=MLX5_ESW_ATTR_FLAG_NO_IN_PORT ; +if (ct_priv->ns_type ==MLX5_FLOW_NAMESPACE_FDB ) + attr->esw_attr->in_mdev = priv->mdev;mlx5_tc_ct_set_tuple_match (netdev_priv (ct_priv->netdev), spec, flow_rule);mlx5e_tc_match_to_reg_match (spec,ZONE_TO_REG , entry->tuple.zone,MLX5_CT_ZONE_MASK );
Signature · 1 line
2.29.2
PATCH 4/17 net/mlx5: E-Switch, Refactor rule offload forward action processing
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Following patches in the series extend forwarding functionality with VF tunnel TX and RX handling. Extract action forwarding processing code into dedicated functions to simplify further extensions:
- Handle every forwarding case with dedicated function instead of inline code.
- Extract forwarding dest dispatch conditional into helper function esw_setup_dests().
- Unify forwaring cleanup code in error path of mlx5_eswitch_add_offloaded_rule() and in rule deletion code of __mlx5_eswitch_del_rule() in new helper function esw_cleanup_dests() (dual to new esw_setup_dests() helper).
This patch does not change functionality.
--- .../mellanox/mlx5/core/eswitch_offloads.c | 189 ++++++++++++------ 1 file changed, 129 insertions(+), 60 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +129 -60
@@ -296,6 +296,124 @@ mlx5_eswitch_set_rule_source_port(struct mlx5_eswitch *esw, } } +static void +esw_setup_ft_dest (struct mlx5_flow_destination *dest, +struct mlx5_flow_act *flow_act, +struct mlx5_flow_attr *attr, +int i) +{ + flow_act->flags |=FLOW_ACT_IGNORE_FLOW_LEVEL ; + dest[i].type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; + dest[i].ft = attr->dest_ft; +} + +static void +esw_setup_slow_path_dest (struct mlx5_flow_destination *dest, +struct mlx5_flow_act *flow_act, +struct mlx5_fs_chains *chains, +int i) +{ + flow_act->flags |=FLOW_ACT_IGNORE_FLOW_LEVEL ; + dest[i].type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; + dest[i].ft =mlx5_chains_get_tc_end_ft (chains); +} + +static int +esw_setup_chain_dest (struct mlx5_flow_destination *dest, +struct mlx5_flow_act *flow_act, +struct mlx5_fs_chains *chains, +u32 chain,u32 prio,u32 level, +int i) +{ +struct mlx5_flow_table *ft; + + flow_act->flags |=FLOW_ACT_IGNORE_FLOW_LEVEL ; + ft =mlx5_chains_get_table (chains, chain, prio, level); +if (IS_ERR (ft)) +return PTR_ERR (ft); + + dest[i].type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; + dest[i].ft = ft; +return 0 ; +} + +static void +esw_cleanup_chain_dest (struct mlx5_fs_chains *chains,u32 chain,u32 prio,u32 level) +{ +mlx5_chains_put_table (chains, chain, prio, level); +} + +static void +esw_setup_vport_dest (struct mlx5_flow_destination *dest,struct mlx5_flow_act *flow_act, +struct mlx5_eswitch *esw,struct mlx5_esw_flow_attr *esw_attr, +int attr_idx,int dest_idx,bool pkt_reformat) +{ + dest[dest_idx].type =MLX5_FLOW_DESTINATION_TYPE_VPORT ; + dest[dest_idx].vport.num = esw_attr->dests[attr_idx].rep->vport; + dest[dest_idx].vport.vhca_id = +MLX5_CAP_GEN (esw_attr->dests[attr_idx].mdev, vhca_id); +if (MLX5_CAP_ESW (esw->dev, merged_eswitch)) + dest[dest_idx].vport.flags |=MLX5_FLOW_DEST_VPORT_VHCA_ID ; +if (esw_attr->dests[attr_idx].flags &MLX5_ESW_DEST_ENCAP ) { +if (pkt_reformat) { + flow_act->action |=MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT ; + flow_act->pkt_reformat = esw_attr->dests[attr_idx].pkt_reformat; + } + dest[dest_idx].vport.flags |=MLX5_FLOW_DEST_VPORT_REFORMAT_ID ; + dest[dest_idx].vport.pkt_reformat = esw_attr->dests[attr_idx].pkt_reformat; + } +} + +static int +esw_setup_vport_dests (struct mlx5_flow_destination *dest,struct mlx5_flow_act *flow_act, +struct mlx5_eswitch *esw,struct mlx5_esw_flow_attr *esw_attr, +int i) +{ +int j; + +for (j = esw_attr->split_count; j < esw_attr->out_count; j++, i++) +esw_setup_vport_dest (dest, flow_act, esw, esw_attr, j, i, true); +return i; +} + +static int +esw_setup_dests (struct mlx5_flow_destination *dest, +struct mlx5_flow_act *flow_act, +struct mlx5_eswitch *esw, +struct mlx5_flow_attr *attr, +int *i) +{ +struct mlx5_esw_flow_attr *esw_attr = attr->esw_attr; +struct mlx5_fs_chains *chains =esw_chains (esw); +int err =0 ; + +if (attr->dest_ft) { +esw_setup_ft_dest (dest, flow_act, attr, *i); + (*i)++; + }else if (attr->flags &MLX5_ESW_ATTR_FLAG_SLOW_PATH ) { +esw_setup_slow_path_dest (dest, flow_act, chains, *i); + (*i)++; + }else if (attr->dest_chain) { + err =esw_setup_chain_dest (dest, flow_act, chains, attr->dest_chain, +1 ,0 , *i); + (*i)++; + }else { + *i =esw_setup_vport_dests (dest, flow_act, esw, esw_attr, *i); + } + +return err; +} + +static void +esw_cleanup_dests (struct mlx5_eswitch *esw, +struct mlx5_flow_attr *attr) +{ +struct mlx5_fs_chains *chains =esw_chains (esw); + +if (!(attr->flags &MLX5_ESW_ATTR_FLAG_SLOW_PATH ) && attr->dest_chain) +esw_cleanup_chain_dest (chains, attr->dest_chain,1 ,0 ); +} +struct mlx5_flow_handle * mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, struct mlx5_flow_spec *spec,
@@ -309,7 +427,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr fwd_attr;struct mlx5_flow_handle *rule;struct mlx5_flow_table *fdb; -int j, i =0 ; +int i =0 ;if (esw->mode !=MLX5_ESWITCH_OFFLOADS )return ERR_PTR (-EOPNOTSUPP );
@@ -331,49 +449,12 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, }if (flow_act.action &MLX5_FLOW_CONTEXT_ACTION_FWD_DEST ) { -struct mlx5_flow_table *ft; - -if (attr->dest_ft) { - flow_act.flags |=FLOW_ACT_IGNORE_FLOW_LEVEL ; - dest[i].type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; - dest[i].ft = attr->dest_ft; - i++; - }else if (attr->flags &MLX5_ESW_ATTR_FLAG_SLOW_PATH ) { - flow_act.flags |=FLOW_ACT_IGNORE_FLOW_LEVEL ; - dest[i].type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; - dest[i].ft =mlx5_chains_get_tc_end_ft (chains); - i++; - }else if (attr->dest_chain) { - flow_act.flags |=FLOW_ACT_IGNORE_FLOW_LEVEL ; - ft =mlx5_chains_get_table (chains, attr->dest_chain, -1 ,0 ); -if (IS_ERR (ft)) { - rule =ERR_CAST (ft); - goto err_create_goto_table; - } - - dest[i].type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; - dest[i].ft = ft; - i++; - }else { -for (j = esw_attr->split_count; j < esw_attr->out_count; j++) { - dest[i].type =MLX5_FLOW_DESTINATION_TYPE_VPORT ; - dest[i].vport.num = esw_attr->dests[j].rep->vport; - dest[i].vport.vhca_id = -MLX5_CAP_GEN (esw_attr->dests[j].mdev, vhca_id); -if (MLX5_CAP_ESW (esw->dev, merged_eswitch)) - dest[i].vport.flags |= -MLX5_FLOW_DEST_VPORT_VHCA_ID ; -if (esw_attr->dests[j].flags &MLX5_ESW_DEST_ENCAP ) { - flow_act.action |=MLX5_FLOW_CONTEXT_ACTION_PACKET_REFORMAT ; - flow_act.pkt_reformat = - esw_attr->dests[j].pkt_reformat; - dest[i].vport.flags |=MLX5_FLOW_DEST_VPORT_REFORMAT_ID ; - dest[i].vport.pkt_reformat = - esw_attr->dests[j].pkt_reformat; - } - i++; - } +int err; + + err =esw_setup_dests (dest, &flow_act, esw, attr, &i); +if (err) { + rule =ERR_PTR (err); + goto err_create_goto_table; } }
@@ -437,8 +518,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,else if (attr->chain || attr->prio)mlx5_chains_put_table (chains, attr->chain, attr->prio,0 ); err_esw_get: -if (!(attr->flags &MLX5_ESW_ATTR_FLAG_SLOW_PATH ) && attr->dest_chain) -mlx5_chains_put_table (chains, attr->dest_chain,1 ,0 ); +esw_cleanup_dests (esw, attr); err_create_goto_table:return rule; }
@@ -474,18 +554,8 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw, } flow_act.action =MLX5_FLOW_CONTEXT_ACTION_FWD_DEST ; -for (i =0 ; i < esw_attr->split_count; i++) { - dest[i].type =MLX5_FLOW_DESTINATION_TYPE_VPORT ; - dest[i].vport.num = esw_attr->dests[i].rep->vport; - dest[i].vport.vhca_id = -MLX5_CAP_GEN (esw_attr->dests[i].mdev, vhca_id); -if (MLX5_CAP_ESW (esw->dev, merged_eswitch)) - dest[i].vport.flags |=MLX5_FLOW_DEST_VPORT_VHCA_ID ; -if (esw_attr->dests[i].flags &MLX5_ESW_DEST_ENCAP ) { - dest[i].vport.flags |=MLX5_FLOW_DEST_VPORT_REFORMAT_ID ; - dest[i].vport.pkt_reformat = esw_attr->dests[i].pkt_reformat; - } - } +for (i =0 ; i < esw_attr->split_count; i++) +esw_setup_vport_dest (dest, &flow_act, esw, esw_attr, i, i, false); dest[i].type =MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ; dest[i].ft = fwd_fdb; i++;
@@ -552,8 +622,7 @@ __mlx5_eswitch_del_rule(struct mlx5_eswitch *esw,esw_vport_tbl_put (esw, &fwd_attr); else if (attr->chain || attr->prio) mlx5_chains_put_table(chains, attr->chain, attr->prio, 0); -if (attr->dest_chain) -mlx5_chains_put_table (chains, attr->dest_chain,1 ,0 ); +esw_cleanup_dests (esw ,attr ); } }
Signature · 1 line
2.29.2
PATCH 5/17 net/mlx5e: VF tunnel TX traffic offloading
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
When tunnel endpoint is on VF, driver still assumes that endpoint is on uplink and incorrectly configures encap rule offload according to that assumption. As a result, traffic is sent directly to the uplink and rules installed on representor of tunnel endpoint VF are ignored.
Implement following changes to allow offloading tx traffic with tunnel endpoint on VF:
- For tunneling flows perform route lookup on route and out devices pair. If out device is uplink and route device is VF of same physical port, then modify packet reg_c_0 metadata register (source port) with the value of VF vport. Use eswitch vhca_id->vport mapping introduced in one of previous patches in the series to obtain vport from route netdevice.
- Recirculate encapsulated packets to VF vport in order to apply any flow rules installed on VF representor that match on encapsulated traffic.
Only enable support for this functionality when all following conditions are true:
- Hardware advertises capability to preserve reg_c_0 value on packet recirculation.
- Vport metadata matching is enabled.
- Termination tables are to be used by the flow.
Example TC rules for VF tunnel traffic:
1. Rule that redirects packets from UL to VF rep that has the tunnel endpoint IP address:
$ tc -s filter show dev enp8s0f0 ingress
filter protocol ip pref 4 flower chain 0
filter protocol ip pref 4 flower chain 0 handle 0x1
dst_mac 16:c9:a0:2d:69:2c
src_mac 0c:42:a1:58:ab:e4
eth_type ipv4
ip_flags nofrag
in_hw in_hw_count 1
action order 1: mirred (Egress Redirect to device enp8s0f0_0) stolen
index 3 ref 1 bind 1 installed 377 sec used 0 sec
Action statistics:
Sent 114096 bytes 952 pkt (dropped 0, overlimits 0 requeues 0)
Sent software 0 bytes 0 pkt
Sent hardware 114096 bytes 952 pkt
backlog 0b 0p requeues 0
cookie 878fa48d8c423fc08c3b6ca599b50a97
no_percpu
used_hw_stats delayed2. Rule that decapsulates the tunneled flow and redirects to destination VF representor:
$ tc -s filter show dev vxlan_sys_4789 ingress
filter protocol ip pref 4 flower chain 0
filter protocol ip pref 4 flower chain 0 handle 0x1
dst_mac ca:2e:a7:3f:f5:0f
src_mac 0a:40:bd:30:89:99
eth_type ipv4
enc_dst_ip 7.7.7.5
enc_src_ip 7.7.7.1
enc_key_id 98
enc_dst_port 4789
enc_tos 0
ip_flags nofrag
in_hw in_hw_count 1
action order 1: tunnel_key unset pipe
index 2 ref 1 bind 1 installed 434 sec used 434 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
used_hw_stats delayed action order 2: mirred (Egress Redirect to device enp8s0f0_1) stolen index 4 ref 1 bind 1 installed 434 sec used 0 sec
Action statistics:
Sent 129936 bytes 1082 pkt (dropped 0, overlimits 0 requeues 0) Sent software 0 bytes 0 pkt
Sent hardware 129936 bytes 1082 pkt
backlog 0b 0p requeues 0
cookie ac17cf398c4c69e4a5b2f7aabd1b88ff
no_percpu
used_hw_stats delayed
--- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 87 +++++++++++++ .../net/ethernet/mellanox/mlx5/core/en_tc.h | 1 + .../net/ethernet/mellanox/mlx5/core/eswitch.h | 2 + .../mellanox/mlx5/core/eswitch_offloads.c | 120 ++++++++++++++++-- include/linux/mlx5/eswitch.h | 2 + 5 files changed, 201 insertions(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +87 -0
@@ -165,6 +165,11 @@ struct mlx5e_tc_attr_to_reg_mapping mlx5e_tc_attr_to_reg_mappings[] = { .moffset = 0, .mlen = 2, }, + [VPORT_TO_REG] = { + .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_0, + .moffset = 2, + .mlen = 2, + }, [TUNNEL_TO_REG] = { .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_1, .moffset = 1,
@@ -1315,6 +1320,44 @@ static void remove_unready_flow(struct mlx5e_tc_flow *flow)mutex_unlock (&uplink_priv->unready_flows_lock); } +static bool same_hw_devs (struct mlx5e_priv *priv,struct mlx5e_priv *peer_priv); + +static bool mlx5e_tc_is_vf_tunnel (struct net_device *out_dev,struct net_device *route_dev) +{ +struct mlx5_core_dev *out_mdev, *route_mdev; +struct mlx5e_priv *out_priv, *route_priv; + + out_priv =netdev_priv (out_dev); + out_mdev = out_priv->mdev; + route_priv =netdev_priv (route_dev); + route_mdev = route_priv->mdev; + +if (out_mdev->coredev_type !=MLX5_COREDEV_PF || + route_mdev->coredev_type !=MLX5_COREDEV_VF ) +return false; + +return same_hw_devs (out_priv, route_priv); +} + +static int mlx5e_tc_query_route_vport (struct net_device *out_dev,struct net_device *route_dev, +u16 *vport) +{ +struct mlx5e_priv *out_priv, *route_priv; +struct mlx5_core_dev *route_mdev; +struct mlx5_eswitch *esw; +u16 vhca_id; +int err; + + out_priv =netdev_priv (out_dev); + esw = out_priv->mdev->priv.eswitch; + route_priv =netdev_priv (route_dev); + route_mdev = route_priv->mdev; + + vhca_id =MLX5_CAP_GEN (route_mdev, vhca_id); + err =mlx5_eswitch_vhca_id_to_vport (esw, vhca_id, vport); +return err; +} + static int mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv, struct mlx5e_tc_flow *flow,
@@ -3700,6 +3743,45 @@ static bool is_duplicated_encap_entry(struct mlx5e_priv *priv,return false; } +static int mlx5e_set_vf_tunnel (struct mlx5_eswitch *esw, +struct mlx5_flow_attr *attr, +struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, +struct net_device *out_dev, +int route_dev_ifindex, +int out_index) +{ +struct mlx5_esw_flow_attr *esw_attr = attr->esw_attr; +struct net_device *route_dev; +u16 vport_num; +int err =0 ; +u32 data; + + route_dev =dev_get_by_index (dev_net (out_dev), route_dev_ifindex); + +if (!route_dev || route_dev->netdev_ops != &mlx5e_netdev_ops || + !mlx5e_tc_is_vf_tunnel (out_dev, route_dev)) + goto out; + + err =mlx5e_tc_query_route_vport (out_dev, route_dev, &vport_num); +if (err) + goto out; + + attr->dest_chain =0 ; + attr->action |=MLX5_FLOW_CONTEXT_ACTION_MOD_HDR ; + esw_attr->dests[out_index].flags |=MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE ; + data =mlx5_eswitch_get_vport_metadata_for_set (esw_attr->in_mdev->priv.eswitch, + vport_num); + err =mlx5e_tc_match_to_reg_set (esw->dev, mod_hdr_acts, +MLX5_FLOW_NAMESPACE_FDB ,VPORT_TO_REG , data); +if (err) + goto out; + +out: +if (route_dev) +dev_put (route_dev); +return err; +} + static int mlx5e_attach_encap(struct mlx5e_priv *priv, struct mlx5e_tc_flow *flow, struct net_device *mirred_dev,
@@ -3791,6 +3873,11 @@ static int mlx5e_attach_encap(struct mlx5e_priv *priv, e->compl_result =1 ; attach_flow: + err =mlx5e_set_vf_tunnel (esw, attr, &parse_attr->mod_hdr_acts, e->out_dev, + e->route_dev_ifindex, out_index); +if (err) + goto out_err; + flow->encaps[out_index].e = e;list_add (&flow->encaps[out_index].list, &e->flows); flow->encaps[out_index].index = out_index;
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +1 -0
@@ -167,6 +167,7 @@ void mlx5e_tc_reoffload_flows_work(struct work_struct *work);enum mlx5e_tc_attr_to_reg {CHAIN_TO_REG , +VPORT_TO_REG ,TUNNEL_TO_REG ,CTSTATE_TO_REG ,ZONE_TO_REG ,
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +2 -0
@@ -389,12 +389,14 @@ enum mlx5_flow_match_level {enum {MLX5_ESW_DEST_ENCAP =BIT (0 ),MLX5_ESW_DEST_ENCAP_VALID =BIT (1 ), +MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE =BIT (2 ), };enum {MLX5_ESW_ATTR_FLAG_VLAN_HANDLED =BIT (0 ),MLX5_ESW_ATTR_FLAG_SLOW_PATH =BIT (1 ),MLX5_ESW_ATTR_FLAG_NO_IN_PORT =BIT (2 ), +MLX5_ESW_ATTR_FLAG_SRC_REWRITE =BIT (3 ), };struct mlx5_esw_flow_attr {
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +109 -11
198 lines not on this page · raw message
include/linux/mlx5/eswitch.h +2 -0
@@ -96,6 +96,8 @@ static inline u32 mlx5_eswitch_get_vport_metadata_mask(void)u32 mlx5_eswitch_get_vport_metadata_for_match (struct mlx5_eswitch *esw,u16 vport_num); +u32 mlx5_eswitch_get_vport_metadata_for_set (struct mlx5_eswitch *esw, +u16 vport_num);u8 mlx5_eswitch_mode (struct mlx5_core_dev *dev);#else /* CONFIG_MLX5_ESWITCH */
Signature · 1 line
2.29.2
PATCH 6/17 net/mlx5e: Refactor tun routing helpers
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Refactor tun routing helpers to use dedicated struct mlx5e_tc_tun_route_attr instead of multiple output arguments. This simplifies the callers (no need to keep track of bunch of output param pointers) and allows to unify struct release code in new mlx5e_tc_tun_route_attr_cleanup() helper instead of requiring callers to manually release some of the output parameters that require it.
Simplify code by unifying error handling at the end of the function and rearranging code. Remove redundant empty line.
--- .../ethernet/mellanox/mlx5/core/en/tc_tun.c | 235 ++++++++++-------- 1 file changed, 126 insertions(+), 109 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +126 -109
@@ -10,6 +10,27 @@#include "rep/tc.h" #include "rep/neigh.h" +struct mlx5e_tc_tun_route_attr { +struct net_device *out_dev; +struct net_device *route_dev; +union { +struct flowi4 fl4; +struct flowi6 fl6; + } fl; +struct neighbour *n; +u8 ttl; +}; + +#define TC_TUN_ROUTE_ATTR_INIT (name) struct mlx5e_tc_tun_route_attr name = {} + +static void mlx5e_tc_tun_route_attr_cleanup (struct mlx5e_tc_tun_route_attr *attr) +{ +if (attr->n) +neigh_release (attr->n); +if (attr->route_dev) +dev_put (attr->route_dev); +} +struct mlx5e_tc_tunnel *mlx5e_get_tc_tun (struct net_device *tunnel_dev) {if (netif_is_vxlan (tunnel_dev))
@@ -79,12 +100,10 @@ static int get_route_and_out_devs(struct mlx5e_priv *priv,static int mlx5e_route_lookup_ipv4_get (struct mlx5e_priv *priv,struct net_device *mirred_dev, -struct net_device **out_dev, -struct net_device **route_dev, -struct flowi4 *fl4, -struct neighbour **out_n, -u8 *out_ttl) +struct mlx5e_tc_tun_route_attr *attr) { +struct net_device *route_dev; +struct net_device *out_dev;struct neighbour *n;struct rtable *rt;
@@ -97,46 +116,50 @@ static int mlx5e_route_lookup_ipv4_get(struct mlx5e_priv *priv,struct mlx5_eswitch *esw = mdev->priv.eswitch; uplink_dev =mlx5_eswitch_uplink_get_proto_dev (esw,REP_ETH ); - fl4->flowi4_oif = uplink_dev->ifindex; + attr->fl.fl4.flowi4_oif = uplink_dev->ifindex; } - rt =ip_route_output_key (dev_net (mirred_dev), fl4); + rt =ip_route_output_key (dev_net (mirred_dev), &attr->fl.fl4);if (IS_ERR (rt))return PTR_ERR (rt);if (mlx5_lag_is_multipath (mdev) && rt->rt_gw_family !=AF_INET ) { -ip_rt_put (rt); -return -ENETUNREACH ; + ret = -ENETUNREACH ; + goto err_rt_release; }#else return -EOPNOTSUPP ;#endif - ret =get_route_and_out_devs (priv, rt->dst.dev, route_dev, out_dev); -if (ret <0 ) { -ip_rt_put (rt); -return ret; - } -dev_hold (*route_dev); + ret =get_route_and_out_devs (priv, rt->dst.dev, &route_dev, &out_dev); +if (ret <0 ) + goto err_rt_release; +dev_hold (route_dev); -if (!(*out_ttl)) - *out_ttl =ip4_dst_hoplimit (&rt->dst); - n =dst_neigh_lookup (&rt->dst, &fl4->daddr); -ip_rt_put (rt); +if (!attr->ttl) + attr->ttl =ip4_dst_hoplimit (&rt->dst); + n =dst_neigh_lookup (&rt->dst, &attr->fl.fl4.daddr);if (!n) { -dev_put (*route_dev); -return -ENOMEM ; + ret = -ENOMEM ; + goto err_dev_release; } - *out_n = n; +ip_rt_put (rt); + attr->route_dev = route_dev; + attr->out_dev = out_dev; + attr->n = n;return 0 ; + +err_dev_release: +dev_put (route_dev); +err_rt_release: +ip_rt_put (rt); +return ret; } -static void mlx5e_route_lookup_ipv4_put (struct net_device *route_dev, -struct neighbour *n) +static void mlx5e_route_lookup_ipv4_put (struct mlx5e_tc_tun_route_attr *attr) { -neigh_release (n); -dev_put (route_dev); +mlx5e_tc_tun_route_attr_cleanup (attr); }static const char *mlx5e_netdev_kind (struct net_device *dev)
@@ -188,28 +211,25 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, {int max_encap_size =MLX5_CAP_ESW (priv->mdev, max_encap_header_size);const struct ip_tunnel_key *tun_key = &e->tun_info->key; -struct net_device *out_dev, *route_dev; -struct flowi4 fl4 = {}; -struct neighbour *n; +TC_TUN_ROUTE_ATTR_INIT (attr);int ipv4_encap_size;char *encap_header; -u8 nud_state, ttl;struct iphdr *ip; +u8 nud_state;int err;/* add the IP fields */ - fl4.flowi4_tos = tun_key->tos; - fl4.daddr = tun_key->u.ipv4.dst; - fl4.saddr = tun_key->u.ipv4.src; - ttl = tun_key->ttl; + attr.fl.fl4.flowi4_tos = tun_key->tos; + attr.fl.fl4.daddr = tun_key->u.ipv4.dst; + attr.fl.fl4.saddr = tun_key->u.ipv4.src; + attr.ttl = tun_key->ttl; - err =mlx5e_route_lookup_ipv4_get (priv, mirred_dev, &out_dev, &route_dev, - &fl4, &n, &ttl); + err =mlx5e_route_lookup_ipv4_get (priv, mirred_dev, &attr);if (err)return err; ipv4_encap_size = - (is_vlan_dev (route_dev) ?VLAN_ETH_HLEN :ETH_HLEN ) + + (is_vlan_dev (attr.route_dev) ?VLAN_ETH_HLEN :ETH_HLEN ) +sizeof (struct iphdr ) + e->tunnel->calc_hlen (e);
@@ -229,37 +249,37 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,/* used by mlx5e_detach_encap to lookup a neigh hash table * entry in the neigh hash table when a user deletes a rule */ - e->m_neigh.dev = n->dev; - e->m_neigh.family = n->ops->family; -memcpy (&e->m_neigh.dst_ip, n->primary_key, n->tbl->key_len); - e->out_dev = out_dev; - e->route_dev_ifindex = route_dev->ifindex; + e->m_neigh.dev = attr.n->dev; + e->m_neigh.family = attr.n->ops->family; +memcpy (&e->m_neigh.dst_ip, attr.n->primary_key, attr.n->tbl->key_len); + e->out_dev = attr.out_dev; + e->route_dev_ifindex = attr.route_dev->ifindex;/* It's important to add the neigh to the hash table before checking * the neigh validity state. So if we'll get a notification, in case the * neigh changes it's validity state, we would find the relevant neigh * in the hash. */ - err =mlx5e_rep_encap_entry_attach (netdev_priv (out_dev), e); + err =mlx5e_rep_encap_entry_attach (netdev_priv (attr.out_dev), e);if (err) goto free_encap; -read_lock_bh (&n->lock); - nud_state = n->nud_state; -ether_addr_copy (e->h_dest, n->ha); -read_unlock_bh (&n->lock); +read_lock_bh (&attr.n->lock); + nud_state = attr.n->nud_state; +ether_addr_copy (e->h_dest, attr.n->ha); +read_unlock_bh (&attr.n->lock);/* add ethernet header */ - ip = (struct iphdr *)gen_eth_tnl_hdr (encap_header, route_dev, e, + ip = (struct iphdr *)gen_eth_tnl_hdr (encap_header, attr.route_dev, e,ETH_P_IP );/* add ip header */ ip->tos = tun_key->tos; ip->version =0x4 ; ip->ihl =0x5 ; - ip->ttl = ttl; - ip->daddr = fl4.daddr; - ip->saddr = fl4.saddr; + ip->ttl = attr.ttl; + ip->daddr = attr.fl.fl4.daddr; + ip->saddr = attr.fl.fl4.saddr;/* add tunneling protocol header */ err = mlx5e_gen_ip_tunnel_header((char *)ip + sizeof(struct iphdr),
@@ -271,7 +291,7 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, e->encap_header = encap_header;if (!(nud_state &NUD_VALID )) { -neigh_event_send (n,NULL ); +neigh_event_send (attr.n,NULL );/* the encap entry will be made valid on neigh update event * and not used before that. */
@@ -287,8 +307,8 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, } e->flags |=MLX5_ENCAP_ENTRY_VALID ; -mlx5e_rep_queue_neigh_stats_work (netdev_priv (out_dev)); -mlx5e_route_lookup_ipv4_put (route_dev, n); +mlx5e_rep_queue_neigh_stats_work (netdev_priv (attr.out_dev)); +mlx5e_route_lookup_ipv4_put (&attr);return err; destroy_neigh_entry:
@@ -296,55 +316,56 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, free_encap:kfree (encap_header); release_neigh: -mlx5e_route_lookup_ipv4_put (route_dev, n); +mlx5e_route_lookup_ipv4_put (&attr);return err; }#if IS_ENABLED (CONFIG_INET ) &&IS_ENABLED (CONFIG_IPV6 )static int mlx5e_route_lookup_ipv6_get (struct mlx5e_priv *priv,struct net_device *mirred_dev, -struct net_device **out_dev, -struct net_device **route_dev, -struct flowi6 *fl6, -struct neighbour **out_n, -u8 *out_ttl) +struct mlx5e_tc_tun_route_attr *attr) { +struct net_device *route_dev; +struct net_device *out_dev;struct dst_entry *dst;struct neighbour *n; -int ret; - dst = ipv6_stub->ipv6_dst_lookup_flow (dev_net (mirred_dev),NULL , fl6, + dst = ipv6_stub->ipv6_dst_lookup_flow (dev_net (mirred_dev),NULL , &attr->fl.fl6,NULL );if (IS_ERR (dst))return PTR_ERR (dst); -if (!(*out_ttl)) - *out_ttl =ip6_dst_hoplimit (dst); +if (!attr->ttl) + attr->ttl =ip6_dst_hoplimit (dst); - ret =get_route_and_out_devs (priv, dst->dev, route_dev, out_dev); -if (ret <0 ) { -dst_release (dst); -return ret; - } + ret =get_route_and_out_devs (priv, dst->dev, &route_dev, &out_dev); +if (ret <0 ) + goto err_dst_release; -dev_hold (*route_dev); - n =dst_neigh_lookup (dst, &fl6->daddr); -dst_release (dst); +dev_hold (route_dev); + n =dst_neigh_lookup (dst, &attr->fl.fl6.daddr);if (!n) { -dev_put (*route_dev); -return -ENOMEM ; + ret = -ENOMEM ; + goto err_dev_release; } - *out_n = n; +dst_release (dst); + attr->out_dev = out_dev; + attr->route_dev = route_dev; + attr->n = n;return 0 ; + +err_dev_release: +dev_put (route_dev); +err_dst_release: +dst_release (dst); +return ret; } -static void mlx5e_route_lookup_ipv6_put (struct net_device *route_dev, -struct neighbour *n) +static void mlx5e_route_lookup_ipv6_put (struct mlx5e_tc_tun_route_attr *attr) { -neigh_release (n); -dev_put (route_dev); +mlx5e_tc_tun_route_attr_cleanup (attr); } int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,
@@ -353,28 +374,24 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, {int max_encap_size =MLX5_CAP_ESW (priv->mdev, max_encap_header_size);const struct ip_tunnel_key *tun_key = &e->tun_info->key; -struct net_device *out_dev, *route_dev; -struct flowi6 fl6 = {}; +TC_TUN_ROUTE_ATTR_INIT (attr);struct ipv6hdr *ip6h; -struct neighbour *n =NULL ;int ipv6_encap_size;char *encap_header; -u8 nud_state, ttl; +u8 nud_state;int err; - ttl = tun_key->ttl; - - fl6.flowlabel =ip6_make_flowinfo (RT_TOS (tun_key->tos), tun_key->label); - fl6.daddr = tun_key->u.ipv6.dst; - fl6.saddr = tun_key->u.ipv6.src; + attr.ttl = tun_key->ttl; + attr.fl.fl6.flowlabel =ip6_make_flowinfo (RT_TOS (tun_key->tos), tun_key->label); + attr.fl.fl6.daddr = tun_key->u.ipv6.dst; + attr.fl.fl6.saddr = tun_key->u.ipv6.src; - err =mlx5e_route_lookup_ipv6_get (priv, mirred_dev, &out_dev, &route_dev, - &fl6, &n, &ttl); + err =mlx5e_route_lookup_ipv6_get (priv, mirred_dev, &attr);if (err)return err; ipv6_encap_size = - (is_vlan_dev (route_dev) ?VLAN_ETH_HLEN :ETH_HLEN ) + + (is_vlan_dev (attr.route_dev) ?VLAN_ETH_HLEN :ETH_HLEN ) +sizeof (struct ipv6hdr ) + e->tunnel->calc_hlen (e);
@@ -394,36 +411,36 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,/* used by mlx5e_detach_encap to lookup a neigh hash table * entry in the neigh hash table when a user deletes a rule */ - e->m_neigh.dev = n->dev; - e->m_neigh.family = n->ops->family; -memcpy (&e->m_neigh.dst_ip, n->primary_key, n->tbl->key_len); - e->out_dev = out_dev; - e->route_dev_ifindex = route_dev->ifindex; + e->m_neigh.dev = attr.n->dev; + e->m_neigh.family = attr.n->ops->family; +memcpy (&e->m_neigh.dst_ip, attr.n->primary_key, attr.n->tbl->key_len); + e->out_dev = attr.out_dev; + e->route_dev_ifindex = attr.route_dev->ifindex;/* It's importent to add the neigh to the hash table before checking * the neigh validity state. So if we'll get a notification, in case the * neigh changes it's validity state, we would find the relevant neigh * in the hash. */ - err =mlx5e_rep_encap_entry_attach (netdev_priv (out_dev), e); + err =mlx5e_rep_encap_entry_attach (netdev_priv (attr.out_dev), e);if (err) goto free_encap; -read_lock_bh (&n->lock); - nud_state = n->nud_state; -ether_addr_copy (e->h_dest, n->ha); -read_unlock_bh (&n->lock); +read_lock_bh (&attr.n->lock); + nud_state = attr.n->nud_state; +ether_addr_copy (e->h_dest, attr.n->ha); +read_unlock_bh (&attr.n->lock);/* add ethernet header */ - ip6h = (struct ipv6hdr *)gen_eth_tnl_hdr (encap_header, route_dev, e, + ip6h = (struct ipv6hdr *)gen_eth_tnl_hdr (encap_header, attr.route_dev, e,ETH_P_IPV6 );/* add ip header */ ip6_flow_hdr (ip6h, tun_key->tos,0 );/* the HW fills up ipv6 payload len */ - ip6h->hop_limit = ttl; - ip6h->daddr = fl6.daddr; - ip6h->saddr = fl6.saddr; + ip6h->hop_limit = attr.ttl; + ip6h->daddr = attr.fl.fl6.daddr; + ip6h->saddr = attr.fl.fl6.saddr;/* add tunneling protocol header */ err = mlx5e_gen_ip_tunnel_header((char *)ip6h + sizeof(struct ipv6hdr),
@@ -435,7 +452,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, e->encap_header = encap_header;if (!(nud_state &NUD_VALID )) { -neigh_event_send (n,NULL ); +neigh_event_send (attr.n,NULL );/* the encap entry will be made valid on neigh update event * and not used before that. */
@@ -452,8 +469,8 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, } e->flags |=MLX5_ENCAP_ENTRY_VALID ; -mlx5e_rep_queue_neigh_stats_work (netdev_priv (out_dev)); -mlx5e_route_lookup_ipv6_put (route_dev, n); +mlx5e_rep_queue_neigh_stats_work (netdev_priv (attr.out_dev)); +mlx5e_route_lookup_ipv6_put (&attr);return err; destroy_neigh_entry:
@@ -461,7 +478,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, free_encap:kfree (encap_header); release_neigh: -mlx5e_route_lookup_ipv6_put (route_dev, n); +mlx5e_route_lookup_ipv6_put (&attr); return err; }#endif
Signature · 1 line
2.29.2
PATCH 7/17 net/mlx5: E-Switch, Indirect table infrastructure
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Indirect table infrastructure is used to allow fully processing VF tunnel traffic in hardware. Kernel software model uses two TC rules for such
traffic: UL rep to tunnel device, then tunnel VF rep to destination VF rep. To implement such pipeline driver needs to program the hardware after matching on UL rule to overwrite source vport from UL to tunnel VF and recirculate the packet to the root table to allow matching on the rule installed on tunnel VF. For this indirect table matches all encapsulated traffic by tunnel parameters and all other IP traffic is sent to tunnel VF by the miss rule.
Indirect table API overview:
- mlx5_esw_indir_table_{init|destroy}() - init and destroy opaque indirect table object.
- mlx5_esw_indir_table_get() - get or create new table according to vport id and IP version. Table has following pre-created groups: recirculation group with match on ethertype and VNI (rules that match encapsulated packets are installed to this group) and forward group with default/miss rule that forwards to vport of tunnel endpoint VF (rule for regular non-encapsulated packets).
- mlx5_esw_indir_table_put() - decrease reference to the indirect table and matching rule (for encapsulated traffic).
- mlx5_esw_indir_table_needed() - check that in_port is an uplink port and out_port is VF on the same eswitch, verify that the rule is for IP traffic and source port rewrite functionality can be used.
- mlx5_esw_indir_table_decap_vport() - function returns decap vport of flow attribute.
--- .../net/ethernet/mellanox/mlx5/core/Makefile | 1 + .../net/ethernet/mellanox/mlx5/core/en_tc.h | 14 + .../mellanox/mlx5/core/esw/indir_table.c | 508 ++++++++++++++++++ .../mellanox/mlx5/core/esw/indir_table.h | 76 +++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 5 + .../mellanox/mlx5/core/eswitch_offloads.c | 12 + 6 files changed, 616 insertions(+) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.h
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -0
@@ -40,6 +40,7 @@ mlx5_core-$(CONFIG_MLX5_ESWITCH) += lag_mp.o lib/geneve.o lib/port_tun.o \ en_rep.o en/rep/bond.o en/mod_hdr.o mlx5_core-$(CONFIG_MLX5_CLS_ACT) += en_tc.o en/rep/tc.o en/rep/neigh.o \ en/mapping.o lib/fs_chains.o en/tc_tun.o \ + esw/indir_table.o \ en/tc_tun_vxlan.o en/tc_tun_gre.o en/tc_tun_geneve.o \ en/tc_tun_mplsoudp.o diag/en_tc_tracepoint.o mlx5_core-$(CONFIG_MLX5_TC_CT) += en/tc_ct.o
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +14 -0
@@ -76,6 +76,7 @@ struct mlx5_flow_attr {struct mlx5_flow_table *dest_ft;u8 inner_match_level;u8 outer_match_level; +u8 ip_version;u32 flags;union {struct mlx5_esw_flow_attr esw_attr[0 ];
@@ -83,6 +84,19 @@ struct mlx5_flow_attr { }; }; +struct mlx5_rx_tun_attr { +u16 decap_vport; +union { +__be32 v4; +struct in6_addr v6; + } src_ip;/* Valid if decap_vport is not zero */ +union { +__be32 v4; +struct in6_addr v6; + } dst_ip;/* Valid if decap_vport is not zero */ +u32 vni; +}; +#define MLX5E_TC_TABLE_CHAIN_TAG_BITS 16#define MLX5E_TC_TABLE_CHAIN_TAG_MASK GENMASK(MLX5E_TC_TABLE_CHAIN_TAG_BITS - 1, 0)
drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.c new file +508 -0
508 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.h new file +76 -0
76 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +5 -0
@@ -161,6 +161,8 @@ struct mlx5_vport {struct devlink_port *dl_port; }; +struct mlx5_esw_indir_table ; + struct mlx5_eswitch_fdb { union { struct legacy_fdb {
@@ -191,6 +193,8 @@ struct mlx5_eswitch_fdb {struct mutex lock; } vports; +struct mlx5_esw_indir_table *indir; + } offloads; };u32 flags;
@@ -418,6 +422,7 @@ struct mlx5_esw_flow_attr {struct mlx5_core_dev *mdev;struct mlx5_termtbl_handle *termtbl; } dests[MLX5_MAX_FLOW_FWD_VPORTS ]; +struct mlx5_rx_tun_attr *rx_tun_attr;struct mlx5_pkt_reformat *decap_pkt_reformat; };
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +12 -0
@@ -38,6 +38,7 @@#include <linux/mlx5/fs.h> #include "mlx5_core.h" #include "eswitch.h" +#include "esw/indir_table.h" #include "esw/acl/ofld.h" #include "rdma.h" #include "en.h"
@@ -2342,12 +2343,20 @@ static void esw_destroy_uplink_offloads_acl_tables(struct mlx5_eswitch *esw)static int esw_offloads_steering_init (struct mlx5_eswitch *esw) { +struct mlx5_esw_indir_table *indir;int err;memset (&esw->fdb_table.offloads,0 ,sizeof (struct offloads_fdb ));mutex_init (&esw->fdb_table.offloads.vports.lock);hash_init (esw->fdb_table.offloads.vports.table); + indir =mlx5_esw_indir_table_init (); +if (IS_ERR (indir)) { + err =PTR_ERR (indir); + goto create_indir_err; + } + esw->fdb_table.offloads.indir = indir; + err =esw_create_uplink_offloads_acl_tables (esw);if (err) goto create_acl_err;
@@ -2379,6 +2388,8 @@ static int esw_offloads_steering_init(struct mlx5_eswitch *esw) create_offloads_err:esw_destroy_uplink_offloads_acl_tables (esw); create_acl_err: +mlx5_esw_indir_table_destroy (esw->fdb_table.offloads.indir); +create_indir_err:mutex_destroy (&esw->fdb_table.offloads.vports.lock);return err; }
@@ -2390,6 +2401,7 @@ static void esw_offloads_steering_cleanup(struct mlx5_eswitch *esw)esw_destroy_restore_table (esw);esw_destroy_offloads_table (esw);esw_destroy_uplink_offloads_acl_tables (esw); +mlx5_esw_indir_table_destroy (esw->fdb_table.offloads.indir);mutex_destroy (&esw->fdb_table.offloads.vports.lock); }
Signature · 1 line
2.29.2
PATCH 8/17 net/mlx5e: Remove redundant match on tunnel destination mac
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Remove hardcoded match on tunnel destination MAC address. Such match is no longer required and would be wrong for stacked devices topology where encapsulation destination MAC address will be the address of tunnel VF that can change dynamically on route change (implemented in following patches in the series).
--- drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +0 -8
@@ -642,14 +642,6 @@ int mlx5e_tc_tun_parse(struct net_device *filter_dev, } } -/* Enforce DMAC when offloading incoming tunneled flows. -* Flow counters require a match on the DMAC. -*/ -MLX5_SET_TO_ONES (fte_match_set_lyr_2_4, headers_c, dmac_47_16); -MLX5_SET_TO_ONES (fte_match_set_lyr_2_4, headers_c, dmac_15_0); -ether_addr_copy (MLX5_ADDR_OF (fte_match_set_lyr_2_4, headers_v, - dmac_47_16), priv->netdev->dev_addr); -/* let software handle IP fragments */ MLX5_SET (fte_match_set_lyr_2_4, headers_c, frag,1 );MLX5_SET (fte_match_set_lyr_2_4, headers_v, frag,0 );
Signature · 1 line
2.29.2
PATCH 9/17 net/mlx5e: VF tunnel RX traffic offloading
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
When tunnel endpoint is on VF the encapsulated RX traffic is exposed on the representor of the VF without any further processing of rules installed on the VF. Detect such case by checking if the device returned by route lookup in decap rule handling code is a mlx5 VF and handle it with new redirection tables API.
Example TC rules for VF tunnel traffic:
1. Rule that encapsulates the tunneled flow and redirects packets from source VF rep to tunnel device:
$ tc -s filter show dev enp8s0f0_1 ingress
filter protocol ip pref 4 flower chain 0
filter protocol ip pref 4 flower chain 0 handle 0x1
dst_mac 0a:40:bd:30:89:99
src_mac ca:2e:a7:3f:f5:0f
eth_type ipv4
ip_tos 0/0x3
ip_flags nofrag
in_hw in_hw_count 1
action order 1: tunnel_key set
src_ip 7.7.7.5
dst_ip 7.7.7.1
key_id 98
dst_port 4789
nocsum
ttl 64 pipe
index 1 ref 1 bind 1 installed 411 sec used 411 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
no_percpu
used_hw_stats delayed action order 2: mirred (Egress Redirect to device vxlan_sys_4789) stolen index 1 ref 1 bind 1 installed 411 sec used 0 sec
Action statistics:
Sent 5615833 bytes 4028 pkt (dropped 0, overlimits 0 requeues 0) Sent software 0 bytes 0 pkt
Sent hardware 5615833 bytes 4028 pkt
backlog 0b 0p requeues 0
cookie bb406d45d343bf7ade9690ae80c7cba4
no_percpu
used_hw_stats delayed
2. Rule that redirects from tunnel device to UL rep:
$ tc -s filter show dev vxlan_sys_4789 ingress
filter protocol ip pref 4 flower chain 0
filter protocol ip pref 4 flower chain 0 handle 0x1
dst_mac ca:2e:a7:3f:f5:0f
src_mac 0a:40:bd:30:89:99
eth_type ipv4
enc_dst_ip 7.7.7.5
enc_src_ip 7.7.7.1
enc_key_id 98
enc_dst_port 4789
enc_tos 0
ip_flags nofrag
in_hw in_hw_count 1
action order 1: tunnel_key unset pipe
index 2 ref 1 bind 1 installed 434 sec used 434 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
used_hw_stats delayed action order 2: mirred (Egress Redirect to device enp8s0f0_1) stolen index 4 ref 1 bind 1 installed 434 sec used 0 sec
Action statistics:
Sent 129936 bytes 1082 pkt (dropped 0, overlimits 0 requeues 0) Sent software 0 bytes 0 pkt
Sent hardware 129936 bytes 1082 pkt
backlog 0b 0p requeues 0
cookie ac17cf398c4c69e4a5b2f7aabd1b88ff
no_percpu
used_hw_stats delayed
--- .../ethernet/mellanox/mlx5/core/en/tc_tun.c | 51 ++++++++ .../ethernet/mellanox/mlx5/core/en/tc_tun.h | 3 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 102 ++++++++++++++- .../net/ethernet/mellanox/mlx5/core/en_tc.h | 4 + .../mellanox/mlx5/core/eswitch_offloads.c | 119 +++++++++++++++++- 5 files changed, 271 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +51 -0
@@ -483,6 +483,57 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, }#endif +int mlx5e_tc_tun_route_lookup (struct mlx5e_priv *priv, +struct mlx5_flow_spec *spec, +struct mlx5_flow_attr *flow_attr) +{ +struct mlx5_esw_flow_attr *esw_attr = flow_attr->esw_attr; +TC_TUN_ROUTE_ATTR_INIT (attr); +u16 vport_num; +int err =0 ; + +if (flow_attr->ip_version ==4 ) { +/* Addresses are swapped for decap */ + attr.fl.fl4.saddr = esw_attr->rx_tun_attr->dst_ip.v4; + attr.fl.fl4.daddr = esw_attr->rx_tun_attr->src_ip.v4; + err =mlx5e_route_lookup_ipv4_get (priv, priv->netdev, &attr); + } +#if IS_ENABLED (CONFIG_INET ) &&IS_ENABLED (CONFIG_IPV6 ) + else if (flow_attr->ip_version == 6) { +/* Addresses are swapped for decap */ + attr.fl.fl6.saddr = esw_attr->rx_tun_attr->dst_ip.v6; + attr.fl.fl6.daddr = esw_attr->rx_tun_attr->src_ip.v6; + err =mlx5e_route_lookup_ipv6_get (priv, priv->netdev, &attr); + } +#endif + else + return 0; + +if (err) +return err; + +if (attr.route_dev->netdev_ops != &mlx5e_netdev_ops || + !mlx5e_tc_is_vf_tunnel (attr.out_dev, attr.route_dev)) + goto out; + + err =mlx5e_tc_query_route_vport (attr.out_dev, attr.route_dev, &vport_num); +if (err) + goto out; + + esw_attr->rx_tun_attr->vni =MLX5_GET (fte_match_param, spec->match_value, + misc_parameters.vxlan_vni); + esw_attr->rx_tun_attr->decap_vport = vport_num; + +out: +if (flow_attr->ip_version ==4 ) +mlx5e_route_lookup_ipv4_put (&attr); +#if IS_ENABLED (CONFIG_INET ) &&IS_ENABLED (CONFIG_IPV6 ) + else if (flow_attr->ip_version == 6) + mlx5e_route_lookup_ipv6_put(&attr); +#endif +return err; +} +bool mlx5e_tc_tun_device_to_offload (struct mlx5e_priv *priv,struct net_device *netdev) {
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h +3 -0
@@ -70,6 +70,9 @@ mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,struct net_device *mirred_dev, struct mlx5e_encap_entry *e) { return -EOPNOTSUPP; }#endif +int mlx5e_tc_tun_route_lookup (struct mlx5e_priv *priv, +struct mlx5_flow_spec *spec, +struct mlx5_flow_attr *attr);bool mlx5e_tc_tun_device_to_offload (struct mlx5e_priv *priv,struct net_device *netdev);
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +99 -3
144 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +4 -0
@@ -257,6 +257,10 @@ mlx5_tc_rule_delete(struct mlx5e_priv *priv,struct mlx5_flow_handle *rule, struct mlx5_flow_attr *attr); +bool mlx5e_tc_is_vf_tunnel (struct net_device *out_dev,struct net_device *route_dev); +int mlx5e_tc_query_route_vport (struct net_device *out_dev,struct net_device *route_dev, +u16 *vport); +#else /* CONFIG_MLX5_CLS_ACT */ static inline int mlx5e_tc_nic_init (struct mlx5e_priv *priv) {return 0 ; }static inline void mlx5e_tc_nic_cleanup (struct mlx5e_priv *priv) {}
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +114 -5
202 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH 10/17 net/mlx5e: Refactor reg_c1 usage
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Following patch in series uses reg_c1 in eswitch code. To use reg_c1 helpers in both TC and eswitch code, refactor existing helpers according to similar use case of reg_c0 and move the functionality into eswitch.h. Calculate reg mappings length from new defines to ensure that they are always in sync and only need to be changed in single place.
--- .../ethernet/mellanox/mlx5/core/en/rep/tc.c | 4 ++-- .../ethernet/mellanox/mlx5/core/en/tc_ct.h | 6 ++---- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 4 ++-- .../net/ethernet/mellanox/mlx5/core/en_tc.h | 2 +- include/linux/mlx5/eswitch.h | 19 +++++++++++++++++++ 5 files changed, 26 insertions(+), 9 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +2 -2
@@ -651,7 +651,7 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, tc_skb_ext->chain = chain; - zone_restore_id = reg_c1 &ZONE_RESTORE_MAX ; + zone_restore_id = reg_c1 &ESW_ZONE_ID_MASK ; uplink_rpriv =mlx5_eswitch_get_uplink_priv (esw,REP_ETH ); uplink_priv = &uplink_rpriv->uplink_priv;
@@ -660,7 +660,7 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, return false; } - tunnel_id = reg_c1 >>REG_MAPPING_SHIFT (TUNNEL_TO_REG ); + tunnel_id = reg_c1 >>ESW_TUN_OFFSET ;return mlx5e_restore_tunnel (priv, skb, tc_priv, tunnel_id);#endif /* CONFIG_NET_TC_SKB_EXT */
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.h +2 -4
@@ -73,7 +73,7 @@ struct mlx5_ct_attr {#define zone_restore_to_reg_ct {\ .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_1,\ .moffset = 0,\ - .mlen = 1,\ + .mlen = (ESW_ZONE_ID_BITS / 8),\ .soffset = MLX5_BYTE_OFF(fte_match_param,\ misc_parameters_2.metadata_reg_c_1) + 3,\ }
@@ -81,14 +81,12 @@ struct mlx5_ct_attr {#define nic_zone_restore_to_reg_ct {\ .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_B,\ .moffset = 2,\ - .mlen = 1,\ + .mlen = (ESW_ZONE_ID_BITS / 8),\ }#define REG_MAPPING_MLEN (reg) (mlx5e_tc_attr_to_reg_mappings[reg].mlen)#define REG_MAPPING_MOFFSET (reg) (mlx5e_tc_attr_to_reg_mappings[reg].moffset)#define REG_MAPPING_SHIFT (reg) (REG_MAPPING_MOFFSET(reg) * 8) -#define ZONE_RESTORE_BITS (REG_MAPPING_MLEN(ZONE_RESTORE_TO_REG) * 8) -#define ZONE_RESTORE_MAX GENMASK(ZONE_RESTORE_BITS - 1, 0)#if IS_ENABLED (CONFIG_MLX5_TC_CT )
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +2 -2
@@ -173,7 +173,7 @@ struct mlx5e_tc_attr_to_reg_mapping mlx5e_tc_attr_to_reg_mappings[] = { [TUNNEL_TO_REG] = { .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_1, .moffset = 1, - .mlen = 3, + .mlen = ((ESW_TUN_OPTS_BITS + ESW_TUN_ID_BITS) / 8), .soffset =MLX5_BYTE_OFF (fte_match_param, misc_parameters_2.metadata_reg_c_1), },
@@ -5649,7 +5649,7 @@ bool mlx5e_tc_update_skb(struct mlx5_cqe64 *cqe, tc_skb_ext->chain = chain; zone_restore_id = (reg_b >>REG_MAPPING_SHIFT (NIC_ZONE_RESTORE_TO_REG )) & -ZONE_RESTORE_MAX ; +ESW_ZONE_ID_MASK ;if (!mlx5e_tc_ct_restore_flow (tc->ct, skb, zone_restore_id))
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +1 -1
@@ -302,7 +302,7 @@ static inline bool mlx5e_cqe_regb_chain(struct mlx5_cqe64 *cqe) reg_b =be32_to_cpu (cqe->ft_metadata); -if (reg_b >> (MLX5E_TC_TABLE_CHAIN_TAG_BITS +ZONE_RESTORE_BITS )) +if (reg_b >> (MLX5E_TC_TABLE_CHAIN_TAG_BITS +ESW_ZONE_ID_BITS ))return false; chain = reg_b &MLX5E_TC_TABLE_CHAIN_TAG_MASK ;
include/linux/mlx5/eswitch.h +19 -0
@@ -98,6 +98,25 @@ u32 mlx5_eswitch_get_vport_metadata_for_match(struct mlx5_eswitch *esw, u16 vport_num);u32 mlx5_eswitch_get_vport_metadata_for_set (struct mlx5_eswitch *esw,u16 vport_num); + +/* Reg C1 usage: +* Reg C1 = < ESW_TUN_ID(12) | ESW_TUN_OPTS(12) | ESW_ZONE_ID(8) > +* +* Highest 12 bits of reg c1 is the encapsulation tunnel id, next 12 bits is +* encapsulation tunnel options, and the lowest 8 bits are used for zone id. +* +* Zone id is used to restore CT flow when packet misses on chain. +* +* Tunnel id and options are used together to restore the tunnel info metadata +* on miss and to support inner header rewrite by means of implicit chain 0 +* flows. +*/ +#define ESW_ZONE_ID_BITS 8 +#define ESW_TUN_OPTS_BITS 12 +#define ESW_TUN_ID_BITS 12 +#define ESW_TUN_OFFSET ESW_ZONE_ID_BITS +#define ESW_ZONE_ID_MASK GENMASK(ESW_ZONE_ID_BITS - 1, 0) +u8 mlx5_eswitch_mode (struct mlx5_core_dev *dev);#else /* CONFIG_MLX5_ESWITCH */
Signature · 1 line
2.29.2
PATCH 11/17 net/mlx5e: Match recirculated packet miss in slow table using reg_c1
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Previous patch in series that implements stack devices RX path implements indirect table rules that match on tunnel VNI. After such rule is created all tunnel traffic is recirculated to root table. However, recirculated packet might not match on any rules installed in the table (for example, when IP traffic follows ARP traffic). In that case packets appear on representor of tunnel endpoint VF instead being redirected to the VF itself.
Extend slow table with additional flow group that matches on reg_c0 (source port value set by indirect tables implemented by previous patch in series) and reg_c1 (special 0xFFF mark). When creating offloads fdb tables, install one rule per VF vport to match on recirculated miss packets and redirect them to appropriate VF vport. Modify indirect tables code to also rewrite reg_c1 with special 0xFFF mark.
Implementation reuses reg_c1 tunnel id bits. This is safe to do because recirculated packets are always matched before decapsulation.
--- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 3 +- .../mellanox/mlx5/core/esw/indir_table.c | 17 ++- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 2 + .../mellanox/mlx5/core/eswitch_offloads.c | 119 +++++++++++++++++- include/linux/mlx5/eswitch.h | 10 +- 5 files changed, 143 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +2 -1
@@ -5515,7 +5515,8 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht) } uplink_priv->tunnel_mapping = mapping; - mapping =mapping_create (sz_enc_opts,ENC_OPTS_BITS_MASK , true); +/* 0xFFF is reserved for stack devices slow path table mark */ + mapping =mapping_create (sz_enc_opts,ENC_OPTS_BITS_MASK -1 , true);if (IS_ERR (mapping)) { err =PTR_ERR (mapping); goto err_enc_opts_mapping;
drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.c +13 -4
@@ -162,7 +162,7 @@ static int mlx5_esw_indir_table_rule_get(struct mlx5_eswitch *esw, (attr->ip_version == 4 ? ETH_P_IP : ETH_P_IPV6)); }else { err = -EOPNOTSUPP ; - goto err_mod_hdr; + goto err_ethertype; }if (attr->ip_version ==4 ) {
@@ -198,13 +198,18 @@ static int mlx5_esw_indir_table_rule_get(struct mlx5_eswitch *esw, err =mlx5e_tc_match_to_reg_set (esw->dev, &mod_acts,MLX5_FLOW_NAMESPACE_FDB ,VPORT_TO_REG , data);if (err) - goto err_mod_hdr; + goto err_mod_hdr_regc0; + + err =mlx5e_tc_match_to_reg_set (esw->dev, &mod_acts,MLX5_FLOW_NAMESPACE_FDB , +TUNNEL_TO_REG ,ESW_TUN_SLOW_TABLE_GOTO_VPORT ); +if (err) + goto err_mod_hdr_regc1; flow_act.modify_hdr =mlx5_modify_header_alloc (esw->dev,MLX5_FLOW_NAMESPACE_FDB , mod_acts.num_actions, mod_acts.actions);if (IS_ERR (flow_act.modify_hdr)) { err =PTR_ERR (flow_act.modify_hdr); - goto err_mod_hdr; + goto err_mod_hdr_alloc; } flow_act.action =MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |MLX5_FLOW_CONTEXT_ACTION_MOD_HDR ;
@@ -236,7 +241,11 @@ static int mlx5_esw_indir_table_rule_get(struct mlx5_eswitch *esw,mlx5_chains_put_table (chains,0 ,1 ,0 ); err_table:mlx5_modify_header_dealloc (esw->dev, flow_act.modify_hdr); -err_mod_hdr: +err_mod_hdr_alloc: +err_mod_hdr_regc1: +dealloc_mod_hdr_actions (&mod_acts); +err_mod_hdr_regc0: +err_ethertype:kfree (rule); out:kfree (rule_spec);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +2 -0
@@ -179,9 +179,11 @@ struct mlx5_eswitch_fdb {struct mlx5_flow_namespace *ns;struct mlx5_flow_table *slow_fdb;struct mlx5_flow_group *send_to_vport_grp; +struct mlx5_flow_group *send_to_vport_meta_grp;struct mlx5_flow_group *peer_miss_grp;struct mlx5_flow_handle **peer_miss_rules;struct mlx5_flow_group *miss_grp; +struct mlx5_flow_handle **send_to_vport_meta_rules;struct mlx5_flow_handle *miss_rule_uni;struct mlx5_flow_handle *miss_rule_multi;int vlan_push_pop_refcount;
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +117 -2
160 lines not on this page · raw message
include/linux/mlx5/eswitch.h +9 -1
@@ -114,8 +114,16 @@ u32 mlx5_eswitch_get_vport_metadata_for_set(struct mlx5_eswitch *esw,#define ESW_ZONE_ID_BITS 8#define ESW_TUN_OPTS_BITS 12#define ESW_TUN_ID_BITS 12 -#define ESW_TUN_OFFSET ESW_ZONE_ID_BITS +#define ESW_TUN_OPTS_OFFSET ESW_ZONE_ID_BITS +#define ESW_TUN_OFFSET ESW_TUN_OPTS_OFFSET#define ESW_ZONE_ID_MASK GENMASK(ESW_ZONE_ID_BITS - 1, 0) +#define ESW_TUN_OPTS_MASK GENMASK(32 - ESW_TUN_ID_BITS - 1, ESW_TUN_OPTS_OFFSET) +#define ESW_TUN_MASK GENMASK(31, ESW_TUN_OFFSET) +#define ESW_TUN_ID_SLOW_TABLE_GOTO_VPORT 0/* 0 is not a valid tunnel id */ +#define ESW_TUN_OPTS_SLOW_TABLE_GOTO_VPORT 0xFFF/* 0xFFF is a reserved mapping */ +#define ESW_TUN_SLOW_TABLE_GOTO_VPORT ((ESW_TUN_ID_SLOW_TABLE_GOTO_VPORT << ESW_TUN_OPTS_BITS) | \ + ESW_TUN_OPTS_SLOW_TABLE_GOTO_VPORT) +#define ESW_TUN_SLOW_TABLE_GOTO_VPORT_MARK ESW_TUN_OPTS_MASKu8 mlx5_eswitch_mode (struct mlx5_core_dev *dev);#else /* CONFIG_MLX5_ESWITCH */
Signature · 1 line
2.29.2
PATCH 12/17 net/mlx5e: Extract tc tunnel encap/decap code to dedicated file
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Following patches in series extend the extracted code with routing infrastructure. To improve code modularity created a dedicated tc_tun_encap.c source file and move encap/decap related code to the new file. Export code that is used by both regular TC code and encap/decap code into tc_priv.h (new header intended to be used only by TC module). Rename some exported functions by adding "mlx5e_" prefix to their names.
--- .../net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../ethernet/mellanox/mlx5/core/en/tc_priv.h | 163 ++++ .../ethernet/mellanox/mlx5/core/en/tc_tun.c | 1 + .../mellanox/mlx5/core/en/tc_tun_encap.c | 734 ++++++++++++++ .../mellanox/mlx5/core/en/tc_tun_encap.h | 30 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 900 +----------------- .../net/ethernet/mellanox/mlx5/core/en_tc.h | 2 + 7 files changed, 947 insertions(+), 885 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.h
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
@@ -40,7 +40,7 @@ mlx5_core-$(CONFIG_MLX5_ESWITCH) += lag_mp.o lib/geneve.o lib/port_tun.o \ en_rep.o en/rep/bond.o en/mod_hdr.o mlx5_core-$(CONFIG_MLX5_CLS_ACT) += en_tc.o en/rep/tc.o en/rep/neigh.o \ en/mapping.o lib/fs_chains.o en/tc_tun.o \ - esw/indir_table.o \ + esw/indir_table.o en/tc_tun_encap.o \ en/tc_tun_vxlan.o en/tc_tun_gre.o en/tc_tun_geneve.o \ en/tc_tun_mplsoudp.o diag/en_tc_tracepoint.o mlx5_core-$(CONFIG_MLX5_TC_CT) += en/tc_ct.o
drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h new file +163 -0
163 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +1 -0
@@ -6,6 +6,7 @@#include <net/geneve.h> #include <net/bareudp.h> #include "en/tc_tun.h" +#include "en/tc_priv.h" #include "en_tc.h" #include "rep/tc.h" #include "rep/neigh.h"
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c new file +734 -0
734 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* Copyright (c) 2021 Mellanox Technologies. */ + +#ifndef __MLX5_EN_TC_TUN_ENCAP_H__ +#define __MLX5_EN_TC_TUN_ENCAP_H__ + +#include "tc_priv.h" + +void mlx5e_detach_encap (struct mlx5e_priv *priv, +struct mlx5e_tc_flow *flow,int out_index); + +int mlx5e_attach_encap (struct mlx5e_priv *priv, +struct mlx5e_tc_flow *flow, +struct net_device *mirred_dev, +int out_index, +struct netlink_ext_ack *extack, +struct net_device **encap_dev, +bool *encap_valid); +int mlx5e_attach_decap (struct mlx5e_priv *priv, +struct mlx5e_tc_flow *flow, +struct netlink_ext_ack *extack); +void mlx5e_detach_decap (struct mlx5e_priv *priv, +struct mlx5e_tc_flow *flow); + +struct ip_tunnel_info *mlx5e_dup_tun_info (const struct ip_tunnel_info *tun_info); + +int mlx5e_tc_set_attr_rx_tun (struct mlx5e_tc_flow *flow, +struct mlx5_flow_spec *spec); + +#endif /* __MLX5_EN_TC_TUN_ENCAP_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +16 -884
1,006 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +2 -0
@@ -37,6 +37,8 @@#include "en.h" #include "eswitch.h" #include "en/tc_ct.h" +#include "en/tc_tun.h" +#include "en_rep.h" #define MLX5E_TC_FLOW_ID_MASK 0x0000ffff
Signature · 1 line
2.29.2
PATCH 13/17 net/mlx5e: Create route entry infrastructure
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Implement dedicated route entry infrastructure to be used in following patch by route update event. Both encap (indirectly through their corresponding encap entries) and decap (directly) flows are attached to routing entry. Since route update also requires updating encap (route device MAC address is a source MAC address of tunnel encapsulation), same encap_tbl_lock mutex is used for synchronization.
The new infrastructure looks similar to existing infrastructures for shared encap, mod_hdr and hairpin entries:
- Per-eswitch hash table is used for quick entry lookup.
- Flows are attached to per-entry linked list and hold reference to entry during their lifetime.
- Atomic reference counting and rcu mechanisms are used as synchronization primitives for concurrent access.
The infrastructure also enables connection tracking on stacked devices topology by attaching CT chain 0 flow on tunneling dev to decap route entry.
--- .../ethernet/mellanox/mlx5/core/en/tc_priv.h | 11 + .../mellanox/mlx5/core/en/tc_tun_encap.c | 258 +++++++++++++++++- .../mellanox/mlx5/core/en/tc_tun_encap.h | 5 + .../net/ethernet/mellanox/mlx5/core/en_rep.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 24 +- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 1 + .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + 7 files changed, 290 insertions(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h +11 -0
@@ -25,6 +25,7 @@ enum {MLX5E_TC_FLOW_FLAG_DELETED =MLX5E_TC_FLOW_BASE +6 ,MLX5E_TC_FLOW_FLAG_CT =MLX5E_TC_FLOW_BASE +7 ,MLX5E_TC_FLOW_FLAG_L3_TO_L2_DECAP =MLX5E_TC_FLOW_BASE +8 , + MLX5E_TC_FLOW_FLAG_TUN_RX = MLX5E_TC_FLOW_BASE + 9, }; struct mlx5e_tc_flow_parse_attr {
@@ -59,6 +60,11 @@ struct encap_flow_item {int index; }; +struct encap_route_flow_item { +struct mlx5e_route_entry *r;/* attached route instance */ +int index; +}; +struct mlx5e_tc_flow {struct rhash_head node;struct mlx5e_priv *priv;
@@ -70,6 +76,11 @@ struct mlx5e_tc_flow {struct list_head l3_to_l2_reformat;struct mlx5e_decap_entry *decap_reformat; +/* flows sharing same route entry */ +struct list_head decap_routes; +struct mlx5e_route_entry *decap_route; +struct encap_route_flow_item encap_routes[MLX5_MAX_FLOW_FWD_VPORTS ]; +/* Flow can be associated with multiple encap IDs. * The number of encaps is bounded by the number of supported * destinations.
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +256 -2
333 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.h +5 -0
@@ -22,6 +22,11 @@ int mlx5e_attach_decap(struct mlx5e_priv *priv,void mlx5e_detach_decap (struct mlx5e_priv *priv,struct mlx5e_tc_flow *flow); +int mlx5e_attach_decap_route (struct mlx5e_priv *priv, +struct mlx5e_tc_flow *flow); +void mlx5e_detach_decap_route (struct mlx5e_priv *priv, +struct mlx5e_tc_flow *flow); +struct ip_tunnel_info *mlx5e_dup_tun_info (const struct ip_tunnel_info *tun_info); int mlx5e_tc_set_attr_rx_tun(struct mlx5e_tc_flow *flow,
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +1 -0
@@ -181,6 +181,7 @@ struct mlx5e_encap_entry {*/ struct hlist_node encap_hlist;struct list_head flows; +struct list_head route_list;struct mlx5_pkt_reformat *pkt_reformat;const struct ip_tunnel_info *tun_info;unsigned char h_dest[ETH_ALEN ];/* destination eth addr */
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +15 -9
@@ -1251,6 +1251,12 @@ mlx5e_tc_add_fdb_flow(struct mlx5e_priv *priv,return -EOPNOTSUPP ; } +if (flow_flag_test (flow,TUN_RX )) { + err =mlx5e_attach_decap_route (priv, flow); +if (err) +return err; + } +if (flow_flag_test (flow,L3_TO_L2_DECAP )) { err =mlx5e_attach_decap (priv, flow, extack);if (err)
@@ -1335,8 +1341,10 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv, {struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;struct mlx5_flow_attr *attr = flow->attr; +struct mlx5_esw_flow_attr *esw_attr;int out_index; + esw_attr = attr->esw_attr;mlx5e_put_flow_tunnel_id (flow);if (flow_flag_test (flow,NOT_READY ))
@@ -1354,11 +1362,15 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,mlx5_eswitch_del_vlan_action (esw, attr); -for (out_index =0 ; out_index <MLX5_MAX_FLOW_FWD_VPORTS ; out_index++) -if (attr->esw_attr->dests[out_index].flags &MLX5_ESW_DEST_ENCAP ) { +if (flow->decap_route) +mlx5e_detach_decap_route (priv, flow); + +for (out_index =0 ; out_index <MLX5_MAX_FLOW_FWD_VPORTS ; out_index++) { +if (esw_attr->dests[out_index].flags &MLX5_ESW_DEST_ENCAP ) {mlx5e_detach_encap (priv, flow, out_index);kfree (attr->parse_attr->tun_info[out_index]); } + }kvfree (attr->parse_attr);kvfree (attr->esw_attr->rx_tun_attr);
@@ -1368,7 +1380,7 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,mlx5e_detach_mod_hdr (priv, flow);if (attr->action &MLX5_FLOW_CONTEXT_ACTION_COUNT ) -mlx5_fc_destroy (attr->esw_attr->counter_dev, attr->counter); +mlx5_fc_destroy (esw_attr->counter_dev, attr->counter);if (flow_flag_test (flow,L3_TO_L2_DECAP ))mlx5e_detach_decap (priv, flow);
@@ -3692,12 +3704,6 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, } } -if (decap && esw_attr->rx_tun_attr) { - err =mlx5e_tc_tun_route_lookup (priv, &parse_attr->spec, attr); -if (err) -return err; - } -/* always set IP version for indirect table handling */ attr->ip_version =mlx5e_tc_get_ip_version (&parse_attr->spec, true);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1 -0
@@ -1830,6 +1830,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)mutex_init (&esw->offloads.decap_tbl_lock);hash_init (esw->offloads.decap_tbl);mlx5e_mod_hdr_tbl_init (&esw->offloads.mod_hdr); +hash_init (esw->offloads.route_tbl);atomic64_set (&esw->offloads.num_flows,0 );ida_init (&esw->offloads.vport_metadata_ida);xa_init_flags (&esw->offloads.vhca_map,XA_FLAGS_ALLOC );
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +1 -0
@@ -214,6 +214,7 @@ struct mlx5_esw_offload {struct mutex peer_mutex;struct mutex encap_tbl_lock;/* protects encap_tbl */ DECLARE_HASHTABLE (encap_tbl,8 ); +DECLARE_HASHTABLE (route_tbl,8 );struct mutex decap_tbl_lock;/* protects decap_tbl */ DECLARE_HASHTABLE (decap_tbl,8 );struct mod_hdr_tbl mod_hdr;
Signature · 1 line
2.29.2
PATCH 14/17 net/mlx5e: Refactor neigh update infrastructure
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Following patches in series implements route update which can cause encap entries to migrate between routing devices. Consecutively, their parent nhe's need to be also transferable between devices instead of having neigh device as a part of their immutable key. Move neigh device from struct mlx5_neigh to struct mlx5e_neigh_hash_entry and check that nhe and neigh devices are the same in workqueue neigh update handler.
Save neigh net_device that can change dynamically in dedicated nhe->dev field. With FIB event handler that is implemented in following patches changing nhe->dev, NETEVENT_DELAY_PROBE_TIME_UPDATE handler can concurrently access the nhe entry when traversing neigh list under rcu read lock. Processing stale values in that handler doesn't change the handler logic, so just wrap all accesses to the dev pointer in {WRITE|READ}_ONCE() helpers.
--- .../mlx5/core/diag/en_rep_tracepoint.h | 4 ++-- .../mlx5/core/diag/en_tc_tracepoint.h | 4 ++-- .../mellanox/mlx5/core/en/rep/neigh.c | 16 +++++++++----- .../mellanox/mlx5/core/en/rep/neigh.h | 3 ++- .../ethernet/mellanox/mlx5/core/en/rep/tc.c | 8 ++++--- .../ethernet/mellanox/mlx5/core/en/rep/tc.h | 4 +++- .../ethernet/mellanox/mlx5/core/en/tc_tun.c | 22 +++++++------------ .../mellanox/mlx5/core/en/tc_tun_encap.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en_rep.h | 3 +-- 9 files changed, 35 insertions(+), 31 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/diag/en_rep_tracepoint.h +2 -2
@@ -15,7 +15,7 @@ TRACE_EVENT(mlx5e_rep_neigh_update, TP_PROTO(const struct mlx5e_neigh_hash_entry *nhe, const u8 *ha, bool neigh_connected), TP_ARGS(nhe, ha, neigh_connected), - TP_STRUCT__entry(__string(devname, nhe->m_neigh.dev->name) + TP_STRUCT__entry(__string(devname, nhe->neigh_dev->name) __array(u8, ha, ETH_ALEN) __array(u8, v4, 4) __array(u8, v6, 16)
@@ -25,7 +25,7 @@ TRACE_EVENT(mlx5e_rep_neigh_update,struct in6_addr *pin6;__be32 *p32; -__assign_str (devname, mn->dev->name); +__assign_str (devname, nhe->neigh_dev->name); __entry->neigh_connected = neigh_connected;memcpy (__entry->ha, ha,ETH_ALEN );
drivers/net/ethernet/mellanox/mlx5/core/diag/en_tc_tracepoint.h +2 -2
@@ -77,7 +77,7 @@ TRACE_EVENT(mlx5e_stats_flower, TRACE_EVENT(mlx5e_tc_update_neigh_used_value, TP_PROTO(const struct mlx5e_neigh_hash_entry *nhe, bool neigh_used), TP_ARGS(nhe, neigh_used), - TP_STRUCT__entry(__string(devname, nhe->m_neigh.dev->name) + TP_STRUCT__entry(__string(devname, nhe->neigh_dev->name) __array(u8, v4, 4) __array(u8, v6, 16) __field(bool, neigh_used)
@@ -86,7 +86,7 @@ TRACE_EVENT(mlx5e_tc_update_neigh_used_value,struct in6_addr *pin6;__be32 *p32; -__assign_str (devname, mn->dev->name); +__assign_str (devname, nhe->neigh_dev->name); __entry->neigh_used = neigh_used; p32 = (__be32 *)__entry->v4;
drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.c +11 -5
@@ -129,10 +129,10 @@ static void mlx5e_rep_neigh_update(struct work_struct *work) work);struct mlx5e_neigh_hash_entry *nhe = update_work->nhe;struct neighbour *n = update_work->n; +bool neigh_connected, same_dev;struct mlx5e_encap_entry *e;unsigned char ha[ETH_ALEN ];struct mlx5e_priv *priv; -bool neigh_connected;u8 nud_state, dead;rtnl_lock ();
@@ -146,12 +146,16 @@ static void mlx5e_rep_neigh_update(struct work_struct *work)memcpy (ha, n->ha,ETH_ALEN ); nud_state = n->nud_state; dead = n->dead; + same_dev =READ_ONCE (nhe->neigh_dev) == n->dev;read_unlock_bh (&n->lock); neigh_connected = (nud_state &NUD_VALID ) && !dead;trace_mlx5e_rep_neigh_update (nhe, ha, neigh_connected); +if (!same_dev) + goto out; +list_for_each_entry (e, &nhe->encap_list, encap_list) {if (!mlx5e_encap_take (e))continue ;
@@ -160,6 +164,7 @@ static void mlx5e_rep_neigh_update(struct work_struct *work)mlx5e_rep_update_flows (priv, e, neigh_connected, ha);mlx5e_encap_put (priv, e); } +out:rtnl_unlock ();mlx5e_release_neigh_update_work (update_work); }
@@ -175,7 +180,6 @@ static struct neigh_update_work *mlx5e_alloc_neigh_update_work(struct mlx5e_privif (WARN_ON (!update_work))return NULL ; - m_neigh.dev = n->dev; m_neigh.family = n->ops->family;memcpy (&m_neigh.dst_ip, n->primary_key, n->tbl->key_len);
@@ -246,7 +250,7 @@ static int mlx5e_rep_netevent_event(struct notifier_block *nb,rcu_read_lock ();list_for_each_entry_rcu (nhe, &neigh_update->neigh_list, neigh_list) { -if (p->dev == nhe->m_neigh.dev) { +if (p->dev ==READ_ONCE (nhe->neigh_dev)) { found = true;break ; }
@@ -369,7 +373,8 @@ mlx5e_rep_neigh_entry_lookup(struct mlx5e_priv *priv, }int mlx5e_rep_neigh_entry_create (struct mlx5e_priv *priv, -struct mlx5e_encap_entry *e, +struct mlx5e_neigh *m_neigh, +struct net_device *neigh_dev,struct mlx5e_neigh_hash_entry **nhe) {int err;
@@ -379,10 +384,11 @@ int mlx5e_rep_neigh_entry_create(struct mlx5e_priv *priv,return -ENOMEM ; (*nhe)->priv = priv; -memcpy (&(*nhe)->m_neigh, &e->m_neigh,sizeof (e->m_neigh)); +memcpy (&(*nhe)->m_neigh, m_neigh,sizeof (*m_neigh));spin_lock_init (&(*nhe)->encap_list_lock);INIT_LIST_HEAD (&(*nhe)->encap_list);refcount_set (&(*nhe)->refcnt,1 ); +WRITE_ONCE ((*nhe)->neigh_dev, neigh_dev); err =mlx5e_rep_neigh_entry_insert (priv, *nhe);if (err)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/neigh.h +2 -1
@@ -16,7 +16,8 @@ struct mlx5e_neigh_hash_entry * mlx5e_rep_neigh_entry_lookup(struct mlx5e_priv *priv, struct mlx5e_neigh *m_neigh);int mlx5e_rep_neigh_entry_create (struct mlx5e_priv *priv, -struct mlx5e_encap_entry *e, +struct mlx5e_neigh *m_neigh, +struct net_device *neigh_dev,struct mlx5e_neigh_hash_entry **nhe);void mlx5e_rep_neigh_entry_release (struct mlx5e_neigh_hash_entry *nhe);
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +5 -3
@@ -26,7 +26,9 @@ struct mlx5e_rep_indr_block_priv { };int mlx5e_rep_encap_entry_attach (struct mlx5e_priv *priv, -struct mlx5e_encap_entry *e) +struct mlx5e_encap_entry *e, +struct mlx5e_neigh *m_neigh, +struct net_device *neigh_dev) {struct mlx5e_rep_priv *rpriv = priv->ppriv;struct mlx5_rep_uplink_priv *uplink_priv = &rpriv->uplink_priv;
@@ -39,9 +41,9 @@ int mlx5e_rep_encap_entry_attach(struct mlx5e_priv *priv,return err;mutex_lock (&rpriv->neigh_update.encap_lock); - nhe =mlx5e_rep_neigh_entry_lookup (priv, &e->m_neigh); + nhe =mlx5e_rep_neigh_entry_lookup (priv, m_neigh);if (!nhe) { - err =mlx5e_rep_neigh_entry_create (priv, e, &nhe); + err =mlx5e_rep_neigh_entry_create (priv, m_neigh, neigh_dev, &nhe);if (err) {mutex_unlock (&rpriv->neigh_update.encap_lock); mlx5_tun_entropy_refcount_dec(tun_entropy,
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.h +3 -1
@@ -27,7 +27,9 @@ void mlx5e_rep_update_flows(struct mlx5e_priv *priv, unsigned char ha[ETH_ALEN]);int mlx5e_rep_encap_entry_attach (struct mlx5e_priv *priv, -struct mlx5e_encap_entry *e); +struct mlx5e_encap_entry *e, +struct mlx5e_neigh *m_neigh, +struct net_device *neigh_dev);void mlx5e_rep_encap_entry_detach (struct mlx5e_priv *priv,struct mlx5e_encap_entry *e);
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +8 -14
@@ -212,6 +212,7 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, {int max_encap_size =MLX5_CAP_ESW (priv->mdev, max_encap_header_size);const struct ip_tunnel_key *tun_key = &e->tun_info->key; +struct mlx5e_neigh m_neigh = {};TC_TUN_ROUTE_ATTR_INIT (attr);int ipv4_encap_size;char *encap_header;
@@ -247,12 +248,8 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv, goto release_neigh; } -/* used by mlx5e_detach_encap to lookup a neigh hash table -* entry in the neigh hash table when a user deletes a rule -*/ - e->m_neigh.dev = attr.n->dev; - e->m_neigh.family = attr.n->ops->family; -memcpy (&e->m_neigh.dst_ip, attr.n->primary_key, attr.n->tbl->key_len); + m_neigh.family = attr.n->ops->family; +memcpy (&m_neigh.dst_ip, attr.n->primary_key, attr.n->tbl->key_len); e->out_dev = attr.out_dev; e->route_dev_ifindex = attr.route_dev->ifindex;
@@ -261,7 +258,7 @@ int mlx5e_tc_tun_create_header_ipv4(struct mlx5e_priv *priv,* neigh changes it's validity state, we would find the relevant neigh * in the hash. */ - err =mlx5e_rep_encap_entry_attach (netdev_priv (attr.out_dev), e); + err =mlx5e_rep_encap_entry_attach (netdev_priv (attr.out_dev), e, &m_neigh, attr.n->dev);if (err) goto free_encap;
@@ -375,6 +372,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, {int max_encap_size =MLX5_CAP_ESW (priv->mdev, max_encap_header_size);const struct ip_tunnel_key *tun_key = &e->tun_info->key; +struct mlx5e_neigh m_neigh = {};TC_TUN_ROUTE_ATTR_INIT (attr);struct ipv6hdr *ip6h;int ipv6_encap_size;
@@ -409,12 +407,8 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv, goto release_neigh; } -/* used by mlx5e_detach_encap to lookup a neigh hash table -* entry in the neigh hash table when a user deletes a rule -*/ - e->m_neigh.dev = attr.n->dev; - e->m_neigh.family = attr.n->ops->family; -memcpy (&e->m_neigh.dst_ip, attr.n->primary_key, attr.n->tbl->key_len); + m_neigh.family = attr.n->ops->family; +memcpy (&m_neigh.dst_ip, attr.n->primary_key, attr.n->tbl->key_len); e->out_dev = attr.out_dev; e->route_dev_ifindex = attr.route_dev->ifindex;
@@ -423,7 +417,7 @@ int mlx5e_tc_tun_create_header_ipv6(struct mlx5e_priv *priv,* neigh changes it's validity state, we would find the relevant neigh * in the hash. */ - err =mlx5e_rep_encap_entry_attach (netdev_priv (attr.out_dev), e); + err =mlx5e_rep_encap_entry_attach (netdev_priv (attr.out_dev), e, &m_neigh, attr.n->dev);if (err) goto free_encap;
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +1 -1
@@ -310,7 +310,7 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe)/* find the relevant neigh according to the cached device and * dst ip pair */ - n =neigh_lookup (tbl, &m_neigh->dst_ip, m_neigh->dev); + n =neigh_lookup (tbl, &m_neigh->dst_ip,READ_ONCE (nhe->neigh_dev));if (!n)return ;
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +1 -2
@@ -110,7 +110,6 @@ struct mlx5e_rep_priv *mlx5e_rep_to_rep_priv(struct mlx5_eswitch_rep *rep) }struct mlx5e_neigh { -struct net_device *dev;union {__be32 v4;struct in6_addr v6;
@@ -122,6 +121,7 @@ struct mlx5e_neigh_hash_entry {struct rhash_head rhash_node;struct mlx5e_neigh m_neigh;struct mlx5e_priv *priv; +struct net_device *neigh_dev;/* Save the neigh hash entry in a list on the representor in * addition to the hash table. In order to iterate easily over the
@@ -175,7 +175,6 @@ struct mlx5e_encap_entry {struct mlx5e_neigh_hash_entry *nhe;/* neigh hash entry list of encaps sharing the same neigh */ struct list_head encap_list; -struct mlx5e_neigh m_neigh;/* a node of the eswitch encap hash table which keeping all the encap * entries */
Signature · 1 line
2.29.2
PATCH 15/17 net/mlx5e: TC preparation refactoring for routing update event
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Following patch in series implement routing update event which requires ability to modify rule match_to_reg modify header actions dynamically during rule lifetime. In order to accommodate such behavior, refactor and extend TC infrastructure in following ways:
- Modify mod_hdr infrastructure to preserve its parse attribute for whole rule lifetime, instead of deallocating it after rule creation.
- Extend match_to_reg infrastructure with new function mlx5e_tc_match_to_reg_set_and_get_id() that returns mod_hdr action id that can be used afterwards to update the action, and mlx5e_tc_match_to_reg_mod_hdr_change() that can modify existing actions by its id.
- Extend tun API with new functions mlx5e_tc_tun_update_header_ipv{4|6}() that are used to updated existing encap entry tunnel header.
--- .../ethernet/mellanox/mlx5/core/en/tc_ct.c | 1 - .../ethernet/mellanox/mlx5/core/en/tc_tun.c | 198 ++++++++++++++++++ .../ethernet/mellanox/mlx5/core/en/tc_tun.h | 10 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 73 ++++++- .../net/ethernet/mellanox/mlx5/core/en_tc.h | 15 ++ 5 files changed, 288 insertions(+), 9 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +0 -1
@@ -1763,7 +1763,6 @@ __mlx5_tc_ct_flow_offload_clear(struct mlx5_tc_ct_priv *ct_priv, goto err_set_registers; } -dealloc_mod_hdr_actions (mod_acts); pre_ct_attr->modify_hdr = mod_hdr; pre_ct_attr->action |=MLX5_FLOW_CONTEXT_ACTION_MOD_HDR ;
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +198 -0
210 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h +10 -0
@@ -59,16 +59,26 @@ int mlx5e_tc_tun_init_encap_attr(struct net_device *tunnel_dev,int mlx5e_tc_tun_create_header_ipv4 (struct mlx5e_priv *priv,struct net_device *mirred_dev,struct mlx5e_encap_entry *e); +int mlx5e_tc_tun_update_header_ipv4 (struct mlx5e_priv *priv, +struct net_device *mirred_dev, +struct mlx5e_encap_entry *e);#if IS_ENABLED (CONFIG_INET ) &&IS_ENABLED (CONFIG_IPV6 )int mlx5e_tc_tun_create_header_ipv6 (struct mlx5e_priv *priv,struct net_device *mirred_dev,struct mlx5e_encap_entry *e); +int mlx5e_tc_tun_update_header_ipv6 (struct mlx5e_priv *priv, +struct net_device *mirred_dev, +struct mlx5e_encap_entry *e);#else static inline int mlx5e_tc_tun_create_header_ipv6 (struct mlx5e_priv *priv,struct net_device *mirred_dev,struct mlx5e_encap_entry *e) {return -EOPNOTSUPP ; } +int mlx5e_tc_tun_update_header_ipv6 (struct mlx5e_priv *priv, +struct net_device *mirred_dev, +struct mlx5e_encap_entry *e) +{return -EOPNOTSUPP ; }#endif int mlx5e_tc_tun_route_lookup(struct mlx5e_priv *priv, struct mlx5_flow_spec *spec,
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +65 -8
112 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +15 -0
@@ -214,6 +214,11 @@ int mlx5e_tc_match_to_reg_set(struct mlx5_core_dev *mdev,enum mlx5e_tc_attr_to_reg type, u32 data); +void mlx5e_tc_match_to_reg_mod_hdr_change (struct mlx5_core_dev *mdev, +struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, +enum mlx5e_tc_attr_to_reg type, +int act_id,u32 data); + void mlx5e_tc_match_to_reg_match(struct mlx5_flow_spec *spec, enum mlx5e_tc_attr_to_reg type, u32 data,
@@ -224,6 +229,16 @@ void mlx5e_tc_match_to_reg_get_match(struct mlx5_flow_spec *spec, u32 *data, u32 *mask); +int mlx5e_tc_match_to_reg_set_and_get_id (struct mlx5_core_dev *mdev, +struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, +enum mlx5_flow_namespace_type ns, +enum mlx5e_tc_attr_to_reg type, +u32 data); + +int mlx5e_tc_add_flow_mod_hdr (struct mlx5e_priv *priv, +struct mlx5e_tc_flow_parse_attr *parse_attr, +struct mlx5e_tc_flow *flow); +int alloc_mod_hdr_actions (struct mlx5_core_dev *mdev,int namespace,struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
Signature · 1 line
2.29.2
PATCH 16/17 net/mlx5e: Rename some encap-specific API to generic names
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Some of the encap-specific functions and fields will also be used by route update infrastructure in following patches. Rename them to generic names.
--- drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c | 10 +++++----- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_tc.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +1 -1
@@ -124,7 +124,7 @@ void mlx5e_rep_update_flows(struct mlx5e_priv *priv, } unlock:mutex_unlock (&esw->offloads.encap_tbl_lock); -mlx5e_put_encap_flow_list (priv, &flow_list); +mlx5e_put_flow_list (priv, &flow_list); } static int
drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h +1 -1
@@ -95,7 +95,7 @@ struct mlx5e_tc_flow {* due to missing route) */ struct net_device *orig_dev;/* netdev adding flow first */ -int tmp_efi_index; +int tmp_entry_index;struct list_head tmp_list;/* temporary flow list used by neigh update */ refcount_t refcnt;struct rcu_head rcu_head;
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +5 -5
@@ -106,8 +106,8 @@ void mlx5e_tc_encap_flows_add(struct mlx5e_priv *priv, esw_attr = attr->esw_attr; spec = &attr->parse_attr->spec; - esw_attr->dests[flow->tmp_efi_index].pkt_reformat = e->pkt_reformat; - esw_attr->dests[flow->tmp_efi_index].flags |=MLX5_ESW_DEST_ENCAP_VALID ; + esw_attr->dests[flow->tmp_entry_index].pkt_reformat = e->pkt_reformat; + esw_attr->dests[flow->tmp_entry_index].flags |=MLX5_ESW_DEST_ENCAP_VALID ;/* Flow can be associated with multiple encap entries. * Before offloading the flow verify that all of them have * a valid neighbour.
@@ -161,7 +161,7 @@ void mlx5e_tc_encap_flows_del(struct mlx5e_priv *priv,/* update from encap rule to slow path rule */ rule =mlx5e_tc_offload_to_slow_path (esw, flow, spec);/* mark the flow's encap dest as non-valid */ - esw_attr->dests[flow->tmp_efi_index].flags &= ~MLX5_ESW_DEST_ENCAP_VALID ; + esw_attr->dests[flow->tmp_entry_index].flags &= ~MLX5_ESW_DEST_ENCAP_VALID ;if (IS_ERR (rule)) { err =PTR_ERR (rule);
@@ -195,7 +195,7 @@ void mlx5e_take_all_encap_flows(struct mlx5e_encap_entry *e, struct list_head *fcontinue ;wait_for_completion (&flow->init_done); - flow->tmp_efi_index = efi->index; + flow->tmp_entry_index = efi->index;list_add (&flow->tmp_list, flow_list); } }
@@ -294,7 +294,7 @@ void mlx5e_tc_update_neigh_used_value(struct mlx5e_neigh_hash_entry *nhe) }mutex_unlock (&esw->offloads.encap_tbl_lock); -mlx5e_put_encap_flow_list (priv, &flow_list); +mlx5e_put_flow_list (priv, &flow_list);if (neigh_used) {/* release current encap before breaking the loop */ mlx5e_encap_put (priv, e);
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +1 -1
@@ -1451,7 +1451,7 @@ struct mlx5_fc *mlx5e_tc_get_counter(struct mlx5e_tc_flow *flow) }/* Iterate over tmp_list of flows attached to flow_list head. */ -void mlx5e_put_encap_flow_list (struct mlx5e_priv *priv,struct list_head *flow_list) +void mlx5e_put_flow_list (struct mlx5e_priv *priv,struct list_head *flow_list) {struct mlx5e_tc_flow *flow, *tmp;
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +1 -1
@@ -174,7 +174,7 @@ bool mlx5e_encap_take(struct mlx5e_encap_entry *e);void mlx5e_encap_put (struct mlx5e_priv *priv,struct mlx5e_encap_entry *e);void mlx5e_take_all_encap_flows (struct mlx5e_encap_entry *e,struct list_head *flow_list); -void mlx5e_put_encap_flow_list (struct mlx5e_priv *priv,struct list_head *flow_list); +void mlx5e_put_flow_list (struct mlx5e_priv *priv,struct list_head *flow_list);struct mlx5e_neigh_hash_entry ;void mlx5e_tc_update_neigh_used_value (struct mlx5e_neigh_hash_entry *nhe);
Signature · 1 line
2.29.2
PATCH 17/17 net/mlx5e: Handle FIB events to update tunnel endpoint device
In reply to Saeed MahameedFrom: Vlad Buslov <[email protected]>
Process FIB route update events to dynamically update the stack device rules when tunnel routing changes. Use rtnl lock to prevent FIB event handler from running concurrently with neigh update and neigh stats workqueue tasks. Use encap_tbl_lock mutex to synchronize with TC rule update path that doesn't use rtnl lock.
FIB event workflow for encap flows:
- Unoffload all flows attached to route encaps from slow or fast path depending on encap destination endpoint neigh state.
- Update encap IP header according to new route dev.
- Update flows mod_hdr action that is responsible for overwriting reg_c0 source port bits to source port of new underlying VF of new route dev. This step requires changing flow create/delete code to save flow parse attribute mod_hdr_acts structure for whole flow lifetime instead of deallocating it after flow creation. Refactor mod_hdr code to allow saving id of individual mod_hdr actions and updating them with dedicated helper.
- Offload all flows to either slow or fast path depending on encap destination endpoint neigh state.
FIB event workflow for decap flows:
- Unoffload all route flows from hardware. When last route flow is deleted all indirect table rules for the route dev will also be deleted.
- Update flow attr decap_vport and destination MAC according to underlying VF of new rote dev.
- Offload all route flows back to hardware creating new indirect table rules according to updated flow attribute data.
Extract some neigh update code to helper functions to be used by both neigh update and route update infrastructure.
--- .../ethernet/mellanox/mlx5/core/en/tc_priv.h | 1 + .../mellanox/mlx5/core/en/tc_tun_encap.c | 751 +++++++++++++++++- .../mellanox/mlx5/core/en/tc_tun_encap.h | 3 + .../net/ethernet/mellanox/mlx5/core/en_rep.h | 6 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 76 +- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 1 - .../net/ethernet/mellanox/mlx5/core/eswitch.h | 2 +- 7 files changed, 773 insertions(+), 67 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h +1 -0
@@ -26,6 +26,7 @@ enum {MLX5E_TC_FLOW_FLAG_CT =MLX5E_TC_FLOW_BASE +7 ,MLX5E_TC_FLOW_FLAG_L3_TO_L2_DECAP =MLX5E_TC_FLOW_BASE +8 ,MLX5E_TC_FLOW_FLAG_TUN_RX =MLX5E_TC_FLOW_BASE +9 , + MLX5E_TC_FLOW_FLAG_FAILED = MLX5E_TC_FLOW_BASE + 10, }; struct mlx5e_tc_flow_parse_attr {
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +708 -43
934 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.h +3 -0
@@ -32,4 +32,7 @@ struct ip_tunnel_info *mlx5e_dup_tun_info(const struct ip_tunnel_info *tun_info)int mlx5e_tc_set_attr_rx_tun (struct mlx5e_tc_flow *flow,struct mlx5_flow_spec *spec); +struct mlx5e_tc_tun_encap *mlx5e_tc_tun_init (struct mlx5e_priv *priv); +void mlx5e_tc_tun_cleanup (struct mlx5e_tc_tun_encap *encap); +#endif /* __MLX5_EN_TC_TUN_ENCAP_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +6 -0
@@ -59,6 +59,8 @@ struct mlx5e_neigh_update_table {struct mlx5_tc_ct_priv ;struct mlx5e_rep_bond ; +struct mlx5e_tc_tun_encap ; +struct mlx5_rep_uplink_priv {/* Filters DB - instantiated by the uplink representor and shared by * the uplink's VFs
@@ -90,6 +92,9 @@ struct mlx5_rep_uplink_priv {/* support eswitch vports bonding */ struct mlx5e_rep_bond *bond; + +/* tc tunneling encapsulation private data */ +struct mlx5e_tc_tun_encap *encap; };struct mlx5e_rep_priv {
@@ -153,6 +158,7 @@ enum {/* set when the encap entry is successfully offloaded into HW */ MLX5_ENCAP_ENTRY_VALID =BIT (0 ),MLX5_REFORMAT_DECAP =BIT (1 ), + MLX5_ENCAP_ENTRY_NO_ROUTE = BIT(2), }; struct mlx5e_decap_key {
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +54 -22
187 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0 -1
@@ -1830,7 +1830,6 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)mutex_init (&esw->offloads.decap_tbl_lock);hash_init (esw->offloads.decap_tbl);mlx5e_mod_hdr_tbl_init (&esw->offloads.mod_hdr); -hash_init (esw->offloads.route_tbl);atomic64_set (&esw->offloads.num_flows,0 );ida_init (&esw->offloads.vport_metadata_ida);xa_init_flags (&esw->offloads.vhca_map,XA_FLAGS_ALLOC );
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +1 -1
@@ -214,7 +214,6 @@ struct mlx5_esw_offload {struct mutex peer_mutex;struct mutex encap_tbl_lock;/* protects encap_tbl */ DECLARE_HASHTABLE (encap_tbl,8 ); -DECLARE_HASHTABLE (route_tbl,8 );struct mutex decap_tbl_lock;/* protects decap_tbl */ DECLARE_HASHTABLE (decap_tbl,8 );struct mod_hdr_tbl mod_hdr;
@@ -424,6 +423,7 @@ struct mlx5_esw_flow_attr {struct mlx5_pkt_reformat *pkt_reformat;struct mlx5_core_dev *mdev;struct mlx5_termtbl_handle *termtbl; +int src_port_rewrite_act_id; } dests[MLX5_MAX_FLOW_FWD_VPORTS ];struct mlx5_rx_tun_attr *rx_tun_attr;struct mlx5_pkt_reformat *decap_pkt_reformat;
Signature · 1 line
2.29.2
Jakub Kicinski
maintainerQuoted 4 lines · On Thu, 4 Feb 2021 22:40:34 -0800 Saeed Mahameed wrote:
This series adds support for VF tunneling from Vlad, For more information please see tag log below.
Please pull and let me know if there is any problem.
Patch 2 and on do not build, could you investigate?
Quoted 7 lines · Jakub Kicinski
Quoted 4 lines · On Thu, 4 Feb 2021 22:40:34 -0800 Saeed Mahameed wrote:
This series adds support for VF tunneling from Vlad, For more information please see tag log below.
Please pull and let me know if there is any problem.
Patch 2 and on do not build, could you investigate?
I sent the wrong version (facepalm), Sorry, i had to rebase this series at the last minute and collect all the dependencies manually and eventually sent an older broken version.
sending V2.