Merge tag 'io_uring-5.15-2021-09-11' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / drivers / infiniband / hw / bnxt_re / ib_verbs.c
index 2efaa80..408dfbc 100644 (file)
@@ -163,6 +163,10 @@ int bnxt_re_query_device(struct ib_device *ibdev,
        ib_attr->max_qp_init_rd_atom = dev_attr->max_qp_init_rd_atom;
        ib_attr->atomic_cap = IB_ATOMIC_NONE;
        ib_attr->masked_atomic_cap = IB_ATOMIC_NONE;
+       if (dev_attr->is_atomic) {
+               ib_attr->atomic_cap = IB_ATOMIC_GLOB;
+               ib_attr->masked_atomic_cap = IB_ATOMIC_GLOB;
+       }
 
        ib_attr->max_ee_rd_atom = 0;
        ib_attr->max_res_rd_atom = 0;
@@ -811,7 +815,7 @@ int bnxt_re_destroy_qp(struct ib_qp *ib_qp, struct ib_udata *udata)
        if (ib_qp->qp_type == IB_QPT_GSI && rdev->gsi_ctx.gsi_sqp) {
                rc = bnxt_re_destroy_gsi_sqp(qp);
                if (rc)
-                       goto sh_fail;
+                       return rc;
        }
 
        mutex_lock(&rdev->qp_lock);
@@ -822,10 +826,7 @@ int bnxt_re_destroy_qp(struct ib_qp *ib_qp, struct ib_udata *udata)
        ib_umem_release(qp->rumem);
        ib_umem_release(qp->sumem);
 
-       kfree(qp);
        return 0;
-sh_fail:
-       return rc;
 }
 
 static u8 __from_ib_qp_type(enum ib_qp_type type)
