forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c
....@@ -35,6 +35,7 @@
3535 #include <linux/ipv6.h>
3636 #include <linux/tcp.h>
3737 #include <linux/mlx5/fs.h>
38
+#include <linux/mlx5/mpfs.h>
3839 #include "en.h"
3940 #include "lib/mpfs.h"
4041
....@@ -678,9 +679,9 @@
678679 int i;
679680
680681 for (i = 0; i < MLX5E_NUM_TT; i++) {
681
- if (!IS_ERR_OR_NULL(ttc->rules[i])) {
682
- mlx5_del_flow_rules(ttc->rules[i]);
683
- ttc->rules[i] = NULL;
682
+ if (!IS_ERR_OR_NULL(ttc->rules[i].rule)) {
683
+ mlx5_del_flow_rules(ttc->rules[i].rule);
684
+ ttc->rules[i].rule = NULL;
684685 }
685686 }
686687
....@@ -753,7 +754,54 @@
753754 .etype = ETH_P_IPV6,
754755 .proto = IPPROTO_GRE,
755756 },
757
+ [MLX5E_TT_IPV4_IPIP] = {
758
+ .etype = ETH_P_IP,
759
+ .proto = IPPROTO_IPIP,
760
+ },
761
+ [MLX5E_TT_IPV6_IPIP] = {
762
+ .etype = ETH_P_IPV6,
763
+ .proto = IPPROTO_IPIP,
764
+ },
765
+ [MLX5E_TT_IPV4_IPV6] = {
766
+ .etype = ETH_P_IP,
767
+ .proto = IPPROTO_IPV6,
768
+ },
769
+ [MLX5E_TT_IPV6_IPV6] = {
770
+ .etype = ETH_P_IPV6,
771
+ .proto = IPPROTO_IPV6,
772
+ },
773
+
756774 };
775
+
776
+bool mlx5e_tunnel_proto_supported(struct mlx5_core_dev *mdev, u8 proto_type)
777
+{
778
+ switch (proto_type) {
779
+ case IPPROTO_GRE:
780
+ return MLX5_CAP_ETH(mdev, tunnel_stateless_gre);
781
+ case IPPROTO_IPIP:
782
+ case IPPROTO_IPV6:
783
+ return MLX5_CAP_ETH(mdev, tunnel_stateless_ip_over_ip);
784
+ default:
785
+ return false;
786
+ }
787
+}
788
+
789
+bool mlx5e_any_tunnel_proto_supported(struct mlx5_core_dev *mdev)
790
+{
791
+ int tt;
792
+
793
+ for (tt = 0; tt < MLX5E_NUM_TUNNEL_TT; tt++) {
794
+ if (mlx5e_tunnel_proto_supported(mdev, ttc_tunnel_rules[tt].proto))
795
+ return true;
796
+ }
797
+ return false;
798
+}
799
+
800
+bool mlx5e_tunnel_inner_ft_supported(struct mlx5_core_dev *mdev)
801
+{
802
+ return (mlx5e_any_tunnel_proto_supported(mdev) &&
803
+ MLX5_CAP_FLOWTABLE_NIC_RX(mdev, ft_field_support.inner_ip_version));
804
+}
757805
758806 static u8 mlx5e_etype_to_ipv(u16 ethertype)
759807 {
....@@ -816,7 +864,8 @@
816864 struct mlx5e_ttc_table *ttc)
817865 {
818866 struct mlx5_flow_destination dest = {};
819
- struct mlx5_flow_handle **rules;
867
+ struct mlx5_flow_handle **trules;
868
+ struct mlx5e_ttc_rule *rules;
820869 struct mlx5_flow_table *ft;
821870 int tt;
822871 int err;
....@@ -826,55 +875,50 @@
826875
827876 dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
828877 for (tt = 0; tt < MLX5E_NUM_TT; tt++) {
878
+ struct mlx5e_ttc_rule *rule = &rules[tt];
879
+
829880 if (tt == MLX5E_TT_ANY)
830881 dest.tir_num = params->any_tt_tirn;
831882 else
832883 dest.tir_num = params->indir_tirn[tt];
833
- rules[tt] = mlx5e_generate_ttc_rule(priv, ft, &dest,
834
- ttc_rules[tt].etype,
835
- ttc_rules[tt].proto);
836
- if (IS_ERR(rules[tt]))
884
+
885
+ rule->rule = mlx5e_generate_ttc_rule(priv, ft, &dest,
886
+ ttc_rules[tt].etype,
887
+ ttc_rules[tt].proto);
888
+ if (IS_ERR(rule->rule)) {
889
+ err = PTR_ERR(rule->rule);
890
+ rule->rule = NULL;
837891 goto del_rules;
892
+ }
893
+ rule->default_dest = dest;
838894 }
839895
840896 if (!params->inner_ttc || !mlx5e_tunnel_inner_ft_supported(priv->mdev))
841897 return 0;
842898
843
- rules = ttc->tunnel_rules;
899
+ trules = ttc->tunnel_rules;
844900 dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
845901 dest.ft = params->inner_ttc->ft.t;
846902 for (tt = 0; tt < MLX5E_NUM_TUNNEL_TT; tt++) {
847
- rules[tt] = mlx5e_generate_ttc_rule(priv, ft, &dest,
848
- ttc_tunnel_rules[tt].etype,
849
- ttc_tunnel_rules[tt].proto);
850
- if (IS_ERR(rules[tt]))
903
+ if (!mlx5e_tunnel_proto_supported(priv->mdev,
904
+ ttc_tunnel_rules[tt].proto))
905
+ continue;
906
+ trules[tt] = mlx5e_generate_ttc_rule(priv, ft, &dest,
907
+ ttc_tunnel_rules[tt].etype,
908
+ ttc_tunnel_rules[tt].proto);
909
+ if (IS_ERR(trules[tt])) {
910
+ err = PTR_ERR(trules[tt]);
911
+ trules[tt] = NULL;
851912 goto del_rules;
913
+ }
852914 }
853915
854916 return 0;
855917
856918 del_rules:
857
- err = PTR_ERR(rules[tt]);
858
- rules[tt] = NULL;
859919 mlx5e_cleanup_ttc_rules(ttc);
860920 return err;
861921 }
862
-
863
-#define MLX5E_TTC_NUM_GROUPS 3
864
-#define MLX5E_TTC_GROUP1_SIZE (BIT(3) + MLX5E_NUM_TUNNEL_TT)
865
-#define MLX5E_TTC_GROUP2_SIZE BIT(1)
866
-#define MLX5E_TTC_GROUP3_SIZE BIT(0)
867
-#define MLX5E_TTC_TABLE_SIZE (MLX5E_TTC_GROUP1_SIZE +\
868
- MLX5E_TTC_GROUP2_SIZE +\
869
- MLX5E_TTC_GROUP3_SIZE)
870
-
871
-#define MLX5E_INNER_TTC_NUM_GROUPS 3
872
-#define MLX5E_INNER_TTC_GROUP1_SIZE BIT(3)
873
-#define MLX5E_INNER_TTC_GROUP2_SIZE BIT(1)
874
-#define MLX5E_INNER_TTC_GROUP3_SIZE BIT(0)
875
-#define MLX5E_INNER_TTC_TABLE_SIZE (MLX5E_INNER_TTC_GROUP1_SIZE +\
876
- MLX5E_INNER_TTC_GROUP2_SIZE +\
877
- MLX5E_INNER_TTC_GROUP3_SIZE)
878922
879923 static int mlx5e_create_ttc_table_groups(struct mlx5e_ttc_table *ttc,
880924 bool use_ipv)
....@@ -988,33 +1032,38 @@
9881032 struct mlx5e_ttc_table *ttc)
9891033 {
9901034 struct mlx5_flow_destination dest = {};
991
- struct mlx5_flow_handle **rules;
1035
+ struct mlx5e_ttc_rule *rules;
9921036 struct mlx5_flow_table *ft;
9931037 int err;
9941038 int tt;
9951039
9961040 ft = ttc->ft.t;
9971041 rules = ttc->rules;
998
-
9991042 dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
1043
+
10001044 for (tt = 0; tt < MLX5E_NUM_TT; tt++) {
1045
+ struct mlx5e_ttc_rule *rule = &rules[tt];
1046
+
10011047 if (tt == MLX5E_TT_ANY)
10021048 dest.tir_num = params->any_tt_tirn;
10031049 else
10041050 dest.tir_num = params->indir_tirn[tt];
10051051
1006
- rules[tt] = mlx5e_generate_inner_ttc_rule(priv, ft, &dest,
1007
- ttc_rules[tt].etype,
1008
- ttc_rules[tt].proto);
1009
- if (IS_ERR(rules[tt]))
1052
+ rule->rule = mlx5e_generate_inner_ttc_rule(priv, ft, &dest,
1053
+ ttc_rules[tt].etype,
1054
+ ttc_rules[tt].proto);
1055
+ if (IS_ERR(rule->rule)) {
1056
+ err = PTR_ERR(rule->rule);
1057
+ rule->rule = NULL;
10101058 goto del_rules;
1059
+ }
1060
+ rule->default_dest = dest;
10111061 }
10121062
10131063 return 0;
10141064
10151065 del_rules:
1016
- err = PTR_ERR(rules[tt]);
1017
- rules[tt] = NULL;
1066
+
10181067 mlx5e_cleanup_ttc_rules(ttc);
10191068 return err;
10201069 }
....@@ -1089,7 +1138,7 @@
10891138 ttc_params->inner_ttc = &priv->fs.inner_ttc;
10901139 }
10911140
1092
-void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params)
1141
+static void mlx5e_set_inner_ttc_ft_params(struct ttc_params *ttc_params)
10931142 {
10941143 struct mlx5_flow_table_attr *ft_attr = &ttc_params->ft_attr;
10951144
....@@ -1108,8 +1157,8 @@
11081157 ft_attr->prio = MLX5E_NIC_PRIO;
11091158 }
11101159
1111
-int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
1112
- struct mlx5e_ttc_table *ttc)
1160
+static int mlx5e_create_inner_ttc_table(struct mlx5e_priv *priv, struct ttc_params *params,
1161
+ struct mlx5e_ttc_table *ttc)
11131162 {
11141163 struct mlx5e_flow_table *ft = &ttc->ft;
11151164 int err;
....@@ -1139,8 +1188,8 @@
11391188 return err;
11401189 }
11411190
1142
-void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
1143
- struct mlx5e_ttc_table *ttc)
1191
+static void mlx5e_destroy_inner_ttc_table(struct mlx5e_priv *priv,
1192
+ struct mlx5e_ttc_table *ttc)
11441193 {
11451194 if (!mlx5e_tunnel_inner_ft_supported(priv->mdev))
11461195 return;
....@@ -1184,6 +1233,30 @@
11841233 return err;
11851234 }
11861235
1236
+int mlx5e_ttc_fwd_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type,
1237
+ struct mlx5_flow_destination *new_dest)
1238
+{
1239
+ return mlx5_modify_rule_destination(priv->fs.ttc.rules[type].rule, new_dest, NULL);
1240
+}
1241
+
1242
+struct mlx5_flow_destination
1243
+mlx5e_ttc_get_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type)
1244
+{
1245
+ struct mlx5_flow_destination *dest = &priv->fs.ttc.rules[type].default_dest;
1246
+
1247
+ WARN_ONCE(dest->type != MLX5_FLOW_DESTINATION_TYPE_TIR,
1248
+ "TTC[%d] default dest is not setup yet", type);
1249
+
1250
+ return *dest;
1251
+}
1252
+
1253
+int mlx5e_ttc_fwd_default_dest(struct mlx5e_priv *priv, enum mlx5e_traffic_types type)
1254
+{
1255
+ struct mlx5_flow_destination dest = mlx5e_ttc_get_default_dest(priv, type);
1256
+
1257
+ return mlx5e_ttc_fwd_dest(priv, type, &dest);
1258
+}
1259
+
11871260 static void mlx5e_del_l2_flow_rule(struct mlx5e_priv *priv,
11881261 struct mlx5e_l2_rule *ai)
11891262 {