rpc_rdma.c 34 KB

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