mlx5 updates 2021-04-06
Subsystems (5)
From: Saeed Mahameed <[email protected]>
Hi Dave, Jakub,
This series From Chris adds the support for TC psample offloads to mlx5 driver.
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 0b35e0deb5bee7d4882356d6663522c1562a8321:
docs: ethtool: correct quotes (2021-04-06 16:56:58 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux.git tags/mlx5-updates-2021-04-06
for you to fetch changes up to f94d6389f6a8abd04760dcd015d14961260a8000:
net/mlx5e: TC, Add support to offload sample action (2021-04-06 21:36:05 -0700)
----------------------------------------------------------------
mlx5-updates-2021-04-06
Introduce TC sample offload
Background
----------
The tc sample action allows user to sample traffic matched by tc classifier. The sampling consists of choosing packets randomly and sampling them using psample module.
The tc sample parameters include group id, sampling rate and packet's truncation (to save kernel-user traffic).
Sample in TC SW
---------------
User must specify rate and group id for sample action, truncate is optional.
tc filter add dev enp4s0f0_0 ingress protocol ip prio 1 flower \
src_mac 02:25:d0:14:01:02 dst_mac 02:25:d0:14:01:03 \ action sample rate 10 group 5 trunc 60 \ action mirred egress redirect dev enp4s0f0_1
The tc sample action kernel module 'act_sample' will call another kernel module 'psample' to send sampled packets to userspace.
MLX5 sample HW offload - MLX5 driver patches
--------------------------------------------
The sample action is translated to a goto flow table object destination which samples packets according to the provided sample ratio. Sampled packets are duplicated. One copy is processed by a termination table, named the sample table, which sends the packet to the eswitch manager port (that will be processed by software).
The second copy is processed by the default table which executes the subsequent actions. The default table is created per <vport, chain, prio> tuple as rules with different prios and chains may overlap.
For example, for the following typical flow table:
+-------------------------------+ + original flow table + +-------------------------------+ + original match + +-------------------------------+
+ sample action + other actions +
+-------------------------------+
We translate the tc filter with sample action to the following HW model:
+---------------------+
+ original flow table +
+---------------------+
+ original match +
+---------------------+
|
v
+------------------------------------------------+
+ Flow Sampler Object +
+------------------------------------------------+
+ sample ratio +
+------------------------------------------------+
+ sample table id | default table id +
+------------------------------------------------+
| |
v v
+-----------------------------+ +----------------------------------------+
+ sample table + + default table per <vport, chain, prio> +
+-----------------------------+ +----------------------------------------+
+ forward to management vport + + original match +
+-----------------------------+ +----------------------------------------+
+ other actions +
+----------------------------------------+Flow sampler object
-------------------
Hardware introduces flow sampler object to do sample. It is a new destination type. Driver needs to specify two flow table ids in it. One is sample table id. The other one is the default table id. Sample table samples the packets according to the sample rate and forward the sampled packets to eswitch manager port. Default table finishes the subsequent actions.
Group id and reg_c0
-------------------
Userspace program will take different actions for sampled packets according to tc sample action group id. So hardware must pass group id to software for each sampled packets. In Paul Blakey's "Introduce connection tracking offload" patch set, reg_c0 lower 16 bits are used for miss packet chain id restore. We convert reg_c0 lower 16 bits to a common object pool, so other features can also use it.
Since sample group id is 32 bits, create a 16 bits object id to map the group id and write the object id to reg_c0 lower 16 bits. reg_c0 can only be used for matching. Write reg_c0 to flow_tag, so software can get the object id via flow_tag and find group id via the common object pool.
Sampler restore handle
----------------------
Use common object pool to create an object id to map sample parameters. Allocate a modify header action to write the object id to reg_c0 lower 16 bits. Create a restore rule to pass the object id to software. So software can identify sampled packets via the object id and send it to userspace.
Aggregate the modify header action, restore rule and object id to a sample restore handle. Re-use identical sample restore handle for the same object id.
Send sampled packets to userspace
---------------------------------
The destination for sampled packets is eswitch manager port, so representors can receive sampled packets together with the group id. Driver will send sampled packets and group id to userspace via psample.
----------------------------------------------------------------
Chris Mi (13):
net/mlx5: E-switch, Move vport table functions to a new file net/mlx5: E-switch, Rename functions to follow naming convention. net/mlx5: E-switch, Generalize per vport table API net/mlx5: E-switch, Set per vport table default group number net/mlx5: Map register values to restore objects net/mlx5: Instantiate separate mapping objects for FDB and NIC tables net/mlx5e: TC, Parse sample action
net/mlx5e: TC, Add sampler termination table API net/mlx5e: TC, Add sampler object API
net/mlx5e: TC, Add sampler restore handle API
net/mlx5e: TC, Refactor tc update skb function
net/mlx5e: TC, Handle sampled packets
net/mlx5e: TC, Add support to offload sample action
drivers/net/ethernet/mellanox/mlx5/core/Kconfig | 12 + drivers/net/ethernet/mellanox/mlx5/core/Makefile | 8 +- drivers/net/ethernet/mellanox/mlx5/core/en/fs.h | 1 + .../net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 77 ++- .../net/ethernet/mellanox/mlx5/core/en/tc_priv.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_rep.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 95 +++- .../net/ethernet/mellanox/mlx5/core/esw/sample.c | 585 +++++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/esw/sample.h | 42 ++ .../net/ethernet/mellanox/mlx5/core/esw/vporttbl.c | 140 +++++ drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 45 +- .../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 310 ++++------- .../ethernet/mellanox/mlx5/core/lib/fs_chains.c | 52 +- .../ethernet/mellanox/mlx5/core/lib/fs_chains.h | 6 +- include/linux/mlx5/eswitch.h | 9 +- 15 files changed, 1101 insertions(+), 283 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/vporttbl.c
PATCH 1/13 net/mlx5: E-switch, Move vport table functions to a new file
From: Chris Mi <[email protected]>
Currently, the vport table functions are in common eswitch offload file. This file is too big. Move the vport table create, delete and lookup functions to a separate file. Put the file in esw directory.
Pre-step for generalizing its functionality for serving both the mirroring and the sample features.
--- .../net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../mellanox/mlx5/core/esw/vporttbl.c | 136 +++++++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 12 +- .../mellanox/mlx5/core/eswitch_offloads.c | 215 +++--------------- 4 files changed, 183 insertions(+), 182 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/vporttbl.c
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
@@ -53,7 +53,7 @@ mlx5_core-$(CONFIG_MLX5_ESWITCH) += eswitch.o eswitch_offloads.o eswitch_offlo mlx5_core-$(CONFIG_MLX5_ESWITCH) += esw/acl/helper.o \ esw/acl/egress_lgcy.o esw/acl/egress_ofld.o \ esw/acl/ingress_lgcy.o esw/acl/ingress_ofld.o \ - esw/devlink_port.o + esw/devlink_port.o esw/vporttbl.o mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o mlx5_core-$(CONFIG_VXLAN) += lib/vxlan.o
drivers/net/ethernet/mellanox/mlx5/core/esw/vporttbl.c new file +136 -0
136 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +10 -2
@@ -713,8 +713,16 @@ void esw_vport_destroy_offloads_acl_tables(struct mlx5_eswitch *esw, struct mlx5_vport *vport); -int mlx5_esw_vport_tbl_get (struct mlx5_eswitch *esw); -void mlx5_esw_vport_tbl_put (struct mlx5_eswitch *esw); +struct mlx5_vport_tbl_attr { +u16 chain; +u16 prio; +u16 vport; +}; + +struct mlx5_flow_table * +esw_vport_tbl_get (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr); +void +esw_vport_tbl_put (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr);struct mlx5_flow_handle *esw_add_restore_rule (struct mlx5_eswitch *esw,u32 tag);
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +36 -179
227 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH 2/13 net/mlx5: E-switch, Rename functions to follow naming convention.
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Public api starts with mlx5 and remove mlx5 for non-public api.
--- .../mellanox/mlx5/core/esw/vporttbl.c | 4 +-- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 4 +-- .../mellanox/mlx5/core/eswitch_offloads.c | 26 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/vporttbl.c +2 -2
@@ -66,7 +66,7 @@ esw_vport_tbl_lookup(struct mlx5_eswitch *esw, struct mlx5_vport_key *skey, u32 }struct mlx5_flow_table * -esw_vport_tbl_get (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr) +mlx5_esw_vporttbl_get (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr) {struct mlx5_core_dev *dev = esw->dev;struct mlx5_flow_namespace *ns;
@@ -116,7 +116,7 @@ esw_vport_tbl_get(struct mlx5_eswitch *esw, struct mlx5_vport_tbl_attr *attr) }void -esw_vport_tbl_put (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr) +mlx5_esw_vporttbl_put (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr) {struct mlx5_vport_table *e;struct mlx5_vport_key key;
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +2 -2
@@ -720,9 +720,9 @@ struct mlx5_vport_tbl_attr { };struct mlx5_flow_table * -esw_vport_tbl_get (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr); +mlx5_esw_vporttbl_get (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr);void -esw_vport_tbl_put (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr); +mlx5_esw_vporttbl_put (struct mlx5_eswitch *esw,struct mlx5_vport_tbl_attr *attr);struct mlx5_flow_handle *esw_add_restore_rule (struct mlx5_eswitch *esw,u32 tag);
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +13 -13
@@ -483,7 +483,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, fwd_attr.prio = attr->prio; fwd_attr.vport = esw_attr->in_rep->vport; - fdb =esw_vport_tbl_get (esw, &fwd_attr); + fdb =mlx5_esw_vporttbl_get (esw, &fwd_attr); }else {if (attr->chain || attr->prio) fdb = mlx5_chains_get_table(chains, attr->chain,
@@ -515,7 +515,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, err_add_rule:if (split) -esw_vport_tbl_put (esw, &fwd_attr); +mlx5_esw_vporttbl_put (esw, &fwd_attr);else if (attr->chain || attr->prio)mlx5_chains_put_table (chains, attr->chain, attr->prio,0 ); err_esw_get:
@@ -548,7 +548,7 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw, fwd_attr.chain = attr->chain; fwd_attr.prio = attr->prio; fwd_attr.vport = esw_attr->in_rep->vport; - fwd_fdb =esw_vport_tbl_get (esw, &fwd_attr); + fwd_fdb =mlx5_esw_vporttbl_get (esw, &fwd_attr);if (IS_ERR (fwd_fdb)) { rule =ERR_CAST (fwd_fdb); goto err_get_fwd;
@@ -593,7 +593,7 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw,return rule; err_chain_src_rewrite:esw_put_dest_tables_loop (esw, attr,0 , i); -esw_vport_tbl_put (esw, &fwd_attr); +mlx5_esw_vporttbl_put (esw, &fwd_attr); err_get_fwd:mlx5_chains_put_table (chains, attr->chain, attr->prio,0 ); err_get_fast:
@@ -631,12 +631,12 @@ __mlx5_eswitch_del_rule(struct mlx5_eswitch *esw, }if (fwd_rule) { -esw_vport_tbl_put (esw, &fwd_attr); +mlx5_esw_vporttbl_put (esw, &fwd_attr);mlx5_chains_put_table (chains, attr->chain, attr->prio,0 );esw_put_dest_tables_loop (esw, attr,0 , esw_attr->split_count); }else {if (split) -esw_vport_tbl_put (esw, &fwd_attr); +mlx5_esw_vporttbl_put (esw, &fwd_attr);else if (attr->chain || attr->prio)mlx5_chains_put_table (chains, attr->chain, attr->prio,0 );esw_cleanup_dests (esw, attr);
@@ -1335,7 +1335,7 @@ static void esw_set_flow_group_source_port(struct mlx5_eswitch *esw, }#if IS_ENABLED (CONFIG_MLX5_CLS_ACT ) -static void mlx5_esw_vport_tbl_put (struct mlx5_eswitch *esw) +static void esw_vport_tbl_put (struct mlx5_eswitch *esw) {struct mlx5_vport_tbl_attr attr;struct mlx5_vport *vport;
@@ -1345,11 +1345,11 @@ static void mlx5_esw_vport_tbl_put(struct mlx5_eswitch *esw) attr.prio =1 ; mlx5_esw_for_all_vports(esw, i, vport) { attr.vport = vport->vport; -esw_vport_tbl_put (esw, &attr); +mlx5_esw_vporttbl_put (esw, &attr); } } -static int mlx5_esw_vport_tbl_get (struct mlx5_eswitch *esw) +static int esw_vport_tbl_get (struct mlx5_eswitch *esw) {struct mlx5_vport_tbl_attr attr;struct mlx5_flow_table *fdb;
@@ -1360,14 +1360,14 @@ static int mlx5_esw_vport_tbl_get(struct mlx5_eswitch *esw) attr.prio =1 ; mlx5_esw_for_all_vports(esw, i, vport) { attr.vport = vport->vport; - fdb =esw_vport_tbl_get (esw, &attr); + fdb =mlx5_esw_vporttbl_get (esw, &attr);if (IS_ERR (fdb)) goto out; }return 0 ; out: -mlx5_esw_vport_tbl_put (esw); +esw_vport_tbl_put (esw);return PTR_ERR (fdb); }
@@ -1448,7 +1448,7 @@ esw_chains_create(struct mlx5_eswitch *esw, struct mlx5_flow_table *miss_fdb)/* Open level 1 for split fdb rules now if prios isn't supported */ if (!mlx5_chains_prios_supported (chains)) { - err =mlx5_esw_vport_tbl_get (esw); + err =esw_vport_tbl_get (esw);if (err) goto level_1_err; }
@@ -1472,7 +1472,7 @@ static void esw_chains_destroy(struct mlx5_eswitch *esw, struct mlx5_fs_chains *chains) {if (!mlx5_chains_prios_supported (chains)) -mlx5_esw_vport_tbl_put (esw); +esw_vport_tbl_put (esw);mlx5_chains_put_table (chains,0 ,1 ,0 );mlx5_chains_put_table (chains,mlx5_chains_get_nf_ft_chain (chains),1 ,0 );mlx5_chains_destroy (chains);
Signature · 1 line
2.30.2
PATCH 3/13 net/mlx5: E-switch, Generalize per vport table API
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Currently, per vport table was used only for port mirroring actions. However, sample action will also require a per vport table instance.
Generalize the vport table API to work with multiple namespaces where each namespace manages its own vport table instance.
--- .../ethernet/mellanox/mlx5/core/esw/vporttbl.c | 15 ++++++++------- drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 7 +++++++ .../mellanox/mlx5/core/eswitch_offloads.c | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/vporttbl.c +8 -7
@@ -3,9 +3,6 @@#include "eswitch.h" -#define MLX5_ESW_VPORT_TABLE_SIZE 128 -#define MLX5_ESW_VPORT_TBL_NUM_GROUPS 4 -/* This struct is used as a key to the hash table and we need it to be packed * so hash result is consistent */
@@ -14,6 +11,7 @@ struct mlx5_vport_key {u16 prio;u16 vport;u16 vhca_id; +const struct esw_vport_tbl_namespace *vport_ns; } __packed;struct mlx5_vport_table {
@@ -24,14 +22,16 @@ struct mlx5_vport_table { };static struct mlx5_flow_table * -esw_vport_tbl_create (struct mlx5_eswitch *esw,struct mlx5_flow_namespace *ns) +esw_vport_tbl_create (struct mlx5_eswitch *esw,struct mlx5_flow_namespace *ns, +const struct esw_vport_tbl_namespace *vport_ns) {struct mlx5_flow_table_attr ft_attr = {};struct mlx5_flow_table *fdb; - ft_attr.autogroup.max_num_groups =MLX5_ESW_VPORT_TBL_NUM_GROUPS ; - ft_attr.max_fte =MLX5_ESW_VPORT_TABLE_SIZE ; + ft_attr.autogroup.max_num_groups = vport_ns->max_num_groups; + ft_attr.max_fte = vport_ns->max_fte; ft_attr.prio =FDB_PER_VPORT ; + ft_attr.flags = vport_ns->flags; fdb =mlx5_create_auto_grouped_flow_table (ns, &ft_attr);if (IS_ERR (fdb)) { esw_warn(esw->dev, "Failed to create per vport FDB Table err %ld\n",
@@ -49,6 +49,7 @@ static u32 flow_attr_to_vport_key(struct mlx5_eswitch *esw, key->chain = attr->chain; key->prio = attr->prio; key->vhca_id =MLX5_CAP_GEN (esw->dev, vhca_id); + key->vport_ns = attr->vport_ns;return jhash (key,sizeof (*key),0 ); }
@@ -96,7 +97,7 @@ mlx5_esw_vporttbl_get(struct mlx5_eswitch *esw, struct mlx5_vport_tbl_attr *attr goto err_ns; } - fdb =esw_vport_tbl_create (esw, ns); + fdb =esw_vport_tbl_create (esw, ns, attr->vport_ns);if (IS_ERR (fdb)) goto err_ns;
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +7 -0
@@ -713,10 +713,17 @@ void esw_vport_destroy_offloads_acl_tables(struct mlx5_eswitch *esw, struct mlx5_vport *vport); +struct esw_vport_tbl_namespace { +int max_fte; +int max_num_groups; +u32 flags; +}; +struct mlx5_vport_tbl_attr {u16 chain;u16 prio;u16 vport; +const struct esw_vport_tbl_namespace *vport_ns; }; struct mlx5_flow_table *
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +14 -0
@@ -54,6 +54,15 @@#define MLX5_ESW_MISS_FLOWS (2)#define UPLINK_REP_INDEX 0 +#define MLX5_ESW_VPORT_TBL_SIZE 128 +#define MLX5_ESW_VPORT_TBL_NUM_GROUPS 4 + +static const struct esw_vport_tbl_namespace mlx5_esw_vport_tbl_mirror_ns = { + .max_fte =MLX5_ESW_VPORT_TBL_SIZE , + .max_num_groups =MLX5_ESW_VPORT_TBL_NUM_GROUPS , + .flags =0 , +}; +static struct mlx5_eswitch_rep *mlx5_eswitch_get_rep (struct mlx5_eswitch *esw,u16 vport_num) {
@@ -482,6 +491,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, fwd_attr.chain = attr->chain; fwd_attr.prio = attr->prio; fwd_attr.vport = esw_attr->in_rep->vport; + fwd_attr.vport_ns = &mlx5_esw_vport_tbl_mirror_ns; fdb =mlx5_esw_vporttbl_get (esw, &fwd_attr); }else {
@@ -548,6 +558,7 @@ mlx5_eswitch_add_fwd_rule(struct mlx5_eswitch *esw, fwd_attr.chain = attr->chain; fwd_attr.prio = attr->prio; fwd_attr.vport = esw_attr->in_rep->vport; + fwd_attr.vport_ns = &mlx5_esw_vport_tbl_mirror_ns; fwd_fdb =mlx5_esw_vporttbl_get (esw, &fwd_attr);if (IS_ERR (fwd_fdb)) { rule =ERR_CAST (fwd_fdb);
@@ -628,6 +639,7 @@ __mlx5_eswitch_del_rule(struct mlx5_eswitch *esw, fwd_attr.chain = attr->chain; fwd_attr.prio = attr->prio; fwd_attr.vport = esw_attr->in_rep->vport; + fwd_attr.vport_ns = &mlx5_esw_vport_tbl_mirror_ns; }if (fwd_rule) {
@@ -1345,6 +1357,7 @@ static void esw_vport_tbl_put(struct mlx5_eswitch *esw) attr.prio =1 ; mlx5_esw_for_all_vports(esw, i, vport) { attr.vport = vport->vport; + attr.vport_ns = &mlx5_esw_vport_tbl_mirror_ns;mlx5_esw_vporttbl_put (esw, &attr); } }
@@ -1360,6 +1373,7 @@ static int esw_vport_tbl_get(struct mlx5_eswitch *esw) attr.prio =1 ; mlx5_esw_for_all_vports(esw, i, vport) { attr.vport = vport->vport; + attr.vport_ns = &mlx5_esw_vport_tbl_mirror_ns; fdb =mlx5_esw_vporttbl_get (esw, &attr);if (IS_ERR (fdb)) goto out;
Signature · 1 line
2.30.2
PATCH 4/13 net/mlx5: E-switch, Set per vport table default group number
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Different per voprt table is created using a different per vport table namespace. Because we can't use variable to set the namespace member value. If max group number is 0 in the namespace, use the eswitch default max group number.
--- drivers/net/ethernet/mellanox/mlx5/core/esw/vporttbl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/vporttbl.c +4 -1
@@ -28,7 +28,10 @@ esw_vport_tbl_create(struct mlx5_eswitch *esw, struct mlx5_flow_namespace *ns,struct mlx5_flow_table_attr ft_attr = {};struct mlx5_flow_table *fdb; - ft_attr.autogroup.max_num_groups = vport_ns->max_num_groups; +if (vport_ns->max_num_groups) + ft_attr.autogroup.max_num_groups = vport_ns->max_num_groups; +else + ft_attr.autogroup.max_num_groups = esw->params.large_group_num; ft_attr.max_fte = vport_ns->max_fte; ft_attr.prio =FDB_PER_VPORT ; ft_attr.flags = vport_ns->flags;
Signature · 1 line
2.30.2
PATCH 5/13 net/mlx5: Map register values to restore objects
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Currently reg_c0 lower 16 bits and reg_b are used to store the chain id that missed in FDB and NIC tables accordingly. However, the registers' values may index a restore object, rather than a single u32 value. Different object types can be used to restore mutually exclusive contexts such as chain id and sample group id.
Use the mapping object to associate an index with a restore object as a prestep for supporting additional restore types.
--- .../ethernet/mellanox/mlx5/core/en/rep/tc.c | 38 +++++++++++-------- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 9 ++++- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 13 ++++++- .../mellanox/mlx5/core/eswitch_offloads.c | 14 ++----- .../mellanox/mlx5/core/lib/fs_chains.c | 20 ++++++---- .../mellanox/mlx5/core/lib/fs_chains.h | 3 +- include/linux/mlx5/eswitch.h | 9 ++--- 7 files changed, 63 insertions(+), 43 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +22 -16
@@ -618,9 +618,10 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, struct mlx5e_tc_update_priv *tc_priv) {#if IS_ENABLED (CONFIG_NET_TC_SKB_EXT ) -u32 chain =0 , reg_c0, reg_c1, tunnel_id, zone_restore_id; +u32 reg_c0, reg_c1, tunnel_id, zone_restore_id;struct mlx5_rep_uplink_priv *uplink_priv;struct mlx5e_rep_priv *uplink_rpriv; +struct mlx5_mapped_obj mapped_obj;struct tc_skb_ext *tc_skb_ext;struct mlx5_eswitch *esw;struct mlx5e_priv *priv;
@@ -640,30 +641,35 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, priv =netdev_priv (skb->dev); esw = priv->mdev->priv.eswitch; - err =mlx5_get_chain_for_tag (esw_chains (esw), reg_c0, &chain); + err =mlx5_get_mapped_object (esw_chains (esw), reg_c0, &mapped_obj);if (err) {netdev_dbg (priv->netdev, -"Couldn't find chain for chain tag: %d, err: %d\n" , +"Couldn't find mapped object for reg_c0: %d, err: %d\n" , reg_c0, err);return false; } -if (chain) { - tc_skb_ext =skb_ext_add (skb,TC_SKB_EXT ); -if (!tc_skb_ext) { -WARN_ON (1 ); -return false; - } +if (mapped_obj.type ==MLX5_MAPPED_OBJ_CHAIN ) { +if (mapped_obj.chain) { + tc_skb_ext =skb_ext_add (skb,TC_SKB_EXT ); +if (!tc_skb_ext) { +WARN_ON (1 ); +return false; + } - tc_skb_ext->chain = chain; + tc_skb_ext->chain = mapped_obj.chain; - zone_restore_id = reg_c1 &ESW_ZONE_ID_MASK ; + 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; -if (!mlx5e_tc_ct_restore_flow (uplink_priv->ct_priv, skb, - zone_restore_id)) -return false; + uplink_rpriv =mlx5_eswitch_get_uplink_priv (esw,REP_ETH ); + uplink_priv = &uplink_rpriv->uplink_priv; +if (!mlx5e_tc_ct_restore_flow (uplink_priv->ct_priv, skb, + zone_restore_id)) +return false; + } + }else { +netdev_dbg (priv->netdev,"Invalid mapped object type: %d\n" , mapped_obj.type); +return false; } tunnel_id = reg_c1 >>ESW_TUN_OFFSET ;
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +7 -2
@@ -4973,6 +4973,7 @@ bool mlx5e_tc_update_skb(struct mlx5_cqe64 *cqe,u32 chain =0 , chain_tag, reg_b, zone_restore_id;struct mlx5e_priv *priv =netdev_priv (skb->dev);struct mlx5e_tc_table *tc = &priv->fs.tc; +struct mlx5_mapped_obj mapped_obj;struct tc_skb_ext *tc_skb_ext;int err;
@@ -4980,7 +4981,7 @@ bool mlx5e_tc_update_skb(struct mlx5_cqe64 *cqe, chain_tag = reg_b &MLX5E_TC_TABLE_CHAIN_TAG_MASK ; - err =mlx5_get_chain_for_tag (nic_chains (priv), chain_tag, &chain); + err =mlx5_get_mapped_object (nic_chains (priv), chain_tag, &mapped_obj);if (err) { netdev_dbg(priv->netdev, "Couldn't find chain for chain tag: %d, err: %d\n",
@@ -4988,7 +4989,8 @@ bool mlx5e_tc_update_skb(struct mlx5_cqe64 *cqe,return false; } -if (chain) { +if (mapped_obj.type ==MLX5_MAPPED_OBJ_CHAIN ) { + chain = mapped_obj.chain; tc_skb_ext =skb_ext_add (skb,TC_SKB_EXT );if (WARN_ON (!tc_skb_ext))return false;
@@ -5001,6 +5003,9 @@ bool mlx5e_tc_update_skb(struct mlx5_cqe64 *cqe,if (!mlx5e_tc_ct_restore_flow (tc->ct, skb, zone_restore_id)) return false; + }else { +netdev_dbg (priv->netdev,"Invalid mapped object type: %d\n" , mapped_obj.type); +return false; }#endif /* CONFIG_NET_TC_SKB_EXT */
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +11 -2
@@ -47,6 +47,17 @@#include "sf/sf.h" #include "en/tc_ct.h" +enum mlx5_mapped_obj_type { +MLX5_MAPPED_OBJ_CHAIN , +}; + +struct mlx5_mapped_obj { +enum mlx5_mapped_obj_type type; +union { +u32 chain; + }; +}; +#ifdef CONFIG_MLX5_ESWITCH #define ESW_OFFLOADS_DEFAULT_NUM_GROUPS 15
@@ -733,8 +744,6 @@ mlx5_esw_vporttbl_put(struct mlx5_eswitch *esw, struct mlx5_vport_tbl_attr *attrstruct mlx5_flow_handle *esw_add_restore_rule (struct mlx5_eswitch *esw,u32 tag); -u32 -esw_get_max_restore_tag (struct mlx5_eswitch *esw);int esw_offloads_load_rep (struct mlx5_eswitch *esw,u16 vport_num);void esw_offloads_unload_rep (struct mlx5_eswitch *esw,u16 vport_num);
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +4 -10
@@ -1286,7 +1286,7 @@ esw_add_restore_rule(struct mlx5_eswitch *esw, u32 tag) misc =MLX5_ADDR_OF (fte_match_param, spec->match_criteria, misc_parameters_2);MLX5_SET (fte_match_set_misc2, misc, metadata_reg_c_0, -ESW_CHAIN_TAG_METADATA_MASK ); +ESW_REG_C0_USER_DATA_METADATA_MASK ); misc =MLX5_ADDR_OF (fte_match_param, spec->match_value, misc_parameters_2);MLX5_SET (fte_match_set_misc2, misc, metadata_reg_c_0, tag);
@@ -1312,12 +1312,6 @@ esw_add_restore_rule(struct mlx5_eswitch *esw, u32 tag)return flow_rule; } -u32 -esw_get_max_restore_tag (struct mlx5_eswitch *esw) -{ -return ESW_CHAIN_TAG_METADATA_MASK ; -} -#define MAX_PF_SQ 256#define MAX_SQ_NVPORTS 32
@@ -1434,7 +1428,7 @@ esw_chains_create(struct mlx5_eswitch *esw, struct mlx5_flow_table *miss_fdb) attr.max_ft_sz = fdb_max; attr.max_grp_num = esw->params.large_group_num; attr.default_ft = miss_fdb; - attr.max_restore_tag =esw_get_max_restore_tag (esw); + attr.max_restore_tag =ESW_REG_C0_USER_DATA_METADATA_MASK ; chains =mlx5_chains_create (dev, &attr);if (IS_ERR (chains)) {
@@ -1928,7 +1922,7 @@ static int esw_create_restore_table(struct mlx5_eswitch *esw) goto out_free; } - ft_attr.max_fte =1 <<ESW_CHAIN_TAG_METADATA_BITS ; + ft_attr.max_fte =1 <<ESW_REG_C0_USER_DATA_METADATA_BITS ; ft =mlx5_create_flow_table (ns, &ft_attr);if (IS_ERR (ft)) { err =PTR_ERR (ft);
@@ -1943,7 +1937,7 @@ static int esw_create_restore_table(struct mlx5_eswitch *esw) misc_parameters_2);MLX5_SET (fte_match_set_misc2, misc, metadata_reg_c_0, -ESW_CHAIN_TAG_METADATA_MASK ); +ESW_REG_C0_USER_DATA_METADATA_MASK );MLX5_SET (create_flow_group_in, flow_group_in, start_flow_index,0 );MLX5_SET (create_flow_group_in, flow_group_in, end_flow_index, ft_attr.max_fte -1 );
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_chains.c +13 -7
@@ -832,8 +832,7 @@ mlx5_chains_init(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr)if (err) goto init_prios_ht_err; - mapping =mapping_create (sizeof (u32), attr->max_restore_tag, - true); + mapping =mapping_create (sizeof (struct mlx5_mapped_obj ), attr->max_restore_tag, true);if (IS_ERR (mapping)) { err =PTR_ERR (mapping); goto mapping_err;
@@ -884,21 +883,28 @@ int mlx5_chains_get_chain_mapping(struct mlx5_fs_chains *chains, u32 chain, u32 *chain_mapping) { - return mapping_add(chains_mapping(chains), &chain, chain_mapping); + struct mapping_ctx *ctx = chains->chains_mapping; +struct mlx5_mapped_obj mapped_obj = {}; + + mapped_obj.type =MLX5_MAPPED_OBJ_CHAIN ; + mapped_obj.chain = chain; +return mapping_add (ctx, &mapped_obj, chain_mapping); }int mlx5_chains_put_chain_mapping (struct mlx5_fs_chains *chains,u32 chain_mapping) { -return mapping_remove (chains_mapping (chains), chain_mapping); +struct mapping_ctx *ctx = chains->chains_mapping; + +return mapping_remove (ctx, chain_mapping); } -int mlx5_get_chain_for_tag (struct mlx5_fs_chains *chains,u32 tag, -u32 *chain) +int +mlx5_get_mapped_object (struct mlx5_fs_chains *chains,u32 tag,struct mlx5_mapped_obj *obj) {int err; - err =mapping_find (chains_mapping (chains), tag, chain); + err =mapping_find (chains->chains_mapping, tag, obj);if (err) {mlx5_core_warn (chains->dev,"Can't find chain for tag: %d\n" , tag);return -ENOENT ;
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_chains.h +2 -1
@@ -7,6 +7,7 @@#include <linux/mlx5/fs.h> struct mlx5_fs_chains ; +struct mlx5_mapped_obj ;enum mlx5_chains_flags {MLX5_CHAINS_AND_PRIOS_SUPPORTED =BIT (0 ),
@@ -64,7 +65,7 @@ mlx5_chains_create(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr);void mlx5_chains_destroy (struct mlx5_fs_chains *chains);int -mlx5_get_chain_for_tag (struct mlx5_fs_chains *chains,u32 tag,u32 *chain); +mlx5_get_mapped_object (struct mlx5_fs_chains *chains,u32 tag,struct mlx5_mapped_obj *obj); void mlx5_chains_set_end_ft(struct mlx5_fs_chains *chains,
include/linux/mlx5/eswitch.h +4 -5
@@ -74,20 +74,19 @@ bool mlx5_eswitch_reg_c1_loopback_enabled(const struct mlx5_eswitch *esw);bool mlx5_eswitch_vport_match_metadata_enabled (const struct mlx5_eswitch *esw);/* Reg C0 usage: -* Reg C0 = < ESW_PFNUM_BITS(4) | ESW_VPORT BITS(12) | ESW_CHAIN_TAG(16) > +* Reg C0 = < ESW_PFNUM_BITS(4) | ESW_VPORT BITS(12) | ESW_REG_C0_OBJ(16) > * * Highest 4 bits of the reg c0 is the PF_NUM (range 0-15), 12 bits of * unique non-zero vport id (range 1-4095). The rest (lowest 16 bits) is left -* for tc chain tag restoration. +* for user data objects managed by a common mapping context. * PFNUM + VPORT comprise the SOURCE_PORT matching. */ #define ESW_VPORT_BITS 12#define ESW_PFNUM_BITS 4#define ESW_SOURCE_PORT_METADATA_BITS (ESW_PFNUM_BITS + ESW_VPORT_BITS)#define ESW_SOURCE_PORT_METADATA_OFFSET (32 - ESW_SOURCE_PORT_METADATA_BITS) -#define ESW_CHAIN_TAG_METADATA_BITS (32 - ESW_SOURCE_PORT_METADATA_BITS) -#define ESW_CHAIN_TAG_METADATA_MASK GENMASK(ESW_CHAIN_TAG_METADATA_BITS - 1,\ - 0) +#define ESW_REG_C0_USER_DATA_METADATA_BITS (32 - ESW_SOURCE_PORT_METADATA_BITS) +#define ESW_REG_C0_USER_DATA_METADATA_MASK GENMASK(ESW_REG_C0_USER_DATA_METADATA_BITS - 1, 0)static inline u32 mlx5_eswitch_get_vport_metadata_mask (void ) {
Signature · 1 line
2.30.2
PATCH 6/13 net/mlx5: Instantiate separate mapping objects for FDB and NIC tables
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Currently, the u32 chain id is mapped to u16 value which is stored on the lower 16 bits of reg_c0 for FDB and reg_b for NIC tables. The mapping is internally maintained by the chains object. However, with the introduction of reg_c0 objects the fdb may store more than just the chain id on reg_c0. This is not relevant for NIC tables.
Separate the chains mapping instantiation for FDB and NIC tables. Remove the mapping from the chains object. For FDB tables, create the mapping per eswitch. For NIC tables, create the mapping per tc table. Pass the corresponding mapping pointer when creating the chains object.
--- .../net/ethernet/mellanox/mlx5/core/Makefile | 5 ++- .../net/ethernet/mellanox/mlx5/core/en/fs.h | 1 + .../ethernet/mellanox/mlx5/core/en/rep/tc.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 19 +++++++-- .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + .../mellanox/mlx5/core/eswitch_offloads.c | 16 ++++++- .../mellanox/mlx5/core/lib/fs_chains.c | 42 +++---------------- .../mellanox/mlx5/core/lib/fs_chains.h | 5 +-- 8 files changed, 43 insertions(+), 48 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/Makefile +3 -2
@@ -37,9 +37,10 @@ mlx5_core-$(CONFIG_MLX5_EN_RXNFC) += en_fs_ethtool.o mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o en/port_buffer.o mlx5_core-$(CONFIG_PCI_HYPERV_INTERFACE) += en/hv_vhca_stats.o 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 + en_rep.o en/rep/bond.o en/mod_hdr.o \ + en/mapping.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 \ + lib/fs_chains.o en/tc_tun.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
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +1 -0
@@ -29,6 +29,7 @@ struct mlx5e_tc_table {struct netdev_net_notifier netdevice_nn;struct mlx5_tc_ct_priv *ct; +struct mapping_ctx *mapping; };struct mlx5e_flow_table {
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +1 -1
@@ -641,7 +641,7 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, priv =netdev_priv (skb->dev); esw = priv->mdev->priv.eswitch; - err =mlx5_get_mapped_object (esw_chains (esw), reg_c0, &mapped_obj); + err =mapping_find (esw->offloads.reg_c0_obj_pool, reg_c0, &mapped_obj);if (err) { netdev_dbg(priv->netdev, "Couldn't find mapped object for reg_c0: %d, err: %d\n",
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +15 -4
@@ -4731,6 +4731,7 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv) {struct mlx5e_tc_table *tc = &priv->fs.tc;struct mlx5_core_dev *dev = priv->mdev; +struct mapping_ctx *chains_mapping;struct mlx5_chains_attr attr = {};int err;
@@ -4745,15 +4746,22 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)lockdep_set_class (&tc->ht.mutex, &tc_ht_lock_key); -if (MLX5_CAP_FLOWTABLE_NIC_RX (priv->mdev, ignore_flow_level)) { + chains_mapping =mapping_create (sizeof (struct mlx5_mapped_obj ), +MLX5E_TC_TABLE_CHAIN_TAG_MASK , true); +if (IS_ERR (chains_mapping)) { + err =PTR_ERR (chains_mapping); + goto err_mapping; + } + tc->mapping = chains_mapping; + +if (MLX5_CAP_FLOWTABLE_NIC_RX (priv->mdev, ignore_flow_level)) attr.flags =MLX5_CHAINS_AND_PRIOS_SUPPORTED |MLX5_CHAINS_IGNORE_FLOW_LEVEL_SUPPORTED ; - attr.max_restore_tag =MLX5E_TC_TABLE_CHAIN_TAG_MASK ; - } attr.ns =MLX5_FLOW_NAMESPACE_KERNEL ; attr.max_ft_sz =mlx5e_tc_nic_get_ft_size (dev); attr.max_grp_num =MLX5E_TC_TABLE_NUM_GROUPS ; attr.default_ft =mlx5e_vlan_get_flowtable (priv->fs.vlan); + attr.mapping = chains_mapping; tc->chains =mlx5_chains_create (dev, &attr);if (IS_ERR (tc->chains)) {
@@ -4780,6 +4788,8 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)mlx5_tc_ct_clean (tc->ct);mlx5_chains_destroy (tc->chains); err_chains: +mapping_destroy (chains_mapping); +err_mapping:rhashtable_destroy (&tc->ht);return err; }
@@ -4814,6 +4824,7 @@ void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv)mutex_destroy (&tc->t_lock);mlx5_tc_ct_clean (tc->ct); +mapping_destroy (tc->mapping);mlx5_chains_destroy (tc->chains); }
@@ -4981,7 +4992,7 @@ bool mlx5e_tc_update_skb(struct mlx5_cqe64 *cqe, chain_tag = reg_b &MLX5E_TC_TABLE_CHAIN_TAG_MASK ; - err =mlx5_get_mapped_object (nic_chains (priv), chain_tag, &mapped_obj); + err =mapping_find (tc->mapping, chain_tag, &mapped_obj);if (err) { netdev_dbg(priv->netdev, "Couldn't find chain for chain tag: %d, err: %d\n",
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +1 -0
@@ -217,6 +217,7 @@ struct mlx5_esw_offload {struct mlx5_flow_table *ft_offloads_restore;struct mlx5_flow_group *restore_group;struct mlx5_modify_hdr *restore_copy_hdr_id; +struct mapping_ctx *reg_c0_obj_pool;struct mlx5_flow_table *ft_offloads;struct mlx5_flow_group *vport_rx_group;
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +15 -1
@@ -47,6 +47,7 @@#include "lib/eq.h" #include "lib/fs_chains.h" #include "en_tc.h" +#include "en/mapping.h" /* There are two match-all miss flows, one for unicast dst mac and * one for multicast.
@@ -1428,7 +1429,7 @@ esw_chains_create(struct mlx5_eswitch *esw, struct mlx5_flow_table *miss_fdb) attr.max_ft_sz = fdb_max; attr.max_grp_num = esw->params.large_group_num; attr.default_ft = miss_fdb; - attr.max_restore_tag =ESW_REG_C0_USER_DATA_METADATA_MASK ; + attr.mapping = esw->offloads.reg_c0_obj_pool; chains =mlx5_chains_create (dev, &attr);if (IS_ERR (chains)) {
@@ -2595,6 +2596,7 @@ static int mlx5_esw_host_number_init(struct mlx5_eswitch *esw)int esw_offloads_enable (struct mlx5_eswitch *esw) { +struct mapping_ctx *reg_c0_obj_pool;struct mlx5_vport *vport;int err, i;
@@ -2622,6 +2624,15 @@ int esw_offloads_enable(struct mlx5_eswitch *esw)if (err) goto err_vport_metadata; + reg_c0_obj_pool =mapping_create (sizeof (struct mlx5_mapped_obj ), +ESW_REG_C0_USER_DATA_METADATA_MASK , + true); +if (IS_ERR (reg_c0_obj_pool)) { + err =PTR_ERR (reg_c0_obj_pool); + goto err_pool; + } + esw->offloads.reg_c0_obj_pool = reg_c0_obj_pool; + err =esw_offloads_steering_init (esw);if (err) goto err_steering_init;
@@ -2648,6 +2659,8 @@ int esw_offloads_enable(struct mlx5_eswitch *esw) err_uplink:esw_offloads_steering_cleanup (esw); err_steering_init: +mapping_destroy (reg_c0_obj_pool); +err_pool:esw_set_passing_vport_metadata (esw, false); err_vport_metadata:esw_offloads_metadata_uninit (esw);
@@ -2686,6 +2699,7 @@ void esw_offloads_disable(struct mlx5_eswitch *esw)esw_offloads_unload_rep (esw,MLX5_VPORT_UPLINK );esw_set_passing_vport_metadata (esw, false);esw_offloads_steering_cleanup (esw); +mapping_destroy (esw->offloads.reg_c0_obj_pool);esw_offloads_metadata_uninit (esw); esw->flags &= ~MLX5_ESWITCH_VPORT_MATCH_METADATA ;mlx5_rdma_disable_roce (esw->dev);
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_chains.c +6 -36
108 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/lib/fs_chains.h +1 -4
@@ -21,7 +21,7 @@ struct mlx5_chains_attr {u32 max_ft_sz;u32 max_grp_num;struct mlx5_flow_table *default_ft; -u32 max_restore_tag; +struct mapping_ctx *mapping; };#if IS_ENABLED (CONFIG_MLX5_CLS_ACT )
@@ -64,9 +64,6 @@ struct mlx5_fs_chains * mlx5_chains_create(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr);void mlx5_chains_destroy (struct mlx5_fs_chains *chains); -int -mlx5_get_mapped_object (struct mlx5_fs_chains *chains,u32 tag,struct mlx5_mapped_obj *obj); -void mlx5_chains_set_end_ft (struct mlx5_fs_chains *chains,struct mlx5_flow_table *ft);
Signature · 1 line
2.30.2
PATCH 7/13 net/mlx5e: TC, Parse sample action
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Parse TC sample action and save sample parameters in flow attribute data structure.
--- .../ethernet/mellanox/mlx5/core/en/tc_priv.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 28 +++++++++++++++++++ .../ethernet/mellanox/mlx5/core/esw/sample.h | 13 +++++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 2 ++ 4 files changed, 44 insertions(+) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h
drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h +1 -0
@@ -27,6 +27,7 @@ enum {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 , + MLX5E_TC_FLOW_FLAG_SAMPLE = MLX5E_TC_FLOW_BASE + 11, }; struct mlx5e_tc_flow_parse_attr {
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +28 -0
@@ -47,6 +47,7 @@#include <net/tc_act/tc_pedit.h> #include <net/tc_act/tc_csum.h> #include <net/tc_act/tc_mpls.h> +#include <net/psample.h> #include <net/arp.h> #include <net/ipv6_stubs.h> #include <net/bareudp.h>
@@ -1481,6 +1482,7 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,if (flow_flag_test (flow,L3_TO_L2_DECAP ))mlx5e_detach_decap (priv, flow); +kfree (flow->attr->esw_attr->sample);kfree (flow->attr); }
@@ -3627,6 +3629,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,bool ft_flow =mlx5e_is_ft_flow (flow);const struct flow_action_entry *act;struct mlx5_esw_flow_attr *esw_attr; +struct mlx5_sample_attr sample = {};bool encap = false, decap = false;u32 action = attr->action;int err, i, if_count =0 ;
@@ -3881,6 +3884,10 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, attr->dest_chain = act->chain_index;break ;case FLOW_ACTION_CT : +if (flow_flag_test (flow,SAMPLE )) { +NL_SET_ERR_MSG_MOD (extack,"Sample action with connection tracking is not supported" ); +return -EOPNOTSUPP ; + } err =mlx5_tc_ct_parse_action (get_ct_priv (priv), attr, act, extack);if (err)return err;
@@ -3888,6 +3895,17 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,flow_flag_set (flow,CT ); esw_attr->split_count = esw_attr->out_count;break ; +case FLOW_ACTION_SAMPLE : +if (flow_flag_test (flow,CT )) { +NL_SET_ERR_MSG_MOD (extack,"Sample action with connection tracking is not supported" ); +return -EOPNOTSUPP ; + } + sample.rate = act->sample.rate; + sample.group_num = act->sample.psample_group->group_num; +if (act->sample.truncate) + sample.trunc_size = act->sample.trunc_size; +flow_flag_set (flow,SAMPLE ); +break ;default :NL_SET_ERR_MSG_MOD (extack,"The offload action is not supported" );return -EOPNOTSUPP ;
@@ -3966,6 +3984,16 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv,return -EOPNOTSUPP ; } +/* Allocate sample attribute only when there is a sample action and +* no errors after parsing. +*/ +if (flow_flag_test (flow,SAMPLE )) { + esw_attr->sample =kzalloc (sizeof (*esw_attr->sample),GFP_KERNEL ); +if (!esw_attr->sample) +return -ENOMEM ; + *esw_attr->sample = sample; + } +return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* Copyright (c) 2021 Mellanox Technologies. */ + +#ifndef __MLX5_EN_TC_SAMPLE_H__ +#define __MLX5_EN_TC_SAMPLE_H__ + +struct mlx5_sample_attr { +u32 group_num; +u32 rate; +u32 trunc_size; +}; + +#endif /* __MLX5_EN_TC_SAMPLE_H__ */
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +2 -0
@@ -46,6 +46,7 @@#include "lib/fs_chains.h" #include "sf/sf.h" #include "en/tc_ct.h" +#include "esw/sample.h" enum mlx5_mapped_obj_type {MLX5_MAPPED_OBJ_CHAIN ,
@@ -440,6 +441,7 @@ struct mlx5_esw_flow_attr { } dests[MLX5_MAX_FLOW_FWD_VPORTS ];struct mlx5_rx_tun_attr *rx_tun_attr;struct mlx5_pkt_reformat *decap_pkt_reformat; +struct mlx5_sample_attr *sample; }; int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
Signature · 1 line
2.30.2
PATCH 8/13 net/mlx5e: TC, Add sampler termination table API
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Sampled packets are sent to software using termination tables. There is only one rule in that table that is to forward sampled packets to the e-switch management vport.
Create a sampler termination table and rule for each eswitch.
--- .../net/ethernet/mellanox/mlx5/core/Kconfig | 12 +++ .../net/ethernet/mellanox/mlx5/core/Makefile | 1 + .../net/ethernet/mellanox/mlx5/core/en_rep.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_tc.c | 11 +++ .../ethernet/mellanox/mlx5/core/esw/sample.c | 96 +++++++++++++++++++ .../ethernet/mellanox/mlx5/core/esw/sample.h | 8 ++ 6 files changed, 129 insertions(+) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c
drivers/net/ethernet/mellanox/mlx5/core/Kconfig +12 -0
@@ -104,6 +104,18 @@ config MLX5_TC_CT If unsure, set to Y +config MLX5_TC_SAMPLE + bool "MLX5 TC sample offload support" + depends on MLX5_CLS_ACT + default y + help + Say Y here if you want to support offloading sample rules via tc + sample action. + If set to N, will not be able to configure tc rules with sample + action. + + If unsure, set to Y + config MLX5_CORE_EN_DCB bool "Data Center Bridging (DCB) Support" default y
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -0
@@ -55,6 +55,7 @@ mlx5_core-$(CONFIG_MLX5_ESWITCH) += esw/acl/helper.o \ esw/acl/egress_lgcy.o esw/acl/egress_ofld.o \ esw/acl/ingress_lgcy.o esw/acl/ingress_ofld.o \ esw/devlink_port.o esw/vporttbl.o +mlx5_core-$(CONFIG_MLX5_TC_SAMPLE) += esw/sample.o mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o mlx5_core-$(CONFIG_VXLAN) += lib/vxlan.o
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +1 -0
@@ -89,6 +89,7 @@ struct mlx5_rep_uplink_priv {struct mapping_ctx *tunnel_enc_opts_mapping;struct mlx5_tc_ct_priv *ct_priv; +struct mlx5_esw_psample *esw_psample;/* support eswitch vports bonding */ struct mlx5e_rep_bond *bond;
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +11 -0
@@ -66,6 +66,7 @@#include "en/mod_hdr.h" #include "en/tc_priv.h" #include "en/tc_tun_encap.h" +#include "esw/sample.h" #include "lib/devcom.h" #include "lib/geneve.h" #include "lib/fs_chains.h"
@@ -4876,6 +4877,10 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht) &esw->offloads.mod_hdr, MLX5_FLOW_NAMESPACE_FDB); +#if IS_ENABLED (CONFIG_MLX5_TC_SAMPLE ) + uplink_priv->esw_psample =mlx5_esw_sample_init (netdev_priv (priv->netdev)); +#endif + mapping =mapping_create (sizeof (struct tunnel_match_key ),TUNNEL_INFO_BITS_MASK , true);if (IS_ERR (mapping)) {
@@ -4913,6 +4918,9 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht) err_enc_opts_mapping:mapping_destroy (uplink_priv->tunnel_mapping); err_tun_mapping: +#if IS_ENABLED (CONFIG_MLX5_TC_SAMPLE ) +mlx5_esw_sample_cleanup (uplink_priv->esw_psample); +#endif mlx5_tc_ct_clean (uplink_priv->ct_priv);netdev_warn (priv->netdev,"Failed to initialize tc (eswitch), err: %d" , err);
@@ -4931,6 +4939,9 @@ void mlx5e_tc_esw_cleanup(struct rhashtable *tc_ht)mapping_destroy (uplink_priv->tunnel_enc_opts_mapping);mapping_destroy (uplink_priv->tunnel_mapping); +#if IS_ENABLED (CONFIG_MLX5_TC_SAMPLE ) +mlx5_esw_sample_cleanup (uplink_priv->esw_psample); +#endif mlx5_tc_ct_clean (uplink_priv->ct_priv); }
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c new file +96 -0
96 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h +8 -0
@@ -4,10 +4,18 @@#ifndef __MLX5_EN_TC_SAMPLE_H__#define __MLX5_EN_TC_SAMPLE_H__ +#include "en.h" +struct mlx5_sample_attr {u32 group_num;u32 rate;u32 trunc_size; }; +struct mlx5_esw_psample * +mlx5_esw_sample_init (struct mlx5e_priv *priv); + +void +mlx5_esw_sample_cleanup (struct mlx5_esw_psample *esw_psample); +#endif /* __MLX5_EN_TC_SAMPLE_H__ */
Signature · 1 line
2.30.2
PATCH 9/13 net/mlx5e: TC, Add sampler object API
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
In order to offload sample action, HW introduces sampler object. The sampler object samples packets according to the provided sample ratio. Sampled packets are duplicated. One copy is processed by a termination table, named the sample table, which sends the packet up to software. The second copy is processed by the default table.
Instantiate sampler object. Re-use identical sampler object for the same sample ratio, sample table and default table as a prestep for offloading tc sample actions.
--- .../ethernet/mellanox/mlx5/core/esw/sample.c | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c +131 -0
@@ -3,11 +3,28 @@#include "esw/sample.h" #include "eswitch.h" +#include "en_tc.h" +#include "fs_core.h" struct mlx5_esw_psample {struct mlx5e_priv *priv;struct mlx5_flow_table *termtbl;struct mlx5_flow_handle *termtbl_rule; + DECLARE_HASHTABLE(hashtbl, 8); +struct mutex ht_lock;/* protect hashtbl */ +}; + +struct mlx5_sampler { +struct hlist_node hlist; +u32 sampler_id; +u32 sample_ratio; +u32 sample_table_id; +u32 default_table_id; +int count; +}; + +struct mlx5_sample_flow { +struct mlx5_sampler *sampler; }; static int
@@ -64,6 +81,117 @@ sampler_termtbl_destroy(struct mlx5_esw_psample *esw_psample)mlx5_destroy_flow_table (esw_psample->termtbl); } +static int +sampler_obj_create (struct mlx5_core_dev *mdev,struct mlx5_sampler *sampler) +{ +u32 in[MLX5_ST_SZ_DW (create_sampler_obj_in)] = {}; +u32 out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; +u64 general_obj_types; +void *obj; +int err; + + general_obj_types =MLX5_CAP_GEN_64 (mdev, general_obj_types); +if (!(general_obj_types &MLX5_HCA_CAP_GENERAL_OBJECT_TYPES_SAMPLER )) +return -EOPNOTSUPP ; +if (!MLX5_CAP_ESW_FLOWTABLE_FDB (mdev, ignore_flow_level)) +return -EOPNOTSUPP ; + + obj =MLX5_ADDR_OF (create_sampler_obj_in, in, sampler_object); +MLX5_SET (sampler_obj, obj, table_type,FS_FT_FDB ); +MLX5_SET (sampler_obj, obj, ignore_flow_level,1 ); +MLX5_SET (sampler_obj, obj, level,1 ); +MLX5_SET (sampler_obj, obj, sample_ratio, sampler->sample_ratio); +MLX5_SET (sampler_obj, obj, sample_table_id, sampler->sample_table_id); +MLX5_SET (sampler_obj, obj, default_table_id, sampler->default_table_id); +MLX5_SET (general_obj_in_cmd_hdr, in, opcode,MLX5_CMD_OP_CREATE_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, in, obj_type,MLX5_GENERAL_OBJECT_TYPES_SAMPLER ); + + err =mlx5_cmd_exec (mdev, in,sizeof (in), out,sizeof (out)); +if (!err) + sampler->sampler_id =MLX5_GET (general_obj_out_cmd_hdr, out, obj_id); + +return err; +} + +static void +sampler_obj_destroy (struct mlx5_core_dev *mdev,u32 sampler_id) +{ +u32 in[MLX5_ST_SZ_DW (general_obj_in_cmd_hdr)] = {}; +u32 out[MLX5_ST_SZ_DW (general_obj_out_cmd_hdr)]; + +MLX5_SET (general_obj_in_cmd_hdr, in, opcode,MLX5_CMD_OP_DESTROY_GENERAL_OBJECT ); +MLX5_SET (general_obj_in_cmd_hdr, in, obj_type,MLX5_GENERAL_OBJECT_TYPES_SAMPLER ); +MLX5_SET (general_obj_in_cmd_hdr, in, obj_id, sampler_id); + +mlx5_cmd_exec (mdev, in,sizeof (in), out,sizeof (out)); +} + +static u32 +sampler_hash (u32 sample_ratio,u32 default_table_id) +{ +return jhash_2words (sample_ratio, default_table_id,0 ); +} + +static int +sampler_cmp (u32 sample_ratio1,u32 default_table_id1,u32 sample_ratio2,u32 default_table_id2) +{ +return sample_ratio1 != sample_ratio2 || default_table_id1 != default_table_id2; +} + +static struct mlx5_sampler * +sampler_get (struct mlx5_esw_psample *esw_psample,u32 sample_ratio,u32 default_table_id) +{ +struct mlx5_sampler *sampler; +u32 hash_key; +int err; + +mutex_lock (&esw_psample->ht_lock); + hash_key =sampler_hash (sample_ratio, default_table_id); +hash_for_each_possible (esw_psample->hashtbl, sampler, hlist, hash_key) +if (!sampler_cmp (sampler->sample_ratio, sampler->default_table_id, + sample_ratio, default_table_id)) + goto add_ref; + + sampler =kzalloc (sizeof (*sampler),GFP_KERNEL ); +if (!sampler) { + err = -ENOMEM ; + goto err_alloc; + } + + sampler->sample_table_id = esw_psample->termtbl->id; + sampler->default_table_id = default_table_id; + sampler->sample_ratio = sample_ratio; + + err =sampler_obj_create (esw_psample->priv->mdev, sampler); +if (err) + goto err_create; + +hash_add (esw_psample->hashtbl, &sampler->hlist, hash_key); + +add_ref: + sampler->count++; +mutex_unlock (&esw_psample->ht_lock); +return sampler; + +err_create: +kfree (sampler); +err_alloc: +mutex_unlock (&esw_psample->ht_lock); +return ERR_PTR (err); +} + +static void +sampler_put (struct mlx5_esw_psample *esw_psample,struct mlx5_sampler *sampler) +{ +mutex_lock (&esw_psample->ht_lock); +if (--sampler->count ==0 ) { +hash_del (&sampler->hlist); +sampler_obj_destroy (esw_psample->priv->mdev, sampler->sampler_id); +kfree (sampler); + } +mutex_unlock (&esw_psample->ht_lock); +} +struct mlx5_esw_psample *mlx5_esw_sample_init (struct mlx5e_priv *priv) {
@@ -78,6 +206,8 @@ mlx5_esw_sample_init(struct mlx5e_priv *priv)if (err) goto err_termtbl; +mutex_init (&esw_psample->ht_lock); +return esw_psample; err_termtbl:
@@ -91,6 +221,7 @@ mlx5_esw_sample_cleanup(struct mlx5_esw_psample *esw_psample)if (IS_ERR_OR_NULL (esw_psample))return ; +mutex_destroy (&esw_psample->ht_lock);sampler_termtbl_destroy (esw_psample);kfree (esw_psample); }
Signature · 1 line
2.30.2
PATCH 10/13 net/mlx5e: TC, Add sampler restore handle API
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Use common object pool to create an object ID to map sample parameters. Allocate a modify header action to write the object ID to reg_c0 lower 16 bits. Create a restore rule to pass the object ID to software. So software can identify sampled packets via the object ID and send it to userspace.
Aggregate the modify header action, restore rule and object ID to a sample restore handle. Re-use identical sample restore handle for the same object ID.
--- .../ethernet/mellanox/mlx5/core/esw/sample.c | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c +108 -0
@@ -1,6 +1,8 @@// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* Copyright (c) 2021 Mellanox Technologies. */ +#include <linux/skbuff.h> +#include <net/psample.h> #include "esw/sample.h" #include "eswitch.h" #include "en_tc.h"
@@ -12,6 +14,8 @@ struct mlx5_esw_psample {struct mlx5_flow_handle *termtbl_rule;DECLARE_HASHTABLE (hashtbl,8 );struct mutex ht_lock;/* protect hashtbl */ +DECLARE_HASHTABLE (restore_hashtbl,8 ); +struct mutex restore_lock;/* protect restore_hashtbl */ };struct mlx5_sampler {
@@ -25,6 +29,15 @@ struct mlx5_sampler {struct mlx5_sample_flow {struct mlx5_sampler *sampler; +struct mlx5_sample_restore *restore; +}; + +struct mlx5_sample_restore { +struct hlist_node hlist; +struct mlx5_modify_hdr *modify_hdr; +struct mlx5_flow_handle *rule; +u32 obj_id; +int count; }; static int
@@ -192,6 +205,99 @@ sampler_put(struct mlx5_esw_psample *esw_psample, struct mlx5_sampler *sampler)mutex_unlock (&esw_psample->ht_lock); } +static struct mlx5_modify_hdr * +sample_metadata_rule_get (struct mlx5_core_dev *mdev,u32 obj_id) +{ +struct mlx5e_tc_mod_hdr_acts mod_acts = {}; +struct mlx5_modify_hdr *modify_hdr; +int err; + + err =mlx5e_tc_match_to_reg_set (mdev, &mod_acts,MLX5_FLOW_NAMESPACE_FDB , +CHAIN_TO_REG , obj_id); +if (err) + goto err_set_regc0; + + modify_hdr =mlx5_modify_header_alloc (mdev,MLX5_FLOW_NAMESPACE_FDB , + mod_acts.num_actions, + mod_acts.actions); +if (IS_ERR (modify_hdr)) { + err =PTR_ERR (modify_hdr); + goto err_modify_hdr; + } + +dealloc_mod_hdr_actions (&mod_acts); +return modify_hdr; + +err_modify_hdr: +dealloc_mod_hdr_actions (&mod_acts); +err_set_regc0: +return ERR_PTR (err); +} + +static struct mlx5_sample_restore * +sample_restore_get (struct mlx5_esw_psample *esw_psample,u32 obj_id) +{ +struct mlx5_core_dev *mdev = esw_psample->priv->mdev; +struct mlx5_eswitch *esw = mdev->priv.eswitch; +struct mlx5_sample_restore *restore; +struct mlx5_modify_hdr *modify_hdr; +int err; + +mutex_lock (&esw_psample->restore_lock); +hash_for_each_possible (esw_psample->restore_hashtbl, restore, hlist, obj_id) +if (restore->obj_id == obj_id) + goto add_ref; + + restore =kzalloc (sizeof (*restore),GFP_KERNEL ); +if (!restore) { + err = -ENOMEM ; + goto err_alloc; + } + restore->obj_id = obj_id; + + modify_hdr =sample_metadata_rule_get (mdev, obj_id); +if (IS_ERR (modify_hdr)) { + err =PTR_ERR (modify_hdr); + goto err_modify_hdr; + } + restore->modify_hdr = modify_hdr; + + restore->rule =esw_add_restore_rule (esw, obj_id); +if (IS_ERR (restore->rule)) { + err =PTR_ERR (restore->rule); + goto err_restore; + } + +hash_add (esw_psample->restore_hashtbl, &restore->hlist, obj_id); +add_ref: + restore->count++; +mutex_unlock (&esw_psample->restore_lock); +return restore; + +err_restore: +mlx5_modify_header_dealloc (mdev, restore->modify_hdr); +err_modify_hdr: +kfree (restore); +err_alloc: +mutex_unlock (&esw_psample->restore_lock); +return ERR_PTR (err); +} + +static void +sample_restore_put (struct mlx5_esw_psample *esw_psample,struct mlx5_sample_restore *restore) +{ +mutex_lock (&esw_psample->restore_lock); +if (--restore->count ==0 ) +hash_del (&restore->hlist); +mutex_unlock (&esw_psample->restore_lock); + +if (!restore->count) { +mlx5_del_flow_rules (restore->rule); +mlx5_modify_header_dealloc (esw_psample->priv->mdev, restore->modify_hdr); +kfree (restore); + } +} +struct mlx5_esw_psample *mlx5_esw_sample_init (struct mlx5e_priv *priv) {
@@ -207,6 +313,7 @@ mlx5_esw_sample_init(struct mlx5e_priv *priv) goto err_termtbl;mutex_init (&esw_psample->ht_lock); +mutex_init (&esw_psample->restore_lock);return esw_psample;
@@ -221,6 +328,7 @@ mlx5_esw_sample_cleanup(struct mlx5_esw_psample *esw_psample)if (IS_ERR_OR_NULL (esw_psample))return ; +mutex_destroy (&esw_psample->restore_lock);mutex_destroy (&esw_psample->ht_lock);sampler_termtbl_destroy (esw_psample);kfree (esw_psample);
Signature · 1 line
2.30.2
PATCH 11/13 net/mlx5e: TC, Refactor tc update skb function
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
As a pre-step to process sampled packet in this function.
--- .../ethernet/mellanox/mlx5/core/en/rep/tc.c | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +33 -26
@@ -611,20 +611,46 @@ static bool mlx5e_restore_tunnel(struct mlx5e_priv *priv, struct sk_buff *skb,return true; } + +static bool mlx5e_restore_skb (struct sk_buff *skb,u32 chain,u32 reg_c1, +struct mlx5e_tc_update_priv *tc_priv) +{ +struct mlx5e_priv *priv =netdev_priv (skb->dev); +u32 tunnel_id = reg_c1 >>ESW_TUN_OFFSET ; + +if (chain) { +struct mlx5_rep_uplink_priv *uplink_priv; +struct mlx5e_rep_priv *uplink_rpriv; +struct tc_skb_ext *tc_skb_ext; +struct mlx5_eswitch *esw; +u32 zone_restore_id; + + tc_skb_ext =skb_ext_add (skb,TC_SKB_EXT ); +if (!tc_skb_ext) { +WARN_ON (1 ); +return false; + } + tc_skb_ext->chain = chain; + zone_restore_id = reg_c1 &ESW_ZONE_ID_MASK ; + esw = priv->mdev->priv.eswitch; + uplink_rpriv =mlx5_eswitch_get_uplink_priv (esw,REP_ETH ); + uplink_priv = &uplink_rpriv->uplink_priv; +if (!mlx5e_tc_ct_restore_flow (uplink_priv->ct_priv, skb, + zone_restore_id)) +return false; + } +return mlx5e_restore_tunnel (priv, skb, tc_priv, tunnel_id); +}#endif /* CONFIG_NET_TC_SKB_EXT */ bool mlx5e_rep_tc_update_skb (struct mlx5_cqe64 *cqe,struct sk_buff *skb,struct mlx5e_tc_update_priv *tc_priv) { -#if IS_ENABLED (CONFIG_NET_TC_SKB_EXT ) -u32 reg_c0, reg_c1, tunnel_id, zone_restore_id; -struct mlx5_rep_uplink_priv *uplink_priv; -struct mlx5e_rep_priv *uplink_rpriv;struct mlx5_mapped_obj mapped_obj; -struct tc_skb_ext *tc_skb_ext;struct mlx5_eswitch *esw;struct mlx5e_priv *priv; +u32 reg_c0, reg_c1;int err; reg_c0 = (be32_to_cpu (cqe->sop_drop_qpn) &MLX5E_TC_FLOW_ID_MASK );
@@ -640,7 +666,6 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, priv =netdev_priv (skb->dev); esw = priv->mdev->priv.eswitch; - err =mapping_find (esw->offloads.reg_c0_obj_pool, reg_c0, &mapped_obj);if (err) { netdev_dbg(priv->netdev,
@@ -649,31 +674,13 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe,return false; } +#if IS_ENABLED (CONFIG_NET_TC_SKB_EXT )if (mapped_obj.type ==MLX5_MAPPED_OBJ_CHAIN ) { -if (mapped_obj.chain) { - tc_skb_ext =skb_ext_add (skb,TC_SKB_EXT ); -if (!tc_skb_ext) { -WARN_ON (1 ); -return false; - } - - tc_skb_ext->chain = mapped_obj.chain; - - 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; -if (!mlx5e_tc_ct_restore_flow (uplink_priv->ct_priv, skb, - zone_restore_id)) -return false; - } +return mlx5e_restore_skb (skb, mapped_obj.chain, reg_c1, tc_priv); }else {netdev_dbg (priv->netdev,"Invalid mapped object type: %d\n" , mapped_obj.type);return false; } - - tunnel_id = reg_c1 >>ESW_TUN_OFFSET ; -return mlx5e_restore_tunnel (priv, skb, tc_priv, tunnel_id);#endif /* CONFIG_NET_TC_SKB_EXT */ return true;
Signature · 1 line
2.30.2
PATCH 12/13 net/mlx5e: TC, Handle sampled packets
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
Mark the sampled packets with a sample restore object. Send sampled packets using the psample api.
--- .../net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 14 +++++++++++--- .../net/ethernet/mellanox/mlx5/core/esw/sample.c | 15 +++++++++++++++ .../net/ethernet/mellanox/mlx5/core/esw/sample.h | 3 +++ drivers/net/ethernet/mellanox/mlx5/core/eswitch.h | 6 ++++++ 4 files changed, 35 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +11 -3
@@ -17,6 +17,7 @@#include "en/mapping.h" #include "en/tc_tun.h" #include "lib/port_tun.h" +#include "esw/sample.h" struct mlx5e_rep_indr_block_priv {struct net_device *netdev;
@@ -675,13 +676,20 @@ bool mlx5e_rep_tc_update_skb(struct mlx5_cqe64 *cqe, }#if IS_ENABLED (CONFIG_NET_TC_SKB_EXT ) -if (mapped_obj.type ==MLX5_MAPPED_OBJ_CHAIN ) { +if (mapped_obj.type ==MLX5_MAPPED_OBJ_CHAIN )return mlx5e_restore_skb (skb, mapped_obj.chain, reg_c1, tc_priv); - }else { +#endif /* CONFIG_NET_TC_SKB_EXT */ +#if IS_ENABLED (CONFIG_MLX5_TC_SAMPLE ) +if (mapped_obj.type ==MLX5_MAPPED_OBJ_SAMPLE ) { +mlx5_esw_sample_skb (skb, &mapped_obj); +return false; + } +#endif /* CONFIG_MLX5_TC_SAMPLE */ +if (mapped_obj.type !=MLX5_MAPPED_OBJ_SAMPLE && + mapped_obj.type !=MLX5_MAPPED_OBJ_CHAIN ) {netdev_dbg (priv->netdev,"Invalid mapped object type: %d\n" , mapped_obj.type);return false; } -#endif /* CONFIG_NET_TC_SKB_EXT */ return true; }
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c +15 -0
@@ -298,6 +298,21 @@ sample_restore_put(struct mlx5_esw_psample *esw_psample, struct mlx5_sample_rest } } +void mlx5_esw_sample_skb (struct sk_buff *skb,struct mlx5_mapped_obj *mapped_obj) +{ +u32 trunc_size = mapped_obj->sample.trunc_size; +struct psample_group psample_group = {}; +struct psample_metadata md = {}; + + md.trunc_size = trunc_size ?min (trunc_size, skb->len) : skb->len; + md.in_ifindex = skb->dev->ifindex; + psample_group.group_num = mapped_obj->sample.group_id; + psample_group.net = &init_net; +skb_push (skb, skb->mac_len); + +psample_sample_packet (&psample_group, skb, mapped_obj->sample.rate, &md); +} +struct mlx5_esw_psample *mlx5_esw_sample_init (struct mlx5e_priv *priv) {
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h +3 -0
@@ -5,6 +5,7 @@#define __MLX5_EN_TC_SAMPLE_H__#include "en.h" +#include "eswitch.h" struct mlx5_sample_attr {u32 group_num;
@@ -12,6 +13,8 @@ struct mlx5_sample_attr {u32 trunc_size; }; +void mlx5_esw_sample_skb (struct sk_buff *skb,struct mlx5_mapped_obj *mapped_obj); +struct mlx5_esw_psample *mlx5_esw_sample_init (struct mlx5e_priv *priv);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +6 -0
@@ -50,12 +50,18 @@enum mlx5_mapped_obj_type {MLX5_MAPPED_OBJ_CHAIN , +MLX5_MAPPED_OBJ_SAMPLE , };struct mlx5_mapped_obj {enum mlx5_mapped_obj_type type;union {u32 chain; +struct { +u32 group_id; +u32 rate; +u32 trunc_size; + } sample; }; };
Signature · 1 line
2.30.2
PATCH 13/13 net/mlx5e: TC, Add support to offload sample action
In reply to Saeed MahameedFrom: Chris Mi <[email protected]>
The following diagram illustrates the hardware model for tc sample action:
+---------------------+
+ original flow table +
+---------------------+
+ original match +
+---------------------+
|
v
+------------------------------------------------+
+ Flow Sampler Object +
+------------------------------------------------+
+ sample ratio +
+------------------------------------------------+
+ sample table id | default table id +
+------------------------------------------------+
| |
v v
+-----------------------------+ +----------------------------------------+
+ sample table + + default table per <vport, chain, prio> +
+-----------------------------+ +----------------------------------------+
+ forward to management vport + + original match +
+-----------------------------+ +----------------------------------------+
+ other actions +
+----------------------------------------+The sample action is translated to a goto flow table object destination which samples packets according to the provided sample ratio. Sampled packets are duplicated. One copy is processed by a termination table, named the sample table, which sends the packet to the eswitch manager port (that will be processed by software).
The second copy is processed by the default table which executes the subsequent actions. The default table is created per <vport, chain, prio> tuple as rules with different prios and chains may overlap.
--- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 30 +++ .../ethernet/mellanox/mlx5/core/esw/sample.c | 235 ++++++++++++++++++ .../ethernet/mellanox/mlx5/core/esw/sample.h | 18 ++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 4 + .../mellanox/mlx5/core/eswitch_offloads.c | 43 +++- 5 files changed, 328 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +30 -0
@@ -223,6 +223,25 @@ get_ct_priv(struct mlx5e_priv *priv)return priv->fs.tc.ct; } +#if IS_ENABLED (CONFIG_MLX5_TC_SAMPLE ) +static struct mlx5_esw_psample * +get_sample_priv (struct mlx5e_priv *priv) +{ +struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; +struct mlx5_rep_uplink_priv *uplink_priv; +struct mlx5e_rep_priv *uplink_rpriv; + +if (is_mdev_switchdev_mode (priv->mdev)) { + uplink_rpriv =mlx5_eswitch_get_uplink_priv (esw,REP_ETH ); + uplink_priv = &uplink_rpriv->uplink_priv; + +return uplink_priv->esw_psample; + } + +return NULL ; +} +#endif +struct mlx5_flow_handle * mlx5_tc_rule_insert(struct mlx5e_priv *priv, struct mlx5_flow_spec *spec,
@@ -1092,6 +1111,10 @@ mlx5e_tc_offload_fdb_rules(struct mlx5_eswitch *esw, rule =mlx5_tc_ct_flow_offload (get_ct_priv (flow->priv), flow, spec, attr, mod_hdr_acts); +#if IS_ENABLED (CONFIG_MLX5_TC_SAMPLE ) + } else if (flow_flag_test(flow, SAMPLE)) { + rule =mlx5_esw_sample_offload (get_sample_priv (flow->priv), spec, attr); +#endif }else { rule =mlx5_eswitch_add_offloaded_rule (esw, spec, attr); }
@@ -1127,6 +1150,13 @@ void mlx5e_tc_unoffload_fdb_rules(struct mlx5_eswitch *esw,return ; } +#if IS_ENABLED (CONFIG_MLX5_TC_SAMPLE ) +if (flow_flag_test (flow,SAMPLE )) { +mlx5_esw_sample_unoffload (get_sample_priv (flow->priv), flow->rule[0 ], attr); +return ; + } +#endif +if (attr->esw_attr->split_count)mlx5_eswitch_del_fwd_rule (esw, flow->rule[1 ], attr);
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.c +235 -0
258 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/esw/sample.h +18 -0
@@ -7,14 +7,32 @@#include "en.h" #include "eswitch.h" +struct mlx5e_priv ; +struct mlx5_flow_attr ; +struct mlx5_esw_psample ; +struct mlx5_sample_attr {u32 group_num;u32 rate;u32 trunc_size; +u32 restore_obj_id; +u32 sampler_id; +struct mlx5_flow_table *sample_default_tbl; +struct mlx5_sample_flow *sample_flow; };void mlx5_esw_sample_skb (struct sk_buff *skb,struct mlx5_mapped_obj *mapped_obj); +struct mlx5_flow_handle * +mlx5_esw_sample_offload (struct mlx5_esw_psample *sample_priv, +struct mlx5_flow_spec *spec, +struct mlx5_flow_attr *attr); + +void +mlx5_esw_sample_unoffload (struct mlx5_esw_psample *sample_priv, +struct mlx5_flow_handle *rule, +struct mlx5_flow_attr *attr); +struct mlx5_esw_psample *mlx5_esw_sample_init (struct mlx5e_priv *priv);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +4 -0
@@ -376,6 +376,9 @@ void mlx5_eswitch_termtbl_put(struct mlx5_eswitch *esw, struct mlx5_termtbl_handle *tt); +void +mlx5_eswitch_clear_rule_source_port (struct mlx5_eswitch *esw,struct mlx5_flow_spec *spec); +struct mlx5_flow_handle * mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw, struct mlx5_flow_spec *spec,
@@ -423,6 +426,7 @@ enum {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 ), + MLX5_ESW_ATTR_FLAG_SAMPLE = BIT(4), }; struct mlx5_esw_flow_attr {
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +41 -2
67 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [net-next 01/13] net/mlx5: E-switch, Move vport table functions to a new file
In reply to Saeed MahameedThis series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 10 lines · On Tue, 6 Apr 2021 21:54:09 -0700 you wrote:
From: Chris Mi <[email protected]>
Currently, the vport table functions are in common eswitch offload file. This file is too big. Move the vport table create, delete and lookup functions to a separate file. Put the file in esw directory.
Pre-step for generalizing its functionality for serving both the mirroring and the sample features.
[...]
Here is the summary with links:
- [net-next,01/13] net/mlx5: E-switch, Move vport table functions to a new file
https://git.kernel.org/netdev/net-next/c/4c7f40287aa5 - [net-next,02/13] net/mlx5: E-switch, Rename functions to follow naming convention. https://git.kernel.org/netdev/net-next/c/0a9e2307870b - [net-next,03/13] net/mlx5: E-switch, Generalize per vport table API https://git.kernel.org/netdev/net-next/c/c796bb7cd230 - [net-next,04/13] net/mlx5: E-switch, Set per vport table default group number https://git.kernel.org/netdev/net-next/c/c1904360dde8 - [net-next,05/13] net/mlx5: Map register values to restore objects https://git.kernel.org/netdev/net-next/c/a91d98a0a2b8 - [net-next,06/13] net/mlx5: Instantiate separate mapping objects for FDB and NIC tables https://git.kernel.org/netdev/net-next/c/c935568271b5 - [net-next,07/13] net/mlx5e: TC, Parse sample action https://git.kernel.org/netdev/net-next/c/41c2fd949803 - [net-next,08/13] net/mlx5e: TC, Add sampler termination table API https://git.kernel.org/netdev/net-next/c/2a9ab10a5689 - [net-next,09/13] net/mlx5e: TC, Add sampler object API https://git.kernel.org/netdev/net-next/c/11ecd6c60b4e - [net-next,10/13] net/mlx5e: TC, Add sampler restore handle API https://git.kernel.org/netdev/net-next/c/36a3196256bf - [net-next,11/13] net/mlx5e: TC, Refactor tc update skb function https://git.kernel.org/netdev/net-next/c/7319a1cc3ca9 - [net-next,12/13] net/mlx5e: TC, Handle sampled packets https://git.kernel.org/netdev/net-next/c/be9dc0047450 - [net-next,13/13] net/mlx5e: TC, Add support to offload sample action https://git.kernel.org/netdev/net-next/c/f94d6389f6a8
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html