Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 2 | /* |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 3 | * Copyright (c) 2015, 2017 Oracle. All rights reserved. |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 4 | * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved. |
| 5 | */ |
| 6 | |
| 7 | /* Lightweight memory registration using Fast Registration Work |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 8 | * Requests (FRWR). |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 9 | * |
| 10 | * FRWR features ordered asynchronous registration and deregistration |
| 11 | * of arbitrarily sized memory regions. This is the fastest and safest |
| 12 | * but most complex memory registration mode. |
| 13 | */ |
| 14 | |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 15 | /* Normal operation |
| 16 | * |
| 17 | * A Memory Region is prepared for RDMA READ or WRITE using a FAST_REG |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 18 | * Work Request (frwr_op_map). When the RDMA operation is finished, this |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 19 | * Memory Region is invalidated using a LOCAL_INV Work Request |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 20 | * (frwr_op_unmap_sync). |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 21 | * |
| 22 | * Typically these Work Requests are not signaled, and neither are RDMA |
| 23 | * SEND Work Requests (with the exception of signaling occasionally to |
| 24 | * prevent provider work queue overflows). This greatly reduces HCA |
| 25 | * interrupt workload. |
| 26 | * |
| 27 | * As an optimization, frwr_op_unmap marks MRs INVALID before the |
| 28 | * LOCAL_INV WR is posted. If posting succeeds, the MR is placed on |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 29 | * rb_mrs immediately so that no work (like managing a linked list |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 30 | * under a spinlock) is needed in the completion upcall. |
| 31 | * |
| 32 | * But this means that frwr_op_map() can occasionally encounter an MR |
| 33 | * that is INVALID but the LOCAL_INV WR has not completed. Work Queue |
| 34 | * ordering prevents a subsequent FAST_REG WR from executing against |
| 35 | * that MR while it is still being invalidated. |
| 36 | */ |
| 37 | |
| 38 | /* Transport recovery |
| 39 | * |
| 40 | * ->op_map and the transport connect worker cannot run at the same |
| 41 | * time, but ->op_unmap can fire while the transport connect worker |
| 42 | * is running. Thus MR recovery is handled in ->op_map, to guarantee |
| 43 | * that recovered MRs are owned by a sending RPC, and not one where |
| 44 | * ->op_unmap could fire at the same time transport reconnect is |
| 45 | * being done. |
| 46 | * |
| 47 | * When the underlying transport disconnects, MRs are left in one of |
Chuck Lever | 62bdf94 | 2016-11-07 16:16:24 -0500 | [diff] [blame] | 48 | * four states: |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 49 | * |
| 50 | * INVALID: The MR was not in use before the QP entered ERROR state. |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 51 | * |
| 52 | * VALID: The MR was registered before the QP entered ERROR state. |
| 53 | * |
Chuck Lever | 62bdf94 | 2016-11-07 16:16:24 -0500 | [diff] [blame] | 54 | * FLUSHED_FR: The MR was being registered when the QP entered ERROR |
| 55 | * state, and the pending WR was flushed. |
| 56 | * |
| 57 | * FLUSHED_LI: The MR was being invalidated when the QP entered ERROR |
| 58 | * state, and the pending WR was flushed. |
| 59 | * |
| 60 | * When frwr_op_map encounters FLUSHED and VALID MRs, they are recovered |
| 61 | * with ib_dereg_mr and then are re-initialized. Because MR recovery |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 62 | * allocates fresh resources, it is deferred to a workqueue, and the |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 63 | * recovered MRs are placed back on the rb_mrs list when recovery is |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 64 | * complete. frwr_op_map allocates another MR for the current RPC while |
| 65 | * the broken MR is reset. |
| 66 | * |
| 67 | * To ensure that frwr_op_map doesn't encounter an MR that is marked |
| 68 | * INVALID but that is about to be flushed due to a previous transport |
| 69 | * disconnect, the transport connect worker attempts to drain all |
| 70 | * pending send queue WRs before the transport is reconnected. |
| 71 | */ |
| 72 | |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 73 | #include <linux/sunrpc/rpc_rdma.h> |
| 74 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 75 | #include "xprt_rdma.h" |
Chuck Lever | b6e717cb | 2018-05-07 15:27:05 -0400 | [diff] [blame^] | 76 | #include <trace/events/rpcrdma.h> |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 77 | |
| 78 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
| 79 | # define RPCDBG_FACILITY RPCDBG_TRANS |
| 80 | #endif |
| 81 | |
Chuck Lever | b54054c | 2016-06-29 13:53:27 -0400 | [diff] [blame] | 82 | bool |
| 83 | frwr_is_supported(struct rpcrdma_ia *ia) |
| 84 | { |
| 85 | struct ib_device_attr *attrs = &ia->ri_device->attrs; |
| 86 | |
| 87 | if (!(attrs->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS)) |
| 88 | goto out_not_supported; |
| 89 | if (attrs->max_fast_reg_page_list_len == 0) |
| 90 | goto out_not_supported; |
| 91 | return true; |
| 92 | |
| 93 | out_not_supported: |
| 94 | pr_info("rpcrdma: 'frwr' mode is not supported by device %s\n", |
| 95 | ia->ri_device->name); |
| 96 | return false; |
| 97 | } |
| 98 | |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 99 | static int |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 100 | frwr_op_init_mr(struct rpcrdma_ia *ia, struct rpcrdma_mr *mr) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 101 | { |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 102 | unsigned int depth = ia->ri_max_frwr_depth; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 103 | struct rpcrdma_frwr *frwr = &mr->frwr; |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 104 | int rc; |
| 105 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 106 | frwr->fr_mr = ib_alloc_mr(ia->ri_pd, ia->ri_mrtype, depth); |
| 107 | if (IS_ERR(frwr->fr_mr)) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 108 | goto out_mr_err; |
| 109 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 110 | mr->mr_sg = kcalloc(depth, sizeof(*mr->mr_sg), GFP_KERNEL); |
| 111 | if (!mr->mr_sg) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 112 | goto out_list_err; |
| 113 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 114 | sg_init_table(mr->mr_sg, depth); |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 115 | init_completion(&frwr->fr_linv_done); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 116 | return 0; |
| 117 | |
| 118 | out_mr_err: |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 119 | rc = PTR_ERR(frwr->fr_mr); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 120 | dprintk("RPC: %s: ib_alloc_mr status %i\n", |
| 121 | __func__, rc); |
| 122 | return rc; |
| 123 | |
| 124 | out_list_err: |
| 125 | rc = -ENOMEM; |
| 126 | dprintk("RPC: %s: sg allocation failure\n", |
| 127 | __func__); |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 128 | ib_dereg_mr(frwr->fr_mr); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 129 | return rc; |
| 130 | } |
| 131 | |
| 132 | static void |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 133 | frwr_op_release_mr(struct rpcrdma_mr *mr) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 134 | { |
| 135 | int rc; |
| 136 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 137 | /* Ensure MR is not on any rl_registered list */ |
| 138 | if (!list_empty(&mr->mr_list)) |
| 139 | list_del(&mr->mr_list); |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 140 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 141 | rc = ib_dereg_mr(mr->frwr.fr_mr); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 142 | if (rc) |
| 143 | pr_err("rpcrdma: final ib_dereg_mr for %p returned %i\n", |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 144 | mr, rc); |
| 145 | kfree(mr->mr_sg); |
| 146 | kfree(mr); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static int |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 150 | __frwr_mr_reset(struct rpcrdma_ia *ia, struct rpcrdma_mr *mr) |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 151 | { |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 152 | struct rpcrdma_frwr *frwr = &mr->frwr; |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 153 | int rc; |
| 154 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 155 | rc = ib_dereg_mr(frwr->fr_mr); |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 156 | if (rc) { |
| 157 | pr_warn("rpcrdma: ib_dereg_mr status %d, frwr %p orphaned\n", |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 158 | rc, mr); |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 159 | return rc; |
| 160 | } |
| 161 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 162 | frwr->fr_mr = ib_alloc_mr(ia->ri_pd, ia->ri_mrtype, |
| 163 | ia->ri_max_frwr_depth); |
| 164 | if (IS_ERR(frwr->fr_mr)) { |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 165 | pr_warn("rpcrdma: ib_alloc_mr status %ld, frwr %p orphaned\n", |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 166 | PTR_ERR(frwr->fr_mr), mr); |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 167 | return PTR_ERR(frwr->fr_mr); |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 170 | dprintk("RPC: %s: recovered FRWR %p\n", __func__, frwr); |
| 171 | frwr->fr_state = FRWR_IS_INVALID; |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 172 | return 0; |
| 173 | } |
| 174 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 175 | /* Reset of a single FRWR. Generate a fresh rkey by replacing the MR. |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 176 | */ |
Chuck Lever | 660bb49 | 2016-05-02 14:42:21 -0400 | [diff] [blame] | 177 | static void |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 178 | frwr_op_recover_mr(struct rpcrdma_mr *mr) |
Chuck Lever | 660bb49 | 2016-05-02 14:42:21 -0400 | [diff] [blame] | 179 | { |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 180 | enum rpcrdma_frwr_state state = mr->frwr.fr_state; |
| 181 | struct rpcrdma_xprt *r_xprt = mr->mr_xprt; |
Chuck Lever | 660bb49 | 2016-05-02 14:42:21 -0400 | [diff] [blame] | 182 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
Chuck Lever | 660bb49 | 2016-05-02 14:42:21 -0400 | [diff] [blame] | 183 | int rc; |
| 184 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 185 | rc = __frwr_mr_reset(ia, mr); |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 186 | if (state != FRWR_FLUSHED_LI) { |
| 187 | trace_xprtrdma_dma_unmap(mr); |
Chuck Lever | 62bdf94 | 2016-11-07 16:16:24 -0500 | [diff] [blame] | 188 | ib_dma_unmap_sg(ia->ri_device, |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 189 | mr->mr_sg, mr->mr_nents, mr->mr_dir); |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 190 | } |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 191 | if (rc) |
| 192 | goto out_release; |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 193 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 194 | rpcrdma_mr_put(mr); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 195 | r_xprt->rx_stats.mrs_recovered++; |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 196 | return; |
| 197 | |
| 198 | out_release: |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 199 | pr_err("rpcrdma: FRWR reset failed %d, %p release\n", rc, mr); |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 200 | r_xprt->rx_stats.mrs_orphaned++; |
| 201 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 202 | spin_lock(&r_xprt->rx_buf.rb_mrlock); |
| 203 | list_del(&mr->mr_all); |
| 204 | spin_unlock(&r_xprt->rx_buf.rb_mrlock); |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 205 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 206 | frwr_op_release_mr(mr); |
Chuck Lever | 951e721 | 2015-05-26 11:52:25 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Chuck Lever | 91e70e7 | 2015-03-30 14:34:58 -0400 | [diff] [blame] | 209 | static int |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 210 | frwr_op_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep, |
| 211 | struct rpcrdma_create_data_internal *cdata) |
| 212 | { |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 213 | struct ib_device_attr *attrs = &ia->ri_device->attrs; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 214 | int depth, delta; |
| 215 | |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 216 | ia->ri_mrtype = IB_MR_TYPE_MEM_REG; |
| 217 | if (attrs->device_cap_flags & IB_DEVICE_SG_GAPS_REG) |
| 218 | ia->ri_mrtype = IB_MR_TYPE_SG_GAPS; |
| 219 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 220 | ia->ri_max_frwr_depth = |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 221 | min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS, |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 222 | attrs->max_fast_reg_page_list_len); |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 223 | dprintk("RPC: %s: device's max FR page list len = %u\n", |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 224 | __func__, ia->ri_max_frwr_depth); |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 225 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 226 | /* Add room for frwr register and invalidate WRs. |
| 227 | * 1. FRWR reg WR for head |
| 228 | * 2. FRWR invalidate WR for head |
| 229 | * 3. N FRWR reg WRs for pagelist |
| 230 | * 4. N FRWR invalidate WRs for pagelist |
| 231 | * 5. FRWR reg WR for tail |
| 232 | * 6. FRWR invalidate WR for tail |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 233 | * 7. The RDMA_SEND WR |
| 234 | */ |
| 235 | depth = 7; |
| 236 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 237 | /* Calculate N if the device max FRWR depth is smaller than |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 238 | * RPCRDMA_MAX_DATA_SEGS. |
| 239 | */ |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 240 | if (ia->ri_max_frwr_depth < RPCRDMA_MAX_DATA_SEGS) { |
| 241 | delta = RPCRDMA_MAX_DATA_SEGS - ia->ri_max_frwr_depth; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 242 | do { |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 243 | depth += 2; /* FRWR reg + invalidate */ |
| 244 | delta -= ia->ri_max_frwr_depth; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 245 | } while (delta > 0); |
| 246 | } |
| 247 | |
| 248 | ep->rep_attr.cap.max_send_wr *= depth; |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 249 | if (ep->rep_attr.cap.max_send_wr > attrs->max_qp_wr) { |
| 250 | cdata->max_requests = attrs->max_qp_wr / depth; |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 251 | if (!cdata->max_requests) |
| 252 | return -EINVAL; |
| 253 | ep->rep_attr.cap.max_send_wr = cdata->max_requests * |
| 254 | depth; |
| 255 | } |
| 256 | |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 257 | ia->ri_max_segs = max_t(unsigned int, 1, RPCRDMA_MAX_DATA_SEGS / |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 258 | ia->ri_max_frwr_depth); |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 262 | /* FRWR mode conveys a list of pages per chunk segment. The |
| 263 | * maximum length of that list is the FRWR page list depth. |
| 264 | */ |
| 265 | static size_t |
| 266 | frwr_op_maxpages(struct rpcrdma_xprt *r_xprt) |
| 267 | { |
| 268 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
| 269 | |
| 270 | return min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS, |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 271 | RPCRDMA_MAX_HDR_SEGS * ia->ri_max_frwr_depth); |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Chuck Lever | e46ac34 | 2015-03-30 14:35:35 -0400 | [diff] [blame] | 274 | static void |
Chuck Lever | 62bdf94 | 2016-11-07 16:16:24 -0500 | [diff] [blame] | 275 | __frwr_sendcompletion_flush(struct ib_wc *wc, const char *wr) |
Chuck Lever | e46ac34 | 2015-03-30 14:35:35 -0400 | [diff] [blame] | 276 | { |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 277 | if (wc->status != IB_WC_WR_FLUSH_ERR) |
| 278 | pr_err("rpcrdma: %s: %s (%u/0x%x)\n", |
| 279 | wr, ib_wc_status_msg(wc->status), |
| 280 | wc->status, wc->vendor_err); |
Chuck Lever | e46ac34 | 2015-03-30 14:35:35 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 283 | /** |
Chuck Lever | 6afafa7 | 2017-06-08 11:53:24 -0400 | [diff] [blame] | 284 | * frwr_wc_fastreg - Invoked by RDMA provider for a flushed FastReg WC |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 285 | * @cq: completion queue (ignored) |
| 286 | * @wc: completed WR |
| 287 | * |
| 288 | */ |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 289 | static void |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 290 | frwr_wc_fastreg(struct ib_cq *cq, struct ib_wc *wc) |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 291 | { |
Chuck Lever | 58f10ad | 2017-12-20 16:30:56 -0500 | [diff] [blame] | 292 | struct ib_cqe *cqe = wc->wr_cqe; |
| 293 | struct rpcrdma_frwr *frwr = |
| 294 | container_of(cqe, struct rpcrdma_frwr, fr_cqe); |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 295 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 296 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
| 297 | if (wc->status != IB_WC_SUCCESS) { |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 298 | frwr->fr_state = FRWR_FLUSHED_FR; |
Chuck Lever | 62bdf94 | 2016-11-07 16:16:24 -0500 | [diff] [blame] | 299 | __frwr_sendcompletion_flush(wc, "fastreg"); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 300 | } |
Chuck Lever | 58f10ad | 2017-12-20 16:30:56 -0500 | [diff] [blame] | 301 | trace_xprtrdma_wc_fastreg(wc, frwr); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 302 | } |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 303 | |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 304 | /** |
Chuck Lever | 6afafa7 | 2017-06-08 11:53:24 -0400 | [diff] [blame] | 305 | * frwr_wc_localinv - Invoked by RDMA provider for a flushed LocalInv WC |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 306 | * @cq: completion queue (ignored) |
| 307 | * @wc: completed WR |
| 308 | * |
| 309 | */ |
| 310 | static void |
| 311 | frwr_wc_localinv(struct ib_cq *cq, struct ib_wc *wc) |
| 312 | { |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 313 | struct ib_cqe *cqe = wc->wr_cqe; |
| 314 | struct rpcrdma_frwr *frwr = container_of(cqe, struct rpcrdma_frwr, |
| 315 | fr_cqe); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 316 | |
| 317 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
| 318 | if (wc->status != IB_WC_SUCCESS) { |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 319 | frwr->fr_state = FRWR_FLUSHED_LI; |
Chuck Lever | 62bdf94 | 2016-11-07 16:16:24 -0500 | [diff] [blame] | 320 | __frwr_sendcompletion_flush(wc, "localinv"); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 321 | } |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 322 | trace_xprtrdma_wc_li(wc, frwr); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
Chuck Lever | 6afafa7 | 2017-06-08 11:53:24 -0400 | [diff] [blame] | 326 | * frwr_wc_localinv_wake - Invoked by RDMA provider for a signaled LocalInv WC |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 327 | * @cq: completion queue (ignored) |
| 328 | * @wc: completed WR |
| 329 | * |
| 330 | * Awaken anyone waiting for an MR to finish being fenced. |
| 331 | */ |
| 332 | static void |
| 333 | frwr_wc_localinv_wake(struct ib_cq *cq, struct ib_wc *wc) |
| 334 | { |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 335 | struct ib_cqe *cqe = wc->wr_cqe; |
| 336 | struct rpcrdma_frwr *frwr = container_of(cqe, struct rpcrdma_frwr, |
| 337 | fr_cqe); |
Chuck Lever | 2fa8f88 | 2016-03-04 11:28:53 -0500 | [diff] [blame] | 338 | |
| 339 | /* WARNING: Only wr_cqe and status are reliable at this point */ |
Chuck Lever | 62bdf94 | 2016-11-07 16:16:24 -0500 | [diff] [blame] | 340 | if (wc->status != IB_WC_SUCCESS) { |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 341 | frwr->fr_state = FRWR_FLUSHED_LI; |
Chuck Lever | 62bdf94 | 2016-11-07 16:16:24 -0500 | [diff] [blame] | 342 | __frwr_sendcompletion_flush(wc, "localinv"); |
| 343 | } |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 344 | complete(&frwr->fr_linv_done); |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 345 | trace_xprtrdma_wc_li_wake(wc, frwr); |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 346 | } |
| 347 | |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 348 | /* Post a REG_MR Work Request to register a memory region |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 349 | * for remote access via RDMA READ or RDMA WRITE. |
| 350 | */ |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 351 | static struct rpcrdma_mr_seg * |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 352 | frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg, |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 353 | int nsegs, bool writing, struct rpcrdma_mr **out) |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 354 | { |
| 355 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 356 | bool holes_ok = ia->ri_mrtype == IB_MR_TYPE_SG_GAPS; |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 357 | struct rpcrdma_frwr *frwr; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 358 | struct rpcrdma_mr *mr; |
| 359 | struct ib_mr *ibmr; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 360 | struct ib_reg_wr *reg_wr; |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 361 | int i, n; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 362 | u8 key; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 363 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 364 | mr = NULL; |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 365 | do { |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 366 | if (mr) |
| 367 | rpcrdma_mr_defer_recovery(mr); |
| 368 | mr = rpcrdma_mr_get(r_xprt); |
| 369 | if (!mr) |
Chuck Lever | 9e679d5 | 2018-02-28 15:30:44 -0500 | [diff] [blame] | 370 | return ERR_PTR(-EAGAIN); |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 371 | } while (mr->frwr.fr_state != FRWR_IS_INVALID); |
| 372 | frwr = &mr->frwr; |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 373 | frwr->fr_state = FRWR_IS_VALID; |
Chuck Lever | c14d86e | 2015-05-26 11:52:35 -0400 | [diff] [blame] | 374 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 375 | if (nsegs > ia->ri_max_frwr_depth) |
| 376 | nsegs = ia->ri_max_frwr_depth; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 377 | for (i = 0; i < nsegs;) { |
| 378 | if (seg->mr_page) |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 379 | sg_set_page(&mr->mr_sg[i], |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 380 | seg->mr_page, |
| 381 | seg->mr_len, |
| 382 | offset_in_page(seg->mr_offset)); |
| 383 | else |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 384 | sg_set_buf(&mr->mr_sg[i], seg->mr_offset, |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 385 | seg->mr_len); |
| 386 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 387 | ++seg; |
| 388 | ++i; |
Chuck Lever | 5e9fc6a | 2016-11-29 10:52:24 -0500 | [diff] [blame] | 389 | if (holes_ok) |
| 390 | continue; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 391 | if ((i < nsegs && offset_in_page(seg->mr_offset)) || |
| 392 | offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len)) |
| 393 | break; |
| 394 | } |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 395 | mr->mr_dir = rpcrdma_data_dir(writing); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 396 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 397 | mr->mr_nents = ib_dma_map_sg(ia->ri_device, mr->mr_sg, i, mr->mr_dir); |
| 398 | if (!mr->mr_nents) |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 399 | goto out_dmamap_err; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 400 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 401 | ibmr = frwr->fr_mr; |
| 402 | n = ib_map_mr_sg(ibmr, mr->mr_sg, mr->mr_nents, NULL, PAGE_SIZE); |
| 403 | if (unlikely(n != mr->mr_nents)) |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 404 | goto out_mapmr_err; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 405 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 406 | key = (u8)(ibmr->rkey & 0x000000FF); |
| 407 | ib_update_fast_reg_key(ibmr, ++key); |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 408 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 409 | reg_wr = &frwr->fr_regwr; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 410 | reg_wr->mr = ibmr; |
| 411 | reg_wr->key = ibmr->rkey; |
Chuck Lever | 3cf4e16 | 2015-12-16 17:22:31 -0500 | [diff] [blame] | 412 | reg_wr->access = writing ? |
| 413 | IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE : |
| 414 | IB_ACCESS_REMOTE_READ; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 415 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 416 | mr->mr_handle = ibmr->rkey; |
| 417 | mr->mr_length = ibmr->length; |
| 418 | mr->mr_offset = ibmr->iova; |
Sagi Grimberg | 4143f34 | 2015-10-13 19:11:35 +0300 | [diff] [blame] | 419 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 420 | *out = mr; |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 421 | return seg; |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 422 | |
| 423 | out_dmamap_err: |
Chuck Lever | 1f54189 | 2017-06-08 11:52:36 -0400 | [diff] [blame] | 424 | pr_err("rpcrdma: failed to DMA map sg %p sg_nents %d\n", |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 425 | mr->mr_sg, i); |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 426 | frwr->fr_state = FRWR_IS_INVALID; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 427 | rpcrdma_mr_put(mr); |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 428 | return ERR_PTR(-EIO); |
Chuck Lever | 564471d | 2016-06-29 13:52:21 -0400 | [diff] [blame] | 429 | |
| 430 | out_mapmr_err: |
Chuck Lever | 1f54189 | 2017-06-08 11:52:36 -0400 | [diff] [blame] | 431 | pr_err("rpcrdma: failed to map mr %p (%d/%d)\n", |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 432 | frwr->fr_mr, n, mr->mr_nents); |
| 433 | rpcrdma_mr_defer_recovery(mr); |
Chuck Lever | 6748b0ca | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 434 | return ERR_PTR(-EIO); |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 435 | } |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 436 | |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 437 | /* Post Send WR containing the RPC Call message. |
| 438 | * |
| 439 | * For FRMR, chain any FastReg WRs to the Send WR. Only a |
| 440 | * single ib_post_send call is needed to register memory |
| 441 | * and then post the Send WR. |
| 442 | */ |
| 443 | static int |
| 444 | frwr_op_send(struct rpcrdma_ia *ia, struct rpcrdma_req *req) |
| 445 | { |
| 446 | struct ib_send_wr *post_wr, *bad_wr; |
| 447 | struct rpcrdma_mr *mr; |
| 448 | |
| 449 | post_wr = &req->rl_sendctx->sc_wr; |
| 450 | list_for_each_entry(mr, &req->rl_registered, mr_list) { |
| 451 | struct rpcrdma_frwr *frwr; |
| 452 | |
| 453 | frwr = &mr->frwr; |
| 454 | |
| 455 | frwr->fr_cqe.done = frwr_wc_fastreg; |
| 456 | frwr->fr_regwr.wr.next = post_wr; |
| 457 | frwr->fr_regwr.wr.wr_cqe = &frwr->fr_cqe; |
| 458 | frwr->fr_regwr.wr.num_sge = 0; |
| 459 | frwr->fr_regwr.wr.opcode = IB_WR_REG_MR; |
| 460 | frwr->fr_regwr.wr.send_flags = 0; |
| 461 | |
| 462 | post_wr = &frwr->fr_regwr.wr; |
| 463 | } |
| 464 | |
| 465 | /* If ib_post_send fails, the next ->send_request for |
| 466 | * @req will queue these MWs for recovery. |
| 467 | */ |
| 468 | return ib_post_send(ia->ri_id->qp, post_wr, &bad_wr); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 469 | } |
| 470 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 471 | /* Handle a remotely invalidated mr on the @mrs list |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 472 | */ |
| 473 | static void |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 474 | frwr_op_reminv(struct rpcrdma_rep *rep, struct list_head *mrs) |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 475 | { |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 476 | struct rpcrdma_mr *mr; |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 477 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 478 | list_for_each_entry(mr, mrs, mr_list) |
| 479 | if (mr->mr_handle == rep->rr_inv_rkey) { |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 480 | list_del(&mr->mr_list); |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 481 | trace_xprtrdma_remoteinv(mr); |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 482 | mr->frwr.fr_state = FRWR_IS_INVALID; |
Chuck Lever | ec12e47 | 2017-12-14 20:58:04 -0500 | [diff] [blame] | 483 | rpcrdma_mr_unmap_and_put(mr); |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 484 | break; /* only one invalidated MR per RPC */ |
| 485 | } |
| 486 | } |
| 487 | |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 488 | /* Invalidate all memory regions that were registered for "req". |
| 489 | * |
| 490 | * Sleeps until it is safe for the host CPU to access the |
| 491 | * previously mapped memory regions. |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 492 | * |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 493 | * Caller ensures that @mrs is not empty before the call. This |
Chuck Lever | 451d26e | 2017-06-08 11:52:04 -0400 | [diff] [blame] | 494 | * function empties the list. |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 495 | */ |
| 496 | static void |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 497 | frwr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct list_head *mrs) |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 498 | { |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 499 | struct ib_send_wr *first, **prev, *last, *bad_wr; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 500 | struct rpcrdma_ia *ia = &r_xprt->rx_ia; |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 501 | struct rpcrdma_frwr *frwr; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 502 | struct rpcrdma_mr *mr; |
Chuck Lever | 8d38de6 | 2016-11-29 10:52:16 -0500 | [diff] [blame] | 503 | int count, rc; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 504 | |
Chuck Lever | 451d26e | 2017-06-08 11:52:04 -0400 | [diff] [blame] | 505 | /* ORDER: Invalidate all of the MRs first |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 506 | * |
| 507 | * Chain the LOCAL_INV Work Requests and post them with |
| 508 | * a single ib_post_send() call. |
| 509 | */ |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 510 | frwr = NULL; |
Chuck Lever | 8d38de6 | 2016-11-29 10:52:16 -0500 | [diff] [blame] | 511 | count = 0; |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 512 | prev = &first; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 513 | list_for_each_entry(mr, mrs, mr_list) { |
| 514 | mr->frwr.fr_state = FRWR_IS_INVALID; |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 515 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 516 | frwr = &mr->frwr; |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 517 | trace_xprtrdma_localinv(mr); |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 518 | |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 519 | frwr->fr_cqe.done = frwr_wc_localinv; |
| 520 | last = &frwr->fr_invwr; |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 521 | memset(last, 0, sizeof(*last)); |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 522 | last->wr_cqe = &frwr->fr_cqe; |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 523 | last->opcode = IB_WR_LOCAL_INV; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 524 | last->ex.invalidate_rkey = mr->mr_handle; |
Chuck Lever | 8d38de6 | 2016-11-29 10:52:16 -0500 | [diff] [blame] | 525 | count++; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 526 | |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 527 | *prev = last; |
| 528 | prev = &last->next; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 529 | } |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 530 | if (!frwr) |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 531 | goto unmap; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 532 | |
| 533 | /* Strong send queue ordering guarantees that when the |
| 534 | * last WR in the chain completes, all WRs in the chain |
| 535 | * are complete. |
| 536 | */ |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 537 | last->send_flags = IB_SEND_SIGNALED; |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 538 | frwr->fr_cqe.done = frwr_wc_localinv_wake; |
| 539 | reinit_completion(&frwr->fr_linv_done); |
Chuck Lever | 8d38de6 | 2016-11-29 10:52:16 -0500 | [diff] [blame] | 540 | |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 541 | /* Transport disconnect drains the receive CQ before it |
| 542 | * replaces the QP. The RPC reply handler won't call us |
| 543 | * unless ri_id->qp is a valid pointer. |
| 544 | */ |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 545 | r_xprt->rx_stats.local_inv_needed++; |
Chuck Lever | 8d75483 | 2017-06-08 11:52:28 -0400 | [diff] [blame] | 546 | bad_wr = NULL; |
Chuck Lever | a100fda | 2016-11-29 10:52:57 -0500 | [diff] [blame] | 547 | rc = ib_post_send(ia->ri_id->qp, first, &bad_wr); |
Chuck Lever | 8d75483 | 2017-06-08 11:52:28 -0400 | [diff] [blame] | 548 | if (bad_wr != first) |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 549 | wait_for_completion(&frwr->fr_linv_done); |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 550 | if (rc) |
| 551 | goto reset_mrs; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 552 | |
Chuck Lever | 451d26e | 2017-06-08 11:52:04 -0400 | [diff] [blame] | 553 | /* ORDER: Now DMA unmap all of the MRs, and return |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 554 | * them to the free MR list. |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 555 | */ |
Chuck Lever | b892a69 | 2016-03-04 11:28:01 -0500 | [diff] [blame] | 556 | unmap: |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 557 | while (!list_empty(mrs)) { |
| 558 | mr = rpcrdma_mr_pop(mrs); |
Chuck Lever | ec12e47 | 2017-12-14 20:58:04 -0500 | [diff] [blame] | 559 | rpcrdma_mr_unmap_and_put(mr); |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 560 | } |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 561 | return; |
| 562 | |
| 563 | reset_mrs: |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 564 | pr_err("rpcrdma: FRWR invalidate ib_post_send returned %i\n", rc); |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 565 | |
| 566 | /* Find and reset the MRs in the LOCAL_INV WRs that did not |
Chuck Lever | 8d75483 | 2017-06-08 11:52:28 -0400 | [diff] [blame] | 567 | * get posted. |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 568 | */ |
Chuck Lever | 8d75483 | 2017-06-08 11:52:28 -0400 | [diff] [blame] | 569 | while (bad_wr) { |
Chuck Lever | ce5b371 | 2017-12-14 20:57:47 -0500 | [diff] [blame] | 570 | frwr = container_of(bad_wr, struct rpcrdma_frwr, |
| 571 | fr_invwr); |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 572 | mr = container_of(frwr, struct rpcrdma_mr, frwr); |
Chuck Lever | 8d75483 | 2017-06-08 11:52:28 -0400 | [diff] [blame] | 573 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 574 | __frwr_mr_reset(ia, mr); |
Chuck Lever | 8d75483 | 2017-06-08 11:52:28 -0400 | [diff] [blame] | 575 | |
| 576 | bad_wr = bad_wr->next; |
Chuck Lever | d7a21c1 | 2016-05-02 14:42:12 -0400 | [diff] [blame] | 577 | } |
| 578 | goto unmap; |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 579 | } |
| 580 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 581 | const struct rpcrdma_memreg_ops rpcrdma_frwr_memreg_ops = { |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 582 | .ro_map = frwr_op_map, |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 583 | .ro_send = frwr_op_send, |
Chuck Lever | c344161 | 2017-12-14 20:56:26 -0500 | [diff] [blame] | 584 | .ro_reminv = frwr_op_reminv, |
Chuck Lever | c9918ff | 2015-12-16 17:22:47 -0500 | [diff] [blame] | 585 | .ro_unmap_sync = frwr_op_unmap_sync, |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 586 | .ro_recover_mr = frwr_op_recover_mr, |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 587 | .ro_open = frwr_op_open, |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 588 | .ro_maxpages = frwr_op_maxpages, |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 589 | .ro_init_mr = frwr_op_init_mr, |
| 590 | .ro_release_mr = frwr_op_release_mr, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 591 | .ro_displayname = "frwr", |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 592 | .ro_send_w_inv_ok = RPCRDMA_CMP_F_SND_W_INV_OK, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 593 | }; |