RDMA/mana_ib: Introduce mana_ib_install_cq_cb helper function
authorKonstantin Taranov <kotaranov@microsoft.com>
Mon, 22 Jan 2024 23:23:01 +0000 (15:23 -0800)
committerLeon Romanovsky <leon@kernel.org>
Thu, 25 Jan 2024 10:03:14 +0000 (12:03 +0200)
Use a helper function to install callbacks to CQs.
This patch removes code repetition.

Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
Link: https://lore.kernel.org/r/1705965781-3235-4-git-send-email-kotaranov@linux.microsoft.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/mana/cq.c
drivers/infiniband/hw/mana/mana_ib.h
drivers/infiniband/hw/mana/qp.c

index 3369e7b665f9f8620a20cd50519f783d1a0b64b6..83d20c3f048dfe6935f5c51466d3e1ca93698b10 100644 (file)
@@ -100,10 +100,29 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
        return 0;
 }
 
-void mana_ib_cq_handler(void *ctx, struct gdma_queue *gdma_cq)
+static void mana_ib_cq_handler(void *ctx, struct gdma_queue *gdma_cq)
 {
        struct mana_ib_cq *cq = ctx;
 
        if (cq->ibcq.comp_handler)
                cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context);
 }
+
+int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq)
+{
+       struct gdma_context *gc = mdev_to_gc(mdev);
+       struct gdma_queue *gdma_cq;
+
+       /* Create CQ table entry */
+       WARN_ON(gc->cq_table[cq->id]);
+       gdma_cq = kzalloc(sizeof(*gdma_cq), GFP_KERNEL);
+       if (!gdma_cq)
+               return -ENOMEM;
+
+       gdma_cq->cq.context = cq;
+       gdma_cq->type = GDMA_CQ;
+       gdma_cq->cq.callback = mana_ib_cq_handler;
+       gdma_cq->id = cq->id;
+       gc->cq_table[cq->id] = gdma_cq;
+       return 0;
+}
index d373639e25d4a12a08dba2aa6c0176f39fb13e21..6a03ae645c012db0c03c78e847825e47fad82530 100644 (file)
@@ -158,6 +158,8 @@ static inline struct net_device *mana_ib_get_netdev(struct ib_device *ibdev, u32
        return mc->ports[port - 1];
 }
 
+int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq);
+
 int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
                                 mana_handle_t *gdma_region);
 
@@ -226,6 +228,4 @@ int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index,
 void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext);
 
 int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *mdev);
-
-void mana_ib_cq_handler(void *ctx, struct gdma_queue *gdma_cq);
 #endif
index f5427599e0336ab0abd9285c2c25d1833f15ead8..5d4c05dcd0032f054958f20c790bcc501410eef5 100644 (file)
@@ -104,7 +104,6 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd,
        struct gdma_queue **gdma_cq_allocated;
        mana_handle_t *mana_ind_table;
        struct mana_port_context *mpc;
-       struct gdma_queue *gdma_cq;
        unsigned int ind_tbl_size;
        struct net_device *ndev;
        struct mana_ib_cq *cq;
@@ -229,19 +228,11 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd,
                mana_ind_table[i] = wq->rx_object;
 
                /* Create CQ table entry */
-               WARN_ON(gc->cq_table[cq->id]);
-               gdma_cq = kzalloc(sizeof(*gdma_cq), GFP_KERNEL);
-               if (!gdma_cq) {
-                       ret = -ENOMEM;
+               ret = mana_ib_install_cq_cb(mdev, cq);
+               if (ret)
                        goto fail;
-               }
-               gdma_cq_allocated[i] = gdma_cq;
 
-               gdma_cq->cq.context = cq;
-               gdma_cq->type = GDMA_CQ;
-               gdma_cq->cq.callback = mana_ib_cq_handler;
-               gdma_cq->id = cq->id;
-               gc->cq_table[cq->id] = gdma_cq;
+               gdma_cq_allocated[i] = gc->cq_table[cq->id];
        }
        resp.num_entries = i;
 
@@ -407,18 +398,9 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd,
        send_cq->id = cq_spec.queue_index;
 
        /* Create CQ table entry */
-       WARN_ON(gc->cq_table[send_cq->id]);
-       gdma_cq = kzalloc(sizeof(*gdma_cq), GFP_KERNEL);
-       if (!gdma_cq) {
-               err = -ENOMEM;
+       err = mana_ib_install_cq_cb(mdev, send_cq);
+       if (err)
                goto err_destroy_wq_obj;
-       }
-
-       gdma_cq->cq.context = send_cq;
-       gdma_cq->type = GDMA_CQ;
-       gdma_cq->cq.callback = mana_ib_cq_handler;
-       gdma_cq->id = send_cq->id;
-       gc->cq_table[send_cq->id] = gdma_cq;
 
        ibdev_dbg(&mdev->ib_dev,
                  "ret %d qp->tx_object 0x%llx sq id %llu cq id %llu\n", err,