\"Talpey, Thomas\ | f58851e | 2007-09-10 13:50:12 -0400 | [diff] [blame] | 1 | /* |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 2 | * 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\ | f58851e | 2007-09-10 13:50:12 -0400 | [diff] [blame] | 38 | */ |
| 39 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 40 | /* |
| 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 Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 50 | #include <linux/interrupt.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 51 | #include <linux/slab.h> |
Chuck Lever | eba8ff6 | 2015-01-21 11:03:02 -0500 | [diff] [blame] | 52 | #include <linux/prefetch.h> |
Chuck Lever | 0dd39ca | 2015-03-30 14:33:43 -0400 | [diff] [blame] | 53 | #include <linux/sunrpc/addr.h> |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 54 | #include <linux/sunrpc/svc_rdma.h> |
Chuck Lever | 65866f8 | 2014-05-28 10:33:59 -0400 | [diff] [blame] | 55 | #include <asm/bitops.h> |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 56 | #include <linux/module.h> /* try_module_get()/module_put() */ |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 57 | #include <rdma/ib_cm.h> |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 58 | |
\"Talpey, Thomas\ | f58851e | 2007-09-10 13:50:12 -0400 | [diff] [blame] | 59 | #include "xprt_rdma.h" |
| 60 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 61 | /* |
| 62 | * Globals/Macros |
| 63 | */ |
| 64 | |
Jeff Layton | f895b25 | 2014-11-17 16:58:04 -0500 | [diff] [blame] | 65 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 66 | # define RPCDBG_FACILITY RPCDBG_TRANS |
| 67 | #endif |
| 68 | |
| 69 | /* |
| 70 | * internal functions |
| 71 | */ |
Chuck Lever | bebd031 | 2017-04-11 13:23:10 -0400 | [diff] [blame^] | 72 | static void rpcrdma_destroy_mrs(struct rpcrdma_buffer *buf); |
| 73 | static void rpcrdma_dma_unmap_regbuf(struct rpcrdma_regbuf *rb); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 74 | |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 75 | static struct workqueue_struct *rpcrdma_receive_wq; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 76 | |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 77 | int |
| 78 | rpcrdma_alloc_wq(void) |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 79 | { |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 80 | struct workqueue_struct *recv_wq; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 81 | |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 82 | recv_wq = alloc_workqueue("xprtrdma_receive", |
| 83 | WQ_MEM_RECLAIM | WQ_UNBOUND | WQ_HIGHPRI, |
| 84 | 0); |
| 85 | if (!recv_wq) |
| 86 | return -ENOMEM; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 87 | |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 88 | rpcrdma_receive_wq = recv_wq; |
| 89 | return 0; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 92 | void |
| 93 | rpcrdma_destroy_wq(void) |
Chuck Lever | f1a03b7 | 2014-11-08 20:14:37 -0500 | [diff] [blame] | 94 | { |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 95 | struct workqueue_struct *wq; |
Chuck Lever | f1a03b7 | 2014-11-08 20:14:37 -0500 | [diff] [blame] | 96 | |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 97 | if (rpcrdma_receive_wq) { |
| 98 | wq = rpcrdma_receive_wq; |
| 99 | rpcrdma_receive_wq = NULL; |
| 100 | destroy_workqueue(wq); |
| 101 | } |
Chuck Lever | f1a03b7 | 2014-11-08 20:14:37 -0500 | [diff] [blame] | 102 | } |
| 103 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 104 | static void |
| 105 | rpcrdma_qp_async_error_upcall(struct ib_event *event, void *context) |
| 106 | { |
| 107 | struct rpcrdma_ep *ep = context; |
| 108 | |
Chuck Lever | 2f6922c | 2016-11-29 10:53:21 -0500 | [diff] [blame] | 109 | pr_err("rpcrdma: %s on device %s ep %p\n", |
| 110 | ib_event_msg(event->event), event->device->name, context); |
| 111 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 112 | if (ep->rep_connected == 1) { |
| 113 | ep->rep_connected = -EIO; |
Chuck Lever | afadc46 | 2015-01-21 11:03:11 -0500 | [diff] [blame] | 114 | rpcrdma_conn_func(ep); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 115 | wake_up_all(&ep->rep_connect_wait); |
| 116 | } |
| 117 | } |
| 118 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 119 | /** |
| 120 | * rpcrdma_wc_send - Invoked by RDMA provider for each polled Send WC |
| 121 | * @cq: completion queue (ignored) |
| 122 | * @wc: completed WR |
| 123 | * |
Chuck Lever | 4220a07 | 2015-10-24 17:26:45 -0400 | [diff] [blame] | 124 | */ |
| 125 | static void |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 126 | rpcrdma_wc_send(struct ib_cq *cq, struct ib_wc *wc) |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 127 | { |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 128 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
| 129 | if (wc->status != IB_WC_SUCCESS && wc->status != IB_WC_WR_FLUSH_ERR) |
| 130 | pr_err("rpcrdma: Send: %s (%u/0x%x)\n", |
| 131 | ib_wc_status_msg(wc->status), |
| 132 | wc->status, wc->vendor_err); |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Chuck Lever | 23826c7 | 2016-03-04 11:28:27 -0500 | [diff] [blame] | 135 | /* Perform basic sanity checking to avoid using garbage |
| 136 | * to update the credit grant value. |
| 137 | */ |
| 138 | static void |
| 139 | rpcrdma_update_granted_credits(struct rpcrdma_rep *rep) |
| 140 | { |
| 141 | struct rpcrdma_msg *rmsgp = rdmab_to_msg(rep->rr_rdmabuf); |
| 142 | struct rpcrdma_buffer *buffer = &rep->rr_rxprt->rx_buf; |
| 143 | u32 credits; |
| 144 | |
| 145 | if (rep->rr_len < RPCRDMA_HDRLEN_ERR) |
| 146 | return; |
| 147 | |
| 148 | credits = be32_to_cpu(rmsgp->rm_credit); |
| 149 | if (credits == 0) |
| 150 | credits = 1; /* don't deadlock */ |
| 151 | else if (credits > buffer->rb_max_requests) |
| 152 | credits = buffer->rb_max_requests; |
| 153 | |
| 154 | atomic_set(&buffer->rb_credits, credits); |
| 155 | } |
| 156 | |
Chuck Lever | 552bf22 | 2016-03-04 11:28:36 -0500 | [diff] [blame] | 157 | /** |
Chuck Lever | 1519e96 | 2016-09-15 10:57:49 -0400 | [diff] [blame] | 158 | * rpcrdma_wc_receive - Invoked by RDMA provider for each polled Receive WC |
Chuck Lever | 552bf22 | 2016-03-04 11:28:36 -0500 | [diff] [blame] | 159 | * @cq: completion queue (ignored) |
| 160 | * @wc: completed WR |
| 161 | * |
| 162 | */ |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 163 | static void |
Chuck Lever | 1519e96 | 2016-09-15 10:57:49 -0400 | [diff] [blame] | 164 | rpcrdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc) |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 165 | { |
Chuck Lever | 552bf22 | 2016-03-04 11:28:36 -0500 | [diff] [blame] | 166 | struct ib_cqe *cqe = wc->wr_cqe; |
| 167 | struct rpcrdma_rep *rep = container_of(cqe, struct rpcrdma_rep, |
| 168 | rr_cqe); |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 169 | |
Chuck Lever | 8502427 | 2015-01-21 11:02:04 -0500 | [diff] [blame] | 170 | /* WARNING: Only wr_id and status are reliable at this point */ |
| 171 | if (wc->status != IB_WC_SUCCESS) |
| 172 | goto out_fail; |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 173 | |
Chuck Lever | 8502427 | 2015-01-21 11:02:04 -0500 | [diff] [blame] | 174 | /* status == SUCCESS means all fields in wc are trustworthy */ |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 175 | if (wc->opcode != IB_WC_RECV) |
| 176 | return; |
| 177 | |
Chuck Lever | 8502427 | 2015-01-21 11:02:04 -0500 | [diff] [blame] | 178 | dprintk("RPC: %s: rep %p opcode 'recv', length %u: success\n", |
| 179 | __func__, rep, wc->byte_len); |
| 180 | |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 181 | rep->rr_len = wc->byte_len; |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 182 | rep->rr_wc_flags = wc->wc_flags; |
| 183 | rep->rr_inv_rkey = wc->ex.invalidate_rkey; |
| 184 | |
Chuck Lever | 91a10c5 | 2017-04-11 13:23:02 -0400 | [diff] [blame] | 185 | ib_dma_sync_single_for_cpu(rdmab_device(rep->rr_rdmabuf), |
Chuck Lever | 6b1184c | 2015-01-21 11:04:25 -0500 | [diff] [blame] | 186 | rdmab_addr(rep->rr_rdmabuf), |
| 187 | rep->rr_len, DMA_FROM_DEVICE); |
Chuck Lever | 23826c7 | 2016-03-04 11:28:27 -0500 | [diff] [blame] | 188 | |
| 189 | rpcrdma_update_granted_credits(rep); |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 190 | |
| 191 | out_schedule: |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 192 | queue_work(rpcrdma_receive_wq, &rep->rr_work); |
Chuck Lever | 8502427 | 2015-01-21 11:02:04 -0500 | [diff] [blame] | 193 | return; |
Chuck Lever | fe97b47 | 2015-10-24 17:27:10 -0400 | [diff] [blame] | 194 | |
Chuck Lever | 8502427 | 2015-01-21 11:02:04 -0500 | [diff] [blame] | 195 | out_fail: |
| 196 | if (wc->status != IB_WC_WR_FLUSH_ERR) |
Chuck Lever | 552bf22 | 2016-03-04 11:28:36 -0500 | [diff] [blame] | 197 | pr_err("rpcrdma: Recv: %s (%u/0x%x)\n", |
| 198 | ib_wc_status_msg(wc->status), |
| 199 | wc->status, wc->vendor_err); |
Chuck Lever | b0e178a | 2015-10-24 17:26:54 -0400 | [diff] [blame] | 200 | rep->rr_len = RPCRDMA_BAD_LEN; |
Chuck Lever | 8502427 | 2015-01-21 11:02:04 -0500 | [diff] [blame] | 201 | goto out_schedule; |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 202 | } |
| 203 | |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 204 | static void |
| 205 | rpcrdma_update_connect_private(struct rpcrdma_xprt *r_xprt, |
| 206 | struct rdma_conn_param *param) |
| 207 | { |
| 208 | struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data; |
| 209 | const struct rpcrdma_connect_private *pmsg = param->private_data; |
| 210 | unsigned int rsize, wsize; |
| 211 | |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 212 | /* Default settings for RPC-over-RDMA Version One */ |
| 213 | r_xprt->rx_ia.ri_reminv_expected = false; |
Chuck Lever | b5f0afb | 2017-02-08 16:59:54 -0500 | [diff] [blame] | 214 | r_xprt->rx_ia.ri_implicit_roundup = xprt_rdma_pad_optimize; |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 215 | rsize = RPCRDMA_V1_DEF_INLINE_SIZE; |
| 216 | wsize = RPCRDMA_V1_DEF_INLINE_SIZE; |
| 217 | |
| 218 | if (pmsg && |
| 219 | pmsg->cp_magic == rpcrdma_cmp_magic && |
| 220 | pmsg->cp_version == RPCRDMA_CMP_VERSION) { |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 221 | r_xprt->rx_ia.ri_reminv_expected = true; |
Chuck Lever | c95a3c6 | 2017-02-08 17:00:02 -0500 | [diff] [blame] | 222 | r_xprt->rx_ia.ri_implicit_roundup = true; |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 223 | rsize = rpcrdma_decode_buffer_size(pmsg->cp_send_size); |
| 224 | wsize = rpcrdma_decode_buffer_size(pmsg->cp_recv_size); |
| 225 | } |
| 226 | |
| 227 | if (rsize < cdata->inline_rsize) |
| 228 | cdata->inline_rsize = rsize; |
| 229 | if (wsize < cdata->inline_wsize) |
| 230 | cdata->inline_wsize = wsize; |
Chuck Lever | 6d6bf72 | 2016-11-29 10:53:13 -0500 | [diff] [blame] | 231 | dprintk("RPC: %s: max send %u, max recv %u\n", |
| 232 | __func__, cdata->inline_wsize, cdata->inline_rsize); |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 233 | rpcrdma_set_max_header_sizes(r_xprt); |
| 234 | } |
| 235 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 236 | static int |
| 237 | rpcrdma_conn_upcall(struct rdma_cm_id *id, struct rdma_cm_event *event) |
| 238 | { |
| 239 | struct rpcrdma_xprt *xprt = id->context; |
| 240 | struct rpcrdma_ia *ia = &xprt->rx_ia; |
| 241 | struct rpcrdma_ep *ep = &xprt->rx_ep; |
Jeff Layton | f895b25 | 2014-11-17 16:58:04 -0500 | [diff] [blame] | 242 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
Chuck Lever | 0dd39ca | 2015-03-30 14:33:43 -0400 | [diff] [blame] | 243 | struct sockaddr *sap = (struct sockaddr *)&ep->rep_remote_addr; |
Ingo Molnar | ff0db04 | 2008-11-25 16:58:42 -0800 | [diff] [blame] | 244 | #endif |
Chuck Lever | ce1ab9a | 2015-01-21 11:03:35 -0500 | [diff] [blame] | 245 | struct ib_qp_attr *attr = &ia->ri_qp_attr; |
| 246 | struct ib_qp_init_attr *iattr = &ia->ri_qp_init_attr; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 247 | int connstate = 0; |
| 248 | |
| 249 | switch (event->event) { |
| 250 | case RDMA_CM_EVENT_ADDR_RESOLVED: |
| 251 | case RDMA_CM_EVENT_ROUTE_RESOLVED: |
Tom Talpey | 5675add | 2008-10-09 15:01:41 -0400 | [diff] [blame] | 252 | ia->ri_async_rc = 0; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 253 | complete(&ia->ri_done); |
| 254 | break; |
| 255 | case RDMA_CM_EVENT_ADDR_ERROR: |
| 256 | ia->ri_async_rc = -EHOSTUNREACH; |
| 257 | dprintk("RPC: %s: CM address resolution error, ep 0x%p\n", |
| 258 | __func__, ep); |
| 259 | complete(&ia->ri_done); |
| 260 | break; |
| 261 | case RDMA_CM_EVENT_ROUTE_ERROR: |
| 262 | ia->ri_async_rc = -ENETUNREACH; |
| 263 | dprintk("RPC: %s: CM route resolution error, ep 0x%p\n", |
| 264 | __func__, ep); |
| 265 | complete(&ia->ri_done); |
| 266 | break; |
Chuck Lever | bebd031 | 2017-04-11 13:23:10 -0400 | [diff] [blame^] | 267 | case RDMA_CM_EVENT_DEVICE_REMOVAL: |
| 268 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
| 269 | pr_info("rpcrdma: removing device for %pIS:%u\n", |
| 270 | sap, rpc_get_port(sap)); |
| 271 | #endif |
| 272 | set_bit(RPCRDMA_IAF_REMOVING, &ia->ri_flags); |
| 273 | ep->rep_connected = -ENODEV; |
| 274 | xprt_force_disconnect(&xprt->rx_xprt); |
| 275 | wait_for_completion(&ia->ri_remove_done); |
| 276 | |
| 277 | ia->ri_id = NULL; |
| 278 | ia->ri_pd = NULL; |
| 279 | ia->ri_device = NULL; |
| 280 | /* Return 1 to ensure the core destroys the id. */ |
| 281 | return 1; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 282 | case RDMA_CM_EVENT_ESTABLISHED: |
| 283 | connstate = 1; |
Chuck Lever | ce1ab9a | 2015-01-21 11:03:35 -0500 | [diff] [blame] | 284 | ib_query_qp(ia->ri_id->qp, attr, |
| 285 | IB_QP_MAX_QP_RD_ATOMIC | IB_QP_MAX_DEST_RD_ATOMIC, |
| 286 | iattr); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 287 | dprintk("RPC: %s: %d responder resources" |
| 288 | " (%d initiator)\n", |
Chuck Lever | ce1ab9a | 2015-01-21 11:03:35 -0500 | [diff] [blame] | 289 | __func__, attr->max_dest_rd_atomic, |
| 290 | attr->max_rd_atomic); |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 291 | rpcrdma_update_connect_private(xprt, &event->param.conn); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 292 | goto connected; |
| 293 | case RDMA_CM_EVENT_CONNECT_ERROR: |
| 294 | connstate = -ENOTCONN; |
| 295 | goto connected; |
| 296 | case RDMA_CM_EVENT_UNREACHABLE: |
| 297 | connstate = -ENETDOWN; |
| 298 | goto connected; |
| 299 | case RDMA_CM_EVENT_REJECTED: |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 300 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
| 301 | pr_info("rpcrdma: connection to %pIS:%u on %s rejected: %s\n", |
| 302 | sap, rpc_get_port(sap), ia->ri_device->name, |
| 303 | rdma_reject_msg(id, event->status)); |
| 304 | #endif |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 305 | connstate = -ECONNREFUSED; |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 306 | if (event->status == IB_CM_REJ_STALE_CONN) |
| 307 | connstate = -EAGAIN; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 308 | goto connected; |
| 309 | case RDMA_CM_EVENT_DISCONNECTED: |
| 310 | connstate = -ECONNABORTED; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 311 | connected: |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 312 | dprintk("RPC: %s: %sconnected\n", |
| 313 | __func__, connstate > 0 ? "" : "dis"); |
Chuck Lever | 23826c7 | 2016-03-04 11:28:27 -0500 | [diff] [blame] | 314 | atomic_set(&xprt->rx_buf.rb_credits, 1); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 315 | ep->rep_connected = connstate; |
Chuck Lever | afadc46 | 2015-01-21 11:03:11 -0500 | [diff] [blame] | 316 | rpcrdma_conn_func(ep); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 317 | wake_up_all(&ep->rep_connect_wait); |
Chuck Lever | 8079fb7 | 2014-07-29 17:26:12 -0400 | [diff] [blame] | 318 | /*FALLTHROUGH*/ |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 319 | default: |
Chuck Lever | 0dd39ca | 2015-03-30 14:33:43 -0400 | [diff] [blame] | 320 | dprintk("RPC: %s: %pIS:%u (ep 0x%p): %s\n", |
| 321 | __func__, sap, rpc_get_port(sap), ep, |
Sagi Grimberg | 76357c7 | 2015-05-18 13:40:32 +0300 | [diff] [blame] | 322 | rdma_event_msg(event->event)); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 323 | break; |
| 324 | } |
| 325 | |
Jeff Layton | f895b25 | 2014-11-17 16:58:04 -0500 | [diff] [blame] | 326 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
Tom Talpey | b3cd8d4 | 2008-10-09 15:02:02 -0400 | [diff] [blame] | 327 | if (connstate == 1) { |
Chuck Lever | ce1ab9a | 2015-01-21 11:03:35 -0500 | [diff] [blame] | 328 | int ird = attr->max_dest_rd_atomic; |
Tom Talpey | b3cd8d4 | 2008-10-09 15:02:02 -0400 | [diff] [blame] | 329 | int tird = ep->rep_remote_cma.responder_resources; |
Chuck Lever | 0dd39ca | 2015-03-30 14:33:43 -0400 | [diff] [blame] | 330 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 331 | pr_info("rpcrdma: connection to %pIS:%u on %s, memreg '%s', %d credits, %d responders%s\n", |
Chuck Lever | 0dd39ca | 2015-03-30 14:33:43 -0400 | [diff] [blame] | 332 | sap, rpc_get_port(sap), |
Chuck Lever | 89e0d112 | 2015-05-26 11:51:56 -0400 | [diff] [blame] | 333 | ia->ri_device->name, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 334 | ia->ri_ops->ro_displayname, |
Tom Talpey | b3cd8d4 | 2008-10-09 15:02:02 -0400 | [diff] [blame] | 335 | xprt->rx_buf.rb_max_requests, |
| 336 | ird, ird < 4 && ird < tird / 2 ? " (low!)" : ""); |
| 337 | } else if (connstate < 0) { |
Chuck Lever | 0dd39ca | 2015-03-30 14:33:43 -0400 | [diff] [blame] | 338 | pr_info("rpcrdma: connection to %pIS:%u closed (%d)\n", |
| 339 | sap, rpc_get_port(sap), connstate); |
Tom Talpey | b3cd8d4 | 2008-10-09 15:02:02 -0400 | [diff] [blame] | 340 | } |
| 341 | #endif |
| 342 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 346 | static void rpcrdma_destroy_id(struct rdma_cm_id *id) |
| 347 | { |
| 348 | if (id) { |
| 349 | module_put(id->device->owner); |
| 350 | rdma_destroy_id(id); |
| 351 | } |
| 352 | } |
| 353 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 354 | static struct rdma_cm_id * |
| 355 | rpcrdma_create_id(struct rpcrdma_xprt *xprt, |
| 356 | struct rpcrdma_ia *ia, struct sockaddr *addr) |
| 357 | { |
Chuck Lever | 109b88a | 2016-11-29 10:52:40 -0500 | [diff] [blame] | 358 | unsigned long wtimeout = msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT) + 1; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 359 | struct rdma_cm_id *id; |
| 360 | int rc; |
| 361 | |
Tom Talpey | 1a95405 | 2008-10-09 15:01:31 -0400 | [diff] [blame] | 362 | init_completion(&ia->ri_done); |
Chuck Lever | bebd031 | 2017-04-11 13:23:10 -0400 | [diff] [blame^] | 363 | init_completion(&ia->ri_remove_done); |
Tom Talpey | 1a95405 | 2008-10-09 15:01:31 -0400 | [diff] [blame] | 364 | |
Guy Shapiro | fa20105 | 2015-10-22 15:20:10 +0300 | [diff] [blame] | 365 | id = rdma_create_id(&init_net, rpcrdma_conn_upcall, xprt, RDMA_PS_TCP, |
| 366 | IB_QPT_RC); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 367 | if (IS_ERR(id)) { |
| 368 | rc = PTR_ERR(id); |
| 369 | dprintk("RPC: %s: rdma_create_id() failed %i\n", |
| 370 | __func__, rc); |
| 371 | return id; |
| 372 | } |
| 373 | |
Tom Talpey | 5675add | 2008-10-09 15:01:41 -0400 | [diff] [blame] | 374 | ia->ri_async_rc = -ETIMEDOUT; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 375 | rc = rdma_resolve_addr(id, NULL, addr, RDMA_RESOLVE_TIMEOUT); |
| 376 | if (rc) { |
| 377 | dprintk("RPC: %s: rdma_resolve_addr() failed %i\n", |
| 378 | __func__, rc); |
| 379 | goto out; |
| 380 | } |
Chuck Lever | 109b88a | 2016-11-29 10:52:40 -0500 | [diff] [blame] | 381 | rc = wait_for_completion_interruptible_timeout(&ia->ri_done, wtimeout); |
| 382 | if (rc < 0) { |
| 383 | dprintk("RPC: %s: wait() exited: %i\n", |
| 384 | __func__, rc); |
| 385 | goto out; |
| 386 | } |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 387 | |
| 388 | /* FIXME: |
| 389 | * Until xprtrdma supports DEVICE_REMOVAL, the provider must |
| 390 | * be pinned while there are active NFS/RDMA mounts to prevent |
| 391 | * hangs and crashes at umount time. |
| 392 | */ |
| 393 | if (!ia->ri_async_rc && !try_module_get(id->device->owner)) { |
| 394 | dprintk("RPC: %s: Failed to get device module\n", |
| 395 | __func__); |
| 396 | ia->ri_async_rc = -ENODEV; |
| 397 | } |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 398 | rc = ia->ri_async_rc; |
| 399 | if (rc) |
| 400 | goto out; |
| 401 | |
Tom Talpey | 5675add | 2008-10-09 15:01:41 -0400 | [diff] [blame] | 402 | ia->ri_async_rc = -ETIMEDOUT; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 403 | rc = rdma_resolve_route(id, RDMA_RESOLVE_TIMEOUT); |
| 404 | if (rc) { |
| 405 | dprintk("RPC: %s: rdma_resolve_route() failed %i\n", |
| 406 | __func__, rc); |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 407 | goto put; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 408 | } |
Chuck Lever | 109b88a | 2016-11-29 10:52:40 -0500 | [diff] [blame] | 409 | rc = wait_for_completion_interruptible_timeout(&ia->ri_done, wtimeout); |
| 410 | if (rc < 0) { |
| 411 | dprintk("RPC: %s: wait() exited: %i\n", |
| 412 | __func__, rc); |
| 413 | goto put; |
| 414 | } |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 415 | rc = ia->ri_async_rc; |
| 416 | if (rc) |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 417 | goto put; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 418 | |
| 419 | return id; |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 420 | put: |
| 421 | module_put(id->device->owner); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 422 | out: |
| 423 | rdma_destroy_id(id); |
| 424 | return ERR_PTR(rc); |
| 425 | } |
| 426 | |
| 427 | /* |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 428 | * Exported functions. |
| 429 | */ |
| 430 | |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 431 | /** |
| 432 | * rpcrdma_ia_open - Open and initialize an Interface Adapter. |
| 433 | * @xprt: controlling transport |
| 434 | * @addr: IP address of remote peer |
| 435 | * |
| 436 | * Returns 0 on success, negative errno if an appropriate |
| 437 | * Interface Adapter could not be found and opened. |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 438 | */ |
| 439 | int |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 440 | rpcrdma_ia_open(struct rpcrdma_xprt *xprt, struct sockaddr *addr) |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 441 | { |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 442 | struct rpcrdma_ia *ia = &xprt->rx_ia; |
Chuck Lever | d1ed857 | 2015-08-03 13:03:30 -0400 | [diff] [blame] | 443 | int rc; |
| 444 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 445 | ia->ri_id = rpcrdma_create_id(xprt, ia, addr); |
| 446 | if (IS_ERR(ia->ri_id)) { |
| 447 | rc = PTR_ERR(ia->ri_id); |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 448 | goto out_err; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 449 | } |
Chuck Lever | 89e0d112 | 2015-05-26 11:51:56 -0400 | [diff] [blame] | 450 | ia->ri_device = ia->ri_id->device; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 451 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 452 | ia->ri_pd = ib_alloc_pd(ia->ri_device, 0); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 453 | if (IS_ERR(ia->ri_pd)) { |
| 454 | rc = PTR_ERR(ia->ri_pd); |
Chuck Lever | b54054c | 2016-06-29 13:53:27 -0400 | [diff] [blame] | 455 | pr_err("rpcrdma: ib_alloc_pd() returned %d\n", rc); |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 456 | goto out_err; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 457 | } |
| 458 | |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 459 | switch (xprt_rdma_memreg_strategy) { |
Tom Talpey | 3197d309 | 2008-10-09 15:00:20 -0400 | [diff] [blame] | 460 | case RPCRDMA_FRMR: |
Chuck Lever | b54054c | 2016-06-29 13:53:27 -0400 | [diff] [blame] | 461 | if (frwr_is_supported(ia)) { |
| 462 | ia->ri_ops = &rpcrdma_frwr_memreg_ops; |
| 463 | break; |
| 464 | } |
| 465 | /*FALLTHROUGH*/ |
Tom Talpey | bd7ed1d | 2008-10-09 15:00:09 -0400 | [diff] [blame] | 466 | case RPCRDMA_MTHCAFMR: |
Chuck Lever | b54054c | 2016-06-29 13:53:27 -0400 | [diff] [blame] | 467 | if (fmr_is_supported(ia)) { |
| 468 | ia->ri_ops = &rpcrdma_fmr_memreg_ops; |
| 469 | break; |
| 470 | } |
| 471 | /*FALLTHROUGH*/ |
Tom Talpey | bd7ed1d | 2008-10-09 15:00:09 -0400 | [diff] [blame] | 472 | default: |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 473 | pr_err("rpcrdma: Device %s does not support memreg mode %d\n", |
| 474 | ia->ri_device->name, xprt_rdma_memreg_strategy); |
Chuck Lever | b54054c | 2016-06-29 13:53:27 -0400 | [diff] [blame] | 475 | rc = -EINVAL; |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 476 | goto out_err; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 477 | } |
| 478 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 479 | return 0; |
Chuck Lever | 5ae711a | 2015-01-21 11:03:19 -0500 | [diff] [blame] | 480 | |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 481 | out_err: |
| 482 | rpcrdma_ia_close(ia); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 483 | return rc; |
| 484 | } |
| 485 | |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 486 | /** |
Chuck Lever | bebd031 | 2017-04-11 13:23:10 -0400 | [diff] [blame^] | 487 | * rpcrdma_ia_remove - Handle device driver unload |
| 488 | * @ia: interface adapter being removed |
| 489 | * |
| 490 | * Divest transport H/W resources associated with this adapter, |
| 491 | * but allow it to be restored later. |
| 492 | */ |
| 493 | void |
| 494 | rpcrdma_ia_remove(struct rpcrdma_ia *ia) |
| 495 | { |
| 496 | struct rpcrdma_xprt *r_xprt = container_of(ia, struct rpcrdma_xprt, |
| 497 | rx_ia); |
| 498 | struct rpcrdma_ep *ep = &r_xprt->rx_ep; |
| 499 | struct rpcrdma_buffer *buf = &r_xprt->rx_buf; |
| 500 | struct rpcrdma_req *req; |
| 501 | struct rpcrdma_rep *rep; |
| 502 | |
| 503 | cancel_delayed_work_sync(&buf->rb_refresh_worker); |
| 504 | |
| 505 | /* This is similar to rpcrdma_ep_destroy, but: |
| 506 | * - Don't cancel the connect worker. |
| 507 | * - Don't call rpcrdma_ep_disconnect, which waits |
| 508 | * for another conn upcall, which will deadlock. |
| 509 | * - rdma_disconnect is unneeded, the underlying |
| 510 | * connection is already gone. |
| 511 | */ |
| 512 | if (ia->ri_id->qp) { |
| 513 | ib_drain_qp(ia->ri_id->qp); |
| 514 | rdma_destroy_qp(ia->ri_id); |
| 515 | ia->ri_id->qp = NULL; |
| 516 | } |
| 517 | ib_free_cq(ep->rep_attr.recv_cq); |
| 518 | ib_free_cq(ep->rep_attr.send_cq); |
| 519 | |
| 520 | /* The ULP is responsible for ensuring all DMA |
| 521 | * mappings and MRs are gone. |
| 522 | */ |
| 523 | list_for_each_entry(rep, &buf->rb_recv_bufs, rr_list) |
| 524 | rpcrdma_dma_unmap_regbuf(rep->rr_rdmabuf); |
| 525 | list_for_each_entry(req, &buf->rb_allreqs, rl_all) { |
| 526 | rpcrdma_dma_unmap_regbuf(req->rl_rdmabuf); |
| 527 | rpcrdma_dma_unmap_regbuf(req->rl_sendbuf); |
| 528 | rpcrdma_dma_unmap_regbuf(req->rl_recvbuf); |
| 529 | } |
| 530 | rpcrdma_destroy_mrs(buf); |
| 531 | |
| 532 | /* Allow waiters to continue */ |
| 533 | complete(&ia->ri_remove_done); |
| 534 | } |
| 535 | |
| 536 | /** |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 537 | * rpcrdma_ia_close - Clean up/close an IA. |
| 538 | * @ia: interface adapter to close |
| 539 | * |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 540 | */ |
| 541 | void |
| 542 | rpcrdma_ia_close(struct rpcrdma_ia *ia) |
| 543 | { |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 544 | dprintk("RPC: %s: entering\n", __func__); |
Tom Talpey | fee08ca | 2008-10-09 15:01:00 -0400 | [diff] [blame] | 545 | if (ia->ri_id != NULL && !IS_ERR(ia->ri_id)) { |
| 546 | if (ia->ri_id->qp) |
| 547 | rdma_destroy_qp(ia->ri_id); |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 548 | rpcrdma_destroy_id(ia->ri_id); |
Tom Talpey | fee08ca | 2008-10-09 15:01:00 -0400 | [diff] [blame] | 549 | } |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 550 | ia->ri_id = NULL; |
| 551 | ia->ri_device = NULL; |
Chuck Lever | 6d44698 | 2015-05-26 11:51:27 -0400 | [diff] [blame] | 552 | |
| 553 | /* If the pd is still busy, xprtrdma missed freeing a resource */ |
| 554 | if (ia->ri_pd && !IS_ERR(ia->ri_pd)) |
Jason Gunthorpe | 7dd7864 | 2015-08-05 14:34:31 -0600 | [diff] [blame] | 555 | ib_dealloc_pd(ia->ri_pd); |
Chuck Lever | fff0959 | 2017-04-11 13:22:54 -0400 | [diff] [blame] | 556 | ia->ri_pd = NULL; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Create unconnected endpoint. |
| 561 | */ |
| 562 | int |
| 563 | rpcrdma_ep_create(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia, |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 564 | struct rpcrdma_create_data_internal *cdata) |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 565 | { |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 566 | struct rpcrdma_connect_private *pmsg = &ep->rep_cm_private; |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 567 | unsigned int max_qp_wr, max_sge; |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 568 | struct ib_cq *sendcq, *recvcq; |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 569 | int rc; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 570 | |
Chuck Lever | eed5087 | 2017-03-11 15:52:47 -0500 | [diff] [blame] | 571 | max_sge = min_t(unsigned int, ia->ri_device->attrs.max_sge, |
| 572 | RPCRDMA_MAX_SEND_SGES); |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 573 | if (max_sge < RPCRDMA_MIN_SEND_SGES) { |
| 574 | pr_warn("rpcrdma: HCA provides only %d send SGEs\n", max_sge); |
Chuck Lever | b3221d6 | 2015-08-03 13:03:39 -0400 | [diff] [blame] | 575 | return -ENOMEM; |
| 576 | } |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 577 | ia->ri_max_send_sges = max_sge - RPCRDMA_MIN_SEND_SGES; |
Chuck Lever | b3221d6 | 2015-08-03 13:03:39 -0400 | [diff] [blame] | 578 | |
Or Gerlitz | e3e45b1 | 2015-12-18 10:59:48 +0200 | [diff] [blame] | 579 | if (ia->ri_device->attrs.max_qp_wr <= RPCRDMA_BACKWARD_WRS) { |
Chuck Lever | 124fa17 | 2015-10-24 17:27:51 -0400 | [diff] [blame] | 580 | dprintk("RPC: %s: insufficient wqe's available\n", |
| 581 | __func__); |
| 582 | return -ENOMEM; |
| 583 | } |
Chuck Lever | 550d750 | 2016-05-02 14:41:47 -0400 | [diff] [blame] | 584 | max_qp_wr = ia->ri_device->attrs.max_qp_wr - RPCRDMA_BACKWARD_WRS - 1; |
Chuck Lever | 124fa17 | 2015-10-24 17:27:51 -0400 | [diff] [blame] | 585 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 586 | /* check provider's send/recv wr limits */ |
Chuck Lever | 124fa17 | 2015-10-24 17:27:51 -0400 | [diff] [blame] | 587 | if (cdata->max_requests > max_qp_wr) |
| 588 | cdata->max_requests = max_qp_wr; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 589 | |
| 590 | ep->rep_attr.event_handler = rpcrdma_qp_async_error_upcall; |
| 591 | ep->rep_attr.qp_context = ep; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 592 | ep->rep_attr.srq = NULL; |
| 593 | ep->rep_attr.cap.max_send_wr = cdata->max_requests; |
Chuck Lever | 124fa17 | 2015-10-24 17:27:51 -0400 | [diff] [blame] | 594 | ep->rep_attr.cap.max_send_wr += RPCRDMA_BACKWARD_WRS; |
Chuck Lever | 550d750 | 2016-05-02 14:41:47 -0400 | [diff] [blame] | 595 | ep->rep_attr.cap.max_send_wr += 1; /* drain cqe */ |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 596 | rc = ia->ri_ops->ro_open(ia, ep, cdata); |
| 597 | if (rc) |
| 598 | return rc; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 599 | ep->rep_attr.cap.max_recv_wr = cdata->max_requests; |
Chuck Lever | 124fa17 | 2015-10-24 17:27:51 -0400 | [diff] [blame] | 600 | ep->rep_attr.cap.max_recv_wr += RPCRDMA_BACKWARD_WRS; |
Chuck Lever | 550d750 | 2016-05-02 14:41:47 -0400 | [diff] [blame] | 601 | ep->rep_attr.cap.max_recv_wr += 1; /* drain cqe */ |
Chuck Lever | 16f906d | 2017-02-08 17:00:10 -0500 | [diff] [blame] | 602 | ep->rep_attr.cap.max_send_sge = max_sge; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 603 | ep->rep_attr.cap.max_recv_sge = 1; |
| 604 | ep->rep_attr.cap.max_inline_data = 0; |
| 605 | ep->rep_attr.sq_sig_type = IB_SIGNAL_REQ_WR; |
| 606 | ep->rep_attr.qp_type = IB_QPT_RC; |
| 607 | ep->rep_attr.port_num = ~0; |
| 608 | |
| 609 | dprintk("RPC: %s: requested max: dtos: send %d recv %d; " |
| 610 | "iovs: send %d recv %d\n", |
| 611 | __func__, |
| 612 | ep->rep_attr.cap.max_send_wr, |
| 613 | ep->rep_attr.cap.max_recv_wr, |
| 614 | ep->rep_attr.cap.max_send_sge, |
| 615 | ep->rep_attr.cap.max_recv_sge); |
| 616 | |
| 617 | /* set trigger for requesting send completion */ |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 618 | ep->rep_cqinit = ep->rep_attr.cap.max_send_wr/2 - 1; |
Chuck Lever | 26ae9d1 | 2015-12-16 17:23:20 -0500 | [diff] [blame] | 619 | if (ep->rep_cqinit <= 2) |
| 620 | ep->rep_cqinit = 0; /* always signal? */ |
Chuck Lever | 8d38de6 | 2016-11-29 10:52:16 -0500 | [diff] [blame] | 621 | rpcrdma_init_cqcount(ep, 0); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 622 | init_waitqueue_head(&ep->rep_connect_wait); |
Chuck Lever | 254f91e | 2014-05-28 10:32:17 -0400 | [diff] [blame] | 623 | INIT_DELAYED_WORK(&ep->rep_connect_worker, rpcrdma_connect_worker); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 624 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 625 | sendcq = ib_alloc_cq(ia->ri_device, NULL, |
| 626 | ep->rep_attr.cap.max_send_wr + 1, |
| 627 | 0, IB_POLL_SOFTIRQ); |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 628 | if (IS_ERR(sendcq)) { |
| 629 | rc = PTR_ERR(sendcq); |
| 630 | dprintk("RPC: %s: failed to create send CQ: %i\n", |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 631 | __func__, rc); |
| 632 | goto out1; |
| 633 | } |
| 634 | |
Chuck Lever | 552bf22 | 2016-03-04 11:28:36 -0500 | [diff] [blame] | 635 | recvcq = ib_alloc_cq(ia->ri_device, NULL, |
| 636 | ep->rep_attr.cap.max_recv_wr + 1, |
| 637 | 0, IB_POLL_SOFTIRQ); |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 638 | if (IS_ERR(recvcq)) { |
| 639 | rc = PTR_ERR(recvcq); |
| 640 | dprintk("RPC: %s: failed to create recv CQ: %i\n", |
| 641 | __func__, rc); |
| 642 | goto out2; |
| 643 | } |
| 644 | |
Chuck Lever | fc66448 | 2014-05-28 10:33:25 -0400 | [diff] [blame] | 645 | ep->rep_attr.send_cq = sendcq; |
| 646 | ep->rep_attr.recv_cq = recvcq; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 647 | |
| 648 | /* Initialize cma parameters */ |
Chuck Lever | b2dde94 | 2016-05-02 14:43:03 -0400 | [diff] [blame] | 649 | memset(&ep->rep_remote_cma, 0, sizeof(ep->rep_remote_cma)); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 650 | |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 651 | /* Prepare RDMA-CM private message */ |
| 652 | pmsg->cp_magic = rpcrdma_cmp_magic; |
| 653 | pmsg->cp_version = RPCRDMA_CMP_VERSION; |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 654 | pmsg->cp_flags |= ia->ri_ops->ro_send_w_inv_ok; |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 655 | pmsg->cp_send_size = rpcrdma_encode_buffer_size(cdata->inline_wsize); |
| 656 | pmsg->cp_recv_size = rpcrdma_encode_buffer_size(cdata->inline_rsize); |
| 657 | ep->rep_remote_cma.private_data = pmsg; |
| 658 | ep->rep_remote_cma.private_data_len = sizeof(*pmsg); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 659 | |
| 660 | /* Client offers RDMA Read but does not initiate */ |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 661 | ep->rep_remote_cma.initiator_depth = 0; |
Or Gerlitz | e3e45b1 | 2015-12-18 10:59:48 +0200 | [diff] [blame] | 662 | if (ia->ri_device->attrs.max_qp_rd_atom > 32) /* arbitrary but <= 255 */ |
Tom Tucker | b334eaa | 2008-10-09 15:00:30 -0400 | [diff] [blame] | 663 | ep->rep_remote_cma.responder_resources = 32; |
| 664 | else |
Chuck Lever | 7bc7972 | 2015-01-21 11:03:27 -0500 | [diff] [blame] | 665 | ep->rep_remote_cma.responder_resources = |
Or Gerlitz | e3e45b1 | 2015-12-18 10:59:48 +0200 | [diff] [blame] | 666 | ia->ri_device->attrs.max_qp_rd_atom; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 667 | |
Chuck Lever | b2dde94 | 2016-05-02 14:43:03 -0400 | [diff] [blame] | 668 | /* Limit transport retries so client can detect server |
| 669 | * GID changes quickly. RPC layer handles re-establishing |
| 670 | * transport connection and retransmission. |
| 671 | */ |
| 672 | ep->rep_remote_cma.retry_count = 6; |
| 673 | |
| 674 | /* RPC-over-RDMA handles its own flow control. In addition, |
| 675 | * make all RNR NAKs visible so we know that RPC-over-RDMA |
| 676 | * flow control is working correctly (no NAKs should be seen). |
| 677 | */ |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 678 | ep->rep_remote_cma.flow_control = 0; |
| 679 | ep->rep_remote_cma.rnr_retry_count = 0; |
| 680 | |
| 681 | return 0; |
| 682 | |
| 683 | out2: |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 684 | ib_free_cq(sendcq); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 685 | out1: |
| 686 | return rc; |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * rpcrdma_ep_destroy |
| 691 | * |
| 692 | * Disconnect and destroy endpoint. After this, the only |
| 693 | * valid operations on the ep are to free it (if dynamically |
| 694 | * allocated) or re-create it. |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 695 | */ |
Chuck Lever | 7f1d541 | 2014-05-28 10:33:16 -0400 | [diff] [blame] | 696 | void |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 697 | rpcrdma_ep_destroy(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia) |
| 698 | { |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 699 | dprintk("RPC: %s: entering, connected is %d\n", |
| 700 | __func__, ep->rep_connected); |
| 701 | |
Chuck Lever | 254f91e | 2014-05-28 10:32:17 -0400 | [diff] [blame] | 702 | cancel_delayed_work_sync(&ep->rep_connect_worker); |
| 703 | |
Steve Wise | 72c0217 | 2015-09-21 12:24:23 -0500 | [diff] [blame] | 704 | if (ia->ri_id->qp) { |
Chuck Lever | 550d750 | 2016-05-02 14:41:47 -0400 | [diff] [blame] | 705 | rpcrdma_ep_disconnect(ep, ia); |
Tom Talpey | fee08ca | 2008-10-09 15:01:00 -0400 | [diff] [blame] | 706 | rdma_destroy_qp(ia->ri_id); |
| 707 | ia->ri_id->qp = NULL; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 708 | } |
| 709 | |
Chuck Lever | 552bf22 | 2016-03-04 11:28:36 -0500 | [diff] [blame] | 710 | ib_free_cq(ep->rep_attr.recv_cq); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 711 | ib_free_cq(ep->rep_attr.send_cq); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | /* |
| 715 | * Connect unconnected endpoint. |
| 716 | */ |
| 717 | int |
| 718 | rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia) |
| 719 | { |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 720 | struct rpcrdma_xprt *r_xprt = container_of(ia, struct rpcrdma_xprt, |
| 721 | rx_ia); |
Chuck Lever | 73806c8 | 2014-07-29 17:23:25 -0400 | [diff] [blame] | 722 | struct rdma_cm_id *id, *old; |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 723 | struct sockaddr *sap; |
| 724 | unsigned int extras; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 725 | int rc = 0; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 726 | |
Tom Talpey | c055551 | 2008-10-10 11:32:45 -0400 | [diff] [blame] | 727 | if (ep->rep_connected != 0) { |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 728 | retry: |
Chuck Lever | ec62f40 | 2014-05-28 10:34:07 -0400 | [diff] [blame] | 729 | dprintk("RPC: %s: reconnecting...\n", __func__); |
Chuck Lever | 282191c | 2014-07-29 17:25:55 -0400 | [diff] [blame] | 730 | |
| 731 | rpcrdma_ep_disconnect(ep, ia); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 732 | |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 733 | sap = (struct sockaddr *)&r_xprt->rx_data.addr; |
| 734 | id = rpcrdma_create_id(r_xprt, ia, sap); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 735 | if (IS_ERR(id)) { |
Chuck Lever | ec62f40 | 2014-05-28 10:34:07 -0400 | [diff] [blame] | 736 | rc = -EHOSTUNREACH; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 737 | goto out; |
| 738 | } |
| 739 | /* TEMP TEMP TEMP - fail if new device: |
| 740 | * Deregister/remarshal *all* requests! |
| 741 | * Close and recreate adapter, pd, etc! |
| 742 | * Re-determine all attributes still sane! |
| 743 | * More stuff I haven't thought of! |
| 744 | * Rrrgh! |
| 745 | */ |
Chuck Lever | 89e0d112 | 2015-05-26 11:51:56 -0400 | [diff] [blame] | 746 | if (ia->ri_device != id->device) { |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 747 | printk("RPC: %s: can't reconnect on " |
| 748 | "different device!\n", __func__); |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 749 | rpcrdma_destroy_id(id); |
Chuck Lever | ec62f40 | 2014-05-28 10:34:07 -0400 | [diff] [blame] | 750 | rc = -ENETUNREACH; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 751 | goto out; |
| 752 | } |
| 753 | /* END TEMP */ |
Chuck Lever | ec62f40 | 2014-05-28 10:34:07 -0400 | [diff] [blame] | 754 | rc = rdma_create_qp(id, ia->ri_pd, &ep->rep_attr); |
| 755 | if (rc) { |
| 756 | dprintk("RPC: %s: rdma_create_qp failed %i\n", |
| 757 | __func__, rc); |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 758 | rpcrdma_destroy_id(id); |
Chuck Lever | ec62f40 | 2014-05-28 10:34:07 -0400 | [diff] [blame] | 759 | rc = -ENETUNREACH; |
| 760 | goto out; |
| 761 | } |
Chuck Lever | 73806c8 | 2014-07-29 17:23:25 -0400 | [diff] [blame] | 762 | |
Chuck Lever | 73806c8 | 2014-07-29 17:23:25 -0400 | [diff] [blame] | 763 | old = ia->ri_id; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 764 | ia->ri_id = id; |
Chuck Lever | 73806c8 | 2014-07-29 17:23:25 -0400 | [diff] [blame] | 765 | |
| 766 | rdma_destroy_qp(old); |
Devesh Sharma | d0f36c4 | 2015-08-03 13:05:04 -0400 | [diff] [blame] | 767 | rpcrdma_destroy_id(old); |
Chuck Lever | ec62f40 | 2014-05-28 10:34:07 -0400 | [diff] [blame] | 768 | } else { |
| 769 | dprintk("RPC: %s: connecting...\n", __func__); |
| 770 | rc = rdma_create_qp(ia->ri_id, ia->ri_pd, &ep->rep_attr); |
| 771 | if (rc) { |
| 772 | dprintk("RPC: %s: rdma_create_qp failed %i\n", |
| 773 | __func__, rc); |
| 774 | /* do not update ep->rep_connected */ |
| 775 | return -ENETUNREACH; |
| 776 | } |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 777 | } |
| 778 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 779 | 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\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 788 | wait_event_interruptible(ep->rep_connect_wait, ep->rep_connected != 0); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 789 | if (ep->rep_connected <= 0) { |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 790 | if (ep->rep_connected == -EAGAIN) |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 791 | goto retry; |
| 792 | rc = ep->rep_connected; |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 793 | goto out; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 794 | } |
| 795 | |
Chuck Lever | 0a90487 | 2017-02-08 17:00:35 -0500 | [diff] [blame] | 796 | 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\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 801 | out: |
| 802 | if (rc) |
| 803 | ep->rep_connected = rc; |
| 804 | return rc; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * rpcrdma_ep_disconnect |
| 809 | * |
| 810 | * This is separate from destroy to facilitate the ability |
| 811 | * to reconnect without recreating the endpoint. |
| 812 | * |
| 813 | * This call is not reentrant, and must not be made in parallel |
| 814 | * on the same endpoint. |
| 815 | */ |
Chuck Lever | 282191c | 2014-07-29 17:25:55 -0400 | [diff] [blame] | 816 | void |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 817 | rpcrdma_ep_disconnect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia) |
| 818 | { |
| 819 | int rc; |
| 820 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 821 | rc = rdma_disconnect(ia->ri_id); |
| 822 | if (!rc) { |
| 823 | /* returns without wait if not connected */ |
| 824 | wait_event_interruptible(ep->rep_connect_wait, |
| 825 | ep->rep_connected != 1); |
| 826 | dprintk("RPC: %s: after wait, %sconnected\n", __func__, |
| 827 | (ep->rep_connected == 1) ? "still " : "dis"); |
| 828 | } else { |
| 829 | dprintk("RPC: %s: rdma_disconnect %i\n", __func__, rc); |
| 830 | ep->rep_connected = rc; |
| 831 | } |
Chuck Lever | 550d750 | 2016-05-02 14:41:47 -0400 | [diff] [blame] | 832 | |
| 833 | ib_drain_qp(ia->ri_id->qp); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 834 | } |
| 835 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 836 | static void |
| 837 | rpcrdma_mr_recovery_worker(struct work_struct *work) |
| 838 | { |
| 839 | struct rpcrdma_buffer *buf = container_of(work, struct rpcrdma_buffer, |
| 840 | rb_recovery_worker.work); |
| 841 | struct rpcrdma_mw *mw; |
| 842 | |
| 843 | spin_lock(&buf->rb_recovery_lock); |
| 844 | while (!list_empty(&buf->rb_stale_mrs)) { |
Chuck Lever | 9a5c63e | 2017-02-08 17:00:43 -0500 | [diff] [blame] | 845 | mw = rpcrdma_pop_mw(&buf->rb_stale_mrs); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 846 | spin_unlock(&buf->rb_recovery_lock); |
| 847 | |
| 848 | dprintk("RPC: %s: recovering MR %p\n", __func__, mw); |
| 849 | mw->mw_xprt->rx_ia.ri_ops->ro_recover_mr(mw); |
| 850 | |
| 851 | spin_lock(&buf->rb_recovery_lock); |
kbuild test robot | 53d7852 | 2016-07-16 06:02:05 +0800 | [diff] [blame] | 852 | } |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 853 | spin_unlock(&buf->rb_recovery_lock); |
| 854 | } |
| 855 | |
| 856 | void |
| 857 | rpcrdma_defer_mr_recovery(struct rpcrdma_mw *mw) |
| 858 | { |
| 859 | struct rpcrdma_xprt *r_xprt = mw->mw_xprt; |
| 860 | struct rpcrdma_buffer *buf = &r_xprt->rx_buf; |
| 861 | |
| 862 | spin_lock(&buf->rb_recovery_lock); |
Chuck Lever | 9a5c63e | 2017-02-08 17:00:43 -0500 | [diff] [blame] | 863 | rpcrdma_push_mw(mw, &buf->rb_stale_mrs); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 864 | spin_unlock(&buf->rb_recovery_lock); |
| 865 | |
| 866 | schedule_delayed_work(&buf->rb_recovery_worker, 0); |
| 867 | } |
| 868 | |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 869 | static void |
| 870 | rpcrdma_create_mrs(struct rpcrdma_xprt *r_xprt) |
| 871 | { |
| 872 | struct rpcrdma_buffer *buf = &r_xprt->rx_buf; |
| 873 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
| 874 | unsigned int count; |
| 875 | LIST_HEAD(free); |
| 876 | LIST_HEAD(all); |
| 877 | |
| 878 | for (count = 0; count < 32; count++) { |
| 879 | struct rpcrdma_mw *mw; |
| 880 | int rc; |
| 881 | |
| 882 | mw = kzalloc(sizeof(*mw), GFP_KERNEL); |
| 883 | if (!mw) |
| 884 | break; |
| 885 | |
| 886 | rc = ia->ri_ops->ro_init_mr(ia, mw); |
| 887 | if (rc) { |
| 888 | kfree(mw); |
| 889 | break; |
| 890 | } |
| 891 | |
| 892 | mw->mw_xprt = r_xprt; |
| 893 | |
| 894 | list_add(&mw->mw_list, &free); |
| 895 | list_add(&mw->mw_all, &all); |
| 896 | } |
| 897 | |
| 898 | spin_lock(&buf->rb_mwlock); |
| 899 | list_splice(&free, &buf->rb_mws); |
| 900 | list_splice(&all, &buf->rb_all); |
| 901 | r_xprt->rx_stats.mrs_allocated += count; |
| 902 | spin_unlock(&buf->rb_mwlock); |
| 903 | |
| 904 | dprintk("RPC: %s: created %u MRs\n", __func__, count); |
| 905 | } |
| 906 | |
| 907 | static void |
| 908 | rpcrdma_mr_refresh_worker(struct work_struct *work) |
| 909 | { |
| 910 | struct rpcrdma_buffer *buf = container_of(work, struct rpcrdma_buffer, |
| 911 | rb_refresh_worker.work); |
| 912 | struct rpcrdma_xprt *r_xprt = container_of(buf, struct rpcrdma_xprt, |
| 913 | rx_buf); |
| 914 | |
| 915 | rpcrdma_create_mrs(r_xprt); |
| 916 | } |
| 917 | |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 918 | struct rpcrdma_req * |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 919 | rpcrdma_create_req(struct rpcrdma_xprt *r_xprt) |
| 920 | { |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 921 | struct rpcrdma_buffer *buffer = &r_xprt->rx_buf; |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 922 | struct rpcrdma_req *req; |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 923 | |
Chuck Lever | 85275c8 | 2015-01-21 11:04:16 -0500 | [diff] [blame] | 924 | req = kzalloc(sizeof(*req), GFP_KERNEL); |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 925 | if (req == NULL) |
Chuck Lever | 85275c8 | 2015-01-21 11:04:16 -0500 | [diff] [blame] | 926 | return ERR_PTR(-ENOMEM); |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 927 | |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 928 | INIT_LIST_HEAD(&req->rl_free); |
| 929 | spin_lock(&buffer->rb_reqslock); |
| 930 | list_add(&req->rl_all, &buffer->rb_allreqs); |
| 931 | spin_unlock(&buffer->rb_reqslock); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 932 | req->rl_cqe.done = rpcrdma_wc_send; |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 933 | req->rl_buffer = &r_xprt->rx_buf; |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 934 | INIT_LIST_HEAD(&req->rl_registered); |
Chuck Lever | 90aab60 | 2016-09-15 10:56:43 -0400 | [diff] [blame] | 935 | req->rl_send_wr.next = NULL; |
| 936 | req->rl_send_wr.wr_cqe = &req->rl_cqe; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 937 | req->rl_send_wr.sg_list = req->rl_send_sge; |
Chuck Lever | 90aab60 | 2016-09-15 10:56:43 -0400 | [diff] [blame] | 938 | req->rl_send_wr.opcode = IB_WR_SEND; |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 939 | return req; |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 940 | } |
| 941 | |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 942 | struct rpcrdma_rep * |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 943 | rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt) |
| 944 | { |
| 945 | struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data; |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 946 | struct rpcrdma_rep *rep; |
| 947 | int rc; |
| 948 | |
| 949 | rc = -ENOMEM; |
Chuck Lever | 6b1184c | 2015-01-21 11:04:25 -0500 | [diff] [blame] | 950 | rep = kzalloc(sizeof(*rep), GFP_KERNEL); |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 951 | if (rep == NULL) |
| 952 | goto out; |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 953 | |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 954 | rep->rr_rdmabuf = rpcrdma_alloc_regbuf(cdata->inline_rsize, |
Chuck Lever | 99ef4db | 2016-09-15 10:56:10 -0400 | [diff] [blame] | 955 | DMA_FROM_DEVICE, GFP_KERNEL); |
Chuck Lever | 6b1184c | 2015-01-21 11:04:25 -0500 | [diff] [blame] | 956 | if (IS_ERR(rep->rr_rdmabuf)) { |
| 957 | rc = PTR_ERR(rep->rr_rdmabuf); |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 958 | goto out_free; |
Chuck Lever | 6b1184c | 2015-01-21 11:04:25 -0500 | [diff] [blame] | 959 | } |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 960 | |
Chuck Lever | 1519e96 | 2016-09-15 10:57:49 -0400 | [diff] [blame] | 961 | rep->rr_cqe.done = rpcrdma_wc_receive; |
Chuck Lever | fed171b | 2015-05-26 11:51:37 -0400 | [diff] [blame] | 962 | rep->rr_rxprt = r_xprt; |
Chuck Lever | 496b77a | 2016-09-15 10:57:57 -0400 | [diff] [blame] | 963 | INIT_WORK(&rep->rr_work, rpcrdma_reply_handler); |
Chuck Lever | 6ea8e71 | 2016-09-15 10:56:51 -0400 | [diff] [blame] | 964 | rep->rr_recv_wr.next = NULL; |
| 965 | rep->rr_recv_wr.wr_cqe = &rep->rr_cqe; |
| 966 | rep->rr_recv_wr.sg_list = &rep->rr_rdmabuf->rg_iov; |
| 967 | rep->rr_recv_wr.num_sge = 1; |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 968 | return rep; |
| 969 | |
| 970 | out_free: |
| 971 | kfree(rep); |
| 972 | out: |
| 973 | return ERR_PTR(rc); |
| 974 | } |
| 975 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 976 | int |
Chuck Lever | ac920d0 | 2015-01-21 11:03:44 -0500 | [diff] [blame] | 977 | rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt) |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 978 | { |
Chuck Lever | ac920d0 | 2015-01-21 11:03:44 -0500 | [diff] [blame] | 979 | struct rpcrdma_buffer *buf = &r_xprt->rx_buf; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 980 | int i, rc; |
| 981 | |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 982 | buf->rb_max_requests = r_xprt->rx_data.max_requests; |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 983 | buf->rb_bc_srv_max_requests = 0; |
Chuck Lever | 23826c7 | 2016-03-04 11:28:27 -0500 | [diff] [blame] | 984 | atomic_set(&buf->rb_credits, 1); |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 985 | spin_lock_init(&buf->rb_mwlock); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 986 | spin_lock_init(&buf->rb_lock); |
| 987 | spin_lock_init(&buf->rb_recovery_lock); |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 988 | INIT_LIST_HEAD(&buf->rb_mws); |
| 989 | INIT_LIST_HEAD(&buf->rb_all); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 990 | INIT_LIST_HEAD(&buf->rb_stale_mrs); |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 991 | INIT_DELAYED_WORK(&buf->rb_refresh_worker, |
| 992 | rpcrdma_mr_refresh_worker); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 993 | INIT_DELAYED_WORK(&buf->rb_recovery_worker, |
| 994 | rpcrdma_mr_recovery_worker); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 995 | |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 996 | rpcrdma_create_mrs(r_xprt); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 997 | |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 998 | INIT_LIST_HEAD(&buf->rb_send_bufs); |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 999 | INIT_LIST_HEAD(&buf->rb_allreqs); |
| 1000 | spin_lock_init(&buf->rb_reqslock); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1001 | for (i = 0; i < buf->rb_max_requests; i++) { |
| 1002 | struct rpcrdma_req *req; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1003 | |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1004 | req = rpcrdma_create_req(r_xprt); |
| 1005 | if (IS_ERR(req)) { |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1006 | dprintk("RPC: %s: request buffer %d alloc" |
| 1007 | " failed\n", __func__, i); |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1008 | rc = PTR_ERR(req); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1009 | goto out; |
| 1010 | } |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1011 | req->rl_backchannel = false; |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1012 | list_add(&req->rl_free, &buf->rb_send_bufs); |
| 1013 | } |
| 1014 | |
| 1015 | INIT_LIST_HEAD(&buf->rb_recv_bufs); |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1016 | for (i = 0; i < buf->rb_max_requests + RPCRDMA_MAX_BC_REQUESTS; i++) { |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1017 | struct rpcrdma_rep *rep; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1018 | |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1019 | rep = rpcrdma_create_rep(r_xprt); |
| 1020 | if (IS_ERR(rep)) { |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1021 | dprintk("RPC: %s: reply buffer %d alloc failed\n", |
| 1022 | __func__, i); |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1023 | rc = PTR_ERR(rep); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1024 | goto out; |
| 1025 | } |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1026 | list_add(&rep->rr_list, &buf->rb_recv_bufs); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1027 | } |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1028 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1029 | return 0; |
| 1030 | out: |
| 1031 | rpcrdma_buffer_destroy(buf); |
| 1032 | return rc; |
| 1033 | } |
| 1034 | |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1035 | static struct rpcrdma_req * |
| 1036 | rpcrdma_buffer_get_req_locked(struct rpcrdma_buffer *buf) |
| 1037 | { |
| 1038 | struct rpcrdma_req *req; |
| 1039 | |
| 1040 | req = list_first_entry(&buf->rb_send_bufs, |
| 1041 | struct rpcrdma_req, rl_free); |
| 1042 | list_del(&req->rl_free); |
| 1043 | return req; |
| 1044 | } |
| 1045 | |
| 1046 | static struct rpcrdma_rep * |
| 1047 | rpcrdma_buffer_get_rep_locked(struct rpcrdma_buffer *buf) |
| 1048 | { |
| 1049 | struct rpcrdma_rep *rep; |
| 1050 | |
| 1051 | rep = list_first_entry(&buf->rb_recv_bufs, |
| 1052 | struct rpcrdma_rep, rr_list); |
| 1053 | list_del(&rep->rr_list); |
| 1054 | return rep; |
| 1055 | } |
| 1056 | |
Chuck Lever | 2e84522 | 2014-07-29 17:25:38 -0400 | [diff] [blame] | 1057 | static void |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 1058 | rpcrdma_destroy_rep(struct rpcrdma_rep *rep) |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1059 | { |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 1060 | rpcrdma_free_regbuf(rep->rr_rdmabuf); |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1061 | kfree(rep); |
| 1062 | } |
| 1063 | |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1064 | void |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 1065 | rpcrdma_destroy_req(struct rpcrdma_req *req) |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1066 | { |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 1067 | rpcrdma_free_regbuf(req->rl_recvbuf); |
| 1068 | rpcrdma_free_regbuf(req->rl_sendbuf); |
| 1069 | rpcrdma_free_regbuf(req->rl_rdmabuf); |
Chuck Lever | 1392402 | 2015-01-21 11:03:52 -0500 | [diff] [blame] | 1070 | kfree(req); |
| 1071 | } |
| 1072 | |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 1073 | static void |
| 1074 | rpcrdma_destroy_mrs(struct rpcrdma_buffer *buf) |
| 1075 | { |
| 1076 | struct rpcrdma_xprt *r_xprt = container_of(buf, struct rpcrdma_xprt, |
| 1077 | rx_buf); |
| 1078 | struct rpcrdma_ia *ia = rdmab_to_ia(buf); |
| 1079 | struct rpcrdma_mw *mw; |
| 1080 | unsigned int count; |
| 1081 | |
| 1082 | count = 0; |
| 1083 | spin_lock(&buf->rb_mwlock); |
| 1084 | while (!list_empty(&buf->rb_all)) { |
| 1085 | mw = list_entry(buf->rb_all.next, struct rpcrdma_mw, mw_all); |
| 1086 | list_del(&mw->mw_all); |
| 1087 | |
| 1088 | spin_unlock(&buf->rb_mwlock); |
| 1089 | ia->ri_ops->ro_release_mr(mw); |
| 1090 | count++; |
| 1091 | spin_lock(&buf->rb_mwlock); |
| 1092 | } |
| 1093 | spin_unlock(&buf->rb_mwlock); |
| 1094 | r_xprt->rx_stats.mrs_allocated = 0; |
| 1095 | |
| 1096 | dprintk("RPC: %s: released %u MRs\n", __func__, count); |
| 1097 | } |
| 1098 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1099 | void |
| 1100 | rpcrdma_buffer_destroy(struct rpcrdma_buffer *buf) |
| 1101 | { |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 1102 | cancel_delayed_work_sync(&buf->rb_recovery_worker); |
Chuck Lever | 9378b27 | 2017-04-11 13:22:29 -0400 | [diff] [blame] | 1103 | cancel_delayed_work_sync(&buf->rb_refresh_worker); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 1104 | |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1105 | while (!list_empty(&buf->rb_recv_bufs)) { |
| 1106 | struct rpcrdma_rep *rep; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1107 | |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1108 | rep = rpcrdma_buffer_get_rep_locked(buf); |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 1109 | rpcrdma_destroy_rep(rep); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1110 | } |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1111 | buf->rb_send_count = 0; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1112 | |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1113 | spin_lock(&buf->rb_reqslock); |
| 1114 | while (!list_empty(&buf->rb_allreqs)) { |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1115 | struct rpcrdma_req *req; |
Allen Andrews | 4034ba0 | 2014-05-28 10:32:09 -0400 | [diff] [blame] | 1116 | |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1117 | req = list_first_entry(&buf->rb_allreqs, |
| 1118 | struct rpcrdma_req, rl_all); |
| 1119 | list_del(&req->rl_all); |
| 1120 | |
| 1121 | spin_unlock(&buf->rb_reqslock); |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 1122 | rpcrdma_destroy_req(req); |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1123 | spin_lock(&buf->rb_reqslock); |
Chuck Lever | 9f9d802 | 2014-07-29 17:24:45 -0400 | [diff] [blame] | 1124 | } |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1125 | spin_unlock(&buf->rb_reqslock); |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1126 | buf->rb_recv_count = 0; |
Chuck Lever | 9f9d802 | 2014-07-29 17:24:45 -0400 | [diff] [blame] | 1127 | |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 1128 | rpcrdma_destroy_mrs(buf); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1129 | } |
| 1130 | |
Chuck Lever | 346aa66 | 2015-05-26 11:52:06 -0400 | [diff] [blame] | 1131 | struct rpcrdma_mw * |
| 1132 | rpcrdma_get_mw(struct rpcrdma_xprt *r_xprt) |
Chuck Lever | c2922c0 | 2014-07-29 17:24:36 -0400 | [diff] [blame] | 1133 | { |
Chuck Lever | 346aa66 | 2015-05-26 11:52:06 -0400 | [diff] [blame] | 1134 | struct rpcrdma_buffer *buf = &r_xprt->rx_buf; |
| 1135 | struct rpcrdma_mw *mw = NULL; |
Chuck Lever | 346aa66 | 2015-05-26 11:52:06 -0400 | [diff] [blame] | 1136 | |
Chuck Lever | 58d1dcf | 2015-05-26 11:53:13 -0400 | [diff] [blame] | 1137 | spin_lock(&buf->rb_mwlock); |
Chuck Lever | 9a5c63e | 2017-02-08 17:00:43 -0500 | [diff] [blame] | 1138 | if (!list_empty(&buf->rb_mws)) |
| 1139 | mw = rpcrdma_pop_mw(&buf->rb_mws); |
Chuck Lever | 58d1dcf | 2015-05-26 11:53:13 -0400 | [diff] [blame] | 1140 | spin_unlock(&buf->rb_mwlock); |
Chuck Lever | 346aa66 | 2015-05-26 11:52:06 -0400 | [diff] [blame] | 1141 | |
| 1142 | if (!mw) |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 1143 | goto out_nomws; |
Chuck Lever | 346aa66 | 2015-05-26 11:52:06 -0400 | [diff] [blame] | 1144 | return mw; |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 1145 | |
| 1146 | out_nomws: |
| 1147 | dprintk("RPC: %s: no MWs available\n", __func__); |
Chuck Lever | bebd031 | 2017-04-11 13:23:10 -0400 | [diff] [blame^] | 1148 | if (r_xprt->rx_ep.rep_connected != -ENODEV) |
| 1149 | schedule_delayed_work(&buf->rb_refresh_worker, 0); |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 1150 | |
| 1151 | /* Allow the reply handler and refresh worker to run */ |
| 1152 | cond_resched(); |
| 1153 | |
| 1154 | return NULL; |
Chuck Lever | c2922c0 | 2014-07-29 17:24:36 -0400 | [diff] [blame] | 1155 | } |
| 1156 | |
Chuck Lever | 346aa66 | 2015-05-26 11:52:06 -0400 | [diff] [blame] | 1157 | void |
| 1158 | rpcrdma_put_mw(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mw *mw) |
Chuck Lever | c2922c0 | 2014-07-29 17:24:36 -0400 | [diff] [blame] | 1159 | { |
Chuck Lever | 346aa66 | 2015-05-26 11:52:06 -0400 | [diff] [blame] | 1160 | struct rpcrdma_buffer *buf = &r_xprt->rx_buf; |
Chuck Lever | c2922c0 | 2014-07-29 17:24:36 -0400 | [diff] [blame] | 1161 | |
Chuck Lever | 58d1dcf | 2015-05-26 11:53:13 -0400 | [diff] [blame] | 1162 | spin_lock(&buf->rb_mwlock); |
Chuck Lever | 9a5c63e | 2017-02-08 17:00:43 -0500 | [diff] [blame] | 1163 | rpcrdma_push_mw(mw, &buf->rb_mws); |
Chuck Lever | 58d1dcf | 2015-05-26 11:53:13 -0400 | [diff] [blame] | 1164 | spin_unlock(&buf->rb_mwlock); |
Chuck Lever | c2922c0 | 2014-07-29 17:24:36 -0400 | [diff] [blame] | 1165 | } |
| 1166 | |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1167 | static struct rpcrdma_rep * |
| 1168 | rpcrdma_buffer_get_rep(struct rpcrdma_buffer *buffers) |
| 1169 | { |
| 1170 | /* If an RPC previously completed without a reply (say, a |
| 1171 | * credential problem or a soft timeout occurs) then hold off |
| 1172 | * on supplying more Receive buffers until the number of new |
| 1173 | * pending RPCs catches up to the number of posted Receives. |
| 1174 | */ |
| 1175 | if (unlikely(buffers->rb_send_count < buffers->rb_recv_count)) |
| 1176 | return NULL; |
| 1177 | |
| 1178 | if (unlikely(list_empty(&buffers->rb_recv_bufs))) |
| 1179 | return NULL; |
| 1180 | buffers->rb_recv_count++; |
| 1181 | return rpcrdma_buffer_get_rep_locked(buffers); |
| 1182 | } |
| 1183 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1184 | /* |
| 1185 | * Get a set of request/reply buffers. |
Chuck Lever | 78d506e | 2016-09-06 11:22:49 -0400 | [diff] [blame] | 1186 | * |
| 1187 | * Reply buffer (if available) is attached to send buffer upon return. |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1188 | */ |
| 1189 | struct rpcrdma_req * |
| 1190 | rpcrdma_buffer_get(struct rpcrdma_buffer *buffers) |
| 1191 | { |
| 1192 | struct rpcrdma_req *req; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1193 | |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1194 | spin_lock(&buffers->rb_lock); |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1195 | if (list_empty(&buffers->rb_send_bufs)) |
| 1196 | goto out_reqbuf; |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1197 | buffers->rb_send_count++; |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1198 | req = rpcrdma_buffer_get_req_locked(buffers); |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1199 | req->rl_reply = rpcrdma_buffer_get_rep(buffers); |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1200 | spin_unlock(&buffers->rb_lock); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1201 | return req; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1202 | |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1203 | out_reqbuf: |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1204 | spin_unlock(&buffers->rb_lock); |
Chuck Lever | 78d506e | 2016-09-06 11:22:49 -0400 | [diff] [blame] | 1205 | pr_warn("RPC: %s: out of request buffers\n", __func__); |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1206 | return NULL; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | /* |
| 1210 | * Put request/reply buffers back into pool. |
| 1211 | * Pre-decrement counter/array index. |
| 1212 | */ |
| 1213 | void |
| 1214 | rpcrdma_buffer_put(struct rpcrdma_req *req) |
| 1215 | { |
| 1216 | struct rpcrdma_buffer *buffers = req->rl_buffer; |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1217 | struct rpcrdma_rep *rep = req->rl_reply; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1218 | |
Chuck Lever | 90aab60 | 2016-09-15 10:56:43 -0400 | [diff] [blame] | 1219 | req->rl_send_wr.num_sge = 0; |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1220 | req->rl_reply = NULL; |
| 1221 | |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1222 | spin_lock(&buffers->rb_lock); |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1223 | buffers->rb_send_count--; |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1224 | list_add_tail(&req->rl_free, &buffers->rb_send_bufs); |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1225 | if (rep) { |
| 1226 | buffers->rb_recv_count--; |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1227 | list_add_tail(&rep->rr_list, &buffers->rb_recv_bufs); |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1228 | } |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1229 | spin_unlock(&buffers->rb_lock); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | * Recover reply buffers from pool. |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1234 | * This happens when recovering from disconnect. |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1235 | */ |
| 1236 | void |
| 1237 | rpcrdma_recv_buffer_get(struct rpcrdma_req *req) |
| 1238 | { |
| 1239 | struct rpcrdma_buffer *buffers = req->rl_buffer; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1240 | |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1241 | spin_lock(&buffers->rb_lock); |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1242 | req->rl_reply = rpcrdma_buffer_get_rep(buffers); |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1243 | spin_unlock(&buffers->rb_lock); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /* |
| 1247 | * Put reply buffers back into pool when not attached to |
| 1248 | * request. This happens in error conditions. |
| 1249 | */ |
| 1250 | void |
| 1251 | rpcrdma_recv_buffer_put(struct rpcrdma_rep *rep) |
| 1252 | { |
Chuck Lever | fed171b | 2015-05-26 11:51:37 -0400 | [diff] [blame] | 1253 | struct rpcrdma_buffer *buffers = &rep->rr_rxprt->rx_buf; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1254 | |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1255 | spin_lock(&buffers->rb_lock); |
Chuck Lever | 05c9746 | 2016-09-06 11:22:58 -0400 | [diff] [blame] | 1256 | buffers->rb_recv_count--; |
Chuck Lever | 1e465fd | 2015-10-24 17:27:02 -0400 | [diff] [blame] | 1257 | list_add_tail(&rep->rr_list, &buffers->rb_recv_bufs); |
Chuck Lever | a5b027e | 2015-10-24 17:27:27 -0400 | [diff] [blame] | 1258 | spin_unlock(&buffers->rb_lock); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1259 | } |
| 1260 | |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1261 | /** |
Chuck Lever | 99ef4db | 2016-09-15 10:56:10 -0400 | [diff] [blame] | 1262 | * rpcrdma_alloc_regbuf - allocate and DMA-map memory for SEND/RECV buffers |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1263 | * @size: size of buffer to be allocated, in bytes |
Chuck Lever | 99ef4db | 2016-09-15 10:56:10 -0400 | [diff] [blame] | 1264 | * @direction: direction of data movement |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1265 | * @flags: GFP flags |
| 1266 | * |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1267 | * Returns an ERR_PTR, or a pointer to a regbuf, a buffer that |
| 1268 | * can be persistently DMA-mapped for I/O. |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1269 | * |
| 1270 | * xprtrdma uses a regbuf for posting an outgoing RDMA SEND, or for |
Chuck Lever | 99ef4db | 2016-09-15 10:56:10 -0400 | [diff] [blame] | 1271 | * receiving the payload of RDMA RECV operations. During Long Calls |
| 1272 | * or Replies they may be registered externally via ro_map. |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1273 | */ |
| 1274 | struct rpcrdma_regbuf * |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 1275 | rpcrdma_alloc_regbuf(size_t size, enum dma_data_direction direction, |
| 1276 | gfp_t flags) |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1277 | { |
| 1278 | struct rpcrdma_regbuf *rb; |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1279 | |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1280 | rb = kmalloc(sizeof(*rb) + size, flags); |
| 1281 | if (rb == NULL) |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1282 | return ERR_PTR(-ENOMEM); |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1283 | |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1284 | rb->rg_device = NULL; |
Chuck Lever | 99ef4db | 2016-09-15 10:56:10 -0400 | [diff] [blame] | 1285 | rb->rg_direction = direction; |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1286 | rb->rg_iov.length = size; |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1287 | |
| 1288 | return rb; |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1289 | } |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1290 | |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1291 | /** |
| 1292 | * __rpcrdma_map_regbuf - DMA-map a regbuf |
| 1293 | * @ia: controlling rpcrdma_ia |
| 1294 | * @rb: regbuf to be mapped |
| 1295 | */ |
| 1296 | bool |
| 1297 | __rpcrdma_dma_map_regbuf(struct rpcrdma_ia *ia, struct rpcrdma_regbuf *rb) |
| 1298 | { |
Chuck Lever | 91a10c5 | 2017-04-11 13:23:02 -0400 | [diff] [blame] | 1299 | struct ib_device *device = ia->ri_device; |
| 1300 | |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1301 | if (rb->rg_direction == DMA_NONE) |
| 1302 | return false; |
| 1303 | |
Chuck Lever | 91a10c5 | 2017-04-11 13:23:02 -0400 | [diff] [blame] | 1304 | rb->rg_iov.addr = ib_dma_map_single(device, |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1305 | (void *)rb->rg_base, |
| 1306 | rdmab_length(rb), |
| 1307 | rb->rg_direction); |
Chuck Lever | 91a10c5 | 2017-04-11 13:23:02 -0400 | [diff] [blame] | 1308 | if (ib_dma_mapping_error(device, rdmab_addr(rb))) |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1309 | return false; |
| 1310 | |
Chuck Lever | 91a10c5 | 2017-04-11 13:23:02 -0400 | [diff] [blame] | 1311 | rb->rg_device = device; |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1312 | rb->rg_iov.lkey = ia->ri_pd->local_dma_lkey; |
| 1313 | return true; |
| 1314 | } |
| 1315 | |
| 1316 | static void |
| 1317 | rpcrdma_dma_unmap_regbuf(struct rpcrdma_regbuf *rb) |
| 1318 | { |
| 1319 | if (!rpcrdma_regbuf_is_mapped(rb)) |
| 1320 | return; |
| 1321 | |
| 1322 | ib_dma_unmap_single(rb->rg_device, rdmab_addr(rb), |
| 1323 | rdmab_length(rb), rb->rg_direction); |
| 1324 | rb->rg_device = NULL; |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * rpcrdma_free_regbuf - deregister and free registered buffer |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1329 | * @rb: regbuf to be deregistered and freed |
| 1330 | */ |
| 1331 | void |
Chuck Lever | 13650c2 | 2016-09-15 10:56:26 -0400 | [diff] [blame] | 1332 | rpcrdma_free_regbuf(struct rpcrdma_regbuf *rb) |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1333 | { |
Chuck Lever | e531dca | 2015-08-03 13:03:20 -0400 | [diff] [blame] | 1334 | if (!rb) |
| 1335 | return; |
| 1336 | |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1337 | rpcrdma_dma_unmap_regbuf(rb); |
Chuck Lever | e531dca | 2015-08-03 13:03:20 -0400 | [diff] [blame] | 1338 | kfree(rb); |
Chuck Lever | 9128c3e | 2015-01-21 11:04:00 -0500 | [diff] [blame] | 1339 | } |
| 1340 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1341 | /* |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1342 | * Prepost any receive buffer, then post send. |
| 1343 | * |
| 1344 | * Receive buffer is donated to hardware, reclaimed upon recv completion. |
| 1345 | */ |
| 1346 | int |
| 1347 | rpcrdma_ep_post(struct rpcrdma_ia *ia, |
| 1348 | struct rpcrdma_ep *ep, |
| 1349 | struct rpcrdma_req *req) |
| 1350 | { |
Chuck Lever | 90aab60 | 2016-09-15 10:56:43 -0400 | [diff] [blame] | 1351 | struct ib_send_wr *send_wr = &req->rl_send_wr; |
| 1352 | struct ib_send_wr *send_wr_fail; |
Chuck Lever | 655fec6 | 2016-09-15 10:57:24 -0400 | [diff] [blame] | 1353 | int rc; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1354 | |
Chuck Lever | 90aab60 | 2016-09-15 10:56:43 -0400 | [diff] [blame] | 1355 | if (req->rl_reply) { |
| 1356 | rc = rpcrdma_ep_post_recv(ia, req->rl_reply); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1357 | if (rc) |
Chuck Lever | 7a89f9c | 2016-06-29 13:53:43 -0400 | [diff] [blame] | 1358 | return rc; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1359 | req->rl_reply = NULL; |
| 1360 | } |
| 1361 | |
Chuck Lever | b3221d6 | 2015-08-03 13:03:39 -0400 | [diff] [blame] | 1362 | dprintk("RPC: %s: posting %d s/g entries\n", |
Chuck Lever | 90aab60 | 2016-09-15 10:56:43 -0400 | [diff] [blame] | 1363 | __func__, send_wr->num_sge); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1364 | |
Chuck Lever | 8d38de6 | 2016-11-29 10:52:16 -0500 | [diff] [blame] | 1365 | rpcrdma_set_signaled(ep, send_wr); |
Chuck Lever | 90aab60 | 2016-09-15 10:56:43 -0400 | [diff] [blame] | 1366 | rc = ib_post_send(ia->ri_id->qp, send_wr, &send_wr_fail); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1367 | if (rc) |
Chuck Lever | 7a89f9c | 2016-06-29 13:53:43 -0400 | [diff] [blame] | 1368 | goto out_postsend_err; |
| 1369 | return 0; |
| 1370 | |
| 1371 | out_postsend_err: |
| 1372 | pr_err("rpcrdma: RDMA Send ib_post_send returned %i\n", rc); |
| 1373 | return -ENOTCONN; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1374 | } |
| 1375 | |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1376 | int |
| 1377 | rpcrdma_ep_post_recv(struct rpcrdma_ia *ia, |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1378 | struct rpcrdma_rep *rep) |
| 1379 | { |
Chuck Lever | 6ea8e71 | 2016-09-15 10:56:51 -0400 | [diff] [blame] | 1380 | struct ib_recv_wr *recv_wr_fail; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1381 | int rc; |
| 1382 | |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1383 | if (!rpcrdma_dma_map_regbuf(ia, rep->rr_rdmabuf)) |
| 1384 | goto out_map; |
Chuck Lever | 6ea8e71 | 2016-09-15 10:56:51 -0400 | [diff] [blame] | 1385 | rc = ib_post_recv(ia->ri_id->qp, &rep->rr_recv_wr, &recv_wr_fail); |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1386 | if (rc) |
Chuck Lever | 7a89f9c | 2016-06-29 13:53:43 -0400 | [diff] [blame] | 1387 | goto out_postrecv; |
| 1388 | return 0; |
| 1389 | |
Chuck Lever | 54cbd6b | 2016-09-15 10:56:18 -0400 | [diff] [blame] | 1390 | out_map: |
| 1391 | pr_err("rpcrdma: failed to DMA map the Receive buffer\n"); |
| 1392 | return -EIO; |
| 1393 | |
Chuck Lever | 7a89f9c | 2016-06-29 13:53:43 -0400 | [diff] [blame] | 1394 | out_postrecv: |
| 1395 | pr_err("rpcrdma: ib_post_recv returned %i\n", rc); |
| 1396 | return -ENOTCONN; |
\"Talpey, Thomas\ | c56c65f | 2007-09-10 13:51:18 -0400 | [diff] [blame] | 1397 | } |
Chuck Lever | 43e9598 | 2014-07-29 17:23:34 -0400 | [diff] [blame] | 1398 | |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1399 | /** |
| 1400 | * rpcrdma_ep_post_extra_recv - Post buffers for incoming backchannel requests |
| 1401 | * @r_xprt: transport associated with these backchannel resources |
| 1402 | * @min_reqs: minimum number of incoming requests expected |
| 1403 | * |
| 1404 | * Returns zero if all requested buffers were posted, or a negative errno. |
| 1405 | */ |
| 1406 | int |
| 1407 | rpcrdma_ep_post_extra_recv(struct rpcrdma_xprt *r_xprt, unsigned int count) |
| 1408 | { |
| 1409 | struct rpcrdma_buffer *buffers = &r_xprt->rx_buf; |
| 1410 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1411 | struct rpcrdma_rep *rep; |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1412 | int rc; |
| 1413 | |
| 1414 | while (count--) { |
Chuck Lever | 9b06688 | 2015-12-16 17:22:06 -0500 | [diff] [blame] | 1415 | spin_lock(&buffers->rb_lock); |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1416 | if (list_empty(&buffers->rb_recv_bufs)) |
| 1417 | goto out_reqbuf; |
| 1418 | rep = rpcrdma_buffer_get_rep_locked(buffers); |
Chuck Lever | 9b06688 | 2015-12-16 17:22:06 -0500 | [diff] [blame] | 1419 | spin_unlock(&buffers->rb_lock); |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1420 | |
Chuck Lever | b157380 | 2016-09-15 10:56:35 -0400 | [diff] [blame] | 1421 | rc = rpcrdma_ep_post_recv(ia, rep); |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1422 | if (rc) |
| 1423 | goto out_rc; |
| 1424 | } |
| 1425 | |
| 1426 | return 0; |
| 1427 | |
| 1428 | out_reqbuf: |
Chuck Lever | 9b06688 | 2015-12-16 17:22:06 -0500 | [diff] [blame] | 1429 | spin_unlock(&buffers->rb_lock); |
Chuck Lever | f531a5d | 2015-10-24 17:27:43 -0400 | [diff] [blame] | 1430 | pr_warn("%s: no extra receive buffers\n", __func__); |
| 1431 | return -ENOMEM; |
| 1432 | |
| 1433 | out_rc: |
| 1434 | rpcrdma_recv_buffer_put(rep); |
| 1435 | return rc; |
| 1436 | } |