99#include "fs_core.h"
1010#include "lib/ipsec_fs_roce.h"
1111#include "lib/fs_chains.h"
12+ #include "esw/ipsec_fs.h"
1213
1314#define NUM_IPSEC_FTE BIT(15)
1415#define MLX5_REFORMAT_TYPE_ADD_ESP_TRANSPORT_SIZE 16
@@ -19,29 +20,6 @@ struct mlx5e_ipsec_fc {
1920 struct mlx5_fc * drop ;
2021};
2122
22- struct mlx5e_ipsec_ft {
23- struct mutex mutex ; /* Protect changes to this struct */
24- struct mlx5_flow_table * pol ;
25- struct mlx5_flow_table * sa ;
26- struct mlx5_flow_table * status ;
27- u32 refcnt ;
28- };
29-
30- struct mlx5e_ipsec_miss {
31- struct mlx5_flow_group * group ;
32- struct mlx5_flow_handle * rule ;
33- };
34-
35- struct mlx5e_ipsec_rx {
36- struct mlx5e_ipsec_ft ft ;
37- struct mlx5e_ipsec_miss pol ;
38- struct mlx5e_ipsec_miss sa ;
39- struct mlx5e_ipsec_rule status ;
40- struct mlx5e_ipsec_fc * fc ;
41- struct mlx5_fs_chains * chains ;
42- u8 allow_tunnel_mode : 1 ;
43- };
44-
4523struct mlx5e_ipsec_tx {
4624 struct mlx5e_ipsec_ft ft ;
4725 struct mlx5e_ipsec_miss pol ;
@@ -259,9 +237,9 @@ static void ipsec_rx_ft_disconnect(struct mlx5e_ipsec *ipsec, u32 family)
259237static void rx_destroy (struct mlx5_core_dev * mdev , struct mlx5e_ipsec * ipsec ,
260238 struct mlx5e_ipsec_rx * rx , u32 family )
261239{
262-
263240 /* disconnect */
264- ipsec_rx_ft_disconnect (ipsec , family );
241+ if (rx != ipsec -> rx_esw )
242+ ipsec_rx_ft_disconnect (ipsec , family );
265243
266244 if (rx -> chains ) {
267245 ipsec_chains_destroy (rx -> chains );
@@ -276,8 +254,12 @@ static void rx_destroy(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
276254 mlx5_destroy_flow_table (rx -> ft .sa );
277255 if (rx -> allow_tunnel_mode )
278256 mlx5_eswitch_unblock_encap (mdev );
279- mlx5_del_flow_rules (rx -> status .rule );
280- mlx5_modify_header_dealloc (mdev , rx -> status .modify_hdr );
257+ if (rx == ipsec -> rx_esw ) {
258+ mlx5_esw_ipsec_rx_status_destroy (ipsec , rx );
259+ } else {
260+ mlx5_del_flow_rules (rx -> status .rule );
261+ mlx5_modify_header_dealloc (mdev , rx -> status .modify_hdr );
262+ }
281263 mlx5_destroy_flow_table (rx -> ft .status );
282264
283265 mlx5_ipsec_fs_roce_rx_destroy (ipsec -> roce , family );
@@ -288,6 +270,13 @@ static void ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec,
288270 u32 family ,
289271 struct mlx5e_ipsec_rx_create_attr * attr )
290272{
273+ if (rx == ipsec -> rx_esw ) {
274+ /* For packet offload in switchdev mode, RX & TX use FDB namespace */
275+ attr -> ns = ipsec -> tx_esw -> ns ;
276+ mlx5_esw_ipsec_rx_create_attr_set (ipsec , attr );
277+ return ;
278+ }
279+
291280 attr -> ns = mlx5e_fs_get_ns (ipsec -> fs , false);
292281 attr -> ttc = mlx5e_fs_get_ttc (ipsec -> fs , false);
293282 attr -> family = family ;
@@ -306,6 +295,9 @@ static int ipsec_rx_status_pass_dest_get(struct mlx5e_ipsec *ipsec,
306295 struct mlx5_flow_table * ft ;
307296 int err ;
308297
298+ if (rx == ipsec -> rx_esw )
299+ return mlx5_esw_ipsec_rx_status_pass_dest_get (ipsec , dest );
300+
309301 * dest = mlx5_ttc_get_default_dest (attr -> ttc , family2tt (attr -> family ));
310302 err = mlx5_ipsec_fs_roce_rx_create (ipsec -> mdev , ipsec -> roce , attr -> ns , dest ,
311303 attr -> family , MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL ,
@@ -357,7 +349,10 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
357349
358350 dest [1 ].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER ;
359351 dest [1 ].counter_id = mlx5_fc_id (rx -> fc -> cnt );
360- err = ipsec_status_rule (mdev , rx , dest );
352+ if (rx == ipsec -> rx_esw )
353+ err = mlx5_esw_ipsec_rx_status_create (ipsec , rx , dest );
354+ else
355+ err = ipsec_status_rule (mdev , rx , dest );
361356 if (err )
362357 goto err_add ;
363358
@@ -406,7 +401,8 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
406401
407402connect :
408403 /* connect */
409- ipsec_rx_ft_connect (ipsec , rx , & attr );
404+ if (rx != ipsec -> rx_esw )
405+ ipsec_rx_ft_connect (ipsec , rx , & attr );
410406 return 0 ;
411407
412408err_pol_miss :
@@ -864,18 +860,22 @@ static void setup_fte_upper_proto_match(struct mlx5_flow_spec *spec, struct upsp
864860 }
865861}
866862
867- static enum mlx5_flow_namespace_type ipsec_fs_get_ns (struct mlx5e_ipsec * ipsec , u8 dir )
863+ static enum mlx5_flow_namespace_type ipsec_fs_get_ns (struct mlx5e_ipsec * ipsec ,
864+ int type , u8 dir )
868865{
866+ if (ipsec -> is_uplink_rep && type == XFRM_DEV_OFFLOAD_PACKET )
867+ return MLX5_FLOW_NAMESPACE_FDB ;
868+
869869 if (dir == XFRM_DEV_OFFLOAD_IN )
870870 return MLX5_FLOW_NAMESPACE_KERNEL ;
871871
872872 return MLX5_FLOW_NAMESPACE_EGRESS ;
873873}
874874
875- static int setup_modify_header (struct mlx5e_ipsec * ipsec , u32 val , u8 dir ,
875+ static int setup_modify_header (struct mlx5e_ipsec * ipsec , int type , u32 val , u8 dir ,
876876 struct mlx5_flow_act * flow_act )
877877{
878- enum mlx5_flow_namespace_type ns_type = ipsec_fs_get_ns (ipsec , dir );
878+ enum mlx5_flow_namespace_type ns_type = ipsec_fs_get_ns (ipsec , type , dir );
879879 u8 action [MLX5_UN_SZ_BYTES (set_add_copy_action_in_auto )] = {};
880880 struct mlx5_core_dev * mdev = ipsec -> mdev ;
881881 struct mlx5_modify_hdr * modify_hdr ;
@@ -1085,7 +1085,8 @@ static int setup_pkt_reformat(struct mlx5e_ipsec *ipsec,
10851085 struct mlx5_accel_esp_xfrm_attrs * attrs ,
10861086 struct mlx5_flow_act * flow_act )
10871087{
1088- enum mlx5_flow_namespace_type ns_type = ipsec_fs_get_ns (ipsec , attrs -> dir );
1088+ enum mlx5_flow_namespace_type ns_type = ipsec_fs_get_ns (ipsec , attrs -> type ,
1089+ attrs -> dir );
10891090 struct mlx5_pkt_reformat_params reformat_params = {};
10901091 struct mlx5_core_dev * mdev = ipsec -> mdev ;
10911092 struct mlx5_pkt_reformat * pkt_reformat ;
@@ -1127,7 +1128,7 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
11271128 struct mlx5_flow_spec * spec ;
11281129 struct mlx5e_ipsec_rx * rx ;
11291130 struct mlx5_fc * counter ;
1130- int err ;
1131+ int err = 0 ;
11311132
11321133 rx = rx_ft_get (mdev , ipsec , attrs -> family , attrs -> type );
11331134 if (IS_ERR (rx ))
@@ -1148,8 +1149,10 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
11481149 setup_fte_esp (spec );
11491150 setup_fte_no_frags (spec );
11501151
1151- err = setup_modify_header (ipsec , sa_entry -> ipsec_obj_id | BIT (31 ),
1152- XFRM_DEV_OFFLOAD_IN , & flow_act );
1152+ if (rx != ipsec -> rx_esw )
1153+ err = setup_modify_header (ipsec , attrs -> type ,
1154+ sa_entry -> ipsec_obj_id | BIT (31 ),
1155+ XFRM_DEV_OFFLOAD_IN , & flow_act );
11531156 if (err )
11541157 goto err_mod_header ;
11551158
@@ -1340,7 +1343,7 @@ static int tx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
13401343 if (!attrs -> reqid )
13411344 break ;
13421345
1343- err = setup_modify_header (ipsec , attrs -> reqid ,
1346+ err = setup_modify_header (ipsec , attrs -> type , attrs -> reqid ,
13441347 XFRM_DEV_OFFLOAD_OUT , & flow_act );
13451348 if (err )
13461349 goto err_mod_header ;
@@ -1388,6 +1391,7 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
13881391{
13891392 struct mlx5_accel_pol_xfrm_attrs * attrs = & pol_entry -> attrs ;
13901393 struct mlx5_core_dev * mdev = mlx5e_ipsec_pol2dev (pol_entry );
1394+ struct mlx5e_ipsec * ipsec = pol_entry -> ipsec ;
13911395 struct mlx5_flow_destination dest [2 ];
13921396 struct mlx5_flow_act flow_act = {};
13931397 struct mlx5_flow_handle * rule ;
@@ -1433,6 +1437,8 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
14331437 }
14341438
14351439 flow_act .flags |= FLOW_ACT_NO_APPEND ;
1440+ if (rx == ipsec -> rx_esw && rx -> chains )
1441+ flow_act .flags |= FLOW_ACT_IGNORE_FLOW_LEVEL ;
14361442 dest [dstn ].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE ;
14371443 dest [dstn ].ft = rx -> ft .sa ;
14381444 dstn ++ ;
0 commit comments