Skip to content

Commit 7cf20fc

Browse files
Christoph Hellwigdledford
authored andcommitted
net/9p: convert to new CQ API
Trivial conversion to the new RDMA CQ API. Signed-off-by: Christoph Hellwig <[email protected]> Acked-by: Dominique Martinet <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent fc77dbd commit 7cf20fc

File tree

1 file changed

+31
-55
lines changed

1 file changed

+31
-55
lines changed

net/9p/trans_rdma.c

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,13 @@ struct p9_trans_rdma {
109109
/**
110110
* p9_rdma_context - Keeps track of in-process WR
111111
*
112-
* @wc_op: The original WR op for when the CQE completes in error.
113112
* @busa: Bus address to unmap when the WR completes
114113
* @req: Keeps track of requests (send)
115114
* @rc: Keepts track of replies (receive)
116115
*/
117116
struct p9_rdma_req;
118117
struct p9_rdma_context {
119-
enum ib_wc_opcode wc_op;
118+
struct ib_cqe cqe;
120119
dma_addr_t busa;
121120
union {
122121
struct p9_req_t *req;
@@ -284,9 +283,12 @@ p9_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
284283
}
285284

286285
static void
287-
handle_recv(struct p9_client *client, struct p9_trans_rdma *rdma,
288-
struct p9_rdma_context *c, enum ib_wc_status status, u32 byte_len)
286+
recv_done(struct ib_cq *cq, struct ib_wc *wc)
289287
{
288+
struct p9_client *client = cq->cq_context;
289+
struct p9_trans_rdma *rdma = client->trans;
290+
struct p9_rdma_context *c =
291+
container_of(wc->wr_cqe, struct p9_rdma_context, cqe);
290292
struct p9_req_t *req;
291293
int err = 0;
292294
int16_t tag;
@@ -295,7 +297,7 @@ handle_recv(struct p9_client *client, struct p9_trans_rdma *rdma,
295297
ib_dma_unmap_single(rdma->cm_id->device, c->busa, client->msize,
296298
DMA_FROM_DEVICE);
297299

298-
if (status != IB_WC_SUCCESS)
300+
if (wc->status != IB_WC_SUCCESS)
299301
goto err_out;
300302

301303
err = p9_parse_header(c->rc, NULL, NULL, &tag, 1);
@@ -316,21 +318,32 @@ handle_recv(struct p9_client *client, struct p9_trans_rdma *rdma,
316318
req->rc = c->rc;
317319
p9_client_cb(client, req, REQ_STATUS_RCVD);
318320

321+
out:
322+
up(&rdma->rq_sem);
323+
kfree(c);
319324
return;
320325

321326
err_out:
322-
p9_debug(P9_DEBUG_ERROR, "req %p err %d status %d\n", req, err, status);
327+
p9_debug(P9_DEBUG_ERROR, "req %p err %d status %d\n",
328+
req, err, wc->status);
323329
rdma->state = P9_RDMA_FLUSHING;
324330
client->status = Disconnected;
331+
goto out;
325332
}
326333

327334
static void
328-
handle_send(struct p9_client *client, struct p9_trans_rdma *rdma,
329-
struct p9_rdma_context *c, enum ib_wc_status status, u32 byte_len)
335+
send_done(struct ib_cq *cq, struct ib_wc *wc)
330336
{
337+
struct p9_client *client = cq->cq_context;
338+
struct p9_trans_rdma *rdma = client->trans;
339+
struct p9_rdma_context *c =
340+
container_of(wc->wr_cqe, struct p9_rdma_context, cqe);
341+
331342
ib_dma_unmap_single(rdma->cm_id->device,
332343
c->busa, c->req->tc->size,
333344
DMA_TO_DEVICE);
345+
up(&rdma->sq_sem);
346+
kfree(c);
334347
}
335348

336349
static void qp_event_handler(struct ib_event *event, void *context)
@@ -339,42 +352,6 @@ static void qp_event_handler(struct ib_event *event, void *context)
339352
event->event, context);
340353
}
341354

342-
static void cq_comp_handler(struct ib_cq *cq, void *cq_context)
343-
{
344-
struct p9_client *client = cq_context;
345-
struct p9_trans_rdma *rdma = client->trans;
346-
int ret;
347-
struct ib_wc wc;
348-
349-
ib_req_notify_cq(rdma->cq, IB_CQ_NEXT_COMP);
350-
while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
351-
struct p9_rdma_context *c = (void *) (unsigned long) wc.wr_id;
352-
353-
switch (c->wc_op) {
354-
case IB_WC_RECV:
355-
handle_recv(client, rdma, c, wc.status, wc.byte_len);
356-
up(&rdma->rq_sem);
357-
break;
358-
359-
case IB_WC_SEND:
360-
handle_send(client, rdma, c, wc.status, wc.byte_len);
361-
up(&rdma->sq_sem);
362-
break;
363-
364-
default:
365-
pr_err("unexpected completion type, c->wc_op=%d, wc.opcode=%d, status=%d\n",
366-
c->wc_op, wc.opcode, wc.status);
367-
break;
368-
}
369-
kfree(c);
370-
}
371-
}
372-
373-
static void cq_event_handler(struct ib_event *e, void *v)
374-
{
375-
p9_debug(P9_DEBUG_ERROR, "CQ event %d context %p\n", e->event, v);
376-
}
377-
378355
static void rdma_destroy_trans(struct p9_trans_rdma *rdma)
379356
{
380357
if (!rdma)
@@ -387,7 +364,7 @@ static void rdma_destroy_trans(struct p9_trans_rdma *rdma)
387364
ib_dealloc_pd(rdma->pd);
388365

389366
if (rdma->cq && !IS_ERR(rdma->cq))
390-
ib_destroy_cq(rdma->cq);
367+
ib_free_cq(rdma->cq);
391368

392369
if (rdma->cm_id && !IS_ERR(rdma->cm_id))
393370
rdma_destroy_id(rdma->cm_id);
@@ -408,13 +385,14 @@ post_recv(struct p9_client *client, struct p9_rdma_context *c)
408385
if (ib_dma_mapping_error(rdma->cm_id->device, c->busa))
409386
goto error;
410387

388+
c->cqe.done = recv_done;
389+
411390
sge.addr = c->busa;
412391
sge.length = client->msize;
413392
sge.lkey = rdma->pd->local_dma_lkey;
414393

415394
wr.next = NULL;
416-
c->wc_op = IB_WC_RECV;
417-
wr.wr_id = (unsigned long) c;
395+
wr.wr_cqe = &c->cqe;
418396
wr.sg_list = &sge;
419397
wr.num_sge = 1;
420398
return ib_post_recv(rdma->qp, &wr, &bad_wr);
@@ -499,13 +477,14 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
499477
goto send_error;
500478
}
501479

480+
c->cqe.done = send_done;
481+
502482
sge.addr = c->busa;
503483
sge.length = c->req->tc->size;
504484
sge.lkey = rdma->pd->local_dma_lkey;
505485

506486
wr.next = NULL;
507-
c->wc_op = IB_WC_SEND;
508-
wr.wr_id = (unsigned long) c;
487+
wr.wr_cqe = &c->cqe;
509488
wr.opcode = IB_WR_SEND;
510489
wr.send_flags = IB_SEND_SIGNALED;
511490
wr.sg_list = &sge;
@@ -642,7 +621,6 @@ rdma_create_trans(struct p9_client *client, const char *addr, char *args)
642621
struct p9_trans_rdma *rdma;
643622
struct rdma_conn_param conn_param;
644623
struct ib_qp_init_attr qp_attr;
645-
struct ib_cq_init_attr cq_attr = {};
646624

647625
/* Parse the transport specific mount options */
648626
err = parse_opts(args, &opts);
@@ -695,13 +673,11 @@ rdma_create_trans(struct p9_client *client, const char *addr, char *args)
695673
goto error;
696674

697675
/* Create the Completion Queue */
698-
cq_attr.cqe = opts.sq_depth + opts.rq_depth + 1;
699-
rdma->cq = ib_create_cq(rdma->cm_id->device, cq_comp_handler,
700-
cq_event_handler, client,
701-
&cq_attr);
676+
rdma->cq = ib_alloc_cq(rdma->cm_id->device, client,
677+
opts.sq_depth + opts.rq_depth + 1,
678+
0, IB_POLL_SOFTIRQ);
702679
if (IS_ERR(rdma->cq))
703680
goto error;
704-
ib_req_notify_cq(rdma->cq, IB_CQ_NEXT_COMP);
705681

706682
/* Create the Protection Domain */
707683
rdma->pd = ib_alloc_pd(rdma->cm_id->device);

0 commit comments

Comments
 (0)