2 * Copyright (c) 2014 Open Grid Computing, Inc. All rights reserved.
3 * Copyright (c) 2005-2007 Network Appliance, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the BSD-type
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
15 * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials provided
21 * with the distribution.
23 * Neither the name of the Network Appliance, Inc. nor the names of
24 * its contributors may be used to endorse or promote products
25 * derived from this software without specific prior written
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * Author: Tom Tucker <tom@opengridcomputing.com>
43 #include <linux/sunrpc/svc_xprt.h>
44 #include <linux/sunrpc/debug.h>
45 #include <linux/sunrpc/rpc_rdma.h>
46 #include <linux/interrupt.h>
47 #include <linux/sched.h>
48 #include <linux/slab.h>
49 #include <linux/spinlock.h>
50 #include <linux/workqueue.h>
51 #include <rdma/ib_verbs.h>
52 #include <rdma/rdma_cm.h>
53 #include <linux/sunrpc/svc_rdma.h>
54 #include <linux/export.h>
55 #include "xprt_rdma.h"
57 #define RPCDBG_FACILITY RPCDBG_SVCXPRT
59 static struct svc_xprt
*svc_rdma_create(struct svc_serv
*serv
,
61 struct sockaddr
*sa
, int salen
,
63 static struct svc_xprt
*svc_rdma_accept(struct svc_xprt
*xprt
);
64 static void svc_rdma_release_rqst(struct svc_rqst
*);
65 static void dto_tasklet_func(unsigned long data
);
66 static void svc_rdma_detach(struct svc_xprt
*xprt
);
67 static void svc_rdma_free(struct svc_xprt
*xprt
);
68 static int svc_rdma_has_wspace(struct svc_xprt
*xprt
);
69 static int svc_rdma_secure_port(struct svc_rqst
*);
70 static void rq_cq_reap(struct svcxprt_rdma
*xprt
);
71 static void sq_cq_reap(struct svcxprt_rdma
*xprt
);
73 static DECLARE_TASKLET(dto_tasklet
, dto_tasklet_func
, 0UL);
74 static DEFINE_SPINLOCK(dto_lock
);
75 static LIST_HEAD(dto_xprt_q
);
77 static struct svc_xprt_ops svc_rdma_ops
= {
78 .xpo_create
= svc_rdma_create
,
79 .xpo_recvfrom
= svc_rdma_recvfrom
,
80 .xpo_sendto
= svc_rdma_sendto
,
81 .xpo_release_rqst
= svc_rdma_release_rqst
,
82 .xpo_detach
= svc_rdma_detach
,
83 .xpo_free
= svc_rdma_free
,
84 .xpo_prep_reply_hdr
= svc_rdma_prep_reply_hdr
,
85 .xpo_has_wspace
= svc_rdma_has_wspace
,
86 .xpo_accept
= svc_rdma_accept
,
87 .xpo_secure_port
= svc_rdma_secure_port
,
90 struct svc_xprt_class svc_rdma_class
= {
92 .xcl_owner
= THIS_MODULE
,
93 .xcl_ops
= &svc_rdma_ops
,
94 .xcl_max_payload
= RPCSVC_MAXPAYLOAD_RDMA
,
95 .xcl_ident
= XPRT_TRANSPORT_RDMA
,
98 struct svc_rdma_op_ctxt
*svc_rdma_get_context(struct svcxprt_rdma
*xprt
)
100 struct svc_rdma_op_ctxt
*ctxt
;
102 ctxt
= kmem_cache_alloc(svc_rdma_ctxt_cachep
,
103 GFP_KERNEL
| __GFP_NOFAIL
);
105 INIT_LIST_HEAD(&ctxt
->dto_q
);
108 atomic_inc(&xprt
->sc_ctxt_used
);
112 void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt
*ctxt
)
114 struct svcxprt_rdma
*xprt
= ctxt
->xprt
;
116 for (i
= 0; i
< ctxt
->count
&& ctxt
->sge
[i
].length
; i
++) {
118 * Unmap the DMA addr in the SGE if the lkey matches
119 * the sc_dma_lkey, otherwise, ignore it since it is
120 * an FRMR lkey and will be unmapped later when the
121 * last WR that uses it completes.
123 if (ctxt
->sge
[i
].lkey
== xprt
->sc_dma_lkey
) {
124 atomic_dec(&xprt
->sc_dma_used
);
125 ib_dma_unmap_page(xprt
->sc_cm_id
->device
,
133 void svc_rdma_put_context(struct svc_rdma_op_ctxt
*ctxt
, int free_pages
)
135 struct svcxprt_rdma
*xprt
;
140 for (i
= 0; i
< ctxt
->count
; i
++)
141 put_page(ctxt
->pages
[i
]);
143 kmem_cache_free(svc_rdma_ctxt_cachep
, ctxt
);
144 atomic_dec(&xprt
->sc_ctxt_used
);
148 * Temporary NFS req mappings are shared across all transport
149 * instances. These are short lived and should be bounded by the number
150 * of concurrent server threads * depth of the SQ.
152 struct svc_rdma_req_map
*svc_rdma_get_req_map(void)
154 struct svc_rdma_req_map
*map
;
155 map
= kmem_cache_alloc(svc_rdma_map_cachep
,
156 GFP_KERNEL
| __GFP_NOFAIL
);
161 void svc_rdma_put_req_map(struct svc_rdma_req_map
*map
)
163 kmem_cache_free(svc_rdma_map_cachep
, map
);
166 /* ib_cq event handler */
167 static void cq_event_handler(struct ib_event
*event
, void *context
)
169 struct svc_xprt
*xprt
= context
;
170 dprintk("svcrdma: received CQ event %s (%d), context=%p\n",
171 ib_event_msg(event
->event
), event
->event
, context
);
172 set_bit(XPT_CLOSE
, &xprt
->xpt_flags
);
175 /* QP event handler */
176 static void qp_event_handler(struct ib_event
*event
, void *context
)
178 struct svc_xprt
*xprt
= context
;
180 switch (event
->event
) {
181 /* These are considered benign events */
182 case IB_EVENT_PATH_MIG
:
183 case IB_EVENT_COMM_EST
:
184 case IB_EVENT_SQ_DRAINED
:
185 case IB_EVENT_QP_LAST_WQE_REACHED
:
186 dprintk("svcrdma: QP event %s (%d) received for QP=%p\n",
187 ib_event_msg(event
->event
), event
->event
,
190 /* These are considered fatal events */
191 case IB_EVENT_PATH_MIG_ERR
:
192 case IB_EVENT_QP_FATAL
:
193 case IB_EVENT_QP_REQ_ERR
:
194 case IB_EVENT_QP_ACCESS_ERR
:
195 case IB_EVENT_DEVICE_FATAL
:
197 dprintk("svcrdma: QP ERROR event %s (%d) received for QP=%p, "
198 "closing transport\n",
199 ib_event_msg(event
->event
), event
->event
,
201 set_bit(XPT_CLOSE
, &xprt
->xpt_flags
);
207 * Data Transfer Operation Tasklet
209 * Walks a list of transports with I/O pending, removing entries as
210 * they are added to the server's I/O pending list. Two bits indicate
211 * if SQ, RQ, or both have I/O pending. The dto_lock is an irqsave
212 * spinlock that serializes access to the transport list with the RQ
213 * and SQ interrupt handlers.
215 static void dto_tasklet_func(unsigned long data
)
217 struct svcxprt_rdma
*xprt
;
220 spin_lock_irqsave(&dto_lock
, flags
);
221 while (!list_empty(&dto_xprt_q
)) {
222 xprt
= list_entry(dto_xprt_q
.next
,
223 struct svcxprt_rdma
, sc_dto_q
);
224 list_del_init(&xprt
->sc_dto_q
);
225 spin_unlock_irqrestore(&dto_lock
, flags
);
230 svc_xprt_put(&xprt
->sc_xprt
);
231 spin_lock_irqsave(&dto_lock
, flags
);
233 spin_unlock_irqrestore(&dto_lock
, flags
);
237 * Receive Queue Completion Handler
239 * Since an RQ completion handler is called on interrupt context, we
240 * need to defer the handling of the I/O to a tasklet
242 static void rq_comp_handler(struct ib_cq
*cq
, void *cq_context
)
244 struct svcxprt_rdma
*xprt
= cq_context
;
247 /* Guard against unconditional flush call for destroyed QP */
248 if (atomic_read(&xprt
->sc_xprt
.xpt_ref
.refcount
)==0)
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
256 set_bit(RDMAXPRT_RQ_PENDING
, &xprt
->sc_flags
);
259 * If this transport is not already on the DTO transport queue,
262 spin_lock_irqsave(&dto_lock
, flags
);
263 if (list_empty(&xprt
->sc_dto_q
)) {
264 svc_xprt_get(&xprt
->sc_xprt
);
265 list_add_tail(&xprt
->sc_dto_q
, &dto_xprt_q
);
267 spin_unlock_irqrestore(&dto_lock
, flags
);
269 /* Tasklet does all the work to avoid irqsave locks. */
270 tasklet_schedule(&dto_tasklet
);
274 * rq_cq_reap - Process the RQ CQ.
276 * Take all completing WC off the CQE and enqueue the associated DTO
277 * context on the dto_q for the transport.
279 * Note that caller must hold a transport reference.
281 static void rq_cq_reap(struct svcxprt_rdma
*xprt
)
285 struct svc_rdma_op_ctxt
*ctxt
= NULL
;
287 if (!test_and_clear_bit(RDMAXPRT_RQ_PENDING
, &xprt
->sc_flags
))
290 ib_req_notify_cq(xprt
->sc_rq_cq
, IB_CQ_NEXT_COMP
);
291 atomic_inc(&rdma_stat_rq_poll
);
293 while ((ret
= ib_poll_cq(xprt
->sc_rq_cq
, 1, &wc
)) > 0) {
294 ctxt
= (struct svc_rdma_op_ctxt
*)(unsigned long)wc
.wr_id
;
295 ctxt
->wc_status
= wc
.status
;
296 ctxt
->byte_len
= wc
.byte_len
;
297 svc_rdma_unmap_dma(ctxt
);
298 if (wc
.status
!= IB_WC_SUCCESS
) {
299 /* Close the transport */
300 dprintk("svcrdma: transport closing putting ctxt %p\n", ctxt
);
301 set_bit(XPT_CLOSE
, &xprt
->sc_xprt
.xpt_flags
);
302 svc_rdma_put_context(ctxt
, 1);
303 svc_xprt_put(&xprt
->sc_xprt
);
306 spin_lock_bh(&xprt
->sc_rq_dto_lock
);
307 list_add_tail(&ctxt
->dto_q
, &xprt
->sc_rq_dto_q
);
308 spin_unlock_bh(&xprt
->sc_rq_dto_lock
);
309 svc_xprt_put(&xprt
->sc_xprt
);
313 atomic_inc(&rdma_stat_rq_prod
);
315 set_bit(XPT_DATA
, &xprt
->sc_xprt
.xpt_flags
);
317 * If data arrived before established event,
318 * don't enqueue. This defers RPC I/O until the
319 * RDMA connection is complete.
321 if (!test_bit(RDMAXPRT_CONN_PENDING
, &xprt
->sc_flags
))
322 svc_xprt_enqueue(&xprt
->sc_xprt
);
326 * Process a completion context
328 static void process_context(struct svcxprt_rdma
*xprt
,
329 struct svc_rdma_op_ctxt
*ctxt
)
331 svc_rdma_unmap_dma(ctxt
);
333 switch (ctxt
->wr_op
) {
336 pr_err("svcrdma: SEND: ctxt->frmr != NULL\n");
337 svc_rdma_put_context(ctxt
, 1);
340 case IB_WR_RDMA_WRITE
:
342 pr_err("svcrdma: WRITE: ctxt->frmr != NULL\n");
343 svc_rdma_put_context(ctxt
, 0);
346 case IB_WR_RDMA_READ
:
347 case IB_WR_RDMA_READ_WITH_INV
:
348 svc_rdma_put_frmr(xprt
, ctxt
->frmr
);
349 if (test_bit(RDMACTXT_F_LAST_CTXT
, &ctxt
->flags
)) {
350 struct svc_rdma_op_ctxt
*read_hdr
= ctxt
->read_hdr
;
352 spin_lock_bh(&xprt
->sc_rq_dto_lock
);
353 set_bit(XPT_DATA
, &xprt
->sc_xprt
.xpt_flags
);
354 list_add_tail(&read_hdr
->dto_q
,
355 &xprt
->sc_read_complete_q
);
356 spin_unlock_bh(&xprt
->sc_rq_dto_lock
);
358 pr_err("svcrdma: ctxt->read_hdr == NULL\n");
360 svc_xprt_enqueue(&xprt
->sc_xprt
);
362 svc_rdma_put_context(ctxt
, 0);
366 printk(KERN_ERR
"svcrdma: unexpected completion type, "
374 * Send Queue Completion Handler - potentially called on interrupt context.
376 * Note that caller must hold a transport reference.
378 static void sq_cq_reap(struct svcxprt_rdma
*xprt
)
380 struct svc_rdma_op_ctxt
*ctxt
= NULL
;
381 struct ib_wc wc_a
[6];
383 struct ib_cq
*cq
= xprt
->sc_sq_cq
;
386 memset(wc_a
, 0, sizeof(wc_a
));
388 if (!test_and_clear_bit(RDMAXPRT_SQ_PENDING
, &xprt
->sc_flags
))
391 ib_req_notify_cq(xprt
->sc_sq_cq
, IB_CQ_NEXT_COMP
);
392 atomic_inc(&rdma_stat_sq_poll
);
393 while ((ret
= ib_poll_cq(cq
, ARRAY_SIZE(wc_a
), wc_a
)) > 0) {
396 for (i
= 0; i
< ret
; i
++) {
398 if (wc
->status
!= IB_WC_SUCCESS
) {
399 dprintk("svcrdma: sq wc err status %s (%d)\n",
400 ib_wc_status_msg(wc
->status
),
403 /* Close the transport */
404 set_bit(XPT_CLOSE
, &xprt
->sc_xprt
.xpt_flags
);
407 /* Decrement used SQ WR count */
408 atomic_dec(&xprt
->sc_sq_count
);
409 wake_up(&xprt
->sc_send_wait
);
411 ctxt
= (struct svc_rdma_op_ctxt
*)
412 (unsigned long)wc
->wr_id
;
414 process_context(xprt
, ctxt
);
416 svc_xprt_put(&xprt
->sc_xprt
);
421 atomic_inc(&rdma_stat_sq_prod
);
424 static void sq_comp_handler(struct ib_cq
*cq
, void *cq_context
)
426 struct svcxprt_rdma
*xprt
= cq_context
;
429 /* Guard against unconditional flush call for destroyed QP */
430 if (atomic_read(&xprt
->sc_xprt
.xpt_ref
.refcount
)==0)
434 * Set the bit regardless of whether or not it's on the list
435 * because it may be on the list already due to an RQ
438 set_bit(RDMAXPRT_SQ_PENDING
, &xprt
->sc_flags
);
441 * If this transport is not already on the DTO transport queue,
444 spin_lock_irqsave(&dto_lock
, flags
);
445 if (list_empty(&xprt
->sc_dto_q
)) {
446 svc_xprt_get(&xprt
->sc_xprt
);
447 list_add_tail(&xprt
->sc_dto_q
, &dto_xprt_q
);
449 spin_unlock_irqrestore(&dto_lock
, flags
);
451 /* Tasklet does all the work to avoid irqsave locks. */
452 tasklet_schedule(&dto_tasklet
);
455 static struct svcxprt_rdma
*rdma_create_xprt(struct svc_serv
*serv
,
458 struct svcxprt_rdma
*cma_xprt
= kzalloc(sizeof *cma_xprt
, GFP_KERNEL
);
462 svc_xprt_init(&init_net
, &svc_rdma_class
, &cma_xprt
->sc_xprt
, serv
);
463 INIT_LIST_HEAD(&cma_xprt
->sc_accept_q
);
464 INIT_LIST_HEAD(&cma_xprt
->sc_dto_q
);
465 INIT_LIST_HEAD(&cma_xprt
->sc_rq_dto_q
);
466 INIT_LIST_HEAD(&cma_xprt
->sc_read_complete_q
);
467 INIT_LIST_HEAD(&cma_xprt
->sc_frmr_q
);
468 init_waitqueue_head(&cma_xprt
->sc_send_wait
);
470 spin_lock_init(&cma_xprt
->sc_lock
);
471 spin_lock_init(&cma_xprt
->sc_rq_dto_lock
);
472 spin_lock_init(&cma_xprt
->sc_frmr_q_lock
);
474 cma_xprt
->sc_ord
= svcrdma_ord
;
476 cma_xprt
->sc_max_req_size
= svcrdma_max_req_size
;
477 cma_xprt
->sc_max_requests
= svcrdma_max_requests
;
478 cma_xprt
->sc_sq_depth
= svcrdma_max_requests
* RPCRDMA_SQ_DEPTH_MULT
;
479 atomic_set(&cma_xprt
->sc_sq_count
, 0);
480 atomic_set(&cma_xprt
->sc_ctxt_used
, 0);
483 set_bit(XPT_LISTENER
, &cma_xprt
->sc_xprt
.xpt_flags
);
488 int svc_rdma_post_recv(struct svcxprt_rdma
*xprt
)
490 struct ib_recv_wr recv_wr
, *bad_recv_wr
;
491 struct svc_rdma_op_ctxt
*ctxt
;
498 ctxt
= svc_rdma_get_context(xprt
);
500 ctxt
->direction
= DMA_FROM_DEVICE
;
501 for (sge_no
= 0; buflen
< xprt
->sc_max_req_size
; sge_no
++) {
502 if (sge_no
>= xprt
->sc_max_sge
) {
503 pr_err("svcrdma: Too many sges (%d)\n", sge_no
);
506 page
= alloc_page(GFP_KERNEL
| __GFP_NOFAIL
);
507 ctxt
->pages
[sge_no
] = page
;
508 pa
= ib_dma_map_page(xprt
->sc_cm_id
->device
,
511 if (ib_dma_mapping_error(xprt
->sc_cm_id
->device
, pa
))
513 atomic_inc(&xprt
->sc_dma_used
);
514 ctxt
->sge
[sge_no
].addr
= pa
;
515 ctxt
->sge
[sge_no
].length
= PAGE_SIZE
;
516 ctxt
->sge
[sge_no
].lkey
= xprt
->sc_dma_lkey
;
517 ctxt
->count
= sge_no
+ 1;
521 recv_wr
.sg_list
= &ctxt
->sge
[0];
522 recv_wr
.num_sge
= ctxt
->count
;
523 recv_wr
.wr_id
= (u64
)(unsigned long)ctxt
;
525 svc_xprt_get(&xprt
->sc_xprt
);
526 ret
= ib_post_recv(xprt
->sc_qp
, &recv_wr
, &bad_recv_wr
);
528 svc_rdma_unmap_dma(ctxt
);
529 svc_rdma_put_context(ctxt
, 1);
530 svc_xprt_put(&xprt
->sc_xprt
);
535 svc_rdma_unmap_dma(ctxt
);
536 svc_rdma_put_context(ctxt
, 1);
541 * This function handles the CONNECT_REQUEST event on a listening
542 * endpoint. It is passed the cma_id for the _new_ connection. The context in
543 * this cma_id is inherited from the listening cma_id and is the svc_xprt
544 * structure for the listening endpoint.
546 * This function creates a new xprt for the new connection and enqueues it on
547 * the accept queue for the listent xprt. When the listen thread is kicked, it
548 * will call the recvfrom method on the listen xprt which will accept the new
551 static void handle_connect_req(struct rdma_cm_id
*new_cma_id
, size_t client_ird
)
553 struct svcxprt_rdma
*listen_xprt
= new_cma_id
->context
;
554 struct svcxprt_rdma
*newxprt
;
557 /* Create a new transport */
558 newxprt
= rdma_create_xprt(listen_xprt
->sc_xprt
.xpt_server
, 0);
560 dprintk("svcrdma: failed to create new transport\n");
563 newxprt
->sc_cm_id
= new_cma_id
;
564 new_cma_id
->context
= newxprt
;
565 dprintk("svcrdma: Creating newxprt=%p, cm_id=%p, listenxprt=%p\n",
566 newxprt
, newxprt
->sc_cm_id
, listen_xprt
);
568 /* Save client advertised inbound read limit for use later in accept. */
569 newxprt
->sc_ord
= client_ird
;
571 /* Set the local and remote addresses in the transport */
572 sa
= (struct sockaddr
*)&newxprt
->sc_cm_id
->route
.addr
.dst_addr
;
573 svc_xprt_set_remote(&newxprt
->sc_xprt
, sa
, svc_addr_len(sa
));
574 sa
= (struct sockaddr
*)&newxprt
->sc_cm_id
->route
.addr
.src_addr
;
575 svc_xprt_set_local(&newxprt
->sc_xprt
, sa
, svc_addr_len(sa
));
578 * Enqueue the new transport on the accept queue of the listening
581 spin_lock_bh(&listen_xprt
->sc_lock
);
582 list_add_tail(&newxprt
->sc_accept_q
, &listen_xprt
->sc_accept_q
);
583 spin_unlock_bh(&listen_xprt
->sc_lock
);
585 set_bit(XPT_CONN
, &listen_xprt
->sc_xprt
.xpt_flags
);
586 svc_xprt_enqueue(&listen_xprt
->sc_xprt
);
590 * Handles events generated on the listening endpoint. These events will be
591 * either be incoming connect requests or adapter removal events.
593 static int rdma_listen_handler(struct rdma_cm_id
*cma_id
,
594 struct rdma_cm_event
*event
)
596 struct svcxprt_rdma
*xprt
= cma_id
->context
;
599 switch (event
->event
) {
600 case RDMA_CM_EVENT_CONNECT_REQUEST
:
601 dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, "
602 "event = %s (%d)\n", cma_id
, cma_id
->context
,
603 rdma_event_msg(event
->event
), event
->event
);
604 handle_connect_req(cma_id
,
605 event
->param
.conn
.initiator_depth
);
608 case RDMA_CM_EVENT_ESTABLISHED
:
609 /* Accept complete */
610 dprintk("svcrdma: Connection completed on LISTEN xprt=%p, "
611 "cm_id=%p\n", xprt
, cma_id
);
614 case RDMA_CM_EVENT_DEVICE_REMOVAL
:
615 dprintk("svcrdma: Device removal xprt=%p, cm_id=%p\n",
618 set_bit(XPT_CLOSE
, &xprt
->sc_xprt
.xpt_flags
);
622 dprintk("svcrdma: Unexpected event on listening endpoint %p, "
623 "event = %s (%d)\n", cma_id
,
624 rdma_event_msg(event
->event
), event
->event
);
631 static int rdma_cma_handler(struct rdma_cm_id
*cma_id
,
632 struct rdma_cm_event
*event
)
634 struct svc_xprt
*xprt
= cma_id
->context
;
635 struct svcxprt_rdma
*rdma
=
636 container_of(xprt
, struct svcxprt_rdma
, sc_xprt
);
637 switch (event
->event
) {
638 case RDMA_CM_EVENT_ESTABLISHED
:
639 /* Accept complete */
641 dprintk("svcrdma: Connection completed on DTO xprt=%p, "
642 "cm_id=%p\n", xprt
, cma_id
);
643 clear_bit(RDMAXPRT_CONN_PENDING
, &rdma
->sc_flags
);
644 svc_xprt_enqueue(xprt
);
646 case RDMA_CM_EVENT_DISCONNECTED
:
647 dprintk("svcrdma: Disconnect on DTO xprt=%p, cm_id=%p\n",
650 set_bit(XPT_CLOSE
, &xprt
->xpt_flags
);
651 svc_xprt_enqueue(xprt
);
655 case RDMA_CM_EVENT_DEVICE_REMOVAL
:
656 dprintk("svcrdma: Device removal cma_id=%p, xprt = %p, "
657 "event = %s (%d)\n", cma_id
, xprt
,
658 rdma_event_msg(event
->event
), event
->event
);
660 set_bit(XPT_CLOSE
, &xprt
->xpt_flags
);
661 svc_xprt_enqueue(xprt
);
666 dprintk("svcrdma: Unexpected event on DTO endpoint %p, "
667 "event = %s (%d)\n", cma_id
,
668 rdma_event_msg(event
->event
), event
->event
);
675 * Create a listening RDMA service endpoint.
677 static struct svc_xprt
*svc_rdma_create(struct svc_serv
*serv
,
679 struct sockaddr
*sa
, int salen
,
682 struct rdma_cm_id
*listen_id
;
683 struct svcxprt_rdma
*cma_xprt
;
686 dprintk("svcrdma: Creating RDMA socket\n");
687 if (sa
->sa_family
!= AF_INET
) {
688 dprintk("svcrdma: Address family %d is not supported.\n", sa
->sa_family
);
689 return ERR_PTR(-EAFNOSUPPORT
);
691 cma_xprt
= rdma_create_xprt(serv
, 1);
693 return ERR_PTR(-ENOMEM
);
695 listen_id
= rdma_create_id(rdma_listen_handler
, cma_xprt
, RDMA_PS_TCP
,
697 if (IS_ERR(listen_id
)) {
698 ret
= PTR_ERR(listen_id
);
699 dprintk("svcrdma: rdma_create_id failed = %d\n", ret
);
703 ret
= rdma_bind_addr(listen_id
, sa
);
705 dprintk("svcrdma: rdma_bind_addr failed = %d\n", ret
);
708 cma_xprt
->sc_cm_id
= listen_id
;
710 ret
= rdma_listen(listen_id
, RPCRDMA_LISTEN_BACKLOG
);
712 dprintk("svcrdma: rdma_listen failed = %d\n", ret
);
717 * We need to use the address from the cm_id in case the
718 * caller specified 0 for the port number.
720 sa
= (struct sockaddr
*)&cma_xprt
->sc_cm_id
->route
.addr
.src_addr
;
721 svc_xprt_set_local(&cma_xprt
->sc_xprt
, sa
, salen
);
723 return &cma_xprt
->sc_xprt
;
726 rdma_destroy_id(listen_id
);
732 static struct svc_rdma_fastreg_mr
*rdma_alloc_frmr(struct svcxprt_rdma
*xprt
)
735 struct ib_fast_reg_page_list
*pl
;
736 struct svc_rdma_fastreg_mr
*frmr
;
739 frmr
= kmalloc(sizeof(*frmr
), GFP_KERNEL
);
743 num_sg
= min_t(u32
, RPCSVC_MAXPAGES
, xprt
->sc_frmr_pg_list_len
);
744 mr
= ib_alloc_mr(xprt
->sc_pd
, IB_MR_TYPE_MEM_REG
, num_sg
);
748 pl
= ib_alloc_fast_reg_page_list(xprt
->sc_cm_id
->device
,
754 frmr
->page_list
= pl
;
755 INIT_LIST_HEAD(&frmr
->frmr_list
);
763 return ERR_PTR(-ENOMEM
);
766 static void rdma_dealloc_frmr_q(struct svcxprt_rdma
*xprt
)
768 struct svc_rdma_fastreg_mr
*frmr
;
770 while (!list_empty(&xprt
->sc_frmr_q
)) {
771 frmr
= list_entry(xprt
->sc_frmr_q
.next
,
772 struct svc_rdma_fastreg_mr
, frmr_list
);
773 list_del_init(&frmr
->frmr_list
);
774 ib_dereg_mr(frmr
->mr
);
775 ib_free_fast_reg_page_list(frmr
->page_list
);
780 struct svc_rdma_fastreg_mr
*svc_rdma_get_frmr(struct svcxprt_rdma
*rdma
)
782 struct svc_rdma_fastreg_mr
*frmr
= NULL
;
784 spin_lock_bh(&rdma
->sc_frmr_q_lock
);
785 if (!list_empty(&rdma
->sc_frmr_q
)) {
786 frmr
= list_entry(rdma
->sc_frmr_q
.next
,
787 struct svc_rdma_fastreg_mr
, frmr_list
);
788 list_del_init(&frmr
->frmr_list
);
790 frmr
->page_list_len
= 0;
792 spin_unlock_bh(&rdma
->sc_frmr_q_lock
);
796 return rdma_alloc_frmr(rdma
);
799 static void frmr_unmap_dma(struct svcxprt_rdma
*xprt
,
800 struct svc_rdma_fastreg_mr
*frmr
)
803 for (page_no
= 0; page_no
< frmr
->page_list_len
; page_no
++) {
804 dma_addr_t addr
= frmr
->page_list
->page_list
[page_no
];
805 if (ib_dma_mapping_error(frmr
->mr
->device
, addr
))
807 atomic_dec(&xprt
->sc_dma_used
);
808 ib_dma_unmap_page(frmr
->mr
->device
, addr
, PAGE_SIZE
,
813 void svc_rdma_put_frmr(struct svcxprt_rdma
*rdma
,
814 struct svc_rdma_fastreg_mr
*frmr
)
817 frmr_unmap_dma(rdma
, frmr
);
818 spin_lock_bh(&rdma
->sc_frmr_q_lock
);
819 WARN_ON_ONCE(!list_empty(&frmr
->frmr_list
));
820 list_add(&frmr
->frmr_list
, &rdma
->sc_frmr_q
);
821 spin_unlock_bh(&rdma
->sc_frmr_q_lock
);
826 * This is the xpo_recvfrom function for listening endpoints. Its
827 * purpose is to accept incoming connections. The CMA callback handler
828 * has already created a new transport and attached it to the new CMA
831 * There is a queue of pending connections hung on the listening
832 * transport. This queue contains the new svc_xprt structure. This
833 * function takes svc_xprt structures off the accept_q and completes
836 static struct svc_xprt
*svc_rdma_accept(struct svc_xprt
*xprt
)
838 struct svcxprt_rdma
*listen_rdma
;
839 struct svcxprt_rdma
*newxprt
= NULL
;
840 struct rdma_conn_param conn_param
;
841 struct ib_cq_init_attr cq_attr
= {};
842 struct ib_qp_init_attr qp_attr
;
843 struct ib_device_attr devattr
;
844 int uninitialized_var(dma_mr_acc
);
849 listen_rdma
= container_of(xprt
, struct svcxprt_rdma
, sc_xprt
);
850 clear_bit(XPT_CONN
, &xprt
->xpt_flags
);
851 /* Get the next entry off the accept list */
852 spin_lock_bh(&listen_rdma
->sc_lock
);
853 if (!list_empty(&listen_rdma
->sc_accept_q
)) {
854 newxprt
= list_entry(listen_rdma
->sc_accept_q
.next
,
855 struct svcxprt_rdma
, sc_accept_q
);
856 list_del_init(&newxprt
->sc_accept_q
);
858 if (!list_empty(&listen_rdma
->sc_accept_q
))
859 set_bit(XPT_CONN
, &listen_rdma
->sc_xprt
.xpt_flags
);
860 spin_unlock_bh(&listen_rdma
->sc_lock
);
864 dprintk("svcrdma: newxprt from accept queue = %p, cm_id=%p\n",
865 newxprt
, newxprt
->sc_cm_id
);
867 ret
= ib_query_device(newxprt
->sc_cm_id
->device
, &devattr
);
869 dprintk("svcrdma: could not query device attributes on "
870 "device %p, rc=%d\n", newxprt
->sc_cm_id
->device
, ret
);
874 /* Qualify the transport resource defaults with the
875 * capabilities of this particular device */
876 newxprt
->sc_max_sge
= min((size_t)devattr
.max_sge
,
877 (size_t)RPCSVC_MAXPAGES
);
878 newxprt
->sc_max_sge_rd
= min_t(size_t, devattr
.max_sge_rd
,
880 newxprt
->sc_max_requests
= min((size_t)devattr
.max_qp_wr
,
881 (size_t)svcrdma_max_requests
);
882 newxprt
->sc_sq_depth
= RPCRDMA_SQ_DEPTH_MULT
* newxprt
->sc_max_requests
;
885 * Limit ORD based on client limit, local device limit, and
886 * configured svcrdma limit.
888 newxprt
->sc_ord
= min_t(size_t, devattr
.max_qp_rd_atom
, newxprt
->sc_ord
);
889 newxprt
->sc_ord
= min_t(size_t, svcrdma_ord
, newxprt
->sc_ord
);
891 newxprt
->sc_pd
= ib_alloc_pd(newxprt
->sc_cm_id
->device
);
892 if (IS_ERR(newxprt
->sc_pd
)) {
893 dprintk("svcrdma: error creating PD for connect request\n");
896 cq_attr
.cqe
= newxprt
->sc_sq_depth
;
897 newxprt
->sc_sq_cq
= ib_create_cq(newxprt
->sc_cm_id
->device
,
902 if (IS_ERR(newxprt
->sc_sq_cq
)) {
903 dprintk("svcrdma: error creating SQ CQ for connect request\n");
906 cq_attr
.cqe
= newxprt
->sc_max_requests
;
907 newxprt
->sc_rq_cq
= ib_create_cq(newxprt
->sc_cm_id
->device
,
912 if (IS_ERR(newxprt
->sc_rq_cq
)) {
913 dprintk("svcrdma: error creating RQ CQ for connect request\n");
917 memset(&qp_attr
, 0, sizeof qp_attr
);
918 qp_attr
.event_handler
= qp_event_handler
;
919 qp_attr
.qp_context
= &newxprt
->sc_xprt
;
920 qp_attr
.cap
.max_send_wr
= newxprt
->sc_sq_depth
;
921 qp_attr
.cap
.max_recv_wr
= newxprt
->sc_max_requests
;
922 qp_attr
.cap
.max_send_sge
= newxprt
->sc_max_sge
;
923 qp_attr
.cap
.max_recv_sge
= newxprt
->sc_max_sge
;
924 qp_attr
.sq_sig_type
= IB_SIGNAL_REQ_WR
;
925 qp_attr
.qp_type
= IB_QPT_RC
;
926 qp_attr
.send_cq
= newxprt
->sc_sq_cq
;
927 qp_attr
.recv_cq
= newxprt
->sc_rq_cq
;
928 dprintk("svcrdma: newxprt->sc_cm_id=%p, newxprt->sc_pd=%p\n"
929 " cm_id->device=%p, sc_pd->device=%p\n"
930 " cap.max_send_wr = %d\n"
931 " cap.max_recv_wr = %d\n"
932 " cap.max_send_sge = %d\n"
933 " cap.max_recv_sge = %d\n",
934 newxprt
->sc_cm_id
, newxprt
->sc_pd
,
935 newxprt
->sc_cm_id
->device
, newxprt
->sc_pd
->device
,
936 qp_attr
.cap
.max_send_wr
,
937 qp_attr
.cap
.max_recv_wr
,
938 qp_attr
.cap
.max_send_sge
,
939 qp_attr
.cap
.max_recv_sge
);
941 ret
= rdma_create_qp(newxprt
->sc_cm_id
, newxprt
->sc_pd
, &qp_attr
);
943 dprintk("svcrdma: failed to create QP, ret=%d\n", ret
);
946 newxprt
->sc_qp
= newxprt
->sc_cm_id
->qp
;
949 * Use the most secure set of MR resources based on the
950 * transport type and available memory management features in
951 * the device. Here's the table implemented below:
953 * Fast Global DMA Remote WR
955 * Sup'd Sup'd Needed Needed
967 * NB: iWARP requires remote write access for the data sink
968 * of an RDMA_READ. IB does not.
970 newxprt
->sc_reader
= rdma_read_chunk_lcl
;
971 if (devattr
.device_cap_flags
& IB_DEVICE_MEM_MGT_EXTENSIONS
) {
972 newxprt
->sc_frmr_pg_list_len
=
973 devattr
.max_fast_reg_page_list_len
;
974 newxprt
->sc_dev_caps
|= SVCRDMA_DEVCAP_FAST_REG
;
975 newxprt
->sc_reader
= rdma_read_chunk_frmr
;
979 * Determine if a DMA MR is required and if so, what privs are required
981 if (!rdma_protocol_iwarp(newxprt
->sc_cm_id
->device
,
982 newxprt
->sc_cm_id
->port_num
) &&
983 !rdma_ib_or_roce(newxprt
->sc_cm_id
->device
,
984 newxprt
->sc_cm_id
->port_num
))
987 if (!(newxprt
->sc_dev_caps
& SVCRDMA_DEVCAP_FAST_REG
) ||
988 !(devattr
.device_cap_flags
& IB_DEVICE_LOCAL_DMA_LKEY
)) {
990 dma_mr_acc
= IB_ACCESS_LOCAL_WRITE
;
991 if (rdma_protocol_iwarp(newxprt
->sc_cm_id
->device
,
992 newxprt
->sc_cm_id
->port_num
) &&
993 !(newxprt
->sc_dev_caps
& SVCRDMA_DEVCAP_FAST_REG
))
994 dma_mr_acc
|= IB_ACCESS_REMOTE_WRITE
;
997 if (rdma_protocol_iwarp(newxprt
->sc_cm_id
->device
,
998 newxprt
->sc_cm_id
->port_num
))
999 newxprt
->sc_dev_caps
|= SVCRDMA_DEVCAP_READ_W_INV
;
1001 /* Create the DMA MR if needed, otherwise, use the DMA LKEY */
1003 /* Register all of physical memory */
1004 newxprt
->sc_phys_mr
=
1005 ib_get_dma_mr(newxprt
->sc_pd
, dma_mr_acc
);
1006 if (IS_ERR(newxprt
->sc_phys_mr
)) {
1007 dprintk("svcrdma: Failed to create DMA MR ret=%d\n",
1011 newxprt
->sc_dma_lkey
= newxprt
->sc_phys_mr
->lkey
;
1013 newxprt
->sc_dma_lkey
=
1014 newxprt
->sc_cm_id
->device
->local_dma_lkey
;
1016 /* Post receive buffers */
1017 for (i
= 0; i
< newxprt
->sc_max_requests
; i
++) {
1018 ret
= svc_rdma_post_recv(newxprt
);
1020 dprintk("svcrdma: failure posting receive buffers\n");
1025 /* Swap out the handler */
1026 newxprt
->sc_cm_id
->event_handler
= rdma_cma_handler
;
1029 * Arm the CQs for the SQ and RQ before accepting so we can't
1030 * miss the first message
1032 ib_req_notify_cq(newxprt
->sc_sq_cq
, IB_CQ_NEXT_COMP
);
1033 ib_req_notify_cq(newxprt
->sc_rq_cq
, IB_CQ_NEXT_COMP
);
1035 /* Accept Connection */
1036 set_bit(RDMAXPRT_CONN_PENDING
, &newxprt
->sc_flags
);
1037 memset(&conn_param
, 0, sizeof conn_param
);
1038 conn_param
.responder_resources
= 0;
1039 conn_param
.initiator_depth
= newxprt
->sc_ord
;
1040 ret
= rdma_accept(newxprt
->sc_cm_id
, &conn_param
);
1042 dprintk("svcrdma: failed to accept new connection, ret=%d\n",
1047 dprintk("svcrdma: new connection %p accepted with the following "
1049 " local_ip : %pI4\n"
1050 " local_port : %d\n"
1051 " remote_ip : %pI4\n"
1052 " remote_port : %d\n"
1054 " max_sge_rd : %d\n"
1056 " max_requests : %d\n"
1059 &((struct sockaddr_in
*)&newxprt
->sc_cm_id
->
1060 route
.addr
.src_addr
)->sin_addr
.s_addr
,
1061 ntohs(((struct sockaddr_in
*)&newxprt
->sc_cm_id
->
1062 route
.addr
.src_addr
)->sin_port
),
1063 &((struct sockaddr_in
*)&newxprt
->sc_cm_id
->
1064 route
.addr
.dst_addr
)->sin_addr
.s_addr
,
1065 ntohs(((struct sockaddr_in
*)&newxprt
->sc_cm_id
->
1066 route
.addr
.dst_addr
)->sin_port
),
1067 newxprt
->sc_max_sge
,
1068 newxprt
->sc_max_sge_rd
,
1069 newxprt
->sc_sq_depth
,
1070 newxprt
->sc_max_requests
,
1073 return &newxprt
->sc_xprt
;
1076 dprintk("svcrdma: failure accepting new connection rc=%d.\n", ret
);
1077 /* Take a reference in case the DTO handler runs */
1078 svc_xprt_get(&newxprt
->sc_xprt
);
1079 if (newxprt
->sc_qp
&& !IS_ERR(newxprt
->sc_qp
))
1080 ib_destroy_qp(newxprt
->sc_qp
);
1081 rdma_destroy_id(newxprt
->sc_cm_id
);
1082 /* This call to put will destroy the transport */
1083 svc_xprt_put(&newxprt
->sc_xprt
);
1087 static void svc_rdma_release_rqst(struct svc_rqst
*rqstp
)
1092 * When connected, an svc_xprt has at least two references:
1094 * - A reference held by the cm_id between the ESTABLISHED and
1095 * DISCONNECTED events. If the remote peer disconnected first, this
1096 * reference could be gone.
1098 * - A reference held by the svc_recv code that called this function
1099 * as part of close processing.
1101 * At a minimum one references should still be held.
1103 static void svc_rdma_detach(struct svc_xprt
*xprt
)
1105 struct svcxprt_rdma
*rdma
=
1106 container_of(xprt
, struct svcxprt_rdma
, sc_xprt
);
1107 dprintk("svc: svc_rdma_detach(%p)\n", xprt
);
1109 /* Disconnect and flush posted WQE */
1110 rdma_disconnect(rdma
->sc_cm_id
);
1113 static void __svc_rdma_free(struct work_struct
*work
)
1115 struct svcxprt_rdma
*rdma
=
1116 container_of(work
, struct svcxprt_rdma
, sc_work
);
1117 dprintk("svcrdma: svc_rdma_free(%p)\n", rdma
);
1119 /* We should only be called from kref_put */
1120 if (atomic_read(&rdma
->sc_xprt
.xpt_ref
.refcount
) != 0)
1121 pr_err("svcrdma: sc_xprt still in use? (%d)\n",
1122 atomic_read(&rdma
->sc_xprt
.xpt_ref
.refcount
));
1125 * Destroy queued, but not processed read completions. Note
1126 * that this cleanup has to be done before destroying the
1127 * cm_id because the device ptr is needed to unmap the dma in
1128 * svc_rdma_put_context.
1130 while (!list_empty(&rdma
->sc_read_complete_q
)) {
1131 struct svc_rdma_op_ctxt
*ctxt
;
1132 ctxt
= list_entry(rdma
->sc_read_complete_q
.next
,
1133 struct svc_rdma_op_ctxt
,
1135 list_del_init(&ctxt
->dto_q
);
1136 svc_rdma_put_context(ctxt
, 1);
1139 /* Destroy queued, but not processed recv completions */
1140 while (!list_empty(&rdma
->sc_rq_dto_q
)) {
1141 struct svc_rdma_op_ctxt
*ctxt
;
1142 ctxt
= list_entry(rdma
->sc_rq_dto_q
.next
,
1143 struct svc_rdma_op_ctxt
,
1145 list_del_init(&ctxt
->dto_q
);
1146 svc_rdma_put_context(ctxt
, 1);
1149 /* Warn if we leaked a resource or under-referenced */
1150 if (atomic_read(&rdma
->sc_ctxt_used
) != 0)
1151 pr_err("svcrdma: ctxt still in use? (%d)\n",
1152 atomic_read(&rdma
->sc_ctxt_used
));
1153 if (atomic_read(&rdma
->sc_dma_used
) != 0)
1154 pr_err("svcrdma: dma still in use? (%d)\n",
1155 atomic_read(&rdma
->sc_dma_used
));
1157 /* De-allocate fastreg mr */
1158 rdma_dealloc_frmr_q(rdma
);
1160 /* Destroy the QP if present (not a listener) */
1161 if (rdma
->sc_qp
&& !IS_ERR(rdma
->sc_qp
))
1162 ib_destroy_qp(rdma
->sc_qp
);
1164 if (rdma
->sc_sq_cq
&& !IS_ERR(rdma
->sc_sq_cq
))
1165 ib_destroy_cq(rdma
->sc_sq_cq
);
1167 if (rdma
->sc_rq_cq
&& !IS_ERR(rdma
->sc_rq_cq
))
1168 ib_destroy_cq(rdma
->sc_rq_cq
);
1170 if (rdma
->sc_phys_mr
&& !IS_ERR(rdma
->sc_phys_mr
))
1171 ib_dereg_mr(rdma
->sc_phys_mr
);
1173 if (rdma
->sc_pd
&& !IS_ERR(rdma
->sc_pd
))
1174 ib_dealloc_pd(rdma
->sc_pd
);
1176 /* Destroy the CM ID */
1177 rdma_destroy_id(rdma
->sc_cm_id
);
1182 static void svc_rdma_free(struct svc_xprt
*xprt
)
1184 struct svcxprt_rdma
*rdma
=
1185 container_of(xprt
, struct svcxprt_rdma
, sc_xprt
);
1186 INIT_WORK(&rdma
->sc_work
, __svc_rdma_free
);
1187 queue_work(svc_rdma_wq
, &rdma
->sc_work
);
1190 static int svc_rdma_has_wspace(struct svc_xprt
*xprt
)
1192 struct svcxprt_rdma
*rdma
=
1193 container_of(xprt
, struct svcxprt_rdma
, sc_xprt
);
1196 * If there are already waiters on the SQ,
1199 if (waitqueue_active(&rdma
->sc_send_wait
))
1202 /* Otherwise return true. */
1206 static int svc_rdma_secure_port(struct svc_rqst
*rqstp
)
1211 int svc_rdma_send(struct svcxprt_rdma
*xprt
, struct ib_send_wr
*wr
)
1213 struct ib_send_wr
*bad_wr
, *n_wr
;
1218 if (test_bit(XPT_CLOSE
, &xprt
->sc_xprt
.xpt_flags
))
1222 for (n_wr
= wr
->next
; n_wr
; n_wr
= n_wr
->next
)
1225 /* If the SQ is full, wait until an SQ entry is available */
1227 spin_lock_bh(&xprt
->sc_lock
);
1228 if (xprt
->sc_sq_depth
< atomic_read(&xprt
->sc_sq_count
) + wr_count
) {
1229 spin_unlock_bh(&xprt
->sc_lock
);
1230 atomic_inc(&rdma_stat_sq_starve
);
1232 /* See if we can opportunistically reap SQ WR to make room */
1235 /* Wait until SQ WR available if SQ still full */
1236 wait_event(xprt
->sc_send_wait
,
1237 atomic_read(&xprt
->sc_sq_count
) <
1239 if (test_bit(XPT_CLOSE
, &xprt
->sc_xprt
.xpt_flags
))
1243 /* Take a transport ref for each WR posted */
1244 for (i
= 0; i
< wr_count
; i
++)
1245 svc_xprt_get(&xprt
->sc_xprt
);
1247 /* Bump used SQ WR count and post */
1248 atomic_add(wr_count
, &xprt
->sc_sq_count
);
1249 ret
= ib_post_send(xprt
->sc_qp
, wr
, &bad_wr
);
1251 set_bit(XPT_CLOSE
, &xprt
->sc_xprt
.xpt_flags
);
1252 atomic_sub(wr_count
, &xprt
->sc_sq_count
);
1253 for (i
= 0; i
< wr_count
; i
++)
1254 svc_xprt_put(&xprt
->sc_xprt
);
1255 dprintk("svcrdma: failed to post SQ WR rc=%d, "
1256 "sc_sq_count=%d, sc_sq_depth=%d\n",
1257 ret
, atomic_read(&xprt
->sc_sq_count
),
1260 spin_unlock_bh(&xprt
->sc_lock
);
1262 wake_up(&xprt
->sc_send_wait
);
1268 void svc_rdma_send_error(struct svcxprt_rdma
*xprt
, struct rpcrdma_msg
*rmsgp
,
1269 enum rpcrdma_errcode err
)
1271 struct ib_send_wr err_wr
;
1273 struct svc_rdma_op_ctxt
*ctxt
;
1278 p
= alloc_page(GFP_KERNEL
| __GFP_NOFAIL
);
1279 va
= page_address(p
);
1281 /* XDR encode error */
1282 length
= svc_rdma_xdr_encode_error(xprt
, rmsgp
, err
, va
);
1284 ctxt
= svc_rdma_get_context(xprt
);
1285 ctxt
->direction
= DMA_FROM_DEVICE
;
1289 /* Prepare SGE for local address */
1290 ctxt
->sge
[0].addr
= ib_dma_map_page(xprt
->sc_cm_id
->device
,
1291 p
, 0, length
, DMA_FROM_DEVICE
);
1292 if (ib_dma_mapping_error(xprt
->sc_cm_id
->device
, ctxt
->sge
[0].addr
)) {
1294 svc_rdma_put_context(ctxt
, 1);
1297 atomic_inc(&xprt
->sc_dma_used
);
1298 ctxt
->sge
[0].lkey
= xprt
->sc_dma_lkey
;
1299 ctxt
->sge
[0].length
= length
;
1301 /* Prepare SEND WR */
1302 memset(&err_wr
, 0, sizeof err_wr
);
1303 ctxt
->wr_op
= IB_WR_SEND
;
1304 err_wr
.wr_id
= (unsigned long)ctxt
;
1305 err_wr
.sg_list
= ctxt
->sge
;
1307 err_wr
.opcode
= IB_WR_SEND
;
1308 err_wr
.send_flags
= IB_SEND_SIGNALED
;
1311 ret
= svc_rdma_send(xprt
, &err_wr
);
1313 dprintk("svcrdma: Error %d posting send for protocol error\n",
1315 svc_rdma_unmap_dma(ctxt
);
1316 svc_rdma_put_context(ctxt
, 1);