@@ -1098,10 +1099,6 @@ static int bnxt_re_init_rq_attr(struct bnxt_re_qp *qp,
                struct bnxt_re_srq *srq;
 
                srq = container_of(init_attr->srq, struct bnxt_re_srq, ib_srq);
-               if (!srq) {
-                       ibdev_err(&rdev->ibdev, "SRQ not found");
-                       return -EINVAL;
-               }
                qplqp->srq = &srq->qplib_srq;
                rq->max_wqe = 0;
        } else {
@@ -1279,22 +1276,12 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd,
        /* Setup CQs */
        if (init_attr->send_cq) {
                cq = container_of(init_attr->send_cq, struct bnxt_re_cq, ib_cq);
-               if (!cq) {
-                       ibdev_err(&rdev->ibdev, "Send CQ not found");
-                       rc = -EINVAL;
-                       goto out;
-               }
                qplqp->scq = &cq->qplib_cq;
                qp->scq = cq;
        }
 
        if (init_attr->recv_cq) {
                cq = container_of(init_attr->recv_cq, struct bnxt_re_cq, ib_cq);
-               if (!cq) {
-                       ibdev_err(&rdev->ibdev, "Receive CQ not found");
-                       rc = -EINVAL;
-                       goto out;
-               }
                qplqp->rcq = &cq->qplib_cq;
                qp->rcq = cq;
        }
@@ -1322,7 +1309,7 @@ out:
 static int bnxt_re_create_shadow_gsi(struct bnxt_re_qp *qp,
                                     struct bnxt_re_pd *pd)
 {
-       struct bnxt_re_sqp_entries *sqp_tbl = NULL;
+       struct bnxt_re_sqp_entries *sqp_tbl;
        struct bnxt_re_dev *rdev;
        struct bnxt_re_qp *sqp;
        struct bnxt_re_ah *sah;
@@ -1330,7 +1317,7 @@ static int bnxt_re_create_shadow_gsi(struct bnxt_re_qp *qp,
 
        rdev = qp->rdev;
        /* Create a shadow QP to handle the QP1 traffic */
-       sqp_tbl = kzalloc(sizeof(*sqp_tbl) * BNXT_RE_MAX_GSI_SQP_ENTRIES,
+       sqp_tbl = kcalloc(BNXT_RE_MAX_GSI_SQP_ENTRIES, sizeof(*sqp_tbl),
                          GFP_KERNEL);
        if (!sqp_tbl)
                return -ENOMEM;
@@ -1412,27 +1399,22 @@ static bool bnxt_re_test_qp_limits(struct bnxt_re_dev *rdev,
        return rc;
 }
 
-struct ib_qp *bnxt_re_create_qp(struct ib_pd *ib_pd,
-                               struct ib_qp_init_attr *qp_init_attr,
-                               struct ib_udata *udata)
+int bnxt_re_create_qp(struct ib_qp *ib_qp, struct ib_qp_init_attr *qp_init_attr,
+                     struct ib_udata *udata)
 {
+       struct ib_pd *ib_pd = ib_qp->pd;
        struct bnxt_re_pd *pd = container_of(ib_pd, struct bnxt_re_pd, ib_pd);
        struct bnxt_re_dev *rdev = pd->rdev;
        struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
-       struct bnxt_re_qp *qp;
+       struct bnxt_re_qp *qp = container_of(ib_qp, struct bnxt_re_qp, ib_qp);
        int rc;
 
        rc = bnxt_re_test_qp_limits(rdev, qp_init_attr, dev_attr);
        if (!rc) {
                rc = -EINVAL;
-               goto exit;
+               goto fail;
        }
 
-       qp = kzalloc(sizeof(*qp), GFP_KERNEL);
-       if (!qp) {
-               rc = -ENOMEM;
-               goto exit;
-       }
        qp->rdev = rdev;
        rc = bnxt_re_init_qp_attr(qp, pd, qp_init_attr, udata);
        if (rc)
@@ -1475,16 +1457,14 @@ struct ib_qp *bnxt_re_create_qp(struct ib_pd *ib_pd,
        mutex_unlock(&rdev->qp_lock);
        atomic_inc(&rdev->qp_count);
 
-       return &qp->ib_qp;
+       return 0;
 qp_destroy:
        bnxt_qplib_destroy_qp(&rdev->qplib_res, &qp->qplib_qp);
 free_umem:
        ib_umem_release(qp->rumem);
        ib_umem_release(qp->sumem);
 fail:
-       kfree(qp);
-exit:
-       return ERR_PTR(rc);
+       return rc;
 }
 
 static u8 __from_ib_qp_state(enum ib_qp_state state)
@@ -1691,6 +1671,7 @@ int bnxt_re_create_srq(struct ib_srq *ib_srq,
        if (nq)
                nq->budget++;
        atomic_inc(&rdev->srq_count);
+       spin_lock_init(&srq->lock);
 
        return 0;
 
@@ -3473,10 +3454,6 @@ int bnxt_re_poll_cq(struct ib_cq *ib_cq, int num_entries, struct ib_wc *wc)
                                ((struct bnxt_qplib_qp *)
                                 (unsigned long)(cqe->qp_handle),
                                 struct bnxt_re_qp, qplib_qp);
-                       if (!qp) {
-                               ibdev_err(&cq->rdev->ibdev, "POLL CQ : bad QP handle");
-                               continue;
-                       }
                        wc->qp = &qp->ib_qp;
                        wc->ex.imm_data = cqe->immdata;
                        wc->src_qp = cqe->src_qp;
@@ -3858,7 +3835,7 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
                container_of(ctx, struct bnxt_re_ucontext, ib_uctx);
        struct bnxt_re_dev *rdev = to_bnxt_re_dev(ibdev, ibdev);
        struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
-       struct bnxt_re_uctx_resp resp;
+       struct bnxt_re_uctx_resp resp = {};
        u32 chip_met_rev_num = 0;
        int rc;
 
@@ -3886,15 +3863,15 @@ int bnxt_re_alloc_ucontext(struct ib_ucontext *ctx, struct ib_udata *udata)
        chip_met_rev_num |= ((u32)rdev->chip_ctx->chip_metal & 0xFF) <<
                             BNXT_RE_CHIP_ID0_CHIP_MET_SFT;
        resp.chip_id0 = chip_met_rev_num;
-       /* Future extension of chip info */
-       resp.chip_id1 = 0;
        /*Temp, Use xa_alloc instead */
        resp.dev_id = rdev->en_dev->pdev->devfn;
        resp.max_qp = rdev->qplib_ctx.qpc_count;
        resp.pg_size = PAGE_SIZE;
        resp.cqe_sz = sizeof(struct cq_base);
        resp.max_cqd = dev_attr->max_cq_wqes;
-       resp.rsvd    = 0;
+
+       resp.comp_mask |= BNXT_RE_UCNTX_CMASK_HAVE_MODE;
+       resp.mode = rdev->chip_ctx->modes.wqe_mode;
 
        rc = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp)));
        if (rc) {