blob: 1bf7b1ee569944c7f270c01c2875eb7bc84b1224 [file] [log] [blame]
\"Talpey, Thomas\f58851e2007-09-10 13:50:12 -04001/*
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04002 * Copyright (c) 2003-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.
\"Talpey, Thomas\f58851e2007-09-10 13:50:12 -040038 */
39
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040040/*
41 * verbs.c
42 *
43 * Encapsulates the major functions managing:
44 * o adapters
45 * o endpoints
46 * o connections
47 * o buffer memory
48 */
49
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000050#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090051#include <linux/slab.h>
Chuck Levereba8ff62015-01-21 11:03:02 -050052#include <linux/prefetch.h>
Chuck Lever0dd39ca2015-03-30 14:33:43 -040053#include <linux/sunrpc/addr.h>
Chuck Lever05c97462016-09-06 11:22:58 -040054#include <linux/sunrpc/svc_rdma.h>
Chuck Leverae729502017-10-20 10:48:12 -040055
56#include <asm-generic/barrier.h>
Chuck Lever65866f82014-05-28 10:33:59 -040057#include <asm/bitops.h>
Chuck Lever56a6bd12017-04-11 13:23:34 -040058
Chuck Lever0a904872017-02-08 17:00:35 -050059#include <rdma/ib_cm.h>
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040060
\"Talpey, Thomas\f58851e2007-09-10 13:50:12 -040061#include "xprt_rdma.h"
62
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040063/*
64 * Globals/Macros
65 */
66
Jeff Laytonf895b252014-11-17 16:58:04 -050067#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040068# define RPCDBG_FACILITY RPCDBG_TRANS
69#endif
70
71/*
72 * internal functions
73 */
Chuck Levera9b0e382017-04-11 13:23:26 -040074static void rpcrdma_create_mrs(struct rpcrdma_xprt *r_xprt);
Chuck Leverbebd0312017-04-11 13:23:10 -040075static void rpcrdma_destroy_mrs(struct rpcrdma_buffer *buf);
76static void rpcrdma_dma_unmap_regbuf(struct rpcrdma_regbuf *rb);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040077
Chuck Leverd8f532d2017-10-16 15:01:30 -040078struct workqueue_struct *rpcrdma_receive_wq __read_mostly;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040079
Chuck Leverfe97b472015-10-24 17:27:10 -040080int
81rpcrdma_alloc_wq(void)
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040082{
Chuck Leverfe97b472015-10-24 17:27:10 -040083 struct workqueue_struct *recv_wq;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040084
Chuck Leverfe97b472015-10-24 17:27:10 -040085 recv_wq = alloc_workqueue("xprtrdma_receive",
86 WQ_MEM_RECLAIM | WQ_UNBOUND | WQ_HIGHPRI,
87 0);
88 if (!recv_wq)
89 return -ENOMEM;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040090
Chuck Leverfe97b472015-10-24 17:27:10 -040091 rpcrdma_receive_wq = recv_wq;
92 return 0;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -040093}
94
Chuck Leverfe97b472015-10-24 17:27:10 -040095void
96rpcrdma_destroy_wq(void)
Chuck Leverf1a03b72014-11-08 20:14:37 -050097{
Chuck Leverfe97b472015-10-24 17:27:10 -040098 struct workqueue_struct *wq;
Chuck Leverf1a03b72014-11-08 20:14:37 -050099
Chuck Leverfe97b472015-10-24 17:27:10 -0400100 if (rpcrdma_receive_wq) {
101 wq = rpcrdma_receive_wq;
102 rpcrdma_receive_wq = NULL;
103 destroy_workqueue(wq);
104 }
Chuck Leverf1a03b72014-11-08 20:14:37 -0500105}
106
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400107static void
108rpcrdma_qp_async_error_upcall(struct ib_event *event, void *context)
109{
110 struct rpcrdma_ep *ep = context;
111
Chuck Lever2f6922c2016-11-29 10:53:21 -0500112 pr_err("rpcrdma: %s on device %s ep %p\n",
113 ib_event_msg(event->event), event->device->name, context);
114
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400115 if (ep->rep_connected == 1) {
116 ep->rep_connected = -EIO;
Chuck Leverafadc462015-01-21 11:03:11 -0500117 rpcrdma_conn_func(ep);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400118 wake_up_all(&ep->rep_connect_wait);
119 }
120}
121
Chuck Lever2fa8f882016-03-04 11:28:53 -0500122/**
123 * rpcrdma_wc_send - Invoked by RDMA provider for each polled Send WC
124 * @cq: completion queue (ignored)
125 * @wc: completed WR
126 *
Chuck Lever4220a072015-10-24 17:26:45 -0400127 */
128static void
Chuck Lever2fa8f882016-03-04 11:28:53 -0500129rpcrdma_wc_send(struct ib_cq *cq, struct ib_wc *wc)
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400130{
Chuck Leverae729502017-10-20 10:48:12 -0400131 struct ib_cqe *cqe = wc->wr_cqe;
132 struct rpcrdma_sendctx *sc =
133 container_of(cqe, struct rpcrdma_sendctx, sc_cqe);
134
Chuck Lever2fa8f882016-03-04 11:28:53 -0500135 /* WARNING: Only wr_cqe and status are reliable at this point */
136 if (wc->status != IB_WC_SUCCESS && wc->status != IB_WC_WR_FLUSH_ERR)
137 pr_err("rpcrdma: Send: %s (%u/0x%x)\n",
138 ib_wc_status_msg(wc->status),
139 wc->status, wc->vendor_err);
Chuck Leverae729502017-10-20 10:48:12 -0400140
141 rpcrdma_sendctx_put_locked(sc);
Chuck Leverfc664482014-05-28 10:33:25 -0400142}
143
Chuck Lever552bf222016-03-04 11:28:36 -0500144/**
Chuck Lever1519e962016-09-15 10:57:49 -0400145 * rpcrdma_wc_receive - Invoked by RDMA provider for each polled Receive WC
Chuck Lever552bf222016-03-04 11:28:36 -0500146 * @cq: completion queue (ignored)
147 * @wc: completed WR
148 *
149 */
Chuck Leverfe97b472015-10-24 17:27:10 -0400150static void
Chuck Lever1519e962016-09-15 10:57:49 -0400151rpcrdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc)
Chuck Leverfc664482014-05-28 10:33:25 -0400152{
Chuck Lever552bf222016-03-04 11:28:36 -0500153 struct ib_cqe *cqe = wc->wr_cqe;
154 struct rpcrdma_rep *rep = container_of(cqe, struct rpcrdma_rep,
155 rr_cqe);
Chuck Leverfc664482014-05-28 10:33:25 -0400156
Chuck Lever85024272015-01-21 11:02:04 -0500157 /* WARNING: Only wr_id and status are reliable at this point */
158 if (wc->status != IB_WC_SUCCESS)
159 goto out_fail;
Chuck Leverfc664482014-05-28 10:33:25 -0400160
Chuck Lever85024272015-01-21 11:02:04 -0500161 /* status == SUCCESS means all fields in wc are trustworthy */
Chuck Lever85024272015-01-21 11:02:04 -0500162 dprintk("RPC: %s: rep %p opcode 'recv', length %u: success\n",
163 __func__, rep, wc->byte_len);
164
Chuck Lever96f87782017-08-03 14:30:03 -0400165 rpcrdma_set_xdrlen(&rep->rr_hdrbuf, wc->byte_len);
Chuck Leverc8b920b2016-09-15 10:57:16 -0400166 rep->rr_wc_flags = wc->wc_flags;
167 rep->rr_inv_rkey = wc->ex.invalidate_rkey;
168
Chuck Lever91a10c52017-04-11 13:23:02 -0400169 ib_dma_sync_single_for_cpu(rdmab_device(rep->rr_rdmabuf),
Chuck Lever6b1184c2015-01-21 11:04:25 -0500170 rdmab_addr(rep->rr_rdmabuf),
Chuck Levere2a67192017-08-03 14:30:44 -0400171 wc->byte_len, DMA_FROM_DEVICE);
Chuck Lever23826c72016-03-04 11:28:27 -0500172
Chuck Leverfc664482014-05-28 10:33:25 -0400173out_schedule:
Chuck Leverd8f532d2017-10-16 15:01:30 -0400174 rpcrdma_reply_handler(rep);
Chuck Lever85024272015-01-21 11:02:04 -0500175 return;
Chuck Leverfe97b472015-10-24 17:27:10 -0400176
Chuck Lever85024272015-01-21 11:02:04 -0500177out_fail:
178 if (wc->status != IB_WC_WR_FLUSH_ERR)
Chuck Lever552bf222016-03-04 11:28:36 -0500179 pr_err("rpcrdma: Recv: %s (%u/0x%x)\n",
180 ib_wc_status_msg(wc->status),
181 wc->status, wc->vendor_err);
Chuck Levere2a67192017-08-03 14:30:44 -0400182 rpcrdma_set_xdrlen(&rep->rr_hdrbuf, 0);
Chuck Lever85024272015-01-21 11:02:04 -0500183 goto out_schedule;
Chuck Leverfc664482014-05-28 10:33:25 -0400184}
185
Chuck Lever87cfb9a2016-09-15 10:57:07 -0400186static void
187rpcrdma_update_connect_private(struct rpcrdma_xprt *r_xprt,
188 struct rdma_conn_param *param)
189{
190 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
191 const struct rpcrdma_connect_private *pmsg = param->private_data;
192 unsigned int rsize, wsize;
193
Chuck Leverc8b920b2016-09-15 10:57:16 -0400194 /* Default settings for RPC-over-RDMA Version One */
195 r_xprt->rx_ia.ri_reminv_expected = false;
Chuck Leverb5f0afb2017-02-08 16:59:54 -0500196 r_xprt->rx_ia.ri_implicit_roundup = xprt_rdma_pad_optimize;
Chuck Lever87cfb9a2016-09-15 10:57:07 -0400197 rsize = RPCRDMA_V1_DEF_INLINE_SIZE;
198 wsize = RPCRDMA_V1_DEF_INLINE_SIZE;
199
200 if (pmsg &&
201 pmsg->cp_magic == rpcrdma_cmp_magic &&
202 pmsg->cp_version == RPCRDMA_CMP_VERSION) {
Chuck Leverc8b920b2016-09-15 10:57:16 -0400203 r_xprt->rx_ia.ri_reminv_expected = true;
Chuck Leverc95a3c62017-02-08 17:00:02 -0500204 r_xprt->rx_ia.ri_implicit_roundup = true;
Chuck Lever87cfb9a2016-09-15 10:57:07 -0400205 rsize = rpcrdma_decode_buffer_size(pmsg->cp_send_size);
206 wsize = rpcrdma_decode_buffer_size(pmsg->cp_recv_size);
207 }
208
209 if (rsize < cdata->inline_rsize)
210 cdata->inline_rsize = rsize;
211 if (wsize < cdata->inline_wsize)
212 cdata->inline_wsize = wsize;
Chuck Lever6d6bf722016-11-29 10:53:13 -0500213 dprintk("RPC: %s: max send %u, max recv %u\n",
214 __func__, cdata->inline_wsize, cdata->inline_rsize);
Chuck Lever87cfb9a2016-09-15 10:57:07 -0400215 rpcrdma_set_max_header_sizes(r_xprt);
216}
217
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400218static int
219rpcrdma_conn_upcall(struct rdma_cm_id *id, struct rdma_cm_event *event)
220{
221 struct rpcrdma_xprt *xprt = id->context;
222 struct rpcrdma_ia *ia = &xprt->rx_ia;
223 struct rpcrdma_ep *ep = &xprt->rx_ep;
Jeff Laytonf895b252014-11-17 16:58:04 -0500224#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Chuck Lever0dd39ca2015-03-30 14:33:43 -0400225 struct sockaddr *sap = (struct sockaddr *)&ep->rep_remote_addr;
Ingo Molnarff0db042008-11-25 16:58:42 -0800226#endif
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400227 int connstate = 0;
228
229 switch (event->event) {
230 case RDMA_CM_EVENT_ADDR_RESOLVED:
231 case RDMA_CM_EVENT_ROUTE_RESOLVED:
Tom Talpey5675add2008-10-09 15:01:41 -0400232 ia->ri_async_rc = 0;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400233 complete(&ia->ri_done);
234 break;
235 case RDMA_CM_EVENT_ADDR_ERROR:
236 ia->ri_async_rc = -EHOSTUNREACH;
237 dprintk("RPC: %s: CM address resolution error, ep 0x%p\n",
238 __func__, ep);
239 complete(&ia->ri_done);
240 break;
241 case RDMA_CM_EVENT_ROUTE_ERROR:
242 ia->ri_async_rc = -ENETUNREACH;
243 dprintk("RPC: %s: CM route resolution error, ep 0x%p\n",
244 __func__, ep);
245 complete(&ia->ri_done);
246 break;
Chuck Leverbebd0312017-04-11 13:23:10 -0400247 case RDMA_CM_EVENT_DEVICE_REMOVAL:
248#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Chuck Lever173b8f42017-06-08 11:53:00 -0400249 pr_info("rpcrdma: removing device %s for %pIS:%u\n",
250 ia->ri_device->name,
Chuck Leverbebd0312017-04-11 13:23:10 -0400251 sap, rpc_get_port(sap));
252#endif
253 set_bit(RPCRDMA_IAF_REMOVING, &ia->ri_flags);
254 ep->rep_connected = -ENODEV;
255 xprt_force_disconnect(&xprt->rx_xprt);
256 wait_for_completion(&ia->ri_remove_done);
257
258 ia->ri_id = NULL;
259 ia->ri_pd = NULL;
260 ia->ri_device = NULL;
261 /* Return 1 to ensure the core destroys the id. */
262 return 1;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400263 case RDMA_CM_EVENT_ESTABLISHED:
264 connstate = 1;
Chuck Lever87cfb9a2016-09-15 10:57:07 -0400265 rpcrdma_update_connect_private(xprt, &event->param.conn);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400266 goto connected;
267 case RDMA_CM_EVENT_CONNECT_ERROR:
268 connstate = -ENOTCONN;
269 goto connected;
270 case RDMA_CM_EVENT_UNREACHABLE:
271 connstate = -ENETDOWN;
272 goto connected;
273 case RDMA_CM_EVENT_REJECTED:
Chuck Lever173b8f42017-06-08 11:53:00 -0400274 dprintk("rpcrdma: connection to %pIS:%u rejected: %s\n",
275 sap, rpc_get_port(sap),
Chuck Lever0a904872017-02-08 17:00:35 -0500276 rdma_reject_msg(id, event->status));
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400277 connstate = -ECONNREFUSED;
Chuck Lever0a904872017-02-08 17:00:35 -0500278 if (event->status == IB_CM_REJ_STALE_CONN)
279 connstate = -EAGAIN;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400280 goto connected;
281 case RDMA_CM_EVENT_DISCONNECTED:
282 connstate = -ECONNABORTED;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400283connected:
Chuck Leverbe798f92017-10-16 15:01:39 -0400284 xprt->rx_buf.rb_credits = 1;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400285 ep->rep_connected = connstate;
Chuck Leverafadc462015-01-21 11:03:11 -0500286 rpcrdma_conn_func(ep);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400287 wake_up_all(&ep->rep_connect_wait);
Chuck Lever8079fb72014-07-29 17:26:12 -0400288 /*FALLTHROUGH*/
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400289 default:
Chuck Lever173b8f42017-06-08 11:53:00 -0400290 dprintk("RPC: %s: %pIS:%u on %s/%s (ep 0x%p): %s\n",
291 __func__, sap, rpc_get_port(sap),
292 ia->ri_device->name, ia->ri_ops->ro_displayname,
293 ep, rdma_event_msg(event->event));
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400294 break;
295 }
296
297 return 0;
298}
299
300static struct rdma_cm_id *
301rpcrdma_create_id(struct rpcrdma_xprt *xprt,
302 struct rpcrdma_ia *ia, struct sockaddr *addr)
303{
Chuck Lever109b88a2016-11-29 10:52:40 -0500304 unsigned long wtimeout = msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT) + 1;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400305 struct rdma_cm_id *id;
306 int rc;
307
Tom Talpey1a954052008-10-09 15:01:31 -0400308 init_completion(&ia->ri_done);
Chuck Leverbebd0312017-04-11 13:23:10 -0400309 init_completion(&ia->ri_remove_done);
Tom Talpey1a954052008-10-09 15:01:31 -0400310
Guy Shapirofa201052015-10-22 15:20:10 +0300311 id = rdma_create_id(&init_net, rpcrdma_conn_upcall, xprt, RDMA_PS_TCP,
312 IB_QPT_RC);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400313 if (IS_ERR(id)) {
314 rc = PTR_ERR(id);
315 dprintk("RPC: %s: rdma_create_id() failed %i\n",
316 __func__, rc);
317 return id;
318 }
319
Tom Talpey5675add2008-10-09 15:01:41 -0400320 ia->ri_async_rc = -ETIMEDOUT;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400321 rc = rdma_resolve_addr(id, NULL, addr, RDMA_RESOLVE_TIMEOUT);
322 if (rc) {
323 dprintk("RPC: %s: rdma_resolve_addr() failed %i\n",
324 __func__, rc);
325 goto out;
326 }
Chuck Lever109b88a2016-11-29 10:52:40 -0500327 rc = wait_for_completion_interruptible_timeout(&ia->ri_done, wtimeout);
328 if (rc < 0) {
329 dprintk("RPC: %s: wait() exited: %i\n",
330 __func__, rc);
331 goto out;
332 }
Devesh Sharmad0f36c42015-08-03 13:05:04 -0400333
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400334 rc = ia->ri_async_rc;
335 if (rc)
336 goto out;
337
Tom Talpey5675add2008-10-09 15:01:41 -0400338 ia->ri_async_rc = -ETIMEDOUT;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400339 rc = rdma_resolve_route(id, RDMA_RESOLVE_TIMEOUT);
340 if (rc) {
341 dprintk("RPC: %s: rdma_resolve_route() failed %i\n",
342 __func__, rc);
Chuck Lever56a6bd12017-04-11 13:23:34 -0400343 goto out;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400344 }
Chuck Lever109b88a2016-11-29 10:52:40 -0500345 rc = wait_for_completion_interruptible_timeout(&ia->ri_done, wtimeout);
346 if (rc < 0) {
347 dprintk("RPC: %s: wait() exited: %i\n",
348 __func__, rc);
Chuck Lever56a6bd12017-04-11 13:23:34 -0400349 goto out;
Chuck Lever109b88a2016-11-29 10:52:40 -0500350 }
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400351 rc = ia->ri_async_rc;
352 if (rc)
Chuck Lever56a6bd12017-04-11 13:23:34 -0400353 goto out;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400354
355 return id;
Chuck Lever56a6bd12017-04-11 13:23:34 -0400356
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400357out:
358 rdma_destroy_id(id);
359 return ERR_PTR(rc);
360}
361
362/*
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400363 * Exported functions.
364 */
365
Chuck Leverfff09592017-04-11 13:22:54 -0400366/**
367 * rpcrdma_ia_open - Open and initialize an Interface Adapter.
368 * @xprt: controlling transport
369 * @addr: IP address of remote peer
370 *
371 * Returns 0 on success, negative errno if an appropriate
372 * Interface Adapter could not be found and opened.
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400373 */
374int
Chuck Leverfff09592017-04-11 13:22:54 -0400375rpcrdma_ia_open(struct rpcrdma_xprt *xprt, struct sockaddr *addr)
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400376{
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400377 struct rpcrdma_ia *ia = &xprt->rx_ia;
Chuck Leverd1ed8572015-08-03 13:03:30 -0400378 int rc;
379
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400380 ia->ri_id = rpcrdma_create_id(xprt, ia, addr);
381 if (IS_ERR(ia->ri_id)) {
382 rc = PTR_ERR(ia->ri_id);
Chuck Leverfff09592017-04-11 13:22:54 -0400383 goto out_err;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400384 }
Chuck Lever89e0d1122015-05-26 11:51:56 -0400385 ia->ri_device = ia->ri_id->device;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400386
Christoph Hellwiged082d32016-09-05 12:56:17 +0200387 ia->ri_pd = ib_alloc_pd(ia->ri_device, 0);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400388 if (IS_ERR(ia->ri_pd)) {
389 rc = PTR_ERR(ia->ri_pd);
Chuck Leverb54054c2016-06-29 13:53:27 -0400390 pr_err("rpcrdma: ib_alloc_pd() returned %d\n", rc);
Chuck Leverfff09592017-04-11 13:22:54 -0400391 goto out_err;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400392 }
393
Chuck Leverfff09592017-04-11 13:22:54 -0400394 switch (xprt_rdma_memreg_strategy) {
Tom Talpey3197d3092008-10-09 15:00:20 -0400395 case RPCRDMA_FRMR:
Chuck Leverb54054c2016-06-29 13:53:27 -0400396 if (frwr_is_supported(ia)) {
397 ia->ri_ops = &rpcrdma_frwr_memreg_ops;
398 break;
399 }
400 /*FALLTHROUGH*/
Tom Talpeybd7ed1d2008-10-09 15:00:09 -0400401 case RPCRDMA_MTHCAFMR:
Chuck Leverb54054c2016-06-29 13:53:27 -0400402 if (fmr_is_supported(ia)) {
403 ia->ri_ops = &rpcrdma_fmr_memreg_ops;
404 break;
405 }
406 /*FALLTHROUGH*/
Tom Talpeybd7ed1d2008-10-09 15:00:09 -0400407 default:
Chuck Leverfff09592017-04-11 13:22:54 -0400408 pr_err("rpcrdma: Device %s does not support memreg mode %d\n",
409 ia->ri_device->name, xprt_rdma_memreg_strategy);
Chuck Leverb54054c2016-06-29 13:53:27 -0400410 rc = -EINVAL;
Chuck Leverfff09592017-04-11 13:22:54 -0400411 goto out_err;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400412 }
413
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400414 return 0;
Chuck Lever5ae711a2015-01-21 11:03:19 -0500415
Chuck Leverfff09592017-04-11 13:22:54 -0400416out_err:
417 rpcrdma_ia_close(ia);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400418 return rc;
419}
420
Chuck Leverfff09592017-04-11 13:22:54 -0400421/**
Chuck Leverbebd0312017-04-11 13:23:10 -0400422 * rpcrdma_ia_remove - Handle device driver unload
423 * @ia: interface adapter being removed
424 *
425 * Divest transport H/W resources associated with this adapter,
426 * but allow it to be restored later.
427 */
428void
429rpcrdma_ia_remove(struct rpcrdma_ia *ia)
430{
431 struct rpcrdma_xprt *r_xprt = container_of(ia, struct rpcrdma_xprt,
432 rx_ia);
433 struct rpcrdma_ep *ep = &r_xprt->rx_ep;
434 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
435 struct rpcrdma_req *req;
436 struct rpcrdma_rep *rep;
437
438 cancel_delayed_work_sync(&buf->rb_refresh_worker);
439
440 /* This is similar to rpcrdma_ep_destroy, but:
441 * - Don't cancel the connect worker.
442 * - Don't call rpcrdma_ep_disconnect, which waits
443 * for another conn upcall, which will deadlock.
444 * - rdma_disconnect is unneeded, the underlying
445 * connection is already gone.
446 */
447 if (ia->ri_id->qp) {
448 ib_drain_qp(ia->ri_id->qp);
449 rdma_destroy_qp(ia->ri_id);
450 ia->ri_id->qp = NULL;
451 }
452 ib_free_cq(ep->rep_attr.recv_cq);
453 ib_free_cq(ep->rep_attr.send_cq);
454
455 /* The ULP is responsible for ensuring all DMA
456 * mappings and MRs are gone.
457 */
458 list_for_each_entry(rep, &buf->rb_recv_bufs, rr_list)
459 rpcrdma_dma_unmap_regbuf(rep->rr_rdmabuf);
460 list_for_each_entry(req, &buf->rb_allreqs, rl_all) {
461 rpcrdma_dma_unmap_regbuf(req->rl_rdmabuf);
462 rpcrdma_dma_unmap_regbuf(req->rl_sendbuf);
463 rpcrdma_dma_unmap_regbuf(req->rl_recvbuf);
464 }
465 rpcrdma_destroy_mrs(buf);
466
467 /* Allow waiters to continue */
468 complete(&ia->ri_remove_done);
469}
470
471/**
Chuck Leverfff09592017-04-11 13:22:54 -0400472 * rpcrdma_ia_close - Clean up/close an IA.
473 * @ia: interface adapter to close
474 *
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400475 */
476void
477rpcrdma_ia_close(struct rpcrdma_ia *ia)
478{
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400479 dprintk("RPC: %s: entering\n", __func__);
Tom Talpeyfee08ca2008-10-09 15:01:00 -0400480 if (ia->ri_id != NULL && !IS_ERR(ia->ri_id)) {
481 if (ia->ri_id->qp)
482 rdma_destroy_qp(ia->ri_id);
Chuck Lever56a6bd12017-04-11 13:23:34 -0400483 rdma_destroy_id(ia->ri_id);
Tom Talpeyfee08ca2008-10-09 15:01:00 -0400484 }
Chuck Leverfff09592017-04-11 13:22:54 -0400485 ia->ri_id = NULL;
486 ia->ri_device = NULL;
Chuck Lever6d446982015-05-26 11:51:27 -0400487
488 /* If the pd is still busy, xprtrdma missed freeing a resource */
489 if (ia->ri_pd && !IS_ERR(ia->ri_pd))
Jason Gunthorpe7dd78642015-08-05 14:34:31 -0600490 ib_dealloc_pd(ia->ri_pd);
Chuck Leverfff09592017-04-11 13:22:54 -0400491 ia->ri_pd = NULL;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400492}
493
494/*
495 * Create unconnected endpoint.
496 */
497int
498rpcrdma_ep_create(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia,
Chuck Lever16f906d2017-02-08 17:00:10 -0500499 struct rpcrdma_create_data_internal *cdata)
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400500{
Chuck Lever87cfb9a2016-09-15 10:57:07 -0400501 struct rpcrdma_connect_private *pmsg = &ep->rep_cm_private;
Chuck Lever16f906d2017-02-08 17:00:10 -0500502 unsigned int max_qp_wr, max_sge;
Chuck Leverfc664482014-05-28 10:33:25 -0400503 struct ib_cq *sendcq, *recvcq;
Chuck Lever2fa8f882016-03-04 11:28:53 -0500504 int rc;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400505
Chuck Levereed50872017-03-11 15:52:47 -0500506 max_sge = min_t(unsigned int, ia->ri_device->attrs.max_sge,
507 RPCRDMA_MAX_SEND_SGES);
Chuck Lever16f906d2017-02-08 17:00:10 -0500508 if (max_sge < RPCRDMA_MIN_SEND_SGES) {
509 pr_warn("rpcrdma: HCA provides only %d send SGEs\n", max_sge);
Chuck Leverb3221d62015-08-03 13:03:39 -0400510 return -ENOMEM;
511 }
Chuck Lever16f906d2017-02-08 17:00:10 -0500512 ia->ri_max_send_sges = max_sge - RPCRDMA_MIN_SEND_SGES;
Chuck Leverb3221d62015-08-03 13:03:39 -0400513
Or Gerlitze3e45b12015-12-18 10:59:48 +0200514 if (ia->ri_device->attrs.max_qp_wr <= RPCRDMA_BACKWARD_WRS) {
Chuck Lever124fa172015-10-24 17:27:51 -0400515 dprintk("RPC: %s: insufficient wqe's available\n",
516 __func__);
517 return -ENOMEM;
518 }
Chuck Lever550d7502016-05-02 14:41:47 -0400519 max_qp_wr = ia->ri_device->attrs.max_qp_wr - RPCRDMA_BACKWARD_WRS - 1;
Chuck Lever124fa172015-10-24 17:27:51 -0400520
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400521 /* check provider's send/recv wr limits */
Chuck Lever124fa172015-10-24 17:27:51 -0400522 if (cdata->max_requests > max_qp_wr)
523 cdata->max_requests = max_qp_wr;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400524
525 ep->rep_attr.event_handler = rpcrdma_qp_async_error_upcall;
526 ep->rep_attr.qp_context = ep;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400527 ep->rep_attr.srq = NULL;
528 ep->rep_attr.cap.max_send_wr = cdata->max_requests;
Chuck Lever124fa172015-10-24 17:27:51 -0400529 ep->rep_attr.cap.max_send_wr += RPCRDMA_BACKWARD_WRS;
Chuck Lever550d7502016-05-02 14:41:47 -0400530 ep->rep_attr.cap.max_send_wr += 1; /* drain cqe */
Chuck Lever3968cb52015-03-30 14:35:26 -0400531 rc = ia->ri_ops->ro_open(ia, ep, cdata);
532 if (rc)
533 return rc;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400534 ep->rep_attr.cap.max_recv_wr = cdata->max_requests;
Chuck Lever124fa172015-10-24 17:27:51 -0400535 ep->rep_attr.cap.max_recv_wr += RPCRDMA_BACKWARD_WRS;
Chuck Lever550d7502016-05-02 14:41:47 -0400536 ep->rep_attr.cap.max_recv_wr += 1; /* drain cqe */
Chuck Lever16f906d2017-02-08 17:00:10 -0500537 ep->rep_attr.cap.max_send_sge = max_sge;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400538 ep->rep_attr.cap.max_recv_sge = 1;
539 ep->rep_attr.cap.max_inline_data = 0;
540 ep->rep_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
541 ep->rep_attr.qp_type = IB_QPT_RC;
542 ep->rep_attr.port_num = ~0;
543
544 dprintk("RPC: %s: requested max: dtos: send %d recv %d; "
545 "iovs: send %d recv %d\n",
546 __func__,
547 ep->rep_attr.cap.max_send_wr,
548 ep->rep_attr.cap.max_recv_wr,
549 ep->rep_attr.cap.max_send_sge,
550 ep->rep_attr.cap.max_recv_sge);
551
552 /* set trigger for requesting send completion */
Chuck Leverae729502017-10-20 10:48:12 -0400553 ep->rep_send_batch = min_t(unsigned int, RPCRDMA_MAX_SEND_BATCH,
554 cdata->max_requests >> 2);
555 ep->rep_send_count = ep->rep_send_batch;
Chuck Leverfc664482014-05-28 10:33:25 -0400556 ep->rep_cqinit = ep->rep_attr.cap.max_send_wr/2 - 1;
Chuck Lever26ae9d12015-12-16 17:23:20 -0500557 if (ep->rep_cqinit <= 2)
558 ep->rep_cqinit = 0; /* always signal? */
Chuck Lever8d38de62016-11-29 10:52:16 -0500559 rpcrdma_init_cqcount(ep, 0);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400560 init_waitqueue_head(&ep->rep_connect_wait);
Chuck Lever254f91e2014-05-28 10:32:17 -0400561 INIT_DELAYED_WORK(&ep->rep_connect_worker, rpcrdma_connect_worker);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400562
Chuck Lever2fa8f882016-03-04 11:28:53 -0500563 sendcq = ib_alloc_cq(ia->ri_device, NULL,
564 ep->rep_attr.cap.max_send_wr + 1,
565 0, IB_POLL_SOFTIRQ);
Chuck Leverfc664482014-05-28 10:33:25 -0400566 if (IS_ERR(sendcq)) {
567 rc = PTR_ERR(sendcq);
568 dprintk("RPC: %s: failed to create send CQ: %i\n",
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400569 __func__, rc);
570 goto out1;
571 }
572
Chuck Lever552bf222016-03-04 11:28:36 -0500573 recvcq = ib_alloc_cq(ia->ri_device, NULL,
574 ep->rep_attr.cap.max_recv_wr + 1,
Chuck Leverd8f532d2017-10-16 15:01:30 -0400575 0, IB_POLL_WORKQUEUE);
Chuck Leverfc664482014-05-28 10:33:25 -0400576 if (IS_ERR(recvcq)) {
577 rc = PTR_ERR(recvcq);
578 dprintk("RPC: %s: failed to create recv CQ: %i\n",
579 __func__, rc);
580 goto out2;
581 }
582
Chuck Leverfc664482014-05-28 10:33:25 -0400583 ep->rep_attr.send_cq = sendcq;
584 ep->rep_attr.recv_cq = recvcq;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400585
586 /* Initialize cma parameters */
Chuck Leverb2dde942016-05-02 14:43:03 -0400587 memset(&ep->rep_remote_cma, 0, sizeof(ep->rep_remote_cma));
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400588
Chuck Lever87cfb9a2016-09-15 10:57:07 -0400589 /* Prepare RDMA-CM private message */
590 pmsg->cp_magic = rpcrdma_cmp_magic;
591 pmsg->cp_version = RPCRDMA_CMP_VERSION;
Chuck Leverc8b920b2016-09-15 10:57:16 -0400592 pmsg->cp_flags |= ia->ri_ops->ro_send_w_inv_ok;
Chuck Lever87cfb9a2016-09-15 10:57:07 -0400593 pmsg->cp_send_size = rpcrdma_encode_buffer_size(cdata->inline_wsize);
594 pmsg->cp_recv_size = rpcrdma_encode_buffer_size(cdata->inline_rsize);
595 ep->rep_remote_cma.private_data = pmsg;
596 ep->rep_remote_cma.private_data_len = sizeof(*pmsg);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400597
598 /* Client offers RDMA Read but does not initiate */
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400599 ep->rep_remote_cma.initiator_depth = 0;
Or Gerlitze3e45b12015-12-18 10:59:48 +0200600 if (ia->ri_device->attrs.max_qp_rd_atom > 32) /* arbitrary but <= 255 */
Tom Tuckerb334eaa2008-10-09 15:00:30 -0400601 ep->rep_remote_cma.responder_resources = 32;
602 else
Chuck Lever7bc79722015-01-21 11:03:27 -0500603 ep->rep_remote_cma.responder_resources =
Or Gerlitze3e45b12015-12-18 10:59:48 +0200604 ia->ri_device->attrs.max_qp_rd_atom;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400605
Chuck Leverb2dde942016-05-02 14:43:03 -0400606 /* Limit transport retries so client can detect server
607 * GID changes quickly. RPC layer handles re-establishing
608 * transport connection and retransmission.
609 */
610 ep->rep_remote_cma.retry_count = 6;
611
612 /* RPC-over-RDMA handles its own flow control. In addition,
613 * make all RNR NAKs visible so we know that RPC-over-RDMA
614 * flow control is working correctly (no NAKs should be seen).
615 */
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400616 ep->rep_remote_cma.flow_control = 0;
617 ep->rep_remote_cma.rnr_retry_count = 0;
618
619 return 0;
620
621out2:
Chuck Lever2fa8f882016-03-04 11:28:53 -0500622 ib_free_cq(sendcq);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400623out1:
624 return rc;
625}
626
627/*
628 * rpcrdma_ep_destroy
629 *
630 * Disconnect and destroy endpoint. After this, the only
631 * valid operations on the ep are to free it (if dynamically
632 * allocated) or re-create it.
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400633 */
Chuck Lever7f1d5412014-05-28 10:33:16 -0400634void
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400635rpcrdma_ep_destroy(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
636{
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400637 dprintk("RPC: %s: entering, connected is %d\n",
638 __func__, ep->rep_connected);
639
Chuck Lever254f91e2014-05-28 10:32:17 -0400640 cancel_delayed_work_sync(&ep->rep_connect_worker);
641
Steve Wise72c02172015-09-21 12:24:23 -0500642 if (ia->ri_id->qp) {
Chuck Lever550d7502016-05-02 14:41:47 -0400643 rpcrdma_ep_disconnect(ep, ia);
Tom Talpeyfee08ca2008-10-09 15:01:00 -0400644 rdma_destroy_qp(ia->ri_id);
645 ia->ri_id->qp = NULL;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400646 }
647
Chuck Lever552bf222016-03-04 11:28:36 -0500648 ib_free_cq(ep->rep_attr.recv_cq);
Chuck Lever2fa8f882016-03-04 11:28:53 -0500649 ib_free_cq(ep->rep_attr.send_cq);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400650}
651
Chuck Levera9b0e382017-04-11 13:23:26 -0400652/* Re-establish a connection after a device removal event.
653 * Unlike a normal reconnection, a fresh PD and a new set
654 * of MRs and buffers is needed.
655 */
656static int
657rpcrdma_ep_recreate_xprt(struct rpcrdma_xprt *r_xprt,
658 struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
659{
660 struct sockaddr *sap = (struct sockaddr *)&r_xprt->rx_data.addr;
661 int rc, err;
662
663 pr_info("%s: r_xprt = %p\n", __func__, r_xprt);
664
665 rc = -EHOSTUNREACH;
666 if (rpcrdma_ia_open(r_xprt, sap))
667 goto out1;
668
669 rc = -ENOMEM;
670 err = rpcrdma_ep_create(ep, ia, &r_xprt->rx_data);
671 if (err) {
672 pr_err("rpcrdma: rpcrdma_ep_create returned %d\n", err);
673 goto out2;
674 }
675
676 rc = -ENETUNREACH;
677 err = rdma_create_qp(ia->ri_id, ia->ri_pd, &ep->rep_attr);
678 if (err) {
679 pr_err("rpcrdma: rdma_create_qp returned %d\n", err);
680 goto out3;
681 }
682
683 rpcrdma_create_mrs(r_xprt);
684 return 0;
685
686out3:
687 rpcrdma_ep_destroy(ep, ia);
688out2:
689 rpcrdma_ia_close(ia);
690out1:
691 return rc;
692}
693
Chuck Lever18908962017-04-11 13:23:18 -0400694static int
695rpcrdma_ep_reconnect(struct rpcrdma_xprt *r_xprt, struct rpcrdma_ep *ep,
696 struct rpcrdma_ia *ia)
697{
698 struct sockaddr *sap = (struct sockaddr *)&r_xprt->rx_data.addr;
699 struct rdma_cm_id *id, *old;
700 int err, rc;
701
702 dprintk("RPC: %s: reconnecting...\n", __func__);
703
704 rpcrdma_ep_disconnect(ep, ia);
705
706 rc = -EHOSTUNREACH;
707 id = rpcrdma_create_id(r_xprt, ia, sap);
708 if (IS_ERR(id))
709 goto out;
710
711 /* As long as the new ID points to the same device as the
712 * old ID, we can reuse the transport's existing PD and all
713 * previously allocated MRs. Also, the same device means
714 * the transport's previous DMA mappings are still valid.
715 *
716 * This is a sanity check only. There should be no way these
717 * point to two different devices here.
718 */
719 old = id;
720 rc = -ENETUNREACH;
721 if (ia->ri_device != id->device) {
722 pr_err("rpcrdma: can't reconnect on different device!\n");
723 goto out_destroy;
724 }
725
726 err = rdma_create_qp(id, ia->ri_pd, &ep->rep_attr);
727 if (err) {
728 dprintk("RPC: %s: rdma_create_qp returned %d\n",
729 __func__, err);
730 goto out_destroy;
731 }
732
733 /* Atomically replace the transport's ID and QP. */
734 rc = 0;
735 old = ia->ri_id;
736 ia->ri_id = id;
737 rdma_destroy_qp(old);
738
739out_destroy:
Chuck Lever56a6bd12017-04-11 13:23:34 -0400740 rdma_destroy_id(old);
Chuck Lever18908962017-04-11 13:23:18 -0400741out:
742 return rc;
743}
744
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400745/*
746 * Connect unconnected endpoint.
747 */
748int
749rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
750{
Chuck Lever0a904872017-02-08 17:00:35 -0500751 struct rpcrdma_xprt *r_xprt = container_of(ia, struct rpcrdma_xprt,
752 rx_ia);
Chuck Lever0a904872017-02-08 17:00:35 -0500753 unsigned int extras;
Chuck Lever18908962017-04-11 13:23:18 -0400754 int rc;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400755
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400756retry:
Chuck Lever18908962017-04-11 13:23:18 -0400757 switch (ep->rep_connected) {
758 case 0:
Chuck Leverec62f402014-05-28 10:34:07 -0400759 dprintk("RPC: %s: connecting...\n", __func__);
760 rc = rdma_create_qp(ia->ri_id, ia->ri_pd, &ep->rep_attr);
761 if (rc) {
762 dprintk("RPC: %s: rdma_create_qp failed %i\n",
763 __func__, rc);
Chuck Lever18908962017-04-11 13:23:18 -0400764 rc = -ENETUNREACH;
765 goto out_noupdate;
Chuck Leverec62f402014-05-28 10:34:07 -0400766 }
Chuck Lever18908962017-04-11 13:23:18 -0400767 break;
Chuck Levera9b0e382017-04-11 13:23:26 -0400768 case -ENODEV:
769 rc = rpcrdma_ep_recreate_xprt(r_xprt, ep, ia);
770 if (rc)
771 goto out_noupdate;
772 break;
Chuck Lever18908962017-04-11 13:23:18 -0400773 default:
774 rc = rpcrdma_ep_reconnect(r_xprt, ep, ia);
775 if (rc)
776 goto out;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400777 }
778
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400779 ep->rep_connected = 0;
780
781 rc = rdma_connect(ia->ri_id, &ep->rep_remote_cma);
782 if (rc) {
783 dprintk("RPC: %s: rdma_connect() failed with %i\n",
784 __func__, rc);
785 goto out;
786 }
787
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400788 wait_event_interruptible(ep->rep_connect_wait, ep->rep_connected != 0);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400789 if (ep->rep_connected <= 0) {
Chuck Lever0a904872017-02-08 17:00:35 -0500790 if (ep->rep_connected == -EAGAIN)
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400791 goto retry;
792 rc = ep->rep_connected;
Chuck Lever0a904872017-02-08 17:00:35 -0500793 goto out;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400794 }
795
Chuck Lever0a904872017-02-08 17:00:35 -0500796 dprintk("RPC: %s: connected\n", __func__);
797 extras = r_xprt->rx_buf.rb_bc_srv_max_requests;
798 if (extras)
799 rpcrdma_ep_post_extra_recv(r_xprt, extras);
800
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400801out:
802 if (rc)
803 ep->rep_connected = rc;
Chuck Lever18908962017-04-11 13:23:18 -0400804
805out_noupdate:
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400806 return rc;
807}
808
809/*
810 * rpcrdma_ep_disconnect
811 *
812 * This is separate from destroy to facilitate the ability
813 * to reconnect without recreating the endpoint.
814 *
815 * This call is not reentrant, and must not be made in parallel
816 * on the same endpoint.
817 */
Chuck Lever282191c2014-07-29 17:25:55 -0400818void
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400819rpcrdma_ep_disconnect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
820{
821 int rc;
822
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400823 rc = rdma_disconnect(ia->ri_id);
824 if (!rc) {
825 /* returns without wait if not connected */
826 wait_event_interruptible(ep->rep_connect_wait,
827 ep->rep_connected != 1);
828 dprintk("RPC: %s: after wait, %sconnected\n", __func__,
829 (ep->rep_connected == 1) ? "still " : "dis");
830 } else {
831 dprintk("RPC: %s: rdma_disconnect %i\n", __func__, rc);
832 ep->rep_connected = rc;
833 }
Chuck Lever550d7502016-05-02 14:41:47 -0400834
835 ib_drain_qp(ia->ri_id->qp);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -0400836}
837
Chuck Leverae729502017-10-20 10:48:12 -0400838/* Fixed-size circular FIFO queue. This implementation is wait-free and
839 * lock-free.
840 *
841 * Consumer is the code path that posts Sends. This path dequeues a
842 * sendctx for use by a Send operation. Multiple consumer threads
843 * are serialized by the RPC transport lock, which allows only one
844 * ->send_request call at a time.
845 *
846 * Producer is the code path that handles Send completions. This path
847 * enqueues a sendctx that has been completed. Multiple producer
848 * threads are serialized by the ib_poll_cq() function.
849 */
850
851/* rpcrdma_sendctxs_destroy() assumes caller has already quiesced
852 * queue activity, and ib_drain_qp has flushed all remaining Send
853 * requests.
854 */
855static void rpcrdma_sendctxs_destroy(struct rpcrdma_buffer *buf)
856{
857 unsigned long i;
858
859 for (i = 0; i <= buf->rb_sc_last; i++)
860 kfree(buf->rb_sc_ctxs[i]);
861 kfree(buf->rb_sc_ctxs);
862}
863
864static struct rpcrdma_sendctx *rpcrdma_sendctx_create(struct rpcrdma_ia *ia)
865{
866 struct rpcrdma_sendctx *sc;
867
868 sc = kzalloc(sizeof(*sc) +
869 ia->ri_max_send_sges * sizeof(struct ib_sge),
870 GFP_KERNEL);
871 if (!sc)
872 return NULL;
873
874 sc->sc_wr.wr_cqe = &sc->sc_cqe;
875 sc->sc_wr.sg_list = sc->sc_sges;
876 sc->sc_wr.opcode = IB_WR_SEND;
877 sc->sc_cqe.done = rpcrdma_wc_send;
878 return sc;
879}
880
881static int rpcrdma_sendctxs_create(struct rpcrdma_xprt *r_xprt)
882{
883 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
884 struct rpcrdma_sendctx *sc;
885 unsigned long i;
886
887 /* Maximum number of concurrent outstanding Send WRs. Capping
888 * the circular queue size stops Send Queue overflow by causing
889 * the ->send_request call to fail temporarily before too many
890 * Sends are posted.
891 */
892 i = buf->rb_max_requests + RPCRDMA_MAX_BC_REQUESTS;
893 dprintk("RPC: %s: allocating %lu send_ctxs\n", __func__, i);
894 buf->rb_sc_ctxs = kcalloc(i, sizeof(sc), GFP_KERNEL);
895 if (!buf->rb_sc_ctxs)
896 return -ENOMEM;
897
898 buf->rb_sc_last = i - 1;
899 for (i = 0; i <= buf->rb_sc_last; i++) {
900 sc = rpcrdma_sendctx_create(&r_xprt->rx_ia);
901 if (!sc)
902 goto out_destroy;
903
904 sc->sc_xprt = r_xprt;
905 buf->rb_sc_ctxs[i] = sc;
906 }
907
908 return 0;
909
910out_destroy:
911 rpcrdma_sendctxs_destroy(buf);
912 return -ENOMEM;
913}
914
915/* The sendctx queue is not guaranteed to have a size that is a
916 * power of two, thus the helpers in circ_buf.h cannot be used.
917 * The other option is to use modulus (%), which can be expensive.
918 */
919static unsigned long rpcrdma_sendctx_next(struct rpcrdma_buffer *buf,
920 unsigned long item)
921{
922 return likely(item < buf->rb_sc_last) ? item + 1 : 0;
923}
924
925/**
926 * rpcrdma_sendctx_get_locked - Acquire a send context
927 * @buf: transport buffers from which to acquire an unused context
928 *
929 * Returns pointer to a free send completion context; or NULL if
930 * the queue is empty.
931 *
932 * Usage: Called to acquire an SGE array before preparing a Send WR.
933 *
934 * The caller serializes calls to this function (per rpcrdma_buffer),
935 * and provides an effective memory barrier that flushes the new value
936 * of rb_sc_head.
937 */
938struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked(struct rpcrdma_buffer *buf)
939{
940 struct rpcrdma_xprt *r_xprt;
941 struct rpcrdma_sendctx *sc;
942 unsigned long next_head;
943
944 next_head = rpcrdma_sendctx_next(buf, buf->rb_sc_head);
945
946 if (next_head == READ_ONCE(buf->rb_sc_tail))
947 goto out_emptyq;
948
949 /* ORDER: item must be accessed _before_ head is updated */
950 sc = buf->rb_sc_ctxs[next_head];
951
952 /* Releasing the lock in the caller acts as a memory
953 * barrier that flushes rb_sc_head.
954 */
955 buf->rb_sc_head = next_head;
956
957 return sc;
958
959out_emptyq:
960 /* The queue is "empty" if there have not been enough Send
961 * completions recently. This is a sign the Send Queue is
962 * backing up. Cause the caller to pause and try again.
963 */
964 dprintk("RPC: %s: empty sendctx queue\n", __func__);
965 r_xprt = container_of(buf, struct rpcrdma_xprt, rx_buf);
966 r_xprt->rx_stats.empty_sendctx_q++;
967 return NULL;
968}
969
970/**
971 * rpcrdma_sendctx_put_locked - Release a send context
972 * @sc: send context to release
973 *
974 * Usage: Called from Send completion to return a sendctxt
975 * to the queue.
976 *
977 * The caller serializes calls to this function (per rpcrdma_buffer).
978 */
979void rpcrdma_sendctx_put_locked(struct rpcrdma_sendctx *sc)
980{
981 struct rpcrdma_buffer *buf = &sc->sc_xprt->rx_buf;
982 unsigned long next_tail;
983
984 /* Unmap SGEs of previously completed by unsignaled
985 * Sends by walking up the queue until @sc is found.
986 */
987 next_tail = buf->rb_sc_tail;
988 do {
989 next_tail = rpcrdma_sendctx_next(buf, next_tail);
990
991 /* ORDER: item must be accessed _before_ tail is updated */
992 rpcrdma_unmap_sendctx(buf->rb_sc_ctxs[next_tail]);
993
994 } while (buf->rb_sc_ctxs[next_tail] != sc);
995
996 /* Paired with READ_ONCE */
997 smp_store_release(&buf->rb_sc_tail, next_tail);
998}
999
Chuck Lever505bbe62016-06-29 13:52:54 -04001000static void
1001rpcrdma_mr_recovery_worker(struct work_struct *work)
1002{
1003 struct rpcrdma_buffer *buf = container_of(work, struct rpcrdma_buffer,
1004 rb_recovery_worker.work);
1005 struct rpcrdma_mw *mw;
1006
1007 spin_lock(&buf->rb_recovery_lock);
1008 while (!list_empty(&buf->rb_stale_mrs)) {
Chuck Lever9a5c63e2017-02-08 17:00:43 -05001009 mw = rpcrdma_pop_mw(&buf->rb_stale_mrs);
Chuck Lever505bbe62016-06-29 13:52:54 -04001010 spin_unlock(&buf->rb_recovery_lock);
1011
1012 dprintk("RPC: %s: recovering MR %p\n", __func__, mw);
1013 mw->mw_xprt->rx_ia.ri_ops->ro_recover_mr(mw);
1014
1015 spin_lock(&buf->rb_recovery_lock);
kbuild test robot53d78522016-07-16 06:02:05 +08001016 }
Chuck Lever505bbe62016-06-29 13:52:54 -04001017 spin_unlock(&buf->rb_recovery_lock);
1018}
1019
1020void
1021rpcrdma_defer_mr_recovery(struct rpcrdma_mw *mw)
1022{
1023 struct rpcrdma_xprt *r_xprt = mw->mw_xprt;
1024 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
1025
1026 spin_lock(&buf->rb_recovery_lock);
Chuck Lever9a5c63e2017-02-08 17:00:43 -05001027 rpcrdma_push_mw(mw, &buf->rb_stale_mrs);
Chuck Lever505bbe62016-06-29 13:52:54 -04001028 spin_unlock(&buf->rb_recovery_lock);
1029
1030 schedule_delayed_work(&buf->rb_recovery_worker, 0);
1031}
1032
Chuck Levere2ac2362016-06-29 13:54:00 -04001033static void
1034rpcrdma_create_mrs(struct rpcrdma_xprt *r_xprt)
1035{
1036 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
1037 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
1038 unsigned int count;
1039 LIST_HEAD(free);
1040 LIST_HEAD(all);
1041
1042 for (count = 0; count < 32; count++) {
1043 struct rpcrdma_mw *mw;
1044 int rc;
1045
1046 mw = kzalloc(sizeof(*mw), GFP_KERNEL);
1047 if (!mw)
1048 break;
1049
1050 rc = ia->ri_ops->ro_init_mr(ia, mw);
1051 if (rc) {
1052 kfree(mw);
1053 break;
1054 }
1055
1056 mw->mw_xprt = r_xprt;
1057
1058 list_add(&mw->mw_list, &free);
1059 list_add(&mw->mw_all, &all);
1060 }
1061
1062 spin_lock(&buf->rb_mwlock);
1063 list_splice(&free, &buf->rb_mws);
1064 list_splice(&all, &buf->rb_all);
1065 r_xprt->rx_stats.mrs_allocated += count;
1066 spin_unlock(&buf->rb_mwlock);
1067
1068 dprintk("RPC: %s: created %u MRs\n", __func__, count);
1069}
1070
1071static void
1072rpcrdma_mr_refresh_worker(struct work_struct *work)
1073{
1074 struct rpcrdma_buffer *buf = container_of(work, struct rpcrdma_buffer,
1075 rb_refresh_worker.work);
1076 struct rpcrdma_xprt *r_xprt = container_of(buf, struct rpcrdma_xprt,
1077 rx_buf);
1078
1079 rpcrdma_create_mrs(r_xprt);
1080}
1081
Chuck Leverf531a5d2015-10-24 17:27:43 -04001082struct rpcrdma_req *
Chuck Lever13924022015-01-21 11:03:52 -05001083rpcrdma_create_req(struct rpcrdma_xprt *r_xprt)
1084{
Chuck Leverf531a5d2015-10-24 17:27:43 -04001085 struct rpcrdma_buffer *buffer = &r_xprt->rx_buf;
Chuck Lever13924022015-01-21 11:03:52 -05001086 struct rpcrdma_req *req;
Chuck Lever13924022015-01-21 11:03:52 -05001087
Chuck Lever85275c82015-01-21 11:04:16 -05001088 req = kzalloc(sizeof(*req), GFP_KERNEL);
Chuck Lever13924022015-01-21 11:03:52 -05001089 if (req == NULL)
Chuck Lever85275c82015-01-21 11:04:16 -05001090 return ERR_PTR(-ENOMEM);
Chuck Lever13924022015-01-21 11:03:52 -05001091
Chuck Leverf531a5d2015-10-24 17:27:43 -04001092 spin_lock(&buffer->rb_reqslock);
1093 list_add(&req->rl_all, &buffer->rb_allreqs);
1094 spin_unlock(&buffer->rb_reqslock);
Chuck Lever13924022015-01-21 11:03:52 -05001095 req->rl_buffer = &r_xprt->rx_buf;
Chuck Lever9d6b0402016-06-29 13:54:16 -04001096 INIT_LIST_HEAD(&req->rl_registered);
Chuck Lever13924022015-01-21 11:03:52 -05001097 return req;
Chuck Lever13924022015-01-21 11:03:52 -05001098}
1099
Chuck Leverf531a5d2015-10-24 17:27:43 -04001100struct rpcrdma_rep *
Chuck Lever13924022015-01-21 11:03:52 -05001101rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt)
1102{
1103 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
Chuck Lever13924022015-01-21 11:03:52 -05001104 struct rpcrdma_rep *rep;
1105 int rc;
1106
1107 rc = -ENOMEM;
Chuck Lever6b1184c2015-01-21 11:04:25 -05001108 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
Chuck Lever13924022015-01-21 11:03:52 -05001109 if (rep == NULL)
1110 goto out;
Chuck Lever13924022015-01-21 11:03:52 -05001111
Chuck Lever13650c22016-09-15 10:56:26 -04001112 rep->rr_rdmabuf = rpcrdma_alloc_regbuf(cdata->inline_rsize,
Chuck Lever99ef4db2016-09-15 10:56:10 -04001113 DMA_FROM_DEVICE, GFP_KERNEL);
Chuck Lever6b1184c2015-01-21 11:04:25 -05001114 if (IS_ERR(rep->rr_rdmabuf)) {
1115 rc = PTR_ERR(rep->rr_rdmabuf);
Chuck Lever13924022015-01-21 11:03:52 -05001116 goto out_free;
Chuck Lever6b1184c2015-01-21 11:04:25 -05001117 }
Chuck Lever96f87782017-08-03 14:30:03 -04001118 xdr_buf_init(&rep->rr_hdrbuf, rep->rr_rdmabuf->rg_base,
1119 rdmab_length(rep->rr_rdmabuf));
Chuck Lever13924022015-01-21 11:03:52 -05001120
Chuck Lever1519e962016-09-15 10:57:49 -04001121 rep->rr_cqe.done = rpcrdma_wc_receive;
Chuck Leverfed171b2015-05-26 11:51:37 -04001122 rep->rr_rxprt = r_xprt;
Chuck Leverd8f532d2017-10-16 15:01:30 -04001123 INIT_WORK(&rep->rr_work, rpcrdma_deferred_completion);
Chuck Lever6ea8e712016-09-15 10:56:51 -04001124 rep->rr_recv_wr.next = NULL;
1125 rep->rr_recv_wr.wr_cqe = &rep->rr_cqe;
1126 rep->rr_recv_wr.sg_list = &rep->rr_rdmabuf->rg_iov;
1127 rep->rr_recv_wr.num_sge = 1;
Chuck Lever13924022015-01-21 11:03:52 -05001128 return rep;
1129
1130out_free:
1131 kfree(rep);
1132out:
1133 return ERR_PTR(rc);
1134}
1135
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001136int
Chuck Leverac920d02015-01-21 11:03:44 -05001137rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001138{
Chuck Leverac920d02015-01-21 11:03:44 -05001139 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001140 int i, rc;
1141
Chuck Lever1e465fd2015-10-24 17:27:02 -04001142 buf->rb_max_requests = r_xprt->rx_data.max_requests;
Chuck Leverf531a5d2015-10-24 17:27:43 -04001143 buf->rb_bc_srv_max_requests = 0;
Chuck Levere2ac2362016-06-29 13:54:00 -04001144 spin_lock_init(&buf->rb_mwlock);
Chuck Lever505bbe62016-06-29 13:52:54 -04001145 spin_lock_init(&buf->rb_lock);
1146 spin_lock_init(&buf->rb_recovery_lock);
Chuck Levere2ac2362016-06-29 13:54:00 -04001147 INIT_LIST_HEAD(&buf->rb_mws);
1148 INIT_LIST_HEAD(&buf->rb_all);
Chuck Lever505bbe62016-06-29 13:52:54 -04001149 INIT_LIST_HEAD(&buf->rb_stale_mrs);
Chuck Levere2ac2362016-06-29 13:54:00 -04001150 INIT_DELAYED_WORK(&buf->rb_refresh_worker,
1151 rpcrdma_mr_refresh_worker);
Chuck Lever505bbe62016-06-29 13:52:54 -04001152 INIT_DELAYED_WORK(&buf->rb_recovery_worker,
1153 rpcrdma_mr_recovery_worker);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001154
Chuck Levere2ac2362016-06-29 13:54:00 -04001155 rpcrdma_create_mrs(r_xprt);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001156
Chuck Lever1e465fd2015-10-24 17:27:02 -04001157 INIT_LIST_HEAD(&buf->rb_send_bufs);
Chuck Leverf531a5d2015-10-24 17:27:43 -04001158 INIT_LIST_HEAD(&buf->rb_allreqs);
1159 spin_lock_init(&buf->rb_reqslock);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001160 for (i = 0; i < buf->rb_max_requests; i++) {
1161 struct rpcrdma_req *req;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001162
Chuck Lever13924022015-01-21 11:03:52 -05001163 req = rpcrdma_create_req(r_xprt);
1164 if (IS_ERR(req)) {
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001165 dprintk("RPC: %s: request buffer %d alloc"
1166 " failed\n", __func__, i);
Chuck Lever13924022015-01-21 11:03:52 -05001167 rc = PTR_ERR(req);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001168 goto out;
1169 }
Chuck Leverf531a5d2015-10-24 17:27:43 -04001170 req->rl_backchannel = false;
Chuck Levera80d66c2017-06-08 11:52:12 -04001171 list_add(&req->rl_list, &buf->rb_send_bufs);
Chuck Lever1e465fd2015-10-24 17:27:02 -04001172 }
1173
1174 INIT_LIST_HEAD(&buf->rb_recv_bufs);
Chuck Lever05c97462016-09-06 11:22:58 -04001175 for (i = 0; i < buf->rb_max_requests + RPCRDMA_MAX_BC_REQUESTS; i++) {
Chuck Lever1e465fd2015-10-24 17:27:02 -04001176 struct rpcrdma_rep *rep;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001177
Chuck Lever13924022015-01-21 11:03:52 -05001178 rep = rpcrdma_create_rep(r_xprt);
1179 if (IS_ERR(rep)) {
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001180 dprintk("RPC: %s: reply buffer %d alloc failed\n",
1181 __func__, i);
Chuck Lever13924022015-01-21 11:03:52 -05001182 rc = PTR_ERR(rep);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001183 goto out;
1184 }
Chuck Lever1e465fd2015-10-24 17:27:02 -04001185 list_add(&rep->rr_list, &buf->rb_recv_bufs);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001186 }
Chuck Lever13924022015-01-21 11:03:52 -05001187
Chuck Leverae729502017-10-20 10:48:12 -04001188 rc = rpcrdma_sendctxs_create(r_xprt);
1189 if (rc)
1190 goto out;
1191
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001192 return 0;
1193out:
1194 rpcrdma_buffer_destroy(buf);
1195 return rc;
1196}
1197
Chuck Lever1e465fd2015-10-24 17:27:02 -04001198static struct rpcrdma_req *
1199rpcrdma_buffer_get_req_locked(struct rpcrdma_buffer *buf)
1200{
1201 struct rpcrdma_req *req;
1202
1203 req = list_first_entry(&buf->rb_send_bufs,
Chuck Levera80d66c2017-06-08 11:52:12 -04001204 struct rpcrdma_req, rl_list);
Chuck Lever431af642017-06-08 11:52:20 -04001205 list_del_init(&req->rl_list);
Chuck Lever1e465fd2015-10-24 17:27:02 -04001206 return req;
1207}
1208
1209static struct rpcrdma_rep *
1210rpcrdma_buffer_get_rep_locked(struct rpcrdma_buffer *buf)
1211{
1212 struct rpcrdma_rep *rep;
1213
1214 rep = list_first_entry(&buf->rb_recv_bufs,
1215 struct rpcrdma_rep, rr_list);
1216 list_del(&rep->rr_list);
1217 return rep;
1218}
1219
Chuck Lever2e845222014-07-29 17:25:38 -04001220static void
Chuck Lever13650c22016-09-15 10:56:26 -04001221rpcrdma_destroy_rep(struct rpcrdma_rep *rep)
Chuck Lever13924022015-01-21 11:03:52 -05001222{
Chuck Lever13650c22016-09-15 10:56:26 -04001223 rpcrdma_free_regbuf(rep->rr_rdmabuf);
Chuck Lever13924022015-01-21 11:03:52 -05001224 kfree(rep);
1225}
1226
Chuck Leverf531a5d2015-10-24 17:27:43 -04001227void
Chuck Lever13650c22016-09-15 10:56:26 -04001228rpcrdma_destroy_req(struct rpcrdma_req *req)
Chuck Lever13924022015-01-21 11:03:52 -05001229{
Chuck Lever13650c22016-09-15 10:56:26 -04001230 rpcrdma_free_regbuf(req->rl_recvbuf);
1231 rpcrdma_free_regbuf(req->rl_sendbuf);
1232 rpcrdma_free_regbuf(req->rl_rdmabuf);
Chuck Lever13924022015-01-21 11:03:52 -05001233 kfree(req);
1234}
1235
Chuck Levere2ac2362016-06-29 13:54:00 -04001236static void
1237rpcrdma_destroy_mrs(struct rpcrdma_buffer *buf)
1238{
1239 struct rpcrdma_xprt *r_xprt = container_of(buf, struct rpcrdma_xprt,
1240 rx_buf);
1241 struct rpcrdma_ia *ia = rdmab_to_ia(buf);
1242 struct rpcrdma_mw *mw;
1243 unsigned int count;
1244
1245 count = 0;
1246 spin_lock(&buf->rb_mwlock);
1247 while (!list_empty(&buf->rb_all)) {
1248 mw = list_entry(buf->rb_all.next, struct rpcrdma_mw, mw_all);
1249 list_del(&mw->mw_all);
1250
1251 spin_unlock(&buf->rb_mwlock);
1252 ia->ri_ops->ro_release_mr(mw);
1253 count++;
1254 spin_lock(&buf->rb_mwlock);
1255 }
1256 spin_unlock(&buf->rb_mwlock);
1257 r_xprt->rx_stats.mrs_allocated = 0;
1258
1259 dprintk("RPC: %s: released %u MRs\n", __func__, count);
1260}
1261
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001262void
1263rpcrdma_buffer_destroy(struct rpcrdma_buffer *buf)
1264{
Chuck Lever505bbe62016-06-29 13:52:54 -04001265 cancel_delayed_work_sync(&buf->rb_recovery_worker);
Chuck Lever9378b272017-04-11 13:22:29 -04001266 cancel_delayed_work_sync(&buf->rb_refresh_worker);
Chuck Lever505bbe62016-06-29 13:52:54 -04001267
Chuck Leverae729502017-10-20 10:48:12 -04001268 rpcrdma_sendctxs_destroy(buf);
1269
Chuck Lever1e465fd2015-10-24 17:27:02 -04001270 while (!list_empty(&buf->rb_recv_bufs)) {
1271 struct rpcrdma_rep *rep;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001272
Chuck Lever1e465fd2015-10-24 17:27:02 -04001273 rep = rpcrdma_buffer_get_rep_locked(buf);
Chuck Lever13650c22016-09-15 10:56:26 -04001274 rpcrdma_destroy_rep(rep);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001275 }
Chuck Lever05c97462016-09-06 11:22:58 -04001276 buf->rb_send_count = 0;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001277
Chuck Leverf531a5d2015-10-24 17:27:43 -04001278 spin_lock(&buf->rb_reqslock);
1279 while (!list_empty(&buf->rb_allreqs)) {
Chuck Lever1e465fd2015-10-24 17:27:02 -04001280 struct rpcrdma_req *req;
Allen Andrews4034ba02014-05-28 10:32:09 -04001281
Chuck Leverf531a5d2015-10-24 17:27:43 -04001282 req = list_first_entry(&buf->rb_allreqs,
1283 struct rpcrdma_req, rl_all);
1284 list_del(&req->rl_all);
1285
1286 spin_unlock(&buf->rb_reqslock);
Chuck Lever13650c22016-09-15 10:56:26 -04001287 rpcrdma_destroy_req(req);
Chuck Leverf531a5d2015-10-24 17:27:43 -04001288 spin_lock(&buf->rb_reqslock);
Chuck Lever9f9d8022014-07-29 17:24:45 -04001289 }
Chuck Leverf531a5d2015-10-24 17:27:43 -04001290 spin_unlock(&buf->rb_reqslock);
Chuck Lever05c97462016-09-06 11:22:58 -04001291 buf->rb_recv_count = 0;
Chuck Lever9f9d8022014-07-29 17:24:45 -04001292
Chuck Levere2ac2362016-06-29 13:54:00 -04001293 rpcrdma_destroy_mrs(buf);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001294}
1295
Chuck Lever346aa662015-05-26 11:52:06 -04001296struct rpcrdma_mw *
1297rpcrdma_get_mw(struct rpcrdma_xprt *r_xprt)
Chuck Leverc2922c02014-07-29 17:24:36 -04001298{
Chuck Lever346aa662015-05-26 11:52:06 -04001299 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
1300 struct rpcrdma_mw *mw = NULL;
Chuck Lever346aa662015-05-26 11:52:06 -04001301
Chuck Lever58d1dcf2015-05-26 11:53:13 -04001302 spin_lock(&buf->rb_mwlock);
Chuck Lever9a5c63e2017-02-08 17:00:43 -05001303 if (!list_empty(&buf->rb_mws))
1304 mw = rpcrdma_pop_mw(&buf->rb_mws);
Chuck Lever58d1dcf2015-05-26 11:53:13 -04001305 spin_unlock(&buf->rb_mwlock);
Chuck Lever346aa662015-05-26 11:52:06 -04001306
1307 if (!mw)
Chuck Levere2ac2362016-06-29 13:54:00 -04001308 goto out_nomws;
Chuck Lever4b196dc62017-06-08 11:51:56 -04001309 mw->mw_flags = 0;
Chuck Lever346aa662015-05-26 11:52:06 -04001310 return mw;
Chuck Levere2ac2362016-06-29 13:54:00 -04001311
1312out_nomws:
1313 dprintk("RPC: %s: no MWs available\n", __func__);
Chuck Leverbebd0312017-04-11 13:23:10 -04001314 if (r_xprt->rx_ep.rep_connected != -ENODEV)
1315 schedule_delayed_work(&buf->rb_refresh_worker, 0);
Chuck Levere2ac2362016-06-29 13:54:00 -04001316
1317 /* Allow the reply handler and refresh worker to run */
1318 cond_resched();
1319
1320 return NULL;
Chuck Leverc2922c02014-07-29 17:24:36 -04001321}
1322
Chuck Lever346aa662015-05-26 11:52:06 -04001323void
1324rpcrdma_put_mw(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mw *mw)
Chuck Leverc2922c02014-07-29 17:24:36 -04001325{
Chuck Lever346aa662015-05-26 11:52:06 -04001326 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
Chuck Leverc2922c02014-07-29 17:24:36 -04001327
Chuck Lever58d1dcf2015-05-26 11:53:13 -04001328 spin_lock(&buf->rb_mwlock);
Chuck Lever9a5c63e2017-02-08 17:00:43 -05001329 rpcrdma_push_mw(mw, &buf->rb_mws);
Chuck Lever58d1dcf2015-05-26 11:53:13 -04001330 spin_unlock(&buf->rb_mwlock);
Chuck Leverc2922c02014-07-29 17:24:36 -04001331}
1332
Chuck Lever05c97462016-09-06 11:22:58 -04001333static struct rpcrdma_rep *
1334rpcrdma_buffer_get_rep(struct rpcrdma_buffer *buffers)
1335{
1336 /* If an RPC previously completed without a reply (say, a
1337 * credential problem or a soft timeout occurs) then hold off
1338 * on supplying more Receive buffers until the number of new
1339 * pending RPCs catches up to the number of posted Receives.
1340 */
1341 if (unlikely(buffers->rb_send_count < buffers->rb_recv_count))
1342 return NULL;
1343
1344 if (unlikely(list_empty(&buffers->rb_recv_bufs)))
1345 return NULL;
1346 buffers->rb_recv_count++;
1347 return rpcrdma_buffer_get_rep_locked(buffers);
1348}
1349
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001350/*
1351 * Get a set of request/reply buffers.
Chuck Lever78d506e2016-09-06 11:22:49 -04001352 *
1353 * Reply buffer (if available) is attached to send buffer upon return.
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001354 */
1355struct rpcrdma_req *
1356rpcrdma_buffer_get(struct rpcrdma_buffer *buffers)
1357{
1358 struct rpcrdma_req *req;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001359
Chuck Levera5b027e2015-10-24 17:27:27 -04001360 spin_lock(&buffers->rb_lock);
Chuck Lever1e465fd2015-10-24 17:27:02 -04001361 if (list_empty(&buffers->rb_send_bufs))
1362 goto out_reqbuf;
Chuck Lever05c97462016-09-06 11:22:58 -04001363 buffers->rb_send_count++;
Chuck Lever1e465fd2015-10-24 17:27:02 -04001364 req = rpcrdma_buffer_get_req_locked(buffers);
Chuck Lever05c97462016-09-06 11:22:58 -04001365 req->rl_reply = rpcrdma_buffer_get_rep(buffers);
Chuck Levera5b027e2015-10-24 17:27:27 -04001366 spin_unlock(&buffers->rb_lock);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001367 return req;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001368
Chuck Lever1e465fd2015-10-24 17:27:02 -04001369out_reqbuf:
Chuck Levera5b027e2015-10-24 17:27:27 -04001370 spin_unlock(&buffers->rb_lock);
Chuck Lever78d506e2016-09-06 11:22:49 -04001371 pr_warn("RPC: %s: out of request buffers\n", __func__);
Chuck Lever1e465fd2015-10-24 17:27:02 -04001372 return NULL;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001373}
1374
1375/*
1376 * Put request/reply buffers back into pool.
1377 * Pre-decrement counter/array index.
1378 */
1379void
1380rpcrdma_buffer_put(struct rpcrdma_req *req)
1381{
1382 struct rpcrdma_buffer *buffers = req->rl_buffer;
Chuck Lever1e465fd2015-10-24 17:27:02 -04001383 struct rpcrdma_rep *rep = req->rl_reply;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001384
Chuck Lever1e465fd2015-10-24 17:27:02 -04001385 req->rl_reply = NULL;
1386
Chuck Levera5b027e2015-10-24 17:27:27 -04001387 spin_lock(&buffers->rb_lock);
Chuck Lever05c97462016-09-06 11:22:58 -04001388 buffers->rb_send_count--;
Chuck Levera80d66c2017-06-08 11:52:12 -04001389 list_add_tail(&req->rl_list, &buffers->rb_send_bufs);
Chuck Lever05c97462016-09-06 11:22:58 -04001390 if (rep) {
1391 buffers->rb_recv_count--;
Chuck Lever1e465fd2015-10-24 17:27:02 -04001392 list_add_tail(&rep->rr_list, &buffers->rb_recv_bufs);
Chuck Lever05c97462016-09-06 11:22:58 -04001393 }
Chuck Levera5b027e2015-10-24 17:27:27 -04001394 spin_unlock(&buffers->rb_lock);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001395}
1396
1397/*
1398 * Recover reply buffers from pool.
Chuck Lever1e465fd2015-10-24 17:27:02 -04001399 * This happens when recovering from disconnect.
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001400 */
1401void
1402rpcrdma_recv_buffer_get(struct rpcrdma_req *req)
1403{
1404 struct rpcrdma_buffer *buffers = req->rl_buffer;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001405
Chuck Levera5b027e2015-10-24 17:27:27 -04001406 spin_lock(&buffers->rb_lock);
Chuck Lever05c97462016-09-06 11:22:58 -04001407 req->rl_reply = rpcrdma_buffer_get_rep(buffers);
Chuck Levera5b027e2015-10-24 17:27:27 -04001408 spin_unlock(&buffers->rb_lock);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001409}
1410
1411/*
1412 * Put reply buffers back into pool when not attached to
1413 * request. This happens in error conditions.
1414 */
1415void
1416rpcrdma_recv_buffer_put(struct rpcrdma_rep *rep)
1417{
Chuck Leverfed171b2015-05-26 11:51:37 -04001418 struct rpcrdma_buffer *buffers = &rep->rr_rxprt->rx_buf;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001419
Chuck Levera5b027e2015-10-24 17:27:27 -04001420 spin_lock(&buffers->rb_lock);
Chuck Lever05c97462016-09-06 11:22:58 -04001421 buffers->rb_recv_count--;
Chuck Lever1e465fd2015-10-24 17:27:02 -04001422 list_add_tail(&rep->rr_list, &buffers->rb_recv_bufs);
Chuck Levera5b027e2015-10-24 17:27:27 -04001423 spin_unlock(&buffers->rb_lock);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001424}
1425
Chuck Lever9128c3e2015-01-21 11:04:00 -05001426/**
Chuck Lever99ef4db2016-09-15 10:56:10 -04001427 * rpcrdma_alloc_regbuf - allocate and DMA-map memory for SEND/RECV buffers
Chuck Lever9128c3e2015-01-21 11:04:00 -05001428 * @size: size of buffer to be allocated, in bytes
Chuck Lever99ef4db2016-09-15 10:56:10 -04001429 * @direction: direction of data movement
Chuck Lever9128c3e2015-01-21 11:04:00 -05001430 * @flags: GFP flags
1431 *
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001432 * Returns an ERR_PTR, or a pointer to a regbuf, a buffer that
1433 * can be persistently DMA-mapped for I/O.
Chuck Lever9128c3e2015-01-21 11:04:00 -05001434 *
1435 * xprtrdma uses a regbuf for posting an outgoing RDMA SEND, or for
Chuck Lever99ef4db2016-09-15 10:56:10 -04001436 * receiving the payload of RDMA RECV operations. During Long Calls
1437 * or Replies they may be registered externally via ro_map.
Chuck Lever9128c3e2015-01-21 11:04:00 -05001438 */
1439struct rpcrdma_regbuf *
Chuck Lever13650c22016-09-15 10:56:26 -04001440rpcrdma_alloc_regbuf(size_t size, enum dma_data_direction direction,
1441 gfp_t flags)
Chuck Lever9128c3e2015-01-21 11:04:00 -05001442{
1443 struct rpcrdma_regbuf *rb;
Chuck Lever9128c3e2015-01-21 11:04:00 -05001444
Chuck Lever9128c3e2015-01-21 11:04:00 -05001445 rb = kmalloc(sizeof(*rb) + size, flags);
1446 if (rb == NULL)
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001447 return ERR_PTR(-ENOMEM);
Chuck Lever9128c3e2015-01-21 11:04:00 -05001448
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001449 rb->rg_device = NULL;
Chuck Lever99ef4db2016-09-15 10:56:10 -04001450 rb->rg_direction = direction;
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001451 rb->rg_iov.length = size;
Chuck Lever9128c3e2015-01-21 11:04:00 -05001452
1453 return rb;
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001454}
Chuck Lever9128c3e2015-01-21 11:04:00 -05001455
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001456/**
1457 * __rpcrdma_map_regbuf - DMA-map a regbuf
1458 * @ia: controlling rpcrdma_ia
1459 * @rb: regbuf to be mapped
1460 */
1461bool
1462__rpcrdma_dma_map_regbuf(struct rpcrdma_ia *ia, struct rpcrdma_regbuf *rb)
1463{
Chuck Lever91a10c52017-04-11 13:23:02 -04001464 struct ib_device *device = ia->ri_device;
1465
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001466 if (rb->rg_direction == DMA_NONE)
1467 return false;
1468
Chuck Lever91a10c52017-04-11 13:23:02 -04001469 rb->rg_iov.addr = ib_dma_map_single(device,
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001470 (void *)rb->rg_base,
1471 rdmab_length(rb),
1472 rb->rg_direction);
Chuck Lever91a10c52017-04-11 13:23:02 -04001473 if (ib_dma_mapping_error(device, rdmab_addr(rb)))
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001474 return false;
1475
Chuck Lever91a10c52017-04-11 13:23:02 -04001476 rb->rg_device = device;
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001477 rb->rg_iov.lkey = ia->ri_pd->local_dma_lkey;
1478 return true;
1479}
1480
1481static void
1482rpcrdma_dma_unmap_regbuf(struct rpcrdma_regbuf *rb)
1483{
1484 if (!rpcrdma_regbuf_is_mapped(rb))
1485 return;
1486
1487 ib_dma_unmap_single(rb->rg_device, rdmab_addr(rb),
1488 rdmab_length(rb), rb->rg_direction);
1489 rb->rg_device = NULL;
Chuck Lever9128c3e2015-01-21 11:04:00 -05001490}
1491
1492/**
1493 * rpcrdma_free_regbuf - deregister and free registered buffer
Chuck Lever9128c3e2015-01-21 11:04:00 -05001494 * @rb: regbuf to be deregistered and freed
1495 */
1496void
Chuck Lever13650c22016-09-15 10:56:26 -04001497rpcrdma_free_regbuf(struct rpcrdma_regbuf *rb)
Chuck Lever9128c3e2015-01-21 11:04:00 -05001498{
Chuck Levere531dca2015-08-03 13:03:20 -04001499 if (!rb)
1500 return;
1501
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001502 rpcrdma_dma_unmap_regbuf(rb);
Chuck Levere531dca2015-08-03 13:03:20 -04001503 kfree(rb);
Chuck Lever9128c3e2015-01-21 11:04:00 -05001504}
1505
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001506/*
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001507 * Prepost any receive buffer, then post send.
1508 *
1509 * Receive buffer is donated to hardware, reclaimed upon recv completion.
1510 */
1511int
1512rpcrdma_ep_post(struct rpcrdma_ia *ia,
1513 struct rpcrdma_ep *ep,
1514 struct rpcrdma_req *req)
1515{
Chuck Leverae729502017-10-20 10:48:12 -04001516 struct ib_send_wr *send_wr = &req->rl_sendctx->sc_wr;
Chuck Lever90aab602016-09-15 10:56:43 -04001517 struct ib_send_wr *send_wr_fail;
Chuck Lever655fec62016-09-15 10:57:24 -04001518 int rc;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001519
Chuck Lever90aab602016-09-15 10:56:43 -04001520 if (req->rl_reply) {
1521 rc = rpcrdma_ep_post_recv(ia, req->rl_reply);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001522 if (rc)
Chuck Lever7a89f9c2016-06-29 13:53:43 -04001523 return rc;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001524 req->rl_reply = NULL;
1525 }
1526
Chuck Leverb3221d62015-08-03 13:03:39 -04001527 dprintk("RPC: %s: posting %d s/g entries\n",
Chuck Lever90aab602016-09-15 10:56:43 -04001528 __func__, send_wr->num_sge);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001529
Chuck Leverae729502017-10-20 10:48:12 -04001530 if (!ep->rep_send_count) {
1531 send_wr->send_flags |= IB_SEND_SIGNALED;
1532 ep->rep_send_count = ep->rep_send_batch;
1533 } else {
1534 send_wr->send_flags &= ~IB_SEND_SIGNALED;
1535 --ep->rep_send_count;
1536 }
Chuck Lever90aab602016-09-15 10:56:43 -04001537 rc = ib_post_send(ia->ri_id->qp, send_wr, &send_wr_fail);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001538 if (rc)
Chuck Lever7a89f9c2016-06-29 13:53:43 -04001539 goto out_postsend_err;
1540 return 0;
1541
1542out_postsend_err:
1543 pr_err("rpcrdma: RDMA Send ib_post_send returned %i\n", rc);
1544 return -ENOTCONN;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001545}
1546
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001547int
1548rpcrdma_ep_post_recv(struct rpcrdma_ia *ia,
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001549 struct rpcrdma_rep *rep)
1550{
Chuck Lever6ea8e712016-09-15 10:56:51 -04001551 struct ib_recv_wr *recv_wr_fail;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001552 int rc;
1553
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001554 if (!rpcrdma_dma_map_regbuf(ia, rep->rr_rdmabuf))
1555 goto out_map;
Chuck Lever6ea8e712016-09-15 10:56:51 -04001556 rc = ib_post_recv(ia->ri_id->qp, &rep->rr_recv_wr, &recv_wr_fail);
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001557 if (rc)
Chuck Lever7a89f9c2016-06-29 13:53:43 -04001558 goto out_postrecv;
1559 return 0;
1560
Chuck Lever54cbd6b2016-09-15 10:56:18 -04001561out_map:
1562 pr_err("rpcrdma: failed to DMA map the Receive buffer\n");
1563 return -EIO;
1564
Chuck Lever7a89f9c2016-06-29 13:53:43 -04001565out_postrecv:
1566 pr_err("rpcrdma: ib_post_recv returned %i\n", rc);
1567 return -ENOTCONN;
\"Talpey, Thomas\c56c65f2007-09-10 13:51:18 -04001568}
Chuck Lever43e95982014-07-29 17:23:34 -04001569
Chuck Leverf531a5d2015-10-24 17:27:43 -04001570/**
1571 * rpcrdma_ep_post_extra_recv - Post buffers for incoming backchannel requests
1572 * @r_xprt: transport associated with these backchannel resources
1573 * @min_reqs: minimum number of incoming requests expected
1574 *
1575 * Returns zero if all requested buffers were posted, or a negative errno.
1576 */
1577int
1578rpcrdma_ep_post_extra_recv(struct rpcrdma_xprt *r_xprt, unsigned int count)
1579{
1580 struct rpcrdma_buffer *buffers = &r_xprt->rx_buf;
1581 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
Chuck Leverf531a5d2015-10-24 17:27:43 -04001582 struct rpcrdma_rep *rep;
Chuck Leverf531a5d2015-10-24 17:27:43 -04001583 int rc;
1584
1585 while (count--) {
Chuck Lever9b066882015-12-16 17:22:06 -05001586 spin_lock(&buffers->rb_lock);
Chuck Leverf531a5d2015-10-24 17:27:43 -04001587 if (list_empty(&buffers->rb_recv_bufs))
1588 goto out_reqbuf;
1589 rep = rpcrdma_buffer_get_rep_locked(buffers);
Chuck Lever9b066882015-12-16 17:22:06 -05001590 spin_unlock(&buffers->rb_lock);
Chuck Leverf531a5d2015-10-24 17:27:43 -04001591
Chuck Leverb1573802016-09-15 10:56:35 -04001592 rc = rpcrdma_ep_post_recv(ia, rep);
Chuck Leverf531a5d2015-10-24 17:27:43 -04001593 if (rc)
1594 goto out_rc;
1595 }
1596
1597 return 0;
1598
1599out_reqbuf:
Chuck Lever9b066882015-12-16 17:22:06 -05001600 spin_unlock(&buffers->rb_lock);
Chuck Leverf531a5d2015-10-24 17:27:43 -04001601 pr_warn("%s: no extra receive buffers\n", __func__);
1602 return -ENOMEM;
1603
1604out_rc:
1605 rpcrdma_recv_buffer_put(rep);
1606 return rc;
1607}