blob: d9ed5f24c3626e5d3442c5657a763c62a670fca3 [file] [log] [blame]
Tom Tucker377f9b22007-12-12 16:13:21 -06001/*
2 * Copyright (c) 2005-2007 Network Appliance, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the BSD-type
8 * license below:
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
21 *
22 * Neither the name of the Network Appliance, Inc. nor the names of
23 * its contributors may be used to endorse or promote products
24 * derived from this software without specific prior written
25 * permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 * Author: Tom Tucker <tom@opengridcomputing.com>
40 */
41
42#include <linux/sunrpc/svc_xprt.h>
43#include <linux/sunrpc/debug.h>
44#include <linux/sunrpc/rpc_rdma.h>
45#include <linux/spinlock.h>
46#include <rdma/ib_verbs.h>
47#include <rdma/rdma_cm.h>
48#include <linux/sunrpc/svc_rdma.h>
49
50#define RPCDBG_FACILITY RPCDBG_SVCXPRT
51
52static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
53 struct sockaddr *sa, int salen,
54 int flags);
55static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt);
56static void svc_rdma_release_rqst(struct svc_rqst *);
Tom Tucker377f9b22007-12-12 16:13:21 -060057static void dto_tasklet_func(unsigned long data);
58static void svc_rdma_detach(struct svc_xprt *xprt);
59static void svc_rdma_free(struct svc_xprt *xprt);
60static int svc_rdma_has_wspace(struct svc_xprt *xprt);
61static void rq_cq_reap(struct svcxprt_rdma *xprt);
62static void sq_cq_reap(struct svcxprt_rdma *xprt);
63
64DECLARE_TASKLET(dto_tasklet, dto_tasklet_func, 0UL);
65static DEFINE_SPINLOCK(dto_lock);
66static LIST_HEAD(dto_xprt_q);
67
68static struct svc_xprt_ops svc_rdma_ops = {
69 .xpo_create = svc_rdma_create,
70 .xpo_recvfrom = svc_rdma_recvfrom,
71 .xpo_sendto = svc_rdma_sendto,
72 .xpo_release_rqst = svc_rdma_release_rqst,
73 .xpo_detach = svc_rdma_detach,
74 .xpo_free = svc_rdma_free,
75 .xpo_prep_reply_hdr = svc_rdma_prep_reply_hdr,
76 .xpo_has_wspace = svc_rdma_has_wspace,
77 .xpo_accept = svc_rdma_accept,
78};
79
80struct svc_xprt_class svc_rdma_class = {
81 .xcl_name = "rdma",
82 .xcl_owner = THIS_MODULE,
83 .xcl_ops = &svc_rdma_ops,
84 .xcl_max_payload = RPCSVC_MAXPAYLOAD_TCP,
85};
86
87static int rdma_bump_context_cache(struct svcxprt_rdma *xprt)
88{
89 int target;
90 int at_least_one = 0;
91 struct svc_rdma_op_ctxt *ctxt;
92
93 target = min(xprt->sc_ctxt_cnt + xprt->sc_ctxt_bump,
94 xprt->sc_ctxt_max);
95
96 spin_lock_bh(&xprt->sc_ctxt_lock);
97 while (xprt->sc_ctxt_cnt < target) {
98 xprt->sc_ctxt_cnt++;
99 spin_unlock_bh(&xprt->sc_ctxt_lock);
100
101 ctxt = kmalloc(sizeof(*ctxt), GFP_KERNEL);
102
103 spin_lock_bh(&xprt->sc_ctxt_lock);
104 if (ctxt) {
105 at_least_one = 1;
106 ctxt->next = xprt->sc_ctxt_head;
107 xprt->sc_ctxt_head = ctxt;
108 } else {
109 /* kmalloc failed...give up for now */
110 xprt->sc_ctxt_cnt--;
111 break;
112 }
113 }
114 spin_unlock_bh(&xprt->sc_ctxt_lock);
115 dprintk("svcrdma: sc_ctxt_max=%d, sc_ctxt_cnt=%d\n",
116 xprt->sc_ctxt_max, xprt->sc_ctxt_cnt);
117 return at_least_one;
118}
119
120struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *xprt)
121{
122 struct svc_rdma_op_ctxt *ctxt;
123
124 while (1) {
125 spin_lock_bh(&xprt->sc_ctxt_lock);
126 if (unlikely(xprt->sc_ctxt_head == NULL)) {
127 /* Try to bump my cache. */
128 spin_unlock_bh(&xprt->sc_ctxt_lock);
129
130 if (rdma_bump_context_cache(xprt))
131 continue;
132
133 printk(KERN_INFO "svcrdma: sleeping waiting for "
134 "context memory on xprt=%p\n",
135 xprt);
136 schedule_timeout_uninterruptible(msecs_to_jiffies(500));
137 continue;
138 }
139 ctxt = xprt->sc_ctxt_head;
140 xprt->sc_ctxt_head = ctxt->next;
141 spin_unlock_bh(&xprt->sc_ctxt_lock);
142 ctxt->xprt = xprt;
143 INIT_LIST_HEAD(&ctxt->dto_q);
144 ctxt->count = 0;
145 break;
146 }
147 return ctxt;
148}
149
150void svc_rdma_put_context(struct svc_rdma_op_ctxt *ctxt, int free_pages)
151{
152 struct svcxprt_rdma *xprt;
153 int i;
154
155 BUG_ON(!ctxt);
156 xprt = ctxt->xprt;
157 if (free_pages)
158 for (i = 0; i < ctxt->count; i++)
159 put_page(ctxt->pages[i]);
160
161 for (i = 0; i < ctxt->count; i++)
162 dma_unmap_single(xprt->sc_cm_id->device->dma_device,
163 ctxt->sge[i].addr,
164 ctxt->sge[i].length,
165 ctxt->direction);
166 spin_lock_bh(&xprt->sc_ctxt_lock);
167 ctxt->next = xprt->sc_ctxt_head;
168 xprt->sc_ctxt_head = ctxt;
169 spin_unlock_bh(&xprt->sc_ctxt_lock);
170}
171
172/* ib_cq event handler */
173static void cq_event_handler(struct ib_event *event, void *context)
174{
175 struct svc_xprt *xprt = context;
176 dprintk("svcrdma: received CQ event id=%d, context=%p\n",
177 event->event, context);
178 set_bit(XPT_CLOSE, &xprt->xpt_flags);
179}
180
181/* QP event handler */
182static void qp_event_handler(struct ib_event *event, void *context)
183{
184 struct svc_xprt *xprt = context;
185
186 switch (event->event) {
187 /* These are considered benign events */
188 case IB_EVENT_PATH_MIG:
189 case IB_EVENT_COMM_EST:
190 case IB_EVENT_SQ_DRAINED:
191 case IB_EVENT_QP_LAST_WQE_REACHED:
192 dprintk("svcrdma: QP event %d received for QP=%p\n",
193 event->event, event->element.qp);
194 break;
195 /* These are considered fatal events */
196 case IB_EVENT_PATH_MIG_ERR:
197 case IB_EVENT_QP_FATAL:
198 case IB_EVENT_QP_REQ_ERR:
199 case IB_EVENT_QP_ACCESS_ERR:
200 case IB_EVENT_DEVICE_FATAL:
201 default:
202 dprintk("svcrdma: QP ERROR event %d received for QP=%p, "
203 "closing transport\n",
204 event->event, event->element.qp);
205 set_bit(XPT_CLOSE, &xprt->xpt_flags);
206 break;
207 }
208}
209
210/*
211 * Data Transfer Operation Tasklet
212 *
213 * Walks a list of transports with I/O pending, removing entries as
214 * they are added to the server's I/O pending list. Two bits indicate
215 * if SQ, RQ, or both have I/O pending. The dto_lock is an irqsave
216 * spinlock that serializes access to the transport list with the RQ
217 * and SQ interrupt handlers.
218 */
219static void dto_tasklet_func(unsigned long data)
220{
221 struct svcxprt_rdma *xprt;
222 unsigned long flags;
223
224 spin_lock_irqsave(&dto_lock, flags);
225 while (!list_empty(&dto_xprt_q)) {
226 xprt = list_entry(dto_xprt_q.next,
227 struct svcxprt_rdma, sc_dto_q);
228 list_del_init(&xprt->sc_dto_q);
229 spin_unlock_irqrestore(&dto_lock, flags);
230
Tom Tuckerdbcd00e2008-05-06 11:33:11 -0500231 rq_cq_reap(xprt);
232 sq_cq_reap(xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600233
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400234 svc_xprt_put(&xprt->sc_xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600235 spin_lock_irqsave(&dto_lock, flags);
236 }
237 spin_unlock_irqrestore(&dto_lock, flags);
238}
239
240/*
241 * Receive Queue Completion Handler
242 *
243 * Since an RQ completion handler is called on interrupt context, we
244 * need to defer the handling of the I/O to a tasklet
245 */
246static void rq_comp_handler(struct ib_cq *cq, void *cq_context)
247{
248 struct svcxprt_rdma *xprt = cq_context;
249 unsigned long flags;
250
251 /*
252 * Set the bit regardless of whether or not it's on the list
253 * because it may be on the list already due to an SQ
254 * completion.
255 */
256 set_bit(RDMAXPRT_RQ_PENDING, &xprt->sc_flags);
257
258 /*
259 * If this transport is not already on the DTO transport queue,
260 * add it
261 */
262 spin_lock_irqsave(&dto_lock, flags);
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400263 if (list_empty(&xprt->sc_dto_q)) {
264 svc_xprt_get(&xprt->sc_xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600265 list_add_tail(&xprt->sc_dto_q, &dto_xprt_q);
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400266 }
Tom Tucker377f9b22007-12-12 16:13:21 -0600267 spin_unlock_irqrestore(&dto_lock, flags);
268
269 /* Tasklet does all the work to avoid irqsave locks. */
270 tasklet_schedule(&dto_tasklet);
271}
272
273/*
274 * rq_cq_reap - Process the RQ CQ.
275 *
276 * Take all completing WC off the CQE and enqueue the associated DTO
277 * context on the dto_q for the transport.
278 */
279static void rq_cq_reap(struct svcxprt_rdma *xprt)
280{
281 int ret;
282 struct ib_wc wc;
283 struct svc_rdma_op_ctxt *ctxt = NULL;
284
Tom Tuckerdbcd00e2008-05-06 11:33:11 -0500285 if (!test_and_clear_bit(RDMAXPRT_RQ_PENDING, &xprt->sc_flags))
286 return;
287
288 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
Tom Tucker377f9b22007-12-12 16:13:21 -0600289 atomic_inc(&rdma_stat_rq_poll);
290
291 spin_lock_bh(&xprt->sc_rq_dto_lock);
292 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
293 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
294 ctxt->wc_status = wc.status;
295 ctxt->byte_len = wc.byte_len;
296 if (wc.status != IB_WC_SUCCESS) {
297 /* Close the transport */
298 set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
299 svc_rdma_put_context(ctxt, 1);
300 continue;
301 }
302 list_add_tail(&ctxt->dto_q, &xprt->sc_rq_dto_q);
303 }
304 spin_unlock_bh(&xprt->sc_rq_dto_lock);
305
306 if (ctxt)
307 atomic_inc(&rdma_stat_rq_prod);
Tom Tuckerdbcd00e2008-05-06 11:33:11 -0500308
309 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
310 /*
311 * If data arrived before established event,
312 * don't enqueue. This defers RPC I/O until the
313 * RDMA connection is complete.
314 */
315 if (!test_bit(RDMAXPRT_CONN_PENDING, &xprt->sc_flags))
316 svc_xprt_enqueue(&xprt->sc_xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600317}
318
319/*
320 * Send Queue Completion Handler - potentially called on interrupt context.
321 */
322static void sq_cq_reap(struct svcxprt_rdma *xprt)
323{
324 struct svc_rdma_op_ctxt *ctxt = NULL;
325 struct ib_wc wc;
326 struct ib_cq *cq = xprt->sc_sq_cq;
327 int ret;
328
Tom Tuckerdbcd00e2008-05-06 11:33:11 -0500329
330 if (!test_and_clear_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags))
331 return;
332
333 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
Tom Tucker377f9b22007-12-12 16:13:21 -0600334 atomic_inc(&rdma_stat_sq_poll);
335 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
336 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
337 xprt = ctxt->xprt;
338
339 if (wc.status != IB_WC_SUCCESS)
340 /* Close the transport */
341 set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
342
343 /* Decrement used SQ WR count */
344 atomic_dec(&xprt->sc_sq_count);
345 wake_up(&xprt->sc_send_wait);
346
347 switch (ctxt->wr_op) {
348 case IB_WR_SEND:
349 case IB_WR_RDMA_WRITE:
350 svc_rdma_put_context(ctxt, 1);
351 break;
352
353 case IB_WR_RDMA_READ:
354 if (test_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags)) {
355 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
356 set_bit(RDMACTXT_F_READ_DONE, &ctxt->flags);
357 spin_lock_bh(&xprt->sc_read_complete_lock);
358 list_add_tail(&ctxt->dto_q,
359 &xprt->sc_read_complete_q);
360 spin_unlock_bh(&xprt->sc_read_complete_lock);
361 svc_xprt_enqueue(&xprt->sc_xprt);
362 }
363 break;
364
365 default:
366 printk(KERN_ERR "svcrdma: unexpected completion type, "
367 "opcode=%d, status=%d\n",
368 wc.opcode, wc.status);
369 break;
370 }
371 }
372
373 if (ctxt)
374 atomic_inc(&rdma_stat_sq_prod);
375}
376
377static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
378{
379 struct svcxprt_rdma *xprt = cq_context;
380 unsigned long flags;
381
382 /*
383 * Set the bit regardless of whether or not it's on the list
384 * because it may be on the list already due to an RQ
385 * completion.
386 */
387 set_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags);
388
389 /*
390 * If this transport is not already on the DTO transport queue,
391 * add it
392 */
393 spin_lock_irqsave(&dto_lock, flags);
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400394 if (list_empty(&xprt->sc_dto_q)) {
395 svc_xprt_get(&xprt->sc_xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600396 list_add_tail(&xprt->sc_dto_q, &dto_xprt_q);
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400397 }
Tom Tucker377f9b22007-12-12 16:13:21 -0600398 spin_unlock_irqrestore(&dto_lock, flags);
399
400 /* Tasklet does all the work to avoid irqsave locks. */
401 tasklet_schedule(&dto_tasklet);
402}
403
404static void create_context_cache(struct svcxprt_rdma *xprt,
405 int ctxt_count, int ctxt_bump, int ctxt_max)
406{
407 struct svc_rdma_op_ctxt *ctxt;
408 int i;
409
410 xprt->sc_ctxt_max = ctxt_max;
411 xprt->sc_ctxt_bump = ctxt_bump;
412 xprt->sc_ctxt_cnt = 0;
413 xprt->sc_ctxt_head = NULL;
414 for (i = 0; i < ctxt_count; i++) {
415 ctxt = kmalloc(sizeof(*ctxt), GFP_KERNEL);
416 if (ctxt) {
417 ctxt->next = xprt->sc_ctxt_head;
418 xprt->sc_ctxt_head = ctxt;
419 xprt->sc_ctxt_cnt++;
420 }
421 }
422}
423
424static void destroy_context_cache(struct svc_rdma_op_ctxt *ctxt)
425{
426 struct svc_rdma_op_ctxt *next;
427 if (!ctxt)
428 return;
429
430 do {
431 next = ctxt->next;
432 kfree(ctxt);
433 ctxt = next;
434 } while (next);
435}
436
437static struct svcxprt_rdma *rdma_create_xprt(struct svc_serv *serv,
438 int listener)
439{
440 struct svcxprt_rdma *cma_xprt = kzalloc(sizeof *cma_xprt, GFP_KERNEL);
441
442 if (!cma_xprt)
443 return NULL;
444 svc_xprt_init(&svc_rdma_class, &cma_xprt->sc_xprt, serv);
445 INIT_LIST_HEAD(&cma_xprt->sc_accept_q);
446 INIT_LIST_HEAD(&cma_xprt->sc_dto_q);
447 INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
448 INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q);
449 init_waitqueue_head(&cma_xprt->sc_send_wait);
450
451 spin_lock_init(&cma_xprt->sc_lock);
452 spin_lock_init(&cma_xprt->sc_read_complete_lock);
453 spin_lock_init(&cma_xprt->sc_ctxt_lock);
454 spin_lock_init(&cma_xprt->sc_rq_dto_lock);
455
456 cma_xprt->sc_ord = svcrdma_ord;
457
458 cma_xprt->sc_max_req_size = svcrdma_max_req_size;
459 cma_xprt->sc_max_requests = svcrdma_max_requests;
460 cma_xprt->sc_sq_depth = svcrdma_max_requests * RPCRDMA_SQ_DEPTH_MULT;
461 atomic_set(&cma_xprt->sc_sq_count, 0);
462
463 if (!listener) {
464 int reqs = cma_xprt->sc_max_requests;
465 create_context_cache(cma_xprt,
466 reqs << 1, /* starting size */
467 reqs, /* bump amount */
468 reqs +
469 cma_xprt->sc_sq_depth +
470 RPCRDMA_MAX_THREADS + 1); /* max */
471 if (!cma_xprt->sc_ctxt_head) {
472 kfree(cma_xprt);
473 return NULL;
474 }
475 clear_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
476 } else
477 set_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
478
479 return cma_xprt;
480}
481
482struct page *svc_rdma_get_page(void)
483{
484 struct page *page;
485
486 while ((page = alloc_page(GFP_KERNEL)) == NULL) {
487 /* If we can't get memory, wait a bit and try again */
488 printk(KERN_INFO "svcrdma: out of memory...retrying in 1000 "
489 "jiffies.\n");
490 schedule_timeout_uninterruptible(msecs_to_jiffies(1000));
491 }
492 return page;
493}
494
495int svc_rdma_post_recv(struct svcxprt_rdma *xprt)
496{
497 struct ib_recv_wr recv_wr, *bad_recv_wr;
498 struct svc_rdma_op_ctxt *ctxt;
499 struct page *page;
500 unsigned long pa;
501 int sge_no;
502 int buflen;
503 int ret;
504
505 ctxt = svc_rdma_get_context(xprt);
506 buflen = 0;
507 ctxt->direction = DMA_FROM_DEVICE;
508 for (sge_no = 0; buflen < xprt->sc_max_req_size; sge_no++) {
509 BUG_ON(sge_no >= xprt->sc_max_sge);
510 page = svc_rdma_get_page();
511 ctxt->pages[sge_no] = page;
512 pa = ib_dma_map_page(xprt->sc_cm_id->device,
513 page, 0, PAGE_SIZE,
514 DMA_FROM_DEVICE);
515 ctxt->sge[sge_no].addr = pa;
516 ctxt->sge[sge_no].length = PAGE_SIZE;
517 ctxt->sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
518 buflen += PAGE_SIZE;
519 }
520 ctxt->count = sge_no;
521 recv_wr.next = NULL;
522 recv_wr.sg_list = &ctxt->sge[0];
523 recv_wr.num_sge = ctxt->count;
524 recv_wr.wr_id = (u64)(unsigned long)ctxt;
525
526 ret = ib_post_recv(xprt->sc_qp, &recv_wr, &bad_recv_wr);
Tom Tucker05a08262008-04-25 14:11:31 -0500527 if (ret)
528 svc_rdma_put_context(ctxt, 1);
Tom Tucker377f9b22007-12-12 16:13:21 -0600529 return ret;
530}
531
532/*
533 * This function handles the CONNECT_REQUEST event on a listening
534 * endpoint. It is passed the cma_id for the _new_ connection. The context in
535 * this cma_id is inherited from the listening cma_id and is the svc_xprt
536 * structure for the listening endpoint.
537 *
538 * This function creates a new xprt for the new connection and enqueues it on
539 * the accept queue for the listent xprt. When the listen thread is kicked, it
540 * will call the recvfrom method on the listen xprt which will accept the new
541 * connection.
542 */
543static void handle_connect_req(struct rdma_cm_id *new_cma_id)
544{
545 struct svcxprt_rdma *listen_xprt = new_cma_id->context;
546 struct svcxprt_rdma *newxprt;
547
548 /* Create a new transport */
549 newxprt = rdma_create_xprt(listen_xprt->sc_xprt.xpt_server, 0);
550 if (!newxprt) {
551 dprintk("svcrdma: failed to create new transport\n");
552 return;
553 }
554 newxprt->sc_cm_id = new_cma_id;
555 new_cma_id->context = newxprt;
556 dprintk("svcrdma: Creating newxprt=%p, cm_id=%p, listenxprt=%p\n",
557 newxprt, newxprt->sc_cm_id, listen_xprt);
558
559 /*
560 * Enqueue the new transport on the accept queue of the listening
561 * transport
562 */
563 spin_lock_bh(&listen_xprt->sc_lock);
564 list_add_tail(&newxprt->sc_accept_q, &listen_xprt->sc_accept_q);
565 spin_unlock_bh(&listen_xprt->sc_lock);
566
567 /*
568 * Can't use svc_xprt_received here because we are not on a
569 * rqstp thread
570 */
571 set_bit(XPT_CONN, &listen_xprt->sc_xprt.xpt_flags);
572 svc_xprt_enqueue(&listen_xprt->sc_xprt);
573}
574
575/*
576 * Handles events generated on the listening endpoint. These events will be
577 * either be incoming connect requests or adapter removal events.
578 */
579static int rdma_listen_handler(struct rdma_cm_id *cma_id,
580 struct rdma_cm_event *event)
581{
582 struct svcxprt_rdma *xprt = cma_id->context;
583 int ret = 0;
584
585 switch (event->event) {
586 case RDMA_CM_EVENT_CONNECT_REQUEST:
587 dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, "
588 "event=%d\n", cma_id, cma_id->context, event->event);
589 handle_connect_req(cma_id);
590 break;
591
592 case RDMA_CM_EVENT_ESTABLISHED:
593 /* Accept complete */
594 dprintk("svcrdma: Connection completed on LISTEN xprt=%p, "
595 "cm_id=%p\n", xprt, cma_id);
596 break;
597
598 case RDMA_CM_EVENT_DEVICE_REMOVAL:
599 dprintk("svcrdma: Device removal xprt=%p, cm_id=%p\n",
600 xprt, cma_id);
601 if (xprt)
602 set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
603 break;
604
605 default:
606 dprintk("svcrdma: Unexpected event on listening endpoint %p, "
607 "event=%d\n", cma_id, event->event);
608 break;
609 }
610
611 return ret;
612}
613
614static int rdma_cma_handler(struct rdma_cm_id *cma_id,
615 struct rdma_cm_event *event)
616{
617 struct svc_xprt *xprt = cma_id->context;
618 struct svcxprt_rdma *rdma =
619 container_of(xprt, struct svcxprt_rdma, sc_xprt);
620 switch (event->event) {
621 case RDMA_CM_EVENT_ESTABLISHED:
622 /* Accept complete */
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400623 svc_xprt_get(xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600624 dprintk("svcrdma: Connection completed on DTO xprt=%p, "
625 "cm_id=%p\n", xprt, cma_id);
626 clear_bit(RDMAXPRT_CONN_PENDING, &rdma->sc_flags);
627 svc_xprt_enqueue(xprt);
628 break;
629 case RDMA_CM_EVENT_DISCONNECTED:
630 dprintk("svcrdma: Disconnect on DTO xprt=%p, cm_id=%p\n",
631 xprt, cma_id);
632 if (xprt) {
633 set_bit(XPT_CLOSE, &xprt->xpt_flags);
634 svc_xprt_enqueue(xprt);
Tom Tucker120693d2008-04-24 14:17:21 -0500635 svc_xprt_put(xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600636 }
637 break;
638 case RDMA_CM_EVENT_DEVICE_REMOVAL:
639 dprintk("svcrdma: Device removal cma_id=%p, xprt = %p, "
640 "event=%d\n", cma_id, xprt, event->event);
641 if (xprt) {
642 set_bit(XPT_CLOSE, &xprt->xpt_flags);
643 svc_xprt_enqueue(xprt);
644 }
645 break;
646 default:
647 dprintk("svcrdma: Unexpected event on DTO endpoint %p, "
648 "event=%d\n", cma_id, event->event);
649 break;
650 }
651 return 0;
652}
653
654/*
655 * Create a listening RDMA service endpoint.
656 */
657static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
658 struct sockaddr *sa, int salen,
659 int flags)
660{
661 struct rdma_cm_id *listen_id;
662 struct svcxprt_rdma *cma_xprt;
663 struct svc_xprt *xprt;
664 int ret;
665
666 dprintk("svcrdma: Creating RDMA socket\n");
667
668 cma_xprt = rdma_create_xprt(serv, 1);
669 if (!cma_xprt)
Tom Tucker58e8f622008-05-06 09:45:54 -0500670 return ERR_PTR(-ENOMEM);
Tom Tucker377f9b22007-12-12 16:13:21 -0600671 xprt = &cma_xprt->sc_xprt;
672
673 listen_id = rdma_create_id(rdma_listen_handler, cma_xprt, RDMA_PS_TCP);
674 if (IS_ERR(listen_id)) {
Tom Tucker58e8f622008-05-06 09:45:54 -0500675 ret = PTR_ERR(listen_id);
676 dprintk("svcrdma: rdma_create_id failed = %d\n", ret);
677 goto err0;
Tom Tucker377f9b22007-12-12 16:13:21 -0600678 }
Tom Tucker58e8f622008-05-06 09:45:54 -0500679
Tom Tucker377f9b22007-12-12 16:13:21 -0600680 ret = rdma_bind_addr(listen_id, sa);
681 if (ret) {
Tom Tucker377f9b22007-12-12 16:13:21 -0600682 dprintk("svcrdma: rdma_bind_addr failed = %d\n", ret);
Tom Tucker58e8f622008-05-06 09:45:54 -0500683 goto err1;
Tom Tucker377f9b22007-12-12 16:13:21 -0600684 }
685 cma_xprt->sc_cm_id = listen_id;
686
687 ret = rdma_listen(listen_id, RPCRDMA_LISTEN_BACKLOG);
688 if (ret) {
Tom Tucker377f9b22007-12-12 16:13:21 -0600689 dprintk("svcrdma: rdma_listen failed = %d\n", ret);
Tom Tucker58e8f622008-05-06 09:45:54 -0500690 goto err1;
Tom Tucker377f9b22007-12-12 16:13:21 -0600691 }
692
693 /*
694 * We need to use the address from the cm_id in case the
695 * caller specified 0 for the port number.
696 */
697 sa = (struct sockaddr *)&cma_xprt->sc_cm_id->route.addr.src_addr;
698 svc_xprt_set_local(&cma_xprt->sc_xprt, sa, salen);
699
700 return &cma_xprt->sc_xprt;
Tom Tucker58e8f622008-05-06 09:45:54 -0500701
702 err1:
703 rdma_destroy_id(listen_id);
704 err0:
705 kfree(cma_xprt);
706 return ERR_PTR(ret);
Tom Tucker377f9b22007-12-12 16:13:21 -0600707}
708
709/*
710 * This is the xpo_recvfrom function for listening endpoints. Its
711 * purpose is to accept incoming connections. The CMA callback handler
712 * has already created a new transport and attached it to the new CMA
713 * ID.
714 *
715 * There is a queue of pending connections hung on the listening
716 * transport. This queue contains the new svc_xprt structure. This
717 * function takes svc_xprt structures off the accept_q and completes
718 * the connection.
719 */
720static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
721{
722 struct svcxprt_rdma *listen_rdma;
723 struct svcxprt_rdma *newxprt = NULL;
724 struct rdma_conn_param conn_param;
725 struct ib_qp_init_attr qp_attr;
726 struct ib_device_attr devattr;
727 struct sockaddr *sa;
728 int ret;
729 int i;
730
731 listen_rdma = container_of(xprt, struct svcxprt_rdma, sc_xprt);
732 clear_bit(XPT_CONN, &xprt->xpt_flags);
733 /* Get the next entry off the accept list */
734 spin_lock_bh(&listen_rdma->sc_lock);
735 if (!list_empty(&listen_rdma->sc_accept_q)) {
736 newxprt = list_entry(listen_rdma->sc_accept_q.next,
737 struct svcxprt_rdma, sc_accept_q);
738 list_del_init(&newxprt->sc_accept_q);
739 }
740 if (!list_empty(&listen_rdma->sc_accept_q))
741 set_bit(XPT_CONN, &listen_rdma->sc_xprt.xpt_flags);
742 spin_unlock_bh(&listen_rdma->sc_lock);
743 if (!newxprt)
744 return NULL;
745
746 dprintk("svcrdma: newxprt from accept queue = %p, cm_id=%p\n",
747 newxprt, newxprt->sc_cm_id);
748
749 ret = ib_query_device(newxprt->sc_cm_id->device, &devattr);
750 if (ret) {
751 dprintk("svcrdma: could not query device attributes on "
752 "device %p, rc=%d\n", newxprt->sc_cm_id->device, ret);
753 goto errout;
754 }
755
756 /* Qualify the transport resource defaults with the
757 * capabilities of this particular device */
758 newxprt->sc_max_sge = min((size_t)devattr.max_sge,
759 (size_t)RPCSVC_MAXPAGES);
760 newxprt->sc_max_requests = min((size_t)devattr.max_qp_wr,
761 (size_t)svcrdma_max_requests);
762 newxprt->sc_sq_depth = RPCRDMA_SQ_DEPTH_MULT * newxprt->sc_max_requests;
763
764 newxprt->sc_ord = min((size_t)devattr.max_qp_rd_atom,
765 (size_t)svcrdma_ord);
766
767 newxprt->sc_pd = ib_alloc_pd(newxprt->sc_cm_id->device);
768 if (IS_ERR(newxprt->sc_pd)) {
769 dprintk("svcrdma: error creating PD for connect request\n");
770 goto errout;
771 }
772 newxprt->sc_sq_cq = ib_create_cq(newxprt->sc_cm_id->device,
773 sq_comp_handler,
774 cq_event_handler,
775 newxprt,
776 newxprt->sc_sq_depth,
777 0);
778 if (IS_ERR(newxprt->sc_sq_cq)) {
779 dprintk("svcrdma: error creating SQ CQ for connect request\n");
780 goto errout;
781 }
782 newxprt->sc_rq_cq = ib_create_cq(newxprt->sc_cm_id->device,
783 rq_comp_handler,
784 cq_event_handler,
785 newxprt,
786 newxprt->sc_max_requests,
787 0);
788 if (IS_ERR(newxprt->sc_rq_cq)) {
789 dprintk("svcrdma: error creating RQ CQ for connect request\n");
790 goto errout;
791 }
792
793 memset(&qp_attr, 0, sizeof qp_attr);
794 qp_attr.event_handler = qp_event_handler;
795 qp_attr.qp_context = &newxprt->sc_xprt;
796 qp_attr.cap.max_send_wr = newxprt->sc_sq_depth;
797 qp_attr.cap.max_recv_wr = newxprt->sc_max_requests;
798 qp_attr.cap.max_send_sge = newxprt->sc_max_sge;
799 qp_attr.cap.max_recv_sge = newxprt->sc_max_sge;
800 qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
801 qp_attr.qp_type = IB_QPT_RC;
802 qp_attr.send_cq = newxprt->sc_sq_cq;
803 qp_attr.recv_cq = newxprt->sc_rq_cq;
804 dprintk("svcrdma: newxprt->sc_cm_id=%p, newxprt->sc_pd=%p\n"
805 " cm_id->device=%p, sc_pd->device=%p\n"
806 " cap.max_send_wr = %d\n"
807 " cap.max_recv_wr = %d\n"
808 " cap.max_send_sge = %d\n"
809 " cap.max_recv_sge = %d\n",
810 newxprt->sc_cm_id, newxprt->sc_pd,
811 newxprt->sc_cm_id->device, newxprt->sc_pd->device,
812 qp_attr.cap.max_send_wr,
813 qp_attr.cap.max_recv_wr,
814 qp_attr.cap.max_send_sge,
815 qp_attr.cap.max_recv_sge);
816
817 ret = rdma_create_qp(newxprt->sc_cm_id, newxprt->sc_pd, &qp_attr);
818 if (ret) {
819 /*
820 * XXX: This is a hack. We need a xx_request_qp interface
821 * that will adjust the qp_attr's with a best-effort
822 * number
823 */
824 qp_attr.cap.max_send_sge -= 2;
825 qp_attr.cap.max_recv_sge -= 2;
826 ret = rdma_create_qp(newxprt->sc_cm_id, newxprt->sc_pd,
827 &qp_attr);
828 if (ret) {
829 dprintk("svcrdma: failed to create QP, ret=%d\n", ret);
830 goto errout;
831 }
832 newxprt->sc_max_sge = qp_attr.cap.max_send_sge;
833 newxprt->sc_max_sge = qp_attr.cap.max_recv_sge;
834 newxprt->sc_sq_depth = qp_attr.cap.max_send_wr;
835 newxprt->sc_max_requests = qp_attr.cap.max_recv_wr;
836 }
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400837 svc_xprt_get(&newxprt->sc_xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600838 newxprt->sc_qp = newxprt->sc_cm_id->qp;
839
840 /* Register all of physical memory */
841 newxprt->sc_phys_mr = ib_get_dma_mr(newxprt->sc_pd,
842 IB_ACCESS_LOCAL_WRITE |
843 IB_ACCESS_REMOTE_WRITE);
844 if (IS_ERR(newxprt->sc_phys_mr)) {
845 dprintk("svcrdma: Failed to create DMA MR ret=%d\n", ret);
846 goto errout;
847 }
848
849 /* Post receive buffers */
850 for (i = 0; i < newxprt->sc_max_requests; i++) {
851 ret = svc_rdma_post_recv(newxprt);
852 if (ret) {
853 dprintk("svcrdma: failure posting receive buffers\n");
854 goto errout;
855 }
856 }
857
858 /* Swap out the handler */
859 newxprt->sc_cm_id->event_handler = rdma_cma_handler;
860
861 /* Accept Connection */
862 set_bit(RDMAXPRT_CONN_PENDING, &newxprt->sc_flags);
863 memset(&conn_param, 0, sizeof conn_param);
864 conn_param.responder_resources = 0;
865 conn_param.initiator_depth = newxprt->sc_ord;
866 ret = rdma_accept(newxprt->sc_cm_id, &conn_param);
867 if (ret) {
868 dprintk("svcrdma: failed to accept new connection, ret=%d\n",
869 ret);
870 goto errout;
871 }
872
873 dprintk("svcrdma: new connection %p accepted with the following "
874 "attributes:\n"
875 " local_ip : %d.%d.%d.%d\n"
876 " local_port : %d\n"
877 " remote_ip : %d.%d.%d.%d\n"
878 " remote_port : %d\n"
879 " max_sge : %d\n"
880 " sq_depth : %d\n"
881 " max_requests : %d\n"
882 " ord : %d\n",
883 newxprt,
884 NIPQUAD(((struct sockaddr_in *)&newxprt->sc_cm_id->
885 route.addr.src_addr)->sin_addr.s_addr),
886 ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id->
887 route.addr.src_addr)->sin_port),
888 NIPQUAD(((struct sockaddr_in *)&newxprt->sc_cm_id->
889 route.addr.dst_addr)->sin_addr.s_addr),
890 ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id->
891 route.addr.dst_addr)->sin_port),
892 newxprt->sc_max_sge,
893 newxprt->sc_sq_depth,
894 newxprt->sc_max_requests,
895 newxprt->sc_ord);
896
897 /* Set the local and remote addresses in the transport */
898 sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
899 svc_xprt_set_remote(&newxprt->sc_xprt, sa, svc_addr_len(sa));
900 sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
901 svc_xprt_set_local(&newxprt->sc_xprt, sa, svc_addr_len(sa));
902
903 ib_req_notify_cq(newxprt->sc_sq_cq, IB_CQ_NEXT_COMP);
904 ib_req_notify_cq(newxprt->sc_rq_cq, IB_CQ_NEXT_COMP);
905 return &newxprt->sc_xprt;
906
907 errout:
908 dprintk("svcrdma: failure accepting new connection rc=%d.\n", ret);
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400909 /* Take a reference in case the DTO handler runs */
910 svc_xprt_get(&newxprt->sc_xprt);
911 if (newxprt->sc_qp && !IS_ERR(newxprt->sc_qp)) {
912 ib_destroy_qp(newxprt->sc_qp);
913 svc_xprt_put(&newxprt->sc_xprt);
914 }
Tom Tucker377f9b22007-12-12 16:13:21 -0600915 rdma_destroy_id(newxprt->sc_cm_id);
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400916 /* This call to put will destroy the transport */
917 svc_xprt_put(&newxprt->sc_xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600918 return NULL;
919}
920
Tom Tucker377f9b22007-12-12 16:13:21 -0600921static void svc_rdma_release_rqst(struct svc_rqst *rqstp)
922{
Tom Tucker377f9b22007-12-12 16:13:21 -0600923}
924
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400925/*
926 * When connected, an svc_xprt has at least three references:
927 *
928 * - A reference held by the QP. We still hold that here because this
929 * code deletes the QP and puts the reference.
930 *
931 * - A reference held by the cm_id between the ESTABLISHED and
932 * DISCONNECTED events. If the remote peer disconnected first, this
933 * reference could be gone.
934 *
935 * - A reference held by the svc_recv code that called this function
936 * as part of close processing.
937 *
938 * At a minimum two references should still be held.
939 */
Tom Tucker377f9b22007-12-12 16:13:21 -0600940static void svc_rdma_detach(struct svc_xprt *xprt)
941{
942 struct svcxprt_rdma *rdma =
943 container_of(xprt, struct svcxprt_rdma, sc_xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600944 dprintk("svc: svc_rdma_detach(%p)\n", xprt);
Tom Tucker377f9b22007-12-12 16:13:21 -0600945
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400946 /* Disconnect and flush posted WQE */
947 rdma_disconnect(rdma->sc_cm_id);
948
949 /* Destroy the QP if present (not a listener) */
950 if (rdma->sc_qp && !IS_ERR(rdma->sc_qp)) {
951 ib_destroy_qp(rdma->sc_qp);
952 svc_xprt_put(xprt);
953 }
954
955 /* Destroy the CM ID */
956 rdma_destroy_id(rdma->sc_cm_id);
Tom Tucker377f9b22007-12-12 16:13:21 -0600957}
958
959static void svc_rdma_free(struct svc_xprt *xprt)
960{
961 struct svcxprt_rdma *rdma = (struct svcxprt_rdma *)xprt;
962 dprintk("svcrdma: svc_rdma_free(%p)\n", rdma);
Tom Tuckerc48cbb42008-03-11 14:31:39 -0400963 /* We should only be called from kref_put */
964 BUG_ON(atomic_read(&xprt->xpt_ref.refcount) != 0);
965 if (rdma->sc_sq_cq && !IS_ERR(rdma->sc_sq_cq))
966 ib_destroy_cq(rdma->sc_sq_cq);
967
968 if (rdma->sc_rq_cq && !IS_ERR(rdma->sc_rq_cq))
969 ib_destroy_cq(rdma->sc_rq_cq);
970
971 if (rdma->sc_phys_mr && !IS_ERR(rdma->sc_phys_mr))
972 ib_dereg_mr(rdma->sc_phys_mr);
973
974 if (rdma->sc_pd && !IS_ERR(rdma->sc_pd))
975 ib_dealloc_pd(rdma->sc_pd);
976
977 destroy_context_cache(rdma->sc_ctxt_head);
Tom Tucker377f9b22007-12-12 16:13:21 -0600978 kfree(rdma);
979}
980
Tom Tucker377f9b22007-12-12 16:13:21 -0600981static int svc_rdma_has_wspace(struct svc_xprt *xprt)
982{
983 struct svcxprt_rdma *rdma =
984 container_of(xprt, struct svcxprt_rdma, sc_xprt);
985
986 /*
987 * If there are fewer SQ WR available than required to send a
988 * simple response, return false.
989 */
990 if ((rdma->sc_sq_depth - atomic_read(&rdma->sc_sq_count) < 3))
991 return 0;
992
993 /*
994 * ...or there are already waiters on the SQ,
995 * return false.
996 */
997 if (waitqueue_active(&rdma->sc_send_wait))
998 return 0;
999
1000 /* Otherwise return true. */
1001 return 1;
1002}
1003
1004int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
1005{
1006 struct ib_send_wr *bad_wr;
1007 int ret;
1008
1009 if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags))
Tom Tucker9d6347a2008-04-25 15:51:27 -05001010 return -ENOTCONN;
Tom Tucker377f9b22007-12-12 16:13:21 -06001011
1012 BUG_ON(wr->send_flags != IB_SEND_SIGNALED);
1013 BUG_ON(((struct svc_rdma_op_ctxt *)(unsigned long)wr->wr_id)->wr_op !=
1014 wr->opcode);
1015 /* If the SQ is full, wait until an SQ entry is available */
1016 while (1) {
1017 spin_lock_bh(&xprt->sc_lock);
1018 if (xprt->sc_sq_depth == atomic_read(&xprt->sc_sq_count)) {
1019 spin_unlock_bh(&xprt->sc_lock);
1020 atomic_inc(&rdma_stat_sq_starve);
Tom Tuckerdbcd00e2008-05-06 11:33:11 -05001021
1022 /* See if we can opportunistically reap SQ WR to make room */
Tom Tucker377f9b22007-12-12 16:13:21 -06001023 sq_cq_reap(xprt);
1024
1025 /* Wait until SQ WR available if SQ still full */
1026 wait_event(xprt->sc_send_wait,
1027 atomic_read(&xprt->sc_sq_count) <
1028 xprt->sc_sq_depth);
Tom Tucker830bb592008-03-11 12:44:27 -05001029 if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags))
1030 return 0;
Tom Tucker377f9b22007-12-12 16:13:21 -06001031 continue;
1032 }
1033 /* Bumped used SQ WR count and post */
1034 ret = ib_post_send(xprt->sc_qp, wr, &bad_wr);
1035 if (!ret)
1036 atomic_inc(&xprt->sc_sq_count);
1037 else
1038 dprintk("svcrdma: failed to post SQ WR rc=%d, "
1039 "sc_sq_count=%d, sc_sq_depth=%d\n",
1040 ret, atomic_read(&xprt->sc_sq_count),
1041 xprt->sc_sq_depth);
1042 spin_unlock_bh(&xprt->sc_lock);
1043 break;
1044 }
1045 return ret;
1046}
1047
1048int svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp,
1049 enum rpcrdma_errcode err)
1050{
1051 struct ib_send_wr err_wr;
1052 struct ib_sge sge;
1053 struct page *p;
1054 struct svc_rdma_op_ctxt *ctxt;
1055 u32 *va;
1056 int length;
1057 int ret;
1058
1059 p = svc_rdma_get_page();
1060 va = page_address(p);
1061
1062 /* XDR encode error */
1063 length = svc_rdma_xdr_encode_error(xprt, rmsgp, err, va);
1064
1065 /* Prepare SGE for local address */
1066 sge.addr = ib_dma_map_page(xprt->sc_cm_id->device,
1067 p, 0, PAGE_SIZE, DMA_FROM_DEVICE);
1068 sge.lkey = xprt->sc_phys_mr->lkey;
1069 sge.length = length;
1070
1071 ctxt = svc_rdma_get_context(xprt);
1072 ctxt->count = 1;
1073 ctxt->pages[0] = p;
1074
1075 /* Prepare SEND WR */
1076 memset(&err_wr, 0, sizeof err_wr);
1077 ctxt->wr_op = IB_WR_SEND;
1078 err_wr.wr_id = (unsigned long)ctxt;
1079 err_wr.sg_list = &sge;
1080 err_wr.num_sge = 1;
1081 err_wr.opcode = IB_WR_SEND;
1082 err_wr.send_flags = IB_SEND_SIGNALED;
1083
1084 /* Post It */
1085 ret = svc_rdma_send(xprt, &err_wr);
1086 if (ret) {
1087 dprintk("svcrdma: Error posting send = %d\n", ret);
1088 svc_rdma_put_context(ctxt, 1);
1089 }
1090
1091 return ret;
1092}