Skip to content

Commit fdefb91

Browse files
Konstantin Taranovrleon
authored andcommitted
RDMA/mana_ib: Implement uapi to create and destroy RC QP
Implement user requests to create and destroy an RC QP. As the user does not have an FMR queue, it is skipped and NO_FMR flag is used. Signed-off-by: Konstantin Taranov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Zhu Yanjun <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 53657a0 commit fdefb91

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

drivers/infiniband/hw/mana/mana_ib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ struct mana_rnic_destroy_cq_resp {
248248
struct gdma_resp_hdr hdr;
249249
}; /* HW Data */
250250

251+
enum mana_rnic_create_rc_flags {
252+
MANA_RC_FLAG_NO_FMR = 2,
253+
};
254+
251255
struct mana_rnic_create_qp_req {
252256
struct gdma_req_hdr hdr;
253257
mana_handle_t adapter;

drivers/infiniband/hw/mana/qp.c

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,78 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd,
398398
return err;
399399
}
400400

401+
static int mana_ib_create_rc_qp(struct ib_qp *ibqp, struct ib_pd *ibpd,
402+
struct ib_qp_init_attr *attr, struct ib_udata *udata)
403+
{
404+
struct mana_ib_dev *mdev = container_of(ibpd->device, struct mana_ib_dev, ib_dev);
405+
struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp);
406+
struct mana_ib_create_rc_qp_resp resp = {};
407+
struct mana_ib_ucontext *mana_ucontext;
408+
struct mana_ib_create_rc_qp ucmd = {};
409+
int i, err, j;
410+
u64 flags = 0;
411+
u32 doorbell;
412+
413+
if (!udata || udata->inlen < sizeof(ucmd))
414+
return -EINVAL;
415+
416+
mana_ucontext = rdma_udata_to_drv_context(udata, struct mana_ib_ucontext, ibucontext);
417+
doorbell = mana_ucontext->doorbell;
418+
flags = MANA_RC_FLAG_NO_FMR;
419+
err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen));
420+
if (err) {
421+
ibdev_dbg(&mdev->ib_dev, "Failed to copy from udata, %d\n", err);
422+
return err;
423+
}
424+
425+
for (i = 0, j = 0; i < MANA_RC_QUEUE_TYPE_MAX; ++i) {
426+
/* skip FMR for user-level RC QPs */
427+
if (i == MANA_RC_SEND_QUEUE_FMR) {
428+
qp->rc_qp.queues[i].id = INVALID_QUEUE_ID;
429+
qp->rc_qp.queues[i].gdma_region = GDMA_INVALID_DMA_REGION;
430+
continue;
431+
}
432+
err = mana_ib_create_queue(mdev, ucmd.queue_buf[j], ucmd.queue_size[j],
433+
&qp->rc_qp.queues[i]);
434+
if (err) {
435+
ibdev_err(&mdev->ib_dev, "Failed to create queue %d, err %d\n", i, err);
436+
goto destroy_queues;
437+
}
438+
j++;
439+
}
440+
441+
err = mana_ib_gd_create_rc_qp(mdev, qp, attr, doorbell, flags);
442+
if (err) {
443+
ibdev_err(&mdev->ib_dev, "Failed to create rc qp %d\n", err);
444+
goto destroy_queues;
445+
}
446+
qp->ibqp.qp_num = qp->rc_qp.queues[MANA_RC_RECV_QUEUE_RESPONDER].id;
447+
qp->port = attr->port_num;
448+
449+
if (udata) {
450+
for (i = 0, j = 0; i < MANA_RC_QUEUE_TYPE_MAX; ++i) {
451+
if (i == MANA_RC_SEND_QUEUE_FMR)
452+
continue;
453+
resp.queue_id[j] = qp->rc_qp.queues[i].id;
454+
j++;
455+
}
456+
err = ib_copy_to_udata(udata, &resp, min(sizeof(resp), udata->outlen));
457+
if (err) {
458+
ibdev_dbg(&mdev->ib_dev, "Failed to copy to udata, %d\n", err);
459+
goto destroy_qp;
460+
}
461+
}
462+
463+
return 0;
464+
465+
destroy_qp:
466+
mana_ib_gd_destroy_rc_qp(mdev, qp);
467+
destroy_queues:
468+
while (i-- > 0)
469+
mana_ib_destroy_queue(mdev, &qp->rc_qp.queues[i]);
470+
return err;
471+
}
472+
401473
int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
402474
struct ib_udata *udata)
403475
{
@@ -409,8 +481,9 @@ int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
409481
udata);
410482

411483
return mana_ib_create_qp_raw(ibqp, ibqp->pd, attr, udata);
484+
case IB_QPT_RC:
485+
return mana_ib_create_rc_qp(ibqp, ibqp->pd, attr, udata);
412486
default:
413-
/* Creating QP other than IB_QPT_RAW_PACKET is not supported */
414487
ibdev_dbg(ibqp->device, "Creating QP type %u not supported\n",
415488
attr->qp_type);
416489
}
@@ -473,6 +546,22 @@ static int mana_ib_destroy_qp_raw(struct mana_ib_qp *qp, struct ib_udata *udata)
473546
return 0;
474547
}
475548

549+
static int mana_ib_destroy_rc_qp(struct mana_ib_qp *qp, struct ib_udata *udata)
550+
{
551+
struct mana_ib_dev *mdev =
552+
container_of(qp->ibqp.device, struct mana_ib_dev, ib_dev);
553+
int i;
554+
555+
/* Ignore return code as there is not much we can do about it.
556+
* The error message is printed inside.
557+
*/
558+
mana_ib_gd_destroy_rc_qp(mdev, qp);
559+
for (i = 0; i < MANA_RC_QUEUE_TYPE_MAX; ++i)
560+
mana_ib_destroy_queue(mdev, &qp->rc_qp.queues[i]);
561+
562+
return 0;
563+
}
564+
476565
int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
477566
{
478567
struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp);
@@ -484,7 +573,8 @@ int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
484573
udata);
485574

486575
return mana_ib_destroy_qp_raw(qp, udata);
487-
576+
case IB_QPT_RC:
577+
return mana_ib_destroy_rc_qp(qp, udata);
488578
default:
489579
ibdev_dbg(ibqp->device, "Unexpected QP type %u\n",
490580
ibqp->qp_type);

include/uapi/rdma/mana-abi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ struct mana_ib_create_qp_resp {
4545
__u32 reserved;
4646
};
4747

48+
struct mana_ib_create_rc_qp {
49+
__aligned_u64 queue_buf[4];
50+
__u32 queue_size[4];
51+
};
52+
53+
struct mana_ib_create_rc_qp_resp {
54+
__u32 queue_id[4];
55+
};
56+
4857
struct mana_ib_create_wq {
4958
__aligned_u64 wq_buf_addr;
5059
__u32 wq_buf_size;

0 commit comments

Comments
 (0)