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 | 96cedde | 2017-12-14 20:57:55 -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 Memory Regions (FMR). |
| 8 | * Referred to sometimes as MTHCAFMR mode. |
| 9 | * |
| 10 | * FMR uses synchronous memory registration and deregistration. |
| 11 | * FMR registration is known to be fast, but FMR deregistration |
| 12 | * can take tens of usecs to complete. |
| 13 | */ |
| 14 | |
Chuck Lever | fc7fbb5 | 2015-05-26 11:52:16 -0400 | [diff] [blame] | 15 | /* Normal operation |
| 16 | * |
| 17 | * A Memory Region is prepared for RDMA READ or WRITE using the |
| 18 | * ib_map_phys_fmr verb (fmr_op_map). When the RDMA operation is |
| 19 | * finished, the Memory Region is unmapped using the ib_unmap_fmr |
| 20 | * verb (fmr_op_unmap). |
| 21 | */ |
| 22 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 23 | #include "xprt_rdma.h" |
| 24 | |
| 25 | #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) |
| 26 | # define RPCDBG_FACILITY RPCDBG_TRANS |
| 27 | #endif |
| 28 | |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 29 | /* Maximum scatter/gather per FMR */ |
| 30 | #define RPCRDMA_MAX_FMR_SGES (64) |
| 31 | |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 32 | /* Access mode of externally registered pages */ |
| 33 | enum { |
| 34 | RPCRDMA_FMR_ACCESS_FLAGS = IB_ACCESS_REMOTE_WRITE | |
| 35 | IB_ACCESS_REMOTE_READ, |
| 36 | }; |
| 37 | |
Chuck Lever | b54054c | 2016-06-29 13:53:27 -0400 | [diff] [blame] | 38 | bool |
| 39 | fmr_is_supported(struct rpcrdma_ia *ia) |
| 40 | { |
| 41 | if (!ia->ri_device->alloc_fmr) { |
| 42 | pr_info("rpcrdma: 'fmr' mode is not supported by device %s\n", |
| 43 | ia->ri_device->name); |
| 44 | return false; |
| 45 | } |
| 46 | return true; |
| 47 | } |
| 48 | |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 49 | static int |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 50 | fmr_op_init_mr(struct rpcrdma_ia *ia, struct rpcrdma_mr *mr) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 51 | { |
| 52 | static struct ib_fmr_attr fmr_attr = { |
| 53 | .max_pages = RPCRDMA_MAX_FMR_SGES, |
| 54 | .max_maps = 1, |
| 55 | .page_shift = PAGE_SHIFT |
| 56 | }; |
| 57 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 58 | mr->fmr.fm_physaddrs = kcalloc(RPCRDMA_MAX_FMR_SGES, |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 59 | sizeof(u64), GFP_KERNEL); |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 60 | if (!mr->fmr.fm_physaddrs) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 61 | goto out_free; |
| 62 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 63 | mr->mr_sg = kcalloc(RPCRDMA_MAX_FMR_SGES, |
| 64 | sizeof(*mr->mr_sg), GFP_KERNEL); |
| 65 | if (!mr->mr_sg) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 66 | goto out_free; |
| 67 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 68 | sg_init_table(mr->mr_sg, RPCRDMA_MAX_FMR_SGES); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 69 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 70 | mr->fmr.fm_mr = ib_alloc_fmr(ia->ri_pd, RPCRDMA_FMR_ACCESS_FLAGS, |
Chuck Lever | 88975eb | 2016-06-29 13:52:37 -0400 | [diff] [blame] | 71 | &fmr_attr); |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 72 | if (IS_ERR(mr->fmr.fm_mr)) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 73 | goto out_fmr_err; |
| 74 | |
Chuck Lever | 054f155 | 2018-05-01 11:37:14 -0400 | [diff] [blame] | 75 | INIT_LIST_HEAD(&mr->mr_list); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 76 | return 0; |
| 77 | |
| 78 | out_fmr_err: |
| 79 | dprintk("RPC: %s: ib_alloc_fmr returned %ld\n", __func__, |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 80 | PTR_ERR(mr->fmr.fm_mr)); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 81 | |
| 82 | out_free: |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 83 | kfree(mr->mr_sg); |
| 84 | kfree(mr->fmr.fm_physaddrs); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 85 | return -ENOMEM; |
| 86 | } |
| 87 | |
| 88 | static int |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 89 | __fmr_unmap(struct rpcrdma_mr *mr) |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 90 | { |
| 91 | LIST_HEAD(l); |
Chuck Lever | 38f1932e | 2016-06-29 13:52:12 -0400 | [diff] [blame] | 92 | int rc; |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 93 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 94 | list_add(&mr->fmr.fm_mr->list, &l); |
Chuck Lever | 38f1932e | 2016-06-29 13:52:12 -0400 | [diff] [blame] | 95 | rc = ib_unmap_fmr(&l); |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 96 | list_del(&mr->fmr.fm_mr->list); |
Chuck Lever | 38f1932e | 2016-06-29 13:52:12 -0400 | [diff] [blame] | 97 | return rc; |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 100 | static void |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 101 | fmr_op_release_mr(struct rpcrdma_mr *mr) |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 102 | { |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 103 | LIST_HEAD(unmap_list); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 104 | int rc; |
| 105 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 106 | kfree(mr->fmr.fm_physaddrs); |
| 107 | kfree(mr->mr_sg); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 108 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 109 | /* In case this one was left mapped, try to unmap it |
| 110 | * to prevent dealloc_fmr from failing with EBUSY |
| 111 | */ |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 112 | rc = __fmr_unmap(mr); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 113 | if (rc) |
| 114 | pr_err("rpcrdma: final ib_unmap_fmr for %p failed %i\n", |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 115 | mr, rc); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 116 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 117 | rc = ib_dealloc_fmr(mr->fmr.fm_mr); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 118 | if (rc) |
| 119 | pr_err("rpcrdma: final ib_dealloc_fmr for %p returned %i\n", |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 120 | mr, rc); |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 121 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 122 | kfree(mr); |
Chuck Lever | d48b1d2 | 2016-06-29 13:52:29 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 125 | /* Reset of a single FMR. |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 126 | */ |
| 127 | static void |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 128 | fmr_op_recover_mr(struct rpcrdma_mr *mr) |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 129 | { |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 130 | struct rpcrdma_xprt *r_xprt = mr->mr_xprt; |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 131 | int rc; |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 132 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 133 | /* ORDER: invalidate first */ |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 134 | rc = __fmr_unmap(mr); |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 135 | if (rc) |
| 136 | goto out_release; |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 137 | |
Chuck Lever | ec12e47 | 2017-12-14 20:58:04 -0500 | [diff] [blame] | 138 | /* ORDER: then DMA unmap */ |
| 139 | rpcrdma_mr_unmap_and_put(mr); |
| 140 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 141 | r_xprt->rx_stats.mrs_recovered++; |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 142 | return; |
| 143 | |
| 144 | out_release: |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 145 | pr_err("rpcrdma: FMR reset failed (%d), %p released\n", rc, mr); |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 146 | r_xprt->rx_stats.mrs_orphaned++; |
| 147 | |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 148 | trace_xprtrdma_dma_unmap(mr); |
Chuck Lever | ec12e47 | 2017-12-14 20:58:04 -0500 | [diff] [blame] | 149 | ib_dma_unmap_sg(r_xprt->rx_ia.ri_device, |
| 150 | mr->mr_sg, mr->mr_nents, mr->mr_dir); |
| 151 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 152 | spin_lock(&r_xprt->rx_buf.rb_mrlock); |
| 153 | list_del(&mr->mr_all); |
| 154 | spin_unlock(&r_xprt->rx_buf.rb_mrlock); |
Chuck Lever | 2ffc871 | 2016-06-29 13:54:08 -0400 | [diff] [blame] | 155 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 156 | fmr_op_release_mr(mr); |
Chuck Lever | ead3f26 | 2016-05-02 14:42:46 -0400 | [diff] [blame] | 157 | } |
| 158 | |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 159 | static int |
| 160 | fmr_op_open(struct rpcrdma_ia *ia, struct rpcrdma_ep *ep, |
| 161 | struct rpcrdma_create_data_internal *cdata) |
| 162 | { |
Chuck Lever | 87cfb9a | 2016-09-15 10:57:07 -0400 | [diff] [blame] | 163 | ia->ri_max_segs = max_t(unsigned int, 1, RPCRDMA_MAX_DATA_SEGS / |
| 164 | RPCRDMA_MAX_FMR_SGES); |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 168 | /* FMR mode conveys up to 64 pages of payload per chunk segment. |
| 169 | */ |
| 170 | static size_t |
| 171 | fmr_op_maxpages(struct rpcrdma_xprt *r_xprt) |
| 172 | { |
| 173 | return min_t(unsigned int, RPCRDMA_MAX_DATA_SEGS, |
Chuck Lever | 9493174 | 2016-05-02 14:40:56 -0400 | [diff] [blame] | 174 | RPCRDMA_MAX_HDR_SEGS * RPCRDMA_MAX_FMR_SGES); |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 177 | /* Use the ib_map_phys_fmr() verb to register a memory region |
| 178 | * for remote access via RDMA READ or RDMA WRITE. |
| 179 | */ |
Chuck Lever | 6748b0c | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 180 | static struct rpcrdma_mr_seg * |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 181 | fmr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg, |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 182 | int nsegs, bool writing, struct rpcrdma_mr **out) |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 183 | { |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 184 | struct rpcrdma_mr_seg *seg1 = seg; |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 185 | int len, pageoff, i, rc; |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 186 | struct rpcrdma_mr *mr; |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 187 | u64 *dma_pages; |
Chuck Lever | fc7fbb5 | 2015-05-26 11:52:16 -0400 | [diff] [blame] | 188 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 189 | mr = rpcrdma_mr_get(r_xprt); |
| 190 | if (!mr) |
Chuck Lever | 9e679d5 | 2018-02-28 15:30:44 -0500 | [diff] [blame] | 191 | return ERR_PTR(-EAGAIN); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 192 | |
| 193 | pageoff = offset_in_page(seg1->mr_offset); |
| 194 | seg1->mr_offset -= pageoff; /* start of page */ |
| 195 | seg1->mr_len += pageoff; |
| 196 | len = -pageoff; |
| 197 | if (nsegs > RPCRDMA_MAX_FMR_SGES) |
| 198 | nsegs = RPCRDMA_MAX_FMR_SGES; |
| 199 | for (i = 0; i < nsegs;) { |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 200 | if (seg->mr_page) |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 201 | sg_set_page(&mr->mr_sg[i], |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 202 | seg->mr_page, |
| 203 | seg->mr_len, |
| 204 | offset_in_page(seg->mr_offset)); |
| 205 | else |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 206 | sg_set_buf(&mr->mr_sg[i], seg->mr_offset, |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 207 | seg->mr_len); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 208 | len += seg->mr_len; |
| 209 | ++seg; |
| 210 | ++i; |
| 211 | /* Check for holes */ |
| 212 | if ((i < nsegs && offset_in_page(seg->mr_offset)) || |
| 213 | offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len)) |
| 214 | break; |
| 215 | } |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 216 | mr->mr_dir = rpcrdma_data_dir(writing); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 217 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 218 | mr->mr_nents = ib_dma_map_sg(r_xprt->rx_ia.ri_device, |
| 219 | mr->mr_sg, i, mr->mr_dir); |
| 220 | if (!mr->mr_nents) |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 221 | goto out_dmamap_err; |
| 222 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 223 | for (i = 0, dma_pages = mr->fmr.fm_physaddrs; i < mr->mr_nents; i++) |
| 224 | dma_pages[i] = sg_dma_address(&mr->mr_sg[i]); |
| 225 | rc = ib_map_phys_fmr(mr->fmr.fm_mr, dma_pages, mr->mr_nents, |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 226 | dma_pages[0]); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 227 | if (rc) |
| 228 | goto out_maperr; |
| 229 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 230 | mr->mr_handle = mr->fmr.fm_mr->rkey; |
| 231 | mr->mr_length = len; |
| 232 | mr->mr_offset = dma_pages[0] + pageoff; |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 233 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 234 | *out = mr; |
Chuck Lever | 6748b0c | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 235 | return seg; |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 236 | |
| 237 | out_dmamap_err: |
Chuck Lever | 1f54189 | 2017-06-08 11:52:36 -0400 | [diff] [blame] | 238 | 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] | 239 | mr->mr_sg, i); |
| 240 | rpcrdma_mr_put(mr); |
Chuck Lever | 6748b0c | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 241 | return ERR_PTR(-EIO); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 242 | |
| 243 | out_maperr: |
Chuck Lever | fcdfb96 | 2016-06-29 13:52:45 -0400 | [diff] [blame] | 244 | pr_err("rpcrdma: ib_map_phys_fmr %u@0x%llx+%i (%d) status %i\n", |
| 245 | len, (unsigned long long)dma_pages[0], |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 246 | pageoff, mr->mr_nents, rc); |
Chuck Lever | ec12e47 | 2017-12-14 20:58:04 -0500 | [diff] [blame] | 247 | rpcrdma_mr_unmap_and_put(mr); |
Chuck Lever | 6748b0c | 2017-08-14 15:38:30 -0400 | [diff] [blame] | 248 | return ERR_PTR(-EIO); |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 249 | } |
| 250 | |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 251 | /* Post Send WR containing the RPC Call message. |
| 252 | */ |
| 253 | static int |
| 254 | fmr_op_send(struct rpcrdma_ia *ia, struct rpcrdma_req *req) |
| 255 | { |
| 256 | struct ib_send_wr *bad_wr; |
| 257 | |
| 258 | return ib_post_send(ia->ri_id->qp, &req->rl_sendctx->sc_wr, &bad_wr); |
| 259 | } |
| 260 | |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 261 | /* Invalidate all memory regions that were registered for "req". |
| 262 | * |
| 263 | * Sleeps until it is safe for the host CPU to access the |
| 264 | * previously mapped memory regions. |
Chuck Lever | 9d6b040 | 2016-06-29 13:54:16 -0400 | [diff] [blame] | 265 | * |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 266 | * Caller ensures that @mrs is not empty before the call. This |
Chuck Lever | 451d26e | 2017-06-08 11:52:04 -0400 | [diff] [blame] | 267 | * function empties the list. |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 268 | */ |
| 269 | static void |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 270 | fmr_op_unmap_sync(struct rpcrdma_xprt *r_xprt, struct list_head *mrs) |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 271 | { |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 272 | struct rpcrdma_mr *mr; |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 273 | LIST_HEAD(unmap_list); |
| 274 | int rc; |
| 275 | |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 276 | /* ORDER: Invalidate all of the req's MRs first |
| 277 | * |
| 278 | * ib_unmap_fmr() is slow, so use a single call instead |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 279 | * of one call per mapped FMR. |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 280 | */ |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 281 | list_for_each_entry(mr, mrs, mr_list) { |
Chuck Lever | 451d26e | 2017-06-08 11:52:04 -0400 | [diff] [blame] | 282 | dprintk("RPC: %s: unmapping fmr %p\n", |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 283 | __func__, &mr->fmr); |
Chuck Lever | 2937fed | 2017-12-20 16:31:12 -0500 | [diff] [blame] | 284 | trace_xprtrdma_localinv(mr); |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 285 | list_add_tail(&mr->fmr.fm_mr->list, &unmap_list); |
Chuck Lever | 451d26e | 2017-06-08 11:52:04 -0400 | [diff] [blame] | 286 | } |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 287 | r_xprt->rx_stats.local_inv_needed++; |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 288 | rc = ib_unmap_fmr(&unmap_list); |
| 289 | if (rc) |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 290 | goto out_reset; |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 291 | |
| 292 | /* ORDER: Now DMA unmap all of the req's MRs, and return |
| 293 | * them to the free MW list. |
| 294 | */ |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 295 | while (!list_empty(mrs)) { |
| 296 | mr = rpcrdma_mr_pop(mrs); |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 297 | list_del(&mr->fmr.fm_mr->list); |
Chuck Lever | ec12e47 | 2017-12-14 20:58:04 -0500 | [diff] [blame] | 298 | rpcrdma_mr_unmap_and_put(mr); |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 299 | } |
| 300 | |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 301 | return; |
| 302 | |
| 303 | out_reset: |
| 304 | pr_err("rpcrdma: ib_unmap_fmr failed (%i)\n", rc); |
| 305 | |
Chuck Lever | 96cedde | 2017-12-14 20:57:55 -0500 | [diff] [blame] | 306 | while (!list_empty(mrs)) { |
| 307 | mr = rpcrdma_mr_pop(mrs); |
| 308 | list_del(&mr->fmr.fm_mr->list); |
| 309 | fmr_op_recover_mr(mr); |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 310 | } |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 311 | } |
| 312 | |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 313 | const struct rpcrdma_memreg_ops rpcrdma_fmr_memreg_ops = { |
Chuck Lever | 9c1b4d7 | 2015-03-30 14:34:39 -0400 | [diff] [blame] | 314 | .ro_map = fmr_op_map, |
Chuck Lever | f287762 | 2018-02-28 15:30:59 -0500 | [diff] [blame] | 315 | .ro_send = fmr_op_send, |
Chuck Lever | 7c7a539 | 2015-12-16 17:22:55 -0500 | [diff] [blame] | 316 | .ro_unmap_sync = fmr_op_unmap_sync, |
Chuck Lever | 505bbe6 | 2016-06-29 13:52:54 -0400 | [diff] [blame] | 317 | .ro_recover_mr = fmr_op_recover_mr, |
Chuck Lever | 3968cb5 | 2015-03-30 14:35:26 -0400 | [diff] [blame] | 318 | .ro_open = fmr_op_open, |
Chuck Lever | 1c9351e | 2015-03-30 14:34:30 -0400 | [diff] [blame] | 319 | .ro_maxpages = fmr_op_maxpages, |
Chuck Lever | e2ac236 | 2016-06-29 13:54:00 -0400 | [diff] [blame] | 320 | .ro_init_mr = fmr_op_init_mr, |
| 321 | .ro_release_mr = fmr_op_release_mr, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 322 | .ro_displayname = "fmr", |
Chuck Lever | c8b920b | 2016-09-15 10:57:16 -0400 | [diff] [blame] | 323 | .ro_send_w_inv_ok = 0, |
Chuck Lever | a0ce85f | 2015-03-30 14:34:21 -0400 | [diff] [blame] | 324 | }; |