@@ -344,6 +344,7 @@ static void del_rule(struct fs_node *node)
344344 struct mlx5_flow_group * fg ;
345345 struct fs_fte * fte ;
346346 u32 * match_value ;
347+ int modify_mask ;
347348 struct mlx5_core_dev * dev = get_dev (node );
348349 int match_len = MLX5_ST_SZ_BYTES (fte_match_param );
349350 int err ;
@@ -367,8 +368,11 @@ static void del_rule(struct fs_node *node)
367368 }
368369 if ((fte -> action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST ) &&
369370 -- fte -> dests_size ) {
371+ modify_mask = BIT (MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST ),
370372 err = mlx5_cmd_update_fte (dev , ft ,
371- fg -> id , fte );
373+ fg -> id ,
374+ modify_mask ,
375+ fte );
372376 if (err )
373377 pr_warn ("%s can't del rule fg id=%d fte_index=%d\n" ,
374378 __func__ , fg -> id , fte -> index );
@@ -615,6 +619,7 @@ int mlx5_modify_rule_destination(struct mlx5_flow_rule *rule,
615619 struct mlx5_flow_table * ft ;
616620 struct mlx5_flow_group * fg ;
617621 struct fs_fte * fte ;
622+ int modify_mask = BIT (MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST );
618623 int err = 0 ;
619624
620625 fs_get_obj (fte , rule -> node .parent );
@@ -626,7 +631,9 @@ int mlx5_modify_rule_destination(struct mlx5_flow_rule *rule,
626631
627632 memcpy (& rule -> dest_attr , dest , sizeof (* dest ));
628633 err = mlx5_cmd_update_fte (get_dev (& ft -> node ),
629- ft , fg -> id , fte );
634+ ft , fg -> id ,
635+ modify_mask ,
636+ fte );
630637 unlock_ref_node (& fte -> node );
631638
632639 return err ;
@@ -877,6 +884,7 @@ static struct mlx5_flow_rule *add_rule_fte(struct fs_fte *fte,
877884{
878885 struct mlx5_flow_table * ft ;
879886 struct mlx5_flow_rule * rule ;
887+ int modify_mask = 0 ;
880888 int err ;
881889
882890 rule = alloc_rule (dest );
@@ -892,14 +900,20 @@ static struct mlx5_flow_rule *add_rule_fte(struct fs_fte *fte,
892900 list_add (& rule -> node .list , & fte -> node .children );
893901 else
894902 list_add_tail (& rule -> node .list , & fte -> node .children );
895- if (dest )
903+ if (dest ) {
896904 fte -> dests_size ++ ;
905+
906+ modify_mask |= dest -> type == MLX5_FLOW_DESTINATION_TYPE_COUNTER ?
907+ BIT (MLX5_SET_FTE_MODIFY_ENABLE_MASK_FLOW_COUNTERS ) :
908+ BIT (MLX5_SET_FTE_MODIFY_ENABLE_MASK_DESTINATION_LIST );
909+ }
910+
897911 if (fte -> dests_size == 1 || !dest )
898912 err = mlx5_cmd_create_fte (get_dev (& ft -> node ),
899913 ft , fg -> id , fte );
900914 else
901915 err = mlx5_cmd_update_fte (get_dev (& ft -> node ),
902- ft , fg -> id , fte );
916+ ft , fg -> id , modify_mask , fte );
903917 if (err )
904918 goto free_rule ;
905919
@@ -1092,10 +1106,40 @@ static struct mlx5_flow_rule *add_rule_fg(struct mlx5_flow_group *fg,
10921106 return rule ;
10931107}
10941108
1109+ struct mlx5_fc * mlx5_flow_rule_counter (struct mlx5_flow_rule * rule )
1110+ {
1111+ struct mlx5_flow_rule * dst ;
1112+ struct fs_fte * fte ;
1113+
1114+ fs_get_obj (fte , rule -> node .parent );
1115+
1116+ fs_for_each_dst (dst , fte ) {
1117+ if (dst -> dest_attr .type == MLX5_FLOW_DESTINATION_TYPE_COUNTER )
1118+ return dst -> dest_attr .counter ;
1119+ }
1120+
1121+ return NULL ;
1122+ }
1123+
1124+ static bool counter_is_valid (struct mlx5_fc * counter , u32 action )
1125+ {
1126+ if (!(action & MLX5_FLOW_CONTEXT_ACTION_COUNT ))
1127+ return !counter ;
1128+
1129+ if (!counter )
1130+ return false;
1131+
1132+ /* Hardware support counter for a drop action only */
1133+ return action == (MLX5_FLOW_CONTEXT_ACTION_DROP | MLX5_FLOW_CONTEXT_ACTION_COUNT );
1134+ }
1135+
10951136static bool dest_is_valid (struct mlx5_flow_destination * dest ,
10961137 u32 action ,
10971138 struct mlx5_flow_table * ft )
10981139{
1140+ if (dest && (dest -> type == MLX5_FLOW_DESTINATION_TYPE_COUNTER ))
1141+ return counter_is_valid (dest -> counter , action );
1142+
10991143 if (!(action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST ))
11001144 return true;
11011145
0 commit comments