@@ -876,11 +876,12 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
876876 struct mlx5_accel_esp_xfrm_attrs * attrs = & sa_entry -> attrs ;
877877 struct mlx5_core_dev * mdev = mlx5e_ipsec_sa2dev (sa_entry );
878878 struct mlx5e_ipsec * ipsec = sa_entry -> ipsec ;
879- struct mlx5_flow_destination dest = {} ;
879+ struct mlx5_flow_destination dest [ 2 ] ;
880880 struct mlx5_flow_act flow_act = {};
881881 struct mlx5_flow_handle * rule ;
882882 struct mlx5_flow_spec * spec ;
883883 struct mlx5e_ipsec_rx * rx ;
884+ struct mlx5_fc * counter ;
884885 int err ;
885886
886887 rx = rx_ft_get (mdev , ipsec , attrs -> family );
@@ -917,14 +918,22 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
917918 break ;
918919 }
919920
921+ counter = mlx5_fc_create (mdev , true);
922+ if (IS_ERR (counter )) {
923+ err = PTR_ERR (counter );
924+ goto err_add_cnt ;
925+ }
920926 flow_act .crypto .type = MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_IPSEC ;
921927 flow_act .crypto .obj_id = sa_entry -> ipsec_obj_id ;
922928 flow_act .flags |= FLOW_ACT_NO_APPEND ;
923929 flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
924- MLX5_FLOW_CONTEXT_ACTION_CRYPTO_DECRYPT ;
925- dest .type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
926- dest .ft = rx -> ft .status ;
927- rule = mlx5_add_flow_rules (rx -> ft .sa , spec , & flow_act , & dest , 1 );
930+ MLX5_FLOW_CONTEXT_ACTION_CRYPTO_DECRYPT |
931+ MLX5_FLOW_CONTEXT_ACTION_COUNT ;
932+ dest [0 ].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
933+ dest [0 ].ft = rx -> ft .status ;
934+ dest [1 ].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER ;
935+ dest [1 ].counter_id = mlx5_fc_id (counter );
936+ rule = mlx5_add_flow_rules (rx -> ft .sa , spec , & flow_act , dest , 2 );
928937 if (IS_ERR (rule )) {
929938 err = PTR_ERR (rule );
930939 mlx5_core_err (mdev , "fail to add RX ipsec rule err=%d\n" , err );
@@ -934,10 +943,13 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
934943
935944 sa_entry -> ipsec_rule .rule = rule ;
936945 sa_entry -> ipsec_rule .modify_hdr = flow_act .modify_hdr ;
946+ sa_entry -> ipsec_rule .fc = counter ;
937947 sa_entry -> ipsec_rule .pkt_reformat = flow_act .pkt_reformat ;
938948 return 0 ;
939949
940950err_add_flow :
951+ mlx5_fc_destroy (mdev , counter );
952+ err_add_cnt :
941953 if (flow_act .pkt_reformat )
942954 mlx5_packet_reformat_dealloc (mdev , flow_act .pkt_reformat );
943955err_pkt_reformat :
@@ -954,11 +966,12 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
954966 struct mlx5_accel_esp_xfrm_attrs * attrs = & sa_entry -> attrs ;
955967 struct mlx5_core_dev * mdev = mlx5e_ipsec_sa2dev (sa_entry );
956968 struct mlx5e_ipsec * ipsec = sa_entry -> ipsec ;
957- struct mlx5_flow_destination dest = {} ;
969+ struct mlx5_flow_destination dest [ 2 ] ;
958970 struct mlx5_flow_act flow_act = {};
959971 struct mlx5_flow_handle * rule ;
960972 struct mlx5_flow_spec * spec ;
961973 struct mlx5e_ipsec_tx * tx ;
974+ struct mlx5_fc * counter ;
962975 int err ;
963976
964977 tx = tx_ft_get (mdev , ipsec );
@@ -996,15 +1009,23 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
9961009 break ;
9971010 }
9981011
1012+ counter = mlx5_fc_create (mdev , true);
1013+ if (IS_ERR (counter )) {
1014+ err = PTR_ERR (counter );
1015+ goto err_add_cnt ;
1016+ }
1017+
9991018 flow_act .crypto .type = MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_IPSEC ;
10001019 flow_act .crypto .obj_id = sa_entry -> ipsec_obj_id ;
10011020 flow_act .flags |= FLOW_ACT_NO_APPEND ;
10021021 flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
10031022 MLX5_FLOW_CONTEXT_ACTION_CRYPTO_ENCRYPT |
10041023 MLX5_FLOW_CONTEXT_ACTION_COUNT ;
1005- dest .ft = tx -> ft .status ;
1006- dest .type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
1007- rule = mlx5_add_flow_rules (tx -> ft .sa , spec , & flow_act , & dest , 1 );
1024+ dest [0 ].ft = tx -> ft .status ;
1025+ dest [0 ].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
1026+ dest [1 ].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER ;
1027+ dest [1 ].counter_id = mlx5_fc_id (counter );
1028+ rule = mlx5_add_flow_rules (tx -> ft .sa , spec , & flow_act , dest , 2 );
10081029 if (IS_ERR (rule )) {
10091030 err = PTR_ERR (rule );
10101031 mlx5_core_err (mdev , "fail to add TX ipsec rule err=%d\n" , err );
@@ -1013,10 +1034,13 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
10131034
10141035 kvfree (spec );
10151036 sa_entry -> ipsec_rule .rule = rule ;
1037+ sa_entry -> ipsec_rule .fc = counter ;
10161038 sa_entry -> ipsec_rule .pkt_reformat = flow_act .pkt_reformat ;
10171039 return 0 ;
10181040
10191041err_add_flow :
1042+ mlx5_fc_destroy (mdev , counter );
1043+ err_add_cnt :
10201044 if (flow_act .pkt_reformat )
10211045 mlx5_packet_reformat_dealloc (mdev , flow_act .pkt_reformat );
10221046err_pkt_reformat :
@@ -1299,7 +1323,7 @@ void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
12991323 struct mlx5_core_dev * mdev = mlx5e_ipsec_sa2dev (sa_entry );
13001324
13011325 mlx5_del_flow_rules (ipsec_rule -> rule );
1302-
1326+ mlx5_fc_destroy ( mdev , ipsec_rule -> fc );
13031327 if (ipsec_rule -> pkt_reformat )
13041328 mlx5_packet_reformat_dealloc (mdev , ipsec_rule -> pkt_reformat );
13051329
0 commit comments