Skip to content

Commit e2013b2

Browse files
majdmellanoxdledford
authored andcommitted
net/mlx5_core: Add RQ and SQ event handling
RQ/SQ will be used to implement IB verbs QPs, so the IB QP affiliated events are affiliated also with SQs and RQs. Since SQ, RQ and QP resource numbers do not share the same name space, a queue type field was added to the event data to specify the SW object that the event is affiliated with. Signed-off-by: Majd Dibbiny <majd@mellanox.com> Reviewed-by: Matan Barak <matanb@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 8d7f9ec commit e2013b2

File tree

5 files changed

+132
-23
lines changed

5 files changed

+132
-23
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ static int mlx5_eq_int(struct mlx5_core_dev *dev, struct mlx5_eq *eq)
227227
case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
228228
case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR:
229229
rsn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff;
230+
rsn |= (eqe->data.qp_srq.type << MLX5_USER_INDEX_LEN);
230231
mlx5_core_dbg(dev, "event %s(%d) arrived on resource 0x%x\n",
231232
eqe_type_str(eqe->type), eqe->type, rsn);
232233
mlx5_rsc_event(dev, rsn, eqe->type);

drivers/net/ethernet/mellanox/mlx5/core/qp.c

Lines changed: 107 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
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+
180220
int 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
}
443467
EXPORT_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);

include/linux/mlx5/device.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ enum {
223223
#define MLX5_UMR_MTT_MASK (MLX5_UMR_MTT_ALIGNMENT - 1)
224224
#define MLX5_UMR_MTT_MIN_CHUNK_SIZE MLX5_UMR_MTT_ALIGNMENT
225225

226+
#define MLX5_USER_INDEX_LEN (MLX5_FLD_SZ_BYTES(qpc, user_index) * 8)
227+
228+
enum {
229+
MLX5_EVENT_QUEUE_TYPE_QP = 0,
230+
MLX5_EVENT_QUEUE_TYPE_RQ = 1,
231+
MLX5_EVENT_QUEUE_TYPE_SQ = 2,
232+
};
233+
226234
enum mlx5_event {
227235
MLX5_EVENT_TYPE_COMP = 0x0,
228236

@@ -479,7 +487,9 @@ struct mlx5_eqe_comp {
479487
};
480488

481489
struct mlx5_eqe_qp_srq {
482-
__be32 reserved[6];
490+
__be32 reserved1[5];
491+
u8 type;
492+
u8 reserved2[3];
483493
__be32 qp_srq_n;
484494
};
485495

include/linux/mlx5/driver.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,11 @@ struct mlx5_core_mr {
346346
};
347347

348348
enum mlx5_res_type {
349-
MLX5_RES_QP,
350-
MLX5_RES_SRQ,
351-
MLX5_RES_XSRQ,
349+
MLX5_RES_QP = MLX5_EVENT_QUEUE_TYPE_QP,
350+
MLX5_RES_RQ = MLX5_EVENT_QUEUE_TYPE_RQ,
351+
MLX5_RES_SQ = MLX5_EVENT_QUEUE_TYPE_SQ,
352+
MLX5_RES_SRQ = 3,
353+
MLX5_RES_XSRQ = 4,
352354
};
353355

354356
struct mlx5_core_rsc_common {

include/linux/mlx5/qp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,14 @@ void mlx5_debug_qp_remove(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp);
651651
int mlx5_core_page_fault_resume(struct mlx5_core_dev *dev, u32 qpn,
652652
u8 context, int error);
653653
#endif
654+
int mlx5_core_create_rq_tracked(struct mlx5_core_dev *dev, u32 *in, int inlen,
655+
struct mlx5_core_qp *rq);
656+
void mlx5_core_destroy_rq_tracked(struct mlx5_core_dev *dev,
657+
struct mlx5_core_qp *rq);
658+
int mlx5_core_create_sq_tracked(struct mlx5_core_dev *dev, u32 *in, int inlen,
659+
struct mlx5_core_qp *sq);
660+
void mlx5_core_destroy_sq_tracked(struct mlx5_core_dev *dev,
661+
struct mlx5_core_qp *sq);
654662

655663
static inline const char *mlx5_qp_type_str(int type)
656664
{

0 commit comments

Comments
 (0)