9
9
10
10
#define NUM_IPSEC_FTE BIT(15)
11
11
12
+ struct mlx5e_ipsec_fc {
13
+ struct mlx5_fc * cnt ;
14
+ struct mlx5_fc * drop ;
15
+ };
16
+
12
17
struct mlx5e_ipsec_ft {
13
18
struct mutex mutex ; /* Protect changes to this struct */
14
19
struct mlx5_flow_table * pol ;
@@ -27,12 +32,14 @@ struct mlx5e_ipsec_rx {
27
32
struct mlx5e_ipsec_miss pol ;
28
33
struct mlx5e_ipsec_miss sa ;
29
34
struct mlx5e_ipsec_rule status ;
35
+ struct mlx5e_ipsec_fc * fc ;
30
36
};
31
37
32
38
struct mlx5e_ipsec_tx {
33
39
struct mlx5e_ipsec_ft ft ;
34
40
struct mlx5e_ipsec_miss pol ;
35
41
struct mlx5_flow_namespace * ns ;
42
+ struct mlx5e_ipsec_fc * fc ;
36
43
};
37
44
38
45
/* IPsec RX flow steering */
@@ -93,9 +100,10 @@ static int ipsec_status_rule(struct mlx5_core_dev *mdev,
93
100
94
101
/* create fte */
95
102
flow_act .action = MLX5_FLOW_CONTEXT_ACTION_MOD_HDR |
96
- MLX5_FLOW_CONTEXT_ACTION_FWD_DEST ;
103
+ MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
104
+ MLX5_FLOW_CONTEXT_ACTION_COUNT ;
97
105
flow_act .modify_hdr = modify_hdr ;
98
- fte = mlx5_add_flow_rules (rx -> ft .status , spec , & flow_act , dest , 1 );
106
+ fte = mlx5_add_flow_rules (rx -> ft .status , spec , & flow_act , dest , 2 );
99
107
if (IS_ERR (fte )) {
100
108
err = PTR_ERR (fte );
101
109
mlx5_core_err (mdev , "fail to add ipsec rx err copy rule err=%d\n" , err );
@@ -178,7 +186,7 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
178
186
{
179
187
struct mlx5_flow_namespace * ns = mlx5e_fs_get_ns (ipsec -> fs , false);
180
188
struct mlx5_ttc_table * ttc = mlx5e_fs_get_ttc (ipsec -> fs , false);
181
- struct mlx5_flow_destination dest ;
189
+ struct mlx5_flow_destination dest [ 2 ] ;
182
190
struct mlx5_flow_table * ft ;
183
191
int err ;
184
192
@@ -189,8 +197,10 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
189
197
190
198
rx -> ft .status = ft ;
191
199
192
- dest = mlx5_ttc_get_default_dest (ttc , family2tt (family ));
193
- err = ipsec_status_rule (mdev , rx , & dest );
200
+ dest [0 ] = mlx5_ttc_get_default_dest (ttc , family2tt (family ));
201
+ dest [1 ].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER ;
202
+ dest [1 ].counter_id = mlx5_fc_id (rx -> fc -> cnt );
203
+ err = ipsec_status_rule (mdev , rx , dest );
194
204
if (err )
195
205
goto err_add ;
196
206
@@ -203,7 +213,7 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
203
213
}
204
214
rx -> ft .sa = ft ;
205
215
206
- err = ipsec_miss_create (mdev , rx -> ft .sa , & rx -> sa , & dest );
216
+ err = ipsec_miss_create (mdev , rx -> ft .sa , & rx -> sa , dest );
207
217
if (err )
208
218
goto err_fs ;
209
219
@@ -214,10 +224,10 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
214
224
goto err_pol_ft ;
215
225
}
216
226
rx -> ft .pol = ft ;
217
- memset (& dest , 0x00 , sizeof (dest ));
218
- dest .type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
219
- dest .ft = rx -> ft .sa ;
220
- err = ipsec_miss_create (mdev , rx -> ft .pol , & rx -> pol , & dest );
227
+ memset (dest , 0x00 , 2 * sizeof (* dest ));
228
+ dest [ 0 ] .type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
229
+ dest [ 0 ] .ft = rx -> ft .sa ;
230
+ err = ipsec_miss_create (mdev , rx -> ft .pol , & rx -> pol , dest );
221
231
if (err )
222
232
goto err_pol_miss ;
223
233
@@ -605,6 +615,7 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
605
615
struct mlx5_accel_esp_xfrm_attrs * attrs = & sa_entry -> attrs ;
606
616
struct mlx5_core_dev * mdev = mlx5e_ipsec_sa2dev (sa_entry );
607
617
struct mlx5e_ipsec * ipsec = sa_entry -> ipsec ;
618
+ struct mlx5_flow_destination dest = {};
608
619
struct mlx5_flow_act flow_act = {};
609
620
struct mlx5_flow_handle * rule ;
610
621
struct mlx5_flow_spec * spec ;
@@ -647,8 +658,11 @@ static int tx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
647
658
flow_act .crypto .obj_id = sa_entry -> ipsec_obj_id ;
648
659
flow_act .flags |= FLOW_ACT_NO_APPEND ;
649
660
flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_ALLOW |
650
- MLX5_FLOW_CONTEXT_ACTION_CRYPTO_ENCRYPT ;
651
- rule = mlx5_add_flow_rules (tx -> ft .sa , spec , & flow_act , NULL , 0 );
661
+ MLX5_FLOW_CONTEXT_ACTION_CRYPTO_ENCRYPT |
662
+ MLX5_FLOW_CONTEXT_ACTION_COUNT ;
663
+ dest .type = MLX5_FLOW_DESTINATION_TYPE_COUNTER ;
664
+ dest .counter_id = mlx5_fc_id (tx -> fc -> cnt );
665
+ rule = mlx5_add_flow_rules (tx -> ft .sa , spec , & flow_act , & dest , 1 );
652
666
if (IS_ERR (rule )) {
653
667
err = PTR_ERR (rule );
654
668
mlx5_core_err (mdev , "fail to add TX ipsec rule err=%d\n" , err );
@@ -674,12 +688,12 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
674
688
{
675
689
struct mlx5_accel_pol_xfrm_attrs * attrs = & pol_entry -> attrs ;
676
690
struct mlx5_core_dev * mdev = mlx5e_ipsec_pol2dev (pol_entry );
677
- struct mlx5_flow_destination dest = {};
691
+ struct mlx5_flow_destination dest [ 2 ] = {};
678
692
struct mlx5_flow_act flow_act = {};
679
693
struct mlx5_flow_handle * rule ;
680
694
struct mlx5_flow_spec * spec ;
681
695
struct mlx5e_ipsec_tx * tx ;
682
- int err ;
696
+ int err , dstn = 0 ;
683
697
684
698
tx = tx_ft_get (mdev , pol_entry -> ipsec );
685
699
if (IS_ERR (tx ))
@@ -703,7 +717,11 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
703
717
flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST ;
704
718
break ;
705
719
case XFRM_POLICY_BLOCK :
706
- flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_DROP ;
720
+ flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_DROP |
721
+ MLX5_FLOW_CONTEXT_ACTION_COUNT ;
722
+ dest [dstn ].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER ;
723
+ dest [dstn ].counter_id = mlx5_fc_id (tx -> fc -> drop );
724
+ dstn ++ ;
707
725
break ;
708
726
default :
709
727
WARN_ON (true);
@@ -712,9 +730,10 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
712
730
}
713
731
714
732
flow_act .flags |= FLOW_ACT_NO_APPEND ;
715
- dest .ft = tx -> ft .sa ;
716
- dest .type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
717
- rule = mlx5_add_flow_rules (tx -> ft .pol , spec , & flow_act , & dest , 1 );
733
+ dest [dstn ].ft = tx -> ft .sa ;
734
+ dest [dstn ].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
735
+ dstn ++ ;
736
+ rule = mlx5_add_flow_rules (tx -> ft .pol , spec , & flow_act , dest , dstn );
718
737
if (IS_ERR (rule )) {
719
738
err = PTR_ERR (rule );
720
739
mlx5_core_err (mdev , "fail to add TX ipsec rule err=%d\n" , err );
@@ -736,12 +755,12 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
736
755
{
737
756
struct mlx5_accel_pol_xfrm_attrs * attrs = & pol_entry -> attrs ;
738
757
struct mlx5_core_dev * mdev = mlx5e_ipsec_pol2dev (pol_entry );
739
- struct mlx5_flow_destination dest = {} ;
758
+ struct mlx5_flow_destination dest [ 2 ] ;
740
759
struct mlx5_flow_act flow_act = {};
741
760
struct mlx5_flow_handle * rule ;
742
761
struct mlx5_flow_spec * spec ;
743
762
struct mlx5e_ipsec_rx * rx ;
744
- int err ;
763
+ int err , dstn = 0 ;
745
764
746
765
rx = rx_ft_get (mdev , pol_entry -> ipsec , attrs -> family );
747
766
if (IS_ERR (rx ))
@@ -765,7 +784,10 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
765
784
flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST ;
766
785
break ;
767
786
case XFRM_POLICY_BLOCK :
768
- flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_DROP ;
787
+ flow_act .action |= MLX5_FLOW_CONTEXT_ACTION_DROP | MLX5_FLOW_CONTEXT_ACTION_COUNT ;
788
+ dest [dstn ].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER ;
789
+ dest [dstn ].counter_id = mlx5_fc_id (rx -> fc -> drop );
790
+ dstn ++ ;
769
791
break ;
770
792
default :
771
793
WARN_ON (true);
@@ -774,9 +796,10 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
774
796
}
775
797
776
798
flow_act .flags |= FLOW_ACT_NO_APPEND ;
777
- dest .type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
778
- dest .ft = rx -> ft .sa ;
779
- rule = mlx5_add_flow_rules (rx -> ft .pol , spec , & flow_act , & dest , 1 );
799
+ dest [dstn ].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
800
+ dest [dstn ].ft = rx -> ft .sa ;
801
+ dstn ++ ;
802
+ rule = mlx5_add_flow_rules (rx -> ft .pol , spec , & flow_act , dest , dstn );
780
803
if (IS_ERR (rule )) {
781
804
err = PTR_ERR (rule );
782
805
mlx5_core_err (mdev , "Fail to add RX IPsec policy rule err=%d\n" , err );
@@ -794,6 +817,116 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
794
817
return err ;
795
818
}
796
819
820
+ static void ipsec_fs_destroy_counters (struct mlx5e_ipsec * ipsec )
821
+ {
822
+ struct mlx5e_ipsec_rx * rx_ipv4 = ipsec -> rx_ipv4 ;
823
+ struct mlx5_core_dev * mdev = ipsec -> mdev ;
824
+ struct mlx5e_ipsec_tx * tx = ipsec -> tx ;
825
+
826
+ mlx5_fc_destroy (mdev , tx -> fc -> drop );
827
+ mlx5_fc_destroy (mdev , tx -> fc -> cnt );
828
+ kfree (tx -> fc );
829
+ mlx5_fc_destroy (mdev , rx_ipv4 -> fc -> drop );
830
+ mlx5_fc_destroy (mdev , rx_ipv4 -> fc -> cnt );
831
+ kfree (rx_ipv4 -> fc );
832
+ }
833
+
834
+ static int ipsec_fs_init_counters (struct mlx5e_ipsec * ipsec )
835
+ {
836
+ struct mlx5e_ipsec_rx * rx_ipv4 = ipsec -> rx_ipv4 ;
837
+ struct mlx5e_ipsec_rx * rx_ipv6 = ipsec -> rx_ipv6 ;
838
+ struct mlx5_core_dev * mdev = ipsec -> mdev ;
839
+ struct mlx5e_ipsec_tx * tx = ipsec -> tx ;
840
+ struct mlx5e_ipsec_fc * fc ;
841
+ struct mlx5_fc * counter ;
842
+ int err ;
843
+
844
+ fc = kzalloc (sizeof (* rx_ipv4 -> fc ), GFP_KERNEL );
845
+ if (!fc )
846
+ return - ENOMEM ;
847
+
848
+ /* Both IPv4 and IPv6 point to same flow counters struct. */
849
+ rx_ipv4 -> fc = fc ;
850
+ rx_ipv6 -> fc = fc ;
851
+ counter = mlx5_fc_create (mdev , false);
852
+ if (IS_ERR (counter )) {
853
+ err = PTR_ERR (counter );
854
+ goto err_rx_cnt ;
855
+ }
856
+
857
+ fc -> cnt = counter ;
858
+ counter = mlx5_fc_create (mdev , false);
859
+ if (IS_ERR (counter )) {
860
+ err = PTR_ERR (counter );
861
+ goto err_rx_drop ;
862
+ }
863
+
864
+ fc -> drop = counter ;
865
+ fc = kzalloc (sizeof (* tx -> fc ), GFP_KERNEL );
866
+ if (!fc ) {
867
+ err = - ENOMEM ;
868
+ goto err_tx_fc ;
869
+ }
870
+
871
+ tx -> fc = fc ;
872
+ counter = mlx5_fc_create (mdev , false);
873
+ if (IS_ERR (counter )) {
874
+ err = PTR_ERR (counter );
875
+ goto err_tx_cnt ;
876
+ }
877
+
878
+ fc -> cnt = counter ;
879
+ counter = mlx5_fc_create (mdev , false);
880
+ if (IS_ERR (counter )) {
881
+ err = PTR_ERR (counter );
882
+ goto err_tx_drop ;
883
+ }
884
+
885
+ fc -> drop = counter ;
886
+ return 0 ;
887
+
888
+ err_tx_drop :
889
+ mlx5_fc_destroy (mdev , tx -> fc -> cnt );
890
+ err_tx_cnt :
891
+ kfree (tx -> fc );
892
+ err_tx_fc :
893
+ mlx5_fc_destroy (mdev , rx_ipv4 -> fc -> drop );
894
+ err_rx_drop :
895
+ mlx5_fc_destroy (mdev , rx_ipv4 -> fc -> cnt );
896
+ err_rx_cnt :
897
+ kfree (rx_ipv4 -> fc );
898
+ return err ;
899
+ }
900
+
901
+ void mlx5e_accel_ipsec_fs_read_stats (struct mlx5e_priv * priv , void * ipsec_stats )
902
+ {
903
+ struct mlx5_core_dev * mdev = priv -> mdev ;
904
+ struct mlx5e_ipsec * ipsec = priv -> ipsec ;
905
+ struct mlx5e_ipsec_hw_stats * stats ;
906
+ struct mlx5e_ipsec_fc * fc ;
907
+
908
+ stats = (struct mlx5e_ipsec_hw_stats * )ipsec_stats ;
909
+
910
+ stats -> ipsec_rx_pkts = 0 ;
911
+ stats -> ipsec_rx_bytes = 0 ;
912
+ stats -> ipsec_rx_drop_pkts = 0 ;
913
+ stats -> ipsec_rx_drop_bytes = 0 ;
914
+ stats -> ipsec_tx_pkts = 0 ;
915
+ stats -> ipsec_tx_bytes = 0 ;
916
+ stats -> ipsec_tx_drop_pkts = 0 ;
917
+ stats -> ipsec_tx_drop_bytes = 0 ;
918
+
919
+ fc = ipsec -> rx_ipv4 -> fc ;
920
+ mlx5_fc_query (mdev , fc -> cnt , & stats -> ipsec_rx_pkts , & stats -> ipsec_rx_bytes );
921
+ mlx5_fc_query (mdev , fc -> drop , & stats -> ipsec_rx_drop_pkts ,
922
+ & stats -> ipsec_rx_drop_bytes );
923
+
924
+ fc = ipsec -> tx -> fc ;
925
+ mlx5_fc_query (mdev , fc -> cnt , & stats -> ipsec_tx_pkts , & stats -> ipsec_tx_bytes );
926
+ mlx5_fc_query (mdev , fc -> drop , & stats -> ipsec_tx_drop_pkts ,
927
+ & stats -> ipsec_tx_drop_bytes );
928
+ }
929
+
797
930
int mlx5e_accel_ipsec_fs_add_rule (struct mlx5e_ipsec_sa_entry * sa_entry )
798
931
{
799
932
if (sa_entry -> attrs .dir == XFRM_DEV_OFFLOAD_OUT )
@@ -848,6 +981,7 @@ void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec)
848
981
if (!ipsec -> tx )
849
982
return ;
850
983
984
+ ipsec_fs_destroy_counters (ipsec );
851
985
mutex_destroy (& ipsec -> tx -> ft .mutex );
852
986
WARN_ON (ipsec -> tx -> ft .refcnt );
853
987
kfree (ipsec -> tx );
@@ -883,13 +1017,19 @@ int mlx5e_accel_ipsec_fs_init(struct mlx5e_ipsec *ipsec)
883
1017
if (!ipsec -> rx_ipv6 )
884
1018
goto err_rx_ipv6 ;
885
1019
1020
+ err = ipsec_fs_init_counters (ipsec );
1021
+ if (err )
1022
+ goto err_counters ;
1023
+
886
1024
mutex_init (& ipsec -> tx -> ft .mutex );
887
1025
mutex_init (& ipsec -> rx_ipv4 -> ft .mutex );
888
1026
mutex_init (& ipsec -> rx_ipv6 -> ft .mutex );
889
1027
ipsec -> tx -> ns = ns ;
890
1028
891
1029
return 0 ;
892
1030
1031
+ err_counters :
1032
+ kfree (ipsec -> rx_ipv6 );
893
1033
err_rx_ipv6 :
894
1034
kfree (ipsec -> rx_ipv4 );
895
1035
err_rx_ipv4 :
0 commit comments