e80f43d589034a95b4de57fa7382999e4c6ab6e8
[deliverable/linux.git] / net / sunrpc / xprtrdma / rpc_rdma.c
1 /*
2 * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the BSD-type
8 * license below:
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
21 *
22 * Neither the name of the Network Appliance, Inc. nor the names of
23 * its contributors may be used to endorse or promote products
24 * derived from this software without specific prior written
25 * permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * rpc_rdma.c
42 *
43 * This file contains the guts of the RPC RDMA protocol, and
44 * does marshaling/unmarshaling, etc. It is also where interfacing
45 * to the Linux RPC framework lives.
46 */
47
48 #include "xprt_rdma.h"
49
50 #include <linux/highmem.h>
51
52 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
53 # define RPCDBG_FACILITY RPCDBG_TRANS
54 #endif
55
56 enum rpcrdma_chunktype {
57 rpcrdma_noch = 0,
58 rpcrdma_readch,
59 rpcrdma_areadch,
60 rpcrdma_writech,
61 rpcrdma_replych
62 };
63
64 static const char transfertypes[][12] = {
65 "inline", /* no chunks */
66 "read list", /* some argument via rdma read */
67 "*read list", /* entire request via rdma read */
68 "write list", /* some result via rdma write */
69 "reply chunk" /* entire reply via rdma write */
70 };
71
72 /* Returns size of largest RPC-over-RDMA header in a Call message
73 *
74 * The largest Call header contains a full-size Read list and a
75 * minimal Reply chunk.
76 */
77 static unsigned int rpcrdma_max_call_header_size(unsigned int maxsegs)
78 {
79 unsigned int size;
80
81 /* Fixed header fields and list discriminators */
82 size = RPCRDMA_HDRLEN_MIN;
83
84 /* Maximum Read list size */
85 maxsegs += 2; /* segment for head and tail buffers */
86 size = maxsegs * sizeof(struct rpcrdma_read_chunk);
87
88 /* Minimal Read chunk size */
89 size += sizeof(__be32); /* segment count */
90 size += sizeof(struct rpcrdma_segment);
91 size += sizeof(__be32); /* list discriminator */
92
93 dprintk("RPC: %s: max call header size = %u\n",
94 __func__, size);
95 return size;
96 }
97
98 /* Returns size of largest RPC-over-RDMA header in a Reply message
99 *
100 * There is only one Write list or one Reply chunk per Reply
101 * message. The larger list is the Write list.
102 */
103 static unsigned int rpcrdma_max_reply_header_size(unsigned int maxsegs)
104 {
105 unsigned int size;
106
107 /* Fixed header fields and list discriminators */
108 size = RPCRDMA_HDRLEN_MIN;
109
110 /* Maximum Write list size */
111 maxsegs += 2; /* segment for head and tail buffers */
112 size = sizeof(__be32); /* segment count */
113 size += maxsegs * sizeof(struct rpcrdma_segment);
114 size += sizeof(__be32); /* list discriminator */
115
116 dprintk("RPC: %s: max reply header size = %u\n",
117 __func__, size);
118 return size;
119 }
120
121 void rpcrdma_set_max_header_sizes(struct rpcrdma_ia *ia,
122 struct rpcrdma_create_data_internal *cdata,
123 unsigned int maxsegs)
124 {
125 ia->ri_max_inline_write = cdata->inline_wsize -
126 rpcrdma_max_call_header_size(maxsegs);
127 ia->ri_max_inline_read = cdata->inline_rsize -
128 rpcrdma_max_reply_header_size(maxsegs);
129 }
130
131 /* The client can send a request inline as long as the RPCRDMA header
132 * plus the RPC call fit under the transport's inline limit. If the
133 * combined call message size exceeds that limit, the client must use
134 * the read chunk list for this operation.
135 */
136 static bool rpcrdma_args_inline(struct rpcrdma_xprt *r_xprt,
137 struct rpc_rqst *rqst)
138 {
139 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
140
141 return rqst->rq_snd_buf.len <= ia->ri_max_inline_write;
142 }
143
144 /* The client can't know how large the actual reply will be. Thus it
145 * plans for the largest possible reply for that particular ULP
146 * operation. If the maximum combined reply message size exceeds that
147 * limit, the client must provide a write list or a reply chunk for
148 * this request.
149 */
150 static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,
151 struct rpc_rqst *rqst)
152 {
153 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
154
155 return rqst->rq_rcv_buf.buflen <= ia->ri_max_inline_read;
156 }
157
158 static int
159 rpcrdma_tail_pullup(struct xdr_buf *buf)
160 {
161 size_t tlen = buf->tail[0].iov_len;
162 size_t skip = tlen & 3;
163
164 /* Do not include the tail if it is only an XDR pad */
165 if (tlen < 4)
166 return 0;
167
168 /* xdr_write_pages() adds a pad at the beginning of the tail
169 * if the content in "buf->pages" is unaligned. Force the
170 * tail's actual content to land at the next XDR position
171 * after the head instead.
172 */
173 if (skip) {
174 unsigned char *src, *dst;
175 unsigned int count;
176
177 src = buf->tail[0].iov_base;
178 dst = buf->head[0].iov_base;
179 dst += buf->head[0].iov_len;
180
181 src += skip;
182 tlen -= skip;
183
184 dprintk("RPC: %s: skip=%zu, memmove(%p, %p, %zu)\n",
185 __func__, skip, dst, src, tlen);
186
187 for (count = tlen; count; count--)
188 *dst++ = *src++;
189 }
190
191 return tlen;
192 }
193
194 /* Split "vec" on page boundaries into segments. FMR registers pages,
195 * not a byte range. Other modes coalesce these segments into a single
196 * MR when they can.
197 */
198 static int
199 rpcrdma_convert_kvec(struct kvec *vec, struct rpcrdma_mr_seg *seg,
200 int n, int nsegs)
201 {
202 size_t page_offset;
203 u32 remaining;
204 char *base;
205
206 base = vec->iov_base;
207 page_offset = offset_in_page(base);
208 remaining = vec->iov_len;
209 while (remaining && n < nsegs) {
210 seg[n].mr_page = NULL;
211 seg[n].mr_offset = base;
212 seg[n].mr_len = min_t(u32, PAGE_SIZE - page_offset, remaining);
213 remaining -= seg[n].mr_len;
214 base += seg[n].mr_len;
215 ++n;
216 page_offset = 0;
217 }
218 return n;
219 }
220
221 /*
222 * Chunk assembly from upper layer xdr_buf.
223 *
224 * Prepare the passed-in xdr_buf into representation as RPC/RDMA chunk
225 * elements. Segments are then coalesced when registered, if possible
226 * within the selected memreg mode.
227 *
228 * Returns positive number of segments converted, or a negative errno.
229 */
230
231 static int
232 rpcrdma_convert_iovs(struct xdr_buf *xdrbuf, unsigned int pos,
233 enum rpcrdma_chunktype type, struct rpcrdma_mr_seg *seg, int nsegs)
234 {
235 int len, n = 0, p;
236 int page_base;
237 struct page **ppages;
238
239 if (pos == 0) {
240 n = rpcrdma_convert_kvec(&xdrbuf->head[0], seg, n, nsegs);
241 if (n == nsegs)
242 return -EIO;
243 }
244
245 len = xdrbuf->page_len;
246 ppages = xdrbuf->pages + (xdrbuf->page_base >> PAGE_SHIFT);
247 page_base = xdrbuf->page_base & ~PAGE_MASK;
248 p = 0;
249 while (len && n < nsegs) {
250 if (!ppages[p]) {
251 /* alloc the pagelist for receiving buffer */
252 ppages[p] = alloc_page(GFP_ATOMIC);
253 if (!ppages[p])
254 return -ENOMEM;
255 }
256 seg[n].mr_page = ppages[p];
257 seg[n].mr_offset = (void *)(unsigned long) page_base;
258 seg[n].mr_len = min_t(u32, PAGE_SIZE - page_base, len);
259 if (seg[n].mr_len > PAGE_SIZE)
260 return -EIO;
261 len -= seg[n].mr_len;
262 ++n;
263 ++p;
264 page_base = 0; /* page offset only applies to first page */
265 }
266
267 /* Message overflows the seg array */
268 if (len && n == nsegs)
269 return -EIO;
270
271 /* When encoding the read list, the tail is always sent inline */
272 if (type == rpcrdma_readch)
273 return n;
274
275 if (xdrbuf->tail[0].iov_len) {
276 /* the rpcrdma protocol allows us to omit any trailing
277 * xdr pad bytes, saving the server an RDMA operation. */
278 if (xdrbuf->tail[0].iov_len < 4 && xprt_rdma_pad_optimize)
279 return n;
280 n = rpcrdma_convert_kvec(&xdrbuf->tail[0], seg, n, nsegs);
281 if (n == nsegs)
282 return -EIO;
283 }
284
285 return n;
286 }
287
288 /*
289 * Create read/write chunk lists, and reply chunks, for RDMA
290 *
291 * Assume check against THRESHOLD has been done, and chunks are required.
292 * Assume only encoding one list entry for read|write chunks. The NFSv3
293 * protocol is simple enough to allow this as it only has a single "bulk
294 * result" in each procedure - complicated NFSv4 COMPOUNDs are not. (The
295 * RDMA/Sessions NFSv4 proposal addresses this for future v4 revs.)
296 *
297 * When used for a single reply chunk (which is a special write
298 * chunk used for the entire reply, rather than just the data), it
299 * is used primarily for READDIR and READLINK which would otherwise
300 * be severely size-limited by a small rdma inline read max. The server
301 * response will come back as an RDMA Write, followed by a message
302 * of type RDMA_NOMSG carrying the xid and length. As a result, reply
303 * chunks do not provide data alignment, however they do not require
304 * "fixup" (moving the response to the upper layer buffer) either.
305 *
306 * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
307 *
308 * Read chunklist (a linked list):
309 * N elements, position P (same P for all chunks of same arg!):
310 * 1 - PHLOO - 1 - PHLOO - ... - 1 - PHLOO - 0
311 *
312 * Write chunklist (a list of (one) counted array):
313 * N elements:
314 * 1 - N - HLOO - HLOO - ... - HLOO - 0
315 *
316 * Reply chunk (a counted array):
317 * N elements:
318 * 1 - N - HLOO - HLOO - ... - HLOO
319 *
320 * Returns positive RPC/RDMA header size, or negative errno.
321 */
322
323 static ssize_t
324 rpcrdma_create_chunks(struct rpc_rqst *rqst, struct xdr_buf *target,
325 struct rpcrdma_msg *headerp, enum rpcrdma_chunktype type)
326 {
327 struct rpcrdma_req *req = rpcr_to_rdmar(rqst);
328 struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(rqst->rq_xprt);
329 int n, nsegs, nchunks = 0;
330 unsigned int pos;
331 struct rpcrdma_mr_seg *seg = req->rl_segments;
332 struct rpcrdma_read_chunk *cur_rchunk = NULL;
333 struct rpcrdma_write_array *warray = NULL;
334 struct rpcrdma_write_chunk *cur_wchunk = NULL;
335 __be32 *iptr = headerp->rm_body.rm_chunks;
336 int (*map)(struct rpcrdma_xprt *, struct rpcrdma_mr_seg *, int, bool);
337
338 if (type == rpcrdma_readch || type == rpcrdma_areadch) {
339 /* a read chunk - server will RDMA Read our memory */
340 cur_rchunk = (struct rpcrdma_read_chunk *) iptr;
341 } else {
342 /* a write or reply chunk - server will RDMA Write our memory */
343 *iptr++ = xdr_zero; /* encode a NULL read chunk list */
344 if (type == rpcrdma_replych)
345 *iptr++ = xdr_zero; /* a NULL write chunk list */
346 warray = (struct rpcrdma_write_array *) iptr;
347 cur_wchunk = (struct rpcrdma_write_chunk *) (warray + 1);
348 }
349
350 if (type == rpcrdma_replych || type == rpcrdma_areadch)
351 pos = 0;
352 else
353 pos = target->head[0].iov_len;
354
355 nsegs = rpcrdma_convert_iovs(target, pos, type, seg, RPCRDMA_MAX_SEGS);
356 if (nsegs < 0)
357 return nsegs;
358
359 map = r_xprt->rx_ia.ri_ops->ro_map;
360 do {
361 n = map(r_xprt, seg, nsegs, cur_wchunk != NULL);
362 if (n <= 0)
363 goto out;
364 if (cur_rchunk) { /* read */
365 cur_rchunk->rc_discrim = xdr_one;
366 /* all read chunks have the same "position" */
367 cur_rchunk->rc_position = cpu_to_be32(pos);
368 cur_rchunk->rc_target.rs_handle =
369 cpu_to_be32(seg->mr_rkey);
370 cur_rchunk->rc_target.rs_length =
371 cpu_to_be32(seg->mr_len);
372 xdr_encode_hyper(
373 (__be32 *)&cur_rchunk->rc_target.rs_offset,
374 seg->mr_base);
375 dprintk("RPC: %s: read chunk "
376 "elem %d@0x%llx:0x%x pos %u (%s)\n", __func__,
377 seg->mr_len, (unsigned long long)seg->mr_base,
378 seg->mr_rkey, pos, n < nsegs ? "more" : "last");
379 cur_rchunk++;
380 r_xprt->rx_stats.read_chunk_count++;
381 } else { /* write/reply */
382 cur_wchunk->wc_target.rs_handle =
383 cpu_to_be32(seg->mr_rkey);
384 cur_wchunk->wc_target.rs_length =
385 cpu_to_be32(seg->mr_len);
386 xdr_encode_hyper(
387 (__be32 *)&cur_wchunk->wc_target.rs_offset,
388 seg->mr_base);
389 dprintk("RPC: %s: %s chunk "
390 "elem %d@0x%llx:0x%x (%s)\n", __func__,
391 (type == rpcrdma_replych) ? "reply" : "write",
392 seg->mr_len, (unsigned long long)seg->mr_base,
393 seg->mr_rkey, n < nsegs ? "more" : "last");
394 cur_wchunk++;
395 if (type == rpcrdma_replych)
396 r_xprt->rx_stats.reply_chunk_count++;
397 else
398 r_xprt->rx_stats.write_chunk_count++;
399 r_xprt->rx_stats.total_rdma_request += seg->mr_len;
400 }
401 nchunks++;
402 seg += n;
403 nsegs -= n;
404 } while (nsegs);
405
406 /* success. all failures return above */
407 req->rl_nchunks = nchunks;
408
409 /*
410 * finish off header. If write, marshal discrim and nchunks.
411 */
412 if (cur_rchunk) {
413 iptr = (__be32 *) cur_rchunk;
414 *iptr++ = xdr_zero; /* finish the read chunk list */
415 *iptr++ = xdr_zero; /* encode a NULL write chunk list */
416 *iptr++ = xdr_zero; /* encode a NULL reply chunk */
417 } else {
418 warray->wc_discrim = xdr_one;
419 warray->wc_nchunks = cpu_to_be32(nchunks);
420 iptr = (__be32 *) cur_wchunk;
421 if (type == rpcrdma_writech) {
422 *iptr++ = xdr_zero; /* finish the write chunk list */
423 *iptr++ = xdr_zero; /* encode a NULL reply chunk */
424 }
425 }
426
427 /*
428 * Return header size.
429 */
430 return (unsigned char *)iptr - (unsigned char *)headerp;
431
432 out:
433 for (pos = 0; nchunks--;)
434 pos += r_xprt->rx_ia.ri_ops->ro_unmap(r_xprt,
435 &req->rl_segments[pos]);
436 return n;
437 }
438
439 static inline __be32 *
440 xdr_encode_rdma_segment(__be32 *iptr, struct rpcrdma_mr_seg *seg)
441 {
442 *iptr++ = cpu_to_be32(seg->mr_rkey);
443 *iptr++ = cpu_to_be32(seg->mr_len);
444 return xdr_encode_hyper(iptr, seg->mr_base);
445 }
446
447 /* XDR-encode the Read list. Supports encoding a list of read
448 * segments that belong to a single read chunk.
449 *
450 * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
451 *
452 * Read chunklist (a linked list):
453 * N elements, position P (same P for all chunks of same arg!):
454 * 1 - PHLOO - 1 - PHLOO - ... - 1 - PHLOO - 0
455 *
456 * Returns a pointer to the XDR word in the RDMA header following
457 * the end of the Read list, or an error pointer.
458 */
459 static __be32 *
460 rpcrdma_encode_read_list(struct rpcrdma_xprt *r_xprt,
461 struct rpcrdma_req *req, struct rpc_rqst *rqst,
462 __be32 *iptr, enum rpcrdma_chunktype rtype)
463 {
464 struct rpcrdma_mr_seg *seg = req->rl_nextseg;
465 unsigned int pos;
466 int n, nsegs;
467
468 if (rtype == rpcrdma_noch) {
469 *iptr++ = xdr_zero; /* item not present */
470 return iptr;
471 }
472
473 pos = rqst->rq_snd_buf.head[0].iov_len;
474 if (rtype == rpcrdma_areadch)
475 pos = 0;
476 nsegs = rpcrdma_convert_iovs(&rqst->rq_snd_buf, pos, rtype, seg,
477 RPCRDMA_MAX_SEGS - req->rl_nchunks);
478 if (nsegs < 0)
479 return ERR_PTR(nsegs);
480
481 do {
482 n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs, false);
483 if (n <= 0)
484 return ERR_PTR(n);
485
486 *iptr++ = xdr_one; /* item present */
487
488 /* All read segments in this chunk
489 * have the same "position".
490 */
491 *iptr++ = cpu_to_be32(pos);
492 iptr = xdr_encode_rdma_segment(iptr, seg);
493
494 dprintk("RPC: %5u %s: read segment pos %u "
495 "%d@0x%016llx:0x%08x (%s)\n",
496 rqst->rq_task->tk_pid, __func__, pos,
497 seg->mr_len, (unsigned long long)seg->mr_base,
498 seg->mr_rkey, n < nsegs ? "more" : "last");
499
500 r_xprt->rx_stats.read_chunk_count++;
501 req->rl_nchunks++;
502 seg += n;
503 nsegs -= n;
504 } while (nsegs);
505 req->rl_nextseg = seg;
506
507 /* Finish Read list */
508 *iptr++ = xdr_zero; /* Next item not present */
509 return iptr;
510 }
511
512 /* XDR-encode the Write list. Supports encoding a list containing
513 * one array of plain segments that belong to a single write chunk.
514 *
515 * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
516 *
517 * Write chunklist (a list of (one) counted array):
518 * N elements:
519 * 1 - N - HLOO - HLOO - ... - HLOO - 0
520 *
521 * Returns a pointer to the XDR word in the RDMA header following
522 * the end of the Write list, or an error pointer.
523 */
524 static __be32 *
525 rpcrdma_encode_write_list(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
526 struct rpc_rqst *rqst, __be32 *iptr,
527 enum rpcrdma_chunktype wtype)
528 {
529 struct rpcrdma_mr_seg *seg = req->rl_nextseg;
530 int n, nsegs, nchunks;
531 __be32 *segcount;
532
533 if (wtype != rpcrdma_writech) {
534 *iptr++ = xdr_zero; /* no Write list present */
535 return iptr;
536 }
537
538 nsegs = rpcrdma_convert_iovs(&rqst->rq_rcv_buf,
539 rqst->rq_rcv_buf.head[0].iov_len,
540 wtype, seg,
541 RPCRDMA_MAX_SEGS - req->rl_nchunks);
542 if (nsegs < 0)
543 return ERR_PTR(nsegs);
544
545 *iptr++ = xdr_one; /* Write list present */
546 segcount = iptr++; /* save location of segment count */
547
548 nchunks = 0;
549 do {
550 n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs, true);
551 if (n <= 0)
552 return ERR_PTR(n);
553
554 iptr = xdr_encode_rdma_segment(iptr, seg);
555
556 dprintk("RPC: %5u %s: write segment "
557 "%d@0x016%llx:0x%08x (%s)\n",
558 rqst->rq_task->tk_pid, __func__,
559 seg->mr_len, (unsigned long long)seg->mr_base,
560 seg->mr_rkey, n < nsegs ? "more" : "last");
561
562 r_xprt->rx_stats.write_chunk_count++;
563 r_xprt->rx_stats.total_rdma_request += seg->mr_len;
564 req->rl_nchunks++;
565 nchunks++;
566 seg += n;
567 nsegs -= n;
568 } while (nsegs);
569 req->rl_nextseg = seg;
570
571 /* Update count of segments in this Write chunk */
572 *segcount = cpu_to_be32(nchunks);
573
574 /* Finish Write list */
575 *iptr++ = xdr_zero; /* Next item not present */
576 return iptr;
577 }
578
579 /* XDR-encode the Reply chunk. Supports encoding an array of plain
580 * segments that belong to a single write (reply) chunk.
581 *
582 * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
583 *
584 * Reply chunk (a counted array):
585 * N elements:
586 * 1 - N - HLOO - HLOO - ... - HLOO
587 *
588 * Returns a pointer to the XDR word in the RDMA header following
589 * the end of the Reply chunk, or an error pointer.
590 */
591 static __be32 *
592 rpcrdma_encode_reply_chunk(struct rpcrdma_xprt *r_xprt,
593 struct rpcrdma_req *req, struct rpc_rqst *rqst,
594 __be32 *iptr, enum rpcrdma_chunktype wtype)
595 {
596 struct rpcrdma_mr_seg *seg = req->rl_nextseg;
597 int n, nsegs, nchunks;
598 __be32 *segcount;
599
600 if (wtype != rpcrdma_replych) {
601 *iptr++ = xdr_zero; /* no Reply chunk present */
602 return iptr;
603 }
604
605 nsegs = rpcrdma_convert_iovs(&rqst->rq_rcv_buf, 0, wtype, seg,
606 RPCRDMA_MAX_SEGS - req->rl_nchunks);
607 if (nsegs < 0)
608 return ERR_PTR(nsegs);
609
610 *iptr++ = xdr_one; /* Reply chunk present */
611 segcount = iptr++; /* save location of segment count */
612
613 nchunks = 0;
614 do {
615 n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs, true);
616 if (n <= 0)
617 return ERR_PTR(n);
618
619 iptr = xdr_encode_rdma_segment(iptr, seg);
620
621 dprintk("RPC: %5u %s: reply segment "
622 "%d@0x%016llx:0x%08x (%s)\n",
623 rqst->rq_task->tk_pid, __func__,
624 seg->mr_len, (unsigned long long)seg->mr_base,
625 seg->mr_rkey, n < nsegs ? "more" : "last");
626
627 r_xprt->rx_stats.reply_chunk_count++;
628 r_xprt->rx_stats.total_rdma_request += seg->mr_len;
629 req->rl_nchunks++;
630 nchunks++;
631 seg += n;
632 nsegs -= n;
633 } while (nsegs);
634 req->rl_nextseg = seg;
635
636 /* Update count of segments in the Reply chunk */
637 *segcount = cpu_to_be32(nchunks);
638
639 return iptr;
640 }
641
642 /*
643 * Copy write data inline.
644 * This function is used for "small" requests. Data which is passed
645 * to RPC via iovecs (or page list) is copied directly into the
646 * pre-registered memory buffer for this request. For small amounts
647 * of data, this is efficient. The cutoff value is tunable.
648 */
649 static void rpcrdma_inline_pullup(struct rpc_rqst *rqst)
650 {
651 int i, npages, curlen;
652 int copy_len;
653 unsigned char *srcp, *destp;
654 struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(rqst->rq_xprt);
655 int page_base;
656 struct page **ppages;
657
658 destp = rqst->rq_svec[0].iov_base;
659 curlen = rqst->rq_svec[0].iov_len;
660 destp += curlen;
661
662 dprintk("RPC: %s: destp 0x%p len %d hdrlen %d\n",
663 __func__, destp, rqst->rq_slen, curlen);
664
665 copy_len = rqst->rq_snd_buf.page_len;
666
667 if (rqst->rq_snd_buf.tail[0].iov_len) {
668 curlen = rqst->rq_snd_buf.tail[0].iov_len;
669 if (destp + copy_len != rqst->rq_snd_buf.tail[0].iov_base) {
670 memmove(destp + copy_len,
671 rqst->rq_snd_buf.tail[0].iov_base, curlen);
672 r_xprt->rx_stats.pullup_copy_count += curlen;
673 }
674 dprintk("RPC: %s: tail destp 0x%p len %d\n",
675 __func__, destp + copy_len, curlen);
676 rqst->rq_svec[0].iov_len += curlen;
677 }
678 r_xprt->rx_stats.pullup_copy_count += copy_len;
679
680 page_base = rqst->rq_snd_buf.page_base;
681 ppages = rqst->rq_snd_buf.pages + (page_base >> PAGE_SHIFT);
682 page_base &= ~PAGE_MASK;
683 npages = PAGE_ALIGN(page_base+copy_len) >> PAGE_SHIFT;
684 for (i = 0; copy_len && i < npages; i++) {
685 curlen = PAGE_SIZE - page_base;
686 if (curlen > copy_len)
687 curlen = copy_len;
688 dprintk("RPC: %s: page %d destp 0x%p len %d curlen %d\n",
689 __func__, i, destp, copy_len, curlen);
690 srcp = kmap_atomic(ppages[i]);
691 memcpy(destp, srcp+page_base, curlen);
692 kunmap_atomic(srcp);
693 rqst->rq_svec[0].iov_len += curlen;
694 destp += curlen;
695 copy_len -= curlen;
696 page_base = 0;
697 }
698 /* header now contains entire send message */
699 }
700
701 /*
702 * Marshal a request: the primary job of this routine is to choose
703 * the transfer modes. See comments below.
704 *
705 * Prepares up to two IOVs per Call message:
706 *
707 * [0] -- RPC RDMA header
708 * [1] -- the RPC header/data
709 *
710 * Returns zero on success, otherwise a negative errno.
711 */
712
713 int
714 rpcrdma_marshal_req(struct rpc_rqst *rqst)
715 {
716 struct rpc_xprt *xprt = rqst->rq_xprt;
717 struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
718 struct rpcrdma_req *req = rpcr_to_rdmar(rqst);
719 enum rpcrdma_chunktype rtype, wtype;
720 struct rpcrdma_msg *headerp;
721 unsigned int pos;
722 ssize_t hdrlen;
723 size_t rpclen;
724 __be32 *iptr;
725
726 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
727 if (test_bit(RPC_BC_PA_IN_USE, &rqst->rq_bc_pa_state))
728 return rpcrdma_bc_marshal_reply(rqst);
729 #endif
730
731 headerp = rdmab_to_msg(req->rl_rdmabuf);
732 /* don't byte-swap XID, it's already done in request */
733 headerp->rm_xid = rqst->rq_xid;
734 headerp->rm_vers = rpcrdma_version;
735 headerp->rm_credit = cpu_to_be32(r_xprt->rx_buf.rb_max_requests);
736 headerp->rm_type = rdma_msg;
737
738 /*
739 * Chunks needed for results?
740 *
741 * o If the expected result is under the inline threshold, all ops
742 * return as inline.
743 * o Large read ops return data as write chunk(s), header as
744 * inline.
745 * o Large non-read ops return as a single reply chunk.
746 */
747 if (rpcrdma_results_inline(r_xprt, rqst))
748 wtype = rpcrdma_noch;
749 else if (rqst->rq_rcv_buf.flags & XDRBUF_READ)
750 wtype = rpcrdma_writech;
751 else
752 wtype = rpcrdma_replych;
753
754 /*
755 * Chunks needed for arguments?
756 *
757 * o If the total request is under the inline threshold, all ops
758 * are sent as inline.
759 * o Large write ops transmit data as read chunk(s), header as
760 * inline.
761 * o Large non-write ops are sent with the entire message as a
762 * single read chunk (protocol 0-position special case).
763 *
764 * This assumes that the upper layer does not present a request
765 * that both has a data payload, and whose non-data arguments
766 * by themselves are larger than the inline threshold.
767 */
768 if (rpcrdma_args_inline(r_xprt, rqst)) {
769 rtype = rpcrdma_noch;
770 rpcrdma_inline_pullup(rqst);
771 rpclen = rqst->rq_svec[0].iov_len;
772 } else if (rqst->rq_snd_buf.flags & XDRBUF_WRITE) {
773 rtype = rpcrdma_readch;
774 rpclen = rqst->rq_svec[0].iov_len;
775 rpclen += rpcrdma_tail_pullup(&rqst->rq_snd_buf);
776 } else {
777 r_xprt->rx_stats.nomsg_call_count++;
778 headerp->rm_type = htonl(RDMA_NOMSG);
779 rtype = rpcrdma_areadch;
780 rpclen = 0;
781 }
782
783 /* This implementation supports the following combinations
784 * of chunk lists in one RPC-over-RDMA Call message:
785 *
786 * - Read list
787 * - Write list
788 * - Reply chunk
789 * - Read list + Reply chunk
790 *
791 * It might not yet support the following combinations:
792 *
793 * - Read list + Write list
794 *
795 * It does not support the following combinations:
796 *
797 * - Write list + Reply chunk
798 * - Read list + Write list + Reply chunk
799 *
800 * This implementation supports only a single chunk in each
801 * Read or Write list. Thus for example the client cannot
802 * send a Call message with a Position Zero Read chunk and a
803 * regular Read chunk at the same time.
804 */
805 req->rl_nchunks = 0;
806 req->rl_nextseg = req->rl_segments;
807 iptr = headerp->rm_body.rm_chunks;
808 iptr = rpcrdma_encode_read_list(r_xprt, req, rqst, iptr, rtype);
809 if (IS_ERR(iptr))
810 goto out_unmap;
811 iptr = rpcrdma_encode_write_list(r_xprt, req, rqst, iptr, wtype);
812 if (IS_ERR(iptr))
813 goto out_unmap;
814 iptr = rpcrdma_encode_reply_chunk(r_xprt, req, rqst, iptr, wtype);
815 if (IS_ERR(iptr))
816 goto out_unmap;
817 hdrlen = (unsigned char *)iptr - (unsigned char *)headerp;
818
819 if (hdrlen + rpclen > RPCRDMA_INLINE_WRITE_THRESHOLD(rqst))
820 goto out_overflow;
821
822 dprintk("RPC: %5u %s: %s/%s: hdrlen %zd rpclen %zd\n",
823 rqst->rq_task->tk_pid, __func__,
824 transfertypes[rtype], transfertypes[wtype],
825 hdrlen, rpclen);
826
827 req->rl_send_iov[0].addr = rdmab_addr(req->rl_rdmabuf);
828 req->rl_send_iov[0].length = hdrlen;
829 req->rl_send_iov[0].lkey = rdmab_lkey(req->rl_rdmabuf);
830
831 req->rl_niovs = 1;
832 if (rtype == rpcrdma_areadch)
833 return 0;
834
835 req->rl_send_iov[1].addr = rdmab_addr(req->rl_sendbuf);
836 req->rl_send_iov[1].length = rpclen;
837 req->rl_send_iov[1].lkey = rdmab_lkey(req->rl_sendbuf);
838
839 req->rl_niovs = 2;
840 return 0;
841
842 out_overflow:
843 pr_err("rpcrdma: send overflow: hdrlen %zd rpclen %zu %s/%s\n",
844 hdrlen, rpclen, transfertypes[rtype], transfertypes[wtype]);
845 /* Terminate this RPC. Chunks registered above will be
846 * released by xprt_release -> xprt_rmda_free .
847 */
848 return -EIO;
849
850 out_unmap:
851 for (pos = 0; req->rl_nchunks--;)
852 pos += r_xprt->rx_ia.ri_ops->ro_unmap(r_xprt,
853 &req->rl_segments[pos]);
854 return PTR_ERR(iptr);
855 }
856
857 /*
858 * Chase down a received write or reply chunklist to get length
859 * RDMA'd by server. See map at rpcrdma_create_chunks()! :-)
860 */
861 static int
862 rpcrdma_count_chunks(struct rpcrdma_rep *rep, unsigned int max, int wrchunk, __be32 **iptrp)
863 {
864 unsigned int i, total_len;
865 struct rpcrdma_write_chunk *cur_wchunk;
866 char *base = (char *)rdmab_to_msg(rep->rr_rdmabuf);
867
868 i = be32_to_cpu(**iptrp);
869 if (i > max)
870 return -1;
871 cur_wchunk = (struct rpcrdma_write_chunk *) (*iptrp + 1);
872 total_len = 0;
873 while (i--) {
874 struct rpcrdma_segment *seg = &cur_wchunk->wc_target;
875 ifdebug(FACILITY) {
876 u64 off;
877 xdr_decode_hyper((__be32 *)&seg->rs_offset, &off);
878 dprintk("RPC: %s: chunk %d@0x%llx:0x%x\n",
879 __func__,
880 be32_to_cpu(seg->rs_length),
881 (unsigned long long)off,
882 be32_to_cpu(seg->rs_handle));
883 }
884 total_len += be32_to_cpu(seg->rs_length);
885 ++cur_wchunk;
886 }
887 /* check and adjust for properly terminated write chunk */
888 if (wrchunk) {
889 __be32 *w = (__be32 *) cur_wchunk;
890 if (*w++ != xdr_zero)
891 return -1;
892 cur_wchunk = (struct rpcrdma_write_chunk *) w;
893 }
894 if ((char *)cur_wchunk > base + rep->rr_len)
895 return -1;
896
897 *iptrp = (__be32 *) cur_wchunk;
898 return total_len;
899 }
900
901 /*
902 * Scatter inline received data back into provided iov's.
903 */
904 static void
905 rpcrdma_inline_fixup(struct rpc_rqst *rqst, char *srcp, int copy_len, int pad)
906 {
907 int i, npages, curlen, olen;
908 char *destp;
909 struct page **ppages;
910 int page_base;
911
912 curlen = rqst->rq_rcv_buf.head[0].iov_len;
913 if (curlen > copy_len) { /* write chunk header fixup */
914 curlen = copy_len;
915 rqst->rq_rcv_buf.head[0].iov_len = curlen;
916 }
917
918 dprintk("RPC: %s: srcp 0x%p len %d hdrlen %d\n",
919 __func__, srcp, copy_len, curlen);
920
921 /* Shift pointer for first receive segment only */
922 rqst->rq_rcv_buf.head[0].iov_base = srcp;
923 srcp += curlen;
924 copy_len -= curlen;
925
926 olen = copy_len;
927 i = 0;
928 rpcx_to_rdmax(rqst->rq_xprt)->rx_stats.fixup_copy_count += olen;
929 page_base = rqst->rq_rcv_buf.page_base;
930 ppages = rqst->rq_rcv_buf.pages + (page_base >> PAGE_SHIFT);
931 page_base &= ~PAGE_MASK;
932
933 if (copy_len && rqst->rq_rcv_buf.page_len) {
934 npages = PAGE_ALIGN(page_base +
935 rqst->rq_rcv_buf.page_len) >> PAGE_SHIFT;
936 for (; i < npages; i++) {
937 curlen = PAGE_SIZE - page_base;
938 if (curlen > copy_len)
939 curlen = copy_len;
940 dprintk("RPC: %s: page %d"
941 " srcp 0x%p len %d curlen %d\n",
942 __func__, i, srcp, copy_len, curlen);
943 destp = kmap_atomic(ppages[i]);
944 memcpy(destp + page_base, srcp, curlen);
945 flush_dcache_page(ppages[i]);
946 kunmap_atomic(destp);
947 srcp += curlen;
948 copy_len -= curlen;
949 if (copy_len == 0)
950 break;
951 page_base = 0;
952 }
953 }
954
955 if (copy_len && rqst->rq_rcv_buf.tail[0].iov_len) {
956 curlen = copy_len;
957 if (curlen > rqst->rq_rcv_buf.tail[0].iov_len)
958 curlen = rqst->rq_rcv_buf.tail[0].iov_len;
959 if (rqst->rq_rcv_buf.tail[0].iov_base != srcp)
960 memmove(rqst->rq_rcv_buf.tail[0].iov_base, srcp, curlen);
961 dprintk("RPC: %s: tail srcp 0x%p len %d curlen %d\n",
962 __func__, srcp, copy_len, curlen);
963 rqst->rq_rcv_buf.tail[0].iov_len = curlen;
964 copy_len -= curlen; ++i;
965 } else
966 rqst->rq_rcv_buf.tail[0].iov_len = 0;
967
968 if (pad) {
969 /* implicit padding on terminal chunk */
970 unsigned char *p = rqst->rq_rcv_buf.tail[0].iov_base;
971 while (pad--)
972 p[rqst->rq_rcv_buf.tail[0].iov_len++] = 0;
973 }
974
975 if (copy_len)
976 dprintk("RPC: %s: %d bytes in"
977 " %d extra segments (%d lost)\n",
978 __func__, olen, i, copy_len);
979
980 /* TBD avoid a warning from call_decode() */
981 rqst->rq_private_buf = rqst->rq_rcv_buf;
982 }
983
984 void
985 rpcrdma_connect_worker(struct work_struct *work)
986 {
987 struct rpcrdma_ep *ep =
988 container_of(work, struct rpcrdma_ep, rep_connect_worker.work);
989 struct rpcrdma_xprt *r_xprt =
990 container_of(ep, struct rpcrdma_xprt, rx_ep);
991 struct rpc_xprt *xprt = &r_xprt->rx_xprt;
992
993 spin_lock_bh(&xprt->transport_lock);
994 if (++xprt->connect_cookie == 0) /* maintain a reserved value */
995 ++xprt->connect_cookie;
996 if (ep->rep_connected > 0) {
997 if (!xprt_test_and_set_connected(xprt))
998 xprt_wake_pending_tasks(xprt, 0);
999 } else {
1000 if (xprt_test_and_clear_connected(xprt))
1001 xprt_wake_pending_tasks(xprt, -ENOTCONN);
1002 }
1003 spin_unlock_bh(&xprt->transport_lock);
1004 }
1005
1006 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1007 /* By convention, backchannel calls arrive via rdma_msg type
1008 * messages, and never populate the chunk lists. This makes
1009 * the RPC/RDMA header small and fixed in size, so it is
1010 * straightforward to check the RPC header's direction field.
1011 */
1012 static bool
1013 rpcrdma_is_bcall(struct rpcrdma_msg *headerp)
1014 {
1015 __be32 *p = (__be32 *)headerp;
1016
1017 if (headerp->rm_type != rdma_msg)
1018 return false;
1019 if (headerp->rm_body.rm_chunks[0] != xdr_zero)
1020 return false;
1021 if (headerp->rm_body.rm_chunks[1] != xdr_zero)
1022 return false;
1023 if (headerp->rm_body.rm_chunks[2] != xdr_zero)
1024 return false;
1025
1026 /* sanity */
1027 if (p[7] != headerp->rm_xid)
1028 return false;
1029 /* call direction */
1030 if (p[8] != cpu_to_be32(RPC_CALL))
1031 return false;
1032
1033 return true;
1034 }
1035 #endif /* CONFIG_SUNRPC_BACKCHANNEL */
1036
1037 /*
1038 * This function is called when an async event is posted to
1039 * the connection which changes the connection state. All it
1040 * does at this point is mark the connection up/down, the rpc
1041 * timers do the rest.
1042 */
1043 void
1044 rpcrdma_conn_func(struct rpcrdma_ep *ep)
1045 {
1046 schedule_delayed_work(&ep->rep_connect_worker, 0);
1047 }
1048
1049 /* Process received RPC/RDMA messages.
1050 *
1051 * Errors must result in the RPC task either being awakened, or
1052 * allowed to timeout, to discover the errors at that time.
1053 */
1054 void
1055 rpcrdma_reply_handler(struct rpcrdma_rep *rep)
1056 {
1057 struct rpcrdma_msg *headerp;
1058 struct rpcrdma_req *req;
1059 struct rpc_rqst *rqst;
1060 struct rpcrdma_xprt *r_xprt = rep->rr_rxprt;
1061 struct rpc_xprt *xprt = &r_xprt->rx_xprt;
1062 __be32 *iptr;
1063 int rdmalen, status, rmerr;
1064 unsigned long cwnd;
1065
1066 dprintk("RPC: %s: incoming rep %p\n", __func__, rep);
1067
1068 if (rep->rr_len == RPCRDMA_BAD_LEN)
1069 goto out_badstatus;
1070 if (rep->rr_len < RPCRDMA_HDRLEN_ERR)
1071 goto out_shortreply;
1072
1073 headerp = rdmab_to_msg(rep->rr_rdmabuf);
1074 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1075 if (rpcrdma_is_bcall(headerp))
1076 goto out_bcall;
1077 #endif
1078
1079 /* Match incoming rpcrdma_rep to an rpcrdma_req to
1080 * get context for handling any incoming chunks.
1081 */
1082 spin_lock_bh(&xprt->transport_lock);
1083 rqst = xprt_lookup_rqst(xprt, headerp->rm_xid);
1084 if (!rqst)
1085 goto out_nomatch;
1086
1087 req = rpcr_to_rdmar(rqst);
1088 if (req->rl_reply)
1089 goto out_duplicate;
1090
1091 /* Sanity checking has passed. We are now committed
1092 * to complete this transaction.
1093 */
1094 list_del_init(&rqst->rq_list);
1095 spin_unlock_bh(&xprt->transport_lock);
1096 dprintk("RPC: %s: reply %p completes request %p (xid 0x%08x)\n",
1097 __func__, rep, req, be32_to_cpu(headerp->rm_xid));
1098
1099 /* from here on, the reply is no longer an orphan */
1100 req->rl_reply = rep;
1101 xprt->reestablish_timeout = 0;
1102
1103 if (headerp->rm_vers != rpcrdma_version)
1104 goto out_badversion;
1105
1106 /* check for expected message types */
1107 /* The order of some of these tests is important. */
1108 switch (headerp->rm_type) {
1109 case rdma_msg:
1110 /* never expect read chunks */
1111 /* never expect reply chunks (two ways to check) */
1112 /* never expect write chunks without having offered RDMA */
1113 if (headerp->rm_body.rm_chunks[0] != xdr_zero ||
1114 (headerp->rm_body.rm_chunks[1] == xdr_zero &&
1115 headerp->rm_body.rm_chunks[2] != xdr_zero) ||
1116 (headerp->rm_body.rm_chunks[1] != xdr_zero &&
1117 req->rl_nchunks == 0))
1118 goto badheader;
1119 if (headerp->rm_body.rm_chunks[1] != xdr_zero) {
1120 /* count any expected write chunks in read reply */
1121 /* start at write chunk array count */
1122 iptr = &headerp->rm_body.rm_chunks[2];
1123 rdmalen = rpcrdma_count_chunks(rep,
1124 req->rl_nchunks, 1, &iptr);
1125 /* check for validity, and no reply chunk after */
1126 if (rdmalen < 0 || *iptr++ != xdr_zero)
1127 goto badheader;
1128 rep->rr_len -=
1129 ((unsigned char *)iptr - (unsigned char *)headerp);
1130 status = rep->rr_len + rdmalen;
1131 r_xprt->rx_stats.total_rdma_reply += rdmalen;
1132 /* special case - last chunk may omit padding */
1133 if (rdmalen &= 3) {
1134 rdmalen = 4 - rdmalen;
1135 status += rdmalen;
1136 }
1137 } else {
1138 /* else ordinary inline */
1139 rdmalen = 0;
1140 iptr = (__be32 *)((unsigned char *)headerp +
1141 RPCRDMA_HDRLEN_MIN);
1142 rep->rr_len -= RPCRDMA_HDRLEN_MIN;
1143 status = rep->rr_len;
1144 }
1145 /* Fix up the rpc results for upper layer */
1146 rpcrdma_inline_fixup(rqst, (char *)iptr, rep->rr_len, rdmalen);
1147 break;
1148
1149 case rdma_nomsg:
1150 /* never expect read or write chunks, always reply chunks */
1151 if (headerp->rm_body.rm_chunks[0] != xdr_zero ||
1152 headerp->rm_body.rm_chunks[1] != xdr_zero ||
1153 headerp->rm_body.rm_chunks[2] != xdr_one ||
1154 req->rl_nchunks == 0)
1155 goto badheader;
1156 iptr = (__be32 *)((unsigned char *)headerp +
1157 RPCRDMA_HDRLEN_MIN);
1158 rdmalen = rpcrdma_count_chunks(rep, req->rl_nchunks, 0, &iptr);
1159 if (rdmalen < 0)
1160 goto badheader;
1161 r_xprt->rx_stats.total_rdma_reply += rdmalen;
1162 /* Reply chunk buffer already is the reply vector - no fixup. */
1163 status = rdmalen;
1164 break;
1165
1166 case rdma_error:
1167 goto out_rdmaerr;
1168
1169 badheader:
1170 default:
1171 dprintk("%s: invalid rpcrdma reply header (type %d):"
1172 " chunks[012] == %d %d %d"
1173 " expected chunks <= %d\n",
1174 __func__, be32_to_cpu(headerp->rm_type),
1175 headerp->rm_body.rm_chunks[0],
1176 headerp->rm_body.rm_chunks[1],
1177 headerp->rm_body.rm_chunks[2],
1178 req->rl_nchunks);
1179 status = -EIO;
1180 r_xprt->rx_stats.bad_reply_count++;
1181 break;
1182 }
1183
1184 out:
1185 /* Invalidate and flush the data payloads before waking the
1186 * waiting application. This guarantees the memory region is
1187 * properly fenced from the server before the application
1188 * accesses the data. It also ensures proper send flow
1189 * control: waking the next RPC waits until this RPC has
1190 * relinquished all its Send Queue entries.
1191 */
1192 if (req->rl_nchunks)
1193 r_xprt->rx_ia.ri_ops->ro_unmap_sync(r_xprt, req);
1194
1195 spin_lock_bh(&xprt->transport_lock);
1196 cwnd = xprt->cwnd;
1197 xprt->cwnd = atomic_read(&r_xprt->rx_buf.rb_credits) << RPC_CWNDSHIFT;
1198 if (xprt->cwnd > cwnd)
1199 xprt_release_rqst_cong(rqst->rq_task);
1200
1201 xprt_complete_rqst(rqst->rq_task, status);
1202 spin_unlock_bh(&xprt->transport_lock);
1203 dprintk("RPC: %s: xprt_complete_rqst(0x%p, 0x%p, %d)\n",
1204 __func__, xprt, rqst, status);
1205 return;
1206
1207 out_badstatus:
1208 rpcrdma_recv_buffer_put(rep);
1209 if (r_xprt->rx_ep.rep_connected == 1) {
1210 r_xprt->rx_ep.rep_connected = -EIO;
1211 rpcrdma_conn_func(&r_xprt->rx_ep);
1212 }
1213 return;
1214
1215 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
1216 out_bcall:
1217 rpcrdma_bc_receive_call(r_xprt, rep);
1218 return;
1219 #endif
1220
1221 /* If the incoming reply terminated a pending RPC, the next
1222 * RPC call will post a replacement receive buffer as it is
1223 * being marshaled.
1224 */
1225 out_badversion:
1226 dprintk("RPC: %s: invalid version %d\n",
1227 __func__, be32_to_cpu(headerp->rm_vers));
1228 status = -EIO;
1229 r_xprt->rx_stats.bad_reply_count++;
1230 goto out;
1231
1232 out_rdmaerr:
1233 rmerr = be32_to_cpu(headerp->rm_body.rm_error.rm_err);
1234 switch (rmerr) {
1235 case ERR_VERS:
1236 pr_err("%s: server reports header version error (%u-%u)\n",
1237 __func__,
1238 be32_to_cpu(headerp->rm_body.rm_error.rm_vers_low),
1239 be32_to_cpu(headerp->rm_body.rm_error.rm_vers_high));
1240 break;
1241 case ERR_CHUNK:
1242 pr_err("%s: server reports header decoding error\n",
1243 __func__);
1244 break;
1245 default:
1246 pr_err("%s: server reports unknown error %d\n",
1247 __func__, rmerr);
1248 }
1249 status = -EREMOTEIO;
1250 r_xprt->rx_stats.bad_reply_count++;
1251 goto out;
1252
1253 /* If no pending RPC transaction was matched, post a replacement
1254 * receive buffer before returning.
1255 */
1256 out_shortreply:
1257 dprintk("RPC: %s: short/invalid reply\n", __func__);
1258 goto repost;
1259
1260 out_nomatch:
1261 spin_unlock_bh(&xprt->transport_lock);
1262 dprintk("RPC: %s: no match for incoming xid 0x%08x len %d\n",
1263 __func__, be32_to_cpu(headerp->rm_xid),
1264 rep->rr_len);
1265 goto repost;
1266
1267 out_duplicate:
1268 spin_unlock_bh(&xprt->transport_lock);
1269 dprintk("RPC: %s: "
1270 "duplicate reply %p to RPC request %p: xid 0x%08x\n",
1271 __func__, rep, req, be32_to_cpu(headerp->rm_xid));
1272
1273 repost:
1274 r_xprt->rx_stats.bad_reply_count++;
1275 if (rpcrdma_ep_post_recv(&r_xprt->rx_ia, &r_xprt->rx_ep, rep))
1276 rpcrdma_recv_buffer_put(rep);
1277 }
This page took 0.094953 seconds and 4 git commands to generate.