40
40
#include "mlx5_core.h"
41
41
#include "lib/eq.h"
42
42
43
+ static int mlx5_core_drain_dct (struct mlx5_core_dev * dev ,
44
+ struct mlx5_core_dct * dct );
45
+
43
46
static struct mlx5_core_rsc_common *
44
47
mlx5_get_rsc (struct mlx5_qp_table * table , u32 rsn )
45
48
{
@@ -227,13 +230,42 @@ static void destroy_resource_common(struct mlx5_core_dev *dev,
227
230
wait_for_completion (& qp -> common .free );
228
231
}
229
232
233
+ static int _mlx5_core_destroy_dct (struct mlx5_core_dev * dev ,
234
+ struct mlx5_core_dct * dct , bool need_cleanup )
235
+ {
236
+ u32 out [MLX5_ST_SZ_DW (destroy_dct_out )] = {0 };
237
+ u32 in [MLX5_ST_SZ_DW (destroy_dct_in )] = {0 };
238
+ struct mlx5_core_qp * qp = & dct -> mqp ;
239
+ int err ;
240
+
241
+ err = mlx5_core_drain_dct (dev , dct );
242
+ if (err ) {
243
+ if (dev -> state == MLX5_DEVICE_STATE_INTERNAL_ERROR ) {
244
+ goto destroy ;
245
+ } else {
246
+ mlx5_core_warn (
247
+ dev , "failed drain DCT 0x%x with error 0x%x\n" ,
248
+ qp -> qpn , err );
249
+ return err ;
250
+ }
251
+ }
252
+ wait_for_completion (& dct -> drained );
253
+ destroy :
254
+ if (need_cleanup )
255
+ destroy_resource_common (dev , & dct -> mqp );
256
+ MLX5_SET (destroy_dct_in , in , opcode , MLX5_CMD_OP_DESTROY_DCT );
257
+ MLX5_SET (destroy_dct_in , in , dctn , qp -> qpn );
258
+ MLX5_SET (destroy_dct_in , in , uid , qp -> uid );
259
+ err = mlx5_cmd_exec (dev , (void * )& in , sizeof (in ),
260
+ (void * )& out , sizeof (out ));
261
+ return err ;
262
+ }
263
+
230
264
int mlx5_core_create_dct (struct mlx5_core_dev * dev ,
231
265
struct mlx5_core_dct * dct ,
232
266
u32 * in , int inlen )
233
267
{
234
268
u32 out [MLX5_ST_SZ_DW (create_dct_out )] = {0 };
235
- u32 din [MLX5_ST_SZ_DW (destroy_dct_in )] = {0 };
236
- u32 dout [MLX5_ST_SZ_DW (destroy_dct_out )] = {0 };
237
269
struct mlx5_core_qp * qp = & dct -> mqp ;
238
270
int err ;
239
271
@@ -254,11 +286,7 @@ int mlx5_core_create_dct(struct mlx5_core_dev *dev,
254
286
255
287
return 0 ;
256
288
err_cmd :
257
- MLX5_SET (destroy_dct_in , din , opcode , MLX5_CMD_OP_DESTROY_DCT );
258
- MLX5_SET (destroy_dct_in , din , dctn , qp -> qpn );
259
- MLX5_SET (destroy_dct_in , din , uid , qp -> uid );
260
- mlx5_cmd_exec (dev , (void * )& in , sizeof (din ),
261
- (void * )& out , sizeof (dout ));
289
+ _mlx5_core_destroy_dct (dev , dct , false);
262
290
return err ;
263
291
}
264
292
EXPORT_SYMBOL_GPL (mlx5_core_create_dct );
@@ -323,29 +351,7 @@ static int mlx5_core_drain_dct(struct mlx5_core_dev *dev,
323
351
int mlx5_core_destroy_dct (struct mlx5_core_dev * dev ,
324
352
struct mlx5_core_dct * dct )
325
353
{
326
- u32 out [MLX5_ST_SZ_DW (destroy_dct_out )] = {0 };
327
- u32 in [MLX5_ST_SZ_DW (destroy_dct_in )] = {0 };
328
- struct mlx5_core_qp * qp = & dct -> mqp ;
329
- int err ;
330
-
331
- err = mlx5_core_drain_dct (dev , dct );
332
- if (err ) {
333
- if (dev -> state == MLX5_DEVICE_STATE_INTERNAL_ERROR ) {
334
- goto destroy ;
335
- } else {
336
- mlx5_core_warn (dev , "failed drain DCT 0x%x with error 0x%x\n" , qp -> qpn , err );
337
- return err ;
338
- }
339
- }
340
- wait_for_completion (& dct -> drained );
341
- destroy :
342
- destroy_resource_common (dev , & dct -> mqp );
343
- MLX5_SET (destroy_dct_in , in , opcode , MLX5_CMD_OP_DESTROY_DCT );
344
- MLX5_SET (destroy_dct_in , in , dctn , qp -> qpn );
345
- MLX5_SET (destroy_dct_in , in , uid , qp -> uid );
346
- err = mlx5_cmd_exec (dev , (void * )& in , sizeof (in ),
347
- (void * )& out , sizeof (out ));
348
- return err ;
354
+ return _mlx5_core_destroy_dct (dev , dct , true);
349
355
}
350
356
EXPORT_SYMBOL_GPL (mlx5_core_destroy_dct );
351
357
0 commit comments