support yellow color policy in mlx5
cover support yellow color policy in mlx5
When creating a meter policy, the actions for yellow color can be specified together with green color. The mlx5 PMD now supports to set the policy for yellow.
The actions list that is supported for yellow is the same as that for green.
Bing Zhao (6):
net/mlx5: add yellow color default policy net/mlx5: support yellow in meter policy validation net/mlx5: enable meter bucket overflow for yellow color net/mlx5: added support for yellow policy rules net/mlx5: split policies handling of colors
doc: update mlx5 metering policy part
doc/guides/rel_notes/release_21_08.rst | 5 + drivers/net/mlx5/mlx5.h | 4 +- drivers/net/mlx5/mlx5_flow.c | 41 +-- drivers/net/mlx5/mlx5_flow_aso.c | 3 + drivers/net/mlx5/mlx5_flow_dv.c | 343 +++++++++++++++---------- drivers/net/mlx5/mlx5_flow_meter.c | 56 ++-- 6 files changed, 271 insertions(+), 181 deletions(-)
Signature · 1 line
2.27.0
PATCH 1/6 net/mlx5: add yellow color default policy
To support the yellow color for the default meter policy, the default policy action for yellow should be created together with the green policy.
The default policy action for yellow action is the same as that for green. In the same table, the same matcher will be reused for yellow and the destination group will be the same.
--- drivers/net/mlx5/mlx5_flow_dv.c | 88 +++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 31 deletions(-)
drivers/net/mlx5/mlx5_flow_dv.c +57 -31
@@ -15365,19 +15365,18 @@ __flow_dv_create_policy_flow(struct rte_eth_dev *dev,if (!is_default_policy && (priv->representor || priv->master)) {if (flow_dv_translate_item_port_id (dev, matcher.buf, value.buf,NULL , attr)) { -DRV_LOG (ERR , -"Failed to create meter policy flow with port." ); +DRV_LOG (ERR ,"Failed to create meter policy%d flow's" +" value with port." , color);return -1 ; } }flow_dv_match_meta_reg (matcher.buf, value.buf, - (enum modify_reg )color_reg_c_idx, -rte_col_2_mlx5_col (color), -UINT32_MAX ); - ret =mlx5_flow_os_create_flow (matcher_object, - (void *)&value, actions_n, actions, rule); + (enum modify_reg )color_reg_c_idx, +rte_col_2_mlx5_col (color),UINT32_MAX ); + ret =mlx5_flow_os_create_flow (matcher_object, (void *)&value, + actions_n, actions, rule);if (ret) { -DRV_LOG (ERR ,"Failed to create meter policy flow." ); +DRV_LOG (ERR ,"Failed to create meter policy%d flow." , color);return -1 ; }return 0 ;
@@ -15416,8 +15415,8 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,if (!is_default_policy && (priv->representor || priv->master)) {if (flow_dv_translate_item_port_id (dev, matcher.mask.buf, value.buf,NULL , attr)) { -DRV_LOG (ERR , -"Failed to register meter drop matcher with port." ); +DRV_LOG (ERR ,"Failed to register meter policy%d matcher" +" with port." , priority);return -1 ; } }
@@ -15425,9 +15424,11 @@ __flow_dv_create_policy_matcher(struct rte_eth_dev *dev,if (priority <RTE_COLOR_RED )flow_dv_match_meta_reg (matcher.mask.buf, value.buf, (enum modify_reg )color_reg_c_idx,0 , color_mask); - matcher.priority = priority; +/* Adjust the priority */ + matcher.priority = (priority ==RTE_COLOR_YELLOW ) ? +RTE_COLOR_GREEN : priority; matcher.crc =rte_raw_cksum ((const void *)matcher.mask.buf, - matcher.mask.size); + matcher.mask.size); entry =mlx5_cache_register (&tbl_data->matchers, &ctx);if (!entry) {DRV_LOG (ERR ,"Failed to register meter drop matcher." );
@@ -15490,15 +15491,18 @@ __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev,/* Prepare matchers. */ color_reg_c_idx = ret;for (i =0 ; i <RTE_COLORS ; i++) { -if (i ==RTE_COLOR_YELLOW || !acts[i].actions_n) +if (!acts[i].actions_n)continue ; attr.priority = i;if (!sub_policy->color_matcher[i]) {/* Create matchers for Color. */ if (__flow_dv_create_policy_matcher (dev, color_reg_c_idx, i, sub_policy, - &attr, is_default_policy, &flow_err)) + &attr, is_default_policy, &flow_err)) { +DRV_LOG (ERR , +"Failed to create color%u matcher." , i);return -1 ; + } }/* Create flow, matching color. */ if (acts[i].actions_n)
@@ -15509,8 +15513,11 @@ __flow_dv_create_domain_policy_rules(struct rte_eth_dev *dev, acts[i].dv_actions, is_default_policy, &sub_policy->color_rule[i], - &attr)) + &attr)) { +DRV_LOG (ERR , +"Failed to create color%u rule." , i);return -1 ; + } }return 0 ; }
@@ -15665,8 +15672,7 @@ __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain)sizeof (struct mlx5_flow_meter_def_policy ), RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);if (!def_policy) { -DRV_LOG (ERR ,"Failed to alloc " -"default policy table." ); +DRV_LOG (ERR ,"Failed to alloc default policy table." ); goto def_policy_error; } mtrmng->def_policy[domain] = def_policy;
@@ -15682,26 +15688,46 @@ __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain) } def_policy->sub_policy.jump_tbl[RTE_COLOR_GREEN ] = jump_tbl; tbl_data =container_of (jump_tbl, - struct mlx5_flow_tbl_data_entry, tbl); + struct mlx5_flow_tbl_data_entry, tbl); def_policy->dr_jump_action[RTE_COLOR_GREEN ] = tbl_data->jump.action; - acts[RTE_COLOR_GREEN ].dv_actions[0 ] = - tbl_data->jump.action; + acts[RTE_COLOR_GREEN ].dv_actions[0 ] = tbl_data->jump.action; acts[RTE_COLOR_GREEN ].actions_n =1 ; +/* +* YELLOW has the same default policy as GREEN does. +* G & Y share the same table and action. +*/ + jump_tbl =flow_dv_tbl_resource_get (dev, +MLX5_FLOW_TABLE_LEVEL_METER , + egress, transfer, false,NULL ,0 , +0 ,MLX5_MTR_TABLE_ID_SUFFIX , &error); +if (!jump_tbl) { +DRV_LOG (ERR , +"Failed to get meter suffix table." ); + goto def_policy_error; + } + def_policy->sub_policy.jump_tbl[RTE_COLOR_YELLOW ] = jump_tbl; + tbl_data =container_of (jump_tbl, + struct mlx5_flow_tbl_data_entry, tbl); + def_policy->dr_jump_action[RTE_COLOR_YELLOW ] = + tbl_data->jump.action; + acts[RTE_COLOR_YELLOW ].dv_actions[0 ] = tbl_data->jump.action; + acts[RTE_COLOR_YELLOW ].actions_n =1 ;/* Create jump action to the drop table. */ if (!mtrmng->drop_tbl[domain]) { mtrmng->drop_tbl[domain] =flow_dv_tbl_resource_get (dev,MLX5_FLOW_TABLE_LEVEL_METER , - egress, transfer, false,NULL ,0 , -0 ,MLX5_MTR_TABLE_ID_DROP , &error); + egress, transfer, false,NULL ,0 , +0 ,MLX5_MTR_TABLE_ID_DROP , &error);if (!mtrmng->drop_tbl[domain]) { -DRV_LOG (ERR ,"Failed to create " -"meter drop table for default policy." ); +DRV_LOG (ERR ,"Failed to create meter " +"drop table for default policy." ); goto def_policy_error; } } +/* all RED: unique Drop table for jump action. */ tbl_data =container_of (mtrmng->drop_tbl[domain], - struct mlx5_flow_tbl_data_entry, tbl); + struct mlx5_flow_tbl_data_entry, tbl); def_policy->dr_jump_action[RTE_COLOR_RED ] = tbl_data->jump.action; acts[RTE_COLOR_RED ].dv_actions[0 ] = tbl_data->jump.action;
@@ -15711,15 +15737,14 @@ __flow_dv_create_domain_def_policy(struct rte_eth_dev *dev, uint32_t domain) &def_policy->sub_policy, egress, transfer, true, acts);if (ret) { -DRV_LOG (ERR ,"Failed to create " -"default policy rules." ); - goto def_policy_error; +DRV_LOG (ERR ,"Failed to create default policy rules." ); + goto def_policy_error; } }return 0 ; def_policy_error:__flow_dv_destroy_domain_def_policy (dev, - (enum mlx5_meter_domain )domain); + (enum mlx5_meter_domain )domain);return -1 ; }
@@ -15742,8 +15767,9 @@ flow_dv_create_def_policy(struct rte_eth_dev *dev)if (!priv->config.dv_esw_en && i ==MLX5_MTR_DOMAIN_TRANSFER )continue ;if (__flow_dv_create_domain_def_policy (dev, i)) { -DRV_LOG (ERR , -"Failed to create default policy" ); +DRV_LOG (ERR ,"Failed to create default policy" ); +/* Rollback the created default policies for others. */ +flow_dv_destroy_def_policy (dev);return -1 ; } }
Signature · 1 line
2.27.0
PATCH 2/6 net/mlx5: support yellow in meter policy validation
In reply to Bing ZhaoIn the previous implementation, the policy for yellow color was not supported. The action validation for yellow was skipped.
Since the yellow color policy needs to be supported, the validation should also be done for yellow color. In the meanwhile, due to the fact that color policies of one meter should be used for the same flow(s), the domains supported of both colors shall be the same. If both of the colors have RSS as the fate actions, except the queues, all other parameters of RSS should be the same.
--- drivers/net/mlx5/mlx5.h | 4 +- drivers/net/mlx5/mlx5_flow.c | 4 +- drivers/net/mlx5/mlx5_flow_dv.c | 151 +++++++++++++++++------------ drivers/net/mlx5/mlx5_flow_meter.c | 3 +- 4 files changed, 97 insertions(+), 65 deletions(-)
drivers/net/mlx5/mlx5.h +2 -2
@@ -608,8 +608,8 @@ struct mlx5_dev_shared_port {/*ASO flow meter structures*/ /* Modify this value if enum rte_mtr_color changes. */ #define RTE_MTR_DROPPED RTE_COLORS -/* Yellow is not supported. */ -#define MLX5_MTR_RTE_COLORS (RTE_COLOR_GREEN + 1) +/* Yellow is now supported. */ +#define MLX5_MTR_RTE_COLORS (RTE_COLOR_YELLOW + 1)/* table_id 22 bits in mlx5_flow_tbl_key so limit policy number. */ #define MLX5_MAX_SUB_POLICY_TBL_NUM 0x3FFFFF#define MLX5_INVALID_POLICY_ID UINT32_MAX
drivers/net/mlx5/mlx5_flow.c +2 -2
@@ -7093,8 +7093,8 @@ mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,const struct mlx5_flow_driver_ops *fops; fops =flow_get_drv_ops (MLX5_FLOW_TYPE_DV ); -return fops->validate_mtr_acts (dev, actions, attr, - is_rss, domain_bitmap, is_def_policy, error); +return fops->validate_mtr_acts (dev, actions, attr, is_rss, + domain_bitmap, is_def_policy, error); }/**
drivers/net/mlx5/mlx5_flow_dv.c +91 -60
305 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_meter.c +2 -1
@@ -660,7 +660,8 @@ mlx5_flow_meter_policy_add(struct rte_eth_dev *dev,RTE_MTR_ERROR_TYPE_METER_POLICY_ID ,NULL , "policy ID exists. "); ret =mlx5_flow_validate_mtr_acts (dev, policy->actions, &attr, - &is_rss, &domain_bitmap, &is_def_policy, error); + &is_rss, &domain_bitmap, + &is_def_policy, error);if (ret)return ret;if (!domain_bitmap)
Signature · 1 line
2.27.0
PATCH 3/6 net/mlx5: enable meter bucket overflow for yellow color
In reply to Bing ZhaoTo support the meter policy for yellow action, the prerequisite is that the hardware needs to support the EBS and then the yellow color of packets can be marked for the further steering.
In the current implementation EBS and overflow were ignored when creating a meter profile. With this commit, if EBS is set by the application, the generation of yellow color will be enabled in the hardware for flow rules steering of packets.
--- drivers/net/mlx5/mlx5_flow_aso.c | 3 +++ drivers/net/mlx5/mlx5_flow_meter.c | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow_aso.c +3 -0
@@ -747,6 +747,9 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq, wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =RTE_BE32 ((1 <<ASO_DSEG_VALID_OFFSET ) | (MLX5_FLOW_COLOR_GREEN <<ASO_DSEG_SC_OFFSET )); +if (fm->profile->srtcm_prm.ebs_eir) + wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |= +RTE_BE32 (1 <<ASO_DSEG_BO_OFFSET ); sq->head++; sq->pi +=2 ;/* Each WQE contains 2 WQEBB's. */ rte_io_wmb ();
drivers/net/mlx5/mlx5_flow_meter.c +5 -5
@@ -312,9 +312,9 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, cbs_man = man; cbs_exp = exp; srtcm->cbs_cir =rte_cpu_to_be_32 (cbs_exp <<ASO_DSEG_CBS_EXP_OFFSET | - cbs_man <<ASO_DSEG_CBS_MAN_OFFSET | - cir_exp <<ASO_DSEG_CIR_EXP_OFFSET | - cir_man); + cbs_man <<ASO_DSEG_CBS_MAN_OFFSET | + cir_exp <<ASO_DSEG_CIR_EXP_OFFSET | + cir_man);mlx5_flow_meter_xbs_man_exp_calc (ebs, &man, &exp);/* Check if ebs mantissa is too large. */ if (exp >ASO_DSEG_EXP_MASK )
@@ -325,7 +325,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, ebs_man = man; ebs_exp = exp; srtcm->ebs_eir =rte_cpu_to_be_32 (ebs_exp <<ASO_DSEG_EBS_EXP_OFFSET | - ebs_man <<ASO_DSEG_EBS_MAN_OFFSET ); + ebs_man <<ASO_DSEG_EBS_MAN_OFFSET );return 0 ; }
@@ -414,7 +414,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev,return ret;/* Meter profile memory allocation. */ fmp =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (struct mlx5_flow_meter_profile ), -RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY );if (fmp ==NULL ) return -rte_mtr_error_set(error, ENOMEM, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
Signature · 1 line
2.27.0
PATCH 4/6 net/mlx5: added support for yellow policy rules
In reply to Bing ZhaoWhen creating a meter policy, both / either of the action rules for green and yellow colors may be provided. After validation, usually the actions are created before the meter is using by a flow rule.
If there is action specified for the yellow color, the action rules should be created together with green color in the same time. The action of green / yellow color can be empty, then the default behavior is the jump action of the rule, just the same as that of the default policy.
If the fate action of either one color is queue / RSS, all the actions rules will be created on the flow splitting stage instead of the policy adding stage.
--- drivers/net/mlx5/mlx5_flow_dv.c | 43 +++++++++++++++++++----------- drivers/net/mlx5/mlx5_flow_meter.c | 43 ++++++++++++++++++------------ 2 files changed, 53 insertions(+), 33 deletions(-)
drivers/net/mlx5/mlx5_flow_dv.c +27 -16
@@ -14702,22 +14702,34 @@ __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,sizeof (struct mlx5_modification_cmd ) * (MLX5_MAX_MODIFY_NUM + 1)]; } mhdr_dummy; +struct mlx5_flow_mtr_mng *mtrmng = priv->sh->mtrmng; egress = (domain ==MLX5_MTR_DOMAIN_EGRESS ) ?1 :0 ; transfer = (domain ==MLX5_MTR_DOMAIN_TRANSFER ) ?1 :0 ;memset (&dh,0 ,sizeof (struct mlx5_flow_handle ));memset (&dev_flow,0 ,sizeof (struct mlx5_flow ));memset (&port_id_action,0 , -sizeof (struct mlx5_flow_dv_port_id_action_resource )); +sizeof (struct mlx5_flow_dv_port_id_action_resource )); dev_flow.handle = &dh; dev_flow.dv.port_id_action = &port_id_action; dev_flow.external = true;for (i =0 ; i <RTE_COLORS ; i++) {if (i <MLX5_MTR_RTE_COLORS ) act_cnt = &mtr_policy->act_cnt[i]; -for (act = actions[i]; - act && act->type !=RTE_FLOW_ACTION_TYPE_END ; - act++) { + act = actions[i]; +/* No policy action, use default. */ +if (!act || act->type ==RTE_FLOW_ACTION_TYPE_END ) { +if (!mtrmng->def_policy[domain]) +return -rte_mtr_error_set (error, +ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY , +NULL , +"Default policy not created." ); + act_cnt->dr_jump_action[domain] = + mtrmng->def_policy[domain]->dr_jump_action[i]; +continue ; + } +for (; act->type !=RTE_FLOW_ACTION_TYPE_END ; act++) {switch (act->type) {case RTE_FLOW_ACTION_TYPE_MARK : {
@@ -14933,6 +14945,7 @@ __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev, action_flags |=MLX5_FLOW_ACTION_PORT_ID ;break ; } +/* G & Y can use the same table by default. */ case RTE_FLOW_ACTION_TYPE_JUMP : {uint32_t jump_group =0 ;
@@ -14947,7 +14960,7 @@ __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev, (1 << MLX5_SCALE_FLOW_GROUP_BIT), };struct mlx5_flow_meter_sub_policy *sub_policy = - mtr_policy->sub_policys[domain][0 ]; + mtr_policy->sub_policys[domain][0 ];if (i >=MLX5_MTR_RTE_COLORS ) return -rte_mtr_error_set(error,
@@ -15036,6 +15049,7 @@ flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev, ret =__flow_dv_create_domain_policy_acts (dev, mtr_policy, actions, (enum mlx5_meter_domain )i, error); +/* Rollback is done in mlx5 layer. */ if (ret)return ret; }
@@ -15538,12 +15552,10 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,for (i =0 ; i <RTE_COLORS ; i++) { acts[i].actions_n =0 ; -if (i ==RTE_COLOR_YELLOW ) -continue ;if (i ==RTE_COLOR_RED ) {/* Only support drop on red. */ acts[i].dv_actions[0 ] = - mtr_policy->dr_drop_action[domain]; + mtr_policy->dr_drop_action[domain]; acts[i].actions_n =1 ;continue ; }
@@ -15555,13 +15567,12 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev, "mark action for policy.");return -1 ; } - acts[i].dv_actions[acts[i].actions_n] = - tag->action; + acts[i].dv_actions[acts[i].actions_n] = tag->action; acts[i].actions_n++; }if (mtr_policy->act_cnt[i].modify_hdr) { acts[i].dv_actions[acts[i].actions_n] = - mtr_policy->act_cnt[i].modify_hdr->action; + mtr_policy->act_cnt[i].modify_hdr->action; acts[i].actions_n++; }if (mtr_policy->act_cnt[i].fate_action) {
@@ -15576,7 +15587,7 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,return -1 ; } acts[i].dv_actions[acts[i].actions_n] = - port_action->action; + port_action->action; acts[i].actions_n++;break ;case MLX5_FLOW_FATE_DROP :
@@ -15588,15 +15599,15 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,case MLX5_FLOW_FATE_SHARED_RSS :case MLX5_FLOW_FATE_QUEUE : hrxq =mlx5_ipool_get - (priv->sh->ipool[MLX5_IPOOL_HRXQ ], - sub_policy->rix_hrxq[i]); + (priv->sh->ipool[MLX5_IPOOL_HRXQ ], + sub_policy->rix_hrxq[i]);if (!hrxq) {DRV_LOG (ERR ,"Failed to find " "queue action for policy." );return -1 ; } acts[i].dv_actions[acts[i].actions_n] = - hrxq->action; + hrxq->action; acts[i].actions_n++;break ;default :
@@ -15610,7 +15621,7 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,if (__flow_dv_create_domain_policy_rules (dev, sub_policy, egress, transfer, false, acts)) {DRV_LOG (ERR , -"Failed to create policy rules per domain." ); +"Failed to create policy rules per domain." );return -1 ; }return 0 ;
drivers/net/mlx5/mlx5_flow_meter.c +26 -17
98 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 5/6 net/mlx5: split policies handling of colors
In reply to Bing ZhaoIf the fate action is either RSS or Queue of a meter policy, the action will only be created in the flow splitting stage. With queue as the fate action, only one sub-policy is needed. And RSS will have more than one sub-policies if there is an expansion.
Since the RSS parameters are the same for both green and yellow colors except the queues, the expansion result will be unique. Even if only one color has the RSS action, the checking and possible expansion will be done then. For each sub-policy, the action rules need to be created separately on its own policy table.
--- drivers/net/mlx5/mlx5_flow.c | 37 +++++++++++--------- drivers/net/mlx5/mlx5_flow_dv.c | 61 +++++++++++++++++---------------- 2 files changed, 51 insertions(+), 47 deletions(-)
drivers/net/mlx5/mlx5_flow.c +20 -17
@@ -4604,7 +4604,7 @@ get_meter_sub_policy(struct rte_eth_dev *dev,uint32_t i;MLX5_ASSERT (wks); -/** +/* * This is a tmp dev_flow, * no need to register any matcher for it in translate. */
@@ -4612,18 +4612,19 @@ get_meter_sub_policy(struct rte_eth_dev *dev,for (i =0 ; i <MLX5_MTR_RTE_COLORS ; i++) {struct mlx5_flow dev_flow = {0 };struct mlx5_flow_handle dev_handle = { {0 } }; +uint8_t fate = policy->act_cnt[i].fate_action; -if (policy->is_rss) { +if (fate ==MLX5_FLOW_FATE_SHARED_RSS ) {const void *rss_act = policy->act_cnt[i].rss->conf;struct rte_flow_action rss_actions[2 ] = { [0 ] = { .type =RTE_FLOW_ACTION_TYPE_RSS , - .conf = rss_act + .conf = rss_act, }, [1 ] = { .type =RTE_FLOW_ACTION_TYPE_END , - .conf =NULL + .conf =NULL , } };
@@ -4650,7 +4651,8 @@ get_meter_sub_policy(struct rte_eth_dev *dev, rss_desc_v[i].tunnel = !!(dev_flow.handle->layers &MLX5_FLOW_LAYER_TUNNEL ); - }else { + rss_desc[i] = &rss_desc_v[i]; + }else if (fate ==MLX5_FLOW_FATE_QUEUE ) {/* This is queue action. */ rss_desc_v[i] = wks->rss_desc; rss_desc_v[i].key_len =0 ;
@@ -4658,24 +4660,24 @@ get_meter_sub_policy(struct rte_eth_dev *dev, rss_desc_v[i].queue = &policy->act_cnt[i].queue; rss_desc_v[i].queue_num =1 ; + rss_desc[i] = &rss_desc_v[i]; + }else { + rss_desc[i] =NULL ; } - rss_desc[i] = &rss_desc_v[i]; } sub_policy =flow_drv_meter_sub_policy_rss_prepare (dev, flow, policy, rss_desc); }else {enum mlx5_meter_domain mtr_domain = attr->transfer ?MLX5_MTR_DOMAIN_TRANSFER : - attr->egress ?MLX5_MTR_DOMAIN_EGRESS : -MLX5_MTR_DOMAIN_INGRESS ; + (attr->egress ?MLX5_MTR_DOMAIN_EGRESS : +MLX5_MTR_DOMAIN_INGRESS ); sub_policy = policy->sub_policys[mtr_domain][0 ]; } -if (!sub_policy) { +if (!sub_policy)rte_flow_error_set (error,EINVAL , -RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , -"Failed to get meter sub-policy." ); - goto exit; - } +RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"Failed to get meter sub-policy." ); exit:return sub_policy; }
@@ -4810,6 +4812,7 @@ flow_meter_split_prep(struct rte_eth_dev *dev,struct mlx5_flow_meter_sub_policy *sub_policy;struct mlx5_flow_tbl_data_entry *tbl_data; +/* Either G or Y can still use default policy. */ if (!fm->def_policy) { sub_policy = get_meter_sub_policy(dev, flow, fm->policy_id, attr,
@@ -4819,8 +4822,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, }else {enum mlx5_meter_domain mtr_domain = attr->transfer ?MLX5_MTR_DOMAIN_TRANSFER : - attr->egress ?MLX5_MTR_DOMAIN_EGRESS : -MLX5_MTR_DOMAIN_INGRESS ; + (attr->egress ?MLX5_MTR_DOMAIN_EGRESS : +MLX5_MTR_DOMAIN_INGRESS ); sub_policy = &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
@@ -4836,8 +4839,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, actions_pre++;if (!tag_action)return rte_flow_error_set (error,ENOMEM , -RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , -"No tag action space." ); +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"No tag action space." );if (!mtr_flow_id) { tag_action->type =RTE_FLOW_ACTION_TYPE_VOID ; goto exit;
drivers/net/mlx5/mlx5_flow_dv.c +31 -30
158 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 6/6 doc: update mlx5 metering policy part
In reply to Bing ZhaoAdded support for yellow color.
--- doc/guides/rel_notes/release_21_08.rst | 5 +++++ 1 file changed, 5 insertions(+)
doc/guides/rel_notes/release_21_08.rst +5 -0
@@ -55,6 +55,11 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Updated Mellanox mlx5 driver.** + + Updated the Mellanox mlx5 driver with new features and improvements, including: + + * Added support for metering policy actions of yellow color. Removed Items -------------
Signature · 1 line
2.27.0
v2 cover support yellow color policy in mlx5
In reply to Bing ZhaoWhen creating a meter policy, the actions for yellow color can be specified together with green color. The mlx5 PMD now supports to set the policy actions for yellow color.
The actions list that is supported for yellow is the same as that for green.
---
v2:
* bug fixes
* add policy and profile consistency checking
* add trTCM RFC2698 and RFC4115 support
---
Bing Zhao (7):
net/mlx5: handle yellow case in default meter policy net/mlx5: enable meter bucket overflow for yellow color net/mlx5: added support for yellow policy rules net/mlx5: split policies handling of colors net/mlx5: support yellow in meter policy validation net/mlx5: check consistency of meter policy and profile net/mlx5: add meter support for trTCM profiles
doc/guides/nics/mlx5.rst | 7 +- doc/guides/rel_notes/release_21_08.rst | 2 + drivers/common/mlx5/mlx5_prm.h | 5 +- drivers/net/mlx5/mlx5.h | 20 +- drivers/net/mlx5/mlx5_flow.c | 46 +-- drivers/net/mlx5/mlx5_flow.h | 4 +- drivers/net/mlx5/mlx5_flow_aso.c | 21 ++ drivers/net/mlx5/mlx5_flow_dv.c | 470 +++++++++++++++---------- drivers/net/mlx5/mlx5_flow_meter.c | 203 +++++++---- 9 files changed, 490 insertions(+), 288 deletions(-)
Signature · 1 line
2.27.0
PATCH v2 1/7 net/mlx5: handle yellow case in default meter policy
In order to support the yellow color for the default meter policy, the default policy action for yellow should be created together with the green policy.
The default policy action for yellow action is the same as that for green. In the same table, the same matcher will be reused for yellow and the destination group will be the same.
--- drivers/net/mlx5/mlx5.h | 6 ++ drivers/net/mlx5/mlx5_flow_dv.c | 144 +++++++++++++++++++------------- 2 files changed, 93 insertions(+), 57 deletions(-)
drivers/net/mlx5/mlx5.h +6 -0
@@ -641,6 +641,12 @@ struct mlx5_dev_shared_port {#define MLX5_MTR_TABLE_ID_SUFFIX 1/* Drop table_id on MLX5_FLOW_TABLE_LEVEL_METER. */ #define MLX5_MTR_TABLE_ID_DROP 2 +/* Priority of the meter policy matcher. */ +#define MLX5_MTR_POLICY_MATCHER_PRIO 0 +/* Default policy. */ +#define MLX5_MTR_POLICY_MODE_DEF 1 +/* Only green color valid. */ +#define MLX5_MTR_POLICY_MODE_OG 2enum mlx5_meter_domain {MLX5_MTR_DOMAIN_INGRESS ,
drivers/net/mlx5/mlx5_flow_dv.c +87 -57
272 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 2/7 net/mlx5: enable meter bucket overflow for yellow color
In reply to Bing ZhaoTo support the meter policy for yellow action, the prerequisite is that the hardware needs to support the EBS, as defined in the RFC2697.
https://datatracker.ietf.org/doc/html/rfc2697
Then some of the packets can be marked as yellow if the tokens of C bucket is not enough but enough in E bucket. The color could be used for the further steering of the packets.
In the current implementation EBS and overflow were ignored when creating a meter profile. With this commit, if EBS is set by the application, the generation of yellow color will be enabled in the hardware for flow rules steering of packets.
--- drivers/net/mlx5/mlx5_flow_aso.c | 4 ++++ drivers/net/mlx5/mlx5_flow_meter.c | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -747,6 +747,10 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq, wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =RTE_BE32 ((1 <<ASO_DSEG_VALID_OFFSET ) | (MLX5_FLOW_COLOR_GREEN <<ASO_DSEG_SC_OFFSET )); +/* Only needed for RFC2697. */ +if (fm->profile->srtcm_prm.ebs_eir) + wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |= +RTE_BE32 (1 <<ASO_DSEG_BO_OFFSET ); sq->head++; sq->pi +=2 ;/* Each WQE contains 2 WQEBB's. */ rte_io_wmb ();
drivers/net/mlx5/mlx5_flow_meter.c +5 -5
@@ -319,9 +319,9 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, cbs_man = man; cbs_exp = exp; srtcm->cbs_cir =rte_cpu_to_be_32 (cbs_exp <<ASO_DSEG_CBS_EXP_OFFSET | - cbs_man <<ASO_DSEG_CBS_MAN_OFFSET | - cir_exp <<ASO_DSEG_CIR_EXP_OFFSET | - cir_man); + cbs_man <<ASO_DSEG_CBS_MAN_OFFSET | + cir_exp <<ASO_DSEG_CIR_EXP_OFFSET | + cir_man);mlx5_flow_meter_xbs_man_exp_calc (ebs, &man, &exp);/* Check if ebs mantissa is too large. */ if (exp >ASO_DSEG_EXP_MASK )
@@ -332,7 +332,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, ebs_man = man; ebs_exp = exp; srtcm->ebs_eir =rte_cpu_to_be_32 (ebs_exp <<ASO_DSEG_EBS_EXP_OFFSET | - ebs_man <<ASO_DSEG_EBS_MAN_OFFSET ); + ebs_man <<ASO_DSEG_EBS_MAN_OFFSET );return 0 ; }
@@ -421,7 +421,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev,return ret;/* Meter profile memory allocation. */ fmp =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (struct mlx5_flow_meter_profile ), -RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY );if (fmp ==NULL ) return -rte_mtr_error_set(error, ENOMEM, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
Signature · 1 line
2.27.0
PATCH v2 3/7 net/mlx5: added support for yellow policy rules
In reply to Bing ZhaoWhen creating a meter policy, both / either of the action rules for green and yellow colors may be provided. After validation, usually the actions are created before the meter is using by a flow rule.
If there is action specified for the yellow color, the action rules should be created together with green color in the same time. The action of green / yellow color can be empty, then the default behavior is the jump action of the rule, just the same as that of the default policy.
If the fate action of either one color is queue / RSS, all the actions rules will be created on the flow splitting stage instead of the policy adding stage.
--- drivers/net/mlx5/mlx5.h | 4 +++ drivers/net/mlx5/mlx5_flow_dv.c | 50 +++++++++++++++------------ drivers/net/mlx5/mlx5_flow_meter.c | 54 ++++++++++++++++++++---------- 3 files changed, 68 insertions(+), 40 deletions(-)
drivers/net/mlx5/mlx5.h +4 -0
@@ -744,6 +744,10 @@ struct mlx5_flow_meter_policy {/* Is queue action in policy table. */ uint32_t is_hierarchy:1;/* Is meter action in policy table. */ + uint32_t skip_y:1; +/* If yellow color policy is skipped. */ + uint32_t skip_g:1; +/* If green color policy is skipped. */ rte_spinlock_t sl;uint32_t ref_cnt;/* Use count. */
drivers/net/mlx5/mlx5_flow_dv.c +28 -22
141 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_meter.c +36 -18
111 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 4/7 net/mlx5: split policies handling of colors
In reply to Bing ZhaoIf the fate action is either RSS or Queue of a meter policy, the action will only be created in the flow splitting stage. With queue as the fate action, only one sub-policy is needed. And RSS will have more than one sub-policies if there is an expansion.
Since the RSS parameters are the same for both green and yellow colors except the queues, the expansion result will be unique. Even if only one color has the RSS action, the checking and possible expansion will be done then. For each sub-policy, the action rules need to be created separately on its own policy table.
--- drivers/net/mlx5/mlx5_flow.c | 40 ++++++++++---------- drivers/net/mlx5/mlx5_flow_dv.c | 67 +++++++++++++++++---------------- 2 files changed, 55 insertions(+), 52 deletions(-)
drivers/net/mlx5/mlx5_flow.c +21 -19
@@ -4687,7 +4687,7 @@ get_meter_sub_policy(struct rte_eth_dev *dev,struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS ] = {0 };uint32_t i; -/** +/* * This is a tmp dev_flow, * no need to register any matcher for it in translate. */
@@ -4695,18 +4695,19 @@ get_meter_sub_policy(struct rte_eth_dev *dev,for (i =0 ; i <MLX5_MTR_RTE_COLORS ; i++) {struct mlx5_flow dev_flow = {0 };struct mlx5_flow_handle dev_handle = { {0 } }; +uint8_t fate = final_policy->act_cnt[i].fate_action; -if (final_policy->is_rss) { +if (fate ==MLX5_FLOW_FATE_SHARED_RSS ) {const void *rss_act = final_policy->act_cnt[i].rss->conf;struct rte_flow_action rss_actions[2 ] = { [0 ] = { .type =RTE_FLOW_ACTION_TYPE_RSS , - .conf = rss_act + .conf = rss_act, }, [1 ] = { .type =RTE_FLOW_ACTION_TYPE_END , - .conf =NULL + .conf =NULL , } };
@@ -4731,9 +4732,10 @@ get_meter_sub_policy(struct rte_eth_dev *dev, rss_desc_v[i].hash_fields ? rss_desc_v[i].queue_num :1 ; rss_desc_v[i].tunnel = - !!(dev_flow.handle->layers & -MLX5_FLOW_LAYER_TUNNEL ); - }else { + !!(dev_flow.handle->layers & +MLX5_FLOW_LAYER_TUNNEL ); + rss_desc[i] = &rss_desc_v[i]; + }else if (fate ==MLX5_FLOW_FATE_QUEUE ) {/* This is queue action. */ rss_desc_v[i] = wks->rss_desc; rss_desc_v[i].key_len =0 ;
@@ -4741,24 +4743,24 @@ get_meter_sub_policy(struct rte_eth_dev *dev, rss_desc_v[i].queue = &final_policy->act_cnt[i].queue; rss_desc_v[i].queue_num =1 ; + rss_desc[i] = &rss_desc_v[i]; + }else { + rss_desc[i] =NULL ; } - rss_desc[i] = &rss_desc_v[i]; } sub_policy =flow_drv_meter_sub_policy_rss_prepare (dev, flow, policy, rss_desc); }else {enum mlx5_meter_domain mtr_domain = attr->transfer ?MLX5_MTR_DOMAIN_TRANSFER : - attr->egress ?MLX5_MTR_DOMAIN_EGRESS : -MLX5_MTR_DOMAIN_INGRESS ; + (attr->egress ?MLX5_MTR_DOMAIN_EGRESS : +MLX5_MTR_DOMAIN_INGRESS ); sub_policy = policy->sub_policys[mtr_domain][0 ]; } -if (!sub_policy) { +if (!sub_policy)rte_flow_error_set (error,EINVAL , -RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , -"Failed to get meter sub-policy." ); - goto exit; - } +RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"Failed to get meter sub-policy." ); exit:return sub_policy; }
@@ -4956,8 +4958,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, }else {enum mlx5_meter_domain mtr_domain = attr->transfer ?MLX5_MTR_DOMAIN_TRANSFER : - attr->egress ?MLX5_MTR_DOMAIN_EGRESS : -MLX5_MTR_DOMAIN_INGRESS ; + (attr->egress ?MLX5_MTR_DOMAIN_EGRESS : +MLX5_MTR_DOMAIN_INGRESS ); sub_policy = &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
@@ -4973,8 +4975,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, actions_pre++;if (!tag_action)return rte_flow_error_set (error,ENOMEM , -RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , -"No tag action space." ); +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"No tag action space." );if (!mtr_flow_id) { tag_action->type =RTE_FLOW_ACTION_TYPE_VOID ; goto exit;
drivers/net/mlx5/mlx5_flow_dv.c +34 -33
173 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v2 5/7 net/mlx5: support yellow in meter policy validation
In reply to Bing ZhaoIn the previous implementation, the policy for yellow color was not supported. The action validation for yellow was skipped.
Since the yellow color policy needs to be supported, the validation should also be done for the yellow color. In the meanwhile, due to the fact that color policies of one meter should be used for the same flow(s), the domains supported of both colors should be the same. If both of the colors have RSS as the termination actions, except the queues, all other parameters of RSS should be the same.
--- doc/guides/nics/mlx5.rst | 6 +- doc/guides/rel_notes/release_21_08.rst | 1 + drivers/net/mlx5/mlx5.h | 8 +- drivers/net/mlx5/mlx5_flow.c | 6 +- drivers/net/mlx5/mlx5_flow.h | 4 +- drivers/net/mlx5/mlx5_flow_dv.c | 209 ++++++++++++++++--------- drivers/net/mlx5/mlx5_flow_meter.c | 15 +- 7 files changed, 156 insertions(+), 93 deletions(-)
doc/guides/nics/mlx5.rst +3 -3
@@ -421,18 +421,18 @@ Limitations - All the meter colors with drop action will be counted only by the global drop statistics. - Green color is not supported with drop action. - - Yellow detection is not supported. + - Yellow detection is only supported with ASO metering. - Red color must be with drop action. - Meter statistics are supported only for drop case. - - Meter yellow color detection is not supported. - A meter action created with pre-defined policy must be the last action in the flow except single case where the policy actions are: - green: NULL or END. - yellow: NULL or END. - RED: DROP / END. - The only supported meter policy actions: - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG. - - yellow: must be empty. + - yellow: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG. - RED: must be DROP. + - Policy actions of RSS for green and yellow should have the same configuration except queues. - meter profile packet mode is supported. - Integrity:
doc/guides/rel_notes/release_21_08.rst +1 -0
@@ -91,6 +91,7 @@ New Features * Added matching on IPv4 Internet Header Length (IHL). * Added support for matching on VXLAN header last 8-bits reserved field. * Optimized multi-thread flow rule insertion rate. + * Added support for metering policy actions of yellow color. * **Added Wangxun ngbe PMD.**
drivers/net/mlx5/mlx5.h +5 -3
@@ -629,11 +629,11 @@ struct mlx5_dev_shared_port {*/ #define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8 -/*ASO flow meter structures*/ +/* ASO flow meter structures */ /* Modify this value if enum rte_mtr_color changes. */ #define RTE_MTR_DROPPED RTE_COLORS -/* Yellow is not supported. */ -#define MLX5_MTR_RTE_COLORS (RTE_COLOR_GREEN + 1) +/* Yellow is now supported. */ +#define MLX5_MTR_RTE_COLORS (RTE_COLOR_YELLOW + 1)/* table_id 22 bits in mlx5_flow_tbl_key so limit policy number. */ #define MLX5_MAX_SUB_POLICY_TBL_NUM 0x3FFFFF#define MLX5_INVALID_POLICY_ID UINT32_MAX
@@ -647,6 +647,8 @@ struct mlx5_dev_shared_port {#define MLX5_MTR_POLICY_MODE_DEF 1/* Only green color valid. */ #define MLX5_MTR_POLICY_MODE_OG 2 +/* Only yellow color valid. */ +#define MLX5_MTR_POLICY_MODE_OY 3enum mlx5_meter_domain {MLX5_MTR_DOMAIN_INGRESS ,
drivers/net/mlx5/mlx5_flow.c +3 -3
@@ -7199,14 +7199,14 @@ mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,struct rte_flow_attr *attr, bool *is_rss, uint8_t *domain_bitmap, - bool *is_def_policy, + uint8_t *policy_mode, struct rte_mtr_error *error) { const struct mlx5_flow_driver_ops *fops; fops =flow_get_drv_ops (MLX5_FLOW_TYPE_DV ); -return fops->validate_mtr_acts (dev, actions, attr, - is_rss, domain_bitmap, is_def_policy, error); +return fops->validate_mtr_acts (dev, actions, attr, is_rss, + domain_bitmap, policy_mode, error); }/**
drivers/net/mlx5/mlx5_flow.h +2 -2
@@ -1209,7 +1209,7 @@ typedef int (*mlx5_flow_validate_mtr_acts_t)struct rte_flow_attr *attr, bool *is_rss, uint8_t *domain_bitmap, - bool *is_def_policy, + uint8_t *policy_mode, struct rte_mtr_error *error);typedef int (*mlx5_flow_create_mtr_acts_t ) (struct rte_eth_dev *dev,
@@ -1690,7 +1690,7 @@ int mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,struct rte_flow_attr *attr, bool *is_rss, uint8_t *domain_bitmap, - bool *is_def_policy, + uint8_t *policy_mode, struct rte_mtr_error *error);void mlx5_flow_destroy_mtr_acts (struct rte_eth_dev *dev,struct mlx5_flow_meter_policy *mtr_policy);
drivers/net/mlx5/mlx5_flow_dv.c +134 -75
388 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_meter.c +8 -7
@@ -582,7 +582,7 @@ mlx5_flow_meter_policy_validate(struct rte_eth_dev *dev,struct rte_flow_attr attr = { .transfer = priv->config.dv_esw_en ?1 :0 };bool is_rss = false; -bool is_def_policy = false; +uint8_t policy_mode;uint8_t domain_bitmap;int ret;
@@ -591,7 +591,7 @@ mlx5_flow_meter_policy_validate(struct rte_eth_dev *dev,RTE_MTR_ERROR_TYPE_METER_POLICY , NULL, "meter policy unsupported."); ret =mlx5_flow_validate_mtr_acts (dev, policy->actions, &attr, - &is_rss, &domain_bitmap, &is_def_policy, error); + &is_rss, &domain_bitmap, &policy_mode, error);if (ret)return ret;return 0 ;
@@ -674,7 +674,7 @@ mlx5_flow_meter_policy_add(struct rte_eth_dev *dev,struct mlx5_flow_meter_policy *mtr_policy =NULL ;struct mlx5_flow_meter_sub_policy *sub_policy;bool is_rss = false; -bool is_def_policy = false; +uint8_t policy_mode;uint32_t i;int ret;uint32_t policy_size =sizeof (struct mlx5_flow_meter_policy );
@@ -701,14 +701,15 @@ mlx5_flow_meter_policy_add(struct rte_eth_dev *dev,RTE_MTR_ERROR_TYPE_METER_POLICY_ID , NULL, "policy ID exists. "); ret =mlx5_flow_validate_mtr_acts (dev, policy->actions, &attr, - &is_rss, &domain_bitmap, &is_def_policy, error); + &is_rss, &domain_bitmap, + &policy_mode, error);if (ret)return ret;if (!domain_bitmap)return -rte_mtr_error_set (error,ENOTSUP , -RTE_MTR_ERROR_TYPE_METER_POLICY , -NULL ,"fail to find policy domain." ); -if (is_def_policy) { +RTE_MTR_ERROR_TYPE_METER_POLICY , +NULL ,"fail to find policy domain." ); +if (policy_mode ==MLX5_MTR_POLICY_MODE_DEF ) {if (priv->sh->mtrmng->def_policy_id !=MLX5_INVALID_POLICY_ID ) return -rte_mtr_error_set(error, EEXIST, RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
Signature · 1 line
2.27.0
PATCH v2 6/7 net/mlx5: check consistency of meter policy and profile
In reply to Bing ZhaoIn the previous implementation, only green color policy was supported in mlx5 PMD. Since yellow color policy is supported now, the consistency of meter policy and profile should be checked.
1. If the profile supports yellow but the policy doesn't, an error should be returned when creating the meter. Or else, there is no explicit steering action for the packets marked with yellow.
2. If the policy supports yellow but the profile doesn't, it will be considered as a valid case. Even if no packet will be handled with the yellow steering action, it is just like that only the green policy presents.
Usually the green color is supported by default, but when it is disabled intentionally with setting the CBS to a small value like zero in the profile, the similar checking on green policy and profile should also be done.
--- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_flow_meter.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +2 -0
@@ -870,6 +870,8 @@ struct mlx5_flow_meter_profile {/**< srtcm_rfc2697 struct. */ };uint32_t ref_cnt;/**< Use count. */ + uint32_t g_support:1; /**< If G color will be generated. */ + uint32_t y_support:1; /**< If Y color will be generated. */ };/* 2 meters in each ASO cache line */
drivers/net/mlx5/mlx5_flow_meter.c +14 -2
@@ -333,6 +333,10 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, ebs_exp = exp; srtcm->ebs_eir =rte_cpu_to_be_32 (ebs_exp <<ASO_DSEG_EBS_EXP_OFFSET | ebs_man <<ASO_DSEG_EBS_MAN_OFFSET ); +if (srtcm->cbs_cir) + fmp->g_support =1 ; +if (srtcm->ebs_eir) + fmp->y_support =1 ;return 0 ; }
@@ -1136,13 +1140,13 @@ mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id,if (!priv->config.dv_esw_en) domain_bitmap &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT ; }else { - mtr_policy =mlx5_flow_meter_policy_find (dev, - params->meter_policy_id, &policy_idx);if (!priv->sh->meter_aso_en)return -rte_mtr_error_set (error,ENOTSUP ,RTE_MTR_ERROR_TYPE_UNSPECIFIED ,NULL ,"Part of the policies cannot be " "supported without ASO " ); + mtr_policy =mlx5_flow_meter_policy_find (dev, + params->meter_policy_id, &policy_idx);if (!mtr_policy) return -rte_mtr_error_set(error, ENOENT, RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
@@ -1153,6 +1157,14 @@ mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id, MLX5_MTR_DOMAIN_EGRESS_BIT : 0) | (mtr_policy->transfer ?MLX5_MTR_DOMAIN_TRANSFER_BIT :0 ); +if (fmp->g_support && mtr_policy->skip_g) +return -rte_mtr_error_set (error,ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY_ID , +NULL ,"Meter green policy is empty." ); +if (fmp->y_support && mtr_policy->skip_y) +return -rte_mtr_error_set (error,ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY_ID , +NULL ,"Meter yellow policy is empty." ); }/* Allocate the flow meter memory. */ if (priv->sh->meter_aso_en) {
Signature · 1 line
2.27.0
PATCH v2 7/7 net/mlx5: add meter support for trTCM profiles
In reply to Bing ZhaoThe support of RFC2698 and RFC4115 are added in mlx5 PMD. Only the ASO metering supports these two profiles.
--- doc/guides/nics/mlx5.rst | 1 + doc/guides/rel_notes/release_21_08.rst | 1 + drivers/common/mlx5/mlx5_prm.h | 5 +- drivers/net/mlx5/mlx5_flow_aso.c | 23 ++++- drivers/net/mlx5/mlx5_flow_meter.c | 112 ++++++++++++++++--------- 5 files changed, 98 insertions(+), 44 deletions(-)
doc/guides/nics/mlx5.rst +1 -0
@@ -434,6 +434,7 @@ Limitations - RED: must be DROP. - Policy actions of RSS for green and yellow should have the same configuration except queues. - meter profile packet mode is supported. + - meter profiles of RFC2697, RFC2698 and RFC4115 are supported. - Integrity:
doc/guides/rel_notes/release_21_08.rst +1 -0
@@ -92,6 +92,7 @@ New Features * Added support for matching on VXLAN header last 8-bits reserved field. * Optimized multi-thread flow rule insertion rate. * Added support for metering policy actions of yellow color. + * Added support for metering trTCM RFC2698 and RFC4115. * **Added Wangxun ngbe PMD.**
drivers/common/mlx5/mlx5_prm.h +3 -2
@@ -3031,11 +3031,12 @@ struct mlx5_aso_mtr_dseg {#define ASO_DSEG_VALID_OFFSET 31#define ASO_DSEG_BO_OFFSET 30#define ASO_DSEG_SC_OFFSET 28 +#define ASO_DSEG_BBOG_OFFSET 27#define ASO_DSEG_MTR_MODE 24#define ASO_DSEG_CBS_EXP_OFFSET 24#define ASO_DSEG_CBS_MAN_OFFSET 16 -#define ASO_DSEG_CIR_EXP_MASK 0x1F -#define ASO_DSEG_CIR_EXP_OFFSET 8 +#define ASO_DSEG_XIR_EXP_MASK 0x1F +#define ASO_DSEG_XIR_EXP_OFFSET 8#define ASO_DSEG_EBS_EXP_OFFSET 24#define ASO_DSEG_EBS_MAN_OFFSET 16#define ASO_DSEG_EXP_MASK 0x1F
drivers/net/mlx5/mlx5_flow_aso.c +20 -3
@@ -747,10 +747,27 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq, wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =RTE_BE32 ((1 <<ASO_DSEG_VALID_OFFSET ) | (MLX5_FLOW_COLOR_GREEN <<ASO_DSEG_SC_OFFSET )); -/* Only needed for RFC2697. */ -if (fm->profile->srtcm_prm.ebs_eir) +switch (fmp->profile.alg) { +case RTE_MTR_SRTCM_RFC2697 : +/* Only needed for RFC2697. */ +if (fm->profile->srtcm_prm.ebs_eir) + wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |= +RTE_BE32 (1 <<ASO_DSEG_BO_OFFSET ); +break ; +case RTE_MTR_TRTCM_RFC2698 : wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |= -RTE_BE32 (1 <<ASO_DSEG_BO_OFFSET ); +RTE_BE32 (1 <<ASO_DSEG_BBOG_OFFSET ); +break ; +case RTE_MTR_TRTCM_RFC4115 : +default : +break ; + } +/* +* Note: +* Due to software performance reason, the token fields will not be +* set when posting the WQE to ASO SQ. It will be filled by the HW +* automatically. +*/ sq->head++; sq->pi +=2 ;/* Each WQE contains 2 WQEBB's. */ rte_io_wmb ();
drivers/net/mlx5/mlx5_flow_meter.c +73 -39
196 lines not on this page · raw message
Signature · 1 line
2.27.0
v3 cover support yellow color policy in mlx5
In reply to Bing ZhaoWhen creating a meter policy, the actions for yellow color can be specified together with green color. The mlx5 PMD now supports to set the policy actions for yellow color.
The actions list that is supported for yellow is the same as that for green.
---
v3:
* patch set building fix
* bug fixes and document update
v2:
* bug fixes
* add policy and profile consistency checking
* add trTCM RFC2698 and RFC4115 support
---
Bing Zhao (7):
net/mlx5: handle yellow case in default meter policy net/mlx5: enable meter bucket overflow for yellow color net/mlx5: added support for yellow policy rules net/mlx5: split policies handling of colors net/mlx5: support yellow in meter policy validation net/mlx5: check consistency of meter policy and profile net/mlx5: add meter support for trTCM profiles
doc/guides/nics/mlx5.rst | 10 +- doc/guides/rel_notes/release_21_08.rst | 2 + drivers/common/mlx5/mlx5_prm.h | 5 +- drivers/net/mlx5/mlx5.h | 20 +- drivers/net/mlx5/mlx5_flow.c | 46 +-- drivers/net/mlx5/mlx5_flow.h | 4 +- drivers/net/mlx5/mlx5_flow_aso.c | 21 ++ drivers/net/mlx5/mlx5_flow_dv.c | 471 +++++++++++++++---------- drivers/net/mlx5/mlx5_flow_meter.c | 203 +++++++---- 9 files changed, 492 insertions(+), 290 deletions(-)
Signature · 1 line
2.27.0
PATCH v3 1/7 net/mlx5: handle yellow case in default meter policy
In order to support the yellow color for the default meter policy, the default policy action for yellow should be created together with the green policy.
The default policy action for yellow action is the same as that for green. In the same table, the same matcher will be reused for yellow and the destination group will be the same.
--- drivers/net/mlx5/mlx5.h | 6 +- drivers/net/mlx5/mlx5_flow_dv.c | 144 +++++++++++++++++++------------- 2 files changed, 91 insertions(+), 59 deletions(-)
drivers/net/mlx5/mlx5.h +4 -2
@@ -632,8 +632,8 @@ struct mlx5_dev_shared_port {/*ASO flow meter structures*/ /* Modify this value if enum rte_mtr_color changes. */ #define RTE_MTR_DROPPED RTE_COLORS -/* Yellow is not supported. */ -#define MLX5_MTR_RTE_COLORS (RTE_COLOR_GREEN + 1) +/* Yellow is now supported. */ +#define MLX5_MTR_RTE_COLORS (RTE_COLOR_YELLOW + 1)/* table_id 22 bits in mlx5_flow_tbl_key so limit policy number. */ #define MLX5_MAX_SUB_POLICY_TBL_NUM 0x3FFFFF#define MLX5_INVALID_POLICY_ID UINT32_MAX
@@ -641,6 +641,8 @@ struct mlx5_dev_shared_port {#define MLX5_MTR_TABLE_ID_SUFFIX 1/* Drop table_id on MLX5_FLOW_TABLE_LEVEL_METER. */ #define MLX5_MTR_TABLE_ID_DROP 2 +/* Priority of the meter policy matcher. */ +#define MLX5_MTR_POLICY_MATCHER_PRIO 0enum mlx5_meter_domain {MLX5_MTR_DOMAIN_INGRESS ,
drivers/net/mlx5/mlx5_flow_dv.c +87 -57
272 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 2/7 net/mlx5: enable meter bucket overflow for yellow color
In reply to Bing ZhaoTo support the meter policy for yellow action, the prerequisite is that the hardware needs to support the EBS, as defined in the RFC2697.
https://datatracker.ietf.org/doc/html/rfc2697
Then some of the packets can be marked as yellow if the tokens of C bucket is not enough but enough in E bucket. The color could be used for the further steering of the packets.
In the current implementation EBS and overflow were ignored when creating a meter profile. With this commit, if EBS is set by the application, the generation of yellow color will be enabled in the hardware for flow rules steering of packets.
--- drivers/net/mlx5/mlx5_flow_aso.c | 4 ++++ drivers/net/mlx5/mlx5_flow_meter.c | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-)
drivers/net/mlx5/mlx5_flow_aso.c +4 -0
@@ -747,6 +747,10 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq, wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =RTE_BE32 ((1 <<ASO_DSEG_VALID_OFFSET ) | (MLX5_FLOW_COLOR_GREEN <<ASO_DSEG_SC_OFFSET )); +/* Only needed for RFC2697. */ +if (fm->profile->srtcm_prm.ebs_eir) + wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |= +RTE_BE32 (1 <<ASO_DSEG_BO_OFFSET ); sq->head++; sq->pi +=2 ;/* Each WQE contains 2 WQEBB's. */ rte_io_wmb ();
drivers/net/mlx5/mlx5_flow_meter.c +5 -5
@@ -319,9 +319,9 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, cbs_man = man; cbs_exp = exp; srtcm->cbs_cir =rte_cpu_to_be_32 (cbs_exp <<ASO_DSEG_CBS_EXP_OFFSET | - cbs_man <<ASO_DSEG_CBS_MAN_OFFSET | - cir_exp <<ASO_DSEG_CIR_EXP_OFFSET | - cir_man); + cbs_man <<ASO_DSEG_CBS_MAN_OFFSET | + cir_exp <<ASO_DSEG_CIR_EXP_OFFSET | + cir_man);mlx5_flow_meter_xbs_man_exp_calc (ebs, &man, &exp);/* Check if ebs mantissa is too large. */ if (exp >ASO_DSEG_EXP_MASK )
@@ -332,7 +332,7 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, ebs_man = man; ebs_exp = exp; srtcm->ebs_eir =rte_cpu_to_be_32 (ebs_exp <<ASO_DSEG_EBS_EXP_OFFSET | - ebs_man <<ASO_DSEG_EBS_MAN_OFFSET ); + ebs_man <<ASO_DSEG_EBS_MAN_OFFSET );return 0 ; }
@@ -421,7 +421,7 @@ mlx5_flow_meter_profile_add(struct rte_eth_dev *dev,return ret;/* Meter profile memory allocation. */ fmp =mlx5_malloc (MLX5_MEM_ZERO ,sizeof (struct mlx5_flow_meter_profile ), -RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY ); +RTE_CACHE_LINE_SIZE ,SOCKET_ID_ANY );if (fmp ==NULL ) return -rte_mtr_error_set(error, ENOMEM, RTE_MTR_ERROR_TYPE_UNSPECIFIED,
Signature · 1 line
2.27.0
PATCH v3 3/7 net/mlx5: added support for yellow policy rules
In reply to Bing ZhaoWhen creating a meter policy, both / either of the action rules for green and yellow colors may be provided. After validation, usually the actions are created before the meter is using by a flow rule.
If there is action specified for the yellow color, the action rules should be created together with green color in the same time. The action of green / yellow color can be empty, then the default behavior is the jump action of the rule, just the same as that of the default policy.
If the fate action of either one color is queue / RSS, all the actions rules will be created on the flow splitting stage instead of the policy adding stage.
--- drivers/net/mlx5/mlx5_flow_dv.c | 46 ++++++++++++++------------- drivers/net/mlx5/mlx5_flow_meter.c | 50 +++++++++++++++++++----------- 2 files changed, 56 insertions(+), 40 deletions(-)
drivers/net/mlx5/mlx5_flow_dv.c +24 -22
@@ -15214,7 +15214,7 @@ __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,struct mlx5_priv *priv = dev->data->dev_private;struct rte_flow_error flow_err;const struct rte_flow_action *act; -uint64_t action_flags =0 ; +uint64_t action_flags;struct mlx5_flow_handle dh;struct mlx5_flow dev_flow;struct mlx5_flow_dv_port_id_action_resource port_id_action;
@@ -15234,21 +15234,20 @@ __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,memset (&dh,0 ,sizeof (struct mlx5_flow_handle ));memset (&dev_flow,0 ,sizeof (struct mlx5_flow ));memset (&port_id_action,0 , -sizeof (struct mlx5_flow_dv_port_id_action_resource )); +sizeof (struct mlx5_flow_dv_port_id_action_resource ));memset (mhdr_res,0 ,sizeof (*mhdr_res)); mhdr_res->ft_type = transfer ?MLX5DV_FLOW_TABLE_TYPE_FDB : - egress ? -MLX5DV_FLOW_TABLE_TYPE_NIC_TX : -MLX5DV_FLOW_TABLE_TYPE_NIC_RX ; + (egress ?MLX5DV_FLOW_TABLE_TYPE_NIC_TX : +MLX5DV_FLOW_TABLE_TYPE_NIC_RX ); dev_flow.handle = &dh; dev_flow.dv.port_id_action = &port_id_action; dev_flow.external = true;for (i =0 ; i <RTE_COLORS ; i++) {if (i <MLX5_MTR_RTE_COLORS ) act_cnt = &mtr_policy->act_cnt[i]; + action_flags =0 ;for (act = actions[i]; - act && act->type !=RTE_FLOW_ACTION_TYPE_END ; - act++) { + act && act->type !=RTE_FLOW_ACTION_TYPE_END ; act++) {switch (act->type) {case RTE_FLOW_ACTION_TYPE_MARK : {
@@ -15456,7 +15455,7 @@ __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev, (1 << MLX5_SCALE_FLOW_GROUP_BIT), };struct mlx5_flow_meter_sub_policy *sub_policy = - mtr_policy->sub_policys[domain][0 ]; + mtr_policy->sub_policys[domain][0 ];if (i >=MLX5_MTR_RTE_COLORS ) return -rte_mtr_error_set(error,
@@ -15500,6 +15499,10 @@ __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev, action_flags |=MLX5_FLOW_ACTION_JUMP ;break ; } +/* +* No need to check meter hierarchy for Y or R colors +* here since it is done in the validation stage. +*/ case RTE_FLOW_ACTION_TYPE_METER : {const struct rte_flow_action_meter *mtr;
@@ -15615,6 +15618,7 @@ flow_dv_create_mtr_policy_acts(struct rte_eth_dev *dev, ret =__flow_dv_create_domain_policy_acts (dev, mtr_policy, actions, (enum mlx5_meter_domain )i, error); +/* Cleaning resource is done in the caller level. */ if (ret)return ret; }
@@ -16156,16 +16160,15 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,for (i =0 ; i <RTE_COLORS ; i++) { acts[i].actions_n =0 ; -if (i ==RTE_COLOR_YELLOW ) -continue ;if (i ==RTE_COLOR_RED ) {/* Only support drop on red. */ acts[i].dv_actions[0 ] = - mtr_policy->dr_drop_action[domain]; + mtr_policy->dr_drop_action[domain]; acts[i].actions_n =1 ;continue ; } -if (mtr_policy->act_cnt[i].fate_action ==MLX5_FLOW_FATE_MTR ) { +if (i ==RTE_COLOR_GREEN && + mtr_policy->act_cnt[i].fate_action ==MLX5_FLOW_FATE_MTR ) {struct rte_flow_attr attr = { .transfer = transfer };
@@ -16199,13 +16202,12 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev, "mark action for policy."); goto err_exit; } - acts[i].dv_actions[acts[i].actions_n] = - tag->action; + acts[i].dv_actions[acts[i].actions_n] = tag->action; acts[i].actions_n++; }if (mtr_policy->act_cnt[i].modify_hdr) { acts[i].dv_actions[acts[i].actions_n] = - mtr_policy->act_cnt[i].modify_hdr->action; + mtr_policy->act_cnt[i].modify_hdr->action; acts[i].actions_n++; }if (mtr_policy->act_cnt[i].fate_action) {
@@ -16220,7 +16222,7 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev, goto err_exit; } acts[i].dv_actions[acts[i].actions_n] = - port_action->action; + port_action->action; acts[i].actions_n++; mtr_policy->dev = dev; match_src_port = true;
@@ -16234,15 +16236,15 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,case MLX5_FLOW_FATE_SHARED_RSS :case MLX5_FLOW_FATE_QUEUE : hrxq =mlx5_ipool_get - (priv->sh->ipool[MLX5_IPOOL_HRXQ ], - sub_policy->rix_hrxq[i]); + (priv->sh->ipool[MLX5_IPOOL_HRXQ ], + sub_policy->rix_hrxq[i]);if (!hrxq) {DRV_LOG (ERR ,"Failed to find " "queue action for policy." ); goto err_exit; } acts[i].dv_actions[acts[i].actions_n] = - hrxq->action; + hrxq->action; acts[i].actions_n++;break ;case MLX5_FLOW_FATE_MTR :
@@ -16284,7 +16286,7 @@ __flow_dv_create_policy_acts_rules(struct rte_eth_dev *dev,if (__flow_dv_create_domain_policy_rules (dev, sub_policy, egress, transfer, match_src_port, acts)) {DRV_LOG (ERR , -"Failed to create policy rules per domain." ); +"Failed to create policy rules per domain." ); goto err_exit; }return 0 ;
@@ -16321,8 +16323,8 @@ flow_dv_create_policy_rules(struct rte_eth_dev *dev,/* Prepare actions list and create policy rules. */ if (__flow_dv_create_policy_acts_rules (dev, mtr_policy, mtr_policy->sub_policys[i][0 ], i)) { -DRV_LOG (ERR , -"Failed to create policy action list per domain." ); +DRV_LOG (ERR ,"Failed to create policy action " +"list per domain." );return -1 ; } }
drivers/net/mlx5/mlx5_flow_meter.c +32 -18
103 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 4/7 net/mlx5: split policies handling of colors
In reply to Bing ZhaoIf the fate action is either RSS or Queue of a meter policy, the action will only be created in the flow splitting stage. With queue as the fate action, only one sub-policy is needed. And RSS will have more than one sub-policies if there is an expansion.
Since the RSS parameters are the same for both green and yellow colors except the queues, the expansion result will be unique. Even if only one color has the RSS action, the checking and possible expansion will be done then. For each sub-policy, the action rules need to be created separately on its own policy table.
--- drivers/net/mlx5/mlx5_flow.c | 40 ++++++++++---------- drivers/net/mlx5/mlx5_flow_dv.c | 67 +++++++++++++++++---------------- 2 files changed, 55 insertions(+), 52 deletions(-)
drivers/net/mlx5/mlx5_flow.c +21 -19
@@ -4687,7 +4687,7 @@ get_meter_sub_policy(struct rte_eth_dev *dev,struct mlx5_flow_rss_desc *rss_desc[MLX5_MTR_RTE_COLORS ] = {0 };uint32_t i; -/** +/* * This is a tmp dev_flow, * no need to register any matcher for it in translate. */
@@ -4695,18 +4695,19 @@ get_meter_sub_policy(struct rte_eth_dev *dev,for (i =0 ; i <MLX5_MTR_RTE_COLORS ; i++) {struct mlx5_flow dev_flow = {0 };struct mlx5_flow_handle dev_handle = { {0 } }; +uint8_t fate = final_policy->act_cnt[i].fate_action; -if (final_policy->is_rss) { +if (fate ==MLX5_FLOW_FATE_SHARED_RSS ) {const void *rss_act = final_policy->act_cnt[i].rss->conf;struct rte_flow_action rss_actions[2 ] = { [0 ] = { .type =RTE_FLOW_ACTION_TYPE_RSS , - .conf = rss_act + .conf = rss_act, }, [1 ] = { .type =RTE_FLOW_ACTION_TYPE_END , - .conf =NULL + .conf =NULL , } };
@@ -4731,9 +4732,10 @@ get_meter_sub_policy(struct rte_eth_dev *dev, rss_desc_v[i].hash_fields ? rss_desc_v[i].queue_num :1 ; rss_desc_v[i].tunnel = - !!(dev_flow.handle->layers & -MLX5_FLOW_LAYER_TUNNEL ); - }else { + !!(dev_flow.handle->layers & +MLX5_FLOW_LAYER_TUNNEL ); + rss_desc[i] = &rss_desc_v[i]; + }else if (fate ==MLX5_FLOW_FATE_QUEUE ) {/* This is queue action. */ rss_desc_v[i] = wks->rss_desc; rss_desc_v[i].key_len =0 ;
@@ -4741,24 +4743,24 @@ get_meter_sub_policy(struct rte_eth_dev *dev, rss_desc_v[i].queue = &final_policy->act_cnt[i].queue; rss_desc_v[i].queue_num =1 ; + rss_desc[i] = &rss_desc_v[i]; + }else { + rss_desc[i] =NULL ; } - rss_desc[i] = &rss_desc_v[i]; } sub_policy =flow_drv_meter_sub_policy_rss_prepare (dev, flow, policy, rss_desc); }else {enum mlx5_meter_domain mtr_domain = attr->transfer ?MLX5_MTR_DOMAIN_TRANSFER : - attr->egress ?MLX5_MTR_DOMAIN_EGRESS : -MLX5_MTR_DOMAIN_INGRESS ; + (attr->egress ?MLX5_MTR_DOMAIN_EGRESS : +MLX5_MTR_DOMAIN_INGRESS ); sub_policy = policy->sub_policys[mtr_domain][0 ]; } -if (!sub_policy) { +if (!sub_policy)rte_flow_error_set (error,EINVAL , -RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , -"Failed to get meter sub-policy." ); - goto exit; - } +RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , +"Failed to get meter sub-policy." ); exit:return sub_policy; }
@@ -4956,8 +4958,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, }else {enum mlx5_meter_domain mtr_domain = attr->transfer ?MLX5_MTR_DOMAIN_TRANSFER : - attr->egress ?MLX5_MTR_DOMAIN_EGRESS : -MLX5_MTR_DOMAIN_INGRESS ; + (attr->egress ?MLX5_MTR_DOMAIN_EGRESS : +MLX5_MTR_DOMAIN_INGRESS ); sub_policy = &priv->sh->mtrmng->def_policy[mtr_domain]->sub_policy;
@@ -4973,8 +4975,8 @@ flow_meter_split_prep(struct rte_eth_dev *dev, actions_pre++;if (!tag_action)return rte_flow_error_set (error,ENOMEM , -RTE_FLOW_ERROR_TYPE_UNSPECIFIED ,NULL , -"No tag action space." ); +RTE_FLOW_ERROR_TYPE_UNSPECIFIED , +NULL ,"No tag action space." );if (!mtr_flow_id) { tag_action->type =RTE_FLOW_ACTION_TYPE_VOID ; goto exit;
drivers/net/mlx5/mlx5_flow_dv.c +34 -33
173 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH v3 5/7 net/mlx5: support yellow in meter policy validation
In reply to Bing ZhaoIn the previous implementation, the policy for yellow color was not supported. The action validation for yellow was skipped.
Since the yellow color policy needs to be supported, the validation should also be done for the yellow color. In the meanwhile, due to the fact that color policies of one meter should be used for the same flow(s), the domains supported of both colors should be the same. If both of the colors have RSS as the termination actions, except the queues, all other parameters of RSS should be the same.
--- doc/guides/nics/mlx5.rst | 9 +- doc/guides/rel_notes/release_21_08.rst | 1 + drivers/net/mlx5/mlx5.h | 8 +- drivers/net/mlx5/mlx5_flow.c | 6 +- drivers/net/mlx5/mlx5_flow.h | 4 +- drivers/net/mlx5/mlx5_flow_dv.c | 210 ++++++++++++++++--------- drivers/net/mlx5/mlx5_flow_meter.c | 15 +- 7 files changed, 160 insertions(+), 93 deletions(-)
doc/guides/nics/mlx5.rst +4 -5
@@ -420,19 +420,18 @@ Limitations - Meter: - All the meter colors with drop action will be counted only by the global drop statistics. - - Green color is not supported with drop action. - - Yellow detection is not supported. + - Yellow detection is only supported with ASO metering. - Red color must be with drop action. - Meter statistics are supported only for drop case. - - Meter yellow color detection is not supported. - A meter action created with pre-defined policy must be the last action in the flow except single case where the policy actions are: - green: NULL or END. - yellow: NULL or END. - RED: DROP / END. - The only supported meter policy actions: - - green: QUEUE, RSS, PORT_ID, JUMP, MARK and SET_TAG. - - yellow: must be empty. + - green: QUEUE, RSS, PORT_ID, JUMP, DROP, MARK and SET_TAG. + - yellow: QUEUE, RSS, PORT_ID, JUMP, DROP, MARK and SET_TAG. - RED: must be DROP. + - Policy actions of RSS for green and yellow should have the same configuration except queues. - meter profile packet mode is supported. - Integrity:
doc/guides/rel_notes/release_21_08.rst +1 -0
@@ -91,6 +91,7 @@ New Features * Added matching on IPv4 Internet Header Length (IHL). * Added support for matching on VXLAN header last 8-bits reserved field. * Optimized multi-thread flow rule insertion rate. + * Added support for metering policy actions of yellow color. * **Added Wangxun ngbe PMD.**
drivers/net/mlx5/mlx5.h +7 -1
@@ -629,7 +629,7 @@ struct mlx5_dev_shared_port {*/ #define MLX5_DV_MAX_NUMBER_OF_ACTIONS 8 -/*ASO flow meter structures*/ +/* ASO flow meter structures */ /* Modify this value if enum rte_mtr_color changes. */ #define RTE_MTR_DROPPED RTE_COLORS/* Yellow is now supported. */
@@ -643,6 +643,12 @@ struct mlx5_dev_shared_port {#define MLX5_MTR_TABLE_ID_DROP 2/* Priority of the meter policy matcher. */ #define MLX5_MTR_POLICY_MATCHER_PRIO 0 +/* Default policy. */ +#define MLX5_MTR_POLICY_MODE_DEF 1 +/* Only green color valid. */ +#define MLX5_MTR_POLICY_MODE_OG 2 +/* Only yellow color valid. */ +#define MLX5_MTR_POLICY_MODE_OY 3enum mlx5_meter_domain {MLX5_MTR_DOMAIN_INGRESS ,
drivers/net/mlx5/mlx5_flow.c +3 -3
@@ -7199,14 +7199,14 @@ mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,struct rte_flow_attr *attr, bool *is_rss, uint8_t *domain_bitmap, - bool *is_def_policy, + uint8_t *policy_mode, struct rte_mtr_error *error) { const struct mlx5_flow_driver_ops *fops; fops =flow_get_drv_ops (MLX5_FLOW_TYPE_DV ); -return fops->validate_mtr_acts (dev, actions, attr, - is_rss, domain_bitmap, is_def_policy, error); +return fops->validate_mtr_acts (dev, actions, attr, is_rss, + domain_bitmap, policy_mode, error); }/**
drivers/net/mlx5/mlx5_flow.h +2 -2
@@ -1209,7 +1209,7 @@ typedef int (*mlx5_flow_validate_mtr_acts_t)struct rte_flow_attr *attr, bool *is_rss, uint8_t *domain_bitmap, - bool *is_def_policy, + uint8_t *policy_mode, struct rte_mtr_error *error);typedef int (*mlx5_flow_create_mtr_acts_t ) (struct rte_eth_dev *dev,
@@ -1690,7 +1690,7 @@ int mlx5_flow_validate_mtr_acts(struct rte_eth_dev *dev,struct rte_flow_attr *attr, bool *is_rss, uint8_t *domain_bitmap, - bool *is_def_policy, + uint8_t *policy_mode, struct rte_mtr_error *error);void mlx5_flow_destroy_mtr_acts (struct rte_eth_dev *dev,struct mlx5_flow_meter_policy *mtr_policy);
drivers/net/mlx5/mlx5_flow_dv.c +135 -75
389 lines not on this page · raw message
drivers/net/mlx5/mlx5_flow_meter.c +8 -7
@@ -582,7 +582,7 @@ mlx5_flow_meter_policy_validate(struct rte_eth_dev *dev,struct rte_flow_attr attr = { .transfer = priv->config.dv_esw_en ?1 :0 };bool is_rss = false; -bool is_def_policy = false; +uint8_t policy_mode;uint8_t domain_bitmap;int ret;
@@ -591,7 +591,7 @@ mlx5_flow_meter_policy_validate(struct rte_eth_dev *dev,RTE_MTR_ERROR_TYPE_METER_POLICY , NULL, "meter policy unsupported."); ret =mlx5_flow_validate_mtr_acts (dev, policy->actions, &attr, - &is_rss, &domain_bitmap, &is_def_policy, error); + &is_rss, &domain_bitmap, &policy_mode, error);if (ret)return ret;return 0 ;
@@ -674,7 +674,7 @@ mlx5_flow_meter_policy_add(struct rte_eth_dev *dev,struct mlx5_flow_meter_policy *mtr_policy =NULL ;struct mlx5_flow_meter_sub_policy *sub_policy;bool is_rss = false; -bool is_def_policy = false; +uint8_t policy_mode;uint32_t i;int ret;uint32_t policy_size =sizeof (struct mlx5_flow_meter_policy );
@@ -701,14 +701,15 @@ mlx5_flow_meter_policy_add(struct rte_eth_dev *dev,RTE_MTR_ERROR_TYPE_METER_POLICY_ID , NULL, "policy ID exists. "); ret =mlx5_flow_validate_mtr_acts (dev, policy->actions, &attr, - &is_rss, &domain_bitmap, &is_def_policy, error); + &is_rss, &domain_bitmap, + &policy_mode, error);if (ret)return ret;if (!domain_bitmap)return -rte_mtr_error_set (error,ENOTSUP , -RTE_MTR_ERROR_TYPE_METER_POLICY , -NULL ,"fail to find policy domain." ); -if (is_def_policy) { +RTE_MTR_ERROR_TYPE_METER_POLICY , +NULL ,"fail to find policy domain." ); +if (policy_mode ==MLX5_MTR_POLICY_MODE_DEF ) {if (priv->sh->mtrmng->def_policy_id !=MLX5_INVALID_POLICY_ID ) return -rte_mtr_error_set(error, EEXIST, RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
Signature · 1 line
2.27.0
PATCH v3 6/7 net/mlx5: check consistency of meter policy and profile
In reply to Bing ZhaoIn the previous implementation, only green color policy was supported in mlx5 PMD. Since yellow color policy is supported now, the consistency of meter policy and profile should be checked.
1. If the profile supports yellow but the policy doesn't, an error should be returned when creating the meter. Or else, there is no explicit steering action for the packets marked with yellow.
2. If the policy supports yellow but the profile doesn't, it will be considered as a valid case. Even if no packet will be handled with the yellow steering action, it is just like that only the green policy presents.
Usually the green color is supported by default, but when it is disabled intentionally with setting the CBS to a small value like zero in the profile, the similar checking on green policy and profile should also be done.
--- drivers/net/mlx5/mlx5.h | 6 ++++++ drivers/net/mlx5/mlx5_flow_dv.c | 4 ++++ drivers/net/mlx5/mlx5_flow_meter.c | 20 ++++++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-)
drivers/net/mlx5/mlx5.h +6 -0
@@ -746,6 +746,10 @@ struct mlx5_flow_meter_policy {/* Is queue action in policy table. */ uint32_t is_hierarchy:1;/* Is meter action in policy table. */ + uint32_t skip_y:1; +/* If yellow color policy is skipped. */ + uint32_t skip_g:1; +/* If green color policy is skipped. */ rte_spinlock_t sl;uint32_t ref_cnt;/* Use count. */
@@ -866,6 +870,8 @@ struct mlx5_flow_meter_profile {/**< srtcm_rfc2697 struct. */ };uint32_t ref_cnt;/**< Use count. */ + uint32_t g_support:1; /**< If G color will be generated. */ + uint32_t y_support:1; /**< If Y color will be generated. */ };/* 2 meters in each ASO cache line */
drivers/net/mlx5/mlx5_flow_dv.c +4 -0
@@ -15245,6 +15245,10 @@ __flow_dv_create_domain_policy_acts(struct rte_eth_dev *dev,for (i =0 ; i <RTE_COLORS ; i++) {if (i <MLX5_MTR_RTE_COLORS ) act_cnt = &mtr_policy->act_cnt[i]; +/* Skip the color policy actions creation. */ +if ((i ==RTE_COLOR_YELLOW && mtr_policy->skip_y) || + (i ==RTE_COLOR_GREEN && mtr_policy->skip_g)) +continue ; action_flags =0 ;for (act = actions[i]; act && act->type !=RTE_FLOW_ACTION_TYPE_END ; act++) {
drivers/net/mlx5/mlx5_flow_meter.c +18 -2
@@ -333,6 +333,10 @@ mlx5_flow_meter_param_fill(struct mlx5_flow_meter_profile *fmp, ebs_exp = exp; srtcm->ebs_eir =rte_cpu_to_be_32 (ebs_exp <<ASO_DSEG_EBS_EXP_OFFSET | ebs_man <<ASO_DSEG_EBS_MAN_OFFSET ); +if (srtcm->cbs_cir) + fmp->g_support =1 ; +if (srtcm->ebs_eir) + fmp->y_support =1 ;return 0 ; }
@@ -750,6 +754,10 @@ mlx5_flow_meter_policy_add(struct rte_eth_dev *dev,return -rte_mtr_error_set (error,ENOMEM ,RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL ,"Memory alloc failed for meter policy." ); +if (policy_mode ==MLX5_MTR_POLICY_MODE_OG ) + mtr_policy->skip_y =1 ; +else if (policy_mode ==MLX5_MTR_POLICY_MODE_OY ) + mtr_policy->skip_g =1 ; policy_size =sizeof (struct mlx5_flow_meter_policy );for (i =0 ; i <MLX5_MTR_DOMAIN_MAX ; i++) {if (!(domain_bitmap & (1 << i)))
@@ -1132,13 +1140,13 @@ mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id,if (!priv->config.dv_esw_en) domain_bitmap &= ~MLX5_MTR_DOMAIN_TRANSFER_BIT ; }else { - mtr_policy =mlx5_flow_meter_policy_find (dev, - params->meter_policy_id, &policy_idx);if (!priv->sh->meter_aso_en)return -rte_mtr_error_set (error,ENOTSUP ,RTE_MTR_ERROR_TYPE_UNSPECIFIED ,NULL ,"Part of the policies cannot be " "supported without ASO " ); + mtr_policy =mlx5_flow_meter_policy_find (dev, + params->meter_policy_id, &policy_idx);if (!mtr_policy) return -rte_mtr_error_set(error, ENOENT, RTE_MTR_ERROR_TYPE_METER_POLICY_ID,
@@ -1149,6 +1157,14 @@ mlx5_flow_meter_create(struct rte_eth_dev *dev, uint32_t meter_id, MLX5_MTR_DOMAIN_EGRESS_BIT : 0) | (mtr_policy->transfer ?MLX5_MTR_DOMAIN_TRANSFER_BIT :0 ); +if (fmp->g_support && mtr_policy->skip_g) +return -rte_mtr_error_set (error,ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY_ID , +NULL ,"Meter green policy is empty." ); +if (fmp->y_support && mtr_policy->skip_y) +return -rte_mtr_error_set (error,ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY_ID , +NULL ,"Meter yellow policy is empty." ); }/* Allocate the flow meter memory. */ if (priv->sh->meter_aso_en) {
Signature · 1 line
2.27.0
PATCH v3 7/7 net/mlx5: add meter support for trTCM profiles
In reply to Bing ZhaoThe support of RFC2698 and RFC4115 are added in mlx5 PMD. Only the ASO metering supports these two profiles.
--- doc/guides/nics/mlx5.rst | 1 + doc/guides/rel_notes/release_21_08.rst | 1 + drivers/common/mlx5/mlx5_prm.h | 5 +- drivers/net/mlx5/mlx5_flow_aso.c | 23 ++++- drivers/net/mlx5/mlx5_flow_meter.c | 112 ++++++++++++++++--------- 5 files changed, 98 insertions(+), 44 deletions(-)
doc/guides/nics/mlx5.rst +1 -0
@@ -433,6 +433,7 @@ Limitations - RED: must be DROP. - Policy actions of RSS for green and yellow should have the same configuration except queues. - meter profile packet mode is supported. + - meter profiles of RFC2697, RFC2698 and RFC4115 are supported. - Integrity:
doc/guides/rel_notes/release_21_08.rst +1 -0
@@ -92,6 +92,7 @@ New Features * Added support for matching on VXLAN header last 8-bits reserved field. * Optimized multi-thread flow rule insertion rate. * Added support for metering policy actions of yellow color. + * Added support for metering trTCM RFC2698 and RFC4115. * **Added Wangxun ngbe PMD.**
drivers/common/mlx5/mlx5_prm.h +3 -2
@@ -3031,11 +3031,12 @@ struct mlx5_aso_mtr_dseg {#define ASO_DSEG_VALID_OFFSET 31#define ASO_DSEG_BO_OFFSET 30#define ASO_DSEG_SC_OFFSET 28 +#define ASO_DSEG_BBOG_OFFSET 27#define ASO_DSEG_MTR_MODE 24#define ASO_DSEG_CBS_EXP_OFFSET 24#define ASO_DSEG_CBS_MAN_OFFSET 16 -#define ASO_DSEG_CIR_EXP_MASK 0x1F -#define ASO_DSEG_CIR_EXP_OFFSET 8 +#define ASO_DSEG_XIR_EXP_MASK 0x1F +#define ASO_DSEG_XIR_EXP_OFFSET 8#define ASO_DSEG_EBS_EXP_OFFSET 24#define ASO_DSEG_EBS_MAN_OFFSET 16#define ASO_DSEG_EXP_MASK 0x1F
drivers/net/mlx5/mlx5_flow_aso.c +20 -3
@@ -747,10 +747,27 @@ mlx5_aso_mtr_sq_enqueue_single(struct mlx5_aso_sq *sq, wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm =RTE_BE32 ((1 <<ASO_DSEG_VALID_OFFSET ) | (MLX5_FLOW_COLOR_GREEN <<ASO_DSEG_SC_OFFSET )); -/* Only needed for RFC2697. */ -if (fm->profile->srtcm_prm.ebs_eir) +switch (fmp->profile.alg) { +case RTE_MTR_SRTCM_RFC2697 : +/* Only needed for RFC2697. */ +if (fm->profile->srtcm_prm.ebs_eir) + wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |= +RTE_BE32 (1 <<ASO_DSEG_BO_OFFSET ); +break ; +case RTE_MTR_TRTCM_RFC2698 : wqe->aso_dseg.mtrs[dseg_idx].v_bo_sc_bbog_mm |= -RTE_BE32 (1 <<ASO_DSEG_BO_OFFSET ); +RTE_BE32 (1 <<ASO_DSEG_BBOG_OFFSET ); +break ; +case RTE_MTR_TRTCM_RFC4115 : +default : +break ; + } +/* +* Note: +* Due to software performance reason, the token fields will not be +* set when posting the WQE to ASO SQ. It will be filled by the HW +* automatically. +*/ sq->head++; sq->pi +=2 ;/* Each WQE contains 2 WQEBB's. */ rte_io_wmb ();
drivers/net/mlx5/mlx5_flow_meter.c +73 -39
196 lines not on this page · raw message
Signature · 1 line
2.27.0
Thomas Monjalon
Applied21/07/2021 10:54, Bing Zhao:
Quoted 9 lines
When creating a meter policy, the actions for yellow color can be specified together with green color. The mlx5 PMD now supports to set the policy actions for yellow color.
The actions list that is supported for yellow is the same as that for green.
Acked-by Matan Azrad <[email protected]>
Quoted 8 lines
Bing Zhao (7):
net/mlx5: handle yellow case in default meter policy net/mlx5: enable meter bucket overflow for yellow color net/mlx5: added support for yellow policy rules net/mlx5: split policies handling of colors net/mlx5: support yellow in meter policy validation net/mlx5: check consistency of meter policy and profile net/mlx5: add meter support for trTCM profiles
Applied, thanks