1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (c) 2015-2018 Oracle. All rights reserved.
4 * Copyright (c) 2014 Open Grid Computing, Inc. All rights reserved.
5 * Copyright (c) 2005-2007 Network Appliance, Inc. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the BSD-type
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
17 * Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
20 * Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials provided
23 * with the distribution.
25 * Neither the name of the Network Appliance, Inc. nor the names of
26 * its contributors may be used to endorse or promote products
27 * derived from this software without specific prior written
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 * Author: Tom Tucker <tom@opengridcomputing.com>
45 #include <linux/interrupt.h>
46 #include <linux/sched.h>
47 #include <linux/slab.h>
48 #include <linux/spinlock.h>
49 #include <linux/workqueue.h>
50 #include <linux/export.h>
52 #include <rdma/ib_verbs.h>
53 #include <rdma/rdma_cm.h>
56 #include <linux/sunrpc/addr.h>
57 #include <linux/sunrpc/debug.h>
58 #include <linux/sunrpc/rpc_rdma.h>
59 #include <linux/sunrpc/svc_xprt.h>
60 #include <linux/sunrpc/svc_rdma.h>
62 #include "xprt_rdma.h"
63 #include <trace/events/rpcrdma.h>
65 #define RPCDBG_FACILITY RPCDBG_SVCXPRT
67 static struct svcxprt_rdma *svc_rdma_create_xprt(struct svc_serv *serv,
69 static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
71 struct sockaddr *sa, int salen,
73 static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt);
74 static void svc_rdma_release_rqst(struct svc_rqst *);
75 static void svc_rdma_detach(struct svc_xprt *xprt);
76 static void svc_rdma_free(struct svc_xprt *xprt);
77 static int svc_rdma_has_wspace(struct svc_xprt *xprt);
78 static void svc_rdma_secure_port(struct svc_rqst *);
79 static void svc_rdma_kill_temp_xprt(struct svc_xprt *);
81 static const struct svc_xprt_ops svc_rdma_ops = {
82 .xpo_create = svc_rdma_create,
83 .xpo_recvfrom = svc_rdma_recvfrom,
84 .xpo_sendto = svc_rdma_sendto,
85 .xpo_release_rqst = svc_rdma_release_rqst,
86 .xpo_detach = svc_rdma_detach,
87 .xpo_free = svc_rdma_free,
88 .xpo_has_wspace = svc_rdma_has_wspace,
89 .xpo_accept = svc_rdma_accept,
90 .xpo_secure_port = svc_rdma_secure_port,
91 .xpo_kill_temp_xprt = svc_rdma_kill_temp_xprt,
94 struct svc_xprt_class svc_rdma_class = {
96 .xcl_owner = THIS_MODULE,
97 .xcl_ops = &svc_rdma_ops,
98 .xcl_max_payload = RPCSVC_MAXPAYLOAD_RDMA,
99 .xcl_ident = XPRT_TRANSPORT_RDMA,
102 /* QP event handler */
103 static void qp_event_handler(struct ib_event *event, void *context)
105 struct svc_xprt *xprt = context;
107 trace_svcrdma_qp_error(event, (struct sockaddr *)&xprt->xpt_remote);
108 switch (event->event) {
109 /* These are considered benign events */
110 case IB_EVENT_PATH_MIG:
111 case IB_EVENT_COMM_EST:
112 case IB_EVENT_SQ_DRAINED:
113 case IB_EVENT_QP_LAST_WQE_REACHED:
116 /* These are considered fatal events */
117 case IB_EVENT_PATH_MIG_ERR:
118 case IB_EVENT_QP_FATAL:
119 case IB_EVENT_QP_REQ_ERR:
120 case IB_EVENT_QP_ACCESS_ERR:
121 case IB_EVENT_DEVICE_FATAL:
123 set_bit(XPT_CLOSE, &xprt->xpt_flags);
124 svc_xprt_enqueue(xprt);
129 static struct svcxprt_rdma *svc_rdma_create_xprt(struct svc_serv *serv,
132 struct svcxprt_rdma *cma_xprt = kzalloc(sizeof *cma_xprt, GFP_KERNEL);
135 dprintk("svcrdma: failed to create new transport\n");
138 svc_xprt_init(net, &svc_rdma_class, &cma_xprt->sc_xprt, serv);
139 INIT_LIST_HEAD(&cma_xprt->sc_accept_q);
140 INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
141 INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q);
142 INIT_LIST_HEAD(&cma_xprt->sc_send_ctxts);
143 INIT_LIST_HEAD(&cma_xprt->sc_recv_ctxts);
144 INIT_LIST_HEAD(&cma_xprt->sc_rw_ctxts);
145 init_waitqueue_head(&cma_xprt->sc_send_wait);
147 spin_lock_init(&cma_xprt->sc_lock);
148 spin_lock_init(&cma_xprt->sc_rq_dto_lock);
149 spin_lock_init(&cma_xprt->sc_send_lock);
150 spin_lock_init(&cma_xprt->sc_recv_lock);
151 spin_lock_init(&cma_xprt->sc_rw_ctxt_lock);
154 * Note that this implies that the underlying transport support
155 * has some form of congestion control (see RFC 7530 section 3.1
156 * paragraph 2). For now, we assume that all supported RDMA
157 * transports are suitable here.
159 set_bit(XPT_CONG_CTRL, &cma_xprt->sc_xprt.xpt_flags);
165 svc_rdma_parse_connect_private(struct svcxprt_rdma *newxprt,
166 struct rdma_conn_param *param)
168 const struct rpcrdma_connect_private *pmsg = param->private_data;
171 pmsg->cp_magic == rpcrdma_cmp_magic &&
172 pmsg->cp_version == RPCRDMA_CMP_VERSION) {
173 newxprt->sc_snd_w_inv = pmsg->cp_flags &
174 RPCRDMA_CMP_F_SND_W_INV_OK;
176 dprintk("svcrdma: client send_size %u, recv_size %u "
177 "remote inv %ssupported\n",
178 rpcrdma_decode_buffer_size(pmsg->cp_send_size),
179 rpcrdma_decode_buffer_size(pmsg->cp_recv_size),
180 newxprt->sc_snd_w_inv ? "" : "un");
185 * This function handles the CONNECT_REQUEST event on a listening
186 * endpoint. It is passed the cma_id for the _new_ connection. The context in
187 * this cma_id is inherited from the listening cma_id and is the svc_xprt
188 * structure for the listening endpoint.
190 * This function creates a new xprt for the new connection and enqueues it on
191 * the accept queue for the listent xprt. When the listen thread is kicked, it
192 * will call the recvfrom method on the listen xprt which will accept the new
195 static void handle_connect_req(struct rdma_cm_id *new_cma_id,
196 struct rdma_conn_param *param)
198 struct svcxprt_rdma *listen_xprt = new_cma_id->context;
199 struct svcxprt_rdma *newxprt;
202 /* Create a new transport */
203 newxprt = svc_rdma_create_xprt(listen_xprt->sc_xprt.xpt_server,
204 listen_xprt->sc_xprt.xpt_net);
207 newxprt->sc_cm_id = new_cma_id;
208 new_cma_id->context = newxprt;
209 svc_rdma_parse_connect_private(newxprt, param);
211 /* Save client advertised inbound read limit for use later in accept. */
212 newxprt->sc_ord = param->initiator_depth;
214 sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
215 svc_xprt_set_remote(&newxprt->sc_xprt, sa, svc_addr_len(sa));
216 /* The remote port is arbitrary and not under the control of the
217 * client ULP. Set it to a fixed value so that the DRC continues
218 * to be effective after a reconnect.
220 rpc_set_port((struct sockaddr *)&newxprt->sc_xprt.xpt_remote, 0);
222 sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
223 svc_xprt_set_local(&newxprt->sc_xprt, sa, svc_addr_len(sa));
226 * Enqueue the new transport on the accept queue of the listening
229 spin_lock_bh(&listen_xprt->sc_lock);
230 list_add_tail(&newxprt->sc_accept_q, &listen_xprt->sc_accept_q);
231 spin_unlock_bh(&listen_xprt->sc_lock);
233 set_bit(XPT_CONN, &listen_xprt->sc_xprt.xpt_flags);
234 svc_xprt_enqueue(&listen_xprt->sc_xprt);
238 * Handles events generated on the listening endpoint. These events will be
239 * either be incoming connect requests or adapter removal events.
241 static int rdma_listen_handler(struct rdma_cm_id *cma_id,
242 struct rdma_cm_event *event)
244 struct sockaddr *sap = (struct sockaddr *)&cma_id->route.addr.src_addr;
246 trace_svcrdma_cm_event(event, sap);
248 switch (event->event) {
249 case RDMA_CM_EVENT_CONNECT_REQUEST:
250 dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, "
251 "event = %s (%d)\n", cma_id, cma_id->context,
252 rdma_event_msg(event->event), event->event);
253 handle_connect_req(cma_id, &event->param.conn);
256 /* NB: No device removal upcall for INADDR_ANY listeners */
257 dprintk("svcrdma: Unexpected event on listening endpoint %p, "
258 "event = %s (%d)\n", cma_id,
259 rdma_event_msg(event->event), event->event);
266 static int rdma_cma_handler(struct rdma_cm_id *cma_id,
267 struct rdma_cm_event *event)
269 struct sockaddr *sap = (struct sockaddr *)&cma_id->route.addr.dst_addr;
270 struct svcxprt_rdma *rdma = cma_id->context;
271 struct svc_xprt *xprt = &rdma->sc_xprt;
273 trace_svcrdma_cm_event(event, sap);
275 switch (event->event) {
276 case RDMA_CM_EVENT_ESTABLISHED:
277 /* Accept complete */
279 dprintk("svcrdma: Connection completed on DTO xprt=%p, "
280 "cm_id=%p\n", xprt, cma_id);
281 clear_bit(RDMAXPRT_CONN_PENDING, &rdma->sc_flags);
282 svc_xprt_enqueue(xprt);
284 case RDMA_CM_EVENT_DISCONNECTED:
285 dprintk("svcrdma: Disconnect on DTO xprt=%p, cm_id=%p\n",
287 set_bit(XPT_CLOSE, &xprt->xpt_flags);
288 svc_xprt_enqueue(xprt);
291 case RDMA_CM_EVENT_DEVICE_REMOVAL:
292 dprintk("svcrdma: Device removal cma_id=%p, xprt = %p, "
293 "event = %s (%d)\n", cma_id, xprt,
294 rdma_event_msg(event->event), event->event);
295 set_bit(XPT_CLOSE, &xprt->xpt_flags);
296 svc_xprt_enqueue(xprt);
300 dprintk("svcrdma: Unexpected event on DTO endpoint %p, "
301 "event = %s (%d)\n", cma_id,
302 rdma_event_msg(event->event), event->event);
309 * Create a listening RDMA service endpoint.
311 static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
313 struct sockaddr *sa, int salen,
316 struct rdma_cm_id *listen_id;
317 struct svcxprt_rdma *cma_xprt;
320 dprintk("svcrdma: Creating RDMA listener\n");
321 if ((sa->sa_family != AF_INET) && (sa->sa_family != AF_INET6)) {
322 dprintk("svcrdma: Address family %d is not supported.\n", sa->sa_family);
323 return ERR_PTR(-EAFNOSUPPORT);
325 cma_xprt = svc_rdma_create_xprt(serv, net);
327 return ERR_PTR(-ENOMEM);
328 set_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
329 strcpy(cma_xprt->sc_xprt.xpt_remotebuf, "listener");
331 listen_id = rdma_create_id(net, rdma_listen_handler, cma_xprt,
332 RDMA_PS_TCP, IB_QPT_RC);
333 if (IS_ERR(listen_id)) {
334 ret = PTR_ERR(listen_id);
335 dprintk("svcrdma: rdma_create_id failed = %d\n", ret);
339 /* Allow both IPv4 and IPv6 sockets to bind a single port
342 #if IS_ENABLED(CONFIG_IPV6)
343 ret = rdma_set_afonly(listen_id, 1);
345 dprintk("svcrdma: rdma_set_afonly failed = %d\n", ret);
349 ret = rdma_bind_addr(listen_id, sa);
351 dprintk("svcrdma: rdma_bind_addr failed = %d\n", ret);
354 cma_xprt->sc_cm_id = listen_id;
356 ret = rdma_listen(listen_id, RPCRDMA_LISTEN_BACKLOG);
358 dprintk("svcrdma: rdma_listen failed = %d\n", ret);
363 * We need to use the address from the cm_id in case the
364 * caller specified 0 for the port number.
366 sa = (struct sockaddr *)&cma_xprt->sc_cm_id->route.addr.src_addr;
367 svc_xprt_set_local(&cma_xprt->sc_xprt, sa, salen);
369 return &cma_xprt->sc_xprt;
372 rdma_destroy_id(listen_id);
379 * This is the xpo_recvfrom function for listening endpoints. Its
380 * purpose is to accept incoming connections. The CMA callback handler
381 * has already created a new transport and attached it to the new CMA
384 * There is a queue of pending connections hung on the listening
385 * transport. This queue contains the new svc_xprt structure. This
386 * function takes svc_xprt structures off the accept_q and completes
389 static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
391 struct svcxprt_rdma *listen_rdma;
392 struct svcxprt_rdma *newxprt = NULL;
393 struct rdma_conn_param conn_param;
394 struct rpcrdma_connect_private pmsg;
395 struct ib_qp_init_attr qp_attr;
396 unsigned int ctxts, rq_depth;
397 struct ib_device *dev;
399 RPC_IFDEBUG(struct sockaddr *sap);
401 listen_rdma = container_of(xprt, struct svcxprt_rdma, sc_xprt);
402 clear_bit(XPT_CONN, &xprt->xpt_flags);
403 /* Get the next entry off the accept list */
404 spin_lock_bh(&listen_rdma->sc_lock);
405 if (!list_empty(&listen_rdma->sc_accept_q)) {
406 newxprt = list_entry(listen_rdma->sc_accept_q.next,
407 struct svcxprt_rdma, sc_accept_q);
408 list_del_init(&newxprt->sc_accept_q);
410 if (!list_empty(&listen_rdma->sc_accept_q))
411 set_bit(XPT_CONN, &listen_rdma->sc_xprt.xpt_flags);
412 spin_unlock_bh(&listen_rdma->sc_lock);
416 dprintk("svcrdma: newxprt from accept queue = %p, cm_id=%p\n",
417 newxprt, newxprt->sc_cm_id);
419 dev = newxprt->sc_cm_id->device;
420 newxprt->sc_port_num = newxprt->sc_cm_id->port_num;
422 /* Qualify the transport resource defaults with the
423 * capabilities of this particular device */
424 /* Transport header, head iovec, tail iovec */
425 newxprt->sc_max_send_sges = 3;
426 /* Add one SGE per page list entry */
427 newxprt->sc_max_send_sges += (svcrdma_max_req_size / PAGE_SIZE) + 1;
428 if (newxprt->sc_max_send_sges > dev->attrs.max_send_sge)
429 newxprt->sc_max_send_sges = dev->attrs.max_send_sge;
430 newxprt->sc_max_req_size = svcrdma_max_req_size;
431 newxprt->sc_max_requests = svcrdma_max_requests;
432 newxprt->sc_max_bc_requests = svcrdma_max_bc_requests;
433 rq_depth = newxprt->sc_max_requests + newxprt->sc_max_bc_requests;
434 if (rq_depth > dev->attrs.max_qp_wr) {
435 pr_warn("svcrdma: reducing receive depth to %d\n",
436 dev->attrs.max_qp_wr);
437 rq_depth = dev->attrs.max_qp_wr;
438 newxprt->sc_max_requests = rq_depth - 2;
439 newxprt->sc_max_bc_requests = 2;
441 newxprt->sc_fc_credits = cpu_to_be32(newxprt->sc_max_requests);
442 ctxts = rdma_rw_mr_factor(dev, newxprt->sc_port_num, RPCSVC_MAXPAGES);
443 ctxts *= newxprt->sc_max_requests;
444 newxprt->sc_sq_depth = rq_depth + ctxts;
445 if (newxprt->sc_sq_depth > dev->attrs.max_qp_wr) {
446 pr_warn("svcrdma: reducing send depth to %d\n",
447 dev->attrs.max_qp_wr);
448 newxprt->sc_sq_depth = dev->attrs.max_qp_wr;
450 atomic_set(&newxprt->sc_sq_avail, newxprt->sc_sq_depth);
452 newxprt->sc_pd = ib_alloc_pd(dev, 0);
453 if (IS_ERR(newxprt->sc_pd)) {
454 dprintk("svcrdma: error creating PD for connect request\n");
457 newxprt->sc_sq_cq = ib_alloc_cq(dev, newxprt, newxprt->sc_sq_depth,
458 0, IB_POLL_WORKQUEUE);
459 if (IS_ERR(newxprt->sc_sq_cq)) {
460 dprintk("svcrdma: error creating SQ CQ for connect request\n");
463 newxprt->sc_rq_cq = ib_alloc_cq(dev, newxprt, rq_depth,
464 0, IB_POLL_WORKQUEUE);
465 if (IS_ERR(newxprt->sc_rq_cq)) {
466 dprintk("svcrdma: error creating RQ CQ for connect request\n");
470 memset(&qp_attr, 0, sizeof qp_attr);
471 qp_attr.event_handler = qp_event_handler;
472 qp_attr.qp_context = &newxprt->sc_xprt;
473 qp_attr.port_num = newxprt->sc_port_num;
474 qp_attr.cap.max_rdma_ctxs = ctxts;
475 qp_attr.cap.max_send_wr = newxprt->sc_sq_depth - ctxts;
476 qp_attr.cap.max_recv_wr = rq_depth;
477 qp_attr.cap.max_send_sge = newxprt->sc_max_send_sges;
478 qp_attr.cap.max_recv_sge = 1;
479 qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
480 qp_attr.qp_type = IB_QPT_RC;
481 qp_attr.send_cq = newxprt->sc_sq_cq;
482 qp_attr.recv_cq = newxprt->sc_rq_cq;
483 dprintk("svcrdma: newxprt->sc_cm_id=%p, newxprt->sc_pd=%p\n",
484 newxprt->sc_cm_id, newxprt->sc_pd);
485 dprintk(" cap.max_send_wr = %d, cap.max_recv_wr = %d\n",
486 qp_attr.cap.max_send_wr, qp_attr.cap.max_recv_wr);
487 dprintk(" cap.max_send_sge = %d, cap.max_recv_sge = %d\n",
488 qp_attr.cap.max_send_sge, qp_attr.cap.max_recv_sge);
490 ret = rdma_create_qp(newxprt->sc_cm_id, newxprt->sc_pd, &qp_attr);
492 dprintk("svcrdma: failed to create QP, ret=%d\n", ret);
495 newxprt->sc_qp = newxprt->sc_cm_id->qp;
497 if (!(dev->attrs.device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS))
498 newxprt->sc_snd_w_inv = false;
499 if (!rdma_protocol_iwarp(dev, newxprt->sc_port_num) &&
500 !rdma_ib_or_roce(dev, newxprt->sc_port_num))
503 if (!svc_rdma_post_recvs(newxprt))
506 /* Swap out the handler */
507 newxprt->sc_cm_id->event_handler = rdma_cma_handler;
509 /* Construct RDMA-CM private message */
510 pmsg.cp_magic = rpcrdma_cmp_magic;
511 pmsg.cp_version = RPCRDMA_CMP_VERSION;
513 pmsg.cp_send_size = pmsg.cp_recv_size =
514 rpcrdma_encode_buffer_size(newxprt->sc_max_req_size);
516 /* Accept Connection */
517 set_bit(RDMAXPRT_CONN_PENDING, &newxprt->sc_flags);
518 memset(&conn_param, 0, sizeof conn_param);
519 conn_param.responder_resources = 0;
520 conn_param.initiator_depth = min_t(int, newxprt->sc_ord,
521 dev->attrs.max_qp_init_rd_atom);
522 if (!conn_param.initiator_depth) {
523 dprintk("svcrdma: invalid ORD setting\n");
527 conn_param.private_data = &pmsg;
528 conn_param.private_data_len = sizeof(pmsg);
529 ret = rdma_accept(newxprt->sc_cm_id, &conn_param);
533 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
534 dprintk("svcrdma: new connection %p accepted:\n", newxprt);
535 sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
536 dprintk(" local address : %pIS:%u\n", sap, rpc_get_port(sap));
537 sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
538 dprintk(" remote address : %pIS:%u\n", sap, rpc_get_port(sap));
539 dprintk(" max_sge : %d\n", newxprt->sc_max_send_sges);
540 dprintk(" sq_depth : %d\n", newxprt->sc_sq_depth);
541 dprintk(" rdma_rw_ctxs : %d\n", ctxts);
542 dprintk(" max_requests : %d\n", newxprt->sc_max_requests);
543 dprintk(" ord : %d\n", conn_param.initiator_depth);
546 trace_svcrdma_xprt_accept(&newxprt->sc_xprt);
547 return &newxprt->sc_xprt;
550 dprintk("svcrdma: failure accepting new connection rc=%d.\n", ret);
551 trace_svcrdma_xprt_fail(&newxprt->sc_xprt);
552 /* Take a reference in case the DTO handler runs */
553 svc_xprt_get(&newxprt->sc_xprt);
554 if (newxprt->sc_qp && !IS_ERR(newxprt->sc_qp))
555 ib_destroy_qp(newxprt->sc_qp);
556 rdma_destroy_id(newxprt->sc_cm_id);
557 /* This call to put will destroy the transport */
558 svc_xprt_put(&newxprt->sc_xprt);
562 static void svc_rdma_release_rqst(struct svc_rqst *rqstp)
567 * When connected, an svc_xprt has at least two references:
569 * - A reference held by the cm_id between the ESTABLISHED and
570 * DISCONNECTED events. If the remote peer disconnected first, this
571 * reference could be gone.
573 * - A reference held by the svc_recv code that called this function
574 * as part of close processing.
576 * At a minimum one references should still be held.
578 static void svc_rdma_detach(struct svc_xprt *xprt)
580 struct svcxprt_rdma *rdma =
581 container_of(xprt, struct svcxprt_rdma, sc_xprt);
583 /* Disconnect and flush posted WQE */
584 rdma_disconnect(rdma->sc_cm_id);
587 static void __svc_rdma_free(struct work_struct *work)
589 struct svcxprt_rdma *rdma =
590 container_of(work, struct svcxprt_rdma, sc_work);
591 struct svc_xprt *xprt = &rdma->sc_xprt;
593 trace_svcrdma_xprt_free(xprt);
595 if (rdma->sc_qp && !IS_ERR(rdma->sc_qp))
596 ib_drain_qp(rdma->sc_qp);
598 svc_rdma_flush_recv_queues(rdma);
600 /* Final put of backchannel client transport */
601 if (xprt->xpt_bc_xprt) {
602 xprt_put(xprt->xpt_bc_xprt);
603 xprt->xpt_bc_xprt = NULL;
606 svc_rdma_destroy_rw_ctxts(rdma);
607 svc_rdma_send_ctxts_destroy(rdma);
608 svc_rdma_recv_ctxts_destroy(rdma);
610 /* Destroy the QP if present (not a listener) */
611 if (rdma->sc_qp && !IS_ERR(rdma->sc_qp))
612 ib_destroy_qp(rdma->sc_qp);
614 if (rdma->sc_sq_cq && !IS_ERR(rdma->sc_sq_cq))
615 ib_free_cq(rdma->sc_sq_cq);
617 if (rdma->sc_rq_cq && !IS_ERR(rdma->sc_rq_cq))
618 ib_free_cq(rdma->sc_rq_cq);
620 if (rdma->sc_pd && !IS_ERR(rdma->sc_pd))
621 ib_dealloc_pd(rdma->sc_pd);
623 /* Destroy the CM ID */
624 rdma_destroy_id(rdma->sc_cm_id);
629 static void svc_rdma_free(struct svc_xprt *xprt)
631 struct svcxprt_rdma *rdma =
632 container_of(xprt, struct svcxprt_rdma, sc_xprt);
633 INIT_WORK(&rdma->sc_work, __svc_rdma_free);
634 queue_work(svc_rdma_wq, &rdma->sc_work);
637 static int svc_rdma_has_wspace(struct svc_xprt *xprt)
639 struct svcxprt_rdma *rdma =
640 container_of(xprt, struct svcxprt_rdma, sc_xprt);
643 * If there are already waiters on the SQ,
646 if (waitqueue_active(&rdma->sc_send_wait))
649 /* Otherwise return true. */
653 static void svc_rdma_secure_port(struct svc_rqst *rqstp)
655 set_bit(RQ_SECURE, &rqstp->rq_flags);
658 static void svc_rdma_kill_temp_xprt(struct svc_xprt *xprt)