rpc_rdma.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  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. * rpc_rdma.c
  41. *
  42. * This file contains the guts of the RPC RDMA protocol, and
  43. * does marshaling/unmarshaling, etc. It is also where interfacing
  44. * to the Linux RPC framework lives.
  45. */
  46. #include "xprt_rdma.h"
  47. #include <linux/highmem.h>
  48. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  49. # define RPCDBG_FACILITY RPCDBG_TRANS
  50. #endif
  51. static const char transfertypes[][12] = {
  52. "inline", /* no chunks */
  53. "read list", /* some argument via rdma read */
  54. "*read list", /* entire request via rdma read */
  55. "write list", /* some result via rdma write */
  56. "reply chunk" /* entire reply via rdma write */
  57. };
  58. /* Returns size of largest RPC-over-RDMA header in a Call message
  59. *
  60. * The largest Call header contains a full-size Read list and a
  61. * minimal Reply chunk.
  62. */
  63. static unsigned int rpcrdma_max_call_header_size(unsigned int maxsegs)
  64. {
  65. unsigned int size;
  66. /* Fixed header fields and list discriminators */
  67. size = RPCRDMA_HDRLEN_MIN;
  68. /* Maximum Read list size */
  69. maxsegs += 2; /* segment for head and tail buffers */
  70. size = maxsegs * sizeof(struct rpcrdma_read_chunk);
  71. /* Minimal Read chunk size */
  72. size += sizeof(__be32); /* segment count */
  73. size += sizeof(struct rpcrdma_segment);
  74. size += sizeof(__be32); /* list discriminator */
  75. dprintk("RPC: %s: max call header size = %u\n",
  76. __func__, size);
  77. return size;
  78. }
  79. /* Returns size of largest RPC-over-RDMA header in a Reply message
  80. *
  81. * There is only one Write list or one Reply chunk per Reply
  82. * message. The larger list is the Write list.
  83. */
  84. static unsigned int rpcrdma_max_reply_header_size(unsigned int maxsegs)
  85. {
  86. unsigned int size;
  87. /* Fixed header fields and list discriminators */
  88. size = RPCRDMA_HDRLEN_MIN;
  89. /* Maximum Write list size */
  90. maxsegs += 2; /* segment for head and tail buffers */
  91. size = sizeof(__be32); /* segment count */
  92. size += maxsegs * sizeof(struct rpcrdma_segment);
  93. size += sizeof(__be32); /* list discriminator */
  94. dprintk("RPC: %s: max reply header size = %u\n",
  95. __func__, size);
  96. return size;
  97. }
  98. void rpcrdma_set_max_header_sizes(struct rpcrdma_xprt *r_xprt)
  99. {
  100. struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
  101. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  102. unsigned int maxsegs = ia->ri_max_segs;
  103. ia->ri_max_inline_write = cdata->inline_wsize -
  104. rpcrdma_max_call_header_size(maxsegs);
  105. ia->ri_max_inline_read = cdata->inline_rsize -
  106. rpcrdma_max_reply_header_size(maxsegs);
  107. }
  108. /* The client can send a request inline as long as the RPCRDMA header
  109. * plus the RPC call fit under the transport's inline limit. If the
  110. * combined call message size exceeds that limit, the client must use
  111. * a Read chunk for this operation.
  112. *
  113. * A Read chunk is also required if sending the RPC call inline would
  114. * exceed this device's max_sge limit.
  115. */
  116. static bool rpcrdma_args_inline(struct rpcrdma_xprt *r_xprt,
  117. struct rpc_rqst *rqst)
  118. {
  119. struct xdr_buf *xdr = &rqst->rq_snd_buf;
  120. unsigned int count, remaining, offset;
  121. if (xdr->len > r_xprt->rx_ia.ri_max_inline_write)
  122. return false;
  123. if (xdr->page_len) {
  124. remaining = xdr->page_len;
  125. offset = offset_in_page(xdr->page_base);
  126. count = 0;
  127. while (remaining) {
  128. remaining -= min_t(unsigned int,
  129. PAGE_SIZE - offset, remaining);
  130. offset = 0;
  131. if (++count > r_xprt->rx_ia.ri_max_send_sges)
  132. return false;
  133. }
  134. }
  135. return true;
  136. }
  137. /* The client can't know how large the actual reply will be. Thus it
  138. * plans for the largest possible reply for that particular ULP
  139. * operation. If the maximum combined reply message size exceeds that
  140. * limit, the client must provide a write list or a reply chunk for
  141. * this request.
  142. */
  143. static bool rpcrdma_results_inline(struct rpcrdma_xprt *r_xprt,
  144. struct rpc_rqst *rqst)
  145. {
  146. struct rpcrdma_ia *ia = &r_xprt->rx_ia;
  147. return rqst->rq_rcv_buf.buflen <= ia->ri_max_inline_read;
  148. }
  149. /* Split "vec" on page boundaries into segments. FMR registers pages,
  150. * not a byte range. Other modes coalesce these segments into a single
  151. * MR when they can.
  152. */
  153. static int
  154. rpcrdma_convert_kvec(struct kvec *vec, struct rpcrdma_mr_seg *seg, int n)
  155. {
  156. size_t page_offset;
  157. u32 remaining;
  158. char *base;
  159. base = vec->iov_base;
  160. page_offset = offset_in_page(base);
  161. remaining = vec->iov_len;
  162. while (remaining && n < RPCRDMA_MAX_SEGS) {
  163. seg[n].mr_page = NULL;
  164. seg[n].mr_offset = base;
  165. seg[n].mr_len = min_t(u32, PAGE_SIZE - page_offset, remaining);
  166. remaining -= seg[n].mr_len;
  167. base += seg[n].mr_len;
  168. ++n;
  169. page_offset = 0;
  170. }
  171. return n;
  172. }
  173. /*
  174. * Chunk assembly from upper layer xdr_buf.
  175. *
  176. * Prepare the passed-in xdr_buf into representation as RPC/RDMA chunk
  177. * elements. Segments are then coalesced when registered, if possible
  178. * within the selected memreg mode.
  179. *
  180. * Returns positive number of segments converted, or a negative errno.
  181. */
  182. static int
  183. rpcrdma_convert_iovs(struct rpcrdma_xprt *r_xprt, struct xdr_buf *xdrbuf,
  184. unsigned int pos, enum rpcrdma_chunktype type,
  185. struct rpcrdma_mr_seg *seg)
  186. {
  187. int len, n, p, page_base;
  188. struct page **ppages;
  189. n = 0;
  190. if (pos == 0) {
  191. n = rpcrdma_convert_kvec(&xdrbuf->head[0], seg, n);
  192. if (n == RPCRDMA_MAX_SEGS)
  193. goto out_overflow;
  194. }
  195. len = xdrbuf->page_len;
  196. ppages = xdrbuf->pages + (xdrbuf->page_base >> PAGE_SHIFT);
  197. page_base = offset_in_page(xdrbuf->page_base);
  198. p = 0;
  199. while (len && n < RPCRDMA_MAX_SEGS) {
  200. if (!ppages[p]) {
  201. /* alloc the pagelist for receiving buffer */
  202. ppages[p] = alloc_page(GFP_ATOMIC);
  203. if (!ppages[p])
  204. return -EAGAIN;
  205. }
  206. seg[n].mr_page = ppages[p];
  207. seg[n].mr_offset = (void *)(unsigned long) page_base;
  208. seg[n].mr_len = min_t(u32, PAGE_SIZE - page_base, len);
  209. if (seg[n].mr_len > PAGE_SIZE)
  210. goto out_overflow;
  211. len -= seg[n].mr_len;
  212. ++n;
  213. ++p;
  214. page_base = 0; /* page offset only applies to first page */
  215. }
  216. /* Message overflows the seg array */
  217. if (len && n == RPCRDMA_MAX_SEGS)
  218. goto out_overflow;
  219. /* When encoding a Read chunk, the tail iovec contains an
  220. * XDR pad and may be omitted.
  221. */
  222. if (type == rpcrdma_readch && r_xprt->rx_ia.ri_implicit_roundup)
  223. return n;
  224. /* When encoding a Write chunk, some servers need to see an
  225. * extra segment for non-XDR-aligned Write chunks. The upper
  226. * layer provides space in the tail iovec that may be used
  227. * for this purpose.
  228. */
  229. if (type == rpcrdma_writech && r_xprt->rx_ia.ri_implicit_roundup)
  230. return n;
  231. if (xdrbuf->tail[0].iov_len) {
  232. n = rpcrdma_convert_kvec(&xdrbuf->tail[0], seg, n);
  233. if (n == RPCRDMA_MAX_SEGS)
  234. goto out_overflow;
  235. }
  236. return n;
  237. out_overflow:
  238. pr_err("rpcrdma: segment array overflow\n");
  239. return -EIO;
  240. }
  241. static inline __be32 *
  242. xdr_encode_rdma_segment(__be32 *iptr, struct rpcrdma_mw *mw)
  243. {
  244. *iptr++ = cpu_to_be32(mw->mw_handle);
  245. *iptr++ = cpu_to_be32(mw->mw_length);
  246. return xdr_encode_hyper(iptr, mw->mw_offset);
  247. }
  248. /* XDR-encode the Read list. Supports encoding a list of read
  249. * segments that belong to a single read chunk.
  250. *
  251. * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
  252. *
  253. * Read chunklist (a linked list):
  254. * N elements, position P (same P for all chunks of same arg!):
  255. * 1 - PHLOO - 1 - PHLOO - ... - 1 - PHLOO - 0
  256. *
  257. * Returns a pointer to the XDR word in the RDMA header following
  258. * the end of the Read list, or an error pointer.
  259. */
  260. static __be32 *
  261. rpcrdma_encode_read_list(struct rpcrdma_xprt *r_xprt,
  262. struct rpcrdma_req *req, struct rpc_rqst *rqst,
  263. __be32 *iptr, enum rpcrdma_chunktype rtype)
  264. {
  265. struct rpcrdma_mr_seg *seg;
  266. struct rpcrdma_mw *mw;
  267. unsigned int pos;
  268. int n, nsegs;
  269. if (rtype == rpcrdma_noch) {
  270. *iptr++ = xdr_zero; /* item not present */
  271. return iptr;
  272. }
  273. pos = rqst->rq_snd_buf.head[0].iov_len;
  274. if (rtype == rpcrdma_areadch)
  275. pos = 0;
  276. seg = req->rl_segments;
  277. nsegs = rpcrdma_convert_iovs(r_xprt, &rqst->rq_snd_buf, pos,
  278. rtype, seg);
  279. if (nsegs < 0)
  280. return ERR_PTR(nsegs);
  281. do {
  282. n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs,
  283. false, &mw);
  284. if (n < 0)
  285. return ERR_PTR(n);
  286. rpcrdma_push_mw(mw, &req->rl_registered);
  287. *iptr++ = xdr_one; /* item present */
  288. /* All read segments in this chunk
  289. * have the same "position".
  290. */
  291. *iptr++ = cpu_to_be32(pos);
  292. iptr = xdr_encode_rdma_segment(iptr, mw);
  293. dprintk("RPC: %5u %s: pos %u %u@0x%016llx:0x%08x (%s)\n",
  294. rqst->rq_task->tk_pid, __func__, pos,
  295. mw->mw_length, (unsigned long long)mw->mw_offset,
  296. mw->mw_handle, n < nsegs ? "more" : "last");
  297. r_xprt->rx_stats.read_chunk_count++;
  298. seg += n;
  299. nsegs -= n;
  300. } while (nsegs);
  301. /* Finish Read list */
  302. *iptr++ = xdr_zero; /* Next item not present */
  303. return iptr;
  304. }
  305. /* XDR-encode the Write list. Supports encoding a list containing
  306. * one array of plain segments that belong to a single write chunk.
  307. *
  308. * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
  309. *
  310. * Write chunklist (a list of (one) counted array):
  311. * N elements:
  312. * 1 - N - HLOO - HLOO - ... - HLOO - 0
  313. *
  314. * Returns a pointer to the XDR word in the RDMA header following
  315. * the end of the Write list, or an error pointer.
  316. */
  317. static __be32 *
  318. rpcrdma_encode_write_list(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req,
  319. struct rpc_rqst *rqst, __be32 *iptr,
  320. enum rpcrdma_chunktype wtype)
  321. {
  322. struct rpcrdma_mr_seg *seg;
  323. struct rpcrdma_mw *mw;
  324. int n, nsegs, nchunks;
  325. __be32 *segcount;
  326. if (wtype != rpcrdma_writech) {
  327. *iptr++ = xdr_zero; /* no Write list present */
  328. return iptr;
  329. }
  330. seg = req->rl_segments;
  331. nsegs = rpcrdma_convert_iovs(r_xprt, &rqst->rq_rcv_buf,
  332. rqst->rq_rcv_buf.head[0].iov_len,
  333. wtype, seg);
  334. if (nsegs < 0)
  335. return ERR_PTR(nsegs);
  336. *iptr++ = xdr_one; /* Write list present */
  337. segcount = iptr++; /* save location of segment count */
  338. nchunks = 0;
  339. do {
  340. n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs,
  341. true, &mw);
  342. if (n < 0)
  343. return ERR_PTR(n);
  344. rpcrdma_push_mw(mw, &req->rl_registered);
  345. iptr = xdr_encode_rdma_segment(iptr, mw);
  346. dprintk("RPC: %5u %s: %u@0x016%llx:0x%08x (%s)\n",
  347. rqst->rq_task->tk_pid, __func__,
  348. mw->mw_length, (unsigned long long)mw->mw_offset,
  349. mw->mw_handle, n < nsegs ? "more" : "last");
  350. r_xprt->rx_stats.write_chunk_count++;
  351. r_xprt->rx_stats.total_rdma_request += seg->mr_len;
  352. nchunks++;
  353. seg += n;
  354. nsegs -= n;
  355. } while (nsegs);
  356. /* Update count of segments in this Write chunk */
  357. *segcount = cpu_to_be32(nchunks);
  358. /* Finish Write list */
  359. *iptr++ = xdr_zero; /* Next item not present */
  360. return iptr;
  361. }
  362. /* XDR-encode the Reply chunk. Supports encoding an array of plain
  363. * segments that belong to a single write (reply) chunk.
  364. *
  365. * Encoding key for single-list chunks (HLOO = Handle32 Length32 Offset64):
  366. *
  367. * Reply chunk (a counted array):
  368. * N elements:
  369. * 1 - N - HLOO - HLOO - ... - HLOO
  370. *
  371. * Returns a pointer to the XDR word in the RDMA header following
  372. * the end of the Reply chunk, or an error pointer.
  373. */
  374. static __be32 *
  375. rpcrdma_encode_reply_chunk(struct rpcrdma_xprt *r_xprt,
  376. struct rpcrdma_req *req, struct rpc_rqst *rqst,
  377. __be32 *iptr, enum rpcrdma_chunktype wtype)
  378. {
  379. struct rpcrdma_mr_seg *seg;
  380. struct rpcrdma_mw *mw;
  381. int n, nsegs, nchunks;
  382. __be32 *segcount;
  383. if (wtype != rpcrdma_replych) {
  384. *iptr++ = xdr_zero; /* no Reply chunk present */
  385. return iptr;
  386. }
  387. seg = req->rl_segments;
  388. nsegs = rpcrdma_convert_iovs(r_xprt, &rqst->rq_rcv_buf, 0, wtype, seg);
  389. if (nsegs < 0)
  390. return ERR_PTR(nsegs);
  391. *iptr++ = xdr_one; /* Reply chunk present */
  392. segcount = iptr++; /* save location of segment count */
  393. nchunks = 0;
  394. do {
  395. n = r_xprt->rx_ia.ri_ops->ro_map(r_xprt, seg, nsegs,
  396. true, &mw);
  397. if (n < 0)
  398. return ERR_PTR(n);
  399. rpcrdma_push_mw(mw, &req->rl_registered);
  400. iptr = xdr_encode_rdma_segment(iptr, mw);
  401. dprintk("RPC: %5u %s: %u@0x%016llx:0x%08x (%s)\n",
  402. rqst->rq_task->tk_pid, __func__,
  403. mw->mw_length, (unsigned long long)mw->mw_offset,
  404. mw->mw_handle, n < nsegs ? "more" : "last");
  405. r_xprt->rx_stats.reply_chunk_count++;
  406. r_xprt->rx_stats.total_rdma_request += seg->mr_len;
  407. nchunks++;
  408. seg += n;
  409. nsegs -= n;
  410. } while (nsegs);
  411. /* Update count of segments in the Reply chunk */
  412. *segcount = cpu_to_be32(nchunks);
  413. return iptr;
  414. }
  415. /* Prepare the RPC-over-RDMA header SGE.
  416. */
  417. static bool
  418. rpcrdma_prepare_hdr_sge(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
  419. u32 len)
  420. {
  421. struct rpcrdma_regbuf *rb = req->rl_rdmabuf;
  422. struct ib_sge *sge = &req->rl_send_sge[0];
  423. if (unlikely(!rpcrdma_regbuf_is_mapped(rb))) {
  424. if (!__rpcrdma_dma_map_regbuf(ia, rb))
  425. return false;
  426. sge->addr = rdmab_addr(rb);
  427. sge->lkey = rdmab_lkey(rb);
  428. }
  429. sge->length = len;
  430. ib_dma_sync_single_for_device(rdmab_device(rb), sge->addr,
  431. sge->length, DMA_TO_DEVICE);
  432. req->rl_send_wr.num_sge++;
  433. return true;
  434. }
  435. /* Prepare the Send SGEs. The head and tail iovec, and each entry
  436. * in the page list, gets its own SGE.
  437. */
  438. static bool
  439. rpcrdma_prepare_msg_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
  440. struct xdr_buf *xdr, enum rpcrdma_chunktype rtype)
  441. {
  442. unsigned int sge_no, page_base, len, remaining;
  443. struct rpcrdma_regbuf *rb = req->rl_sendbuf;
  444. struct ib_device *device = ia->ri_device;
  445. struct ib_sge *sge = req->rl_send_sge;
  446. u32 lkey = ia->ri_pd->local_dma_lkey;
  447. struct page *page, **ppages;
  448. /* The head iovec is straightforward, as it is already
  449. * DMA-mapped. Sync the content that has changed.
  450. */
  451. if (!rpcrdma_dma_map_regbuf(ia, rb))
  452. return false;
  453. sge_no = 1;
  454. sge[sge_no].addr = rdmab_addr(rb);
  455. sge[sge_no].length = xdr->head[0].iov_len;
  456. sge[sge_no].lkey = rdmab_lkey(rb);
  457. ib_dma_sync_single_for_device(rdmab_device(rb), sge[sge_no].addr,
  458. sge[sge_no].length, DMA_TO_DEVICE);
  459. /* If there is a Read chunk, the page list is being handled
  460. * via explicit RDMA, and thus is skipped here. However, the
  461. * tail iovec may include an XDR pad for the page list, as
  462. * well as additional content, and may not reside in the
  463. * same page as the head iovec.
  464. */
  465. if (rtype == rpcrdma_readch) {
  466. len = xdr->tail[0].iov_len;
  467. /* Do not include the tail if it is only an XDR pad */
  468. if (len < 4)
  469. goto out;
  470. page = virt_to_page(xdr->tail[0].iov_base);
  471. page_base = offset_in_page(xdr->tail[0].iov_base);
  472. /* If the content in the page list is an odd length,
  473. * xdr_write_pages() has added a pad at the beginning
  474. * of the tail iovec. Force the tail's non-pad content
  475. * to land at the next XDR position in the Send message.
  476. */
  477. page_base += len & 3;
  478. len -= len & 3;
  479. goto map_tail;
  480. }
  481. /* If there is a page list present, temporarily DMA map
  482. * and prepare an SGE for each page to be sent.
  483. */
  484. if (xdr->page_len) {
  485. ppages = xdr->pages + (xdr->page_base >> PAGE_SHIFT);
  486. page_base = offset_in_page(xdr->page_base);
  487. remaining = xdr->page_len;
  488. while (remaining) {
  489. sge_no++;
  490. if (sge_no > RPCRDMA_MAX_SEND_SGES - 2)
  491. goto out_mapping_overflow;
  492. len = min_t(u32, PAGE_SIZE - page_base, remaining);
  493. sge[sge_no].addr = ib_dma_map_page(device, *ppages,
  494. page_base, len,
  495. DMA_TO_DEVICE);
  496. if (ib_dma_mapping_error(device, sge[sge_no].addr))
  497. goto out_mapping_err;
  498. sge[sge_no].length = len;
  499. sge[sge_no].lkey = lkey;
  500. req->rl_mapped_sges++;
  501. ppages++;
  502. remaining -= len;
  503. page_base = 0;
  504. }
  505. }
  506. /* The tail iovec is not always constructed in the same
  507. * page where the head iovec resides (see, for example,
  508. * gss_wrap_req_priv). To neatly accommodate that case,
  509. * DMA map it separately.
  510. */
  511. if (xdr->tail[0].iov_len) {
  512. page = virt_to_page(xdr->tail[0].iov_base);
  513. page_base = offset_in_page(xdr->tail[0].iov_base);
  514. len = xdr->tail[0].iov_len;
  515. map_tail:
  516. sge_no++;
  517. sge[sge_no].addr = ib_dma_map_page(device, page,
  518. page_base, len,
  519. DMA_TO_DEVICE);
  520. if (ib_dma_mapping_error(device, sge[sge_no].addr))
  521. goto out_mapping_err;
  522. sge[sge_no].length = len;
  523. sge[sge_no].lkey = lkey;
  524. req->rl_mapped_sges++;
  525. }
  526. out:
  527. req->rl_send_wr.num_sge = sge_no + 1;
  528. return true;
  529. out_mapping_overflow:
  530. pr_err("rpcrdma: too many Send SGEs (%u)\n", sge_no);
  531. return false;
  532. out_mapping_err:
  533. pr_err("rpcrdma: Send mapping error\n");
  534. return false;
  535. }
  536. bool
  537. rpcrdma_prepare_send_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
  538. u32 hdrlen, struct xdr_buf *xdr,
  539. enum rpcrdma_chunktype rtype)
  540. {
  541. req->rl_send_wr.num_sge = 0;
  542. req->rl_mapped_sges = 0;
  543. if (!rpcrdma_prepare_hdr_sge(ia, req, hdrlen))
  544. goto out_map;
  545. if (rtype != rpcrdma_areadch)
  546. if (!rpcrdma_prepare_msg_sges(ia, req, xdr, rtype))
  547. goto out_map;
  548. return true;
  549. out_map:
  550. pr_err("rpcrdma: failed to DMA map a Send buffer\n");
  551. return false;
  552. }
  553. void
  554. rpcrdma_unmap_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req)
  555. {
  556. struct ib_device *device = ia->ri_device;
  557. struct ib_sge *sge;
  558. int count;
  559. sge = &req->rl_send_sge[2];
  560. for (count = req->rl_mapped_sges; count--; sge++)
  561. ib_dma_unmap_page(device, sge->addr, sge->length,
  562. DMA_TO_DEVICE);
  563. req->rl_mapped_sges = 0;
  564. }
  565. /*
  566. * Marshal a request: the primary job of this routine is to choose
  567. * the transfer modes. See comments below.
  568. *
  569. * Returns zero on success, otherwise a negative errno.
  570. */
  571. int
  572. rpcrdma_marshal_req(struct rpc_rqst *rqst)
  573. {
  574. struct rpc_xprt *xprt = rqst->rq_xprt;
  575. struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
  576. struct rpcrdma_req *req = rpcr_to_rdmar(rqst);
  577. enum rpcrdma_chunktype rtype, wtype;
  578. struct rpcrdma_msg *headerp;
  579. bool ddp_allowed;
  580. ssize_t hdrlen;
  581. size_t rpclen;
  582. __be32 *iptr;
  583. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  584. if (test_bit(RPC_BC_PA_IN_USE, &rqst->rq_bc_pa_state))
  585. return rpcrdma_bc_marshal_reply(rqst);
  586. #endif
  587. headerp = rdmab_to_msg(req->rl_rdmabuf);
  588. /* don't byte-swap XID, it's already done in request */
  589. headerp->rm_xid = rqst->rq_xid;
  590. headerp->rm_vers = rpcrdma_version;
  591. headerp->rm_credit = cpu_to_be32(r_xprt->rx_buf.rb_max_requests);
  592. headerp->rm_type = rdma_msg;
  593. /* When the ULP employs a GSS flavor that guarantees integrity
  594. * or privacy, direct data placement of individual data items
  595. * is not allowed.
  596. */
  597. ddp_allowed = !(rqst->rq_cred->cr_auth->au_flags &
  598. RPCAUTH_AUTH_DATATOUCH);
  599. /*
  600. * Chunks needed for results?
  601. *
  602. * o If the expected result is under the inline threshold, all ops
  603. * return as inline.
  604. * o Large read ops return data as write chunk(s), header as
  605. * inline.
  606. * o Large non-read ops return as a single reply chunk.
  607. */
  608. if (rpcrdma_results_inline(r_xprt, rqst))
  609. wtype = rpcrdma_noch;
  610. else if (ddp_allowed && rqst->rq_rcv_buf.flags & XDRBUF_READ)
  611. wtype = rpcrdma_writech;
  612. else
  613. wtype = rpcrdma_replych;
  614. /*
  615. * Chunks needed for arguments?
  616. *
  617. * o If the total request is under the inline threshold, all ops
  618. * are sent as inline.
  619. * o Large write ops transmit data as read chunk(s), header as
  620. * inline.
  621. * o Large non-write ops are sent with the entire message as a
  622. * single read chunk (protocol 0-position special case).
  623. *
  624. * This assumes that the upper layer does not present a request
  625. * that both has a data payload, and whose non-data arguments
  626. * by themselves are larger than the inline threshold.
  627. */
  628. if (rpcrdma_args_inline(r_xprt, rqst)) {
  629. rtype = rpcrdma_noch;
  630. rpclen = rqst->rq_snd_buf.len;
  631. } else if (ddp_allowed && rqst->rq_snd_buf.flags & XDRBUF_WRITE) {
  632. rtype = rpcrdma_readch;
  633. rpclen = rqst->rq_snd_buf.head[0].iov_len +
  634. rqst->rq_snd_buf.tail[0].iov_len;
  635. } else {
  636. r_xprt->rx_stats.nomsg_call_count++;
  637. headerp->rm_type = htonl(RDMA_NOMSG);
  638. rtype = rpcrdma_areadch;
  639. rpclen = 0;
  640. }
  641. req->rl_xid = rqst->rq_xid;
  642. rpcrdma_insert_req(&r_xprt->rx_buf, req);
  643. /* This implementation supports the following combinations
  644. * of chunk lists in one RPC-over-RDMA Call message:
  645. *
  646. * - Read list
  647. * - Write list
  648. * - Reply chunk
  649. * - Read list + Reply chunk
  650. *
  651. * It might not yet support the following combinations:
  652. *
  653. * - Read list + Write list
  654. *
  655. * It does not support the following combinations:
  656. *
  657. * - Write list + Reply chunk
  658. * - Read list + Write list + Reply chunk
  659. *
  660. * This implementation supports only a single chunk in each
  661. * Read or Write list. Thus for example the client cannot
  662. * send a Call message with a Position Zero Read chunk and a
  663. * regular Read chunk at the same time.
  664. */
  665. iptr = headerp->rm_body.rm_chunks;
  666. iptr = rpcrdma_encode_read_list(r_xprt, req, rqst, iptr, rtype);
  667. if (IS_ERR(iptr))
  668. goto out_err;
  669. iptr = rpcrdma_encode_write_list(r_xprt, req, rqst, iptr, wtype);
  670. if (IS_ERR(iptr))
  671. goto out_err;
  672. iptr = rpcrdma_encode_reply_chunk(r_xprt, req, rqst, iptr, wtype);
  673. if (IS_ERR(iptr))
  674. goto out_err;
  675. hdrlen = (unsigned char *)iptr - (unsigned char *)headerp;
  676. dprintk("RPC: %5u %s: %s/%s: hdrlen %zd rpclen %zd\n",
  677. rqst->rq_task->tk_pid, __func__,
  678. transfertypes[rtype], transfertypes[wtype],
  679. hdrlen, rpclen);
  680. if (!rpcrdma_prepare_send_sges(&r_xprt->rx_ia, req, hdrlen,
  681. &rqst->rq_snd_buf, rtype)) {
  682. iptr = ERR_PTR(-EIO);
  683. goto out_err;
  684. }
  685. return 0;
  686. out_err:
  687. if (PTR_ERR(iptr) != -ENOBUFS) {
  688. pr_err("rpcrdma: rpcrdma_marshal_req failed, status %ld\n",
  689. PTR_ERR(iptr));
  690. r_xprt->rx_stats.failed_marshal_count++;
  691. }
  692. return PTR_ERR(iptr);
  693. }
  694. /*
  695. * Chase down a received write or reply chunklist to get length
  696. * RDMA'd by server. See map at rpcrdma_create_chunks()! :-)
  697. */
  698. static int
  699. rpcrdma_count_chunks(struct rpcrdma_rep *rep, int wrchunk, __be32 **iptrp)
  700. {
  701. unsigned int i, total_len;
  702. struct rpcrdma_write_chunk *cur_wchunk;
  703. char *base = (char *)rdmab_to_msg(rep->rr_rdmabuf);
  704. i = be32_to_cpu(**iptrp);
  705. cur_wchunk = (struct rpcrdma_write_chunk *) (*iptrp + 1);
  706. total_len = 0;
  707. while (i--) {
  708. struct rpcrdma_segment *seg = &cur_wchunk->wc_target;
  709. ifdebug(FACILITY) {
  710. u64 off;
  711. xdr_decode_hyper((__be32 *)&seg->rs_offset, &off);
  712. dprintk("RPC: %s: chunk %d@0x%016llx:0x%08x\n",
  713. __func__,
  714. be32_to_cpu(seg->rs_length),
  715. (unsigned long long)off,
  716. be32_to_cpu(seg->rs_handle));
  717. }
  718. total_len += be32_to_cpu(seg->rs_length);
  719. ++cur_wchunk;
  720. }
  721. /* check and adjust for properly terminated write chunk */
  722. if (wrchunk) {
  723. __be32 *w = (__be32 *) cur_wchunk;
  724. if (*w++ != xdr_zero)
  725. return -1;
  726. cur_wchunk = (struct rpcrdma_write_chunk *) w;
  727. }
  728. if ((char *)cur_wchunk > base + rep->rr_len)
  729. return -1;
  730. *iptrp = (__be32 *) cur_wchunk;
  731. return total_len;
  732. }
  733. /**
  734. * rpcrdma_inline_fixup - Scatter inline received data into rqst's iovecs
  735. * @rqst: controlling RPC request
  736. * @srcp: points to RPC message payload in receive buffer
  737. * @copy_len: remaining length of receive buffer content
  738. * @pad: Write chunk pad bytes needed (zero for pure inline)
  739. *
  740. * The upper layer has set the maximum number of bytes it can
  741. * receive in each component of rq_rcv_buf. These values are set in
  742. * the head.iov_len, page_len, tail.iov_len, and buflen fields.
  743. *
  744. * Unlike the TCP equivalent (xdr_partial_copy_from_skb), in
  745. * many cases this function simply updates iov_base pointers in
  746. * rq_rcv_buf to point directly to the received reply data, to
  747. * avoid copying reply data.
  748. *
  749. * Returns the count of bytes which had to be memcopied.
  750. */
  751. static unsigned long
  752. rpcrdma_inline_fixup(struct rpc_rqst *rqst, char *srcp, int copy_len, int pad)
  753. {
  754. unsigned long fixup_copy_count;
  755. int i, npages, curlen;
  756. char *destp;
  757. struct page **ppages;
  758. int page_base;
  759. /* The head iovec is redirected to the RPC reply message
  760. * in the receive buffer, to avoid a memcopy.
  761. */
  762. rqst->rq_rcv_buf.head[0].iov_base = srcp;
  763. rqst->rq_private_buf.head[0].iov_base = srcp;
  764. /* The contents of the receive buffer that follow
  765. * head.iov_len bytes are copied into the page list.
  766. */
  767. curlen = rqst->rq_rcv_buf.head[0].iov_len;
  768. if (curlen > copy_len)
  769. curlen = copy_len;
  770. dprintk("RPC: %s: srcp 0x%p len %d hdrlen %d\n",
  771. __func__, srcp, copy_len, curlen);
  772. srcp += curlen;
  773. copy_len -= curlen;
  774. ppages = rqst->rq_rcv_buf.pages +
  775. (rqst->rq_rcv_buf.page_base >> PAGE_SHIFT);
  776. page_base = offset_in_page(rqst->rq_rcv_buf.page_base);
  777. fixup_copy_count = 0;
  778. if (copy_len && rqst->rq_rcv_buf.page_len) {
  779. int pagelist_len;
  780. pagelist_len = rqst->rq_rcv_buf.page_len;
  781. if (pagelist_len > copy_len)
  782. pagelist_len = copy_len;
  783. npages = PAGE_ALIGN(page_base + pagelist_len) >> PAGE_SHIFT;
  784. for (i = 0; i < npages; i++) {
  785. curlen = PAGE_SIZE - page_base;
  786. if (curlen > pagelist_len)
  787. curlen = pagelist_len;
  788. dprintk("RPC: %s: page %d"
  789. " srcp 0x%p len %d curlen %d\n",
  790. __func__, i, srcp, copy_len, curlen);
  791. destp = kmap_atomic(ppages[i]);
  792. memcpy(destp + page_base, srcp, curlen);
  793. flush_dcache_page(ppages[i]);
  794. kunmap_atomic(destp);
  795. srcp += curlen;
  796. copy_len -= curlen;
  797. fixup_copy_count += curlen;
  798. pagelist_len -= curlen;
  799. if (!pagelist_len)
  800. break;
  801. page_base = 0;
  802. }
  803. /* Implicit padding for the last segment in a Write
  804. * chunk is inserted inline at the front of the tail
  805. * iovec. The upper layer ignores the content of
  806. * the pad. Simply ensure inline content in the tail
  807. * that follows the Write chunk is properly aligned.
  808. */
  809. if (pad)
  810. srcp -= pad;
  811. }
  812. /* The tail iovec is redirected to the remaining data
  813. * in the receive buffer, to avoid a memcopy.
  814. */
  815. if (copy_len || pad) {
  816. rqst->rq_rcv_buf.tail[0].iov_base = srcp;
  817. rqst->rq_private_buf.tail[0].iov_base = srcp;
  818. }
  819. return fixup_copy_count;
  820. }
  821. /* Caller must guarantee @rep remains stable during this call.
  822. */
  823. static void
  824. rpcrdma_mark_remote_invalidation(struct list_head *mws,
  825. struct rpcrdma_rep *rep)
  826. {
  827. struct rpcrdma_mw *mw;
  828. if (!(rep->rr_wc_flags & IB_WC_WITH_INVALIDATE))
  829. return;
  830. list_for_each_entry(mw, mws, mw_list)
  831. if (mw->mw_handle == rep->rr_inv_rkey) {
  832. mw->mw_flags = RPCRDMA_MW_F_RI;
  833. break; /* only one invalidated MR per RPC */
  834. }
  835. }
  836. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  837. /* By convention, backchannel calls arrive via rdma_msg type
  838. * messages, and never populate the chunk lists. This makes
  839. * the RPC/RDMA header small and fixed in size, so it is
  840. * straightforward to check the RPC header's direction field.
  841. */
  842. static bool
  843. rpcrdma_is_bcall(struct rpcrdma_msg *headerp)
  844. {
  845. __be32 *p = (__be32 *)headerp;
  846. if (headerp->rm_type != rdma_msg)
  847. return false;
  848. if (headerp->rm_body.rm_chunks[0] != xdr_zero)
  849. return false;
  850. if (headerp->rm_body.rm_chunks[1] != xdr_zero)
  851. return false;
  852. if (headerp->rm_body.rm_chunks[2] != xdr_zero)
  853. return false;
  854. /* sanity */
  855. if (p[7] != headerp->rm_xid)
  856. return false;
  857. /* call direction */
  858. if (p[8] != cpu_to_be32(RPC_CALL))
  859. return false;
  860. return true;
  861. }
  862. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  863. /* Process received RPC/RDMA messages.
  864. *
  865. * Errors must result in the RPC task either being awakened, or
  866. * allowed to timeout, to discover the errors at that time.
  867. */
  868. void
  869. rpcrdma_reply_handler(struct work_struct *work)
  870. {
  871. struct rpcrdma_rep *rep =
  872. container_of(work, struct rpcrdma_rep, rr_work);
  873. struct rpcrdma_xprt *r_xprt = rep->rr_rxprt;
  874. struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
  875. struct rpc_xprt *xprt = &r_xprt->rx_xprt;
  876. struct rpcrdma_msg *headerp;
  877. struct rpcrdma_req *req;
  878. struct rpc_rqst *rqst;
  879. __be32 *iptr;
  880. int rdmalen, status, rmerr;
  881. unsigned long cwnd;
  882. struct list_head mws;
  883. dprintk("RPC: %s: incoming rep %p\n", __func__, rep);
  884. if (rep->rr_len == RPCRDMA_BAD_LEN)
  885. goto out_badstatus;
  886. if (rep->rr_len < RPCRDMA_HDRLEN_ERR)
  887. goto out_shortreply;
  888. headerp = rdmab_to_msg(rep->rr_rdmabuf);
  889. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  890. if (rpcrdma_is_bcall(headerp))
  891. goto out_bcall;
  892. #endif
  893. /* Match incoming rpcrdma_rep to an rpcrdma_req to
  894. * get context for handling any incoming chunks.
  895. */
  896. spin_lock(&buf->rb_lock);
  897. req = rpcrdma_lookup_req_locked(&r_xprt->rx_buf,
  898. headerp->rm_xid);
  899. if (!req)
  900. goto out_nomatch;
  901. if (req->rl_reply)
  902. goto out_duplicate;
  903. list_replace_init(&req->rl_registered, &mws);
  904. rpcrdma_mark_remote_invalidation(&mws, rep);
  905. /* Avoid races with signals and duplicate replies
  906. * by marking this req as matched.
  907. */
  908. req->rl_reply = rep;
  909. spin_unlock(&buf->rb_lock);
  910. dprintk("RPC: %s: reply %p completes request %p (xid 0x%08x)\n",
  911. __func__, rep, req, be32_to_cpu(headerp->rm_xid));
  912. /* Invalidate and unmap the data payloads before waking the
  913. * waiting application. This guarantees the memory regions
  914. * are properly fenced from the server before the application
  915. * accesses the data. It also ensures proper send flow control:
  916. * waking the next RPC waits until this RPC has relinquished
  917. * all its Send Queue entries.
  918. */
  919. if (!list_empty(&mws))
  920. r_xprt->rx_ia.ri_ops->ro_unmap_sync(r_xprt, &mws);
  921. /* Perform XID lookup, reconstruction of the RPC reply, and
  922. * RPC completion while holding the transport lock to ensure
  923. * the rep, rqst, and rq_task pointers remain stable.
  924. */
  925. spin_lock_bh(&xprt->transport_lock);
  926. rqst = xprt_lookup_rqst(xprt, headerp->rm_xid);
  927. if (!rqst)
  928. goto out_norqst;
  929. xprt->reestablish_timeout = 0;
  930. if (headerp->rm_vers != rpcrdma_version)
  931. goto out_badversion;
  932. /* check for expected message types */
  933. /* The order of some of these tests is important. */
  934. switch (headerp->rm_type) {
  935. case rdma_msg:
  936. /* never expect read chunks */
  937. /* never expect reply chunks (two ways to check) */
  938. if (headerp->rm_body.rm_chunks[0] != xdr_zero ||
  939. (headerp->rm_body.rm_chunks[1] == xdr_zero &&
  940. headerp->rm_body.rm_chunks[2] != xdr_zero))
  941. goto badheader;
  942. if (headerp->rm_body.rm_chunks[1] != xdr_zero) {
  943. /* count any expected write chunks in read reply */
  944. /* start at write chunk array count */
  945. iptr = &headerp->rm_body.rm_chunks[2];
  946. rdmalen = rpcrdma_count_chunks(rep, 1, &iptr);
  947. /* check for validity, and no reply chunk after */
  948. if (rdmalen < 0 || *iptr++ != xdr_zero)
  949. goto badheader;
  950. rep->rr_len -=
  951. ((unsigned char *)iptr - (unsigned char *)headerp);
  952. status = rep->rr_len + rdmalen;
  953. r_xprt->rx_stats.total_rdma_reply += rdmalen;
  954. /* special case - last chunk may omit padding */
  955. if (rdmalen &= 3) {
  956. rdmalen = 4 - rdmalen;
  957. status += rdmalen;
  958. }
  959. } else {
  960. /* else ordinary inline */
  961. rdmalen = 0;
  962. iptr = (__be32 *)((unsigned char *)headerp +
  963. RPCRDMA_HDRLEN_MIN);
  964. rep->rr_len -= RPCRDMA_HDRLEN_MIN;
  965. status = rep->rr_len;
  966. }
  967. r_xprt->rx_stats.fixup_copy_count +=
  968. rpcrdma_inline_fixup(rqst, (char *)iptr, rep->rr_len,
  969. rdmalen);
  970. break;
  971. case rdma_nomsg:
  972. /* never expect read or write chunks, always reply chunks */
  973. if (headerp->rm_body.rm_chunks[0] != xdr_zero ||
  974. headerp->rm_body.rm_chunks[1] != xdr_zero ||
  975. headerp->rm_body.rm_chunks[2] != xdr_one)
  976. goto badheader;
  977. iptr = (__be32 *)((unsigned char *)headerp +
  978. RPCRDMA_HDRLEN_MIN);
  979. rdmalen = rpcrdma_count_chunks(rep, 0, &iptr);
  980. if (rdmalen < 0)
  981. goto badheader;
  982. r_xprt->rx_stats.total_rdma_reply += rdmalen;
  983. /* Reply chunk buffer already is the reply vector - no fixup. */
  984. status = rdmalen;
  985. break;
  986. case rdma_error:
  987. goto out_rdmaerr;
  988. badheader:
  989. default:
  990. dprintk("RPC: %5u %s: invalid rpcrdma reply (type %u)\n",
  991. rqst->rq_task->tk_pid, __func__,
  992. be32_to_cpu(headerp->rm_type));
  993. status = -EIO;
  994. r_xprt->rx_stats.bad_reply_count++;
  995. break;
  996. }
  997. out:
  998. cwnd = xprt->cwnd;
  999. xprt->cwnd = atomic_read(&r_xprt->rx_buf.rb_credits) << RPC_CWNDSHIFT;
  1000. if (xprt->cwnd > cwnd)
  1001. xprt_release_rqst_cong(rqst->rq_task);
  1002. xprt_complete_rqst(rqst->rq_task, status);
  1003. spin_unlock_bh(&xprt->transport_lock);
  1004. dprintk("RPC: %s: xprt_complete_rqst(0x%p, 0x%p, %d)\n",
  1005. __func__, xprt, rqst, status);
  1006. return;
  1007. out_badstatus:
  1008. rpcrdma_recv_buffer_put(rep);
  1009. if (r_xprt->rx_ep.rep_connected == 1) {
  1010. r_xprt->rx_ep.rep_connected = -EIO;
  1011. rpcrdma_conn_func(&r_xprt->rx_ep);
  1012. }
  1013. return;
  1014. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  1015. out_bcall:
  1016. rpcrdma_bc_receive_call(r_xprt, rep);
  1017. return;
  1018. #endif
  1019. /* If the incoming reply terminated a pending RPC, the next
  1020. * RPC call will post a replacement receive buffer as it is
  1021. * being marshaled.
  1022. */
  1023. out_badversion:
  1024. dprintk("RPC: %s: invalid version %d\n",
  1025. __func__, be32_to_cpu(headerp->rm_vers));
  1026. status = -EIO;
  1027. r_xprt->rx_stats.bad_reply_count++;
  1028. goto out;
  1029. out_rdmaerr:
  1030. rmerr = be32_to_cpu(headerp->rm_body.rm_error.rm_err);
  1031. switch (rmerr) {
  1032. case ERR_VERS:
  1033. pr_err("%s: server reports header version error (%u-%u)\n",
  1034. __func__,
  1035. be32_to_cpu(headerp->rm_body.rm_error.rm_vers_low),
  1036. be32_to_cpu(headerp->rm_body.rm_error.rm_vers_high));
  1037. break;
  1038. case ERR_CHUNK:
  1039. pr_err("%s: server reports header decoding error\n",
  1040. __func__);
  1041. break;
  1042. default:
  1043. pr_err("%s: server reports unknown error %d\n",
  1044. __func__, rmerr);
  1045. }
  1046. status = -EREMOTEIO;
  1047. r_xprt->rx_stats.bad_reply_count++;
  1048. goto out;
  1049. /* The req was still available, but by the time the transport_lock
  1050. * was acquired, the rqst and task had been released. Thus the RPC
  1051. * has already been terminated.
  1052. */
  1053. out_norqst:
  1054. spin_unlock_bh(&xprt->transport_lock);
  1055. rpcrdma_buffer_put(req);
  1056. dprintk("RPC: %s: race, no rqst left for req %p\n",
  1057. __func__, req);
  1058. return;
  1059. out_shortreply:
  1060. dprintk("RPC: %s: short/invalid reply\n", __func__);
  1061. goto repost;
  1062. out_nomatch:
  1063. spin_unlock(&buf->rb_lock);
  1064. dprintk("RPC: %s: no match for incoming xid 0x%08x len %d\n",
  1065. __func__, be32_to_cpu(headerp->rm_xid),
  1066. rep->rr_len);
  1067. goto repost;
  1068. out_duplicate:
  1069. spin_unlock(&buf->rb_lock);
  1070. dprintk("RPC: %s: "
  1071. "duplicate reply %p to RPC request %p: xid 0x%08x\n",
  1072. __func__, rep, req, be32_to_cpu(headerp->rm_xid));
  1073. /* If no pending RPC transaction was matched, post a replacement
  1074. * receive buffer before returning.
  1075. */
  1076. repost:
  1077. r_xprt->rx_stats.bad_reply_count++;
  1078. if (rpcrdma_ep_post_recv(&r_xprt->rx_ia, rep))
  1079. rpcrdma_recv_buffer_put(rep);
  1080. }