3636#include <linux/mlx5/cmd.h>
3737#include <linux/mlx5/qp.h>
3838#include <linux/mlx5/driver.h>
39+ #include <linux/mlx5/transobj.h>
3940
4041#include "mlx5_core.h"
4142
@@ -77,6 +78,8 @@ void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type)
7778
7879 switch (common -> res ) {
7980 case MLX5_RES_QP :
81+ case MLX5_RES_RQ :
82+ case MLX5_RES_SQ :
8083 qp = (struct mlx5_core_qp * )common ;
8184 qp -> event (qp , event_type );
8285 break ;
@@ -177,12 +180,48 @@ void mlx5_eq_pagefault(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe)
177180}
178181#endif
179182
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+
180220int mlx5_core_create_qp (struct mlx5_core_dev * dev ,
181221 struct mlx5_core_qp * qp ,
182222 struct mlx5_create_qp_mbox_in * in ,
183223 int inlen )
184224{
185- struct mlx5_qp_table * table = & dev -> priv .qp_table ;
186225 struct mlx5_create_qp_mbox_out out ;
187226 struct mlx5_destroy_qp_mbox_in din ;
188227 struct mlx5_destroy_qp_mbox_out dout ;
@@ -206,24 +245,16 @@ int mlx5_core_create_qp(struct mlx5_core_dev *dev,
206245 qp -> qpn = be32_to_cpu (out .qpn ) & 0xffffff ;
207246 mlx5_core_dbg (dev , "qpn = 0x%x\n" , qp -> qpn );
208247
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 )
215250 goto err_cmd ;
216- }
217251
218252 err = mlx5_debug_qp_add (dev , qp );
219253 if (err )
220254 mlx5_core_dbg (dev , "failed adding QP 0x%x to debug file system\n" ,
221255 qp -> qpn );
222256
223- qp -> pid = current -> pid ;
224- atomic_set (& qp -> common .refcount , 1 );
225257 atomic_inc (& dev -> num_qps );
226- init_completion (& qp -> common .free );
227258
228259 return 0 ;
229260
@@ -243,18 +274,11 @@ int mlx5_core_destroy_qp(struct mlx5_core_dev *dev,
243274{
244275 struct mlx5_destroy_qp_mbox_in in ;
245276 struct mlx5_destroy_qp_mbox_out out ;
246- struct mlx5_qp_table * table = & dev -> priv .qp_table ;
247- unsigned long flags ;
248277 int err ;
249278
250279 mlx5_debug_qp_remove (dev , qp );
251280
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 );
258282
259283 memset (& in , 0 , sizeof (in ));
260284 memset (& out , 0 , sizeof (out ));
@@ -442,3 +466,67 @@ int mlx5_core_page_fault_resume(struct mlx5_core_dev *dev, u32 qpn,
442466}
443467EXPORT_SYMBOL_GPL (mlx5_core_page_fault_resume );
444468#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