36
36
#include <linux/mlx5/cmd.h>
37
37
#include <linux/mlx5/qp.h>
38
38
#include <linux/mlx5/driver.h>
39
+ #include <linux/mlx5/transobj.h>
39
40
40
41
#include "mlx5_core.h"
41
42
@@ -77,6 +78,8 @@ void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type)
77
78
78
79
switch (common -> res ) {
79
80
case MLX5_RES_QP :
81
+ case MLX5_RES_RQ :
82
+ case MLX5_RES_SQ :
80
83
qp = (struct mlx5_core_qp * )common ;
81
84
qp -> event (qp , event_type );
82
85
break ;
@@ -177,12 +180,48 @@ void mlx5_eq_pagefault(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe)
177
180
}
178
181
#endif
179
182
183
+ static int create_qprqsq_common (struct mlx5_core_dev * dev ,
184
+ struct mlx5_core_qp * qp ,
185
+ int rsc_type )
186
+ {
187
+ struct mlx5_qp_table * table = & dev -> priv .qp_table ;
188
+ int err ;
189
+
190
+ qp -> common .res = rsc_type ;
191
+ spin_lock_irq (& table -> lock );
192
+ err = radix_tree_insert (& table -> tree ,
193
+ qp -> qpn | (rsc_type << MLX5_USER_INDEX_LEN ),
194
+ qp );
195
+ spin_unlock_irq (& table -> lock );
196
+ if (err )
197
+ return err ;
198
+
199
+ atomic_set (& qp -> common .refcount , 1 );
200
+ init_completion (& qp -> common .free );
201
+ qp -> pid = current -> pid ;
202
+
203
+ return 0 ;
204
+ }
205
+
206
+ static void destroy_qprqsq_common (struct mlx5_core_dev * dev ,
207
+ struct mlx5_core_qp * qp )
208
+ {
209
+ struct mlx5_qp_table * table = & dev -> priv .qp_table ;
210
+ unsigned long flags ;
211
+
212
+ spin_lock_irqsave (& table -> lock , flags );
213
+ radix_tree_delete (& table -> tree ,
214
+ qp -> qpn | (qp -> common .res << MLX5_USER_INDEX_LEN ));
215
+ spin_unlock_irqrestore (& table -> lock , flags );
216
+ mlx5_core_put_rsc ((struct mlx5_core_rsc_common * )qp );
217
+ wait_for_completion (& qp -> common .free );
218
+ }
219
+
180
220
int mlx5_core_create_qp (struct mlx5_core_dev * dev ,
181
221
struct mlx5_core_qp * qp ,
182
222
struct mlx5_create_qp_mbox_in * in ,
183
223
int inlen )
184
224
{
185
- struct mlx5_qp_table * table = & dev -> priv .qp_table ;
186
225
struct mlx5_create_qp_mbox_out out ;
187
226
struct mlx5_destroy_qp_mbox_in din ;
188
227
struct mlx5_destroy_qp_mbox_out dout ;
@@ -206,24 +245,16 @@ int mlx5_core_create_qp(struct mlx5_core_dev *dev,
206
245
qp -> qpn = be32_to_cpu (out .qpn ) & 0xffffff ;
207
246
mlx5_core_dbg (dev , "qpn = 0x%x\n" , qp -> qpn );
208
247
209
- qp -> common .res = MLX5_RES_QP ;
210
- spin_lock_irq (& table -> lock );
211
- err = radix_tree_insert (& table -> tree , qp -> qpn , qp );
212
- spin_unlock_irq (& table -> lock );
213
- if (err ) {
214
- mlx5_core_warn (dev , "err %d\n" , err );
248
+ err = create_qprqsq_common (dev , qp , MLX5_RES_QP );
249
+ if (err )
215
250
goto err_cmd ;
216
- }
217
251
218
252
err = mlx5_debug_qp_add (dev , qp );
219
253
if (err )
220
254
mlx5_core_dbg (dev , "failed adding QP 0x%x to debug file system\n" ,
221
255
qp -> qpn );
222
256
223
- qp -> pid = current -> pid ;
224
- atomic_set (& qp -> common .refcount , 1 );
225
257
atomic_inc (& dev -> num_qps );
226
- init_completion (& qp -> common .free );
227
258
228
259
return 0 ;
229
260
@@ -243,18 +274,11 @@ int mlx5_core_destroy_qp(struct mlx5_core_dev *dev,
243
274
{
244
275
struct mlx5_destroy_qp_mbox_in in ;
245
276
struct mlx5_destroy_qp_mbox_out out ;
246
- struct mlx5_qp_table * table = & dev -> priv .qp_table ;
247
- unsigned long flags ;
248
277
int err ;
249
278
250
279
mlx5_debug_qp_remove (dev , qp );
251
280
252
- spin_lock_irqsave (& table -> lock , flags );
253
- radix_tree_delete (& table -> tree , qp -> qpn );
254
- spin_unlock_irqrestore (& table -> lock , flags );
255
-
256
- mlx5_core_put_rsc ((struct mlx5_core_rsc_common * )qp );
257
- wait_for_completion (& qp -> common .free );
281
+ destroy_qprqsq_common (dev , qp );
258
282
259
283
memset (& in , 0 , sizeof (in ));
260
284
memset (& out , 0 , sizeof (out ));
@@ -442,3 +466,67 @@ int mlx5_core_page_fault_resume(struct mlx5_core_dev *dev, u32 qpn,
442
466
}
443
467
EXPORT_SYMBOL_GPL (mlx5_core_page_fault_resume );
444
468
#endif
469
+
470
+ int mlx5_core_create_rq_tracked (struct mlx5_core_dev * dev , u32 * in , int inlen ,
471
+ struct mlx5_core_qp * rq )
472
+ {
473
+ int err ;
474
+ u32 rqn ;
475
+
476
+ err = mlx5_core_create_rq (dev , in , inlen , & rqn );
477
+ if (err )
478
+ return err ;
479
+
480
+ rq -> qpn = rqn ;
481
+ err = create_qprqsq_common (dev , rq , MLX5_RES_RQ );
482
+ if (err )
483
+ goto err_destroy_rq ;
484
+
485
+ return 0 ;
486
+
487
+ err_destroy_rq :
488
+ mlx5_core_destroy_rq (dev , rq -> qpn );
489
+
490
+ return err ;
491
+ }
492
+ EXPORT_SYMBOL (mlx5_core_create_rq_tracked );
493
+
494
+ void mlx5_core_destroy_rq_tracked (struct mlx5_core_dev * dev ,
495
+ struct mlx5_core_qp * rq )
496
+ {
497
+ destroy_qprqsq_common (dev , rq );
498
+ mlx5_core_destroy_rq (dev , rq -> qpn );
499
+ }
500
+ EXPORT_SYMBOL (mlx5_core_destroy_rq_tracked );
501
+
502
+ int mlx5_core_create_sq_tracked (struct mlx5_core_dev * dev , u32 * in , int inlen ,
503
+ struct mlx5_core_qp * sq )
504
+ {
505
+ int err ;
506
+ u32 sqn ;
507
+
508
+ err = mlx5_core_create_sq (dev , in , inlen , & sqn );
509
+ if (err )
510
+ return err ;
511
+
512
+ sq -> qpn = sqn ;
513
+ err = create_qprqsq_common (dev , sq , MLX5_RES_SQ );
514
+ if (err )
515
+ goto err_destroy_sq ;
516
+
517
+ return 0 ;
518
+
519
+ err_destroy_sq :
520
+ mlx5_core_destroy_sq (dev , sq -> qpn );
521
+
522
+ return err ;
523
+ }
524
+ EXPORT_SYMBOL (mlx5_core_create_sq_tracked );
525
+
526
+ void mlx5_core_destroy_sq_tracked (struct mlx5_core_dev * dev ,
527
+ struct mlx5_core_qp * sq )
528
+ {
529
+ destroy_qprqsq_common (dev , sq );
530
+ mlx5_core_destroy_sq (dev , sq -> qpn );
531
+ }
532
+ EXPORT_SYMBOL (mlx5_core_destroy_sq_tracked );
0 commit comments