Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Oracle. All rights reserved. |
| 3 | * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | /* Lightweight memory registration using Fast Registration Work |
| 7 | * Requests (FRWR). Also referred to sometimes as FRMR mode. |
| 8 | * |
| 9 | * FRWR features ordered asynchronous registration and deregistration |
| 10 | * of arbitrarily sized memory regions. This is the fastest and safest |
| 11 | * but most complex memory registration mode. |
| 12 | */ |
| 13 | |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 14 | /* Normal operation |
| 15 | * |
| 16 | * A Memory Region is prepared for RDMA READ or WRITE using a FAST_REG |
| 17 | * Work Request (frmr_op_map). When the RDMA operation is finished, this |
| 18 | * Memory Region is invalidated using a LOCAL_INV Work Request |
| 19 | * (frmr_op_unmap). |
| 20 | * |
| 21 | * Typically these Work Requests are not signaled, and neither are RDMA |
| 22 | * SEND Work Requests (with the exception of signaling occasionally to |
| 23 | * prevent provider work queue overflows). This greatly reduces HCA |
| 24 | * interrupt workload. |
| 25 | * |
| 26 | * As an optimization, frwr_op_unmap marks MRs INVALID before the |
| 27 | * LOCAL_INV WR is posted. If posting succeeds, the MR is placed on |
| 28 | * rb_mws immediately so that no work (like managing a linked list |
| 29 | * under a spinlock) is needed in the completion upcall. |
| 30 | * |
| 31 | * But this means that frwr_op_map() can occasionally encounter an MR |
| 32 | * that is INVALID but the LOCAL_INV WR has not completed. Work Queue |
| 33 | * ordering prevents a subsequent FAST_REG WR from executing against |
| 34 | * that MR while it is still being invalidated. |
| 35 | */ |
| 36 | |
| 37 | /* Transport recovery |
| 38 | * |
| 39 | * ->op_map and the transport connect worker cannot run at the same |
| 40 | * time, but ->op_unmap can fire while the transport connect worker |
| 41 | * is running. Thus MR recovery is handled in ->op_map, to guarantee |
| 42 | * that recovered MRs are owned by a sending RPC, and not one where |
| 43 | * ->op_unmap could fire at the same time transport reconnect is |
| 44 | * being done. |
| 45 | * |
| 46 | * When the underlying transport disconnects, MRs are left in one of |
| 47 | * three states: |
| 48 | * |
| 49 | * INVALID: The MR was not in use before the QP entered ERROR state. |
| 50 | * (Or, the LOCAL_INV WR has not completed or flushed yet). |
| 51 | * |
| 52 | * STALE: The MR was being registered or unregistered when the QP |
| 53 | * entered ERROR state, and the pending WR was flushed. |
| 54 | * |
| 55 | * VALID: The MR was registered before the QP entered ERROR state. |
| 56 | * |
| 57 | * When frwr_op_map encounters STALE and VALID MRs, they are recovered |
| 58 | * with ib_dereg_mr and then are re-initialized. Beause MR recovery |
| 59 | * allocates fresh resources, it is deferred to a workqueue, and the |
| 60 | * recovered MRs are placed back on the rb_mws list when recovery is |
| 61 | * complete. frwr_op_map allocates another MR for the current RPC while |
| 62 | * the broken MR is reset. |
| 63 | * |
| 64 | * To ensure that frwr_op_map doesn't encounter an MR that is marked |
| 65 | * INVALID but that is about to be flushed due to a previous transport |
| 66 | * disconnect, the transport connect worker attempts to drain all |
| 67 | * pending send queue WRs before the transport is reconnected. |
| 68 | */ |
| 69 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 70 | #include "xprt_rdma.h" |
| 71 | |
| 72 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
| 73 | # define RPCDBG_FACILITY RPCDBG_TRANS |
| 74 | #endif |
| 75 | |
Chuck Lever | 951e721 | 2015-05-26 11:52:25 -0400 | [diff] [blame] | 76 | static struct workqueue_struct *frwr_recovery_wq; |
| 77 | |
| 78 | #define FRWR_RECOVERY_WQ_FLAGS (WQ_UNBOUND | WQ_MEM_RECLAIM) |
| 79 | |
| 80 | int |
| 81 | frwr_alloc_recovery_wq(void) |
| 82 | { |
| 83 | frwr_recovery_wq = alloc_workqueue("frwr_recovery", |
| 84 | FRWR_RECOVERY_WQ_FLAGS, 0); |
| 85 | return !frwr_recovery_wq ? -ENOMEM : 0; |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | frwr_destroy_recovery_wq(void) |
| 90 | { |
| 91 | struct workqueue_struct *wq; |
| 92 | |
| 93 | if (!frwr_recovery_wq) |
| 94 | return; |
| 95 | |
| 96 | wq = frwr_recovery_wq; |
| 97 | frwr_recovery_wq = NULL; |
| 98 | destroy_workqueue(wq); |
| 99 | } |
| 100 | |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame^] | 101 | static int |
| 102 | __frwr_reset_mr(struct rpcrdma_ia *ia, struct rpcrdma_mw *r) |
| 103 | { |
| 104 | struct rpcrdma_frmr *f = &r->frmr; |
| 105 | int rc; |
| 106 | |
| 107 | rc = ib_dereg_mr(f->fr_mr); |
| 108 | if (rc) { |
| 109 | pr_warn("rpcrdma: ib_dereg_mr status %d, frwr %p orphaned\n", |
| 110 | rc, r); |
| 111 | return rc; |
| 112 | } |
| 113 | |
| 114 | f->fr_mr = ib_alloc_mr(ia->ri_pd, IB_MR_TYPE_MEM_REG, |
| 115 | ia->ri_max_frmr_depth); |
| 116 | if (IS_ERR(f->fr_mr)) { |
| 117 | pr_warn("rpcrdma: ib_alloc_mr status %ld, frwr %p orphaned\n", |
| 118 | PTR_ERR(f->fr_mr), r); |
| 119 | return PTR_ERR(f->fr_mr); |
| 120 | } |
| 121 | |
| 122 | dprintk("RPC: %s: recovered FRMR %p\n", __func__, r); |
| 123 | f->fr_state = FRMR_IS_INVALID; |
| 124 | return 0; |
| 125 | } |
| 126 | |
Chuck Lever | 951e721 | 2015-05-26 11:52:25 -0400 | [diff] [blame] | 127 | /* Deferred reset of a single FRMR. Generate a fresh rkey by |
| 128 | * replacing the MR. |
| 129 | * |
| 130 | * There's no recovery if this fails. The FRMR is abandoned, but |
| 131 | * remains in rb_all. It will be cleaned up when the transport is |
| 132 | * destroyed. |
| 133 | */ |
| 134 | static void |
| 135 | __frwr_recovery_worker(struct work_struct *work) |
| 136 | { |
| 137 | struct rpcrdma_mw *r = container_of(work, struct rpcrdma_mw, |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 138 | frmr.fr_work); |
| 139 | struct rpcrdma_xprt *r_xprt = r->frmr.fr_xprt; |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame^] | 140 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
| 141 | int rc; |
Chuck Lever | 951e721 | 2015-05-26 11:52:25 -0400 | [diff] [blame] | 142 | |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame^] | 143 | rc = __frwr_reset_mr(ia, r); |
| 144 | if (rc) |
| 145 | return; |
Chuck Lever | 951e721 | 2015-05-26 11:52:25 -0400 | [diff] [blame] | 146 | |
Chuck Lever | 951e721 | 2015-05-26 11:52:25 -0400 | [diff] [blame] | 147 | rpcrdma_put_mw(r_xprt, r); |
| 148 | return; |
Chuck Lever | 951e721 | 2015-05-26 11:52:25 -0400 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* A broken MR was discovered in a context that can't sleep. |
| 152 | * Defer recovery to the recovery worker. |
| 153 | */ |
| 154 | static void |
| 155 | __frwr_queue_recovery(struct rpcrdma_mw *r) |
| 156 | { |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 157 | INIT_WORK(&r->frmr.fr_work, __frwr_recovery_worker); |
| 158 | queue_work(frwr_recovery_wq, &r->frmr.fr_work); |
Chuck Lever | 951e721 | 2015-05-26 11:52:25 -0400 | [diff] [blame] | 159 | } |
| 160 | |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 161 | static int |
| 162 | __frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device, |
| 163 | unsigned int depth) |
| 164 | { |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 165 | struct rpcrdma_frmr *f = &r->frmr; |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 166 | int rc; |
| 167 | |
Sagi Grimberg | 0410e38 | 2015-07-30 10:32:39 +0300 | [diff] [blame] | 168 | f->fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth); |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 169 | if (IS_ERR(f->fr_mr)) |
| 170 | goto out_mr_err; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 171 | |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 172 | f->fr_sg = kcalloc(depth, sizeof(*f->fr_sg), GFP_KERNEL); |
| 173 | if (!f->fr_sg) |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 174 | goto out_list_err; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 175 | |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 176 | sg_init_table(f->fr_sg, depth); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 177 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 178 | init_completion(&f->fr_linv_done); |
| 179 | |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 180 | return 0; |
| 181 | |
| 182 | out_mr_err: |
| 183 | rc = PTR_ERR(f->fr_mr); |
Sagi Grimberg | 0410e38 | 2015-07-30 10:32:39 +0300 | [diff] [blame] | 184 | dprintk("RPC: %s: ib_alloc_mr status %i\n", |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 185 | __func__, rc); |
| 186 | return rc; |
| 187 | |
| 188 | out_list_err: |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 189 | rc = -ENOMEM; |
| 190 | dprintk("RPC: %s: sg allocation failure\n", |
| 191 | __func__); |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 192 | ib_dereg_mr(f->fr_mr); |
| 193 | return rc; |
| 194 | } |
| 195 | |
Chuck Lever | 31a701a | 2015-03-30 14:35:07 -0400 | [diff] [blame] | 196 | static void |
| 197 | __frwr_release(struct rpcrdma_mw *r) |
| 198 | { |
| 199 | int rc; |
| 200 | |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 201 | rc = ib_dereg_mr(r->frmr.fr_mr); |
Chuck Lever | 31a701a | 2015-03-30 14:35:07 -0400 | [diff] [blame] | 202 | if (rc) |
| 203 | dprintk("RPC: %s: ib_dereg_mr status %i\n", |
| 204 | __func__, rc); |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 205 | kfree(r->frmr.fr_sg); |
Chuck Lever | 31a701a | 2015-03-30 14:35:07 -0400 | [diff] [blame] | 206 | } |
| 207 | |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 208 | static int |
| 209 | frwr_op_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep, |
| 210 | struct rpcrdma_create_data_internal *cdata) |
| 211 | { |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 212 | int depth, delta; |
| 213 | |
| 214 | ia->ri_max_frmr_depth = |
| 215 | min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS, |
Or Gerlitz | e3e45b1 | 2015-12-18 10:59:48 +0200 | [diff] [blame] | 216 | ia->ri_device->attrs.max_fast_reg_page_list_len); |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 217 | dprintk("RPC: %s: device's max FR page list len = %u\n", |
| 218 | __func__, ia->ri_max_frmr_depth); |
| 219 | |
| 220 | /* Add room for frmr register and invalidate WRs. |
| 221 | * 1. FRMR reg WR for head |
| 222 | * 2. FRMR invalidate WR for head |
| 223 | * 3. N FRMR reg WRs for pagelist |
| 224 | * 4. N FRMR invalidate WRs for pagelist |
| 225 | * 5. FRMR reg WR for tail |
| 226 | * 6. FRMR invalidate WR for tail |
| 227 | * 7. The RDMA_SEND WR |
| 228 | */ |
| 229 | depth = 7; |
| 230 | |
| 231 | /* Calculate N if the device max FRMR depth is smaller than |
| 232 | * RPCRDMA_MAX_DATA_SEGS. |
| 233 | */ |
| 234 | if (ia->ri_max_frmr_depth < RPCRDMA_MAX_DATA_SEGS) { |
| 235 | delta = RPCRDMA_MAX_DATA_SEGS - ia->ri_max_frmr_depth; |
| 236 | do { |
| 237 | depth += 2; /* FRMR reg + invalidate */ |
| 238 | delta -= ia->ri_max_frmr_depth; |
| 239 | } while (delta > 0); |
| 240 | } |
| 241 | |
| 242 | ep->rep_attr.cap.max_send_wr *= depth; |
Or Gerlitz | e3e45b1 | 2015-12-18 10:59:48 +0200 | [diff] [blame] | 243 | if (ep->rep_attr.cap.max_send_wr > ia->ri_device->attrs.max_qp_wr) { |
| 244 | cdata->max_requests = ia->ri_device->attrs.max_qp_wr / depth; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 245 | if (!cdata->max_requests) |
| 246 | return -EINVAL; |
| 247 | ep->rep_attr.cap.max_send_wr = cdata->max_requests * |
| 248 | depth; |
| 249 | } |
| 250 | |
Chuck Lever | 302d3de | 2016-05-02 14:41:05 -0400 | [diff] [blame] | 251 | rpcrdma_set_max_header_sizes(ia, cdata, max_t(unsigned int, 1, |
| 252 | RPCRDMA_MAX_DATA_SEGS / |
| 253 | ia->ri_max_frmr_depth)); |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 257 | /* FRWR mode conveys a list of pages per chunk segment. The |
| 258 | * maximum length of that list is the FRWR page list depth. |
| 259 | */ |
| 260 | static size_t |
| 261 | frwr_op_maxpages(struct rpcrdma_xprt *r_xprt) |
| 262 | { |
| 263 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
| 264 | |
| 265 | return min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS, |
Chuck Lever | 9493174 | 2016-05-02 14:40:56 -0400 | [diff] [blame] | 266 | RPCRDMA_MAX_HDR_SEGS * ia->ri_max_frmr_depth); |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Chuck Lever | e46ac34 | 2015-03-30 14:35:35 -0400 | [diff] [blame] | 269 | static void |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 270 | __frwr_sendcompletion_flush(struct ib_wc *wc, struct rpcrdma_frmr *frmr, |
| 271 | const char *wr) |
Chuck Lever | e46ac34 | 2015-03-30 14:35:35 -0400 | [diff] [blame] | 272 | { |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 273 | frmr->fr_state = FRMR_IS_STALE; |
| 274 | if (wc->status != IB_WC_WR_FLUSH_ERR) |
| 275 | pr_err("rpcrdma: %s: %s (%u/0x%x)\n", |
| 276 | wr, ib_wc_status_msg(wc->status), |
| 277 | wc->status, wc->vendor_err); |
Chuck Lever | e46ac34 | 2015-03-30 14:35:35 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 280 | /** |
| 281 | * frwr_wc_fastreg - Invoked by RDMA provider for each polled FastReg WC |
| 282 | * @cq: completion queue (ignored) |
| 283 | * @wc: completed WR |
| 284 | * |
| 285 | */ |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 286 | static void |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 287 | frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc) |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 288 | { |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 289 | struct rpcrdma_frmr *frmr; |
| 290 | struct ib_cqe *cqe; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 291 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 292 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
| 293 | if (wc->status != IB_WC_SUCCESS) { |
| 294 | cqe = wc->wr_cqe; |
| 295 | frmr = container_of(cqe, struct rpcrdma_frmr, fr_cqe); |
| 296 | __frwr_sendcompletion_flush(wc, frmr, "fastreg"); |
| 297 | } |
| 298 | } |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 299 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 300 | /** |
| 301 | * frwr_wc_localinv - Invoked by RDMA provider for each polled LocalInv WC |
| 302 | * @cq: completion queue (ignored) |
| 303 | * @wc: completed WR |
| 304 | * |
| 305 | */ |
| 306 | static void |
| 307 | frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc) |
| 308 | { |
| 309 | struct rpcrdma_frmr *frmr; |
| 310 | struct ib_cqe *cqe; |
| 311 | |
| 312 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
| 313 | if (wc->status != IB_WC_SUCCESS) { |
| 314 | cqe = wc->wr_cqe; |
| 315 | frmr = container_of(cqe, struct rpcrdma_frmr, fr_cqe); |
| 316 | __frwr_sendcompletion_flush(wc, frmr, "localinv"); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * frwr_wc_localinv - Invoked by RDMA provider for each polled LocalInv WC |
| 322 | * @cq: completion queue (ignored) |
| 323 | * @wc: completed WR |
| 324 | * |
| 325 | * Awaken anyone waiting for an MR to finish being fenced. |
| 326 | */ |
| 327 | static void |
| 328 | frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc) |
| 329 | { |
| 330 | struct rpcrdma_frmr *frmr; |
| 331 | struct ib_cqe *cqe; |
| 332 | |
| 333 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
| 334 | cqe = wc->wr_cqe; |
| 335 | frmr = container_of(cqe, struct rpcrdma_frmr, fr_cqe); |
| 336 | if (wc->status != IB_WC_SUCCESS) |
| 337 | __frwr_sendcompletion_flush(wc, frmr, "localinv"); |
| 338 | complete_all(&frmr->fr_linv_done); |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 341 | static int |
| 342 | frwr_op_init(struct rpcrdma_xprt *r_xprt) |
| 343 | { |
| 344 | struct rpcrdma_buffer *buf = &r_xprt->rx_buf; |
Chuck Lever | 89e0d112 | 2015-05-26 11:51:56 -0400 | [diff] [blame] | 345 | struct ib_device *device = r_xprt->rx_ia.ri_device; |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 346 | unsigned int depth = r_xprt->rx_ia.ri_max_frmr_depth; |
| 347 | struct ib_pd *pd = r_xprt->rx_ia.ri_pd; |
| 348 | int i; |
| 349 | |
Chuck Lever | 58d1dcf | 2015-05-26 11:53:13 -0400 | [diff] [blame] | 350 | spin_lock_init(&buf->rb_mwlock); |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 351 | INIT_LIST_HEAD(&buf->rb_mws); |
| 352 | INIT_LIST_HEAD(&buf->rb_all); |
| 353 | |
Chuck Lever | 40c6ed0 | 2015-05-26 11:53:33 -0400 | [diff] [blame] | 354 | i = max_t(int, RPCRDMA_MAX_DATA_SEGS / depth, 1); |
| 355 | i += 2; /* head + tail */ |
| 356 | i *= buf->rb_max_requests; /* one set for each RPC slot */ |
| 357 | dprintk("RPC: %s: initalizing %d FRMRs\n", __func__, i); |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 358 | |
| 359 | while (i--) { |
| 360 | struct rpcrdma_mw *r; |
| 361 | int rc; |
| 362 | |
| 363 | r = kzalloc(sizeof(*r), GFP_KERNEL); |
| 364 | if (!r) |
| 365 | return -ENOMEM; |
| 366 | |
| 367 | rc = __frwr_init(r, pd, device, depth); |
| 368 | if (rc) { |
| 369 | kfree(r); |
| 370 | return rc; |
| 371 | } |
| 372 | |
| 373 | list_add(&r->mw_list, &buf->rb_mws); |
| 374 | list_add(&r->mw_all, &buf->rb_all); |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 375 | r->frmr.fr_xprt = r_xprt; |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 381 | /* Post a FAST_REG Work Request to register a memory region |
| 382 | * for remote access via RDMA READ or RDMA WRITE. |
| 383 | */ |
| 384 | static int |
| 385 | frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg, |
| 386 | int nsegs, bool writing) |
| 387 | { |
| 388 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
Chuck Lever | 89e0d112 | 2015-05-26 11:51:56 -0400 | [diff] [blame] | 389 | struct ib_device *device = ia->ri_device; |
Chuck Lever | d654788 | 2015-03-30 14:35:44 -0400 | [diff] [blame] | 390 | enum dma_data_direction direction = rpcrdma_data_dir(writing); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 391 | struct rpcrdma_mr_seg *seg1 = seg; |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 392 | struct rpcrdma_mw *mw; |
| 393 | struct rpcrdma_frmr *frmr; |
| 394 | struct ib_mr *mr; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 395 | struct ib_reg_wr *reg_wr; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 396 | struct ib_send_wr *bad_wr; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 397 | int rc, i, n, dma_nents; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 398 | u8 key; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 399 | |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 400 | mw = seg1->rl_mw; |
| 401 | seg1->rl_mw = NULL; |
| 402 | do { |
| 403 | if (mw) |
| 404 | __frwr_queue_recovery(mw); |
| 405 | mw = rpcrdma_get_mw(r_xprt); |
| 406 | if (!mw) |
| 407 | return -ENOMEM; |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 408 | } while (mw->frmr.fr_state != FRMR_IS_INVALID); |
| 409 | frmr = &mw->frmr; |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 410 | frmr->fr_state = FRMR_IS_VALID; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 411 | mr = frmr->fr_mr; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 412 | reg_wr = &frmr->fr_regwr; |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 413 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 414 | if (nsegs > ia->ri_max_frmr_depth) |
| 415 | nsegs = ia->ri_max_frmr_depth; |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 416 | |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 417 | for (i = 0; i < nsegs;) { |
| 418 | if (seg->mr_page) |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 419 | sg_set_page(&frmr->fr_sg[i], |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 420 | seg->mr_page, |
| 421 | seg->mr_len, |
| 422 | offset_in_page(seg->mr_offset)); |
| 423 | else |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 424 | sg_set_buf(&frmr->fr_sg[i], seg->mr_offset, |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 425 | seg->mr_len); |
| 426 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 427 | ++seg; |
| 428 | ++i; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 429 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 430 | /* Check for holes */ |
| 431 | if ((i < nsegs && offset_in_page(seg->mr_offset)) || |
| 432 | offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len)) |
| 433 | break; |
| 434 | } |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 435 | frmr->fr_nents = i; |
Chuck Lever | a3aa8b2 | 2016-05-02 14:42:04 -0400 | [diff] [blame] | 436 | frmr->fr_dir = direction; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 437 | |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 438 | dma_nents = ib_dma_map_sg(device, frmr->fr_sg, frmr->fr_nents, direction); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 439 | if (!dma_nents) { |
| 440 | pr_err("RPC: %s: failed to dma map sg %p sg_nents %u\n", |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 441 | __func__, frmr->fr_sg, frmr->fr_nents); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 442 | return -ENOMEM; |
| 443 | } |
| 444 | |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 445 | n = ib_map_mr_sg(mr, frmr->fr_sg, frmr->fr_nents, PAGE_SIZE); |
| 446 | if (unlikely(n != frmr->fr_nents)) { |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 447 | pr_err("RPC: %s: failed to map mr %p (%u/%u)\n", |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 448 | __func__, frmr->fr_mr, n, frmr->fr_nents); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 449 | rc = n < 0 ? n : -EINVAL; |
| 450 | goto out_senderr; |
| 451 | } |
| 452 | |
| 453 | dprintk("RPC: %s: Using frmr %p to map %u segments (%u bytes)\n", |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 454 | __func__, mw, frmr->fr_nents, mr->length); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 455 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 456 | key = (u8)(mr->rkey & 0x000000FF); |
| 457 | ib_update_fast_reg_key(mr, ++key); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 458 | |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 459 | reg_wr->wr.next = NULL; |
| 460 | reg_wr->wr.opcode = IB_WR_REG_MR; |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 461 | frmr->fr_cqe.done = frwr_wc_fastreg; |
| 462 | reg_wr->wr.wr_cqe = &frmr->fr_cqe; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 463 | reg_wr->wr.num_sge = 0; |
| 464 | reg_wr->wr.send_flags = 0; |
| 465 | reg_wr->mr = mr; |
| 466 | reg_wr->key = mr->rkey; |
| 467 | reg_wr->access = writing ? |
| 468 | IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE : |
| 469 | IB_ACCESS_REMOTE_READ; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 470 | |
| 471 | DECR_CQCOUNT(&r_xprt->rx_ep); |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 472 | rc = ib_post_send(ia->ri_id->qp, ®_wr->wr, &bad_wr); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 473 | if (rc) |
| 474 | goto out_senderr; |
| 475 | |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 476 | seg1->rl_mw = mw; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 477 | seg1->mr_rkey = mr->rkey; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 478 | seg1->mr_base = mr->iova; |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 479 | seg1->mr_nsegs = frmr->fr_nents; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 480 | seg1->mr_len = mr->length; |
| 481 | |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 482 | return frmr->fr_nents; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 483 | |
| 484 | out_senderr: |
| 485 | dprintk("RPC: %s: ib_post_send status %i\n", __func__, rc); |
Chuck Lever | 55fdfce | 2016-05-02 14:41:56 -0400 | [diff] [blame] | 486 | ib_dma_unmap_sg(device, frmr->fr_sg, dma_nents, direction); |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 487 | __frwr_queue_recovery(mw); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 488 | return rc; |
| 489 | } |
| 490 | |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 491 | static struct ib_send_wr * |
| 492 | __frwr_prepare_linv_wr(struct rpcrdma_mr_seg *seg) |
| 493 | { |
| 494 | struct rpcrdma_mw *mw = seg->rl_mw; |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 495 | struct rpcrdma_frmr *f = &mw->frmr; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 496 | struct ib_send_wr *invalidate_wr; |
| 497 | |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 498 | f->fr_state = FRMR_IS_INVALID; |
| 499 | invalidate_wr = &f->fr_invwr; |
| 500 | |
| 501 | memset(invalidate_wr, 0, sizeof(*invalidate_wr)); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 502 | f->fr_cqe.done = frwr_wc_localinv; |
| 503 | invalidate_wr->wr_cqe = &f->fr_cqe; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 504 | invalidate_wr->opcode = IB_WR_LOCAL_INV; |
| 505 | invalidate_wr->ex.invalidate_rkey = f->fr_mr->rkey; |
| 506 | |
| 507 | return invalidate_wr; |
| 508 | } |
| 509 | |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 510 | /* Invalidate all memory regions that were registered for "req". |
| 511 | * |
| 512 | * Sleeps until it is safe for the host CPU to access the |
| 513 | * previously mapped memory regions. |
| 514 | */ |
| 515 | static void |
| 516 | frwr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req) |
| 517 | { |
| 518 | struct ib_send_wr *invalidate_wrs, *pos, *prev, *bad_wr; |
| 519 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
| 520 | struct rpcrdma_mr_seg *seg; |
| 521 | unsigned int i, nchunks; |
| 522 | struct rpcrdma_frmr *f; |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame^] | 523 | struct rpcrdma_mw *mw; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 524 | int rc; |
| 525 | |
| 526 | dprintk("RPC: %s: req %p\n", __func__, req); |
| 527 | |
| 528 | /* ORDER: Invalidate all of the req's MRs first |
| 529 | * |
| 530 | * Chain the LOCAL_INV Work Requests and post them with |
| 531 | * a single ib_post_send() call. |
| 532 | */ |
| 533 | invalidate_wrs = pos = prev = NULL; |
| 534 | seg = NULL; |
| 535 | for (i = 0, nchunks = req->rl_nchunks; nchunks; nchunks--) { |
| 536 | seg = &req->rl_segments[i]; |
| 537 | |
| 538 | pos = __frwr_prepare_linv_wr(seg); |
| 539 | |
| 540 | if (!invalidate_wrs) |
| 541 | invalidate_wrs = pos; |
| 542 | else |
| 543 | prev->next = pos; |
| 544 | prev = pos; |
| 545 | |
| 546 | i += seg->mr_nsegs; |
| 547 | } |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 548 | f = &seg->rl_mw->frmr; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 549 | |
| 550 | /* Strong send queue ordering guarantees that when the |
| 551 | * last WR in the chain completes, all WRs in the chain |
| 552 | * are complete. |
| 553 | */ |
| 554 | f->fr_invwr.send_flags = IB_SEND_SIGNALED; |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 555 | f->fr_cqe.done = frwr_wc_localinv_wake; |
| 556 | reinit_completion(&f->fr_linv_done); |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 557 | INIT_CQCOUNT(&r_xprt->rx_ep); |
| 558 | |
| 559 | /* Transport disconnect drains the receive CQ before it |
| 560 | * replaces the QP. The RPC reply handler won't call us |
| 561 | * unless ri_id->qp is a valid pointer. |
| 562 | */ |
| 563 | rc = ib_post_send(ia->ri_id->qp, invalidate_wrs, &bad_wr); |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame^] | 564 | if (rc) |
| 565 | goto reset_mrs; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 566 | |
| 567 | wait_for_completion(&f->fr_linv_done); |
| 568 | |
| 569 | /* ORDER: Now DMA unmap all of the req's MRs, and return |
| 570 | * them to the free MW list. |
| 571 | */ |
Chuck Lever | b892a69 | 2016-03-04 11:28:01 -0500 | [diff] [blame] | 572 | unmap: |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 573 | for (i = 0, nchunks = req->rl_nchunks; nchunks; nchunks--) { |
| 574 | seg = &req->rl_segments[i]; |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame^] | 575 | mw = seg->rl_mw; |
| 576 | seg->rl_mw = NULL; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 577 | |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame^] | 578 | ib_dma_unmap_sg(ia->ri_device, f->fr_sg, f->fr_nents, |
| 579 | f->fr_dir); |
| 580 | rpcrdma_put_mw(r_xprt, mw); |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 581 | |
| 582 | i += seg->mr_nsegs; |
| 583 | seg->mr_nsegs = 0; |
| 584 | } |
| 585 | |
| 586 | req->rl_nchunks = 0; |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame^] | 587 | return; |
| 588 | |
| 589 | reset_mrs: |
| 590 | pr_warn("%s: ib_post_send failed %i\n", __func__, rc); |
| 591 | |
| 592 | /* Find and reset the MRs in the LOCAL_INV WRs that did not |
| 593 | * get posted. This is synchronous, and slow. |
| 594 | */ |
| 595 | for (i = 0, nchunks = req->rl_nchunks; nchunks; nchunks--) { |
| 596 | seg = &req->rl_segments[i]; |
| 597 | mw = seg->rl_mw; |
| 598 | f = &mw->frmr; |
| 599 | |
| 600 | if (mw->frmr.fr_mr->rkey == bad_wr->ex.invalidate_rkey) { |
| 601 | __frwr_reset_mr(ia, mw); |
| 602 | bad_wr = bad_wr->next; |
| 603 | } |
| 604 | |
| 605 | i += seg->mr_nsegs; |
| 606 | } |
| 607 | goto unmap; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 608 | } |
| 609 | |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 610 | /* Post a LOCAL_INV Work Request to prevent further remote access |
| 611 | * via RDMA READ or RDMA WRITE. |
| 612 | */ |
| 613 | static int |
| 614 | frwr_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg) |
| 615 | { |
| 616 | struct rpcrdma_mr_seg *seg1 = seg; |
| 617 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 618 | struct rpcrdma_mw *mw = seg1->rl_mw; |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 619 | struct rpcrdma_frmr *frmr = &mw->frmr; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 620 | struct ib_send_wr *invalidate_wr, *bad_wr; |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 621 | int rc, nsegs = seg->mr_nsegs; |
| 622 | |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 623 | dprintk("RPC: %s: FRMR %p\n", __func__, mw); |
| 624 | |
| 625 | seg1->rl_mw = NULL; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 626 | frmr->fr_state = FRMR_IS_INVALID; |
Chuck Lever | c882a65 | 2016-03-04 11:28:45 -0500 | [diff] [blame] | 627 | invalidate_wr = &mw->frmr.fr_invwr; |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 628 | |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 629 | memset(invalidate_wr, 0, sizeof(*invalidate_wr)); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 630 | frmr->fr_cqe.done = frwr_wc_localinv; |
| 631 | invalidate_wr->wr_cqe = &frmr->fr_cqe; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 632 | invalidate_wr->opcode = IB_WR_LOCAL_INV; |
| 633 | invalidate_wr->ex.invalidate_rkey = frmr->fr_mr->rkey; |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 634 | DECR_CQCOUNT(&r_xprt->rx_ep); |
| 635 | |
Chuck Lever | a3aa8b2 | 2016-05-02 14:42:04 -0400 | [diff] [blame] | 636 | ib_dma_unmap_sg(ia->ri_device, frmr->fr_sg, frmr->fr_nents, frmr->fr_dir); |
Chuck Lever | 89e0d112 | 2015-05-26 11:51:56 -0400 | [diff] [blame] | 637 | read_lock(&ia->ri_qplock); |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 638 | rc = ib_post_send(ia->ri_id->qp, invalidate_wr, &bad_wr); |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 639 | read_unlock(&ia->ri_qplock); |
| 640 | if (rc) |
| 641 | goto out_err; |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 642 | |
| 643 | rpcrdma_put_mw(r_xprt, mw); |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 644 | return nsegs; |
| 645 | |
| 646 | out_err: |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 647 | dprintk("RPC: %s: ib_post_send status %i\n", __func__, rc); |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 648 | __frwr_queue_recovery(mw); |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 649 | return nsegs; |
| 650 | } |
| 651 | |
Chuck Lever | 4561f34 | 2015-03-30 14:35:17 -0400 | [diff] [blame] | 652 | static void |
| 653 | frwr_op_destroy(struct rpcrdma_buffer *buf) |
| 654 | { |
| 655 | struct rpcrdma_mw *r; |
| 656 | |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 657 | /* Ensure stale MWs for "buf" are no longer in flight */ |
| 658 | flush_workqueue(frwr_recovery_wq); |
| 659 | |
Chuck Lever | 4561f34 | 2015-03-30 14:35:17 -0400 | [diff] [blame] | 660 | while (!list_empty(&buf->rb_all)) { |
| 661 | r = list_entry(buf->rb_all.next, struct rpcrdma_mw, mw_all); |
| 662 | list_del(&r->mw_all); |
| 663 | __frwr_release(r); |
| 664 | kfree(r); |
| 665 | } |
| 666 | } |
| 667 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 668 | const struct rpcrdma_memreg_ops rpcrdma_frwr_memreg_ops = { |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 669 | .ro_map = frwr_op_map, |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 670 | .ro_unmap_sync = frwr_op_unmap_sync, |
Chuck Lever | 6814bae | 2015-03-30 14:34:48 -0400 | [diff] [blame] | 671 | .ro_unmap = frwr_op_unmap, |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 672 | .ro_open = frwr_op_open, |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 673 | .ro_maxpages = frwr_op_maxpages, |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 674 | .ro_init = frwr_op_init, |
Chuck Lever | 4561f34 | 2015-03-30 14:35:17 -0400 | [diff] [blame] | 675 | .ro_destroy = frwr_op_destroy, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 676 | .ro_displayname = "frwr", |
| 677 | }; |