Skip to content

Commit 3e41105

Browse files
Konstantin Taranovrleon
authored andcommitted
RDMA/mana_ib: introduce a helper to remove cq callbacks
Intoduce the mana_ib_remove_cq_cb helper to remove cq callbacks. The helper removes code duplicates. Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com> Link: https://lore.kernel.org/r/1714137160-5222-4-git-send-email-kotaranov@linux.microsoft.com Reviewed-by: Long Li <longli@microsoft.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 5843415 commit 3e41105

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

drivers/infiniband/hw/mana/cq.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,10 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
4848
struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq);
4949
struct ib_device *ibdev = ibcq->device;
5050
struct mana_ib_dev *mdev;
51-
struct gdma_context *gc;
5251

5352
mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
54-
gc = mdev_to_gc(mdev);
55-
56-
if (cq->queue.id != INVALID_QUEUE_ID) {
57-
kfree(gc->cq_table[cq->queue.id]);
58-
gc->cq_table[cq->queue.id] = NULL;
59-
}
6053

54+
mana_ib_remove_cq_cb(mdev, cq);
6155
mana_ib_destroy_queue(mdev, &cq->queue);
6256

6357
return 0;
@@ -89,3 +83,14 @@ int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq)
8983
gc->cq_table[cq->queue.id] = gdma_cq;
9084
return 0;
9185
}
86+
87+
void mana_ib_remove_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq)
88+
{
89+
struct gdma_context *gc = mdev_to_gc(mdev);
90+
91+
if (cq->queue.id >= gc->max_num_cqs || cq->queue.id == INVALID_QUEUE_ID)
92+
return;
93+
94+
kfree(gc->cq_table[cq->queue.id]);
95+
gc->cq_table[cq->queue.id] = NULL;
96+
}

drivers/infiniband/hw/mana/mana_ib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static inline void copy_in_reverse(u8 *dst, const u8 *src, u32 size)
255255
}
256256

257257
int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq);
258+
void mana_ib_remove_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq);
258259

259260
int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
260261
mana_handle_t *gdma_region);

drivers/infiniband/hw/mana/qp.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd,
9595
struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp);
9696
struct mana_ib_dev *mdev =
9797
container_of(pd->device, struct mana_ib_dev, ib_dev);
98-
struct gdma_context *gc = mdev_to_gc(mdev);
9998
struct ib_rwq_ind_table *ind_tbl = attr->rwq_ind_tbl;
10099
struct mana_ib_create_qp_rss_resp resp = {};
101100
struct mana_ib_create_qp_rss ucmd = {};
102-
struct gdma_queue **gdma_cq_allocated;
103101
mana_handle_t *mana_ind_table;
104102
struct mana_port_context *mpc;
105103
unsigned int ind_tbl_size;
@@ -173,13 +171,6 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd,
173171
goto fail;
174172
}
175173

176-
gdma_cq_allocated = kcalloc(ind_tbl_size, sizeof(*gdma_cq_allocated),
177-
GFP_KERNEL);
178-
if (!gdma_cq_allocated) {
179-
ret = -ENOMEM;
180-
goto fail;
181-
}
182-
183174
qp->port = port;
184175

185176
for (i = 0; i < ind_tbl_size; i++) {
@@ -229,8 +220,6 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd,
229220
ret = mana_ib_install_cq_cb(mdev, cq);
230221
if (ret)
231222
goto fail;
232-
233-
gdma_cq_allocated[i] = gc->cq_table[cq->queue.id];
234223
}
235224
resp.num_entries = i;
236225

@@ -250,7 +239,6 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd,
250239
goto fail;
251240
}
252241

253-
kfree(gdma_cq_allocated);
254242
kfree(mana_ind_table);
255243

256244
return 0;
@@ -262,13 +250,10 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd,
262250
wq = container_of(ibwq, struct mana_ib_wq, ibwq);
263251
cq = container_of(ibcq, struct mana_ib_cq, ibcq);
264252

265-
gc->cq_table[cq->queue.id] = NULL;
266-
kfree(gdma_cq_allocated[i]);
267-
253+
mana_ib_remove_cq_cb(mdev, cq);
268254
mana_destroy_wq_obj(mpc, GDMA_RQ, wq->rx_object);
269255
}
270256

271-
kfree(gdma_cq_allocated);
272257
kfree(mana_ind_table);
273258

274259
return ret;
@@ -287,10 +272,8 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd,
287272
struct mana_ib_ucontext *mana_ucontext =
288273
rdma_udata_to_drv_context(udata, struct mana_ib_ucontext,
289274
ibucontext);
290-
struct gdma_context *gc = mdev_to_gc(mdev);
291275
struct mana_ib_create_qp_resp resp = {};
292276
struct mana_ib_create_qp ucmd = {};
293-
struct gdma_queue *gdma_cq = NULL;
294277
struct mana_obj_spec wq_spec = {};
295278
struct mana_obj_spec cq_spec = {};
296279
struct mana_port_context *mpc;
@@ -395,14 +378,13 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd,
395378
ibdev_dbg(&mdev->ib_dev,
396379
"Failed copy udata for create qp-raw, %d\n",
397380
err);
398-
goto err_release_gdma_cq;
381+
goto err_remove_cq_cb;
399382
}
400383

401384
return 0;
402385

403-
err_release_gdma_cq:
404-
kfree(gdma_cq);
405-
gc->cq_table[send_cq->queue.id] = NULL;
386+
err_remove_cq_cb:
387+
mana_ib_remove_cq_cb(mdev, send_cq);
406388

407389
err_destroy_wq_obj:
408390
mana_destroy_wq_obj(mpc, GDMA_SQ, qp->qp_handle);

0 commit comments

Comments
 (0)