support the flow-based traffic sampling
Subsystems (2)
PATCH v5 5/7 net/mlx5: split sample flow into two sub flows
In reply to Jiawei WangAdd the sampler action resource structs definition.
The flow with sample action will be splited into two sub flows, the prefix flow with sample action, the suffix flow with the left actions.
For the prefix flow, add the extra the tag action with unique id to metadata register, and suffix flow will add the extra tag item to match that unique id.
--- drivers/net/mlx5/mlx5.c | 11 ++ drivers/net/mlx5/mlx5.h | 3 + drivers/net/mlx5/mlx5_flow.c | 258 ++++++++++++++++++++++++++++++++++++++++++- drivers/net/mlx5/mlx5_flow.h | 36 ++++++ 4 files changed, 304 insertions(+), 4 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -244,6 +244,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_jump_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_sample_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_sample_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
@@ -41,6 +41,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_TAG ,/* Pool for tag resource. */ MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ +MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -514,6 +515,7 @@ struct mlx5_flow_tbl_resource {/* Tables for metering splits should be added here. */ #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)#define MLX5_MAX_TABLES_FDB UINT16_MAX +#define MLX5_FLOW_TABLE_FACTOR 10/* ID generation structure. */ struct mlx5_flow_id_pool {
@@ -642,6 +644,7 @@ struct mlx5_dev_ctx_shared {struct mlx5_hlist *tag_table;uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ +uint32_t sample_action_list;/* List of sample actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +254 -4
294 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow.h +36 -0
@@ -507,6 +507,38 @@ struct mlx5_flow_tbl_data_entry {uint32_t idx;/**< index for the indexed mempool. */ }; +/* Sub rdma-core actions list. */ +struct mlx5_flow_sub_actions_list { +uint32_t actions_num;/**< Number of sample actions. */ +uint64_t action_flags; +void *dr_queue_action; +void *dr_tag_action; +void *dr_cnt_action; +}; + +/* Sample sub-actions resource list. */ +struct mlx5_flow_sub_actions_idx { +uint32_t rix_hrxq;/**< Hash Rx queue object index. */ +uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t cnt; +}; + +/* Sample action resource structure. */ +struct mlx5_flow_dv_sample_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +void *verbs_action;/**< Verbs sample action object. */ +uint8_t ft_type;/** Flow Table Type */ +uint32_t ft_id;/** Flow Table Level */ +void *normal_path_tbl;/** Flow Table pointer */ +void *default_miss;/** default_miss dr_action. */ +uint32_t ratio;/** Sample Ratio */ +struct mlx5_flow_sub_actions_idx sample_idx; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -539,6 +571,8 @@ struct mlx5_flow_handle_dv {/**< Index to push VLAN action resource in cache. */ uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t rix_sample; +/**< Index to sample action resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -604,6 +638,8 @@ struct mlx5_flow_dv_workspace {/**< Pointer to the jump action resource. */ struct mlx5_flow_dv_match_params value;/**< Holds the value that the packet is compared to. */ +struct mlx5_flow_dv_sample_resource *sample_res; +/**< Pointer to the sample action resource. */ };/*
Signature · 1 line
1.8.3.1
PATCH v5 6/7 net/mlx5: update translate function for sample action
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.
--- drivers/net/mlx5/mlx5_flow.c | 16 +- drivers/net/mlx5/mlx5_flow.h | 14 +- drivers/net/mlx5/mlx5_flow_dv.c | 494 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 502 insertions(+), 22 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
@@ -4606,10 +4606,14 @@ struct mlx5_flow_tunnel_info {int hairpin_flow;uint32_t hairpin_id =0 ;struct rte_flow_attr attr_tx = { .priority =0 }; +struct rte_flow_attr attr_factor = {0 };int ret; - hairpin_flow =flow_check_hairpin_split (dev, attr, actions); - ret =flow_drv_validate (dev, attr, items, p_actions_rx, +memcpy ((void *)&attr_factor, (const void *)attr,sizeof (*attr)); +if (external) + attr_factor.group *=MLX5_FLOW_TABLE_FACTOR ; + hairpin_flow =flow_check_hairpin_split (dev, &attr_factor, actions); + ret =flow_drv_validate (dev, &attr_factor, items, p_actions_rx, external, hairpin_flow, error);if (ret <0 )return 0 ;
@@ -4628,7 +4632,7 @@ struct mlx5_flow_tunnel_info { rte_errno =ENOMEM ; goto error_before_flow; } - flow->drv_type =flow_get_drv_type (dev, attr); + flow->drv_type =flow_get_drv_type (dev, &attr_factor);if (hairpin_id !=0 ) flow->hairpin_flow_id = hairpin_id; MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4674,7 +4678,7 @@ struct mlx5_flow_tunnel_info {* depending on configuration. In the simplest * case it just creates unmodified original flow. */ - ret =flow_create_split_outer (dev, flow, attr, + ret =flow_create_split_outer (dev, flow, &attr_factor, buf->entry[i].pattern, p_actions_rx, external, idx, error);
@@ -4711,8 +4715,8 @@ struct mlx5_flow_tunnel_info {* the egress Flows belong to the different device and * copy table should be updated in peer NIC Rx domain. */ -if (attr->ingress && - (external || attr->group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { +if (attr_factor.ingress && + (external || attr_factor.group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { ret =flow_mreg_update_copy_table (dev, flow, actions, error);if (ret) goto error;
drivers/net/mlx5/mlx5_flow.h +7 -7
@@ -366,6 +366,13 @@ enum mlx5_flow_fate_type { MLX5_FLOW_FATE_MAX, }; +/* +* Max number of actions per DV flow. +* See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED +* in rdma-core file providers/mlx5/verbs.c. +*/ +#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8 +/* Matcher PRM representation */ struct mlx5_flow_dv_match_params {size_t size;
@@ -613,13 +620,6 @@ struct mlx5_flow_handle {#define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))#endif -/* -* Max number of actions per DV flow. -* See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED -* in rdma-core file providers/mlx5/verbs.c. -*/ -#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8 -/** Device flow structure only for DV flow creation. */ struct mlx5_flow_dv_workspace {uint32_t group;/**< The group index. */
drivers/net/mlx5/mlx5_flow_dv.c +485 -9
579 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 7/7 app/testpmd: add testpmd command for sample action
In reply to Jiawei WangAdd a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>
The examples for the sample flow use case and result as below:
1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...
This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.
2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...
The flow will result in all the matched ingress packets will be sent to port 2, and the each second packet will also be sent to e-switch manager vport.
--- app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
@@ -56,6 +56,8 @@ enum index {SET_RAW_ENCAP ,SET_RAW_DECAP ,SET_RAW_INDEX , +SET_SAMPLE_ACTIONS , +SET_SAMPLE_INDEX ,/* Top-level command. */ FLOW,
@@ -358,6 +360,10 @@ enum index {ACTION_SET_IPV6_DSCP_VALUE ,ACTION_AGE ,ACTION_AGE_TIMEOUT , +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , + ACTION_SAMPLE_INDEX_VALUE, };/** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -493,6 +499,22 @@ struct action_nvgre_encap_data {struct mplsoudp_decap_conf mplsoudp_decap_conf; +#define ACTION_SAMPLE_ACTIONS_NUM 10 +#define RAW_SAMPLE_CONFS_MAX_NUM 8 +/** Storage for struct rte_flow_action_sample including external data. */ +struct action_sample_data { +struct rte_flow_action_sample conf; +uint32_t idx; +}; +/** Storage for struct rte_flow_action_sample. */ +struct raw_sample_conf { +struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM ]; +}; +struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1189,6 +1211,7 @@ struct parse_action_priv {ACTION_SET_IPV4_DSCP ,ACTION_SET_IPV6_DSCP ,ACTION_AGE , +ACTION_SAMPLE , ZERO, };
@@ -1421,9 +1444,28 @@ struct parse_action_priv { ZERO, }; +static const enum index action_sample[] = { +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , +ACTION_NEXT , +ZERO , +}; + +static const enum index next_action_sample[] = { +ACTION_QUEUE , +ACTION_MARK , +ACTION_COUNT , +ACTION_NEXT , +ZERO , +}; +static int parse_set_raw_encap_decap (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int ); +static int parse_set_sample_action (struct context *,const struct token *, +const char *,unsigned int , +void *,unsigned int );static int parse_set_init (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1491,7 +1533,15 @@ static int parse_vc_action_raw_decap_index(struct context *,static int parse_vc_action_set_meta (struct context *ctx,const struct token *token,const char *str,unsigned int len,void *buf, +unsigned int size); +static int parse_vc_action_sample (struct context *ctx, +const struct token *token,const char *str, +unsigned int len,void *buf,unsigned int size); +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size);static int parse_destroy (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1562,6 +1612,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *, unsigned int, char *, unsigned int);static int comp_set_raw_index (struct context *,const struct token *,unsigned int ,char *,unsigned int ); +static int comp_set_sample_index (struct context *,const struct token *, +unsigned int ,char *,unsigned int );/** Token definitions. */ static const struct token token_list[] = {
@@ -3703,11 +3755,13 @@ static int comp_set_raw_index(struct context *, const struct token *, /* Top level command. */ [SET] = { .name = "set", - .help = "set raw encap/decap data", - .type = "set raw_encap|raw_decap <index> <pattern>", + .help = "set raw encap/decap/sample data", + .type ="set raw_encap|raw_decap <index> <pattern>" + " or set sample_actions <index> <action>", .next =NEXT (NEXT_ENTRY (SET_RAW_ENCAP , - SET_RAW_DECAP)), +SET_RAW_DECAP , + SET_SAMPLE_ACTIONS)), .call = parse_set_init, },/* Sub-level commands. */
@@ -3738,6 +3792,23 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(next_item), .call = parse_port, }, + [SET_SAMPLE_INDEX] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "index of sample actions", + .next = NEXT(next_action_sample), + .call = parse_port, + }, + [SET_SAMPLE_ACTIONS] = { + .name = "sample_actions", + .help = "set sample actions list", + .next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)), + .args =ARGS (ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct buffer , port), +sizeof (((struct buffer *)0 )->port), + 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)), + .call = parse_set_sample_action, + }, [ACTION_SET_TAG] = { .name = "set_tag", .help = "set tag",
@@ -3841,6 +3912,37 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)), .call = parse_vc_conf, }, + [ACTION_SAMPLE] = { + .name = "sample", + .help = "set a sample action", + .next = NEXT(action_sample), + .priv =PRIV_ACTION (SAMPLE , + sizeof(struct action_sample_data)), + .call = parse_vc_action_sample, + }, + [ACTION_SAMPLE_RATIO] = { + .name = "ratio", + .help = "flow sample ratio value", + .next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)), + .args =ARGS (ARGS_ENTRY_ARB + (offsetof(struct action_sample_data , conf) + + offsetof(struct rte_flow_action_sample , ratio), +sizeof (((struct rte_flow_action_sample *)0 )-> + ratio))), + }, + [ACTION_SAMPLE_INDEX] = { + .name = "index", + .help = "the index of sample actions list", + .next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)), + }, + [ACTION_SAMPLE_INDEX_VALUE] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "unsigned integer value", + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc_action_sample_index, + .comp = comp_set_sample_index, + }, };/** Remove and return last entry from argument stack. */
@@ -5351,6 +5453,76 @@ static int comp_set_raw_index(struct context *, const struct token *,return len; } +static int +parse_vc_action_sample (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct buffer *out = buf; +struct rte_flow_action *action; +struct action_sample_data *action_sample_data =NULL ; +static struct rte_flow_action end_action = { +RTE_FLOW_ACTION_TYPE_END ,0 + }; +int ret; + + ret =parse_vc (ctx, token, str, len, buf, size); +if (ret <0 ) +return ret; +/* Nothing else to do if there is no buffer. */ +if (!out) +return ret; +if (!out->args.vc.actions_n) +return -1 ; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; +/* Point to selected object. */ + ctx->object = out->args.vc.data; + ctx->objmask =NULL ; +/* Copy the headers to the buffer. */ + action_sample_data = ctx->object; + action_sample_data->conf.actions = &end_action; + action->conf = &action_sample_data->conf; +return ret; +} + +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct action_sample_data *action_sample_data; +struct rte_flow_action *action; +const struct arg *arg; +struct buffer *out = buf; +int ret; +uint16_t idx; + +RTE_SET_USED (token); +RTE_SET_USED (buf); +RTE_SET_USED (size); +if (ctx->curr !=ACTION_SAMPLE_INDEX_VALUE ) +return -1 ; + arg =ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct action_sample_data , idx), +sizeof (((struct action_sample_data *)0 )->idx), +0 ,RAW_SAMPLE_CONFS_MAX_NUM -1 ); +if (push_args (ctx, arg)) +return -1 ; + ret =parse_int (ctx, token, str, len,NULL ,0 ); +if (ret <0 ) { +pop_args (ctx); +return -1 ; + } +if (!ctx->object) +return len; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; + action_sample_data = ctx->object; + idx = action_sample_data->idx; + action_sample_data->conf.actions = raw_sample_confs[idx].data; + action->conf = &action_sample_data->conf; +return len; +} +/** Parse tokens for destroy command. */ static int parse_destroy(struct context *ctx, const struct token *token,
@@ -6115,6 +6287,38 @@ static int comp_set_raw_index(struct context *, const struct token *,if (!out->command)return -1 ; out->command = ctx->curr; +/* For encap/decap we need is pattern */ + out->args.vc.pattern = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); +return len; +} + +/** Parse set command, initialize output buffer for subsequent tokens. */ +static int +parse_set_sample_action (struct context *ctx,const struct token *token, +const char *str,unsigned int len, +void *buf,unsigned int size) +{ +struct buffer *out = buf; + +/* Token name must match. */ +if (parse_default (ctx, token, str, len,NULL ,0 ) <0 ) +return -1 ; +/* Nothing else to do if there is no buffer. */ +if (!out) +return len; +/* Make sure buffer is large enough. */ +if (size <sizeof (*out)) +return -1 ; + ctx->objdata =0 ; + ctx->objmask =NULL ; + ctx->object = out; +if (!out->command) +return -1 ; + out->command = ctx->curr; +/* For sampler we need is actions */ + out->args.vc.actions = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double ));return len; }
@@ -6151,11 +6355,8 @@ static int comp_set_raw_index(struct context *, const struct token *,return -1 ; out->command = ctx->curr; out->args.vc.data = (uint8_t *)out + size; -/* All we need is pattern */ - out->args.vc.pattern = - (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), -sizeof (double )); - ctx->object = out->args.vc.pattern; + ctx->object = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); }return len; }
@@ -6306,6 +6507,24 @@ static int comp_set_raw_index(struct context *, const struct token *,return nb; } +/** Complete index number for set raw_encap/raw_decap commands. */ +static int +comp_set_sample_index (struct context *ctx,const struct token *token, +unsigned int ent,char *buf,unsigned int size) +{ +uint16_t idx =0 ; +uint16_t nb =0 ; + +RTE_SET_USED (ctx); +RTE_SET_USED (token); +for (idx =0 ; idx <RAW_SAMPLE_CONFS_MAX_NUM ; ++idx) { +if (buf && idx == ent) +return snprintf (buf, size,"%u" , idx); + ++nb; + } +return nb; +} +/** Internal context. */ static struct context cmd_flow_context;
@@ -6751,7 +6970,53 @@ static int comp_set_raw_index(struct context *, const struct token *,return mask; } - +/** Dispatch parsed buffer to function calls. */ +static void +cmd_set_raw_parsed_sample (const struct buffer *in) +{ +uint32_t n = in->args.vc.actions_n; +uint32_t i =0 ; +struct rte_flow_action *action =NULL ; +struct rte_flow_action *data =NULL ; +size_t size =0 ; +uint16_t idx = in->port;/* We borrow port field as index */ +uint32_t max_size =sizeof (struct rte_flow_action ) * +ACTION_SAMPLE_ACTIONS_NUM ; + +RTE_ASSERT (in->command ==SET_SAMPLE_ACTIONS ); + data = (struct rte_flow_action *)&raw_sample_confs[idx].data; +memset (data,0x00 , max_size); +for (; i <= n -1 ; i++) { + action = in->args.vc.actions + i; +if (action->type ==RTE_FLOW_ACTION_TYPE_END ) +break ; +switch (action->type) { +case RTE_FLOW_ACTION_TYPE_MARK : + size =sizeof (struct rte_flow_action_mark ); +rte_memcpy (&sample_mark[idx], + (const void *)action->conf, size); + action->conf = &sample_mark[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_COUNT : + size =sizeof (struct rte_flow_action_count ); +rte_memcpy (&sample_count[idx], + (const void *)action->conf, size); + action->conf = &sample_count[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_QUEUE : + size =sizeof (struct rte_flow_action_queue ); +rte_memcpy (&sample_queue[idx], + (const void *)action->conf, size); + action->conf = &sample_queue[idx]; +break ; +default : +printf ("Error - Not supported action\n" ); +return ; + } +rte_memcpy (data, action,sizeof (struct rte_flow_action )); + data++; + } +}/** Dispatch parsed buffer to function calls. */ static void
@@ -6768,6 +7033,8 @@ static int comp_set_raw_index(struct context *, const struct token *,uint16_t proto =0 ;uint16_t idx = in->port;/* We borrow port field as index */ +if (in->command ==SET_SAMPLE_ACTIONS ) +return cmd_set_raw_parsed_sample (in);RTE_ASSERT (in->command ==SET_RAW_ENCAP || in->command ==SET_RAW_DECAP );if (in->command ==SET_RAW_ENCAP ) {
Signature · 1 line
1.8.3.1
v6 cover support the flow-based traffic sampling
In reply to Jiawei WangThis patch set implement the flow sampling for mlx5 driver.
The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.
v6:
* Update the function that restore vport through metadata register c0 for FDB sampler.
* Add multiple destination support.
* Support the remote mirroring with different encapsulation header.
* Fix coverity error.
v5:
* Add the release note.
* Remove Make changes since it's deprecated.
v4:
* Rebase.
* Fix the coding style issue.
v3:
* Remove 'const' of ratio field.
* Update description and commit messages.
v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.
Jiawei Wang (12):
ethdev: introduce sample action for rte flow common/mlx5: glue for sample action
common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action app/testpmd: add testpmd command for sample action common/mlx5: add glue function for mirroring net/mlx5: update validation for mirroring flow net/mlx5: update translate function for mirror app/testpmd: add port and encap support for sample action net/mlx5: support the native port id actions for mirroring
app/test-pmd/cmdline_flow.c | 301 ++++++++- doc/guides/prog_guide/rte_flow.rst | 25 + doc/guides/rel_notes/release_20_11.rst | 6 + drivers/common/mlx5/linux/meson.build | 4 + drivers/common/mlx5/linux/mlx5_glue.c | 52 ++ drivers/common/mlx5/linux/mlx5_glue.h | 18 + drivers/common/mlx5/mlx5_devx_cmds.c | 27 + drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 61 ++ drivers/net/mlx5/linux/mlx5_os.c | 14 + drivers/net/mlx5/mlx5.c | 22 + drivers/net/mlx5/mlx5.h | 6 + drivers/net/mlx5/mlx5_flow.c | 344 +++++++++- drivers/net/mlx5/mlx5_flow.h | 76 ++- drivers/net/mlx5/mlx5_flow_dv.c | 1125 +++++++++++++++++++++++++++++++- lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 + 17 files changed, 2060 insertions(+), 53 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v6 1/12 ethdev: introduce sample action for rte flow
When using full offload, all traffic will be handled by the HW, and directed to the requested VF or wire, the control application loses visibility on the traffic.
So there's a need for an action that will enable the control application some visibility.
The solution is introduced a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
The packets sampled equals is '1/ratio', if the ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.
--- doc/guides/prog_guide/rte_flow.rst | 25 +++++++++++++++++++++++++ doc/guides/rel_notes/release_20_11.rst | 6 ++++++ lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
@@ -2653,6 +2653,31 @@ timeout passed without any matching on the flow. | ``context`` | user input flow context | +--------------+---------------------------------+ +Action: ``SAMPLE`` +^^^^^^^^^^^^^^^^^^ + +Adds a sample action to a matched flow. + +The matching packets will be duplicated with the specified ``ratio`` and +applied with own set of actions with a fate action, the packets sampled +equals is '1/ratio'. All the packets continue to the target destination. + +When the ``ratio`` is set to 1 then the packets will be 100% mirrored. +``actions`` represent the different set of actions for the sampled or mirrored +packets, and must have a fate action. + +.. _table_rte_flow_action_sample: + +.. table:: SAMPLE + + +--------------+---------------------------------+ + | Field | Value | + +==============+=================================+ + | ``ratio`` | 32 bits sample ratio value | + +--------------+---------------------------------+ + | ``actions`` | sub-action list for sampling | + +--------------+---------------------------------+ + Negative types ~~~~~~~~~~~~~~
doc/guides/rel_notes/release_20_11.rst +6 -0
@@ -55,6 +55,12 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added flow-based traffic sampling support.** + + Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching + packets with specified ratio, and apply with own set of actions with a fate + action. When the ratio is set to 1 then the packets will be 100% mirrored. + Removed Items -------------
lib/librte_ethdev/rte_flow.c +1 -0
@@ -174,6 +174,7 @@ struct rte_flow_desc_data {MK_FLOW_ACTION (SET_IPV4_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (SET_IPV6_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (AGE ,sizeof (struct rte_flow_action_age )), + MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)), };int
lib/librte_ethdev/rte_flow.h +30 -0
@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {* see enum RTE_ETH_EVENT_FLOW_AGED */ RTE_FLOW_ACTION_TYPE_AGE , + +/** +* The matching packets will be duplicated with specified ratio and +* applied with own set of actions with a fate action. +* +* See struct rte_flow_action_sample. +*/ + RTE_FLOW_ACTION_TYPE_SAMPLE, };/**
@@ -2742,6 +2750,28 @@ struct rte_flow_action {struct rte_flow ;/** +* @warning +* @b EXPERIMENTAL: this structure may change without prior notice +* +* RTE_FLOW_ACTION_TYPE_SAMPLE +* +* Adds a sample action to a matched flow. +* +* The matching packets will be duplicated with specified ratio and applied +* with own set of actions with a fate action, the sampled packet could be +* redirected to queue or port. All the packets continue processing on the +* default flow path. +* +* When the sample ratio is set to 1 then the packets will be 100% mirrored. +* Additional action list be supported to add for sampled or mirrored packets. +*/ +struct rte_flow_action_sample { +uint32_t ratio;/**< packets sampled equals to '1/ratio'. */ +const struct rte_flow_action *actions; +/**< sub-action list specific for the sampling hit cases. */ +}; + +/** * Verbose error types. * * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
PATCH v6 2/12 common/mlx5: glue for sample action
In reply to Jiawei Wangrdma-core introduce a new DR sample action.
Add the rdma-core commands in glue to create this action.
Sample action is used for creating the sample object to implement the sampling/mirroring function.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 13 +++++++++++++ drivers/common/mlx5/mlx5_prm.h | 10 ++++++++++ 4 files changed, 40 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -172,6 +172,8 @@ has_sym_args = [ 'RDMA_NLDEV_ATTR_NDEV_INDEX' ], [ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_domain'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
@@ -1063,6 +1063,19 @@#endif } +static void * +mlx5_glue_dr_create_flow_action_sampler ( +struct mlx5dv_dr_flow_sampler_attr *attr) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +return mlx5dv_dr_action_create_flow_sampler (attr); +#else + (void )attr; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1339,6 +1352,8 @@ .devx_port_query = mlx5_glue_devx_port_query, .dr_dump_domain = mlx5_glue_dr_dump_domain, .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, + .dr_create_flow_action_sampler = + mlx5_glue_dr_create_flow_action_sampler, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +13 -0
@@ -77,6 +77,7 @@#ifndef HAVE_MLX5DV_DR enum mlx5dv_dr_domain_type { unused, };struct mlx5dv_dr_domain ; +struct mlx5dv_dr_action ;#endif #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,16 @@struct mlx5dv_dr_flow_meter_attr ;#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +struct mlx5dv_dr_flow_sampler_attr { +uint32_t sample_ratio; +void *default_next_table; +size_t num_sample_actions; +struct mlx5dv_dr_action **sample_actions; +uint64_t action; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -309,6 +320,8 @@ struct mlx5_glue {const void *pp_context, uint32_t flags);void (*dv_free_pp)(struct mlx5dv_pp *pp); +void *(*dr_create_flow_action_sampler) + (struct mlx5dv_dr_flow_sampler_attr *attr); };extern const struct mlx5_glue *mlx5_glue;
drivers/common/mlx5/mlx5_prm.h +10 -0
@@ -1479,6 +1479,16 @@ struct mlx5_ifc_virtio_emulation_cap_bits {u8 reserved_at_0[0x8000 ]; }; +struct mlx5_ifc_set_action_in_bits { +u8 action_type[0x4 ]; +u8 field[0xc ]; +u8 reserved_at_10[0x3 ]; +u8 offset[0x5 ]; +u8 reserved_at_18[0x3 ]; +u8 length[0x5 ]; +u8 data[0x20 ]; +}; +struct mlx5_ifc_query_hca_cap_out_bits {u8 status[0x8 ];u8 reserved_at_8[0x18 ];
Signature · 1 line
1.8.3.1
PATCH v6 3/12 common/mlx5: query sampler object capability via DevX
In reply to Jiawei WangUpdate function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.
Add the related structs definition in mlx5_prm.h.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
@@ -751,6 +751,33 @@ struct mlx5_devx_obj *if (!attr->eth_net_offloads)return 0 ; +/* Query Flow Sampler Capability From FLow Table Properties Layout. */ +memset (in,0 ,sizeof (in)); +memset (out,0 ,sizeof (out)); +MLX5_SET (query_hca_cap_in, in, opcode,MLX5_CMD_OP_QUERY_HCA_CAP ); +MLX5_SET (query_hca_cap_in, in, op_mod, +MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | +MLX5_HCA_CAP_OPMOD_GET_CUR ); + + rc = mlx5_glue->devx_general_cmd (ctx, + in,sizeof (in), + out,sizeof (out)); +if (rc) + goto error; + status =MLX5_GET (query_hca_cap_out, out, status); + syndrome =MLX5_GET (query_hca_cap_out, out, syndrome); +if (status) { +DRV_LOG (DEBUG ,"Failed to query devx HCA capabilities, " +"status %x, syndrome = %x" , + status, syndrome); + attr->log_max_ft_sampler_num =0 ; +return -1 ; + } + hcattr =MLX5_ADDR_OF (query_hca_cap_out, out, capability); + attr->log_max_ft_sampler_num = +MLX5_GET (flow_table_nic_cap, + hcattr, flow_table_properties.log_max_ft_sampler_num); +/* Query HCA offloads for Ethernet protocol. */ memset (in,0 ,sizeof (in));memset (out,0 ,sizeof (out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -102,6 +102,7 @@ struct mlx5_hca_attr { uint32_t scatter_fcs_w_decap_disable:1; uint32_t regex:1;uint32_t regexp_num_of_engines; + uint32_t log_max_ft_sampler_num:8;struct mlx5_hca_qos_attr qos;struct mlx5_hca_vdpa_attr vdpa; };
drivers/common/mlx5/mlx5_prm.h +51 -0
69 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 4/12 net/mlx5: add the validate sample action
In reply to Jiawei WangAdd sample action validate function.
For Sample flow support NIC-RX and FDB domain, must include an action of a dest TIR in NIC_RX.
Only NIC_RX support with addition optional actions. FDB doesn't support any optional action, the sampled packets is always goes to e-switch manager port.
--- drivers/net/mlx5/linux/mlx5_os.c | 14 +++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_flow.h | 1 + drivers/net/mlx5/mlx5_flow_dv.c | 130 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
@@ -1016,6 +1016,20 @@ } }#endif +#if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE ) +if (config->hca_attr.log_max_ft_sampler_num >0 && + config->dv_flow_en) { + priv->sampler_en =1 ; +DRV_LOG (DEBUG ,"The Sampler enabled!\n" ); + }else { + priv->sampler_en =0 ; +if (!config->hca_attr.log_max_ft_sampler_num) +DRV_LOG (WARNING ,"No available register for" +" Sampler." ); +else +DRV_LOG (DEBUG ,"DV flow is not supported!\n" ); + } +#endif }if (config->tx_pp) { DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz",
drivers/net/mlx5/mlx5.h +1 -0
@@ -701,6 +701,7 @@ struct mlx5_priv { unsigned int counter_fallback:1; /* Use counter fallback management. */ unsigned int mtr_en:1; /* Whether support meter. */ unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */ + unsigned int sampler_en:1; /* Whether support sampler. */uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ uint32_t vport_meta_tag;/* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -196,6 +196,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)#define MLX5_FLOW_ACTION_AGE (1ull << 34)#define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35) +#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +130 -0
142 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 5/12 net/mlx5: split sample flow into two sub flows
In reply to Jiawei WangAdd the sampler action resource structs definition.
The flow with sample action will be splited into two sub flows, the prefix flow with sample action, the suffix flow with the left actions.
For the prefix flow, add the extra the tag action with unique id to metadata register, and suffix flow will add the extra tag item to match that unique id.
--- drivers/net/mlx5/mlx5.c | 11 ++ drivers/net/mlx5/mlx5.h | 3 + drivers/net/mlx5/mlx5_flow.c | 306 ++++++++++++++++++++++++++++++++++++++++--- drivers/net/mlx5/mlx5_flow.h | 37 ++++++ 4 files changed, 341 insertions(+), 16 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_jump_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_sample_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_sample_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
@@ -39,6 +39,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_TAG ,/* Pool for tag resource. */ MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ +MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -512,6 +513,7 @@ struct mlx5_flow_tbl_resource {/* Tables for metering splits should be added here. */ #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)#define MLX5_MAX_TABLES_FDB UINT16_MAX +#define MLX5_FLOW_TABLE_FACTOR 10/* ID generation structure. */ struct mlx5_flow_id_pool {
@@ -640,6 +642,7 @@ struct mlx5_dev_ctx_shared {struct mlx5_hlist *tag_table;uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ +uint32_t sample_action_list;/* List of sample actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +290 -16
399 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow.h +37 -0
@@ -507,6 +507,39 @@ struct mlx5_flow_tbl_data_entry {uint32_t idx;/**< index for the indexed mempool. */ }; +/* Sub rdma-core actions list. */ +struct mlx5_flow_sub_actions_list { +uint32_t actions_num;/**< Number of sample actions. */ +uint64_t action_flags; +void *dr_queue_action; +void *dr_tag_action; +void *dr_cnt_action; +}; + +/* Sample sub-actions resource list. */ +struct mlx5_flow_sub_actions_idx { +uint32_t rix_hrxq;/**< Hash Rx queue object index. */ +uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t cnt; +}; + +/* Sample action resource structure. */ +struct mlx5_flow_dv_sample_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +void *verbs_action;/**< Verbs sample action object. */ +uint8_t ft_type;/** Flow Table Type */ +uint32_t ft_id;/** Flow Table Level */ +uint32_t ratio;/** Sample Ratio */ +uint64_t set_action;/** Restore reg_c0 value */ +void *normal_path_tbl;/** Flow Table pointer */ +void *default_miss;/** default_miss dr_action. */ +struct mlx5_flow_sub_actions_idx sample_idx; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -539,6 +572,8 @@ struct mlx5_flow_handle_dv {/**< Index to push VLAN action resource in cache. */ uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t rix_sample; +/**< Index to sample action resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -604,6 +639,8 @@ struct mlx5_flow_dv_workspace {/**< Pointer to the jump action resource. */ struct mlx5_flow_dv_match_params value;/**< Holds the value that the packet is compared to. */ +struct mlx5_flow_dv_sample_resource *sample_res; +/**< Pointer to the sample action resource. */ };/*
Signature · 1 line
1.8.3.1
PATCH v6 6/12 net/mlx5: update translate function for sample action
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action. The metadata register value will be lost in the default path after Sampler in FDB due to CX5 HW limitation.
Since source vport also be shared with metadata register c0, MLX5 PMD would set the source vport to rdma-core and rdma-core will restore the regc0 value after sampler.
--- drivers/net/mlx5/mlx5_flow.c | 16 +- drivers/net/mlx5/mlx5_flow.h | 14 +- drivers/net/mlx5/mlx5_flow_dv.c | 507 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 515 insertions(+), 22 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
@@ -4637,10 +4637,14 @@ struct mlx5_flow_tunnel_info {int hairpin_flow;uint32_t hairpin_id =0 ;struct rte_flow_attr attr_tx = { .priority =0 }; +struct rte_flow_attr attr_factor = {0 };int ret; - hairpin_flow =flow_check_hairpin_split (dev, attr, actions); - ret =flow_drv_validate (dev, attr, items, p_actions_rx, +memcpy ((void *)&attr_factor, (const void *)attr,sizeof (*attr)); +if (external) + attr_factor.group *=MLX5_FLOW_TABLE_FACTOR ; + hairpin_flow =flow_check_hairpin_split (dev, &attr_factor, actions); + ret =flow_drv_validate (dev, &attr_factor, items, p_actions_rx, external, hairpin_flow, error);if (ret <0 )return 0 ;
@@ -4659,7 +4663,7 @@ struct mlx5_flow_tunnel_info { rte_errno =ENOMEM ; goto error_before_flow; } - flow->drv_type =flow_get_drv_type (dev, attr); + flow->drv_type =flow_get_drv_type (dev, &attr_factor);if (hairpin_id !=0 ) flow->hairpin_flow_id = hairpin_id; MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4705,7 +4709,7 @@ struct mlx5_flow_tunnel_info {* depending on configuration. In the simplest * case it just creates unmodified original flow. */ - ret =flow_create_split_outer (dev, flow, attr, + ret =flow_create_split_outer (dev, flow, &attr_factor, buf->entry[i].pattern, p_actions_rx, external, idx, error);
@@ -4742,8 +4746,8 @@ struct mlx5_flow_tunnel_info {* the egress Flows belong to the different device and * copy table should be updated in peer NIC Rx domain. */ -if (attr->ingress && - (external || attr->group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { +if (attr_factor.ingress && + (external || attr_factor.group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { ret =flow_mreg_update_copy_table (dev, flow, actions, error);if (ret) goto error;
drivers/net/mlx5/mlx5_flow.h +7 -7
@@ -366,6 +366,13 @@ enum mlx5_flow_fate_type { MLX5_FLOW_FATE_MAX, }; +/* +* Max number of actions per DV flow. +* See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED +* in rdma-core file providers/mlx5/verbs.c. +*/ +#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8 +/* Matcher PRM representation */ struct mlx5_flow_dv_match_params {size_t size;
@@ -614,13 +621,6 @@ struct mlx5_flow_handle {#define MLX5_FLOW_HANDLE_VERBS_SIZE (sizeof(struct mlx5_flow_handle))#endif -/* -* Max number of actions per DV flow. -* See CREATE_FLOW_MAX_FLOW_ACTIONS_SUPPORTED -* in rdma-core file providers/mlx5/verbs.c. -*/ -#define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8 -/** Device flow structure only for DV flow creation. */ struct mlx5_flow_dv_workspace {uint32_t group;/**< The group index. */
drivers/net/mlx5/mlx5_flow_dv.c +498 -9
592 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 7/12 app/testpmd: add testpmd command for sample action
In reply to Jiawei WangAdd a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>
The examples for the sample flow use case and result as below:
1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...
This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.
2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...
The flow will result in all the matched ingress packets will be sent to port 2, and the each second packet will also be sent to e-switch manager vport.
--- app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
@@ -56,6 +56,8 @@ enum index {SET_RAW_ENCAP ,SET_RAW_DECAP ,SET_RAW_INDEX , +SET_SAMPLE_ACTIONS , +SET_SAMPLE_INDEX ,/* Top-level command. */ FLOW,
@@ -358,6 +360,10 @@ enum index {ACTION_SET_IPV6_DSCP_VALUE ,ACTION_AGE ,ACTION_AGE_TIMEOUT , +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , + ACTION_SAMPLE_INDEX_VALUE, };/** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -493,6 +499,22 @@ struct action_nvgre_encap_data {struct mplsoudp_decap_conf mplsoudp_decap_conf; +#define ACTION_SAMPLE_ACTIONS_NUM 10 +#define RAW_SAMPLE_CONFS_MAX_NUM 8 +/** Storage for struct rte_flow_action_sample including external data. */ +struct action_sample_data { +struct rte_flow_action_sample conf; +uint32_t idx; +}; +/** Storage for struct rte_flow_action_sample. */ +struct raw_sample_conf { +struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM ]; +}; +struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1189,6 +1211,7 @@ struct parse_action_priv {ACTION_SET_IPV4_DSCP ,ACTION_SET_IPV6_DSCP ,ACTION_AGE , +ACTION_SAMPLE , ZERO, };
@@ -1421,9 +1444,28 @@ struct parse_action_priv { ZERO, }; +static const enum index action_sample[] = { +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , +ACTION_NEXT , +ZERO , +}; + +static const enum index next_action_sample[] = { +ACTION_QUEUE , +ACTION_MARK , +ACTION_COUNT , +ACTION_NEXT , +ZERO , +}; +static int parse_set_raw_encap_decap (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int ); +static int parse_set_sample_action (struct context *,const struct token *, +const char *,unsigned int , +void *,unsigned int );static int parse_set_init (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1491,7 +1533,15 @@ static int parse_vc_action_raw_decap_index(struct context *,static int parse_vc_action_set_meta (struct context *ctx,const struct token *token,const char *str,unsigned int len,void *buf, +unsigned int size); +static int parse_vc_action_sample (struct context *ctx, +const struct token *token,const char *str, +unsigned int len,void *buf,unsigned int size); +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size);static int parse_destroy (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1562,6 +1612,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *, unsigned int, char *, unsigned int);static int comp_set_raw_index (struct context *,const struct token *,unsigned int ,char *,unsigned int ); +static int comp_set_sample_index (struct context *,const struct token *, +unsigned int ,char *,unsigned int );/** Token definitions. */ static const struct token token_list[] = {
@@ -3703,11 +3755,13 @@ static int comp_set_raw_index(struct context *, const struct token *, /* Top level command. */ [SET] = { .name = "set", - .help = "set raw encap/decap data", - .type = "set raw_encap|raw_decap <index> <pattern>", + .help = "set raw encap/decap/sample data", + .type ="set raw_encap|raw_decap <index> <pattern>" + " or set sample_actions <index> <action>", .next =NEXT (NEXT_ENTRY (SET_RAW_ENCAP , - SET_RAW_DECAP)), +SET_RAW_DECAP , + SET_SAMPLE_ACTIONS)), .call = parse_set_init, },/* Sub-level commands. */
@@ -3738,6 +3792,23 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(next_item), .call = parse_port, }, + [SET_SAMPLE_INDEX] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "index of sample actions", + .next = NEXT(next_action_sample), + .call = parse_port, + }, + [SET_SAMPLE_ACTIONS] = { + .name = "sample_actions", + .help = "set sample actions list", + .next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)), + .args =ARGS (ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct buffer , port), +sizeof (((struct buffer *)0 )->port), + 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)), + .call = parse_set_sample_action, + }, [ACTION_SET_TAG] = { .name = "set_tag", .help = "set tag",
@@ -3841,6 +3912,37 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)), .call = parse_vc_conf, }, + [ACTION_SAMPLE] = { + .name = "sample", + .help = "set a sample action", + .next = NEXT(action_sample), + .priv =PRIV_ACTION (SAMPLE , + sizeof(struct action_sample_data)), + .call = parse_vc_action_sample, + }, + [ACTION_SAMPLE_RATIO] = { + .name = "ratio", + .help = "flow sample ratio value", + .next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)), + .args =ARGS (ARGS_ENTRY_ARB + (offsetof(struct action_sample_data , conf) + + offsetof(struct rte_flow_action_sample , ratio), +sizeof (((struct rte_flow_action_sample *)0 )-> + ratio))), + }, + [ACTION_SAMPLE_INDEX] = { + .name = "index", + .help = "the index of sample actions list", + .next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)), + }, + [ACTION_SAMPLE_INDEX_VALUE] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "unsigned integer value", + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc_action_sample_index, + .comp = comp_set_sample_index, + }, };/** Remove and return last entry from argument stack. */
@@ -5351,6 +5453,76 @@ static int comp_set_raw_index(struct context *, const struct token *,return len; } +static int +parse_vc_action_sample (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct buffer *out = buf; +struct rte_flow_action *action; +struct action_sample_data *action_sample_data =NULL ; +static struct rte_flow_action end_action = { +RTE_FLOW_ACTION_TYPE_END ,0 + }; +int ret; + + ret =parse_vc (ctx, token, str, len, buf, size); +if (ret <0 ) +return ret; +/* Nothing else to do if there is no buffer. */ +if (!out) +return ret; +if (!out->args.vc.actions_n) +return -1 ; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; +/* Point to selected object. */ + ctx->object = out->args.vc.data; + ctx->objmask =NULL ; +/* Copy the headers to the buffer. */ + action_sample_data = ctx->object; + action_sample_data->conf.actions = &end_action; + action->conf = &action_sample_data->conf; +return ret; +} + +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct action_sample_data *action_sample_data; +struct rte_flow_action *action; +const struct arg *arg; +struct buffer *out = buf; +int ret; +uint16_t idx; + +RTE_SET_USED (token); +RTE_SET_USED (buf); +RTE_SET_USED (size); +if (ctx->curr !=ACTION_SAMPLE_INDEX_VALUE ) +return -1 ; + arg =ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct action_sample_data , idx), +sizeof (((struct action_sample_data *)0 )->idx), +0 ,RAW_SAMPLE_CONFS_MAX_NUM -1 ); +if (push_args (ctx, arg)) +return -1 ; + ret =parse_int (ctx, token, str, len,NULL ,0 ); +if (ret <0 ) { +pop_args (ctx); +return -1 ; + } +if (!ctx->object) +return len; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; + action_sample_data = ctx->object; + idx = action_sample_data->idx; + action_sample_data->conf.actions = raw_sample_confs[idx].data; + action->conf = &action_sample_data->conf; +return len; +} +/** Parse tokens for destroy command. */ static int parse_destroy(struct context *ctx, const struct token *token,
@@ -6115,6 +6287,38 @@ static int comp_set_raw_index(struct context *, const struct token *,if (!out->command)return -1 ; out->command = ctx->curr; +/* For encap/decap we need is pattern */ + out->args.vc.pattern = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); +return len; +} + +/** Parse set command, initialize output buffer for subsequent tokens. */ +static int +parse_set_sample_action (struct context *ctx,const struct token *token, +const char *str,unsigned int len, +void *buf,unsigned int size) +{ +struct buffer *out = buf; + +/* Token name must match. */ +if (parse_default (ctx, token, str, len,NULL ,0 ) <0 ) +return -1 ; +/* Nothing else to do if there is no buffer. */ +if (!out) +return len; +/* Make sure buffer is large enough. */ +if (size <sizeof (*out)) +return -1 ; + ctx->objdata =0 ; + ctx->objmask =NULL ; + ctx->object = out; +if (!out->command) +return -1 ; + out->command = ctx->curr; +/* For sampler we need is actions */ + out->args.vc.actions = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double ));return len; }
@@ -6151,11 +6355,8 @@ static int comp_set_raw_index(struct context *, const struct token *,return -1 ; out->command = ctx->curr; out->args.vc.data = (uint8_t *)out + size; -/* All we need is pattern */ - out->args.vc.pattern = - (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), -sizeof (double )); - ctx->object = out->args.vc.pattern; + ctx->object = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); }return len; }
@@ -6306,6 +6507,24 @@ static int comp_set_raw_index(struct context *, const struct token *,return nb; } +/** Complete index number for set raw_encap/raw_decap commands. */ +static int +comp_set_sample_index (struct context *ctx,const struct token *token, +unsigned int ent,char *buf,unsigned int size) +{ +uint16_t idx =0 ; +uint16_t nb =0 ; + +RTE_SET_USED (ctx); +RTE_SET_USED (token); +for (idx =0 ; idx <RAW_SAMPLE_CONFS_MAX_NUM ; ++idx) { +if (buf && idx == ent) +return snprintf (buf, size,"%u" , idx); + ++nb; + } +return nb; +} +/** Internal context. */ static struct context cmd_flow_context;
@@ -6751,7 +6970,53 @@ static int comp_set_raw_index(struct context *, const struct token *,return mask; } - +/** Dispatch parsed buffer to function calls. */ +static void +cmd_set_raw_parsed_sample (const struct buffer *in) +{ +uint32_t n = in->args.vc.actions_n; +uint32_t i =0 ; +struct rte_flow_action *action =NULL ; +struct rte_flow_action *data =NULL ; +size_t size =0 ; +uint16_t idx = in->port;/* We borrow port field as index */ +uint32_t max_size =sizeof (struct rte_flow_action ) * +ACTION_SAMPLE_ACTIONS_NUM ; + +RTE_ASSERT (in->command ==SET_SAMPLE_ACTIONS ); + data = (struct rte_flow_action *)&raw_sample_confs[idx].data; +memset (data,0x00 , max_size); +for (; i <= n -1 ; i++) { + action = in->args.vc.actions + i; +if (action->type ==RTE_FLOW_ACTION_TYPE_END ) +break ; +switch (action->type) { +case RTE_FLOW_ACTION_TYPE_MARK : + size =sizeof (struct rte_flow_action_mark ); +rte_memcpy (&sample_mark[idx], + (const void *)action->conf, size); + action->conf = &sample_mark[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_COUNT : + size =sizeof (struct rte_flow_action_count ); +rte_memcpy (&sample_count[idx], + (const void *)action->conf, size); + action->conf = &sample_count[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_QUEUE : + size =sizeof (struct rte_flow_action_queue ); +rte_memcpy (&sample_queue[idx], + (const void *)action->conf, size); + action->conf = &sample_queue[idx]; +break ; +default : +printf ("Error - Not supported action\n" ); +return ; + } +rte_memcpy (data, action,sizeof (struct rte_flow_action )); + data++; + } +}/** Dispatch parsed buffer to function calls. */ static void
@@ -6768,6 +7033,8 @@ static int comp_set_raw_index(struct context *, const struct token *,uint16_t proto =0 ;uint16_t idx = in->port;/* We borrow port field as index */ +if (in->command ==SET_SAMPLE_ACTIONS ) +return cmd_set_raw_parsed_sample (in);RTE_ASSERT (in->command ==SET_RAW_ENCAP || in->command ==SET_RAW_DECAP );if (in->command ==SET_RAW_ENCAP ) {
Signature · 1 line
1.8.3.1
PATCH v6 8/12 common/mlx5: add glue function for mirroring
In reply to Jiawei WangUsing extend Destination list in the FTE to implement the mirroring feature.
Add two new rdma-core command for create group action and multiple destination action.
Group action which is a group of sub-action will be used together for input to multiple destination action.
Multiple destination action can be used for mirroring packet to different vport or Queue.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 37 +++++++++++++++++++++++++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 5 +++++ 3 files changed, 44 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -176,6 +176,8 @@ has_sym_args = [ 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_MULTI_DEST', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_multi_dest'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ], ] config = configuration_data()
drivers/common/mlx5/linux/mlx5_glue.c +37 -0
@@ -1076,6 +1076,39 @@#endif } +static void * +mlx5_glue_dr_create_flow_action_group (size_t num_actions,void *actions[]) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_MULTI_DEST +return mlx5dv_dr_action_create_group (num_actions, + (struct mlx5dv_dr_action **)actions); +#else + (void )num_actions; + (void )actions; + errno =ENOTSUP ; +return NULL ; +#endif +} + +static void * +mlx5_glue_dr_create_flow_action_multi_dest (void *domain, +size_t num_actions, +void *actions[]) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_MULTI_DEST +return mlx5dv_dr_action_create_multi_dest + (domain, + num_actions, + (struct mlx5dv_dr_action **)actions); +#else + (void )domain; + (void )num_actions; + (void )actions; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1354,6 +1387,10 @@ .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, .dr_create_flow_action_sampler = mlx5_glue_dr_create_flow_action_sampler, + .dr_create_flow_action_group = + mlx5_glue_dr_create_flow_action_group, + .dr_create_flow_action_multi_dest = + mlx5_glue_dr_create_flow_action_multi_dest, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +5 -0
@@ -322,6 +322,11 @@ struct mlx5_glue {void (*dv_free_pp)(struct mlx5dv_pp *pp);void *(*dr_create_flow_action_sampler) (struct mlx5dv_dr_flow_sampler_attr *attr); +void *(*dr_create_flow_action_group)(size_t num_actions, +void *actions[]); +void *(*dr_create_flow_action_multi_dest)(void *domain, +size_t num_actions, +void *actions[]); };extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
PATCH v6 9/12 net/mlx5: update validation for mirroring flow
In reply to Jiawei WangMirroring flow using sample action with ratio is 1, and it doesn't support jump action with the same one flow.
Sample action must have destination actions like port or queue for mirroring, and don't need split function as sampling flow.
--- drivers/net/mlx5/mlx5_flow.c | 26 +++++++++++++++-- drivers/net/mlx5/mlx5_flow_dv.c | 62 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 82 insertions(+), 6 deletions(-)
drivers/net/mlx5/mlx5_flow.c +24 -2
@@ -3936,16 +3936,38 @@ struct mlx5_flow_tunnel_info {*/ static int flow_check_match_action (const struct rte_flow_action actions[], -enum rte_flow_action_type action) +const struct rte_flow_attr *attr, +enum rte_flow_action_type action) { +const struct rte_flow_action_sample *sample;int actions_n =0 ; +int jump_flag =0 ;int flag =0 ; +uint32_t ratio =0 ; +int sub_type =0 ;for (; actions->type !=RTE_FLOW_ACTION_TYPE_END ; actions++) {if (actions->type == action) flag =1 ; +if (actions->type ==RTE_FLOW_ACTION_TYPE_JUMP ) + jump_flag =1 ; +if (actions->type ==RTE_FLOW_ACTION_TYPE_SAMPLE ) { + sample = actions->conf; + ratio = sample->ratio; + sub_type = ((const struct rte_flow_action *) + (sample->actions))->type; + } actions_n++; } +if (flag && action ==RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) { +if (ratio ==1 ) { +/* JUMP Action not support for Mirroring; +* Mirroring support multi-destination; +*/ +if (!jump_flag && sub_type !=RTE_FLOW_ACTION_TYPE_END ) + flag =0 ; + } + }/* Count RTE_FLOW_ACTION_TYPE_END. */ return flag ? actions_n +1 :0 ; }
@@ -4460,7 +4482,7 @@ struct mlx5_flow_tunnel_info {int ret =0 ;if (priv->sampler_en) - actions_n =flow_check_match_action (actions, + actions_n =flow_check_match_action (actions, attr,RTE_FLOW_ACTION_TYPE_SAMPLE );if (actions_n) {/* The prefix actions must includes sample, tag, end. */
drivers/net/mlx5/mlx5_flow_dv.c +58 -4
86 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 10/12 net/mlx5: update translate function for mirror
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list.
PMD will check the destination action number in current flow, if found multiple destination action, then create the new group rdma action for each destination, these group rdma actions will be used for creating the multiple destination DR action and add it into the flow.
--- drivers/net/mlx5/mlx5.c | 11 + drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.h | 24 +++ drivers/net/mlx5/mlx5_flow_dv.c | 459 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 467 insertions(+), 29 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -252,6 +252,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_sample_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_multi_dest_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_multi_dest_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +2 -0
@@ -40,6 +40,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ +MLX5_IPOOL_MULTI_DEST ,/* Pool for multi-dest resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -643,6 +644,7 @@ struct mlx5_dev_ctx_shared {uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ uint32_t sample_action_list;/* List of sample actions. */ +uint32_t multi_dest_list;/* List of multi_dest. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.h +24 -0
@@ -521,6 +521,8 @@ struct mlx5_flow_sub_actions_list {void *dr_queue_action;void *dr_tag_action;void *dr_cnt_action; +void *dr_port_id_action; +void *dr_encap_action; };/* Sample sub-actions resource list. */
@@ -528,6 +530,8 @@ struct mlx5_flow_sub_actions_idx {uint32_t rix_hrxq;/**< Hash Rx queue object index. */ uint32_t rix_tag;/**< Index to the tag action. */ uint32_t cnt; +uint32_t rix_port_id_action;/**< Index to port ID action resource. */ +uint32_t rix_encap_decap;/**< Index to encap/decap resource. */ };/* Sample action resource structure. */
@@ -547,6 +551,22 @@ struct mlx5_flow_dv_sample_resource {/**< Action resources. */ }; +#define MLX5_MAX_GROUP_NUM 2 + +/* Multi-dest action resource structure. */ +struct mlx5_flow_dv_multi_dest_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +uint8_t ft_type;/** Flow Table Type */ +uint8_t num_of_group;/**< Number of group actions. */ +void *action;/**< Pointer to the rdma core action. */ +void *group_action[MLX5_MAX_GROUP_NUM ]; +struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_GROUP_NUM ]; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_GROUP_NUM ]; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -581,6 +601,8 @@ struct mlx5_flow_handle_dv {/**< Index to the tag action. */ uint32_t rix_sample;/**< Index to sample action resource in cache. */ +uint32_t rix_multi_dest; +/**< Index to multi-dest resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -641,6 +663,8 @@ struct mlx5_flow_dv_workspace {/**< Holds the value that the packet is compared to. */ struct mlx5_flow_dv_sample_resource *sample_res;/**< Pointer to the sample action resource. */ +struct mlx5_flow_dv_multi_dest_resource *multi_dest_res; +/**< Pointer to the multi_dest resource. */ };/*
drivers/net/mlx5/mlx5_flow_dv.c +430 -29
644 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 11/12 app/testpmd: add port and encap support for sample action
In reply to Jiawei WangUse sample action with ratio is 1 for mirroring flow, add supports to set the different port or encap action for mirrored packets.
The example of test-pmd command:
1. set sample_actions 1 port_id id 1 / end
flow create 0 ... pattern eth / end actions
sample ratio 1 index 1 / port_id id 2...
The flow will result in all the matched ingress packets will be sent to port 2, and also mirrored the packets and sent to port 2.
2. set raw_encap 0 eth src.../ ipv4.../...
set raw_encap 1 eth src.../ ipv4.../...
set sample_actions 2 raw_encap index 0 / port_id id 0 / end flow create 0 ... pattern eth / end actions
sample ratio 1 index 2 / raw_encap index 1 / port_id id 0...
The flow will result in all the matched egress packets will be encapsulated and sent to wire, and also mirrored the packets and with the different encapsulated data and sent to wire.
--- app/test-pmd/cmdline_flow.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
app/test-pmd/cmdline_flow.c +16 -0
@@ -514,6 +514,8 @@ struct raw_sample_conf {struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_port_id sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_raw_encap sample_encap[RAW_SAMPLE_CONFS_MAX_NUM ];/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1456,6 +1458,8 @@ struct parse_action_priv {ACTION_QUEUE ,ACTION_MARK ,ACTION_COUNT , +ACTION_PORT_ID , +ACTION_RAW_ENCAP ,ACTION_NEXT , ZERO, };
@@ -7009,6 +7013,18 @@ static int comp_set_sample_index(struct context *, const struct token *, (const void *)action->conf, size); action->conf = &sample_queue[idx];break ; +case RTE_FLOW_ACTION_TYPE_RAW_ENCAP : + size =sizeof (struct rte_flow_action_raw_encap ); +rte_memcpy (&sample_encap[idx], + (const void *)action->conf, size); + action->conf = &sample_encap[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_PORT_ID : + size =sizeof (struct rte_flow_action_port_id ); +rte_memcpy (&sample_port_id[idx], + (const void *)action->conf, size); + action->conf = &sample_port_id[idx]; +break ;default :printf ("Error - Not supported action\n" );return ;
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v6 11/12] app/testpmd: add port and encap support for sample action
Quoted 5 lines · Jiawei Wang
Use sample action with ratio is 1 for mirroring flow, add supports to set the different port or encap action for mirrored packets.
Quoted 7 lines
The example of test-pmd command:
1. set
sample_actions1port_idid 1 / end
flow create 0 ... pattern eth / end actions
sample ratio 1 index 1 /port_idid 2...
The flow will result in all the matched ingress packets will be sent to port 2, and also mirrored the packets and sent to port 2.
^
You probably meant "and also mirrored the packets and sent to port 1"?
Quoted 59 lines
2. set
raw_encap0 eth src.../ ipv4.../...
setraw_encap1 eth src.../ ipv4.../...
setsample_actions2raw_encapindex 0 /port_idid 0 / end flow create 0 ... pattern eth / end actions
sample ratio 1 index 2 /raw_encapindex 1 /port_idid 0...
The flow will result in all the matched egress packets will be encapsulated and sent to wire, and also mirrored the packets and with the different encapsulated data and sent to wire.Signed-off-by Jiawei Wang <[email protected]>--- app/test-pmd/cmdline_flow.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)app/test-pmd/cmdline_flow.c +16
-1@@ -514,6 +514,8 @@ struct raw_sample_conf {struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_port_id sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_raw_encap sample_encap[RAW_SAMPLE_CONFS_MAX_NUM ];/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16@@ -1456,6 +1458,8 @@ struct parse_action_priv {ACTION_QUEUE ,ACTION_MARK ,ACTION_COUNT , +ACTION_PORT_ID , +ACTION_RAW_ENCAP ,ACTION_NEXT , ZERO, };@@ -7009,6 +7013,18 @@ static int comp_set_sample_index(struct context *, const struct token *, (const void *)action->conf, size); action->conf = &sample_queue[idx];break ; +case RTE_FLOW_ACTION_TYPE_RAW_ENCAP : + size =sizeof (struct rte_flow_action_raw_encap ); +rte_memcpy (&sample_encap[idx], + (const void *)action->conf, size); + action->conf = &sample_encap[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_PORT_ID : + size =sizeof (struct rte_flow_action_port_id ); +rte_memcpy (&sample_port_id[idx], + (const void *)action->conf, size); + action->conf = &sample_port_id[idx]; +break ;default :printf ("Error - Not supported action\n" );return ; --1.8.3.1
Re: [dpdk-dev] [PATCH v6 11/12] app/testpmd: add port and encap support for sample action
Yes, Nice catch.
I will fix it.
Thanks.
B.R.
Jonny
Quoted 95 lines
-----Original Message-----
From: Ajit Khaparde <[email protected]>
Sent: Tuesday, September 22, 2020 6:28 AM
To: Jiawei(Jonny) Wang <[email protected]>
Cc: Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Marko Kovacevic <[email protected]>; Andrew Rybchenko <[email protected]>; dpdk-dev <[email protected]>; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v6 11/12] app/testpmd: add port and encap support for sample actionQuoted 11 lines · Jiawei Wang
Use sample action with ratio is 1 for mirroring flow, add supports to set the different port or encap action for mirrored packets.
The example of test-pmd command:
1. set
sample_actions1port_idid 1 / end
flow create 0 ... pattern eth / end actions
sample ratio 1 index 1 /port_idid 2...
The flow will result in all the matched ingress packets will be sent to port 2, and also mirrored the packets and sent to port 2.^You probably meant "and also mirrored the packets and sent to port 1"?
Quoted 20 lines
2. set
raw_encap0 eth src.../ ipv4.../...
setraw_encap1 eth src.../ ipv4.../...
setsample_actions2raw_encapindex 0 /port_idid 0 / end flow create 0 ... pattern eth / end actions
sample ratio 1 index 2 /raw_encapindex 1 /port_idid 0...
The flow will result in all the matched egress packets will be encapsulated and sent to wire, and also mirrored the packets and with the different encapsulated data and sent to wire.Signed-off-by Jiawei Wang <[email protected]>--- app/test-pmd/cmdline_flow.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)app/test-pmd/cmdline_flow.c +0
-0app/test-pmd/cmdline_flow.c struct raw_sample_conf { struct · line 515
Quoted 2 lines
app/test-pmd/cmdline_flow.c +0
-0@@ -514,6 +514,8 @@ struct raw_sample_conf { structrte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
app/test-pmd/cmdline_flow.c struct raw_sample_conf { struct · line 516
Quoted 1 line
app/test-pmd/cmdline_flow.c +0
-0struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
app/test-pmd/cmdline_flow.c static int comp_set_sample_index(struct
Quoted 17 lines
app/test-pmd/cmdline_flow.c +4
-0+struct rte_flow_action_port_id +sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_raw_encap +sample_encap[RAW_SAMPLE_CONFS_MAX_NUM ];/** Maximum number of subsequent tokens and arguments on the stack. */ #define
CTX_STACK_SIZE16 @@ -1456,6 +1458,8 @@ structparse_action_priv{
ACTION_QUEUE,
ACTION_MARK,
ACTION_COUNT,app/test-pmd/cmdline_flow.c +2
-0+ACTION_PORT_ID , +ACTION_RAW_ENCAP ,ACTION_NEXT , ZERO, };@@ -7009,6 +7013,18 @@ static int comp_set_sample_index(structcontext *, const struct token *,
Quoted 21 lines
app/test-pmd/cmdline_flow.c +12
-1(const void *)action->conf, size); action->conf = &sample_queue[idx];break ; +case RTE_FLOW_ACTION_TYPE_RAW_ENCAP : + size =sizeof (struct rte_flow_action_raw_encap ); +rte_memcpy (&sample_encap[idx], + (const void *)action->conf, size); + action->conf = &sample_encap[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_PORT_ID : + size =sizeof (struct rte_flow_action_port_id ); +rte_memcpy (&sample_port_id[idx], + (const void *)action->conf, size); + action->conf = &sample_port_id[idx]; +break ;default :printf ("Error - Not supported action\n" );return ; --1.8.3.1
PATCH v6 12/12 net/mlx5: support the native port id actions for mirroring
In reply to Jiawei WangThis patch to support the mirroring with native port id action even without the sample action in the flow.
The flow would be like:
flow create 0 ingress transfer pattern eth / end actions
port_id id 1 / port_id id 2 / end
Ingress packet match from uplink, send to VF1 but also mirror to VF2.
While PMD parse a e-switch rule and found the multiple port actions, then will create a new multiple destination DR action and add it into the flow instead of two port id action.
--- drivers/net/mlx5/mlx5_flow_dv.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5_flow_dv.c +23 -2
@@ -3738,7 +3738,8 @@ struct field_modify_info modify_tcp[] = {"port id action parameters must be" " specified");if (action_flags & (MLX5_FLOW_FATE_ACTIONS | -MLX5_FLOW_FATE_ESWITCH_ACTIONS )) + (MLX5_FLOW_FATE_ESWITCH_ACTIONS & + ~MLX5_FLOW_ACTION_PORT_ID )))return rte_flow_error_set (error,EINVAL ,RTE_FLOW_ERROR_TYPE_ACTION ,NULL , "can have only one fate actions in"
@@ -9007,6 +9008,7 @@ struct field_modify_info modify_tcp[] = {struct mlx5_flow_dv_sample_resource sample_res;void *sample_actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS ] = {0 };struct mlx5_flow_sub_actions_list *sample_act; +struct mlx5_flow_sub_actions_list *mirror_act;uint32_t sample_act_pos =UINT32_MAX ;uint32_t num_of_dest =0 ;int tmp_actions_n =0 ;
@@ -9056,7 +9058,21 @@ struct field_modify_info modify_tcp[] = { &port_id, error))return -rte_errno; port_id_resource.port_id = port_id; -MLX5_ASSERT (!handle->rix_port_id_action); +if (handle->rix_port_id_action) { +// update for native mirror port id action +struct mlx5_flow_sub_actions_idx *mirror_idx = + &sample_res.sample_idx; + mirror_act = &sample_res.sample_act; + mirror_act->dr_port_id_action = + dev_flow->dv.port_id_action->action; + mirror_idx->rix_port_id_action = + dev_flow->handle->rix_port_id_action; + sample_actions[mirror_act->actions_num++] = + mirror_act->dr_port_id_action; + mirror_act->action_flags |= +MLX5_FLOW_ACTION_PORT_ID ; + action_flags |=MLX5_FLOW_ACTION_SAMPLE ; + }if (flow_dv_port_id_action_resource_register (dev, &port_id_resource, dev_flow, error))return -rte_errno;
@@ -9523,6 +9539,8 @@ struct field_modify_info modify_tcp[] = {RTE_FLOW_ERROR_TYPE_ACTION ,NULL , "cannot create sample action"); +if (sample_act_pos ==UINT32_MAX ) + sample_act_pos = actions_n++;if (num_of_dest >1 ) { dev_flow->dv.actions[sample_act_pos] = dev_flow->dv.multi_dest_res->action;
@@ -9555,6 +9573,9 @@ struct field_modify_info modify_tcp[] = { dev_flow->dv.actions[i]) || (sample_act->dr_port_id_action && sample_act->dr_port_id_action == + dev_flow->dv.actions[i]) || + (mirror_act->dr_port_id_action && + mirror_act->dr_port_id_action == dev_flow->dv.actions[i])) continue; temp_actions[tmp_actions_n++] = dev_flow->dv.actions[i];
Signature · 1 line
1.8.3.1
v7 cover support the flow-based traffic sampling
In reply to Jiawei WangThis patch set implement the flow sampling for mlx5 driver.
The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.
v7:
* Removed change in [PATCH 12/12] net/mlx5: support the native port id actions for mirroring, should use sample action.
* Update the PMD code to match the new rdma-core API for mirroring.
* Optimize the sample flow split routine.
* Update code changes and commit log based on the review.
* Add E-Switch sample flow limitation document.
v6:
* Update the function that restore vport through metadata register c0 for FDB sampler.
* Add multiple destination support.
* Support the remote mirroring with different encapsulation header.
* Fix coverity error.
v5:
* Add the release note.
* Remove Make changes since it's deprecated.
v4:
* Rebase.
* Fix the coding style issue.
v3:
* Remove 'const' of ratio field.
* Update description and commit messages.
v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.
Jiawei Wang (12):
ethdev: introduce sample action for rte flow common/mlx5: glue for sample action
common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action app/testpmd: add testpmd command for sample action common/mlx5: add glue function for mirroring net/mlx5: update validation for mirroring flow net/mlx5: update translate function for mirror app/testpmd: add port and encap support for sample action
doc: add E-Switch sample flow limitation description
app/test-pmd/cmdline_flow.c | 301 ++++++++- doc/guides/nics/mlx5.rst | 5 + doc/guides/prog_guide/rte_flow.rst | 25 + doc/guides/rel_notes/release_20_11.rst | 6 + drivers/common/mlx5/linux/meson.build | 4 + drivers/common/mlx5/linux/mlx5_glue.c | 37 ++ drivers/common/mlx5/linux/mlx5_glue.h | 35 + drivers/common/mlx5/mlx5_devx_cmds.c | 27 + drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 61 ++ drivers/net/mlx5/linux/mlx5_os.c | 14 + drivers/net/mlx5/mlx5.c | 22 + drivers/net/mlx5/mlx5.h | 6 + drivers/net/mlx5/mlx5_flow.c | 400 +++++++++++- drivers/net/mlx5/mlx5_flow.h | 61 ++ drivers/net/mlx5/mlx5_flow_dv.c | 1126 +++++++++++++++++++++++++++++++- lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 + 18 files changed, 2117 insertions(+), 45 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v7 1/12 ethdev: introduce sample action for rte flow
When using full offload, all traffic will be handled by the HW, and forwarded to the requested VF or wire and the control application does not see this traffic anymore. So there's a need for an action that enables the control application some forwarded traffic visibility.
The solution introduces a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
The packets sampled equals is '1/ratio', the ratio value set to 1 means that the packets will be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.
--- doc/guides/prog_guide/rte_flow.rst | 25 +++++++++++++++++++++++++ doc/guides/rel_notes/release_20_11.rst | 6 ++++++ lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
@@ -2666,6 +2666,31 @@ timeout passed without any matching on the flow. | ``context`` | user input flow context | +--------------+---------------------------------+ +Action: ``SAMPLE`` +^^^^^^^^^^^^^^^^^^ + +Adds a sample action to a matched flow. + +The matching packets will be duplicated with the specified ``ratio`` and +applied with own set of actions with a fate action, the packets sampled +equals is '1/ratio'. All the packets continue to the target destination. + +When the ``ratio`` is set to 1 then the packets will be 100% mirrored. +``actions`` represent the different set of actions for the sampled or mirrored +packets, and must have a fate action. + +.. _table_rte_flow_action_sample: + +.. table:: SAMPLE + + +--------------+---------------------------------+ + | Field | Value | + +==============+=================================+ + | ``ratio`` | 32 bits sample ratio value | + +--------------+---------------------------------+ + | ``actions`` | sub-action list for sampling | + +--------------+---------------------------------+ + Negative types ~~~~~~~~~~~~~~
doc/guides/rel_notes/release_20_11.rst +6 -0
@@ -62,6 +62,12 @@ New Features * Added support for non-zero priorities for group 0 flows * Added support for VXLAN decap combined with VLAN pop +* **Added flow-based traffic sampling support.** + + Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching + packets with specified ratio, and apply with own set of actions with a fate + action. When the ratio is set to 1 then the packets will be 100% mirrored. + Removed Items -------------
lib/librte_ethdev/rte_flow.c +1 -0
@@ -174,6 +174,7 @@ struct rte_flow_desc_data {MK_FLOW_ACTION (SET_IPV4_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (SET_IPV6_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (AGE ,sizeof (struct rte_flow_action_age )), + MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)), };int
lib/librte_ethdev/rte_flow.h +30 -0
@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {* see enum RTE_ETH_EVENT_FLOW_AGED */ RTE_FLOW_ACTION_TYPE_AGE , + +/** +* The matching packets will be duplicated with specified ratio and +* applied with own set of actions with a fate action. +* +* See struct rte_flow_action_sample. +*/ + RTE_FLOW_ACTION_TYPE_SAMPLE, };/**
@@ -2742,6 +2750,28 @@ struct rte_flow_action {struct rte_flow ;/** +* @warning +* @b EXPERIMENTAL: this structure may change without prior notice +* +* RTE_FLOW_ACTION_TYPE_SAMPLE +* +* Adds a sample action to a matched flow. +* +* The matching packets will be duplicated with specified ratio and applied +* with own set of actions with a fate action, the sampled packet could be +* redirected to queue or port. All the packets continue processing on the +* default flow path. +* +* When the sample ratio is set to 1 then the packets will be 100% mirrored. +* Additional action list be supported to add for sampled or mirrored packets. +*/ +struct rte_flow_action_sample { +uint32_t ratio;/**< packets sampled equals to '1/ratio'. */ +const struct rte_flow_action *actions; +/**< sub-action list specific for the sampling hit cases. */ +}; + +/** * Verbose error types. * * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
PATCH v7 2/12 common/mlx5: glue for sample action
In reply to Jiawei WangThe new DR sample action is supported since OFED version 5.1.2 or rdma-core version v32.
MLX5 PMD adds the rdma-core command in glue to create this action.
Sample action is used for creating the sample object to implement the sampling/mirroring function.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 13 +++++++++++++ drivers/common/mlx5/mlx5_prm.h | 10 ++++++++++ 4 files changed, 40 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -172,6 +172,8 @@ has_sym_args = [ 'RDMA_NLDEV_ATTR_NDEV_INDEX' ], [ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_domain'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
@@ -1063,6 +1063,19 @@#endif } +static void * +mlx5_glue_dr_create_flow_action_sampler ( +struct mlx5dv_dr_flow_sampler_attr *attr) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +return mlx5dv_dr_action_create_flow_sampler (attr); +#else + (void )attr; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1339,6 +1352,8 @@ .devx_port_query = mlx5_glue_devx_port_query, .dr_dump_domain = mlx5_glue_dr_dump_domain, .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, + .dr_create_flow_action_sampler = + mlx5_glue_dr_create_flow_action_sampler, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +13 -0
@@ -77,6 +77,7 @@#ifndef HAVE_MLX5DV_DR enum mlx5dv_dr_domain_type { unused, };struct mlx5dv_dr_domain ; +struct mlx5dv_dr_action ;#endif #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,16 @@struct mlx5dv_dr_flow_meter_attr ;#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +struct mlx5dv_dr_flow_sampler_attr { +uint32_t sample_ratio; +void *default_next_table; +size_t num_sample_actions; +struct mlx5dv_dr_action **sample_actions; +uint64_t action; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -309,6 +320,8 @@ struct mlx5_glue {const void *pp_context, uint32_t flags);void (*dv_free_pp)(struct mlx5dv_pp *pp); +void *(*dr_create_flow_action_sampler) + (struct mlx5dv_dr_flow_sampler_attr *attr); };extern const struct mlx5_glue *mlx5_glue;
drivers/common/mlx5/mlx5_prm.h +10 -0
@@ -1479,6 +1479,16 @@ struct mlx5_ifc_virtio_emulation_cap_bits {u8 reserved_at_0[0x8000 ]; }; +struct mlx5_ifc_set_action_in_bits { +u8 action_type[0x4 ]; +u8 field[0xc ]; +u8 reserved_at_10[0x3 ]; +u8 offset[0x5 ]; +u8 reserved_at_18[0x3 ]; +u8 length[0x5 ]; +u8 data[0x20 ]; +}; +struct mlx5_ifc_query_hca_cap_out_bits {u8 status[0x8 ];u8 reserved_at_8[0x18 ];
Signature · 1 line
1.8.3.1
PATCH v7 3/12 common/mlx5: query sampler object capability via DevX
In reply to Jiawei WangUpdate function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.
Add the related structs definition in mlx5_prm.h.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
@@ -751,6 +751,33 @@ struct mlx5_devx_obj *if (!attr->eth_net_offloads)return 0 ; +/* Query Flow Sampler Capability From FLow Table Properties Layout. */ +memset (in,0 ,sizeof (in)); +memset (out,0 ,sizeof (out)); +MLX5_SET (query_hca_cap_in, in, opcode,MLX5_CMD_OP_QUERY_HCA_CAP ); +MLX5_SET (query_hca_cap_in, in, op_mod, +MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | +MLX5_HCA_CAP_OPMOD_GET_CUR ); + + rc = mlx5_glue->devx_general_cmd (ctx, + in,sizeof (in), + out,sizeof (out)); +if (rc) + goto error; + status =MLX5_GET (query_hca_cap_out, out, status); + syndrome =MLX5_GET (query_hca_cap_out, out, syndrome); +if (status) { +DRV_LOG (DEBUG ,"Failed to query devx HCA capabilities, " +"status %x, syndrome = %x" , + status, syndrome); + attr->log_max_ft_sampler_num =0 ; +return -1 ; + } + hcattr =MLX5_ADDR_OF (query_hca_cap_out, out, capability); + attr->log_max_ft_sampler_num = +MLX5_GET (flow_table_nic_cap, + hcattr, flow_table_properties.log_max_ft_sampler_num); +/* Query HCA offloads for Ethernet protocol. */ memset (in,0 ,sizeof (in));memset (out,0 ,sizeof (out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -102,6 +102,7 @@ struct mlx5_hca_attr { uint32_t scatter_fcs_w_decap_disable:1; uint32_t regex:1;uint32_t regexp_num_of_engines; + uint32_t log_max_ft_sampler_num:8;struct mlx5_hca_qos_attr qos;struct mlx5_hca_vdpa_attr vdpa; };
drivers/common/mlx5/mlx5_prm.h +51 -0
69 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 4/12 net/mlx5: add the validate sample action
In reply to Jiawei WangAdd sample action validate function.
Sample Flow is supported in NIC-RX and FDB domains. For the NIC-RX the Sample Flow action list must include the destination queue action.
Only NIC-RX domain supports the optional actions list. FDB doesn't support any optional actions, the sampled packets is always forwarded to the E-Switch manager port.
--- drivers/net/mlx5/linux/mlx5_os.c | 14 ++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_flow.h | 1 + drivers/net/mlx5/mlx5_flow_dv.c | 137 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
@@ -1019,6 +1019,20 @@ } }#endif +#if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE ) +if (config->hca_attr.log_max_ft_sampler_num >0 && + config->dv_flow_en) { + priv->sampler_en =1 ; +DRV_LOG (DEBUG ,"The Sampler enabled!\n" ); + }else { + priv->sampler_en =0 ; +if (!config->hca_attr.log_max_ft_sampler_num) +DRV_LOG (WARNING ,"No available register for" +" Sampler." ); +else +DRV_LOG (DEBUG ,"DV flow is not supported!\n" ); + } +#endif }if (config->tx_pp) { DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz",
drivers/net/mlx5/mlx5.h +1 -0
@@ -772,6 +772,7 @@ struct mlx5_priv { unsigned int counter_fallback:1; /* Use counter fallback management. */ unsigned int mtr_en:1; /* Whether support meter. */ unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */ + unsigned int sampler_en:1; /* Whether support sampler. */uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ uint32_t vport_meta_tag;/* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -196,6 +196,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)#define MLX5_FLOW_ACTION_AGE (1ull << 34)#define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35) +#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +137 -0
149 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 5/12 net/mlx5: split sample flow into two sub flows
In reply to Jiawei WangThe flow with sample action will be splited into two sub flows:
the prefix sub flow with the all actions preceding the sample action and sample action itself, and the suffix sub flow with the actions following the sample action.
The original items remain in the prefix sub flow, add the implicit tag action with unique id to set in metadata register, and suffix sub flow uses the tag item to match with that unique id.
The flow split as below:
Original flow: items / actions pre / sample / actions sfx ->
prefix sub flow -
items / actions pre / set_tag action / sample
suffix sub flow -
tag_item / actions sfx
--- drivers/net/mlx5/mlx5.c | 11 ++ drivers/net/mlx5/mlx5.h | 3 + drivers/net/mlx5/mlx5_flow.c | 360 +++++++++++++++++++++++++++++++++++++++++-- drivers/net/mlx5/mlx5_flow.h | 37 +++++ 4 files changed, 394 insertions(+), 17 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_jump_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_sample_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_sample_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
@@ -39,6 +39,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_TAG ,/* Pool for tag resource. */ MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ +MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -512,6 +513,7 @@ struct mlx5_flow_tbl_resource {/* Tables for metering splits should be added here. */ #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)#define MLX5_MAX_TABLES_FDB UINT16_MAX +#define MLX5_FLOW_TABLE_FACTOR 10/* ID generation structure. */ struct mlx5_flow_id_pool {
@@ -640,6 +642,7 @@ struct mlx5_dev_ctx_shared {struct mlx5_hlist *tag_table;uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ +uint32_t sample_action_list;/* List of sample actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +343 -17
453 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow.h +37 -0
@@ -507,6 +507,39 @@ struct mlx5_flow_tbl_data_entry {uint32_t idx;/**< index for the indexed mempool. */ }; +/* Sub rdma-core actions list. */ +struct mlx5_flow_sub_actions_list { +uint32_t actions_num;/**< Number of sample actions. */ +uint64_t action_flags; +void *dr_queue_action; +void *dr_tag_action; +void *dr_cnt_action; +}; + +/* Sample sub-actions resource list. */ +struct mlx5_flow_sub_actions_idx { +uint32_t rix_hrxq;/**< Hash Rx queue object index. */ +uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t cnt; +}; + +/* Sample action resource structure. */ +struct mlx5_flow_dv_sample_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +void *verbs_action;/**< Verbs sample action object. */ +uint8_t ft_type;/** Flow Table Type */ +uint32_t ft_id;/** Flow Table Level */ +uint32_t ratio;/** Sample Ratio */ +uint64_t set_action;/** Restore reg_c0 value */ +void *normal_path_tbl;/** Flow Table pointer */ +void *default_miss;/** default_miss dr_action. */ +struct mlx5_flow_sub_actions_idx sample_idx; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -539,6 +572,8 @@ struct mlx5_flow_handle_dv {/**< Index to push VLAN action resource in cache. */ uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t rix_sample; +/**< Index to sample action resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -604,6 +639,8 @@ struct mlx5_flow_dv_workspace {/**< Pointer to the jump action resource. */ struct mlx5_flow_dv_match_params value;/**< Holds the value that the packet is compared to. */ +struct mlx5_flow_dv_sample_resource *sample_res; +/**< Pointer to the sample action resource. */ };/*
Signature · 1 line
1.8.3.1
PATCH v7 6/12 net/mlx5: update translate function for sample action
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.
The metadata register value will be lost in the default path after Sampler in FDB due to CX5 HW limitation.
Since source vport also be shared with metadata register c0, MLX5 PMD would set the source vport to rdma-core and rdma-core will restore the regc0 value after sampler.
--- drivers/net/mlx5/mlx5_flow.c | 16 +- drivers/net/mlx5/mlx5_flow_dv.c | 508 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 509 insertions(+), 15 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
@@ -4689,10 +4689,14 @@ struct mlx5_flow_tunnel_info {int hairpin_flow;uint32_t hairpin_id =0 ;struct rte_flow_attr attr_tx = { .priority =0 }; +struct rte_flow_attr attr_factor = {0 };int ret; - hairpin_flow =flow_check_hairpin_split (dev, attr, actions); - ret =flow_drv_validate (dev, attr, items, p_actions_rx, +memcpy ((void *)&attr_factor, (const void *)attr,sizeof (*attr)); +if (external) + attr_factor.group *=MLX5_FLOW_TABLE_FACTOR ; + hairpin_flow =flow_check_hairpin_split (dev, &attr_factor, actions); + ret =flow_drv_validate (dev, &attr_factor, items, p_actions_rx, external, hairpin_flow, error);if (ret <0 )return 0 ;
@@ -4711,7 +4715,7 @@ struct mlx5_flow_tunnel_info { rte_errno =ENOMEM ; goto error_before_flow; } - flow->drv_type =flow_get_drv_type (dev, attr); + flow->drv_type =flow_get_drv_type (dev, &attr_factor);if (hairpin_id !=0 ) flow->hairpin_flow_id = hairpin_id; MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4757,7 +4761,7 @@ struct mlx5_flow_tunnel_info {* depending on configuration. In the simplest * case it just creates unmodified original flow. */ - ret =flow_create_split_outer (dev, flow, attr, + ret =flow_create_split_outer (dev, flow, &attr_factor, buf->entry[i].pattern, p_actions_rx, external, idx, error);
@@ -4794,8 +4798,8 @@ struct mlx5_flow_tunnel_info {* the egress Flows belong to the different device and * copy table should be updated in peer NIC Rx domain. */ -if (attr->ingress && - (external || attr->group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { +if (attr_factor.ingress && + (external || attr_factor.group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { ret =flow_mreg_update_copy_table (dev, flow, actions, error);if (ret) goto error;
drivers/net/mlx5/mlx5_flow_dv.c +499 -9
593 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 7/12 app/testpmd: add testpmd command for sample action
In reply to Jiawei WangAdd a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>
The examples for the sample flow use case and result as below:
1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...
This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.
2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...
The flow will result in all the matched ingress packets will be duplicated and sent to the representor peer (VF or wire) on DPDK port 2, and the each second packet will also be sent to E-Switch manager vport.
--- app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
@@ -56,6 +56,8 @@ enum index {SET_RAW_ENCAP ,SET_RAW_DECAP ,SET_RAW_INDEX , +SET_SAMPLE_ACTIONS , +SET_SAMPLE_INDEX ,/* Top-level command. */ FLOW,
@@ -358,6 +360,10 @@ enum index {ACTION_SET_IPV6_DSCP_VALUE ,ACTION_AGE ,ACTION_AGE_TIMEOUT , +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , + ACTION_SAMPLE_INDEX_VALUE, };/** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -493,6 +499,22 @@ struct action_nvgre_encap_data {struct mplsoudp_decap_conf mplsoudp_decap_conf; +#define ACTION_SAMPLE_ACTIONS_NUM 10 +#define RAW_SAMPLE_CONFS_MAX_NUM 8 +/** Storage for struct rte_flow_action_sample including external data. */ +struct action_sample_data { +struct rte_flow_action_sample conf; +uint32_t idx; +}; +/** Storage for struct rte_flow_action_sample. */ +struct raw_sample_conf { +struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM ]; +}; +struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1189,6 +1211,7 @@ struct parse_action_priv {ACTION_SET_IPV4_DSCP ,ACTION_SET_IPV6_DSCP ,ACTION_AGE , +ACTION_SAMPLE , ZERO, };
@@ -1421,9 +1444,28 @@ struct parse_action_priv { ZERO, }; +static const enum index action_sample[] = { +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , +ACTION_NEXT , +ZERO , +}; + +static const enum index next_action_sample[] = { +ACTION_QUEUE , +ACTION_MARK , +ACTION_COUNT , +ACTION_NEXT , +ZERO , +}; +static int parse_set_raw_encap_decap (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int ); +static int parse_set_sample_action (struct context *,const struct token *, +const char *,unsigned int , +void *,unsigned int );static int parse_set_init (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1491,7 +1533,15 @@ static int parse_vc_action_raw_decap_index(struct context *,static int parse_vc_action_set_meta (struct context *ctx,const struct token *token,const char *str,unsigned int len,void *buf, +unsigned int size); +static int parse_vc_action_sample (struct context *ctx, +const struct token *token,const char *str, +unsigned int len,void *buf,unsigned int size); +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size);static int parse_destroy (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1562,6 +1612,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *, unsigned int, char *, unsigned int);static int comp_set_raw_index (struct context *,const struct token *,unsigned int ,char *,unsigned int ); +static int comp_set_sample_index (struct context *,const struct token *, +unsigned int ,char *,unsigned int );/** Token definitions. */ static const struct token token_list[] = {
@@ -3703,11 +3755,13 @@ static int comp_set_raw_index(struct context *, const struct token *, /* Top level command. */ [SET] = { .name = "set", - .help = "set raw encap/decap data", - .type = "set raw_encap|raw_decap <index> <pattern>", + .help = "set raw encap/decap/sample data", + .type ="set raw_encap|raw_decap <index> <pattern>" + " or set sample_actions <index> <action>", .next =NEXT (NEXT_ENTRY (SET_RAW_ENCAP , - SET_RAW_DECAP)), +SET_RAW_DECAP , + SET_SAMPLE_ACTIONS)), .call = parse_set_init, },/* Sub-level commands. */
@@ -3738,6 +3792,23 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(next_item), .call = parse_port, }, + [SET_SAMPLE_INDEX] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "index of sample actions", + .next = NEXT(next_action_sample), + .call = parse_port, + }, + [SET_SAMPLE_ACTIONS] = { + .name = "sample_actions", + .help = "set sample actions list", + .next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)), + .args =ARGS (ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct buffer , port), +sizeof (((struct buffer *)0 )->port), + 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)), + .call = parse_set_sample_action, + }, [ACTION_SET_TAG] = { .name = "set_tag", .help = "set tag",
@@ -3841,6 +3912,37 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)), .call = parse_vc_conf, }, + [ACTION_SAMPLE] = { + .name = "sample", + .help = "set a sample action", + .next = NEXT(action_sample), + .priv =PRIV_ACTION (SAMPLE , + sizeof(struct action_sample_data)), + .call = parse_vc_action_sample, + }, + [ACTION_SAMPLE_RATIO] = { + .name = "ratio", + .help = "flow sample ratio value", + .next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)), + .args =ARGS (ARGS_ENTRY_ARB + (offsetof(struct action_sample_data , conf) + + offsetof(struct rte_flow_action_sample , ratio), +sizeof (((struct rte_flow_action_sample *)0 )-> + ratio))), + }, + [ACTION_SAMPLE_INDEX] = { + .name = "index", + .help = "the index of sample actions list", + .next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)), + }, + [ACTION_SAMPLE_INDEX_VALUE] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "unsigned integer value", + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc_action_sample_index, + .comp = comp_set_sample_index, + }, };/** Remove and return last entry from argument stack. */
@@ -5351,6 +5453,76 @@ static int comp_set_raw_index(struct context *, const struct token *,return len; } +static int +parse_vc_action_sample (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct buffer *out = buf; +struct rte_flow_action *action; +struct action_sample_data *action_sample_data =NULL ; +static struct rte_flow_action end_action = { +RTE_FLOW_ACTION_TYPE_END ,0 + }; +int ret; + + ret =parse_vc (ctx, token, str, len, buf, size); +if (ret <0 ) +return ret; +/* Nothing else to do if there is no buffer. */ +if (!out) +return ret; +if (!out->args.vc.actions_n) +return -1 ; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; +/* Point to selected object. */ + ctx->object = out->args.vc.data; + ctx->objmask =NULL ; +/* Copy the headers to the buffer. */ + action_sample_data = ctx->object; + action_sample_data->conf.actions = &end_action; + action->conf = &action_sample_data->conf; +return ret; +} + +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct action_sample_data *action_sample_data; +struct rte_flow_action *action; +const struct arg *arg; +struct buffer *out = buf; +int ret; +uint16_t idx; + +RTE_SET_USED (token); +RTE_SET_USED (buf); +RTE_SET_USED (size); +if (ctx->curr !=ACTION_SAMPLE_INDEX_VALUE ) +return -1 ; + arg =ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct action_sample_data , idx), +sizeof (((struct action_sample_data *)0 )->idx), +0 ,RAW_SAMPLE_CONFS_MAX_NUM -1 ); +if (push_args (ctx, arg)) +return -1 ; + ret =parse_int (ctx, token, str, len,NULL ,0 ); +if (ret <0 ) { +pop_args (ctx); +return -1 ; + } +if (!ctx->object) +return len; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; + action_sample_data = ctx->object; + idx = action_sample_data->idx; + action_sample_data->conf.actions = raw_sample_confs[idx].data; + action->conf = &action_sample_data->conf; +return len; +} +/** Parse tokens for destroy command. */ static int parse_destroy(struct context *ctx, const struct token *token,
@@ -6115,6 +6287,38 @@ static int comp_set_raw_index(struct context *, const struct token *,if (!out->command)return -1 ; out->command = ctx->curr; +/* For encap/decap we need is pattern */ + out->args.vc.pattern = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); +return len; +} + +/** Parse set command, initialize output buffer for subsequent tokens. */ +static int +parse_set_sample_action (struct context *ctx,const struct token *token, +const char *str,unsigned int len, +void *buf,unsigned int size) +{ +struct buffer *out = buf; + +/* Token name must match. */ +if (parse_default (ctx, token, str, len,NULL ,0 ) <0 ) +return -1 ; +/* Nothing else to do if there is no buffer. */ +if (!out) +return len; +/* Make sure buffer is large enough. */ +if (size <sizeof (*out)) +return -1 ; + ctx->objdata =0 ; + ctx->objmask =NULL ; + ctx->object = out; +if (!out->command) +return -1 ; + out->command = ctx->curr; +/* For sampler we need is actions */ + out->args.vc.actions = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double ));return len; }
@@ -6151,11 +6355,8 @@ static int comp_set_raw_index(struct context *, const struct token *,return -1 ; out->command = ctx->curr; out->args.vc.data = (uint8_t *)out + size; -/* All we need is pattern */ - out->args.vc.pattern = - (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), -sizeof (double )); - ctx->object = out->args.vc.pattern; + ctx->object = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); }return len; }
@@ -6306,6 +6507,24 @@ static int comp_set_raw_index(struct context *, const struct token *,return nb; } +/** Complete index number for set raw_encap/raw_decap commands. */ +static int +comp_set_sample_index (struct context *ctx,const struct token *token, +unsigned int ent,char *buf,unsigned int size) +{ +uint16_t idx =0 ; +uint16_t nb =0 ; + +RTE_SET_USED (ctx); +RTE_SET_USED (token); +for (idx =0 ; idx <RAW_SAMPLE_CONFS_MAX_NUM ; ++idx) { +if (buf && idx == ent) +return snprintf (buf, size,"%u" , idx); + ++nb; + } +return nb; +} +/** Internal context. */ static struct context cmd_flow_context;
@@ -6751,7 +6970,53 @@ static int comp_set_raw_index(struct context *, const struct token *,return mask; } - +/** Dispatch parsed buffer to function calls. */ +static void +cmd_set_raw_parsed_sample (const struct buffer *in) +{ +uint32_t n = in->args.vc.actions_n; +uint32_t i =0 ; +struct rte_flow_action *action =NULL ; +struct rte_flow_action *data =NULL ; +size_t size =0 ; +uint16_t idx = in->port;/* We borrow port field as index */ +uint32_t max_size =sizeof (struct rte_flow_action ) * +ACTION_SAMPLE_ACTIONS_NUM ; + +RTE_ASSERT (in->command ==SET_SAMPLE_ACTIONS ); + data = (struct rte_flow_action *)&raw_sample_confs[idx].data; +memset (data,0x00 , max_size); +for (; i <= n -1 ; i++) { + action = in->args.vc.actions + i; +if (action->type ==RTE_FLOW_ACTION_TYPE_END ) +break ; +switch (action->type) { +case RTE_FLOW_ACTION_TYPE_MARK : + size =sizeof (struct rte_flow_action_mark ); +rte_memcpy (&sample_mark[idx], + (const void *)action->conf, size); + action->conf = &sample_mark[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_COUNT : + size =sizeof (struct rte_flow_action_count ); +rte_memcpy (&sample_count[idx], + (const void *)action->conf, size); + action->conf = &sample_count[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_QUEUE : + size =sizeof (struct rte_flow_action_queue ); +rte_memcpy (&sample_queue[idx], + (const void *)action->conf, size); + action->conf = &sample_queue[idx]; +break ; +default : +printf ("Error - Not supported action\n" ); +return ; + } +rte_memcpy (data, action,sizeof (struct rte_flow_action )); + data++; + } +}/** Dispatch parsed buffer to function calls. */ static void
@@ -6768,6 +7033,8 @@ static int comp_set_raw_index(struct context *, const struct token *,uint16_t proto =0 ;uint16_t idx = in->port;/* We borrow port field as index */ +if (in->command ==SET_SAMPLE_ACTIONS ) +return cmd_set_raw_parsed_sample (in);RTE_ASSERT (in->command ==SET_RAW_ENCAP || in->command ==SET_RAW_DECAP );if (in->command ==SET_RAW_ENCAP ) {
Signature · 1 line
1.8.3.1
PATCH v7 8/12 common/mlx5: add glue function for mirroring
In reply to Jiawei WangThe new DR destination array action is supported since the rdma-core version v32.
Destination array action is used group DR actions to a single action, And it can be used for mirroring packet and forward to every destination (port or queue) in the array.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 26 ++++++++++++++++++++++++-- drivers/common/mlx5/linux/mlx5_glue.h | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -176,6 +176,8 @@ has_sym_args = [ 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_dest_array'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ], ] config = configuration_data()
drivers/common/mlx5/linux/mlx5_glue.c +24 -2
@@ -1064,8 +1064,8 @@ }static void * -mlx5_glue_dr_create_flow_action_sampler ( -struct mlx5dv_dr_flow_sampler_attr *attr) +mlx5_glue_dr_create_flow_action_sampler + (struct mlx5dv_dr_flow_sampler_attr *attr) {#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE return mlx5dv_dr_action_create_flow_sampler (attr);
@@ -1076,6 +1076,26 @@#endif } +static void * +mlx5_glue_dr_action_create_dest_array + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +return mlx5dv_dr_action_create_dest_array + (domain, + num_dest, + dests); +#else + (void )domain; + (void )num_dest; + (void )dests; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1354,6 +1374,8 @@ .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, .dr_create_flow_action_sampler = mlx5_glue_dr_create_flow_action_sampler, + .dr_create_flow_action_dest_array = + mlx5_glue_dr_action_create_dest_array, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +22 -0
@@ -98,6 +98,24 @@ struct mlx5dv_dr_flow_sampler_attr { };#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +enum mlx5dv_dr_action_dest_type { +MLX5DV_DR_ACTION_DEST , +MLX5DV_DR_ACTION_DEST_REFORMAT , +}; +struct mlx5dv_dr_action_dest_reformat { +struct mlx5dv_dr_action *reformat; +struct mlx5dv_dr_action *dest; +}; +struct mlx5dv_dr_action_dest_attr { +enum mlx5dv_dr_action_dest_type type; +union { +struct mlx5dv_dr_action *dest; +struct mlx5dv_dr_action_dest_reformat *dest_reformat; + }; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -322,6 +340,10 @@ struct mlx5_glue {void (*dv_free_pp)(struct mlx5dv_pp *pp);void *(*dr_create_flow_action_sampler) (struct mlx5dv_dr_flow_sampler_attr *attr); +void *(*dr_create_flow_action_dest_array) + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]); };extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
PATCH v7 9/12 net/mlx5: update validation for mirroring flow
In reply to Jiawei WangMirroring flow using sample action with ratio is 1, and it doesn't support jump action with the same one flow.
Sample action must have destination actions like port or queue for mirroring, and don't need split function as sampling flow.
--- drivers/net/mlx5/mlx5_flow.c | 26 +++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 78 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.c +25 -1
@@ -3926,6 +3926,8 @@ struct mlx5_flow_tunnel_info {* * @param[in] actions * Pointer to the list of actions. +* @param[in] attr +* Flow rule attributes. * @param[in] action * The action to be check if exist. * @param[out] match_action_pos
@@ -3939,10 +3941,15 @@ struct mlx5_flow_tunnel_info {*/ static int flow_check_match_action (const struct rte_flow_action actions[], +const struct rte_flow_attr *attr,enum rte_flow_action_type action,int *match_action_pos,int *qrss_action_pos) { +const struct rte_flow_action_sample *sample;int actions_n =0 ; +int jump_flag =0 ; +uint32_t ratio =0 ; +int sub_type =0 ;int flag =0 ; *match_action_pos =-1 ;
@@ -3955,8 +3962,25 @@ struct mlx5_flow_tunnel_info {if (actions->type ==RTE_FLOW_ACTION_TYPE_QUEUE || actions->type ==RTE_FLOW_ACTION_TYPE_RSS ) *qrss_action_pos = actions_n; +if (actions->type ==RTE_FLOW_ACTION_TYPE_JUMP ) + jump_flag =1 ; +if (actions->type ==RTE_FLOW_ACTION_TYPE_SAMPLE ) { + sample = actions->conf; + ratio = sample->ratio; + sub_type = ((const struct rte_flow_action *) + (sample->actions))->type; + } actions_n++; } +if (flag && action ==RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) { +if (ratio ==1 ) { +/* JUMP Action not support for Mirroring; +* Mirroring support multi-destination; +*/ +if (!jump_flag && sub_type !=RTE_FLOW_ACTION_TYPE_END ) + flag =0 ; + } + }/* Count RTE_FLOW_ACTION_TYPE_END. */ return flag ? actions_n +1 :0 ; }
@@ -4508,7 +4532,7 @@ struct mlx5_flow_tunnel_info {int ret =0 ;if (priv->sampler_en) - actions_n =flow_check_match_action (actions, + actions_n =flow_check_match_action (actions, attr,RTE_FLOW_ACTION_TYPE_SAMPLE , &sample_action_pos, &qrss_action_pos);if (actions_n) {
drivers/net/mlx5/mlx5_flow_dv.c +74 -4
122 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 10/12 net/mlx5: update translate function for mirror
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list.
PMD will check the destination action number in current flow, if found multiple destination actions, then create the new destination array rdma action that group actions for each destination. Currently only support port or queue for destination action, and only encap action can be attached into one port destination.
--- drivers/net/mlx5/mlx5.c | 11 + drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.h | 23 ++ drivers/net/mlx5/mlx5_flow_dv.c | 461 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 468 insertions(+), 29 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -252,6 +252,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_sample_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_dest_array_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_dest_array_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +2 -0
@@ -40,6 +40,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ +MLX5_IPOOL_DEST_ARRAY ,/* Pool for destination array resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -643,6 +644,7 @@ struct mlx5_dev_ctx_shared {uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ uint32_t sample_action_list;/* List of sample actions. */ +uint32_t dest_array_list;/* List of destination array actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.h +23 -0
@@ -514,6 +514,8 @@ struct mlx5_flow_sub_actions_list {void *dr_queue_action;void *dr_tag_action;void *dr_cnt_action; +void *dr_port_id_action; +void *dr_encap_action; };/* Sample sub-actions resource list. */
@@ -521,6 +523,8 @@ struct mlx5_flow_sub_actions_idx {uint32_t rix_hrxq;/**< Hash Rx queue object index. */ uint32_t rix_tag;/**< Index to the tag action. */ uint32_t cnt; +uint32_t rix_port_id_action;/**< Index to port ID action resource. */ +uint32_t rix_encap_decap;/**< Index to encap/decap resource. */ };/* Sample action resource structure. */
@@ -540,6 +544,21 @@ struct mlx5_flow_dv_sample_resource {/**< Action resources. */ }; +#define MLX5_MAX_DEST_NUM 2 + +/* Destination array action resource structure. */ +struct mlx5_flow_dv_dest_array_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +uint8_t ft_type;/** Flow Table Type */ +uint8_t num_of_dest;/**< Number of destination actions. */ +void *action;/**< Pointer to the rdma core action. */ +struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_DEST_NUM ]; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_DEST_NUM ]; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -574,6 +593,8 @@ struct mlx5_flow_handle_dv {/**< Index to the tag action. */ uint32_t rix_sample;/**< Index to sample action resource in cache. */ +uint32_t rix_dest_array; +/**< Index to destination array resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -641,6 +662,8 @@ struct mlx5_flow_dv_workspace {/**< Holds the value that the packet is compared to. */ struct mlx5_flow_dv_sample_resource *sample_res;/**< Pointer to the sample action resource. */ +struct mlx5_flow_dv_dest_array_resource *dest_array_res; +/**< Pointer to the destination array resource. */ };/*
drivers/net/mlx5/mlx5_flow_dv.c +432 -29
646 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 11/12 app/testpmd: add port and encap support for sample action
In reply to Jiawei WangUse sample action with ratio is 1 for mirroring flow, add supports to set the different port or encap action for mirrored packets.
The example of test-pmd command:
1. set sample_actions 1 port_id id 1 / end
flow create 0 ... pattern eth / end actions
sample ratio 1 index 1 / port_id id 2...
The flow will result in all the matched ingress packets will be sent to port 2, and also mirrored the packets and sent to port 1.
2. set raw_encap 0 eth src.../ ipv4.../...
set raw_encap 1 eth src.../ ipv4.../...
set sample_actions 2 raw_encap index 0 / port_id id 0 / end flow create 0 ... pattern eth / end actions
sample ratio 1 index 2 / raw_encap index 1 / port_id id 0...
The flow will result in all the matched egress packets will be encapsulated and sent to wire, and also mirrored the packets and with the different encapsulated data and sent to wire.
--- app/test-pmd/cmdline_flow.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
app/test-pmd/cmdline_flow.c +16 -0
@@ -514,6 +514,8 @@ struct raw_sample_conf {struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_port_id sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_raw_encap sample_encap[RAW_SAMPLE_CONFS_MAX_NUM ];/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1456,6 +1458,8 @@ struct parse_action_priv {ACTION_QUEUE ,ACTION_MARK ,ACTION_COUNT , +ACTION_PORT_ID , +ACTION_RAW_ENCAP ,ACTION_NEXT , ZERO, };
@@ -7009,6 +7013,18 @@ static int comp_set_sample_index(struct context *, const struct token *, (const void *)action->conf, size); action->conf = &sample_queue[idx];break ; +case RTE_FLOW_ACTION_TYPE_RAW_ENCAP : + size =sizeof (struct rte_flow_action_raw_encap ); +rte_memcpy (&sample_encap[idx], + (const void *)action->conf, size); + action->conf = &sample_encap[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_PORT_ID : + size =sizeof (struct rte_flow_action_port_id ); +rte_memcpy (&sample_port_id[idx], + (const void *)action->conf, size); + action->conf = &sample_port_id[idx]; +break ;default :printf ("Error - Not supported action\n" );return ;
Signature · 1 line
1.8.3.1
PATCH v7 12/12 doc: add E-Switch sample flow limitation description
In reply to Jiawei WangAdd description about the E-Switch sample flow limitation. Due to Metadata register c0 is deleted while doing the loopback, so that only support forward the sampling packet into e-switch manager port, no additional action support in sample flow.
--- doc/guides/nics/mlx5.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/guides/nics/mlx5.rst +5 -0
@@ -311,6 +311,11 @@ Limitations for some NICs (such as ConnectX-6 Dx and BlueField 2). The capability bit ``scatter_fcs_w_decap_disable`` shows NIC support. +- E-Switch Sample flow: + + - The E-Switch Sample flow must have the eswitch_manager VPORT destination (PF or ECPF) and no additional actions. + - For ConnectX-5, the ``RTE_FLOW_ACTION_TYPE_SAMPLE`` is typically used as first action in the E-Switch egress flow if with header modify or encapsulation actions. + Statistics ----------
Signature · 1 line
1.8.3.1
v8 cover support the flow-based traffic sampling
In reply to Jiawei WangThis patch set implement the flow sampling for mlx5 driver.
The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.
v8:
* Rebase patches based on the latest code.
* Update the offloads dependencies document for sample flow.
* Update sample flow limitation document.
v7:
* Removed change in [PATCH 12/12] net/mlx5: support the native port id actions for mirroring, should use sample action.
* Update the PMD code to match the new rdma-core API for mirroring.
* Optimize the sample flow split routine.
* Update code changes and commit log based on the review.
* Add E-Switch sample flow limitation document.
v6:
* Update the function that restore vport through metadata register c0 for FDB sampler.
* Add multiple destination support.
* Support the remote mirroring with different encapsulation header.
* Fix coverity error.
v5:
* Add the release note.
* Remove Make changes since it's deprecated.
v4:
* Rebase.
* Fix the coding style issue.
v3:
* Remove 'const' of ratio field.
* Update description and commit messages.
v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.
Jiawei Wang (13):
ethdev: introduce sample action for rte flow common/mlx5: glue for sample action
common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action app/testpmd: add testpmd command for sample action common/mlx5: add glue function for mirroring net/mlx5: update validation for mirroring flow net/mlx5: update translate function for mirror app/testpmd: add port and encap support for sample action
doc: add the sample flow limitation description
doc: update offload dependencies document
app/test-pmd/cmdline_flow.c | 301 ++++++++- doc/guides/nics/mlx5.rst | 11 + doc/guides/prog_guide/rte_flow.rst | 25 + doc/guides/rel_notes/release_20_11.rst | 6 + drivers/common/mlx5/linux/meson.build | 4 + drivers/common/mlx5/linux/mlx5_glue.c | 37 ++ drivers/common/mlx5/linux/mlx5_glue.h | 35 + drivers/common/mlx5/mlx5_devx_cmds.c | 27 + drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 61 ++ drivers/net/mlx5/linux/mlx5_os.c | 14 + drivers/net/mlx5/mlx5.c | 22 + drivers/net/mlx5/mlx5.h | 6 + drivers/net/mlx5/mlx5_flow.c | 400 +++++++++++- drivers/net/mlx5/mlx5_flow.h | 61 ++ drivers/net/mlx5/mlx5_flow_dv.c | 1126 +++++++++++++++++++++++++++++++- lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 + 18 files changed, 2123 insertions(+), 45 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v8 1/13 ethdev: introduce sample action for rte flow
When using full offload, all traffic will be handled by the HW, and forwarded to the requested VF or wire and the control application does not see this traffic anymore. So there's a need for an action that enables the control application some forwarded traffic visibility.
The solution introduces a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
The packets sampled equals is '1/ratio', the ratio value set to 1 means that the packets will be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.
--- doc/guides/prog_guide/rte_flow.rst | 25 +++++++++++++++++++++++++ doc/guides/rel_notes/release_20_11.rst | 6 ++++++ lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
@@ -2666,6 +2666,31 @@ timeout passed without any matching on the flow. | ``context`` | user input flow context | +--------------+---------------------------------+ +Action: ``SAMPLE`` +^^^^^^^^^^^^^^^^^^ + +Adds a sample action to a matched flow. + +The matching packets will be duplicated with the specified ``ratio`` and +applied with own set of actions with a fate action, the packets sampled +equals is '1/ratio'. All the packets continue to the target destination. + +When the ``ratio`` is set to 1 then the packets will be 100% mirrored. +``actions`` represent the different set of actions for the sampled or mirrored +packets, and must have a fate action. + +.. _table_rte_flow_action_sample: + +.. table:: SAMPLE + + +--------------+---------------------------------+ + | Field | Value | + +==============+=================================+ + | ``ratio`` | 32 bits sample ratio value | + +--------------+---------------------------------+ + | ``actions`` | sub-action list for sampling | + +--------------+---------------------------------+ + Negative types ~~~~~~~~~~~~~~
doc/guides/rel_notes/release_20_11.rst +6 -0
@@ -78,6 +78,12 @@ New Features ``--portmask=N`` where N represents the hexadecimal bitmask of ports used. +* **Added flow-based traffic sampling support.** + + Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching + packets with specified ratio, and apply with own set of actions with a fate + action. When the ratio is set to 1 then the packets will be 100% mirrored. + Removed Items -------------
lib/librte_ethdev/rte_flow.c +1 -0
@@ -174,6 +174,7 @@ struct rte_flow_desc_data {MK_FLOW_ACTION (SET_IPV4_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (SET_IPV6_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (AGE ,sizeof (struct rte_flow_action_age )), + MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)), };int
lib/librte_ethdev/rte_flow.h +30 -0
@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {* see enum RTE_ETH_EVENT_FLOW_AGED */ RTE_FLOW_ACTION_TYPE_AGE , + +/** +* The matching packets will be duplicated with specified ratio and +* applied with own set of actions with a fate action. +* +* See struct rte_flow_action_sample. +*/ + RTE_FLOW_ACTION_TYPE_SAMPLE, };/**
@@ -2742,6 +2750,28 @@ struct rte_flow_action {struct rte_flow ;/** +* @warning +* @b EXPERIMENTAL: this structure may change without prior notice +* +* RTE_FLOW_ACTION_TYPE_SAMPLE +* +* Adds a sample action to a matched flow. +* +* The matching packets will be duplicated with specified ratio and applied +* with own set of actions with a fate action, the sampled packet could be +* redirected to queue or port. All the packets continue processing on the +* default flow path. +* +* When the sample ratio is set to 1 then the packets will be 100% mirrored. +* Additional action list be supported to add for sampled or mirrored packets. +*/ +struct rte_flow_action_sample { +uint32_t ratio;/**< packets sampled equals to '1/ratio'. */ +const struct rte_flow_action *actions; +/**< sub-action list specific for the sampling hit cases. */ +}; + +/** * Verbose error types. * * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v8 01/13] ethdev: introduce sample action for rte flow
Quoted 19 lines · Jiawei Wang
When using full offload, all traffic will be handled by the HW, and forwarded to the requested VF or wire and the control application does not see this traffic anymore. So there's a need for an action that enables the control application some forwarded traffic visibility.
The solution introduces a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
The packets sampled equals is '1/ratio', the ratio value set to 1 means that the packets will be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
In order to support the sample packet in
rte_flow, newrte_flowaction definitionRTE_FLOW_ACTION_TYPE_SAMPLEand structurerte_flow_action_samplewill be introduced.
Quoted 5 lines
Signed-off-by Jiawei Wang <[email protected]>Acked-by Ori Kam <[email protected]>Acked-by Jerin Jacob <[email protected]>Acked-by Andrew Rybchenko <[email protected]>
Quoted 123 lines
--- doc/guides/prog_guide/rte_flow.rst | 25 +++++++++++++++++++++++++ doc/guides/rel_notes/release_20_11.rst | 6 ++++++ lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+)doc/guides/prog_guide/rte_flow.rst +25
-0@@ -2666,6 +2666,31 @@ timeout passed without any matching on the flow. | ``context`` | user input flow context | +--------------+---------------------------------+ +Action: ``SAMPLE`` +^^^^^^^^^^^^^^^^^^ + +Adds a sample action to a matched flow. + +The matching packets will be duplicated with the specified ``ratio`` and +applied with own set of actions with a fate action, the packets sampled +equals is '1/ratio'. All the packets continue to the target destination. + +When the ``ratio`` is set to 1 then the packets will be 100% mirrored. +``actions`` represent the different set of actions for the sampled or mirrored +packets, and must have a fate action. + +.. _table_rte_flow_action_sample: + +.. table:: SAMPLE + + +--------------+---------------------------------+ + | Field | Value | + +==============+=================================+ + | ``ratio`` | 32 bits sample ratio value | + +--------------+---------------------------------+ + | ``actions`` | sub-action list for sampling | + +--------------+---------------------------------+ + Negative types ~~~~~~~~~~~~~~doc/guides/rel_notes/release_20_11.rst +6
-0@@ -78,6 +78,12 @@ New Features ``--portmask=N`` where N represents the hexadecimal bitmask of ports used. +* **Added flow-based traffic sampling support.** + + Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching + packets with specified ratio, and apply with own set of actions with a fate + action. When the ratio is set to 1 then the packets will be 100% mirrored. + Removed Items -------------lib/librte_ethdev/rte_flow.c +1
-0@@ -174,6 +174,7 @@ struct rte_flow_desc_data {MK_FLOW_ACTION (SET_IPV4_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (SET_IPV6_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (AGE ,sizeof (struct rte_flow_action_age )), + MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)), };int lib/librte_ethdev/rte_flow.h +30
-1@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {* see enum RTE_ETH_EVENT_FLOW_AGED */ RTE_FLOW_ACTION_TYPE_AGE , + +/** +* The matching packets will be duplicated with specified ratio and +* applied with own set of actions with a fate action. +* +* See struct rte_flow_action_sample. +*/ + RTE_FLOW_ACTION_TYPE_SAMPLE, };/** @@ -2742,6 +2750,28 @@ struct rte_flow_action {struct rte_flow ;/** +* @warning +* @b EXPERIMENTAL: this structure may change without prior notice +* +* RTE_FLOW_ACTION_TYPE_SAMPLE +* +* Adds a sample action to a matched flow. +* +* The matching packets will be duplicated with specified ratio and applied +* with own set of actions with a fate action, the sampled packet could be +* redirected to queue or port. All the packets continue processing on the +* default flow path. +* +* When the sample ratio is set to 1 then the packets will be 100% mirrored. +* Additional action list be supported to add for sampled or mirrored packets. +*/ +struct rte_flow_action_sample { +uint32_t ratio;/**< packets sampled equals to '1/ratio'. */ +const struct rte_flow_action *actions; +/**< sub-action list specific for the sampling hit cases. */ +}; + +/** * Verbose error types. * * Most of them provide the type of the object referenced by struct -- 1.8.3.1
PATCH v8 2/13 common/mlx5: glue for sample action
In reply to Jiawei WangThe new DR sample action is supported since OFED version 5.1.2 or rdma-core version v32.
MLX5 PMD adds the rdma-core command in glue to create this action.
Sample action is used for creating the sample object to implement the sampling/mirroring function.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 13 +++++++++++++ drivers/common/mlx5/mlx5_prm.h | 10 ++++++++++ 4 files changed, 40 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -172,6 +172,8 @@ has_sym_args = [ 'RDMA_NLDEV_ATTR_NDEV_INDEX' ], [ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_domain'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
@@ -1063,6 +1063,19 @@#endif } +static void * +mlx5_glue_dr_create_flow_action_sampler ( +struct mlx5dv_dr_flow_sampler_attr *attr) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +return mlx5dv_dr_action_create_flow_sampler (attr); +#else + (void )attr; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1339,6 +1352,8 @@ .devx_port_query = mlx5_glue_devx_port_query, .dr_dump_domain = mlx5_glue_dr_dump_domain, .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, + .dr_create_flow_action_sampler = + mlx5_glue_dr_create_flow_action_sampler, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +13 -0
@@ -77,6 +77,7 @@#ifndef HAVE_MLX5DV_DR enum mlx5dv_dr_domain_type { unused, };struct mlx5dv_dr_domain ; +struct mlx5dv_dr_action ;#endif #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,16 @@struct mlx5dv_dr_flow_meter_attr ;#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +struct mlx5dv_dr_flow_sampler_attr { +uint32_t sample_ratio; +void *default_next_table; +size_t num_sample_actions; +struct mlx5dv_dr_action **sample_actions; +uint64_t action; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -309,6 +320,8 @@ struct mlx5_glue {const void *pp_context, uint32_t flags);void (*dv_free_pp)(struct mlx5dv_pp *pp); +void *(*dr_create_flow_action_sampler) + (struct mlx5dv_dr_flow_sampler_attr *attr); };extern const struct mlx5_glue *mlx5_glue;
drivers/common/mlx5/mlx5_prm.h +10 -0
@@ -1479,6 +1479,16 @@ struct mlx5_ifc_virtio_emulation_cap_bits {u8 reserved_at_0[0x8000 ]; }; +struct mlx5_ifc_set_action_in_bits { +u8 action_type[0x4 ]; +u8 field[0xc ]; +u8 reserved_at_10[0x3 ]; +u8 offset[0x5 ]; +u8 reserved_at_18[0x3 ]; +u8 length[0x5 ]; +u8 data[0x20 ]; +}; +struct mlx5_ifc_query_hca_cap_out_bits {u8 status[0x8 ];u8 reserved_at_8[0x18 ];
Signature · 1 line
1.8.3.1
PATCH v8 3/13 common/mlx5: query sampler object capability via DevX
In reply to Jiawei WangUpdate function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.
Add the related structs definition in mlx5_prm.h.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
@@ -751,6 +751,33 @@ struct mlx5_devx_obj *if (!attr->eth_net_offloads)return 0 ; +/* Query Flow Sampler Capability From FLow Table Properties Layout. */ +memset (in,0 ,sizeof (in)); +memset (out,0 ,sizeof (out)); +MLX5_SET (query_hca_cap_in, in, opcode,MLX5_CMD_OP_QUERY_HCA_CAP ); +MLX5_SET (query_hca_cap_in, in, op_mod, +MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | +MLX5_HCA_CAP_OPMOD_GET_CUR ); + + rc = mlx5_glue->devx_general_cmd (ctx, + in,sizeof (in), + out,sizeof (out)); +if (rc) + goto error; + status =MLX5_GET (query_hca_cap_out, out, status); + syndrome =MLX5_GET (query_hca_cap_out, out, syndrome); +if (status) { +DRV_LOG (DEBUG ,"Failed to query devx HCA capabilities, " +"status %x, syndrome = %x" , + status, syndrome); + attr->log_max_ft_sampler_num =0 ; +return -1 ; + } + hcattr =MLX5_ADDR_OF (query_hca_cap_out, out, capability); + attr->log_max_ft_sampler_num = +MLX5_GET (flow_table_nic_cap, + hcattr, flow_table_properties.log_max_ft_sampler_num); +/* Query HCA offloads for Ethernet protocol. */ memset (in,0 ,sizeof (in));memset (out,0 ,sizeof (out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -102,6 +102,7 @@ struct mlx5_hca_attr { uint32_t scatter_fcs_w_decap_disable:1; uint32_t regex:1;uint32_t regexp_num_of_engines; + uint32_t log_max_ft_sampler_num:8;struct mlx5_hca_qos_attr qos;struct mlx5_hca_vdpa_attr vdpa; };
drivers/common/mlx5/mlx5_prm.h +51 -0
69 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 4/13 net/mlx5: add the validate sample action
In reply to Jiawei WangAdd sample action validate function.
Sample Flow is supported in NIC-RX and FDB domains. For the NIC-RX the Sample Flow action list must include the destination queue action.
Only NIC-RX domain supports the optional actions list. FDB doesn't support any optional actions, the sampled packets is always forwarded to the E-Switch manager port.
--- drivers/net/mlx5/linux/mlx5_os.c | 14 ++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_flow.h | 1 + drivers/net/mlx5/mlx5_flow_dv.c | 137 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
@@ -1035,6 +1035,20 @@ } }#endif +#if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE ) +if (config->hca_attr.log_max_ft_sampler_num >0 && + config->dv_flow_en) { + priv->sampler_en =1 ; +DRV_LOG (DEBUG ,"The Sampler enabled!\n" ); + }else { + priv->sampler_en =0 ; +if (!config->hca_attr.log_max_ft_sampler_num) +DRV_LOG (WARNING ,"No available register for" +" Sampler." ); +else +DRV_LOG (DEBUG ,"DV flow is not supported!\n" ); + } +#endif }if (config->tx_pp) { DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz",
drivers/net/mlx5/mlx5.h +1 -0
@@ -772,6 +772,7 @@ struct mlx5_priv { unsigned int counter_fallback:1; /* Use counter fallback management. */ unsigned int mtr_en:1; /* Whether support meter. */ unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */ + unsigned int sampler_en:1; /* Whether support sampler. */uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ uint32_t vport_meta_tag;/* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -196,6 +196,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)#define MLX5_FLOW_ACTION_AGE (1ull << 34)#define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35) +#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +137 -0
149 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 5/13 net/mlx5: split sample flow into two sub flows
In reply to Jiawei WangThe flow with sample action will be splited into two sub flows:
the prefix sub flow with the all actions preceding the sample action and sample action itself, and the suffix sub flow with the actions following the sample action.
The original items remain in the prefix sub flow, add the implicit tag action with unique id to set in metadata register, and suffix sub flow uses the tag item to match with that unique id.
The flow split as below:
Original flow: items / actions pre / sample / actions sfx ->
prefix sub flow -
items / actions pre / set_tag action / sample
suffix sub flow -
tag_item / actions sfx
--- drivers/net/mlx5/mlx5.c | 11 ++ drivers/net/mlx5/mlx5.h | 3 + drivers/net/mlx5/mlx5_flow.c | 360 +++++++++++++++++++++++++++++++++++++++++-- drivers/net/mlx5/mlx5_flow.h | 37 +++++ 4 files changed, 394 insertions(+), 17 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_jump_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_sample_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_sample_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
@@ -39,6 +39,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_TAG ,/* Pool for tag resource. */ MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ +MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -512,6 +513,7 @@ struct mlx5_flow_tbl_resource {/* Tables for metering splits should be added here. */ #define MLX5_MAX_TABLES_EXTERNAL (MLX5_MAX_TABLES - 3)#define MLX5_MAX_TABLES_FDB UINT16_MAX +#define MLX5_FLOW_TABLE_FACTOR 10/* ID generation structure. */ struct mlx5_flow_id_pool {
@@ -640,6 +642,7 @@ struct mlx5_dev_ctx_shared {struct mlx5_hlist *tag_table;uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ +uint32_t sample_action_list;/* List of sample actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +343 -17
453 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow.h +37 -0
@@ -520,6 +520,39 @@ struct mlx5_flow_tbl_data_entry {uint32_t idx;/**< index for the indexed mempool. */ }; +/* Sub rdma-core actions list. */ +struct mlx5_flow_sub_actions_list { +uint32_t actions_num;/**< Number of sample actions. */ +uint64_t action_flags; +void *dr_queue_action; +void *dr_tag_action; +void *dr_cnt_action; +}; + +/* Sample sub-actions resource list. */ +struct mlx5_flow_sub_actions_idx { +uint32_t rix_hrxq;/**< Hash Rx queue object index. */ +uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t cnt; +}; + +/* Sample action resource structure. */ +struct mlx5_flow_dv_sample_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +void *verbs_action;/**< Verbs sample action object. */ +uint8_t ft_type;/** Flow Table Type */ +uint32_t ft_id;/** Flow Table Level */ +uint32_t ratio;/** Sample Ratio */ +uint64_t set_action;/** Restore reg_c0 value */ +void *normal_path_tbl;/** Flow Table pointer */ +void *default_miss;/** default_miss dr_action. */ +struct mlx5_flow_sub_actions_idx sample_idx; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -552,6 +585,8 @@ struct mlx5_flow_handle_dv {/**< Index to push VLAN action resource in cache. */ uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t rix_sample; +/**< Index to sample action resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -617,6 +652,8 @@ struct mlx5_flow_dv_workspace {/**< Pointer to the jump action resource. */ struct mlx5_flow_dv_match_params value;/**< Holds the value that the packet is compared to. */ +struct mlx5_flow_dv_sample_resource *sample_res; +/**< Pointer to the sample action resource. */ };/*
Signature · 1 line
1.8.3.1
PATCH v8 6/13 net/mlx5: update translate function for sample action
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.
The metadata register value will be lost in the default path after Sampler in FDB due to CX5 HW limitation.
Since source vport also be shared with metadata register c0, MLX5 PMD would set the source vport to rdma-core and rdma-core will restore the regc0 value after sampler.
--- drivers/net/mlx5/mlx5_flow.c | 16 +- drivers/net/mlx5/mlx5_flow_dv.c | 508 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 509 insertions(+), 15 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
@@ -4682,10 +4682,14 @@ struct mlx5_flow_tunnel_info {int hairpin_flow;uint32_t hairpin_id =0 ;struct rte_flow_attr attr_tx = { .priority =0 }; +struct rte_flow_attr attr_factor = {0 };int ret; - hairpin_flow =flow_check_hairpin_split (dev, attr, actions); - ret =flow_drv_validate (dev, attr, items, p_actions_rx, +memcpy ((void *)&attr_factor, (const void *)attr,sizeof (*attr)); +if (external) + attr_factor.group *=MLX5_FLOW_TABLE_FACTOR ; + hairpin_flow =flow_check_hairpin_split (dev, &attr_factor, actions); + ret =flow_drv_validate (dev, &attr_factor, items, p_actions_rx, external, hairpin_flow, error);if (ret <0 )return 0 ;
@@ -4704,7 +4708,7 @@ struct mlx5_flow_tunnel_info { rte_errno =ENOMEM ; goto error_before_flow; } - flow->drv_type =flow_get_drv_type (dev, attr); + flow->drv_type =flow_get_drv_type (dev, &attr_factor);if (hairpin_id !=0 ) flow->hairpin_flow_id = hairpin_id; MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -4750,7 +4754,7 @@ struct mlx5_flow_tunnel_info {* depending on configuration. In the simplest * case it just creates unmodified original flow. */ - ret =flow_create_split_outer (dev, flow, attr, + ret =flow_create_split_outer (dev, flow, &attr_factor, buf->entry[i].pattern, p_actions_rx, external, idx, error);
@@ -4787,8 +4791,8 @@ struct mlx5_flow_tunnel_info {* the egress Flows belong to the different device and * copy table should be updated in peer NIC Rx domain. */ -if (attr->ingress && - (external || attr->group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { +if (attr_factor.ingress && + (external || attr_factor.group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { ret =flow_mreg_update_copy_table (dev, flow, actions, error);if (ret) goto error;
drivers/net/mlx5/mlx5_flow_dv.c +499 -9
593 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 7/13 app/testpmd: add testpmd command for sample action
In reply to Jiawei WangAdd a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>
The examples for the sample flow use case and result as below:
1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...
This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.
2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...
The flow will result in all the matched ingress packets will be duplicated and sent to the representor peer (VF or wire) on DPDK port 2, and the each second packet will also be sent to E-Switch manager vport.
--- app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
@@ -56,6 +56,8 @@ enum index {SET_RAW_ENCAP ,SET_RAW_DECAP ,SET_RAW_INDEX , +SET_SAMPLE_ACTIONS , +SET_SAMPLE_INDEX ,/* Top-level command. */ FLOW,
@@ -358,6 +360,10 @@ enum index {ACTION_SET_IPV6_DSCP_VALUE ,ACTION_AGE ,ACTION_AGE_TIMEOUT , +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , + ACTION_SAMPLE_INDEX_VALUE, };/** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -493,6 +499,22 @@ struct action_nvgre_encap_data {struct mplsoudp_decap_conf mplsoudp_decap_conf; +#define ACTION_SAMPLE_ACTIONS_NUM 10 +#define RAW_SAMPLE_CONFS_MAX_NUM 8 +/** Storage for struct rte_flow_action_sample including external data. */ +struct action_sample_data { +struct rte_flow_action_sample conf; +uint32_t idx; +}; +/** Storage for struct rte_flow_action_sample. */ +struct raw_sample_conf { +struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM ]; +}; +struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1189,6 +1211,7 @@ struct parse_action_priv {ACTION_SET_IPV4_DSCP ,ACTION_SET_IPV6_DSCP ,ACTION_AGE , +ACTION_SAMPLE , ZERO, };
@@ -1421,9 +1444,28 @@ struct parse_action_priv { ZERO, }; +static const enum index action_sample[] = { +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , +ACTION_NEXT , +ZERO , +}; + +static const enum index next_action_sample[] = { +ACTION_QUEUE , +ACTION_MARK , +ACTION_COUNT , +ACTION_NEXT , +ZERO , +}; +static int parse_set_raw_encap_decap (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int ); +static int parse_set_sample_action (struct context *,const struct token *, +const char *,unsigned int , +void *,unsigned int );static int parse_set_init (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1491,7 +1533,15 @@ static int parse_vc_action_raw_decap_index(struct context *,static int parse_vc_action_set_meta (struct context *ctx,const struct token *token,const char *str,unsigned int len,void *buf, +unsigned int size); +static int parse_vc_action_sample (struct context *ctx, +const struct token *token,const char *str, +unsigned int len,void *buf,unsigned int size); +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size);static int parse_destroy (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1562,6 +1612,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *, unsigned int, char *, unsigned int);static int comp_set_raw_index (struct context *,const struct token *,unsigned int ,char *,unsigned int ); +static int comp_set_sample_index (struct context *,const struct token *, +unsigned int ,char *,unsigned int );/** Token definitions. */ static const struct token token_list[] = {
@@ -3703,11 +3755,13 @@ static int comp_set_raw_index(struct context *, const struct token *, /* Top level command. */ [SET] = { .name = "set", - .help = "set raw encap/decap data", - .type = "set raw_encap|raw_decap <index> <pattern>", + .help = "set raw encap/decap/sample data", + .type ="set raw_encap|raw_decap <index> <pattern>" + " or set sample_actions <index> <action>", .next =NEXT (NEXT_ENTRY (SET_RAW_ENCAP , - SET_RAW_DECAP)), +SET_RAW_DECAP , + SET_SAMPLE_ACTIONS)), .call = parse_set_init, },/* Sub-level commands. */
@@ -3738,6 +3792,23 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(next_item), .call = parse_port, }, + [SET_SAMPLE_INDEX] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "index of sample actions", + .next = NEXT(next_action_sample), + .call = parse_port, + }, + [SET_SAMPLE_ACTIONS] = { + .name = "sample_actions", + .help = "set sample actions list", + .next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)), + .args =ARGS (ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct buffer , port), +sizeof (((struct buffer *)0 )->port), + 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)), + .call = parse_set_sample_action, + }, [ACTION_SET_TAG] = { .name = "set_tag", .help = "set tag",
@@ -3841,6 +3912,37 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)), .call = parse_vc_conf, }, + [ACTION_SAMPLE] = { + .name = "sample", + .help = "set a sample action", + .next = NEXT(action_sample), + .priv =PRIV_ACTION (SAMPLE , + sizeof(struct action_sample_data)), + .call = parse_vc_action_sample, + }, + [ACTION_SAMPLE_RATIO] = { + .name = "ratio", + .help = "flow sample ratio value", + .next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)), + .args =ARGS (ARGS_ENTRY_ARB + (offsetof(struct action_sample_data , conf) + + offsetof(struct rte_flow_action_sample , ratio), +sizeof (((struct rte_flow_action_sample *)0 )-> + ratio))), + }, + [ACTION_SAMPLE_INDEX] = { + .name = "index", + .help = "the index of sample actions list", + .next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)), + }, + [ACTION_SAMPLE_INDEX_VALUE] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "unsigned integer value", + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc_action_sample_index, + .comp = comp_set_sample_index, + }, };/** Remove and return last entry from argument stack. */
@@ -5351,6 +5453,76 @@ static int comp_set_raw_index(struct context *, const struct token *,return len; } +static int +parse_vc_action_sample (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct buffer *out = buf; +struct rte_flow_action *action; +struct action_sample_data *action_sample_data =NULL ; +static struct rte_flow_action end_action = { +RTE_FLOW_ACTION_TYPE_END ,0 + }; +int ret; + + ret =parse_vc (ctx, token, str, len, buf, size); +if (ret <0 ) +return ret; +/* Nothing else to do if there is no buffer. */ +if (!out) +return ret; +if (!out->args.vc.actions_n) +return -1 ; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; +/* Point to selected object. */ + ctx->object = out->args.vc.data; + ctx->objmask =NULL ; +/* Copy the headers to the buffer. */ + action_sample_data = ctx->object; + action_sample_data->conf.actions = &end_action; + action->conf = &action_sample_data->conf; +return ret; +} + +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct action_sample_data *action_sample_data; +struct rte_flow_action *action; +const struct arg *arg; +struct buffer *out = buf; +int ret; +uint16_t idx; + +RTE_SET_USED (token); +RTE_SET_USED (buf); +RTE_SET_USED (size); +if (ctx->curr !=ACTION_SAMPLE_INDEX_VALUE ) +return -1 ; + arg =ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct action_sample_data , idx), +sizeof (((struct action_sample_data *)0 )->idx), +0 ,RAW_SAMPLE_CONFS_MAX_NUM -1 ); +if (push_args (ctx, arg)) +return -1 ; + ret =parse_int (ctx, token, str, len,NULL ,0 ); +if (ret <0 ) { +pop_args (ctx); +return -1 ; + } +if (!ctx->object) +return len; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; + action_sample_data = ctx->object; + idx = action_sample_data->idx; + action_sample_data->conf.actions = raw_sample_confs[idx].data; + action->conf = &action_sample_data->conf; +return len; +} +/** Parse tokens for destroy command. */ static int parse_destroy(struct context *ctx, const struct token *token,
@@ -6115,6 +6287,38 @@ static int comp_set_raw_index(struct context *, const struct token *,if (!out->command)return -1 ; out->command = ctx->curr; +/* For encap/decap we need is pattern */ + out->args.vc.pattern = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); +return len; +} + +/** Parse set command, initialize output buffer for subsequent tokens. */ +static int +parse_set_sample_action (struct context *ctx,const struct token *token, +const char *str,unsigned int len, +void *buf,unsigned int size) +{ +struct buffer *out = buf; + +/* Token name must match. */ +if (parse_default (ctx, token, str, len,NULL ,0 ) <0 ) +return -1 ; +/* Nothing else to do if there is no buffer. */ +if (!out) +return len; +/* Make sure buffer is large enough. */ +if (size <sizeof (*out)) +return -1 ; + ctx->objdata =0 ; + ctx->objmask =NULL ; + ctx->object = out; +if (!out->command) +return -1 ; + out->command = ctx->curr; +/* For sampler we need is actions */ + out->args.vc.actions = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double ));return len; }
@@ -6151,11 +6355,8 @@ static int comp_set_raw_index(struct context *, const struct token *,return -1 ; out->command = ctx->curr; out->args.vc.data = (uint8_t *)out + size; -/* All we need is pattern */ - out->args.vc.pattern = - (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), -sizeof (double )); - ctx->object = out->args.vc.pattern; + ctx->object = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); }return len; }
@@ -6306,6 +6507,24 @@ static int comp_set_raw_index(struct context *, const struct token *,return nb; } +/** Complete index number for set raw_encap/raw_decap commands. */ +static int +comp_set_sample_index (struct context *ctx,const struct token *token, +unsigned int ent,char *buf,unsigned int size) +{ +uint16_t idx =0 ; +uint16_t nb =0 ; + +RTE_SET_USED (ctx); +RTE_SET_USED (token); +for (idx =0 ; idx <RAW_SAMPLE_CONFS_MAX_NUM ; ++idx) { +if (buf && idx == ent) +return snprintf (buf, size,"%u" , idx); + ++nb; + } +return nb; +} +/** Internal context. */ static struct context cmd_flow_context;
@@ -6751,7 +6970,53 @@ static int comp_set_raw_index(struct context *, const struct token *,return mask; } - +/** Dispatch parsed buffer to function calls. */ +static void +cmd_set_raw_parsed_sample (const struct buffer *in) +{ +uint32_t n = in->args.vc.actions_n; +uint32_t i =0 ; +struct rte_flow_action *action =NULL ; +struct rte_flow_action *data =NULL ; +size_t size =0 ; +uint16_t idx = in->port;/* We borrow port field as index */ +uint32_t max_size =sizeof (struct rte_flow_action ) * +ACTION_SAMPLE_ACTIONS_NUM ; + +RTE_ASSERT (in->command ==SET_SAMPLE_ACTIONS ); + data = (struct rte_flow_action *)&raw_sample_confs[idx].data; +memset (data,0x00 , max_size); +for (; i <= n -1 ; i++) { + action = in->args.vc.actions + i; +if (action->type ==RTE_FLOW_ACTION_TYPE_END ) +break ; +switch (action->type) { +case RTE_FLOW_ACTION_TYPE_MARK : + size =sizeof (struct rte_flow_action_mark ); +rte_memcpy (&sample_mark[idx], + (const void *)action->conf, size); + action->conf = &sample_mark[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_COUNT : + size =sizeof (struct rte_flow_action_count ); +rte_memcpy (&sample_count[idx], + (const void *)action->conf, size); + action->conf = &sample_count[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_QUEUE : + size =sizeof (struct rte_flow_action_queue ); +rte_memcpy (&sample_queue[idx], + (const void *)action->conf, size); + action->conf = &sample_queue[idx]; +break ; +default : +printf ("Error - Not supported action\n" ); +return ; + } +rte_memcpy (data, action,sizeof (struct rte_flow_action )); + data++; + } +}/** Dispatch parsed buffer to function calls. */ static void
@@ -6768,6 +7033,8 @@ static int comp_set_raw_index(struct context *, const struct token *,uint16_t proto =0 ;uint16_t idx = in->port;/* We borrow port field as index */ +if (in->command ==SET_SAMPLE_ACTIONS ) +return cmd_set_raw_parsed_sample (in);RTE_ASSERT (in->command ==SET_RAW_ENCAP || in->command ==SET_RAW_DECAP );if (in->command ==SET_RAW_ENCAP ) {
Signature · 1 line
1.8.3.1
PATCH v8 8/13 common/mlx5: add glue function for mirroring
In reply to Jiawei WangThe new DR destination array action is supported since the rdma-core version v32.
Destination array action is used group DR actions to a single action, And it can be used for mirroring packet and forward to every destination (port or queue) in the array.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 26 ++++++++++++++++++++++++-- drivers/common/mlx5/linux/mlx5_glue.h | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -176,6 +176,8 @@ has_sym_args = [ 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_dest_array'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ], ] config = configuration_data()
drivers/common/mlx5/linux/mlx5_glue.c +24 -2
@@ -1064,8 +1064,8 @@ }static void * -mlx5_glue_dr_create_flow_action_sampler ( -struct mlx5dv_dr_flow_sampler_attr *attr) +mlx5_glue_dr_create_flow_action_sampler + (struct mlx5dv_dr_flow_sampler_attr *attr) {#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE return mlx5dv_dr_action_create_flow_sampler (attr);
@@ -1076,6 +1076,26 @@#endif } +static void * +mlx5_glue_dr_action_create_dest_array + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +return mlx5dv_dr_action_create_dest_array + (domain, + num_dest, + dests); +#else + (void )domain; + (void )num_dest; + (void )dests; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1354,6 +1374,8 @@ .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, .dr_create_flow_action_sampler = mlx5_glue_dr_create_flow_action_sampler, + .dr_create_flow_action_dest_array = + mlx5_glue_dr_action_create_dest_array, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +22 -0
@@ -98,6 +98,24 @@ struct mlx5dv_dr_flow_sampler_attr { };#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +enum mlx5dv_dr_action_dest_type { +MLX5DV_DR_ACTION_DEST , +MLX5DV_DR_ACTION_DEST_REFORMAT , +}; +struct mlx5dv_dr_action_dest_reformat { +struct mlx5dv_dr_action *reformat; +struct mlx5dv_dr_action *dest; +}; +struct mlx5dv_dr_action_dest_attr { +enum mlx5dv_dr_action_dest_type type; +union { +struct mlx5dv_dr_action *dest; +struct mlx5dv_dr_action_dest_reformat *dest_reformat; + }; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -322,6 +340,10 @@ struct mlx5_glue {void (*dv_free_pp)(struct mlx5dv_pp *pp);void *(*dr_create_flow_action_sampler) (struct mlx5dv_dr_flow_sampler_attr *attr); +void *(*dr_create_flow_action_dest_array) + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]); };extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
PATCH v8 9/13 net/mlx5: update validation for mirroring flow
In reply to Jiawei WangMirroring flow using sample action with ratio is 1, and it doesn't support jump action with the same one flow.
Sample action must have destination actions like port or queue for mirroring, and don't need split function as sampling flow.
--- drivers/net/mlx5/mlx5_flow.c | 26 +++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 78 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.c +25 -1
@@ -3919,6 +3919,8 @@ struct mlx5_flow_tunnel_info {* * @param[in] actions * Pointer to the list of actions. +* @param[in] attr +* Flow rule attributes. * @param[in] action * The action to be check if exist. * @param[out] match_action_pos
@@ -3932,10 +3934,15 @@ struct mlx5_flow_tunnel_info {*/ static int flow_check_match_action (const struct rte_flow_action actions[], +const struct rte_flow_attr *attr,enum rte_flow_action_type action,int *match_action_pos,int *qrss_action_pos) { +const struct rte_flow_action_sample *sample;int actions_n =0 ; +int jump_flag =0 ; +uint32_t ratio =0 ; +int sub_type =0 ;int flag =0 ; *match_action_pos =-1 ;
@@ -3948,8 +3955,25 @@ struct mlx5_flow_tunnel_info {if (actions->type ==RTE_FLOW_ACTION_TYPE_QUEUE || actions->type ==RTE_FLOW_ACTION_TYPE_RSS ) *qrss_action_pos = actions_n; +if (actions->type ==RTE_FLOW_ACTION_TYPE_JUMP ) + jump_flag =1 ; +if (actions->type ==RTE_FLOW_ACTION_TYPE_SAMPLE ) { + sample = actions->conf; + ratio = sample->ratio; + sub_type = ((const struct rte_flow_action *) + (sample->actions))->type; + } actions_n++; } +if (flag && action ==RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) { +if (ratio ==1 ) { +/* JUMP Action not support for Mirroring; +* Mirroring support multi-destination; +*/ +if (!jump_flag && sub_type !=RTE_FLOW_ACTION_TYPE_END ) + flag =0 ; + } + }/* Count RTE_FLOW_ACTION_TYPE_END. */ return flag ? actions_n +1 :0 ; }
@@ -4501,7 +4525,7 @@ struct mlx5_flow_tunnel_info {int ret =0 ;if (priv->sampler_en) - actions_n =flow_check_match_action (actions, + actions_n =flow_check_match_action (actions, attr,RTE_FLOW_ACTION_TYPE_SAMPLE , &sample_action_pos, &qrss_action_pos);if (actions_n) {
drivers/net/mlx5/mlx5_flow_dv.c +74 -4
122 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 10/13 net/mlx5: update translate function for mirror
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list.
PMD will check the destination action number in current flow, if found multiple destination actions, then create the new destination array rdma action that group actions for each destination. Currently only support port or queue for destination action, and only encap action can be attached into one port destination.
--- drivers/net/mlx5/mlx5.c | 11 + drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.h | 23 ++ drivers/net/mlx5/mlx5_flow_dv.c | 461 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 468 insertions(+), 29 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -252,6 +252,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_sample_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_dest_array_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_dest_array_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +2 -0
@@ -40,6 +40,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ +MLX5_IPOOL_DEST_ARRAY ,/* Pool for destination array resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -643,6 +644,7 @@ struct mlx5_dev_ctx_shared {uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ uint32_t sample_action_list;/* List of sample actions. */ +uint32_t dest_array_list;/* List of destination array actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.h +23 -0
@@ -527,6 +527,8 @@ struct mlx5_flow_sub_actions_list {void *dr_queue_action;void *dr_tag_action;void *dr_cnt_action; +void *dr_port_id_action; +void *dr_encap_action; };/* Sample sub-actions resource list. */
@@ -534,6 +536,8 @@ struct mlx5_flow_sub_actions_idx {uint32_t rix_hrxq;/**< Hash Rx queue object index. */ uint32_t rix_tag;/**< Index to the tag action. */ uint32_t cnt; +uint32_t rix_port_id_action;/**< Index to port ID action resource. */ +uint32_t rix_encap_decap;/**< Index to encap/decap resource. */ };/* Sample action resource structure. */
@@ -553,6 +557,21 @@ struct mlx5_flow_dv_sample_resource {/**< Action resources. */ }; +#define MLX5_MAX_DEST_NUM 2 + +/* Destination array action resource structure. */ +struct mlx5_flow_dv_dest_array_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +uint8_t ft_type;/** Flow Table Type */ +uint8_t num_of_dest;/**< Number of destination actions. */ +void *action;/**< Pointer to the rdma core action. */ +struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_DEST_NUM ]; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_DEST_NUM ]; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -587,6 +606,8 @@ struct mlx5_flow_handle_dv {/**< Index to the tag action. */ uint32_t rix_sample;/**< Index to sample action resource in cache. */ +uint32_t rix_dest_array; +/**< Index to destination array resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -654,6 +675,8 @@ struct mlx5_flow_dv_workspace {/**< Holds the value that the packet is compared to. */ struct mlx5_flow_dv_sample_resource *sample_res;/**< Pointer to the sample action resource. */ +struct mlx5_flow_dv_dest_array_resource *dest_array_res; +/**< Pointer to the destination array resource. */ };/*
drivers/net/mlx5/mlx5_flow_dv.c +432 -29
646 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 11/13 app/testpmd: add port and encap support for sample action
In reply to Jiawei WangUse sample action with ratio is 1 for mirroring flow, add supports to set the different port or encap action for mirrored packets.
The example of test-pmd command:
1. set sample_actions 1 port_id id 1 / end
flow create 0 ... pattern eth / end actions
sample ratio 1 index 1 / port_id id 2...
The flow will result in all the matched ingress packets will be sent to port 2, and also mirrored the packets and sent to port 1.
2. set raw_encap 0 eth src.../ ipv4.../...
set raw_encap 1 eth src.../ ipv4.../...
set sample_actions 2 raw_encap index 0 / port_id id 0 / end flow create 0 ... pattern eth / end actions
sample ratio 1 index 2 / raw_encap index 1 / port_id id 0...
The flow will result in all the matched egress packets will be encapsulated and sent to wire, and also mirrored the packets and with the different encapsulated data and sent to wire.
--- app/test-pmd/cmdline_flow.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
app/test-pmd/cmdline_flow.c +16 -0
@@ -514,6 +514,8 @@ struct raw_sample_conf {struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_port_id sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_raw_encap sample_encap[RAW_SAMPLE_CONFS_MAX_NUM ];/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1456,6 +1458,8 @@ struct parse_action_priv {ACTION_QUEUE ,ACTION_MARK ,ACTION_COUNT , +ACTION_PORT_ID , +ACTION_RAW_ENCAP ,ACTION_NEXT , ZERO, };
@@ -7009,6 +7013,18 @@ static int comp_set_sample_index(struct context *, const struct token *, (const void *)action->conf, size); action->conf = &sample_queue[idx];break ; +case RTE_FLOW_ACTION_TYPE_RAW_ENCAP : + size =sizeof (struct rte_flow_action_raw_encap ); +rte_memcpy (&sample_encap[idx], + (const void *)action->conf, size); + action->conf = &sample_encap[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_PORT_ID : + size =sizeof (struct rte_flow_action_port_id ); +rte_memcpy (&sample_port_id[idx], + (const void *)action->conf, size); + action->conf = &sample_port_id[idx]; +break ;default :printf ("Error - Not supported action\n" );return ;
Signature · 1 line
1.8.3.1
PATCH v8 12/13 doc: add the sample flow limitation description
In reply to Jiawei WangAdd description about the sample flow limitation.
Sample Flow supports in NIC-Rx and E-Switch domains.
Due to Metadata register c0 is deleted while doing the loopback, so that only support forward the sampling packet into E-Switch manager port, no additional action support in sample flow.
--- doc/guides/nics/mlx5.rst | 6 ++++++ 1 file changed, 6 insertions(+)
doc/guides/nics/mlx5.rst +6 -0
@@ -311,6 +311,12 @@ Limitations for some NICs (such as ConnectX-6 Dx and BlueField 2). The capability bit ``scatter_fcs_w_decap_disable`` shows NIC support. +- Sample flow: + + - Supports ``RTE_FLOW_ACTION_TYPE_SAMPLE`` action only within NIC Rx and E-Switch steering domain. + - The E-Switch Sample flow must have the eswitch_manager VPORT destination (PF or ECPF) and no additional actions. + - For ConnectX-5, the ``RTE_FLOW_ACTION_TYPE_SAMPLE`` is typically used as first action in the E-Switch egress flow if with header modify or encapsulation actions. + Statistics ----------
Signature · 1 line
1.8.3.1
PATCH v8 13/13 doc: update offload dependencies document
In reply to Jiawei WangAdd the offloads minimum versions for new sampling feature.
--- doc/guides/nics/mlx5.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/guides/nics/mlx5.rst +5 -0
@@ -1458,6 +1458,11 @@ Supported hardware offloads | | | rdma-core 26 | | rdma-core 26 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Sampling | | DPDK 20.11 | | DPDK 20.11 | + | | | OFED 5.2 | | OFED 5.2 | + | | | rdma-core 32 | | rdma-core 32 | + | | | ConnectX-5 | | ConnectX-5 | + +-----------------------+-----------------+-----------------+ Notes for metadata ------------------
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v8 13/13] doc: update offload dependencies document
Regards,
Asaf Penso
Quoted 11 lines
-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Sunday, September 27, 2020 9:19 AM
To: Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Asaf Penso <[email protected]>
Subject: [PATCH v8 13/13] doc: update offload dependencies document
Quoted 3 lines
Add the offloads minimum versions for new sampling feature.
Signed-off-by Jiawei Wang <[email protected]>
Quoted 22 lines
---
doc/guides/nics/mlx5.rst| 5 +++++1 file changed, 5 insertions(+)doc/guides/nics/mlx5.rst index renamed from doc/guides/nics/mlx5.rst +0
-0c021f37..95f6820 100644
doc/guides/nics/mlx5.rst +5
-0@@ -1458,6 +1458,11 @@ Supported hardware offloads | | | rdma-core 26 | | rdma-core 26 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Sampling | | DPDK 20.11 | | DPDK 20.11 | + | | | OFED 5.2 | | OFED 5.2 | + | | | rdma-core 32 | | rdma-core 32 | + | | | ConnectX-5 | | ConnectX-5 | + +-----------------------+-----------------+-----------------+Notes for metadata
------------------
--
1.8.3.1
v9 cover support the flow-based traffic sampling
In reply to Jiawei WangThis patch set implement the flow-based traffic sampling.
The solution is introduced a new rte_flow action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
v9:
* Rebase patches based on the latest code.
* Separate the MLX5 PMD changes into another patches.
v8:
* Rebase patches based on the latest code.
* Update the offloads dependencies document for sample flow.
* Update sample flow limitation document.
v7:
* Removed change in [PATCH 12/12] net/mlx5: support the native port id actions for mirroring, should use sample action.
* Update the PMD code to match the new rdma-core API for mirroring.
* Optimize the sample flow split routine.
* Update code changes and commit log based on the review.
* Add E-Switch sample flow limitation document.
v6:
* Update the function that restore vport through metadata register c0 for FDB sampler.
* Add multiple destination support.
* Support the remote mirroring with different encapsulation header.
* Fix coverity error.
v5:
* Add the release note.
* Remove Make changes since it's deprecated.
v4:
* Rebase.
* Fix the coding style issue.
v3:
* Remove 'const' of ratio field.
* Update description and commit messages.
v2:
* Rebase patches based on the latest code.
* Update rte_flow and release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.
Jiawei Wang (3):
ethdev: introduce sample action for rte flow app/testpmd: add testpmd command for sample action app/testpmd: add port and encap support for sample action
app/test-pmd/cmdline_flow.c | 301 ++++++++++++++++++++++++++++++++- doc/guides/prog_guide/rte_flow.rst | 25 +++ doc/guides/rel_notes/release_20_11.rst | 6 + lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 ++++ 5 files changed, 354 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v9 1/3 ethdev: introduce sample action for rte flow
When using full offload, all traffic will be handled by the HW, and forwarded to the requested VF or wire and the control application does not see this traffic anymore. So there's a need for an action that enables the control application some forwarded traffic visibility.
The solution introduces a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
The packets sampled equals is '1/ratio', the ratio value set to 1 means that the packets will be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
In order to support the sample packet in rte_flow, new rte_flow action definition RTE_FLOW_ACTION_TYPE_SAMPLE and structure rte_flow_action_sample will be introduced.
--- doc/guides/prog_guide/rte_flow.rst | 25 +++++++++++++++++++++++++ doc/guides/rel_notes/release_20_11.rst | 6 ++++++ lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+)
doc/guides/prog_guide/rte_flow.rst +25 -0
@@ -2666,6 +2666,31 @@ timeout passed without any matching on the flow. | ``context`` | user input flow context | +--------------+---------------------------------+ +Action: ``SAMPLE`` +^^^^^^^^^^^^^^^^^^ + +Adds a sample action to a matched flow. + +The matching packets will be duplicated with the specified ``ratio`` and +applied with own set of actions with a fate action, the packets sampled +equals is '1/ratio'. All the packets continue to the target destination. + +When the ``ratio`` is set to 1 then the packets will be 100% mirrored. +``actions`` represent the different set of actions for the sampled or mirrored +packets, and must have a fate action. + +.. _table_rte_flow_action_sample: + +.. table:: SAMPLE + + +--------------+---------------------------------+ + | Field | Value | + +==============+=================================+ + | ``ratio`` | 32 bits sample ratio value | + +--------------+---------------------------------+ + | ``actions`` | sub-action list for sampling | + +--------------+---------------------------------+ + Negative types ~~~~~~~~~~~~~~
doc/guides/rel_notes/release_20_11.rst +6 -0
@@ -118,6 +118,12 @@ New Features * Extern objects and functions can be plugged into the pipeline. * Transaction-oriented table updates. +* **Added flow-based traffic sampling support.** + + Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching + packets with specified ratio, and apply with own set of actions with a fate + action. When the ratio is set to 1 then the packets will be 100% mirrored. + Removed Items -------------
lib/librte_ethdev/rte_flow.c +1 -0
@@ -174,6 +174,7 @@ struct rte_flow_desc_data {MK_FLOW_ACTION (SET_IPV4_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (SET_IPV6_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (AGE ,sizeof (struct rte_flow_action_age )), + MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)), };int
lib/librte_ethdev/rte_flow.h +30 -0
@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {* see enum RTE_ETH_EVENT_FLOW_AGED */ RTE_FLOW_ACTION_TYPE_AGE , + +/** +* The matching packets will be duplicated with specified ratio and +* applied with own set of actions with a fate action. +* +* See struct rte_flow_action_sample. +*/ + RTE_FLOW_ACTION_TYPE_SAMPLE, };/**
@@ -2742,6 +2750,28 @@ struct rte_flow_action {struct rte_flow ;/** +* @warning +* @b EXPERIMENTAL: this structure may change without prior notice +* +* RTE_FLOW_ACTION_TYPE_SAMPLE +* +* Adds a sample action to a matched flow. +* +* The matching packets will be duplicated with specified ratio and applied +* with own set of actions with a fate action, the sampled packet could be +* redirected to queue or port. All the packets continue processing on the +* default flow path. +* +* When the sample ratio is set to 1 then the packets will be 100% mirrored. +* Additional action list be supported to add for sampled or mirrored packets. +*/ +struct rte_flow_action_sample { +uint32_t ratio;/**< packets sampled equals to '1/ratio'. */ +const struct rte_flow_action *actions; +/**< sub-action list specific for the sampling hit cases. */ +}; + +/** * Verbose error types. * * Most of them provide the type of the object referenced by struct
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v9 1/3] ethdev: introduce sample action for rte flow
Quoted 19 lines · Jiawei Wang
When using full offload, all traffic will be handled by the HW, and forwarded to the requested VF or wire and the control application does not see this traffic anymore. So there's a need for an action that enables the control application some forwarded traffic visibility.
The solution introduces a new action that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.
The packets sampled equals is '1/ratio', the ratio value set to 1 means that the packets will be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
In order to support the sample packet in
rte_flow, newrte_flowaction definitionRTE_FLOW_ACTION_TYPE_SAMPLEand structurerte_flow_action_samplewill be introduced.
Quoted 5 lines
Signed-off-by Jiawei Wang <[email protected]>Acked-by Ori Kam <[email protected]>Acked-by Jerin Jacob <[email protected]>Acked-by Andrew Rybchenko <[email protected]>
Quoted 123 lines
--- doc/guides/prog_guide/rte_flow.rst | 25 +++++++++++++++++++++++++ doc/guides/rel_notes/release_20_11.rst | 6 ++++++ lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+)doc/guides/prog_guide/rte_flow.rst +25
-0@@ -2666,6 +2666,31 @@ timeout passed without any matching on the flow. | ``context`` | user input flow context | +--------------+---------------------------------+ +Action: ``SAMPLE`` +^^^^^^^^^^^^^^^^^^ + +Adds a sample action to a matched flow. + +The matching packets will be duplicated with the specified ``ratio`` and +applied with own set of actions with a fate action, the packets sampled +equals is '1/ratio'. All the packets continue to the target destination. + +When the ``ratio`` is set to 1 then the packets will be 100% mirrored. +``actions`` represent the different set of actions for the sampled or mirrored +packets, and must have a fate action. + +.. _table_rte_flow_action_sample: + +.. table:: SAMPLE + + +--------------+---------------------------------+ + | Field | Value | + +==============+=================================+ + | ``ratio`` | 32 bits sample ratio value | + +--------------+---------------------------------+ + | ``actions`` | sub-action list for sampling | + +--------------+---------------------------------+ + Negative types ~~~~~~~~~~~~~~doc/guides/rel_notes/release_20_11.rst +6
-0@@ -118,6 +118,12 @@ New Features * Extern objects and functions can be plugged into the pipeline. * Transaction-oriented table updates. +* **Added flow-based traffic sampling support.** + + Added new action: ``RTE_FLOW_ACTION_TYPE_SAMPLE`` to duplicate the matching + packets with specified ratio, and apply with own set of actions with a fate + action. When the ratio is set to 1 then the packets will be 100% mirrored. + Removed Items -------------lib/librte_ethdev/rte_flow.c +1
-0@@ -174,6 +174,7 @@ struct rte_flow_desc_data {MK_FLOW_ACTION (SET_IPV4_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (SET_IPV6_DSCP ,sizeof (struct rte_flow_action_set_dscp )),MK_FLOW_ACTION (AGE ,sizeof (struct rte_flow_action_age )), + MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)), };int lib/librte_ethdev/rte_flow.h +30
-1@@ -2132,6 +2132,14 @@ enum rte_flow_action_type {* see enum RTE_ETH_EVENT_FLOW_AGED */ RTE_FLOW_ACTION_TYPE_AGE , + +/** +* The matching packets will be duplicated with specified ratio and +* applied with own set of actions with a fate action. +* +* See struct rte_flow_action_sample. +*/ + RTE_FLOW_ACTION_TYPE_SAMPLE, };/** @@ -2742,6 +2750,28 @@ struct rte_flow_action {struct rte_flow ;/** +* @warning +* @b EXPERIMENTAL: this structure may change without prior notice +* +* RTE_FLOW_ACTION_TYPE_SAMPLE +* +* Adds a sample action to a matched flow. +* +* The matching packets will be duplicated with specified ratio and applied +* with own set of actions with a fate action, the sampled packet could be +* redirected to queue or port. All the packets continue processing on the +* default flow path. +* +* When the sample ratio is set to 1 then the packets will be 100% mirrored. +* Additional action list be supported to add for sampled or mirrored packets. +*/ +struct rte_flow_action_sample { +uint32_t ratio;/**< packets sampled equals to '1/ratio'. */ +const struct rte_flow_action *actions; +/**< sub-action list specific for the sampling hit cases. */ +}; + +/** * Verbose error types. * * Most of them provide the type of the object referenced by struct -- 1.8.3.1
PATCH v9 2/3 app/testpmd: add testpmd command for sample action
In reply to Jiawei WangAdd a new testpmd command 'set sample_actions' that supports the multiple sample actions list configuration by using the index:
set sample_actions <index> <actions list>
The examples for the sample flow use case and result as below:
1. set sample_actions 0 mark id 0x8 / queue index 2 / end .. pattern eth / end actions sample ratio 2 index 0 / jump group 2 ...
This flow will result in all the matched ingress packets will be jumped to next flow table, and the each second packet will be marked and sent to queue 2 of the control application.
2. ...pattern eth / end actions sample ratio 2 / port_id id 2 ...
The flow will result in all the matched ingress packets will be duplicated and sent to the representor peer (VF or wire) on DPDK port 2, and the each second packet will also be sent to E-Switch manager vport.
--- app/test-pmd/cmdline_flow.c | 285 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 276 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +276 -9
@@ -56,6 +56,8 @@ enum index {SET_RAW_ENCAP ,SET_RAW_DECAP ,SET_RAW_INDEX , +SET_SAMPLE_ACTIONS , +SET_SAMPLE_INDEX ,/* Top-level command. */ FLOW,
@@ -360,6 +362,10 @@ enum index {ACTION_SET_IPV6_DSCP_VALUE ,ACTION_AGE ,ACTION_AGE_TIMEOUT , +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , + ACTION_SAMPLE_INDEX_VALUE, };/** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -495,6 +501,22 @@ struct action_nvgre_encap_data {struct mplsoudp_decap_conf mplsoudp_decap_conf; +#define ACTION_SAMPLE_ACTIONS_NUM 10 +#define RAW_SAMPLE_CONFS_MAX_NUM 8 +/** Storage for struct rte_flow_action_sample including external data. */ +struct action_sample_data { +struct rte_flow_action_sample conf; +uint32_t idx; +}; +/** Storage for struct rte_flow_action_sample. */ +struct raw_sample_conf { +struct rte_flow_action data[ACTION_SAMPLE_ACTIONS_NUM ]; +}; +struct raw_sample_conf raw_sample_confs[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1193,6 +1215,7 @@ struct parse_action_priv {ACTION_SET_IPV4_DSCP ,ACTION_SET_IPV6_DSCP ,ACTION_AGE , +ACTION_SAMPLE , ZERO, };
@@ -1425,9 +1448,28 @@ struct parse_action_priv { ZERO, }; +static const enum index action_sample[] = { +ACTION_SAMPLE , +ACTION_SAMPLE_RATIO , +ACTION_SAMPLE_INDEX , +ACTION_NEXT , +ZERO , +}; + +static const enum index next_action_sample[] = { +ACTION_QUEUE , +ACTION_MARK , +ACTION_COUNT , +ACTION_NEXT , +ZERO , +}; +static int parse_set_raw_encap_decap (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int ); +static int parse_set_sample_action (struct context *,const struct token *, +const char *,unsigned int , +void *,unsigned int );static int parse_set_init (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1495,7 +1537,15 @@ static int parse_vc_action_raw_decap_index(struct context *,static int parse_vc_action_set_meta (struct context *ctx,const struct token *token,const char *str,unsigned int len,void *buf, +unsigned int size); +static int parse_vc_action_sample (struct context *ctx, +const struct token *token,const char *str, +unsigned int len,void *buf,unsigned int size); +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size);static int parse_destroy (struct context *,const struct token *,const char *,unsigned int ,void *,unsigned int );
@@ -1566,6 +1616,8 @@ static int comp_vc_action_rss_queue(struct context *, const struct token *, unsigned int, char *, unsigned int);static int comp_set_raw_index (struct context *,const struct token *,unsigned int ,char *,unsigned int ); +static int comp_set_sample_index (struct context *,const struct token *, +unsigned int ,char *,unsigned int );/** Token definitions. */ static const struct token token_list[] = {
@@ -3721,11 +3773,13 @@ static int comp_set_raw_index(struct context *, const struct token *, /* Top level command. */ [SET] = { .name = "set", - .help = "set raw encap/decap data", - .type = "set raw_encap|raw_decap <index> <pattern>", + .help = "set raw encap/decap/sample data", + .type ="set raw_encap|raw_decap <index> <pattern>" + " or set sample_actions <index> <action>", .next =NEXT (NEXT_ENTRY (SET_RAW_ENCAP , - SET_RAW_DECAP)), +SET_RAW_DECAP , + SET_SAMPLE_ACTIONS)), .call = parse_set_init, },/* Sub-level commands. */
@@ -3756,6 +3810,23 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(next_item), .call = parse_port, }, + [SET_SAMPLE_INDEX] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "index of sample actions", + .next = NEXT(next_action_sample), + .call = parse_port, + }, + [SET_SAMPLE_ACTIONS] = { + .name = "sample_actions", + .help = "set sample actions list", + .next = NEXT(NEXT_ENTRY(SET_SAMPLE_INDEX)), + .args =ARGS (ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct buffer , port), +sizeof (((struct buffer *)0 )->port), + 0, RAW_SAMPLE_CONFS_MAX_NUM - 1)), + .call = parse_set_sample_action, + }, [ACTION_SET_TAG] = { .name = "set_tag", .help = "set tag",
@@ -3859,6 +3930,37 @@ static int comp_set_raw_index(struct context *, const struct token *, .next = NEXT(action_age, NEXT_ENTRY(UNSIGNED)), .call = parse_vc_conf, }, + [ACTION_SAMPLE] = { + .name = "sample", + .help = "set a sample action", + .next = NEXT(action_sample), + .priv =PRIV_ACTION (SAMPLE , + sizeof(struct action_sample_data)), + .call = parse_vc_action_sample, + }, + [ACTION_SAMPLE_RATIO] = { + .name = "ratio", + .help = "flow sample ratio value", + .next = NEXT(action_sample, NEXT_ENTRY(UNSIGNED)), + .args =ARGS (ARGS_ENTRY_ARB + (offsetof(struct action_sample_data , conf) + + offsetof(struct rte_flow_action_sample , ratio), +sizeof (((struct rte_flow_action_sample *)0 )-> + ratio))), + }, + [ACTION_SAMPLE_INDEX] = { + .name = "index", + .help = "the index of sample actions list", + .next = NEXT(NEXT_ENTRY(ACTION_SAMPLE_INDEX_VALUE)), + }, + [ACTION_SAMPLE_INDEX_VALUE] = { + .name = "{index}", + .type = "UNSIGNED", + .help = "unsigned integer value", + .next = NEXT(NEXT_ENTRY(ACTION_NEXT)), + .call = parse_vc_action_sample_index, + .comp = comp_set_sample_index, + }, };/** Remove and return last entry from argument stack. */
@@ -5369,6 +5471,76 @@ static int comp_set_raw_index(struct context *, const struct token *,return len; } +static int +parse_vc_action_sample (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct buffer *out = buf; +struct rte_flow_action *action; +struct action_sample_data *action_sample_data =NULL ; +static struct rte_flow_action end_action = { +RTE_FLOW_ACTION_TYPE_END ,0 + }; +int ret; + + ret =parse_vc (ctx, token, str, len, buf, size); +if (ret <0 ) +return ret; +/* Nothing else to do if there is no buffer. */ +if (!out) +return ret; +if (!out->args.vc.actions_n) +return -1 ; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; +/* Point to selected object. */ + ctx->object = out->args.vc.data; + ctx->objmask =NULL ; +/* Copy the headers to the buffer. */ + action_sample_data = ctx->object; + action_sample_data->conf.actions = &end_action; + action->conf = &action_sample_data->conf; +return ret; +} + +static int +parse_vc_action_sample_index (struct context *ctx,const struct token *token, +const char *str,unsigned int len,void *buf, +unsigned int size) +{ +struct action_sample_data *action_sample_data; +struct rte_flow_action *action; +const struct arg *arg; +struct buffer *out = buf; +int ret; +uint16_t idx; + +RTE_SET_USED (token); +RTE_SET_USED (buf); +RTE_SET_USED (size); +if (ctx->curr !=ACTION_SAMPLE_INDEX_VALUE ) +return -1 ; + arg =ARGS_ENTRY_ARB_BOUNDED + (offsetof(struct action_sample_data , idx), +sizeof (((struct action_sample_data *)0 )->idx), +0 ,RAW_SAMPLE_CONFS_MAX_NUM -1 ); +if (push_args (ctx, arg)) +return -1 ; + ret =parse_int (ctx, token, str, len,NULL ,0 ); +if (ret <0 ) { +pop_args (ctx); +return -1 ; + } +if (!ctx->object) +return len; + action = &out->args.vc.actions[out->args.vc.actions_n -1 ]; + action_sample_data = ctx->object; + idx = action_sample_data->idx; + action_sample_data->conf.actions = raw_sample_confs[idx].data; + action->conf = &action_sample_data->conf; +return len; +} +/** Parse tokens for destroy command. */ static int parse_destroy(struct context *ctx, const struct token *token,
@@ -6133,6 +6305,38 @@ static int comp_set_raw_index(struct context *, const struct token *,if (!out->command)return -1 ; out->command = ctx->curr; +/* For encap/decap we need is pattern */ + out->args.vc.pattern = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); +return len; +} + +/** Parse set command, initialize output buffer for subsequent tokens. */ +static int +parse_set_sample_action (struct context *ctx,const struct token *token, +const char *str,unsigned int len, +void *buf,unsigned int size) +{ +struct buffer *out = buf; + +/* Token name must match. */ +if (parse_default (ctx, token, str, len,NULL ,0 ) <0 ) +return -1 ; +/* Nothing else to do if there is no buffer. */ +if (!out) +return len; +/* Make sure buffer is large enough. */ +if (size <sizeof (*out)) +return -1 ; + ctx->objdata =0 ; + ctx->objmask =NULL ; + ctx->object = out; +if (!out->command) +return -1 ; + out->command = ctx->curr; +/* For sampler we need is actions */ + out->args.vc.actions = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double ));return len; }
@@ -6169,11 +6373,8 @@ static int comp_set_raw_index(struct context *, const struct token *,return -1 ; out->command = ctx->curr; out->args.vc.data = (uint8_t *)out + size; -/* All we need is pattern */ - out->args.vc.pattern = - (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), -sizeof (double )); - ctx->object = out->args.vc.pattern; + ctx->object = (void *)RTE_ALIGN_CEIL ((uintptr_t )(out +1 ), +sizeof (double )); }return len; }
@@ -6324,6 +6525,24 @@ static int comp_set_raw_index(struct context *, const struct token *,return nb; } +/** Complete index number for set raw_encap/raw_decap commands. */ +static int +comp_set_sample_index (struct context *ctx,const struct token *token, +unsigned int ent,char *buf,unsigned int size) +{ +uint16_t idx =0 ; +uint16_t nb =0 ; + +RTE_SET_USED (ctx); +RTE_SET_USED (token); +for (idx =0 ; idx <RAW_SAMPLE_CONFS_MAX_NUM ; ++idx) { +if (buf && idx == ent) +return snprintf (buf, size,"%u" , idx); + ++nb; + } +return nb; +} +/** Internal context. */ static struct context cmd_flow_context;
@@ -6769,7 +6988,53 @@ static int comp_set_raw_index(struct context *, const struct token *,return mask; } - +/** Dispatch parsed buffer to function calls. */ +static void +cmd_set_raw_parsed_sample (const struct buffer *in) +{ +uint32_t n = in->args.vc.actions_n; +uint32_t i =0 ; +struct rte_flow_action *action =NULL ; +struct rte_flow_action *data =NULL ; +size_t size =0 ; +uint16_t idx = in->port;/* We borrow port field as index */ +uint32_t max_size =sizeof (struct rte_flow_action ) * +ACTION_SAMPLE_ACTIONS_NUM ; + +RTE_ASSERT (in->command ==SET_SAMPLE_ACTIONS ); + data = (struct rte_flow_action *)&raw_sample_confs[idx].data; +memset (data,0x00 , max_size); +for (; i <= n -1 ; i++) { + action = in->args.vc.actions + i; +if (action->type ==RTE_FLOW_ACTION_TYPE_END ) +break ; +switch (action->type) { +case RTE_FLOW_ACTION_TYPE_MARK : + size =sizeof (struct rte_flow_action_mark ); +rte_memcpy (&sample_mark[idx], + (const void *)action->conf, size); + action->conf = &sample_mark[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_COUNT : + size =sizeof (struct rte_flow_action_count ); +rte_memcpy (&sample_count[idx], + (const void *)action->conf, size); + action->conf = &sample_count[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_QUEUE : + size =sizeof (struct rte_flow_action_queue ); +rte_memcpy (&sample_queue[idx], + (const void *)action->conf, size); + action->conf = &sample_queue[idx]; +break ; +default : +printf ("Error - Not supported action\n" ); +return ; + } +rte_memcpy (data, action,sizeof (struct rte_flow_action )); + data++; + } +}/** Dispatch parsed buffer to function calls. */ static void
@@ -6786,6 +7051,8 @@ static int comp_set_raw_index(struct context *, const struct token *,uint16_t proto =0 ;uint16_t idx = in->port;/* We borrow port field as index */ +if (in->command ==SET_SAMPLE_ACTIONS ) +return cmd_set_raw_parsed_sample (in);RTE_ASSERT (in->command ==SET_RAW_ENCAP || in->command ==SET_RAW_DECAP );if (in->command ==SET_RAW_ENCAP ) {
Signature · 1 line
1.8.3.1
PATCH v9 3/3 app/testpmd: add port and encap support for sample action
In reply to Jiawei WangUse sample action with ratio is 1 for mirroring flow, add supports to set the different port or encap action for mirrored packets.
The example of test-pmd command:
1. set sample_actions 1 port_id id 1 / end
flow create 0 ... pattern eth / end actions
sample ratio 1 index 1 / port_id id 2...
The flow will result in all the matched ingress packets will be sent to port 2, and also mirrored the packets and sent to port 1.
2. set raw_encap 0 eth src.../ ipv4.../...
set raw_encap 1 eth src.../ ipv4.../...
set sample_actions 2 raw_encap index 0 / port_id id 0 / end flow create 0 ... pattern eth / end actions
sample ratio 1 index 2 / raw_encap index 1 / port_id id 0...
The flow will result in all the matched egress packets will be encapsulated and sent to wire, and also mirrored the packets and with the different encapsulated data and sent to wire.
--- app/test-pmd/cmdline_flow.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
app/test-pmd/cmdline_flow.c +16 -0
@@ -516,6 +516,8 @@ struct raw_sample_conf {struct rte_flow_action_mark sample_mark[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM ];struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_port_id sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM ]; +struct rte_flow_action_raw_encap sample_encap[RAW_SAMPLE_CONFS_MAX_NUM ];/** Maximum number of subsequent tokens and arguments on the stack. */ #define CTX_STACK_SIZE 16
@@ -1460,6 +1462,8 @@ struct parse_action_priv {ACTION_QUEUE ,ACTION_MARK ,ACTION_COUNT , +ACTION_PORT_ID , +ACTION_RAW_ENCAP ,ACTION_NEXT , ZERO, };
@@ -7027,6 +7031,18 @@ static int comp_set_sample_index(struct context *, const struct token *, (const void *)action->conf, size); action->conf = &sample_queue[idx];break ; +case RTE_FLOW_ACTION_TYPE_RAW_ENCAP : + size =sizeof (struct rte_flow_action_raw_encap ); +rte_memcpy (&sample_encap[idx], + (const void *)action->conf, size); + action->conf = &sample_encap[idx]; +break ; +case RTE_FLOW_ACTION_TYPE_PORT_ID : + size =sizeof (struct rte_flow_action_port_id ); +rte_memcpy (&sample_port_id[idx], + (const void *)action->conf, size); + action->conf = &sample_port_id[idx]; +break ;default :printf ("Error - Not supported action\n" );return ;
Signature · 1 line
1.8.3.1
For MLX5 PMD patch set that implements the flow-based sampling, please see: https://patchwork.dpdk.org/project/dpdk/list/?series=12829
Thanks.
Jonny
Quoted 81 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of Jiawei Wang
Sent: Friday, October 9, 2020 9:46 PM
To: Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Raslan Darawsheh <[email protected]>; [email protected]; [email protected]; Asaf Penso <[email protected]>
Subject: [dpdk-dev] [PATCH v9 0/3] support the flow-based traffic samplingThis patch set implement the flow-based traffic sampling.
The solution is introduced a new
rte_flowaction that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
v9:
* Rebase patches based on the latest code.
* Separate the MLX5 PMD changes into another patches.v8:
* Rebase patches based on the latest code.
* Update the offloads dependencies document for sample flow.
* Update sample flow limitation document.v7:
* Removed change in [PATCH 12/12] net/mlx5: support the native port id actions for mirroring, should use sample action.
* Update the PMD code to match the new rdma-core API for mirroring.
* Optimize the sample flow split routine.
* Update code changes and commit log based on the review.
* Add E-Switch sample flow limitation document.v6:
* Update the function that restore vport through metadata register c0 for FDB sampler.
* Add multiple destination support.
* Support the remote mirroring with different encapsulation header.
* Fix coverity error.v5:
* Add the release note.
* Remove Make changes since it's deprecated.v4:
* Rebase.
* Fix the coding style issue.v3:
* Remove 'const' of ratio field.
* Update description and commit messages.v2:
* Rebase patches based on the latest code.
* Updaterte_flowand release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.Jiawei Wang (3):
ethdev: introduce sample action for rte flow app/testpmd: add testpmd command for sample action app/testpmd: add port and encap support for sample actionapp/test-pmd/cmdline_flow.c | 301 ++++++++++++++++++++++++++++++++- doc/guides/prog_guide/rte_flow.rst | 25 +++ doc/guides/rel_notes/release_20_11.rst | 6 + lib/librte_ethdev/rte_flow.c | 1 + lib/librte_ethdev/rte_flow.h | 30 ++++ 5 files changed, 354 insertions(+), 9 deletions(-)--
1.8.3.1
Quoted 48 lines · Jiawei Wang
This patch set implement the flow-based traffic sampling.
The solution is introduced a new
rte_flowaction that will sample the incoming traffic and send a duplicated traffic with the specified ratio to the application, while the original packet will continue to the target destination.If the sample ratio value be set to 1, means that the packets would be completely mirrored. The sample packet can be assigned with different set of actions from the original packet.
v9:
* Rebase patches based on the latest code.
* Separate the MLX5 PMD changes into another patches.v8:
* Rebase patches based on the latest code.
* Update the offloads dependencies document for sample flow.
* Update sample flow limitation document.v7:
* Removed change in [PATCH 12/12] net/mlx5: support the native port id actions for mirroring, should use sample action.
* Update the PMD code to match the new rdma-core API for mirroring.
* Optimize the sample flow split routine.
* Update code changes and commit log based on the review.
* Add E-Switch sample flow limitation document.v6:
* Update the function that restore vport through metadata register c0 for FDB sampler.
* Add multiple destination support.
* Support the remote mirroring with different encapsulation header.
* Fix coverity error.v5:
* Add the release note.
* Remove Make changes since it's deprecated.v4:
* Rebase.
* Fix the coding style issue.v3:
* Remove 'const' of ratio field.
* Update description and commit messages.v2:
* Rebase patches based on the latest code.
* Updaterte_flowand release documents.
* Fix the compile error.
* Removed unnecessary change in [PATCH 7/8] net/mlx5: update the metadata register c0 support since FDB will use 5-tuple to do match.
* Update changes based on the comments.
Quoted 5 lines
Jiawei Wang (3):
ethdev: introduce sample action for rte flow app/testpmd: add testpmd command for sample action app/testpmd: add port and encap support for sample action
Series applied to dpdk-next-net/main, thanks.
cover Add sampling and mirroring support in MLX5 PMD
In reply to Jiawei WangThis patch set implement the flow sampling and mirroring for mlx5 driver.
MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.
Depends-on: series-12828 ("support the flow-based traffic sampling")
Jiawei Wang (10):
common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action common/mlx5: add glue function for mirroring net/mlx5: update validation for mirroring flow net/mlx5: update translate function for mirror
doc: add the sample flow limitation description
doc: update offload dependencies document
doc/guides/nics/mlx5.rst | 11 + drivers/common/mlx5/linux/meson.build | 4 + drivers/common/mlx5/linux/mlx5_glue.c | 37 ++ drivers/common/mlx5/linux/mlx5_glue.h | 35 + drivers/common/mlx5/mlx5_devx_cmds.c | 27 + drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 61 ++ drivers/net/mlx5/linux/mlx5_os.c | 14 + drivers/net/mlx5/mlx5.c | 22 + drivers/net/mlx5/mlx5.h | 6 + drivers/net/mlx5/mlx5_flow.c | 400 +++++++++++- drivers/net/mlx5/mlx5_flow.h | 61 ++ drivers/net/mlx5/mlx5_flow_dv.c | 1126 ++++++++++++++++++++++++++++++++- 13 files changed, 1769 insertions(+), 36 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/10 common/mlx5: glue for sample action
The new DR sample action is supported since OFED version 5.1.2 or rdma-core version v32.
MLX5 PMD adds the rdma-core command in glue to create this action.
Sample action is used for creating the sample object to implement the sampling/mirroring function.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 13 +++++++++++++ drivers/common/mlx5/mlx5_prm.h | 10 ++++++++++ 4 files changed, 40 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -172,6 +172,8 @@ has_sym_args = [ 'RDMA_NLDEV_ATTR_NDEV_INDEX' ], [ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_domain'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
@@ -1063,6 +1063,19 @@#endif } +static void * +mlx5_glue_dr_create_flow_action_sampler ( +struct mlx5dv_dr_flow_sampler_attr *attr) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +return mlx5dv_dr_action_create_flow_sampler (attr); +#else + (void )attr; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1339,6 +1352,8 @@ .devx_port_query = mlx5_glue_devx_port_query, .dr_dump_domain = mlx5_glue_dr_dump_domain, .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, + .dr_create_flow_action_sampler = + mlx5_glue_dr_create_flow_action_sampler, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +13 -0
@@ -77,6 +77,7 @@#ifndef HAVE_MLX5DV_DR enum mlx5dv_dr_domain_type { unused, };struct mlx5dv_dr_domain ; +struct mlx5dv_dr_action ;#endif #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,16 @@struct mlx5dv_dr_flow_meter_attr ;#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +struct mlx5dv_dr_flow_sampler_attr { +uint32_t sample_ratio; +void *default_next_table; +size_t num_sample_actions; +struct mlx5dv_dr_action **sample_actions; +uint64_t action; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -309,6 +320,8 @@ struct mlx5_glue {const void *pp_context, uint32_t flags);void (*dv_free_pp)(struct mlx5dv_pp *pp); +void *(*dr_create_flow_action_sampler) + (struct mlx5dv_dr_flow_sampler_attr *attr); };extern const struct mlx5_glue *mlx5_glue;
drivers/common/mlx5/mlx5_prm.h +10 -0
@@ -1479,6 +1479,16 @@ struct mlx5_ifc_virtio_emulation_cap_bits {u8 reserved_at_0[0x8000 ]; }; +struct mlx5_ifc_set_action_in_bits { +u8 action_type[0x4 ]; +u8 field[0xc ]; +u8 reserved_at_10[0x3 ]; +u8 offset[0x5 ]; +u8 reserved_at_18[0x3 ]; +u8 length[0x5 ]; +u8 data[0x20 ]; +}; +struct mlx5_ifc_query_hca_cap_out_bits {u8 status[0x8 ];u8 reserved_at_8[0x18 ];
Signature · 1 line
1.8.3.1
PATCH 2/10 common/mlx5: query sampler object capability via DevX
In reply to Jiawei WangUpdate function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.
Add the related structs definition in mlx5_prm.h.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
@@ -751,6 +751,33 @@ struct mlx5_devx_obj *if (!attr->eth_net_offloads)return 0 ; +/* Query Flow Sampler Capability From FLow Table Properties Layout. */ +memset (in,0 ,sizeof (in)); +memset (out,0 ,sizeof (out)); +MLX5_SET (query_hca_cap_in, in, opcode,MLX5_CMD_OP_QUERY_HCA_CAP ); +MLX5_SET (query_hca_cap_in, in, op_mod, +MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | +MLX5_HCA_CAP_OPMOD_GET_CUR ); + + rc = mlx5_glue->devx_general_cmd (ctx, + in,sizeof (in), + out,sizeof (out)); +if (rc) + goto error; + status =MLX5_GET (query_hca_cap_out, out, status); + syndrome =MLX5_GET (query_hca_cap_out, out, syndrome); +if (status) { +DRV_LOG (DEBUG ,"Failed to query devx HCA capabilities, " +"status %x, syndrome = %x" , + status, syndrome); + attr->log_max_ft_sampler_num =0 ; +return -1 ; + } + hcattr =MLX5_ADDR_OF (query_hca_cap_out, out, capability); + attr->log_max_ft_sampler_num = +MLX5_GET (flow_table_nic_cap, + hcattr, flow_table_properties.log_max_ft_sampler_num); +/* Query HCA offloads for Ethernet protocol. */ memset (in,0 ,sizeof (in));memset (out,0 ,sizeof (out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -102,6 +102,7 @@ struct mlx5_hca_attr { uint32_t scatter_fcs_w_decap_disable:1; uint32_t regex:1;uint32_t regexp_num_of_engines; + uint32_t log_max_ft_sampler_num:8;struct mlx5_hca_qos_attr qos;struct mlx5_hca_vdpa_attr vdpa; };
drivers/common/mlx5/mlx5_prm.h +51 -0
69 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 3/10 net/mlx5: add the validate sample action
In reply to Jiawei WangAdd sample action validate function.
Sample Flow is supported in NIC-RX and FDB domains. For the NIC-RX the Sample Flow action list must include the destination queue action.
Only NIC-RX domain supports the optional actions list. FDB doesn't support any optional actions, the sampled packets is always forwarded to the E-Switch manager port.
--- drivers/net/mlx5/linux/mlx5_os.c | 14 ++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_flow.h | 1 + drivers/net/mlx5/mlx5_flow_dv.c | 137 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
@@ -1099,6 +1099,20 @@ } }#endif +#if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE ) +if (config->hca_attr.log_max_ft_sampler_num >0 && + config->dv_flow_en) { + priv->sampler_en =1 ; +DRV_LOG (DEBUG ,"The Sampler enabled!\n" ); + }else { + priv->sampler_en =0 ; +if (!config->hca_attr.log_max_ft_sampler_num) +DRV_LOG (WARNING ,"No available register for" +" Sampler." ); +else +DRV_LOG (DEBUG ,"DV flow is not supported!\n" ); + } +#endif }if (config->tx_pp) { DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz",
drivers/net/mlx5/mlx5.h +1 -0
@@ -813,6 +813,7 @@ struct mlx5_priv { unsigned int counter_fallback:1; /* Use counter fallback management. */ unsigned int mtr_en:1; /* Whether support meter. */ unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */ + unsigned int sampler_en:1; /* Whether support sampler. */uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ uint32_t vport_meta_tag;/* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -196,6 +196,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)#define MLX5_FLOW_ACTION_AGE (1ull << 34)#define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35) +#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +137 -0
149 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 4/10 net/mlx5: split sample flow into two sub flows
In reply to Jiawei WangThe flow with sample action will be splited into two sub flows:
the prefix sub flow with the all actions preceding the sample action and sample action itself, and the suffix sub flow with the actions following the sample action.
The original items remain in the prefix sub flow, add the implicit tag action with unique id to set in metadata register, and suffix sub flow uses the tag item to match with that unique id.
The flow split as below:
Original flow: items / actions pre / sample / actions sfx ->
prefix sub flow -
items / actions pre / set_tag action / sample
suffix sub flow -
tag_item / actions sfx
--- drivers/net/mlx5/mlx5.c | 11 ++ drivers/net/mlx5/mlx5.h | 3 + drivers/net/mlx5/mlx5_flow.c | 360 +++++++++++++++++++++++++++++++++++++++++-- drivers/net/mlx5/mlx5_flow.h | 37 +++++ 4 files changed, 394 insertions(+), 17 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_jump_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_sample_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_sample_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
@@ -39,6 +39,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_TAG ,/* Pool for tag resource. */ MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ +MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -512,6 +513,7 @@ struct mlx5_flow_tbl_resource {#define MLX5_FLOW_TABLE_LEVEL_METER (MLX5_MAX_TABLES - 4)#define MLX5_FLOW_TABLE_LEVEL_SUFFIX (MLX5_MAX_TABLES - 3)#define MLX5_MAX_TABLES_FDB UINT16_MAX +#define MLX5_FLOW_TABLE_FACTOR 10/* ID generation structure. */ struct mlx5_flow_id_pool {
@@ -640,6 +642,7 @@ struct mlx5_dev_ctx_shared {struct mlx5_hlist *tag_table;uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ +uint32_t sample_action_list;/* List of sample actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +343 -17
453 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow.h +37 -0
@@ -520,6 +520,39 @@ struct mlx5_flow_tbl_data_entry {uint32_t idx;/**< index for the indexed mempool. */ }; +/* Sub rdma-core actions list. */ +struct mlx5_flow_sub_actions_list { +uint32_t actions_num;/**< Number of sample actions. */ +uint64_t action_flags; +void *dr_queue_action; +void *dr_tag_action; +void *dr_cnt_action; +}; + +/* Sample sub-actions resource list. */ +struct mlx5_flow_sub_actions_idx { +uint32_t rix_hrxq;/**< Hash Rx queue object index. */ +uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t cnt; +}; + +/* Sample action resource structure. */ +struct mlx5_flow_dv_sample_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +void *verbs_action;/**< Verbs sample action object. */ +uint8_t ft_type;/** Flow Table Type */ +uint32_t ft_id;/** Flow Table Level */ +uint32_t ratio;/** Sample Ratio */ +uint64_t set_action;/** Restore reg_c0 value */ +void *normal_path_tbl;/** Flow Table pointer */ +void *default_miss;/** default_miss dr_action. */ +struct mlx5_flow_sub_actions_idx sample_idx; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -552,6 +585,8 @@ struct mlx5_flow_handle_dv {/**< Index to push VLAN action resource in cache. */ uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t rix_sample; +/**< Index to sample action resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -617,6 +652,8 @@ struct mlx5_flow_dv_workspace {/**< Pointer to the jump action resource. */ struct mlx5_flow_dv_match_params value;/**< Holds the value that the packet is compared to. */ +struct mlx5_flow_dv_sample_resource *sample_res; +/**< Pointer to the sample action resource. */ };/*
Signature · 1 line
1.8.3.1
PATCH 5/10 net/mlx5: update translate function for sample action
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.
The metadata register value will be lost in the default path after Sampler in FDB due to CX5 HW limitation.
Since source vport also be shared with metadata register c0, MLX5 PMD would set the source vport to rdma-core and rdma-core will restore the regc0 value after sampler.
--- drivers/net/mlx5/mlx5_flow.c | 16 +- drivers/net/mlx5/mlx5_flow_dv.c | 508 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 509 insertions(+), 15 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
@@ -5008,10 +5008,14 @@ struct mlx5_flow_tunnel_info {int hairpin_flow;uint32_t hairpin_id =0 ;struct rte_flow_attr attr_tx = { .priority =0 }; +struct rte_flow_attr attr_factor = {0 };int ret; - hairpin_flow =flow_check_hairpin_split (dev, attr, actions); - ret =flow_drv_validate (dev, attr, items, p_actions_rx, +memcpy ((void *)&attr_factor, (const void *)attr,sizeof (*attr)); +if (external) + attr_factor.group *=MLX5_FLOW_TABLE_FACTOR ; + hairpin_flow =flow_check_hairpin_split (dev, &attr_factor, actions); + ret =flow_drv_validate (dev, &attr_factor, items, p_actions_rx, external, hairpin_flow, error);if (ret <0 )return 0 ;
@@ -5030,7 +5034,7 @@ struct mlx5_flow_tunnel_info { rte_errno =ENOMEM ; goto error_before_flow; } - flow->drv_type =flow_get_drv_type (dev, attr); + flow->drv_type =flow_get_drv_type (dev, &attr_factor);if (hairpin_id !=0 ) flow->hairpin_flow_id = hairpin_id; MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -5075,7 +5079,7 @@ struct mlx5_flow_tunnel_info {* depending on configuration. In the simplest * case it just creates unmodified original flow. */ - ret =flow_create_split_outer (dev, flow, attr, + ret =flow_create_split_outer (dev, flow, &attr_factor, buf->entry[i].pattern, p_actions_rx, external, idx, error);
@@ -5112,8 +5116,8 @@ struct mlx5_flow_tunnel_info {* the egress Flows belong to the different device and * copy table should be updated in peer NIC Rx domain. */ -if (attr->ingress && - (external || attr->group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { +if (attr_factor.ingress && + (external || attr_factor.group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { ret =flow_mreg_update_copy_table (dev, flow, actions, error);if (ret) goto error;
drivers/net/mlx5/mlx5_flow_dv.c +499 -9
593 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 6/10 common/mlx5: add glue function for mirroring
In reply to Jiawei WangThe new DR destination array action is supported since the rdma-core version v32.
Destination array action is used group DR actions to a single action, And it can be used for mirroring packet and forward to every destination (port or queue) in the array.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 26 ++++++++++++++++++++++++-- drivers/common/mlx5/linux/mlx5_glue.h | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -176,6 +176,8 @@ has_sym_args = [ 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_dest_array'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ], ] config = configuration_data()
drivers/common/mlx5/linux/mlx5_glue.c +24 -2
@@ -1064,8 +1064,8 @@ }static void * -mlx5_glue_dr_create_flow_action_sampler ( -struct mlx5dv_dr_flow_sampler_attr *attr) +mlx5_glue_dr_create_flow_action_sampler + (struct mlx5dv_dr_flow_sampler_attr *attr) {#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE return mlx5dv_dr_action_create_flow_sampler (attr);
@@ -1076,6 +1076,26 @@#endif } +static void * +mlx5_glue_dr_action_create_dest_array + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +return mlx5dv_dr_action_create_dest_array + (domain, + num_dest, + dests); +#else + (void )domain; + (void )num_dest; + (void )dests; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1354,6 +1374,8 @@ .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, .dr_create_flow_action_sampler = mlx5_glue_dr_create_flow_action_sampler, + .dr_create_flow_action_dest_array = + mlx5_glue_dr_action_create_dest_array, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +22 -0
@@ -98,6 +98,24 @@ struct mlx5dv_dr_flow_sampler_attr { };#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +enum mlx5dv_dr_action_dest_type { +MLX5DV_DR_ACTION_DEST , +MLX5DV_DR_ACTION_DEST_REFORMAT , +}; +struct mlx5dv_dr_action_dest_reformat { +struct mlx5dv_dr_action *reformat; +struct mlx5dv_dr_action *dest; +}; +struct mlx5dv_dr_action_dest_attr { +enum mlx5dv_dr_action_dest_type type; +union { +struct mlx5dv_dr_action *dest; +struct mlx5dv_dr_action_dest_reformat *dest_reformat; + }; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -322,6 +340,10 @@ struct mlx5_glue {void (*dv_free_pp)(struct mlx5dv_pp *pp);void *(*dr_create_flow_action_sampler) (struct mlx5dv_dr_flow_sampler_attr *attr); +void *(*dr_create_flow_action_dest_array) + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]); };extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
PATCH 7/10 net/mlx5: update validation for mirroring flow
In reply to Jiawei WangMirroring flow using sample action with ratio is 1, and it doesn't support jump action with the same one flow.
Sample action must have destination actions like port or queue for mirroring, and don't need split function as sampling flow.
--- drivers/net/mlx5/mlx5_flow.c | 26 +++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 78 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.c +25 -1
@@ -4245,6 +4245,8 @@ struct mlx5_flow_tunnel_info {* * @param[in] actions * Pointer to the list of actions. +* @param[in] attr +* Flow rule attributes. * @param[in] action * The action to be check if exist. * @param[out] match_action_pos
@@ -4258,10 +4260,15 @@ struct mlx5_flow_tunnel_info {*/ static int flow_check_match_action (const struct rte_flow_action actions[], +const struct rte_flow_attr *attr,enum rte_flow_action_type action,int *match_action_pos,int *qrss_action_pos) { +const struct rte_flow_action_sample *sample;int actions_n =0 ; +int jump_flag =0 ; +uint32_t ratio =0 ; +int sub_type =0 ;int flag =0 ; *match_action_pos =-1 ;
@@ -4274,8 +4281,25 @@ struct mlx5_flow_tunnel_info {if (actions->type ==RTE_FLOW_ACTION_TYPE_QUEUE || actions->type ==RTE_FLOW_ACTION_TYPE_RSS ) *qrss_action_pos = actions_n; +if (actions->type ==RTE_FLOW_ACTION_TYPE_JUMP ) + jump_flag =1 ; +if (actions->type ==RTE_FLOW_ACTION_TYPE_SAMPLE ) { + sample = actions->conf; + ratio = sample->ratio; + sub_type = ((const struct rte_flow_action *) + (sample->actions))->type; + } actions_n++; } +if (flag && action ==RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) { +if (ratio ==1 ) { +/* JUMP Action not support for Mirroring; +* Mirroring support multi-destination; +*/ +if (!jump_flag && sub_type !=RTE_FLOW_ACTION_TYPE_END ) + flag =0 ; + } + }/* Count RTE_FLOW_ACTION_TYPE_END. */ return flag ? actions_n +1 :0 ; }
@@ -4827,7 +4851,7 @@ struct mlx5_flow_tunnel_info {int ret =0 ;if (priv->sampler_en) - actions_n =flow_check_match_action (actions, + actions_n =flow_check_match_action (actions, attr,RTE_FLOW_ACTION_TYPE_SAMPLE , &sample_action_pos, &qrss_action_pos);if (actions_n) {
drivers/net/mlx5/mlx5_flow_dv.c +74 -4
122 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 8/10 net/mlx5: update translate function for mirror
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list.
PMD will check the destination action number in current flow, if found multiple destination actions, then create the new destination array rdma action that group actions for each destination. Currently only support port or queue for destination action, and only encap action can be attached into one port destination.
--- drivers/net/mlx5/mlx5.c | 11 + drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.h | 23 ++ drivers/net/mlx5/mlx5_flow_dv.c | 461 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 468 insertions(+), 29 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -252,6 +252,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_sample_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_dest_array_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_dest_array_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +2 -0
@@ -40,6 +40,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ +MLX5_IPOOL_DEST_ARRAY ,/* Pool for destination array resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -643,6 +644,7 @@ struct mlx5_dev_ctx_shared {uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ uint32_t sample_action_list;/* List of sample actions. */ +uint32_t dest_array_list;/* List of destination array actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.h +23 -0
@@ -527,6 +527,8 @@ struct mlx5_flow_sub_actions_list {void *dr_queue_action;void *dr_tag_action;void *dr_cnt_action; +void *dr_port_id_action; +void *dr_encap_action; };/* Sample sub-actions resource list. */
@@ -534,6 +536,8 @@ struct mlx5_flow_sub_actions_idx {uint32_t rix_hrxq;/**< Hash Rx queue object index. */ uint32_t rix_tag;/**< Index to the tag action. */ uint32_t cnt; +uint32_t rix_port_id_action;/**< Index to port ID action resource. */ +uint32_t rix_encap_decap;/**< Index to encap/decap resource. */ };/* Sample action resource structure. */
@@ -553,6 +557,21 @@ struct mlx5_flow_dv_sample_resource {/**< Action resources. */ }; +#define MLX5_MAX_DEST_NUM 2 + +/* Destination array action resource structure. */ +struct mlx5_flow_dv_dest_array_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +uint8_t ft_type;/** Flow Table Type */ +uint8_t num_of_dest;/**< Number of destination actions. */ +void *action;/**< Pointer to the rdma core action. */ +struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_DEST_NUM ]; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_DEST_NUM ]; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -587,6 +606,8 @@ struct mlx5_flow_handle_dv {/**< Index to the tag action. */ uint32_t rix_sample;/**< Index to sample action resource in cache. */ +uint32_t rix_dest_array; +/**< Index to destination array resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -654,6 +675,8 @@ struct mlx5_flow_dv_workspace {/**< Holds the value that the packet is compared to. */ struct mlx5_flow_dv_sample_resource *sample_res;/**< Pointer to the sample action resource. */ +struct mlx5_flow_dv_dest_array_resource *dest_array_res; +/**< Pointer to the destination array resource. */ };/*
drivers/net/mlx5/mlx5_flow_dv.c +432 -29
646 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 9/10 doc: add the sample flow limitation description
In reply to Jiawei WangAdd description about the sample flow limitation.
Sample Flow supports in NIC-Rx and E-Switch domains.
Due to Metadata register c0 is deleted while doing the loopback, so that only support forward the sampling packet into E-Switch manager port, no additional action support in sample flow.
--- doc/guides/nics/mlx5.rst | 6 ++++++ 1 file changed, 6 insertions(+)
doc/guides/nics/mlx5.rst +6 -0
@@ -311,6 +311,12 @@ Limitations for some NICs (such as ConnectX-6 Dx and BlueField 2). The capability bit ``scatter_fcs_w_decap_disable`` shows NIC support. +- Sample flow: + + - Supports ``RTE_FLOW_ACTION_TYPE_SAMPLE`` action only within NIC Rx and E-Switch steering domain. + - The E-Switch Sample flow must have the eswitch_manager VPORT destination (PF or ECPF) and no additional actions. + - For ConnectX-5, the ``RTE_FLOW_ACTION_TYPE_SAMPLE`` is typically used as first action in the E-Switch egress flow if with header modify or encapsulation actions. + Statistics ----------
Signature · 1 line
1.8.3.1
PATCH 10/10 doc: update offload dependencies document
In reply to Jiawei WangAdd the offloads minimum versions for new sampling feature.
--- doc/guides/nics/mlx5.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/guides/nics/mlx5.rst +5 -0
@@ -1458,6 +1458,11 @@ Supported hardware offloads | | | rdma-core 26 | | rdma-core 26 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Sampling | | DPDK 20.11 | | DPDK 20.11 | + | | | OFED 5.2 | | OFED 5.2 | + | | | rdma-core 32 | | rdma-core 32 | + | | | ConnectX-5 | | ConnectX-5 | + +-----------------------+-----------------+-----------------+ Notes for metadata ------------------
Signature · 1 line
1.8.3.1
v2 cover Add sampling and mirroring support in MLX5 PMD
In reply to Jiawei WangThis patch set implement the flow sampling and mirroring for mlx5 driver.
MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.
Depends-on: series-12828 ("support the flow-based traffic sampling")
v2:
* Fix incorrect check for E-Switch sample split flow.
Jiawei Wang (10):
common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action common/mlx5: add glue function for mirroring net/mlx5: update validation for mirroring flow net/mlx5: update translate function for mirror
doc: add the sample flow limitation description
doc: update offload dependencies document
doc/guides/nics/mlx5.rst | 11 + drivers/common/mlx5/linux/meson.build | 4 + drivers/common/mlx5/linux/mlx5_glue.c | 37 ++ drivers/common/mlx5/linux/mlx5_glue.h | 35 + drivers/common/mlx5/mlx5_devx_cmds.c | 27 + drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 61 ++ drivers/net/mlx5/linux/mlx5_os.c | 14 + drivers/net/mlx5/mlx5.c | 22 + drivers/net/mlx5/mlx5.h | 6 + drivers/net/mlx5/mlx5_flow.c | 400 +++++++++++- drivers/net/mlx5/mlx5_flow.h | 61 ++ drivers/net/mlx5/mlx5_flow_dv.c | 1126 ++++++++++++++++++++++++++++++++- 13 files changed, 1769 insertions(+), 36 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/10 common/mlx5: glue for sample action
The new DR sample action is supported since OFED version 5.1.2 or rdma-core version v32.
MLX5 PMD adds the rdma-core command in glue to create this action.
Sample action is used for creating the sample object to implement the sampling/mirroring function.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 13 +++++++++++++ drivers/common/mlx5/mlx5_prm.h | 10 ++++++++++ 4 files changed, 40 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -172,6 +172,8 @@ has_sym_args = [ 'RDMA_NLDEV_ATTR_NDEV_INDEX' ], [ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_domain'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
@@ -1063,6 +1063,19 @@#endif } +static void * +mlx5_glue_dr_create_flow_action_sampler ( +struct mlx5dv_dr_flow_sampler_attr *attr) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +return mlx5dv_dr_action_create_flow_sampler (attr); +#else + (void )attr; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1339,6 +1352,8 @@ .devx_port_query = mlx5_glue_devx_port_query, .dr_dump_domain = mlx5_glue_dr_dump_domain, .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, + .dr_create_flow_action_sampler = + mlx5_glue_dr_create_flow_action_sampler, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +13 -0
@@ -77,6 +77,7 @@#ifndef HAVE_MLX5DV_DR enum mlx5dv_dr_domain_type { unused, };struct mlx5dv_dr_domain ; +struct mlx5dv_dr_action ;#endif #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,16 @@struct mlx5dv_dr_flow_meter_attr ;#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +struct mlx5dv_dr_flow_sampler_attr { +uint32_t sample_ratio; +void *default_next_table; +size_t num_sample_actions; +struct mlx5dv_dr_action **sample_actions; +uint64_t action; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -309,6 +320,8 @@ struct mlx5_glue {const void *pp_context, uint32_t flags);void (*dv_free_pp)(struct mlx5dv_pp *pp); +void *(*dr_create_flow_action_sampler) + (struct mlx5dv_dr_flow_sampler_attr *attr); };extern const struct mlx5_glue *mlx5_glue;
drivers/common/mlx5/mlx5_prm.h +10 -0
@@ -1479,6 +1479,16 @@ struct mlx5_ifc_virtio_emulation_cap_bits {u8 reserved_at_0[0x8000 ]; }; +struct mlx5_ifc_set_action_in_bits { +u8 action_type[0x4 ]; +u8 field[0xc ]; +u8 reserved_at_10[0x3 ]; +u8 offset[0x5 ]; +u8 reserved_at_18[0x3 ]; +u8 length[0x5 ]; +u8 data[0x20 ]; +}; +struct mlx5_ifc_query_hca_cap_out_bits {u8 status[0x8 ];u8 reserved_at_8[0x18 ];
Signature · 1 line
1.8.3.1
PATCH v2 2/10 common/mlx5: query sampler object capability via DevX
In reply to Jiawei WangUpdate function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.
Add the related structs definition in mlx5_prm.h.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
@@ -751,6 +751,33 @@ struct mlx5_devx_obj *if (!attr->eth_net_offloads)return 0 ; +/* Query Flow Sampler Capability From FLow Table Properties Layout. */ +memset (in,0 ,sizeof (in)); +memset (out,0 ,sizeof (out)); +MLX5_SET (query_hca_cap_in, in, opcode,MLX5_CMD_OP_QUERY_HCA_CAP ); +MLX5_SET (query_hca_cap_in, in, op_mod, +MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | +MLX5_HCA_CAP_OPMOD_GET_CUR ); + + rc = mlx5_glue->devx_general_cmd (ctx, + in,sizeof (in), + out,sizeof (out)); +if (rc) + goto error; + status =MLX5_GET (query_hca_cap_out, out, status); + syndrome =MLX5_GET (query_hca_cap_out, out, syndrome); +if (status) { +DRV_LOG (DEBUG ,"Failed to query devx HCA capabilities, " +"status %x, syndrome = %x" , + status, syndrome); + attr->log_max_ft_sampler_num =0 ; +return -1 ; + } + hcattr =MLX5_ADDR_OF (query_hca_cap_out, out, capability); + attr->log_max_ft_sampler_num = +MLX5_GET (flow_table_nic_cap, + hcattr, flow_table_properties.log_max_ft_sampler_num); +/* Query HCA offloads for Ethernet protocol. */ memset (in,0 ,sizeof (in));memset (out,0 ,sizeof (out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -102,6 +102,7 @@ struct mlx5_hca_attr { uint32_t scatter_fcs_w_decap_disable:1; uint32_t regex:1;uint32_t regexp_num_of_engines; + uint32_t log_max_ft_sampler_num:8;struct mlx5_hca_qos_attr qos;struct mlx5_hca_vdpa_attr vdpa; };
drivers/common/mlx5/mlx5_prm.h +51 -0
69 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 3/10 net/mlx5: add the validate sample action
In reply to Jiawei WangAdd sample action validate function.
Sample Flow is supported in NIC-RX and FDB domains. For the NIC-RX the Sample Flow action list must include the destination queue action.
Only NIC-RX domain supports the optional actions list. FDB doesn't support any optional actions, the sampled packets is always forwarded to the E-Switch manager port.
--- drivers/net/mlx5/linux/mlx5_os.c | 14 ++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_flow.h | 1 + drivers/net/mlx5/mlx5_flow_dv.c | 137 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
@@ -1099,6 +1099,20 @@ } }#endif +#if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE ) +if (config->hca_attr.log_max_ft_sampler_num >0 && + config->dv_flow_en) { + priv->sampler_en =1 ; +DRV_LOG (DEBUG ,"The Sampler enabled!\n" ); + }else { + priv->sampler_en =0 ; +if (!config->hca_attr.log_max_ft_sampler_num) +DRV_LOG (WARNING ,"No available register for" +" Sampler." ); +else +DRV_LOG (DEBUG ,"DV flow is not supported!\n" ); + } +#endif }if (config->tx_pp) { DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz",
drivers/net/mlx5/mlx5.h +1 -0
@@ -813,6 +813,7 @@ struct mlx5_priv { unsigned int counter_fallback:1; /* Use counter fallback management. */ unsigned int mtr_en:1; /* Whether support meter. */ unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */ + unsigned int sampler_en:1; /* Whether support sampler. */uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ uint32_t vport_meta_tag;/* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -196,6 +196,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)#define MLX5_FLOW_ACTION_AGE (1ull << 34)#define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35) +#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +137 -0
149 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 4/10 net/mlx5: split sample flow into two sub flows
In reply to Jiawei WangThe flow with sample action will be splited into two sub flows:
the prefix sub flow with the all actions preceding the sample action and sample action itself, and the suffix sub flow with the actions following the sample action.
The original items remain in the prefix sub flow, add the implicit tag action with unique id to set in metadata register, and suffix sub flow uses the tag item to match with that unique id.
The flow split as below:
Original flow: items / actions pre / sample / actions sfx ->
prefix sub flow -
items / actions pre / set_tag action / sample
suffix sub flow -
tag_item / actions sfx
--- drivers/net/mlx5/mlx5.c | 11 ++ drivers/net/mlx5/mlx5.h | 3 + drivers/net/mlx5/mlx5_flow.c | 360 +++++++++++++++++++++++++++++++++++++++++-- drivers/net/mlx5/mlx5_flow.h | 37 +++++ 4 files changed, 394 insertions(+), 17 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_jump_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_sample_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_sample_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
@@ -39,6 +39,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_TAG ,/* Pool for tag resource. */ MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ +MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -512,6 +513,7 @@ struct mlx5_flow_tbl_resource {#define MLX5_FLOW_TABLE_LEVEL_METER (MLX5_MAX_TABLES - 4)#define MLX5_FLOW_TABLE_LEVEL_SUFFIX (MLX5_MAX_TABLES - 3)#define MLX5_MAX_TABLES_FDB UINT16_MAX +#define MLX5_FLOW_TABLE_FACTOR 10/* ID generation structure. */ struct mlx5_flow_id_pool {
@@ -640,6 +642,7 @@ struct mlx5_dev_ctx_shared {struct mlx5_hlist *tag_table;uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ +uint32_t sample_action_list;/* List of sample actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +343 -17
453 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow.h +37 -0
@@ -520,6 +520,39 @@ struct mlx5_flow_tbl_data_entry {uint32_t idx;/**< index for the indexed mempool. */ }; +/* Sub rdma-core actions list. */ +struct mlx5_flow_sub_actions_list { +uint32_t actions_num;/**< Number of sample actions. */ +uint64_t action_flags; +void *dr_queue_action; +void *dr_tag_action; +void *dr_cnt_action; +}; + +/* Sample sub-actions resource list. */ +struct mlx5_flow_sub_actions_idx { +uint32_t rix_hrxq;/**< Hash Rx queue object index. */ +uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t cnt; +}; + +/* Sample action resource structure. */ +struct mlx5_flow_dv_sample_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +void *verbs_action;/**< Verbs sample action object. */ +uint8_t ft_type;/** Flow Table Type */ +uint32_t ft_id;/** Flow Table Level */ +uint32_t ratio;/** Sample Ratio */ +uint64_t set_action;/** Restore reg_c0 value */ +void *normal_path_tbl;/** Flow Table pointer */ +void *default_miss;/** default_miss dr_action. */ +struct mlx5_flow_sub_actions_idx sample_idx; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -552,6 +585,8 @@ struct mlx5_flow_handle_dv {/**< Index to push VLAN action resource in cache. */ uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t rix_sample; +/**< Index to sample action resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -617,6 +652,8 @@ struct mlx5_flow_dv_workspace {/**< Pointer to the jump action resource. */ struct mlx5_flow_dv_match_params value;/**< Holds the value that the packet is compared to. */ +struct mlx5_flow_dv_sample_resource *sample_res; +/**< Pointer to the sample action resource. */ };/*
Signature · 1 line
1.8.3.1
PATCH v2 5/10 net/mlx5: update translate function for sample action
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.
The metadata register value will be lost in the default path after Sampler in FDB due to CX5 HW limitation.
Since source vport also be shared with metadata register c0, MLX5 PMD would set the source vport to rdma-core and rdma-core will restore the regc0 value after sampler.
--- drivers/net/mlx5/mlx5_flow.c | 16 +- drivers/net/mlx5/mlx5_flow_dv.c | 508 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 509 insertions(+), 15 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
@@ -5008,10 +5008,14 @@ struct mlx5_flow_tunnel_info {int hairpin_flow;uint32_t hairpin_id =0 ;struct rte_flow_attr attr_tx = { .priority =0 }; +struct rte_flow_attr attr_factor = {0 };int ret; - hairpin_flow =flow_check_hairpin_split (dev, attr, actions); - ret =flow_drv_validate (dev, attr, items, p_actions_rx, +memcpy ((void *)&attr_factor, (const void *)attr,sizeof (*attr)); +if (external) + attr_factor.group *=MLX5_FLOW_TABLE_FACTOR ; + hairpin_flow =flow_check_hairpin_split (dev, &attr_factor, actions); + ret =flow_drv_validate (dev, &attr_factor, items, p_actions_rx, external, hairpin_flow, error);if (ret <0 )return 0 ;
@@ -5030,7 +5034,7 @@ struct mlx5_flow_tunnel_info { rte_errno =ENOMEM ; goto error_before_flow; } - flow->drv_type =flow_get_drv_type (dev, attr); + flow->drv_type =flow_get_drv_type (dev, &attr_factor);if (hairpin_id !=0 ) flow->hairpin_flow_id = hairpin_id; MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -5075,7 +5079,7 @@ struct mlx5_flow_tunnel_info {* depending on configuration. In the simplest * case it just creates unmodified original flow. */ - ret =flow_create_split_outer (dev, flow, attr, + ret =flow_create_split_outer (dev, flow, &attr_factor, buf->entry[i].pattern, p_actions_rx, external, idx, error);
@@ -5112,8 +5116,8 @@ struct mlx5_flow_tunnel_info {* the egress Flows belong to the different device and * copy table should be updated in peer NIC Rx domain. */ -if (attr->ingress && - (external || attr->group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { +if (attr_factor.ingress && + (external || attr_factor.group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { ret =flow_mreg_update_copy_table (dev, flow, actions, error);if (ret) goto error;
drivers/net/mlx5/mlx5_flow_dv.c +499 -9
593 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 6/10 common/mlx5: add glue function for mirroring
In reply to Jiawei WangThe new DR destination array action is supported since the rdma-core version v32.
Destination array action is used group DR actions to a single action, And it can be used for mirroring packet and forward to every destination (port or queue) in the array.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 26 ++++++++++++++++++++++++-- drivers/common/mlx5/linux/mlx5_glue.h | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -176,6 +176,8 @@ has_sym_args = [ 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_dest_array'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ], ] config = configuration_data()
drivers/common/mlx5/linux/mlx5_glue.c +24 -2
@@ -1064,8 +1064,8 @@ }static void * -mlx5_glue_dr_create_flow_action_sampler ( -struct mlx5dv_dr_flow_sampler_attr *attr) +mlx5_glue_dr_create_flow_action_sampler + (struct mlx5dv_dr_flow_sampler_attr *attr) {#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE return mlx5dv_dr_action_create_flow_sampler (attr);
@@ -1076,6 +1076,26 @@#endif } +static void * +mlx5_glue_dr_action_create_dest_array + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +return mlx5dv_dr_action_create_dest_array + (domain, + num_dest, + dests); +#else + (void )domain; + (void )num_dest; + (void )dests; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1354,6 +1374,8 @@ .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, .dr_create_flow_action_sampler = mlx5_glue_dr_create_flow_action_sampler, + .dr_create_flow_action_dest_array = + mlx5_glue_dr_action_create_dest_array, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +22 -0
@@ -98,6 +98,24 @@ struct mlx5dv_dr_flow_sampler_attr { };#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +enum mlx5dv_dr_action_dest_type { +MLX5DV_DR_ACTION_DEST , +MLX5DV_DR_ACTION_DEST_REFORMAT , +}; +struct mlx5dv_dr_action_dest_reformat { +struct mlx5dv_dr_action *reformat; +struct mlx5dv_dr_action *dest; +}; +struct mlx5dv_dr_action_dest_attr { +enum mlx5dv_dr_action_dest_type type; +union { +struct mlx5dv_dr_action *dest; +struct mlx5dv_dr_action_dest_reformat *dest_reformat; + }; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -322,6 +340,10 @@ struct mlx5_glue {void (*dv_free_pp)(struct mlx5dv_pp *pp);void *(*dr_create_flow_action_sampler) (struct mlx5dv_dr_flow_sampler_attr *attr); +void *(*dr_create_flow_action_dest_array) + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]); };extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
PATCH v2 7/10 net/mlx5: update validation for mirroring flow
In reply to Jiawei WangMirroring flow using sample action with ratio is 1, and it doesn't support jump action with the same one flow.
Sample action must have destination actions like port or queue for mirroring, and don't need split function as sampling flow.
--- drivers/net/mlx5/mlx5_flow.c | 26 +++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 78 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.c +25 -1
@@ -4245,6 +4245,8 @@ struct mlx5_flow_tunnel_info {* * @param[in] actions * Pointer to the list of actions. +* @param[in] attr +* Flow rule attributes. * @param[in] action * The action to be check if exist. * @param[out] match_action_pos
@@ -4258,10 +4260,15 @@ struct mlx5_flow_tunnel_info {*/ static int flow_check_match_action (const struct rte_flow_action actions[], +const struct rte_flow_attr *attr,enum rte_flow_action_type action,int *match_action_pos,int *qrss_action_pos) { +const struct rte_flow_action_sample *sample;int actions_n =0 ; +int jump_flag =0 ; +uint32_t ratio =0 ; +int sub_type =0 ;int flag =0 ; *match_action_pos =-1 ;
@@ -4274,8 +4281,25 @@ struct mlx5_flow_tunnel_info {if (actions->type ==RTE_FLOW_ACTION_TYPE_QUEUE || actions->type ==RTE_FLOW_ACTION_TYPE_RSS ) *qrss_action_pos = actions_n; +if (actions->type ==RTE_FLOW_ACTION_TYPE_JUMP ) + jump_flag =1 ; +if (actions->type ==RTE_FLOW_ACTION_TYPE_SAMPLE ) { + sample = actions->conf; + ratio = sample->ratio; + sub_type = ((const struct rte_flow_action *) + (sample->actions))->type; + } actions_n++; } +if (flag && action ==RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) { +if (ratio ==1 ) { +/* JUMP Action not support for Mirroring; +* Mirroring support multi-destination; +*/ +if (!jump_flag && sub_type !=RTE_FLOW_ACTION_TYPE_END ) + flag =0 ; + } + }/* Count RTE_FLOW_ACTION_TYPE_END. */ return flag ? actions_n +1 :0 ; }
@@ -4827,7 +4851,7 @@ struct mlx5_flow_tunnel_info {int ret =0 ;if (priv->sampler_en) - actions_n =flow_check_match_action (actions, + actions_n =flow_check_match_action (actions, attr,RTE_FLOW_ACTION_TYPE_SAMPLE , &sample_action_pos, &qrss_action_pos);if (actions_n) {
drivers/net/mlx5/mlx5_flow_dv.c +74 -4
122 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 8/10 net/mlx5: update translate function for mirror
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list.
PMD will check the destination action number in current flow, if found multiple destination actions, then create the new destination array rdma action that group actions for each destination. Currently only support port or queue for destination action, and only encap action can be attached into one port destination.
--- drivers/net/mlx5/mlx5.c | 11 + drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.h | 23 ++ drivers/net/mlx5/mlx5_flow_dv.c | 461 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 468 insertions(+), 29 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -252,6 +252,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_sample_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_dest_array_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_dest_array_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +2 -0
@@ -40,6 +40,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ +MLX5_IPOOL_DEST_ARRAY ,/* Pool for destination array resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -643,6 +644,7 @@ struct mlx5_dev_ctx_shared {uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ uint32_t sample_action_list;/* List of sample actions. */ +uint32_t dest_array_list;/* List of destination array actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.h +23 -0
@@ -527,6 +527,8 @@ struct mlx5_flow_sub_actions_list {void *dr_queue_action;void *dr_tag_action;void *dr_cnt_action; +void *dr_port_id_action; +void *dr_encap_action; };/* Sample sub-actions resource list. */
@@ -534,6 +536,8 @@ struct mlx5_flow_sub_actions_idx {uint32_t rix_hrxq;/**< Hash Rx queue object index. */ uint32_t rix_tag;/**< Index to the tag action. */ uint32_t cnt; +uint32_t rix_port_id_action;/**< Index to port ID action resource. */ +uint32_t rix_encap_decap;/**< Index to encap/decap resource. */ };/* Sample action resource structure. */
@@ -553,6 +557,21 @@ struct mlx5_flow_dv_sample_resource {/**< Action resources. */ }; +#define MLX5_MAX_DEST_NUM 2 + +/* Destination array action resource structure. */ +struct mlx5_flow_dv_dest_array_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +rte_atomic32_t refcnt;/**< Reference counter. */ +uint8_t ft_type;/** Flow Table Type */ +uint8_t num_of_dest;/**< Number of destination actions. */ +void *action;/**< Pointer to the rdma core action. */ +struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_DEST_NUM ]; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_DEST_NUM ]; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -587,6 +606,8 @@ struct mlx5_flow_handle_dv {/**< Index to the tag action. */ uint32_t rix_sample;/**< Index to sample action resource in cache. */ +uint32_t rix_dest_array; +/**< Index to destination array resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -654,6 +675,8 @@ struct mlx5_flow_dv_workspace {/**< Holds the value that the packet is compared to. */ struct mlx5_flow_dv_sample_resource *sample_res;/**< Pointer to the sample action resource. */ +struct mlx5_flow_dv_dest_array_resource *dest_array_res; +/**< Pointer to the destination array resource. */ };/*
drivers/net/mlx5/mlx5_flow_dv.c +432 -29
646 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 9/10 doc: add the sample flow limitation description
In reply to Jiawei WangAdd description about the sample flow limitation.
Sample Flow supports in NIC-Rx and E-Switch domains.
Due to Metadata register c0 is deleted while doing the loopback, so that only support forward the sampling packet into E-Switch manager port, no additional action support in sample flow.
--- doc/guides/nics/mlx5.rst | 6 ++++++ 1 file changed, 6 insertions(+)
doc/guides/nics/mlx5.rst +6 -0
@@ -311,6 +311,12 @@ Limitations for some NICs (such as ConnectX-6 Dx and BlueField 2). The capability bit ``scatter_fcs_w_decap_disable`` shows NIC support. +- Sample flow: + + - Supports ``RTE_FLOW_ACTION_TYPE_SAMPLE`` action only within NIC Rx and E-Switch steering domain. + - The E-Switch Sample flow must have the eswitch_manager VPORT destination (PF or ECPF) and no additional actions. + - For ConnectX-5, the ``RTE_FLOW_ACTION_TYPE_SAMPLE`` is typically used as first action in the E-Switch egress flow if with header modify or encapsulation actions. + Statistics ----------
Signature · 1 line
1.8.3.1
PATCH v2 10/10 doc: update offload dependencies document
In reply to Jiawei WangAdd the offloads minimum versions for new sampling feature.
--- doc/guides/nics/mlx5.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/guides/nics/mlx5.rst +5 -0
@@ -1458,6 +1458,11 @@ Supported hardware offloads | | | rdma-core 26 | | rdma-core 26 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Sampling | | DPDK 20.11 | | DPDK 20.11 | + | | | OFED 5.2 | | OFED 5.2 | + | | | rdma-core 32 | | rdma-core 32 | + | | | ConnectX-5 | | ConnectX-5 | + +-----------------------+-----------------+-----------------+ Notes for metadata ------------------
Signature · 1 line
1.8.3.1
v3 cover Add sampling and mirroring support in MLX5 PMD
In reply to Jiawei WangThis patch set implement the flow sampling and mirroring for mlx5 driver.
MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.
Depends-on: series-12828 ("support the flow-based traffic sampling")
v3:
* Use C11 atomic builtins for sampling and mirroring resource register and release.
v2:
* Fix incorrect check for E-Switch sample split flow.
Jiawei Wang (10):
common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action common/mlx5: add glue function for mirroring net/mlx5: update validation for mirroring flow net/mlx5: update translate function for mirror
doc: add the sample flow limitation description
doc: update offload dependencies document
doc/guides/nics/mlx5.rst | 11 + drivers/common/mlx5/linux/meson.build | 4 + drivers/common/mlx5/linux/mlx5_glue.c | 37 ++ drivers/common/mlx5/linux/mlx5_glue.h | 35 + drivers/common/mlx5/mlx5_devx_cmds.c | 27 + drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 61 ++ drivers/net/mlx5/linux/mlx5_os.c | 14 + drivers/net/mlx5/mlx5.c | 22 + drivers/net/mlx5/mlx5.h | 6 + drivers/net/mlx5/mlx5_flow.c | 400 +++++++++++- drivers/net/mlx5/mlx5_flow.h | 61 ++ drivers/net/mlx5/mlx5_flow_dv.c | 1130 ++++++++++++++++++++++++++++++++- 13 files changed, 1773 insertions(+), 36 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v3 1/10 common/mlx5: glue for sample action
The new DR sample action is supported since OFED version 5.1.2 or rdma-core version v32.
MLX5 PMD adds the rdma-core command in glue to create this action.
Sample action is used for creating the sample object to implement the sampling/mirroring function.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 15 +++++++++++++++ drivers/common/mlx5/linux/mlx5_glue.h | 13 +++++++++++++ drivers/common/mlx5/mlx5_prm.h | 10 ++++++++++ 4 files changed, 40 insertions(+)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -172,6 +172,8 @@ has_sym_args = [ 'RDMA_NLDEV_ATTR_NDEV_INDEX' ], [ 'HAVE_MLX5_DR_FLOW_DUMP', 'infiniband/mlx5dv.h', 'mlx5dv_dump_dr_domain'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ],
drivers/common/mlx5/linux/mlx5_glue.c +15 -0
@@ -1063,6 +1063,19 @@#endif } +static void * +mlx5_glue_dr_create_flow_action_sampler ( +struct mlx5dv_dr_flow_sampler_attr *attr) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +return mlx5dv_dr_action_create_flow_sampler (attr); +#else + (void )attr; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1339,6 +1352,8 @@ .devx_port_query = mlx5_glue_devx_port_query, .dr_dump_domain = mlx5_glue_dr_dump_domain, .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, + .dr_create_flow_action_sampler = + mlx5_glue_dr_create_flow_action_sampler, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +13 -0
@@ -77,6 +77,7 @@#ifndef HAVE_MLX5DV_DR enum mlx5dv_dr_domain_type { unused, };struct mlx5dv_dr_domain ; +struct mlx5dv_dr_action ;#endif #ifndef HAVE_MLX5DV_DR_DEVX_PORT
@@ -87,6 +88,16 @@struct mlx5dv_dr_flow_meter_attr ;#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE +struct mlx5dv_dr_flow_sampler_attr { +uint32_t sample_ratio; +void *default_next_table; +size_t num_sample_actions; +struct mlx5dv_dr_action **sample_actions; +uint64_t action; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -309,6 +320,8 @@ struct mlx5_glue {const void *pp_context, uint32_t flags);void (*dv_free_pp)(struct mlx5dv_pp *pp); +void *(*dr_create_flow_action_sampler) + (struct mlx5dv_dr_flow_sampler_attr *attr); };extern const struct mlx5_glue *mlx5_glue;
drivers/common/mlx5/mlx5_prm.h +10 -0
@@ -1479,6 +1479,16 @@ struct mlx5_ifc_virtio_emulation_cap_bits {u8 reserved_at_0[0x8000 ]; }; +struct mlx5_ifc_set_action_in_bits { +u8 action_type[0x4 ]; +u8 field[0xc ]; +u8 reserved_at_10[0x3 ]; +u8 offset[0x5 ]; +u8 reserved_at_18[0x3 ]; +u8 length[0x5 ]; +u8 data[0x20 ]; +}; +struct mlx5_ifc_query_hca_cap_out_bits {u8 status[0x8 ];u8 reserved_at_8[0x18 ];
Signature · 1 line
1.8.3.1
PATCH v3 2/10 common/mlx5: query sampler object capability via DevX
In reply to Jiawei WangUpdate function mlx5_devx_cmd_query_hca_attr() to add the NIC Flow Table attributes query, then get the log_max_flow_sampler_num from flow table properties.
Add the related structs definition in mlx5_prm.h.
--- drivers/common/mlx5/mlx5_devx_cmds.c | 27 +++++++++++++++++++ drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)
drivers/common/mlx5/mlx5_devx_cmds.c +27 -0
@@ -751,6 +751,33 @@ struct mlx5_devx_obj *if (!attr->eth_net_offloads)return 0 ; +/* Query Flow Sampler Capability From FLow Table Properties Layout. */ +memset (in,0 ,sizeof (in)); +memset (out,0 ,sizeof (out)); +MLX5_SET (query_hca_cap_in, in, opcode,MLX5_CMD_OP_QUERY_HCA_CAP ); +MLX5_SET (query_hca_cap_in, in, op_mod, +MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | +MLX5_HCA_CAP_OPMOD_GET_CUR ); + + rc = mlx5_glue->devx_general_cmd (ctx, + in,sizeof (in), + out,sizeof (out)); +if (rc) + goto error; + status =MLX5_GET (query_hca_cap_out, out, status); + syndrome =MLX5_GET (query_hca_cap_out, out, syndrome); +if (status) { +DRV_LOG (DEBUG ,"Failed to query devx HCA capabilities, " +"status %x, syndrome = %x" , + status, syndrome); + attr->log_max_ft_sampler_num =0 ; +return -1 ; + } + hcattr =MLX5_ADDR_OF (query_hca_cap_out, out, capability); + attr->log_max_ft_sampler_num = +MLX5_GET (flow_table_nic_cap, + hcattr, flow_table_properties.log_max_ft_sampler_num); +/* Query HCA offloads for Ethernet protocol. */ memset (in,0 ,sizeof (in));memset (out,0 ,sizeof (out));
drivers/common/mlx5/mlx5_devx_cmds.h +1 -0
@@ -102,6 +102,7 @@ struct mlx5_hca_attr { uint32_t scatter_fcs_w_decap_disable:1; uint32_t regex:1;uint32_t regexp_num_of_engines; + uint32_t log_max_ft_sampler_num:8;struct mlx5_hca_qos_attr qos;struct mlx5_hca_vdpa_attr vdpa; };
drivers/common/mlx5/mlx5_prm.h +51 -0
69 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 3/10 net/mlx5: add the validate sample action
In reply to Jiawei WangAdd sample action validate function.
Sample Flow is supported in NIC-RX and FDB domains. For the NIC-RX the Sample Flow action list must include the destination queue action.
Only NIC-RX domain supports the optional actions list. FDB doesn't support any optional actions, the sampled packets is always forwarded to the E-Switch manager port.
--- drivers/net/mlx5/linux/mlx5_os.c | 14 ++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_flow.h | 1 + drivers/net/mlx5/mlx5_flow_dv.c | 137 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
@@ -1099,6 +1099,20 @@ } }#endif +#if defined(HAVE_MLX5DV_DR ) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE ) +if (config->hca_attr.log_max_ft_sampler_num >0 && + config->dv_flow_en) { + priv->sampler_en =1 ; +DRV_LOG (DEBUG ,"The Sampler enabled!\n" ); + }else { + priv->sampler_en =0 ; +if (!config->hca_attr.log_max_ft_sampler_num) +DRV_LOG (WARNING ,"No available register for" +" Sampler." ); +else +DRV_LOG (DEBUG ,"DV flow is not supported!\n" ); + } +#endif }if (config->tx_pp) { DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz",
drivers/net/mlx5/mlx5.h +1 -0
@@ -813,6 +813,7 @@ struct mlx5_priv { unsigned int counter_fallback:1; /* Use counter fallback management. */ unsigned int mtr_en:1; /* Whether support meter. */ unsigned int mtr_reg_share:1; /* Whether support meter REG_C share. */ + unsigned int sampler_en:1; /* Whether support sampler. */uint16_t domain_id;/* Switch domain identifier. */ uint16_t vport_id;/* Associated VF vport index (if any). */ uint32_t vport_meta_tag;/* Used for vport index match ove VF LAG. */
drivers/net/mlx5/mlx5_flow.h +1 -0
@@ -196,6 +196,7 @@ enum mlx5_feature_name {#define MLX5_FLOW_ACTION_SET_IPV6_DSCP (1ull << 33)#define MLX5_FLOW_ACTION_AGE (1ull << 34)#define MLX5_FLOW_ACTION_DEFAULT_MISS (1ull << 35) +#define MLX5_FLOW_ACTION_SAMPLE (1ull << 36)#define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | \
drivers/net/mlx5/mlx5_flow_dv.c +137 -0
149 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 4/10 net/mlx5: split sample flow into two sub flows
In reply to Jiawei WangThe flow with sample action will be splited into two sub flows:
the prefix sub flow with the all actions preceding the sample action and sample action itself, and the suffix sub flow with the actions following the sample action.
The original items remain in the prefix sub flow, add the implicit tag action with unique id to set in metadata register, and suffix sub flow uses the tag item to match with that unique id.
The flow split as below:
Original flow: items / actions pre / sample / actions sfx ->
prefix sub flow -
items / actions pre / set_tag action / sample
suffix sub flow -
tag_item / actions sfx
--- drivers/net/mlx5/mlx5.c | 11 ++ drivers/net/mlx5/mlx5.h | 3 + drivers/net/mlx5/mlx5_flow.c | 360 +++++++++++++++++++++++++++++++++++++++++-- drivers/net/mlx5/mlx5_flow.h | 37 +++++ 4 files changed, 394 insertions(+), 17 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -241,6 +241,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_jump_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_sample_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_sample_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +3 -0
@@ -39,6 +39,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_TAG ,/* Pool for tag resource. */ MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ +MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -512,6 +513,7 @@ struct mlx5_flow_tbl_resource {#define MLX5_FLOW_TABLE_LEVEL_METER (MLX5_MAX_TABLES - 4)#define MLX5_FLOW_TABLE_LEVEL_SUFFIX (MLX5_MAX_TABLES - 3)#define MLX5_MAX_TABLES_FDB UINT16_MAX +#define MLX5_FLOW_TABLE_FACTOR 10/* ID generation structure. */ struct mlx5_flow_id_pool {
@@ -640,6 +642,7 @@ struct mlx5_dev_ctx_shared {struct mlx5_hlist *tag_table;uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ +uint32_t sample_action_list;/* List of sample actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.c +343 -17
453 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow.h +37 -0
@@ -520,6 +520,39 @@ struct mlx5_flow_tbl_data_entry {uint32_t idx;/**< index for the indexed mempool. */ }; +/* Sub rdma-core actions list. */ +struct mlx5_flow_sub_actions_list { +uint32_t actions_num;/**< Number of sample actions. */ +uint64_t action_flags; +void *dr_queue_action; +void *dr_tag_action; +void *dr_cnt_action; +}; + +/* Sample sub-actions resource list. */ +struct mlx5_flow_sub_actions_idx { +uint32_t rix_hrxq;/**< Hash Rx queue object index. */ +uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t cnt; +}; + +/* Sample action resource structure. */ +struct mlx5_flow_dv_sample_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +uint32_t refcnt;/**< Reference counter. */ +void *verbs_action;/**< Verbs sample action object. */ +uint8_t ft_type;/** Flow Table Type */ +uint32_t ft_id;/** Flow Table Level */ +uint32_t ratio;/** Sample Ratio */ +uint64_t set_action;/** Restore reg_c0 value */ +void *normal_path_tbl;/** Flow Table pointer */ +void *default_miss;/** default_miss dr_action. */ +struct mlx5_flow_sub_actions_idx sample_idx; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -552,6 +585,8 @@ struct mlx5_flow_handle_dv {/**< Index to push VLAN action resource in cache. */ uint32_t rix_tag;/**< Index to the tag action. */ +uint32_t rix_sample; +/**< Index to sample action resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -617,6 +652,8 @@ struct mlx5_flow_dv_workspace {/**< Pointer to the jump action resource. */ struct mlx5_flow_dv_match_params value;/**< Holds the value that the packet is compared to. */ +struct mlx5_flow_dv_sample_resource *sample_res; +/**< Pointer to the sample action resource. */ };/*
Signature · 1 line
1.8.3.1
PATCH v3 5/10 net/mlx5: update translate function for sample action
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list, then create the sample DR action.
The metadata register value will be lost in the default path after Sampler in FDB due to CX5 HW limitation.
Since source vport also be shared with metadata register c0, MLX5 PMD would set the source vport to rdma-core and rdma-core will restore the regc0 value after sampler.
--- drivers/net/mlx5/mlx5_flow.c | 16 +- drivers/net/mlx5/mlx5_flow_dv.c | 510 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 511 insertions(+), 15 deletions(-)
drivers/net/mlx5/mlx5_flow.c +10 -6
@@ -5008,10 +5008,14 @@ struct mlx5_flow_tunnel_info {int hairpin_flow;uint32_t hairpin_id =0 ;struct rte_flow_attr attr_tx = { .priority =0 }; +struct rte_flow_attr attr_factor = {0 };int ret; - hairpin_flow =flow_check_hairpin_split (dev, attr, actions); - ret =flow_drv_validate (dev, attr, items, p_actions_rx, +memcpy ((void *)&attr_factor, (const void *)attr,sizeof (*attr)); +if (external) + attr_factor.group *=MLX5_FLOW_TABLE_FACTOR ; + hairpin_flow =flow_check_hairpin_split (dev, &attr_factor, actions); + ret =flow_drv_validate (dev, &attr_factor, items, p_actions_rx, external, hairpin_flow, error);if (ret <0 )return 0 ;
@@ -5030,7 +5034,7 @@ struct mlx5_flow_tunnel_info { rte_errno =ENOMEM ; goto error_before_flow; } - flow->drv_type =flow_get_drv_type (dev, attr); + flow->drv_type =flow_get_drv_type (dev, &attr_factor);if (hairpin_id !=0 ) flow->hairpin_flow_id = hairpin_id; MLX5_ASSERT(flow->drv_type > MLX5_FLOW_TYPE_MIN &&
@@ -5075,7 +5079,7 @@ struct mlx5_flow_tunnel_info {* depending on configuration. In the simplest * case it just creates unmodified original flow. */ - ret =flow_create_split_outer (dev, flow, attr, + ret =flow_create_split_outer (dev, flow, &attr_factor, buf->entry[i].pattern, p_actions_rx, external, idx, error);
@@ -5112,8 +5116,8 @@ struct mlx5_flow_tunnel_info {* the egress Flows belong to the different device and * copy table should be updated in peer NIC Rx domain. */ -if (attr->ingress && - (external || attr->group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { +if (attr_factor.ingress && + (external || attr_factor.group !=MLX5_FLOW_MREG_CP_TABLE_GROUP )) { ret =flow_mreg_update_copy_table (dev, flow, actions, error);if (ret) goto error;
drivers/net/mlx5/mlx5_flow_dv.c +501 -9
595 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 6/10 common/mlx5: add glue function for mirroring
In reply to Jiawei WangThe new DR destination array action is supported since the rdma-core version v32.
Destination array action is used group DR actions to a single action, And it can be used for mirroring packet and forward to every destination (port or queue) in the array.
--- drivers/common/mlx5/linux/meson.build | 2 ++ drivers/common/mlx5/linux/mlx5_glue.c | 26 ++++++++++++++++++++++++-- drivers/common/mlx5/linux/mlx5_glue.h | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-)
drivers/common/mlx5/linux/meson.build +2 -0
@@ -176,6 +176,8 @@ has_sym_args = [ 'mlx5dv_dr_action_create_flow_sampler'], [ 'HAVE_MLX5DV_DR_MEM_RECLAIM', 'infiniband/mlx5dv.h', 'mlx5dv_dr_domain_set_reclaim_device_memory'], + [ 'HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY', 'infiniband/mlx5dv.h', + 'mlx5dv_dr_action_create_dest_array'], [ 'HAVE_DEVLINK', 'linux/devlink.h', 'DEVLINK_GENL_NAME' ], ] config = configuration_data()
drivers/common/mlx5/linux/mlx5_glue.c +24 -2
@@ -1064,8 +1064,8 @@ }static void * -mlx5_glue_dr_create_flow_action_sampler ( -struct mlx5dv_dr_flow_sampler_attr *attr) +mlx5_glue_dr_create_flow_action_sampler + (struct mlx5dv_dr_flow_sampler_attr *attr) {#ifdef HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE return mlx5dv_dr_action_create_flow_sampler (attr);
@@ -1076,6 +1076,26 @@#endif } +static void * +mlx5_glue_dr_action_create_dest_array + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]) +{ +#ifdef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +return mlx5dv_dr_action_create_dest_array + (domain, + num_dest, + dests); +#else + (void )domain; + (void )num_dest; + (void )dests; + errno =ENOTSUP ; +return NULL ; +#endif +} +static int mlx5_glue_devx_query_eqn (struct ibv_context *ctx,uint32_t cpus,uint32_t *eqn)
@@ -1354,6 +1374,8 @@ .dr_reclaim_domain_memory = mlx5_glue_dr_reclaim_domain_memory, .dr_create_flow_action_sampler = mlx5_glue_dr_create_flow_action_sampler, + .dr_create_flow_action_dest_array = + mlx5_glue_dr_action_create_dest_array, .devx_query_eqn = mlx5_glue_devx_query_eqn, .devx_create_event_channel = mlx5_glue_devx_create_event_channel, .devx_destroy_event_channel = mlx5_glue_devx_destroy_event_channel,
drivers/common/mlx5/linux/mlx5_glue.h +22 -0
@@ -98,6 +98,24 @@ struct mlx5dv_dr_flow_sampler_attr { };#endif +#ifndef HAVE_MLX5_DR_CREATE_ACTION_DEST_ARRAY +enum mlx5dv_dr_action_dest_type { +MLX5DV_DR_ACTION_DEST , +MLX5DV_DR_ACTION_DEST_REFORMAT , +}; +struct mlx5dv_dr_action_dest_reformat { +struct mlx5dv_dr_action *reformat; +struct mlx5dv_dr_action *dest; +}; +struct mlx5dv_dr_action_dest_attr { +enum mlx5dv_dr_action_dest_type type; +union { +struct mlx5dv_dr_action *dest; +struct mlx5dv_dr_action_dest_reformat *dest_reformat; + }; +}; +#endif +#ifndef HAVE_IBV_DEVX_EVENT struct mlx5dv_devx_event_channel {int fd; };struct mlx5dv_devx_async_event_hdr ;
@@ -322,6 +340,10 @@ struct mlx5_glue {void (*dv_free_pp)(struct mlx5dv_pp *pp);void *(*dr_create_flow_action_sampler) (struct mlx5dv_dr_flow_sampler_attr *attr); +void *(*dr_create_flow_action_dest_array) + (void *domain, +size_t num_dest, +struct mlx5dv_dr_action_dest_attr *dests[]); };extern const struct mlx5_glue *mlx5_glue;
Signature · 1 line
1.8.3.1
PATCH v3 7/10 net/mlx5: update validation for mirroring flow
In reply to Jiawei WangMirroring flow using sample action with ratio is 1, and it doesn't support jump action with the same one flow.
Sample action must have destination actions like port or queue for mirroring, and don't need split function as sampling flow.
--- drivers/net/mlx5/mlx5_flow.c | 26 +++++++++++++- drivers/net/mlx5/mlx5_flow_dv.c | 78 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow.c +25 -1
@@ -4245,6 +4245,8 @@ struct mlx5_flow_tunnel_info {* * @param[in] actions * Pointer to the list of actions. +* @param[in] attr +* Flow rule attributes. * @param[in] action * The action to be check if exist. * @param[out] match_action_pos
@@ -4258,10 +4260,15 @@ struct mlx5_flow_tunnel_info {*/ static int flow_check_match_action (const struct rte_flow_action actions[], +const struct rte_flow_attr *attr,enum rte_flow_action_type action,int *match_action_pos,int *qrss_action_pos) { +const struct rte_flow_action_sample *sample;int actions_n =0 ; +int jump_flag =0 ; +uint32_t ratio =0 ; +int sub_type =0 ;int flag =0 ; *match_action_pos =-1 ;
@@ -4274,8 +4281,25 @@ struct mlx5_flow_tunnel_info {if (actions->type ==RTE_FLOW_ACTION_TYPE_QUEUE || actions->type ==RTE_FLOW_ACTION_TYPE_RSS ) *qrss_action_pos = actions_n; +if (actions->type ==RTE_FLOW_ACTION_TYPE_JUMP ) + jump_flag =1 ; +if (actions->type ==RTE_FLOW_ACTION_TYPE_SAMPLE ) { + sample = actions->conf; + ratio = sample->ratio; + sub_type = ((const struct rte_flow_action *) + (sample->actions))->type; + } actions_n++; } +if (flag && action ==RTE_FLOW_ACTION_TYPE_SAMPLE && attr->transfer) { +if (ratio ==1 ) { +/* JUMP Action not support for Mirroring; +* Mirroring support multi-destination; +*/ +if (!jump_flag && sub_type !=RTE_FLOW_ACTION_TYPE_END ) + flag =0 ; + } + }/* Count RTE_FLOW_ACTION_TYPE_END. */ return flag ? actions_n +1 :0 ; }
@@ -4827,7 +4851,7 @@ struct mlx5_flow_tunnel_info {int ret =0 ;if (priv->sampler_en) - actions_n =flow_check_match_action (actions, + actions_n =flow_check_match_action (actions, attr,RTE_FLOW_ACTION_TYPE_SAMPLE , &sample_action_pos, &qrss_action_pos);if (actions_n) {
drivers/net/mlx5/mlx5_flow_dv.c +74 -4
122 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 8/10 net/mlx5: update translate function for mirror
In reply to Jiawei WangTranslate the attribute of sample action that include sample ratio and sub actions list.
PMD will check the destination action number in current flow, if found multiple destination actions, then create the new destination array rdma action that group actions for each destination. Currently only support port or queue for destination action, and only encap action can be attached into one port destination.
--- drivers/net/mlx5/mlx5.c | 11 + drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.h | 23 ++ drivers/net/mlx5/mlx5_flow_dv.c | 463 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 470 insertions(+), 29 deletions(-)
drivers/net/mlx5/mlx5.c +11 -0
@@ -252,6 +252,17 @@ static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = .free = mlx5_free, .type = "mlx5_sample_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_dest_array_resource), + .trunk_size = 64, + .grow_trunk = 3, + .grow_shift = 2, + .need_lock = 0, + .release_mem_en = 1, + .malloc = mlx5_malloc, + .free = mlx5_free, + .type = "mlx5_dest_array_ipool", + }, #endif { .size = sizeof(struct mlx5_flow_meter),
drivers/net/mlx5/mlx5.h +2 -0
@@ -40,6 +40,7 @@ enum mlx5_ipool_index {MLX5_IPOOL_PORT_ID ,/* Pool for port id resource. */ MLX5_IPOOL_JUMP ,/* Pool for jump resource. */ MLX5_IPOOL_SAMPLE ,/* Pool for sample resource. */ +MLX5_IPOOL_DEST_ARRAY ,/* Pool for destination array resource. */ #endifMLX5_IPOOL_MTR ,/* Pool for meter resource. */ MLX5_IPOOL_MCP, /* Pool for metadata resource. */
@@ -643,6 +644,7 @@ struct mlx5_dev_ctx_shared {uint32_t port_id_action_list;/* List of port ID actions. */ uint32_t push_vlan_action_list;/* List of push VLAN actions. */ uint32_t sample_action_list;/* List of sample actions. */ +uint32_t dest_array_list;/* List of destination array actions. */ struct mlx5_flow_counter_mng cmng;/* Counters management structure. */ struct mlx5_flow_default_miss_resource default_miss;/* Default miss action resource structure. */
drivers/net/mlx5/mlx5_flow.h +23 -0
@@ -527,6 +527,8 @@ struct mlx5_flow_sub_actions_list {void *dr_queue_action;void *dr_tag_action;void *dr_cnt_action; +void *dr_port_id_action; +void *dr_encap_action; };/* Sample sub-actions resource list. */
@@ -534,6 +536,8 @@ struct mlx5_flow_sub_actions_idx {uint32_t rix_hrxq;/**< Hash Rx queue object index. */ uint32_t rix_tag;/**< Index to the tag action. */ uint32_t cnt; +uint32_t rix_port_id_action;/**< Index to port ID action resource. */ +uint32_t rix_encap_decap;/**< Index to encap/decap resource. */ };/* Sample action resource structure. */
@@ -553,6 +557,21 @@ struct mlx5_flow_dv_sample_resource {/**< Action resources. */ }; +#define MLX5_MAX_DEST_NUM 2 + +/* Destination array action resource structure. */ +struct mlx5_flow_dv_dest_array_resource { +ILIST_ENTRY (uint32_t )next;/**< Pointer to next element. */ +uint32_t refcnt;/**< Reference counter. */ +uint8_t ft_type;/** Flow Table Type */ +uint8_t num_of_dest;/**< Number of destination actions. */ +void *action;/**< Pointer to the rdma core action. */ +struct mlx5_flow_sub_actions_idx sample_idx[MLX5_MAX_DEST_NUM ]; +/**< Action index resources. */ +struct mlx5_flow_sub_actions_list sample_act[MLX5_MAX_DEST_NUM ]; +/**< Action resources. */ +}; +/* Verbs specification header. */ struct ibv_spec_header {enum ibv_flow_spec_type type;
@@ -587,6 +606,8 @@ struct mlx5_flow_handle_dv {/**< Index to the tag action. */ uint32_t rix_sample;/**< Index to sample action resource in cache. */ +uint32_t rix_dest_array; +/**< Index to destination array resource in cache. */ } __rte_packed;/** Device flow handle structure: used both for creating & destroying. */
@@ -654,6 +675,8 @@ struct mlx5_flow_dv_workspace {/**< Holds the value that the packet is compared to. */ struct mlx5_flow_dv_sample_resource *sample_res;/**< Pointer to the sample action resource. */ +struct mlx5_flow_dv_dest_array_resource *dest_array_res; +/**< Pointer to the destination array resource. */ };/*
drivers/net/mlx5/mlx5_flow_dv.c +434 -29
648 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 9/10 doc: add the sample flow limitation description
In reply to Jiawei WangAdd description about the sample flow limitation.
Sample Flow supports in NIC-Rx and E-Switch domains.
Due to Metadata register c0 is deleted while doing the loopback, so that only support forward the sampling packet into E-Switch manager port, no additional action support in sample flow.
--- doc/guides/nics/mlx5.rst | 6 ++++++ 1 file changed, 6 insertions(+)
doc/guides/nics/mlx5.rst +6 -0
@@ -311,6 +311,12 @@ Limitations for some NICs (such as ConnectX-6 Dx and BlueField 2). The capability bit ``scatter_fcs_w_decap_disable`` shows NIC support. +- Sample flow: + + - Supports ``RTE_FLOW_ACTION_TYPE_SAMPLE`` action only within NIC Rx and E-Switch steering domain. + - The E-Switch Sample flow must have the eswitch_manager VPORT destination (PF or ECPF) and no additional actions. + - For ConnectX-5, the ``RTE_FLOW_ACTION_TYPE_SAMPLE`` is typically used as first action in the E-Switch egress flow if with header modify or encapsulation actions. + Statistics ----------
Signature · 1 line
1.8.3.1
PATCH v3 10/10 doc: update offload dependencies document
In reply to Jiawei WangAdd the offloads minimum versions for new sampling feature.
--- doc/guides/nics/mlx5.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/guides/nics/mlx5.rst +5 -0
@@ -1458,6 +1458,11 @@ Supported hardware offloads | | | rdma-core 26 | | rdma-core 26 | | | | ConnectX-5 | | ConnectX-5 | +-----------------------+-----------------+-----------------+ + | Sampling | | DPDK 20.11 | | DPDK 20.11 | + | | | OFED 5.2 | | OFED 5.2 | + | | | rdma-core 32 | | rdma-core 32 | + | | | ConnectX-5 | | ConnectX-5 | + +-----------------------+-----------------+-----------------+ Notes for metadata ------------------
Signature · 1 line
1.8.3.1
Re: [dpdk-dev] [PATCH v3 00/10] Add sampling and mirroring support in MLX5 PMD
In reply to Jiawei WangHi,
Quoted 51 lines
-----Original Message-----
From: Jiawei Wang <[email protected]>
Sent: Tuesday, October 13, 2020 5:12 PM
To: Ori Kam <[email protected]>; Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; NBU- Contact-Thomas Monjalon <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>; Asaf Penso <[email protected]>
Subject: [PATCH v3 00/10] Add sampling and mirroring support in MLX5 PMDThis patch set implement the flow sampling and mirroring for mlx5 driver. MLX5 PMD driver will be responsible for validate and translate the sample action while creating a flow.
Depends-on: series-12828 ("support the flow-based traffic sampling")
v3:
* Use C11 atomic builtins for sampling and mirroring resource register and release.v2:
* Fix incorrect check for E-Switch sample split flow.Jiawei Wang (10):
common/mlx5: glue for sample action common/mlx5: query sampler object capability via DevX net/mlx5: add the validate sample action net/mlx5: split sample flow into two sub flows net/mlx5: update translate function for sample action common/mlx5: add glue function for mirroring net/mlx5: update validation for mirroring flow net/mlx5: update translate function for mirror
doc: add the sample flow limitation description
doc: update offload dependencies documentdoc/guides/nics/mlx5.rst | 11 + drivers/common/mlx5/linux/meson.build | 4 + drivers/common/mlx5/linux/mlx5_glue.c | 37 ++ drivers/common/mlx5/linux/mlx5_glue.h | 35 + drivers/common/mlx5/mlx5_devx_cmds.c | 27 + drivers/common/mlx5/mlx5_devx_cmds.h | 1 + drivers/common/mlx5/mlx5_prm.h | 61 ++ drivers/net/mlx5/linux/mlx5_os.c | 14 + drivers/net/mlx5/mlx5.c | 22 + drivers/net/mlx5/mlx5.h | 6 + drivers/net/mlx5/mlx5_flow.c | 400 +++++++++++- drivers/net/mlx5/mlx5_flow.h | 61 ++ drivers/net/mlx5/mlx5_flow_dv.c | 1130 ++++++++++++++++++++++++++++++++- 13 files changed, 1773 insertions(+), 36 deletions(-)
Quoted 2 lines
--
1.8.3.1
Series applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh