rpc_rdma.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  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 = xdr->page_base & ~PAGE_MASK;
  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 = xdrbuf->page_base & ~PAGE_MASK;
  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 -ENOBUFS;
  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. list_add(&mw->mw_list, &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. list_add(&mw->mw_list, &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. list_add(&mw->mw_list, &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(ia->ri_device, 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(device, 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 = (unsigned long)xdr->tail[0].iov_base & ~PAGE_MASK;
  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 = xdr->page_base & ~PAGE_MASK;
  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 = (unsigned long)xdr->tail[0].iov_base & ~PAGE_MASK;
  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. /* This implementation supports the following combinations
  642. * of chunk lists in one RPC-over-RDMA Call message:
  643. *
  644. * - Read list
  645. * - Write list
  646. * - Reply chunk
  647. * - Read list + Reply chunk
  648. *
  649. * It might not yet support the following combinations:
  650. *
  651. * - Read list + Write list
  652. *
  653. * It does not support the following combinations:
  654. *
  655. * - Write list + Reply chunk
  656. * - Read list + Write list + Reply chunk
  657. *
  658. * This implementation supports only a single chunk in each
  659. * Read or Write list. Thus for example the client cannot
  660. * send a Call message with a Position Zero Read chunk and a
  661. * regular Read chunk at the same time.
  662. */
  663. iptr = headerp->rm_body.rm_chunks;
  664. iptr = rpcrdma_encode_read_list(r_xprt, req, rqst, iptr, rtype);
  665. if (IS_ERR(iptr))
  666. goto out_unmap;
  667. iptr = rpcrdma_encode_write_list(r_xprt, req, rqst, iptr, wtype);
  668. if (IS_ERR(iptr))
  669. goto out_unmap;
  670. iptr = rpcrdma_encode_reply_chunk(r_xprt, req, rqst, iptr, wtype);
  671. if (IS_ERR(iptr))
  672. goto out_unmap;
  673. hdrlen = (unsigned char *)iptr - (unsigned char *)headerp;
  674. dprintk("RPC: %5u %s: %s/%s: hdrlen %zd rpclen %zd\n",
  675. rqst->rq_task->tk_pid, __func__,
  676. transfertypes[rtype], transfertypes[wtype],
  677. hdrlen, rpclen);
  678. if (!rpcrdma_prepare_send_sges(&r_xprt->rx_ia, req, hdrlen,
  679. &rqst->rq_snd_buf, rtype)) {
  680. iptr = ERR_PTR(-EIO);
  681. goto out_unmap;
  682. }
  683. return 0;
  684. out_unmap:
  685. r_xprt->rx_ia.ri_ops->ro_unmap_safe(r_xprt, req, false);
  686. return PTR_ERR(iptr);
  687. }
  688. /*
  689. * Chase down a received write or reply chunklist to get length
  690. * RDMA'd by server. See map at rpcrdma_create_chunks()! :-)
  691. */
  692. static int
  693. rpcrdma_count_chunks(struct rpcrdma_rep *rep, int wrchunk, __be32 **iptrp)
  694. {
  695. unsigned int i, total_len;
  696. struct rpcrdma_write_chunk *cur_wchunk;
  697. char *base = (char *)rdmab_to_msg(rep->rr_rdmabuf);
  698. i = be32_to_cpu(**iptrp);
  699. cur_wchunk = (struct rpcrdma_write_chunk *) (*iptrp + 1);
  700. total_len = 0;
  701. while (i--) {
  702. struct rpcrdma_segment *seg = &cur_wchunk->wc_target;
  703. ifdebug(FACILITY) {
  704. u64 off;
  705. xdr_decode_hyper((__be32 *)&seg->rs_offset, &off);
  706. dprintk("RPC: %s: chunk %d@0x%llx:0x%x\n",
  707. __func__,
  708. be32_to_cpu(seg->rs_length),
  709. (unsigned long long)off,
  710. be32_to_cpu(seg->rs_handle));
  711. }
  712. total_len += be32_to_cpu(seg->rs_length);
  713. ++cur_wchunk;
  714. }
  715. /* check and adjust for properly terminated write chunk */
  716. if (wrchunk) {
  717. __be32 *w = (__be32 *) cur_wchunk;
  718. if (*w++ != xdr_zero)
  719. return -1;
  720. cur_wchunk = (struct rpcrdma_write_chunk *) w;
  721. }
  722. if ((char *)cur_wchunk > base + rep->rr_len)
  723. return -1;
  724. *iptrp = (__be32 *) cur_wchunk;
  725. return total_len;
  726. }
  727. /**
  728. * rpcrdma_inline_fixup - Scatter inline received data into rqst's iovecs
  729. * @rqst: controlling RPC request
  730. * @srcp: points to RPC message payload in receive buffer
  731. * @copy_len: remaining length of receive buffer content
  732. * @pad: Write chunk pad bytes needed (zero for pure inline)
  733. *
  734. * The upper layer has set the maximum number of bytes it can
  735. * receive in each component of rq_rcv_buf. These values are set in
  736. * the head.iov_len, page_len, tail.iov_len, and buflen fields.
  737. *
  738. * Unlike the TCP equivalent (xdr_partial_copy_from_skb), in
  739. * many cases this function simply updates iov_base pointers in
  740. * rq_rcv_buf to point directly to the received reply data, to
  741. * avoid copying reply data.
  742. *
  743. * Returns the count of bytes which had to be memcopied.
  744. */
  745. static unsigned long
  746. rpcrdma_inline_fixup(struct rpc_rqst *rqst, char *srcp, int copy_len, int pad)
  747. {
  748. unsigned long fixup_copy_count;
  749. int i, npages, curlen;
  750. char *destp;
  751. struct page **ppages;
  752. int page_base;
  753. /* The head iovec is redirected to the RPC reply message
  754. * in the receive buffer, to avoid a memcopy.
  755. */
  756. rqst->rq_rcv_buf.head[0].iov_base = srcp;
  757. rqst->rq_private_buf.head[0].iov_base = srcp;
  758. /* The contents of the receive buffer that follow
  759. * head.iov_len bytes are copied into the page list.
  760. */
  761. curlen = rqst->rq_rcv_buf.head[0].iov_len;
  762. if (curlen > copy_len)
  763. curlen = copy_len;
  764. dprintk("RPC: %s: srcp 0x%p len %d hdrlen %d\n",
  765. __func__, srcp, copy_len, curlen);
  766. srcp += curlen;
  767. copy_len -= curlen;
  768. page_base = rqst->rq_rcv_buf.page_base;
  769. ppages = rqst->rq_rcv_buf.pages + (page_base >> PAGE_SHIFT);
  770. page_base &= ~PAGE_MASK;
  771. fixup_copy_count = 0;
  772. if (copy_len && rqst->rq_rcv_buf.page_len) {
  773. int pagelist_len;
  774. pagelist_len = rqst->rq_rcv_buf.page_len;
  775. if (pagelist_len > copy_len)
  776. pagelist_len = copy_len;
  777. npages = PAGE_ALIGN(page_base + pagelist_len) >> PAGE_SHIFT;
  778. for (i = 0; i < npages; i++) {
  779. curlen = PAGE_SIZE - page_base;
  780. if (curlen > pagelist_len)
  781. curlen = pagelist_len;
  782. dprintk("RPC: %s: page %d"
  783. " srcp 0x%p len %d curlen %d\n",
  784. __func__, i, srcp, copy_len, curlen);
  785. destp = kmap_atomic(ppages[i]);
  786. memcpy(destp + page_base, srcp, curlen);
  787. flush_dcache_page(ppages[i]);
  788. kunmap_atomic(destp);
  789. srcp += curlen;
  790. copy_len -= curlen;
  791. fixup_copy_count += curlen;
  792. pagelist_len -= curlen;
  793. if (!pagelist_len)
  794. break;
  795. page_base = 0;
  796. }
  797. /* Implicit padding for the last segment in a Write
  798. * chunk is inserted inline at the front of the tail
  799. * iovec. The upper layer ignores the content of
  800. * the pad. Simply ensure inline content in the tail
  801. * that follows the Write chunk is properly aligned.
  802. */
  803. if (pad)
  804. srcp -= pad;
  805. }
  806. /* The tail iovec is redirected to the remaining data
  807. * in the receive buffer, to avoid a memcopy.
  808. */
  809. if (copy_len || pad) {
  810. rqst->rq_rcv_buf.tail[0].iov_base = srcp;
  811. rqst->rq_private_buf.tail[0].iov_base = srcp;
  812. }
  813. return fixup_copy_count;
  814. }
  815. void
  816. rpcrdma_connect_worker(struct work_struct *work)
  817. {
  818. struct rpcrdma_ep *ep =
  819. container_of(work, struct rpcrdma_ep, rep_connect_worker.work);
  820. struct rpcrdma_xprt *r_xprt =
  821. container_of(ep, struct rpcrdma_xprt, rx_ep);
  822. struct rpc_xprt *xprt = &r_xprt->rx_xprt;
  823. spin_lock_bh(&xprt->transport_lock);
  824. if (++xprt->connect_cookie == 0) /* maintain a reserved value */
  825. ++xprt->connect_cookie;
  826. if (ep->rep_connected > 0) {
  827. if (!xprt_test_and_set_connected(xprt))
  828. xprt_wake_pending_tasks(xprt, 0);
  829. } else {
  830. if (xprt_test_and_clear_connected(xprt))
  831. xprt_wake_pending_tasks(xprt, -ENOTCONN);
  832. }
  833. spin_unlock_bh(&xprt->transport_lock);
  834. }
  835. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  836. /* By convention, backchannel calls arrive via rdma_msg type
  837. * messages, and never populate the chunk lists. This makes
  838. * the RPC/RDMA header small and fixed in size, so it is
  839. * straightforward to check the RPC header's direction field.
  840. */
  841. static bool
  842. rpcrdma_is_bcall(struct rpcrdma_msg *headerp)
  843. {
  844. __be32 *p = (__be32 *)headerp;
  845. if (headerp->rm_type != rdma_msg)
  846. return false;
  847. if (headerp->rm_body.rm_chunks[0] != xdr_zero)
  848. return false;
  849. if (headerp->rm_body.rm_chunks[1] != xdr_zero)
  850. return false;
  851. if (headerp->rm_body.rm_chunks[2] != xdr_zero)
  852. return false;
  853. /* sanity */
  854. if (p[7] != headerp->rm_xid)
  855. return false;
  856. /* call direction */
  857. if (p[8] != cpu_to_be32(RPC_CALL))
  858. return false;
  859. return true;
  860. }
  861. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  862. /*
  863. * This function is called when an async event is posted to
  864. * the connection which changes the connection state. All it
  865. * does at this point is mark the connection up/down, the rpc
  866. * timers do the rest.
  867. */
  868. void
  869. rpcrdma_conn_func(struct rpcrdma_ep *ep)
  870. {
  871. schedule_delayed_work(&ep->rep_connect_worker, 0);
  872. }
  873. /* Process received RPC/RDMA messages.
  874. *
  875. * Errors must result in the RPC task either being awakened, or
  876. * allowed to timeout, to discover the errors at that time.
  877. */
  878. void
  879. rpcrdma_reply_handler(struct work_struct *work)
  880. {
  881. struct rpcrdma_rep *rep =
  882. container_of(work, struct rpcrdma_rep, rr_work);
  883. struct rpcrdma_msg *headerp;
  884. struct rpcrdma_req *req;
  885. struct rpc_rqst *rqst;
  886. struct rpcrdma_xprt *r_xprt = rep->rr_rxprt;
  887. struct rpc_xprt *xprt = &r_xprt->rx_xprt;
  888. __be32 *iptr;
  889. int rdmalen, status, rmerr;
  890. unsigned long cwnd;
  891. dprintk("RPC: %s: incoming rep %p\n", __func__, rep);
  892. if (rep->rr_len == RPCRDMA_BAD_LEN)
  893. goto out_badstatus;
  894. if (rep->rr_len < RPCRDMA_HDRLEN_ERR)
  895. goto out_shortreply;
  896. headerp = rdmab_to_msg(rep->rr_rdmabuf);
  897. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  898. if (rpcrdma_is_bcall(headerp))
  899. goto out_bcall;
  900. #endif
  901. /* Match incoming rpcrdma_rep to an rpcrdma_req to
  902. * get context for handling any incoming chunks.
  903. */
  904. spin_lock_bh(&xprt->transport_lock);
  905. rqst = xprt_lookup_rqst(xprt, headerp->rm_xid);
  906. if (!rqst)
  907. goto out_nomatch;
  908. req = rpcr_to_rdmar(rqst);
  909. if (req->rl_reply)
  910. goto out_duplicate;
  911. /* Sanity checking has passed. We are now committed
  912. * to complete this transaction.
  913. */
  914. list_del_init(&rqst->rq_list);
  915. spin_unlock_bh(&xprt->transport_lock);
  916. dprintk("RPC: %s: reply %p completes request %p (xid 0x%08x)\n",
  917. __func__, rep, req, be32_to_cpu(headerp->rm_xid));
  918. /* from here on, the reply is no longer an orphan */
  919. req->rl_reply = rep;
  920. xprt->reestablish_timeout = 0;
  921. if (headerp->rm_vers != rpcrdma_version)
  922. goto out_badversion;
  923. /* check for expected message types */
  924. /* The order of some of these tests is important. */
  925. switch (headerp->rm_type) {
  926. case rdma_msg:
  927. /* never expect read chunks */
  928. /* never expect reply chunks (two ways to check) */
  929. /* never expect write chunks without having offered RDMA */
  930. if (headerp->rm_body.rm_chunks[0] != xdr_zero ||
  931. (headerp->rm_body.rm_chunks[1] == xdr_zero &&
  932. headerp->rm_body.rm_chunks[2] != xdr_zero) ||
  933. (headerp->rm_body.rm_chunks[1] != xdr_zero &&
  934. list_empty(&req->rl_registered)))
  935. goto badheader;
  936. if (headerp->rm_body.rm_chunks[1] != xdr_zero) {
  937. /* count any expected write chunks in read reply */
  938. /* start at write chunk array count */
  939. iptr = &headerp->rm_body.rm_chunks[2];
  940. rdmalen = rpcrdma_count_chunks(rep, 1, &iptr);
  941. /* check for validity, and no reply chunk after */
  942. if (rdmalen < 0 || *iptr++ != xdr_zero)
  943. goto badheader;
  944. rep->rr_len -=
  945. ((unsigned char *)iptr - (unsigned char *)headerp);
  946. status = rep->rr_len + rdmalen;
  947. r_xprt->rx_stats.total_rdma_reply += rdmalen;
  948. /* special case - last chunk may omit padding */
  949. if (rdmalen &= 3) {
  950. rdmalen = 4 - rdmalen;
  951. status += rdmalen;
  952. }
  953. } else {
  954. /* else ordinary inline */
  955. rdmalen = 0;
  956. iptr = (__be32 *)((unsigned char *)headerp +
  957. RPCRDMA_HDRLEN_MIN);
  958. rep->rr_len -= RPCRDMA_HDRLEN_MIN;
  959. status = rep->rr_len;
  960. }
  961. r_xprt->rx_stats.fixup_copy_count +=
  962. rpcrdma_inline_fixup(rqst, (char *)iptr, rep->rr_len,
  963. rdmalen);
  964. break;
  965. case rdma_nomsg:
  966. /* never expect read or write chunks, always reply chunks */
  967. if (headerp->rm_body.rm_chunks[0] != xdr_zero ||
  968. headerp->rm_body.rm_chunks[1] != xdr_zero ||
  969. headerp->rm_body.rm_chunks[2] != xdr_one ||
  970. list_empty(&req->rl_registered))
  971. goto badheader;
  972. iptr = (__be32 *)((unsigned char *)headerp +
  973. RPCRDMA_HDRLEN_MIN);
  974. rdmalen = rpcrdma_count_chunks(rep, 0, &iptr);
  975. if (rdmalen < 0)
  976. goto badheader;
  977. r_xprt->rx_stats.total_rdma_reply += rdmalen;
  978. /* Reply chunk buffer already is the reply vector - no fixup. */
  979. status = rdmalen;
  980. break;
  981. case rdma_error:
  982. goto out_rdmaerr;
  983. badheader:
  984. default:
  985. dprintk("RPC: %5u %s: invalid rpcrdma reply (type %u)\n",
  986. rqst->rq_task->tk_pid, __func__,
  987. be32_to_cpu(headerp->rm_type));
  988. status = -EIO;
  989. r_xprt->rx_stats.bad_reply_count++;
  990. break;
  991. }
  992. out:
  993. /* Invalidate and flush the data payloads before waking the
  994. * waiting application. This guarantees the memory region is
  995. * properly fenced from the server before the application
  996. * accesses the data. It also ensures proper send flow
  997. * control: waking the next RPC waits until this RPC has
  998. * relinquished all its Send Queue entries.
  999. */
  1000. if (!list_empty(&req->rl_registered))
  1001. r_xprt->rx_ia.ri_ops->ro_unmap_sync(r_xprt, req);
  1002. spin_lock_bh(&xprt->transport_lock);
  1003. cwnd = xprt->cwnd;
  1004. xprt->cwnd = atomic_read(&r_xprt->rx_buf.rb_credits) << RPC_CWNDSHIFT;
  1005. if (xprt->cwnd > cwnd)
  1006. xprt_release_rqst_cong(rqst->rq_task);
  1007. xprt_complete_rqst(rqst->rq_task, status);
  1008. spin_unlock_bh(&xprt->transport_lock);
  1009. dprintk("RPC: %s: xprt_complete_rqst(0x%p, 0x%p, %d)\n",
  1010. __func__, xprt, rqst, status);
  1011. return;
  1012. out_badstatus:
  1013. rpcrdma_recv_buffer_put(rep);
  1014. if (r_xprt->rx_ep.rep_connected == 1) {
  1015. r_xprt->rx_ep.rep_connected = -EIO;
  1016. rpcrdma_conn_func(&r_xprt->rx_ep);
  1017. }
  1018. return;
  1019. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  1020. out_bcall:
  1021. rpcrdma_bc_receive_call(r_xprt, rep);
  1022. return;
  1023. #endif
  1024. /* If the incoming reply terminated a pending RPC, the next
  1025. * RPC call will post a replacement receive buffer as it is
  1026. * being marshaled.
  1027. */
  1028. out_badversion:
  1029. dprintk("RPC: %s: invalid version %d\n",
  1030. __func__, be32_to_cpu(headerp->rm_vers));
  1031. status = -EIO;
  1032. r_xprt->rx_stats.bad_reply_count++;
  1033. goto out;
  1034. out_rdmaerr:
  1035. rmerr = be32_to_cpu(headerp->rm_body.rm_error.rm_err);
  1036. switch (rmerr) {
  1037. case ERR_VERS:
  1038. pr_err("%s: server reports header version error (%u-%u)\n",
  1039. __func__,
  1040. be32_to_cpu(headerp->rm_body.rm_error.rm_vers_low),
  1041. be32_to_cpu(headerp->rm_body.rm_error.rm_vers_high));
  1042. break;
  1043. case ERR_CHUNK:
  1044. pr_err("%s: server reports header decoding error\n",
  1045. __func__);
  1046. break;
  1047. default:
  1048. pr_err("%s: server reports unknown error %d\n",
  1049. __func__, rmerr);
  1050. }
  1051. status = -EREMOTEIO;
  1052. r_xprt->rx_stats.bad_reply_count++;
  1053. goto out;
  1054. /* If no pending RPC transaction was matched, post a replacement
  1055. * receive buffer before returning.
  1056. */
  1057. out_shortreply:
  1058. dprintk("RPC: %s: short/invalid reply\n", __func__);
  1059. goto repost;
  1060. out_nomatch:
  1061. spin_unlock_bh(&xprt->transport_lock);
  1062. dprintk("RPC: %s: no match for incoming xid 0x%08x len %d\n",
  1063. __func__, be32_to_cpu(headerp->rm_xid),
  1064. rep->rr_len);
  1065. goto repost;
  1066. out_duplicate:
  1067. spin_unlock_bh(&xprt->transport_lock);
  1068. dprintk("RPC: %s: "
  1069. "duplicate reply %p to RPC request %p: xid 0x%08x\n",
  1070. __func__, rep, req, be32_to_cpu(headerp->rm_xid));
  1071. repost:
  1072. r_xprt->rx_stats.bad_reply_count++;
  1073. if (rpcrdma_ep_post_recv(&r_xprt->rx_ia, rep))
  1074. rpcrdma_recv_buffer_put(rep);
  1075. }