@@ -20,9 +20,17 @@ struct mlx5_ipsec_rx_roce {
20
20
struct mlx5_flow_namespace * ns_rdma ;
21
21
};
22
22
23
+ struct mlx5_ipsec_tx_roce {
24
+ struct mlx5_flow_group * g ;
25
+ struct mlx5_flow_table * ft ;
26
+ struct mlx5_flow_handle * rule ;
27
+ struct mlx5_flow_namespace * ns ;
28
+ };
29
+
23
30
struct mlx5_ipsec_fs {
24
31
struct mlx5_ipsec_rx_roce ipv4_rx ;
25
32
struct mlx5_ipsec_rx_roce ipv6_rx ;
33
+ struct mlx5_ipsec_tx_roce tx ;
26
34
};
27
35
28
36
static void ipsec_fs_roce_setup_udp_dport (struct mlx5_flow_spec * spec ,
@@ -86,6 +94,105 @@ ipsec_fs_roce_rx_rule_setup(struct mlx5_core_dev *mdev,
86
94
return err ;
87
95
}
88
96
97
+ static int ipsec_fs_roce_tx_rule_setup (struct mlx5_core_dev * mdev ,
98
+ struct mlx5_ipsec_tx_roce * roce ,
99
+ struct mlx5_flow_table * pol_ft )
100
+ {
101
+ struct mlx5_flow_destination dst = {};
102
+ MLX5_DECLARE_FLOW_ACT (flow_act );
103
+ struct mlx5_flow_handle * rule ;
104
+ int err = 0 ;
105
+
106
+ flow_act .action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST ;
107
+ dst .type = MLX5_FLOW_DESTINATION_TYPE_TABLE_TYPE ;
108
+ dst .ft = pol_ft ;
109
+ rule = mlx5_add_flow_rules (roce -> ft , NULL , & flow_act , & dst ,
110
+ 1 );
111
+ if (IS_ERR (rule )) {
112
+ err = PTR_ERR (rule );
113
+ mlx5_core_err (mdev , "Fail to add TX RoCE IPsec rule err=%d\n" ,
114
+ err );
115
+ goto out ;
116
+ }
117
+ roce -> rule = rule ;
118
+
119
+ out :
120
+ return err ;
121
+ }
122
+
123
+ void mlx5_ipsec_fs_roce_tx_destroy (struct mlx5_ipsec_fs * ipsec_roce )
124
+ {
125
+ struct mlx5_ipsec_tx_roce * tx_roce ;
126
+
127
+ if (!ipsec_roce )
128
+ return ;
129
+
130
+ tx_roce = & ipsec_roce -> tx ;
131
+
132
+ mlx5_del_flow_rules (tx_roce -> rule );
133
+ mlx5_destroy_flow_group (tx_roce -> g );
134
+ mlx5_destroy_flow_table (tx_roce -> ft );
135
+ }
136
+
137
+ #define MLX5_TX_ROCE_GROUP_SIZE BIT(0)
138
+
139
+ int mlx5_ipsec_fs_roce_tx_create (struct mlx5_core_dev * mdev ,
140
+ struct mlx5_ipsec_fs * ipsec_roce ,
141
+ struct mlx5_flow_table * pol_ft )
142
+ {
143
+ struct mlx5_flow_table_attr ft_attr = {};
144
+ struct mlx5_ipsec_tx_roce * roce ;
145
+ struct mlx5_flow_table * ft ;
146
+ struct mlx5_flow_group * g ;
147
+ int ix = 0 ;
148
+ int err ;
149
+ u32 * in ;
150
+
151
+ if (!ipsec_roce )
152
+ return 0 ;
153
+
154
+ roce = & ipsec_roce -> tx ;
155
+
156
+ in = kvzalloc (MLX5_ST_SZ_BYTES (create_flow_group_in ), GFP_KERNEL );
157
+ if (!in )
158
+ return - ENOMEM ;
159
+
160
+ ft_attr .max_fte = 1 ;
161
+ ft = mlx5_create_flow_table (roce -> ns , & ft_attr );
162
+ if (IS_ERR (ft )) {
163
+ err = PTR_ERR (ft );
164
+ mlx5_core_err (mdev , "Fail to create RoCE IPsec tx ft err=%d\n" , err );
165
+ return err ;
166
+ }
167
+
168
+ roce -> ft = ft ;
169
+
170
+ MLX5_SET_CFG (in , start_flow_index , ix );
171
+ ix += MLX5_TX_ROCE_GROUP_SIZE ;
172
+ MLX5_SET_CFG (in , end_flow_index , ix - 1 );
173
+ g = mlx5_create_flow_group (ft , in );
174
+ if (IS_ERR (g )) {
175
+ err = PTR_ERR (g );
176
+ mlx5_core_err (mdev , "Fail to create RoCE IPsec tx group err=%d\n" , err );
177
+ goto fail ;
178
+ }
179
+ roce -> g = g ;
180
+
181
+ err = ipsec_fs_roce_tx_rule_setup (mdev , roce , pol_ft );
182
+ if (err ) {
183
+ mlx5_core_err (mdev , "Fail to create RoCE IPsec tx rules err=%d\n" , err );
184
+ goto rule_fail ;
185
+ }
186
+
187
+ return 0 ;
188
+
189
+ rule_fail :
190
+ mlx5_destroy_flow_group (roce -> g );
191
+ fail :
192
+ mlx5_destroy_flow_table (ft );
193
+ return err ;
194
+ }
195
+
89
196
struct mlx5_flow_table * mlx5_ipsec_fs_roce_ft_get (struct mlx5_ipsec_fs * ipsec_roce , u32 family )
90
197
{
91
198
struct mlx5_ipsec_rx_roce * rx_roce ;
@@ -245,5 +352,17 @@ struct mlx5_ipsec_fs *mlx5_ipsec_fs_roce_init(struct mlx5_core_dev *mdev)
245
352
roce_ipsec -> ipv4_rx .ns_rdma = ns ;
246
353
roce_ipsec -> ipv6_rx .ns_rdma = ns ;
247
354
355
+ ns = mlx5_get_flow_namespace (mdev , MLX5_FLOW_NAMESPACE_RDMA_TX_IPSEC );
356
+ if (!ns ) {
357
+ mlx5_core_err (mdev , "Failed to get RoCE tx ns\n" );
358
+ goto err_tx ;
359
+ }
360
+
361
+ roce_ipsec -> tx .ns = ns ;
362
+
248
363
return roce_ipsec ;
364
+
365
+ err_tx :
366
+ kfree (roce_ipsec );
367
+ return NULL ;
249
368
}
0 commit comments