From: Tom Wu <tomwu@nvidia.com>
Subject: [PATCH] BACKPORT: net/sunrpc/xprtrdma/svc_rdma_recvfrom.c

Change-Id: I7703049f93c41d059a854fe4389d3079b10b15cc
Signed-off-by: Tom Wu <tomwu@nvidia.com>
---
 net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 470 ++++++++++++++++++++++++
 1 file changed, 470 insertions(+)

--- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
@@ -92,7 +92,9 @@
  * are transferred from the svc_rdma_recv_ctxt to the second svc_rqst.
  */
 
+#ifdef HAVE_SVC_RDMA_PCL
 #include <linux/slab.h>
+#endif
 #include <linux/spinlock.h>
 #include <linux/unaligned.h>
 #include <rdma/ib_verbs.h>
@@ -104,7 +106,9 @@
 #include <linux/sunrpc/svc_rdma.h>
 
 #include "xprt_rdma.h"
+#ifdef HAVE_TRACE_RPCRDMA_H
 #include <trace/events/rpcrdma.h>
+#endif
 
 static void svc_rdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc);
 
@@ -135,10 +139,12 @@ svc_rdma_recv_ctxt_alloc(struct svcxprt_
 		goto fail2;
 
 	svc_rdma_recv_cid_init(rdma, &ctxt->rc_cid);
+#ifdef HAVE_SVC_RDMA_PCL
 	pcl_init(&ctxt->rc_call_pcl);
 	pcl_init(&ctxt->rc_read_pcl);
 	pcl_init(&ctxt->rc_write_pcl);
 	pcl_init(&ctxt->rc_reply_pcl);
+#endif
 
 	ctxt->rc_recv_wr.next = NULL;
 	ctxt->rc_recv_wr.wr_cqe = &ctxt->rc_cqe;
@@ -191,6 +197,7 @@ void svc_rdma_recv_ctxts_destroy(struct
  *
  * Returns a recv_ctxt or (rarely) NULL if none are available.
  */
+#ifdef HAVE_SVC_RDMA_PCL
 struct svc_rdma_recv_ctxt *svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma)
 {
 	struct svc_rdma_recv_ctxt *ctxt;
@@ -204,6 +211,29 @@ struct svc_rdma_recv_ctxt *svc_rdma_recv
 	ctxt->rc_page_count = 0;
 	return ctxt;
 }
+#else
+struct svc_rdma_recv_ctxt *svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma)
+{
+	struct svc_rdma_recv_ctxt *ctxt;
+	struct llist_node *node;
+
+	node = llist_del_first(&rdma->sc_recv_ctxts);
+	if (!node)
+		goto out_empty;
+	ctxt = llist_entry(node, struct svc_rdma_recv_ctxt, rc_node);
+
+out:
+	ctxt->rc_page_count = 0;
+	ctxt->rc_read_payload_length = 0;
+	return ctxt;
+
+out_empty:
+	ctxt = svc_rdma_recv_ctxt_alloc(rdma);
+	if (!ctxt)
+		return NULL;
+	goto out;
+}
+#endif
 
 /**
  * svc_rdma_recv_ctxt_put - Return recv_ctxt to free list
@@ -214,21 +244,55 @@ struct svc_rdma_recv_ctxt *svc_rdma_recv
 void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma,
 			    struct svc_rdma_recv_ctxt *ctxt)
 {
+#ifndef HAVE_RELEASE_PAGES_IN_MM_H
+	int i;
+#endif
+
 	svc_rdma_cc_release(rdma, &ctxt->rc_cc, DMA_FROM_DEVICE);
 
 	/* @rc_page_count is normally zero here, but error flows
 	 * can leave pages in @rc_pages.
 	 */
+#ifdef HAVE_RELEASE_PAGES_IN_MM_H
 	release_pages(ctxt->rc_pages, ctxt->rc_page_count);
+#else
+	for (i = 0; i < ctxt->rc_page_count; ++i)
+		put_page(ctxt->rc_pages[i]);
+#endif
 
+#ifdef HAVE_SVC_RDMA_PCL
 	pcl_free(&ctxt->rc_call_pcl);
 	pcl_free(&ctxt->rc_read_pcl);
 	pcl_free(&ctxt->rc_write_pcl);
 	pcl_free(&ctxt->rc_reply_pcl);
+#endif
 
 	llist_add(&ctxt->rc_node, &rdma->sc_recv_ctxts);
 }
 
+#ifdef HAVE_SVC_RDMA_RELEASE_RQST
+/**
+ * svc_rdma_release_rqst - Release transport-specific per-rqst resources
+ * @rqstp: svc_rqst being released
+ *
+ * Ensure that the recv_ctxt is released whether or not a Reply
+ * was sent. For example, the client could close the connection,
+ * or svc_process could drop an RPC, before the Reply is sent.
+ */
+void svc_rdma_release_rqst(struct svc_rqst *rqstp)
+{
+	struct svc_rdma_recv_ctxt *ctxt = rqstp->rq_xprt_ctxt;
+	struct svc_xprt *xprt = rqstp->rq_xprt;
+	struct svcxprt_rdma *rdma =
+		container_of(xprt, struct svcxprt_rdma, sc_xprt);
+
+	rqstp->rq_xprt_ctxt = NULL;
+	if (ctxt)
+		svc_rdma_recv_ctxt_put(rdma, ctxt);
+}
+#endif
+
+#ifdef HAVE_XPO_RELEASE_CTXT
 /**
  * svc_rdma_release_ctxt - Release transport-specific per-rqst resources
  * @xprt: the transport which owned the context
@@ -247,7 +311,9 @@ void svc_rdma_release_ctxt(struct svc_xp
 	if (ctxt)
 		svc_rdma_recv_ctxt_put(rdma, ctxt);
 }
+#endif
 
+#ifdef HAVE_SVC_RDMA_PCL
 static bool svc_rdma_refresh_recvs(struct svcxprt_rdma *rdma,
 				   unsigned int wanted)
 {
@@ -265,10 +331,14 @@ static bool svc_rdma_refresh_recvs(struc
 		if (!ctxt)
 			break;
 
+#ifdef HAVE_TRACE_RPCRDMA_H
 		trace_svcrdma_post_recv(&ctxt->rc_cid);
+#endif
 		ctxt->rc_recv_wr.next = recv_chain;
 		recv_chain = &ctxt->rc_recv_wr;
+#ifdef HAVE_SVCXPRT_RDMA_SC_PENDING_RECVS
 		rdma->sc_pending_recvs++;
+#endif
 	}
 	if (!recv_chain)
 		return true;
@@ -279,7 +349,9 @@ static bool svc_rdma_refresh_recvs(struc
 	return true;
 
 err_free:
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_rq_post_err(rdma, ret);
+#endif
 	while (bad_wr) {
 		ctxt = container_of(bad_wr, struct svc_rdma_recv_ctxt,
 				    rc_recv_wr);
@@ -290,6 +362,40 @@ err_free:
 	 * sc_pending_recvs. */
 	return false;
 }
+#else
+static int __svc_rdma_post_recv(struct svcxprt_rdma *rdma,
+				struct svc_rdma_recv_ctxt *ctxt)
+{
+	int ret;
+
+#ifdef HAVE_TRACE_RPCRDMA_H
+	trace_svcrdma_post_recv(&ctxt->rc_cid);
+#endif
+	ret = ib_post_recv(rdma->sc_qp, &ctxt->rc_recv_wr, NULL);
+	if (ret)
+		goto err_post;
+	return 0;
+
+err_post:
+#ifdef HAVE_TRACE_RPCRDMA_H
+	trace_svcrdma_rq_post_err(rdma, ret);
+#endif
+	svc_rdma_recv_ctxt_put(rdma, ctxt);
+	return ret;
+}
+
+static int svc_rdma_post_recv(struct svcxprt_rdma *rdma)
+{
+	struct svc_rdma_recv_ctxt *ctxt;
+
+	if (test_bit(XPT_CLOSE, &rdma->sc_xprt.xpt_flags))
+		return 0;
+	ctxt = svc_rdma_recv_ctxt_get(rdma);
+	if (!ctxt)
+		return -ENOMEM;
+	return __svc_rdma_post_recv(rdma, ctxt);
+}
+#endif /* end of HAVE_SVC_RDMA_PCL */
 
 /**
  * svc_rdma_post_recvs - Post initial set of Recv WRs
@@ -301,12 +407,17 @@ err_free:
  */
 bool svc_rdma_post_recvs(struct svcxprt_rdma *rdma)
 {
+#ifdef HAVE_SVC_RDMA_PCL
 	unsigned int total;
 
 	/* For each credit, allocate enough recv_ctxts for one
 	 * posted Receive and one RPC in process.
 	 */
+#ifdef HAVE_SVCXPRT_RDMA_SC_PENDING_RECVS
 	total = (rdma->sc_max_requests * 2) + rdma->sc_recv_batch;
+#else
+	total = (rdma->sc_max_requests * 2);
+#endif
 	while (total--) {
 		struct svc_rdma_recv_ctxt *ctxt;
 
@@ -317,6 +428,21 @@ bool svc_rdma_post_recvs(struct svcxprt_
 	}
 
 	return svc_rdma_refresh_recvs(rdma, rdma->sc_max_requests);
+#else
+	struct svc_rdma_recv_ctxt *ctxt;
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < rdma->sc_max_requests; i++) {
+		ctxt = svc_rdma_recv_ctxt_get(rdma);
+		if (!ctxt)
+			return false;
+		ret = __svc_rdma_post_recv(rdma, ctxt);
+		if (ret)
+			return false;
+	}
+	return true;
+#endif
 }
 
 /**
@@ -331,15 +457,20 @@ static void svc_rdma_wc_receive(struct i
 	struct ib_cqe *cqe = wc->wr_cqe;
 	struct svc_rdma_recv_ctxt *ctxt;
 
+#ifdef HAVE_SVCXPRT_RDMA_SC_PENDING_RECVS
 	rdma->sc_pending_recvs--;
+#endif
 
 	/* WARNING: Only wc->wr_cqe and wc->status are reliable */
 	ctxt = container_of(cqe, struct svc_rdma_recv_ctxt, rc_cqe);
 
 	if (wc->status != IB_WC_SUCCESS)
 		goto flushed;
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_wc_recv(wc, &ctxt->rc_cid);
+#endif
 
+#ifdef HAVE_SVC_RDMA_PCL
 	/* If receive posting fails, the connection is about to be
 	 * lost anyway. The server will not be able to send a reply
 	 * for this RPC, and the client will retransmit this RPC
@@ -349,9 +480,18 @@ static void svc_rdma_wc_receive(struct i
 	 * to reduce the likelihood of replayed requests once the
 	 * client reconnects.
 	 */
+#ifdef HAVE_SVCXPRT_RDMA_SC_PENDING_RECVS
 	if (rdma->sc_pending_recvs < rdma->sc_max_requests)
 		if (!svc_rdma_refresh_recvs(rdma, rdma->sc_recv_batch))
 			goto dropped;
+#else
+	if (!svc_rdma_refresh_recvs(rdma, 1))
+		goto dropped;
+#endif
+#else
+		if (svc_rdma_post_recv(rdma))
+			goto dropped;
+#endif
 
 	/* All wc fields are now known to be valid */
 	ctxt->rc_byte_len = wc->byte_len;
@@ -366,13 +506,22 @@ static void svc_rdma_wc_receive(struct i
 	return;
 
 flushed:
+#ifdef HAVE_TRACE_RPCRDMA_H
 	if (wc->status == IB_WC_WR_FLUSH_ERR)
 		trace_svcrdma_wc_recv_flush(wc, &ctxt->rc_cid);
 	else
 		trace_svcrdma_wc_recv_err(wc, &ctxt->rc_cid);
+#endif
 dropped:
 	svc_rdma_recv_ctxt_put(rdma, ctxt);
+#ifdef HAVE_SVC_XPRT_DEFERRED_CLOSE
 	svc_xprt_deferred_close(&rdma->sc_xprt);
+#else
+	set_bit(XPT_CLOSE, &rdma->sc_xprt.xpt_flags);
+#endif
+#ifndef HAVE_SVC_RDMA_PCL
+	svc_xprt_enqueue(&rdma->sc_xprt);
+#endif
 }
 
 /**
@@ -409,6 +558,18 @@ static void svc_rdma_build_arg_xdr(struc
 	arg->len = ctxt->rc_byte_len;
 }
 
+#ifndef HAVE_SVC_RDMA_PCL
+/* This accommodates the largest possible Write chunk.
+ */
+#define MAX_BYTES_WRITE_CHUNK ((u32)(RPCSVC_MAXPAGES << PAGE_SHIFT))
+
+/* This accommodates the largest possible Position-Zero
+ * Read chunk or Reply chunk.
+ */
+#define MAX_BYTES_SPECIAL_CHUNK ((u32)((RPCSVC_MAXPAGES + 2) << PAGE_SHIFT))
+#endif
+
+#ifdef HAVE_SVC_RDMA_PCL
 /**
  * xdr_count_read_segments - Count number of Read segments in Read list
  * @rctxt: Ingress receive context
@@ -527,6 +688,92 @@ static bool xdr_count_write_chunks(struc
 	}
 	return true;
 }
+#else
+/* Sanity check the Read list.
+ *
+ * Implementation limits:
+ * - This implementation supports only one Read chunk.
+ *
+ * Sanity checks:
+ * - Read list does not overflow Receive buffer.
+ * - Segment size limited by largest NFS data payload.
+ *
+ * The segment count is limited to how many segments can
+ * fit in the transport header without overflowing the
+ * buffer. That's about 40 Read segments for a 1KB inline
+ * threshold.
+ *
+ * Return values:
+ *       %true: Read list is valid. @rctxt's xdr_stream is updated
+ *		to point to the first byte past the Read list.
+ *      %false: Read list is corrupt. @rctxt's xdr_stream is left
+ *		in an unknown state.
+ */
+static bool xdr_check_read_list(struct svc_rdma_recv_ctxt *rctxt)
+{
+	u32 position, len;
+	bool first;
+	__be32 *p;
+
+	p = xdr_inline_decode(&rctxt->rc_stream, sizeof(*p));
+	if (!p)
+		return false;
+
+	len = 0;
+	first = true;
+	while (xdr_item_is_present(p)) {
+		p = xdr_inline_decode(&rctxt->rc_stream,
+				      rpcrdma_readseg_maxsz * sizeof(*p));
+		if (!p)
+			return false;
+
+		if (first) {
+			position = be32_to_cpup(p);
+			first = false;
+		} else if (be32_to_cpup(p) != position) {
+			return false;
+		}
+		p += 2;
+		len += be32_to_cpup(p);
+
+		p = xdr_inline_decode(&rctxt->rc_stream, sizeof(*p));
+		if (!p)
+			return false;
+	}
+	return len <= MAX_BYTES_SPECIAL_CHUNK;
+}
+
+/* The segment count is limited to how many segments can
+ * fit in the transport header without overflowing the
+ * buffer. That's about 60 Write segments for a 1KB inline
+ * threshold.
+ */
+static bool xdr_check_write_chunk(struct svc_rdma_recv_ctxt *rctxt, u32 maxlen)
+{
+	u32 i, segcount, total;
+	__be32 *p;
+
+	p = xdr_inline_decode(&rctxt->rc_stream, sizeof(*p));
+	if (!p)
+		return false;
+	segcount = be32_to_cpup(p);
+
+	total = 0;
+	for (i = 0; i < segcount; i++) {
+		u32 handle, length;
+		u64 offset;
+
+		p = xdr_inline_decode(&rctxt->rc_stream,
+				      rpcrdma_segment_maxsz * sizeof(*p));
+		if (!p)
+			return false;
+
+		xdr_decode_rdma_segment(p, &handle, &length, &offset);
+		total += length;
+	}
+	return total <= maxlen;
+}
+#endif
 
 /* Sanity check the Write list.
  *
@@ -545,11 +792,13 @@ static bool xdr_count_write_chunks(struc
  */
 static bool xdr_check_write_list(struct svc_rdma_recv_ctxt *rctxt)
 {
+#ifdef HAVE_SVC_RDMA_PCL
 	__be32 *p;
 
 	p = xdr_inline_decode(&rctxt->rc_stream, sizeof(*p));
 	if (!p)
 		return false;
+
 	if (!xdr_count_write_chunks(rctxt, p))
 		return false;
 	if (!pcl_alloc_write(rctxt, &rctxt->rc_write_pcl, p))
@@ -557,6 +806,27 @@ static bool xdr_check_write_list(struct
 
 	rctxt->rc_cur_result_payload = pcl_first_chunk(&rctxt->rc_write_pcl);
 	return true;
+#else
+	u32 chcount = 0;
+	__be32 *p;
+
+	p = xdr_inline_decode(&rctxt->rc_stream, sizeof(*p));
+	if (!p)
+		return false;
+
+	rctxt->rc_write_list = p;
+	while (xdr_item_is_present(p)) {
+		if (!xdr_check_write_chunk(rctxt, MAX_BYTES_WRITE_CHUNK))
+			return false;
+		++chcount;
+		p = xdr_inline_decode(&rctxt->rc_stream, sizeof(*p));
+		if (!p)
+			return false;
+	}
+	if (!chcount)
+		rctxt->rc_write_list = NULL;
+	return chcount < 2;
+#endif
 }
 
 /* Sanity check the Reply chunk.
@@ -579,6 +849,7 @@ static bool xdr_check_reply_chunk(struct
 	if (!p)
 		return false;
 
+#ifdef HAVE_SVC_RDMA_PCL
 	if (!xdr_item_is_present(p))
 		return true;
 	if (!xdr_check_write_chunk(rctxt))
@@ -586,6 +857,15 @@ static bool xdr_check_reply_chunk(struct
 
 	rctxt->rc_reply_pcl.cl_count = 1;
 	return pcl_alloc_write(rctxt, &rctxt->rc_reply_pcl, p);
+#else
+	rctxt->rc_reply_chunk = NULL;
+	if (xdr_item_is_present(p)) {
+		if (!xdr_check_write_chunk(rctxt, MAX_BYTES_SPECIAL_CHUNK))
+			return false;
+		rctxt->rc_reply_chunk = p;
+	}
+	return true;
+#endif
 }
 
 /* RPC-over-RDMA Version One private extension: Remote Invalidation.
@@ -598,6 +878,7 @@ static bool xdr_check_reply_chunk(struct
 static void svc_rdma_get_inv_rkey(struct svcxprt_rdma *rdma,
 				  struct svc_rdma_recv_ctxt *ctxt)
 {
+#ifdef HAVE_SVC_RDMA_PCL
 	struct svc_rdma_segment *segment;
 	struct svc_rdma_chunk *chunk;
 	u32 inv_rkey;
@@ -641,6 +922,55 @@ static void svc_rdma_get_inv_rkey(struct
 		}
 	}
 	ctxt->rc_inv_rkey = inv_rkey;
+#else
+	__be32 inv_rkey, *p;
+	u32 i, segcount;
+
+	ctxt->rc_inv_rkey = 0;
+
+	if (!rdma->sc_snd_w_inv)
+		return;
+
+	inv_rkey = xdr_zero;
+	p = ctxt->rc_recv_buf;
+	p += rpcrdma_fixed_maxsz;
+
+	/* Read list */
+	while (xdr_item_is_present(p++)) {
+		p++;	/* position */
+		if (inv_rkey == xdr_zero)
+			inv_rkey = *p;
+		else if (inv_rkey != *p)
+			return;
+		p += 4;
+	}
+
+	/* Write list */
+	while (xdr_item_is_present(p++)) {
+		segcount = be32_to_cpup(p++);
+		for (i = 0; i < segcount; i++) {
+			if (inv_rkey == xdr_zero)
+				inv_rkey = *p;
+			else if (inv_rkey != *p)
+				return;
+			p += 4;
+		}
+	}
+
+	/* Reply chunk */
+	if (xdr_item_is_present(p++)) {
+		segcount = be32_to_cpup(p++);
+		for (i = 0; i < segcount; i++) {
+			if (inv_rkey == xdr_zero)
+				inv_rkey = *p;
+			else if (inv_rkey != *p)
+				return;
+			p += 4;
+		}
+	}
+
+	ctxt->rc_inv_rkey = be32_to_cpu(inv_rkey);
+#endif
 }
 
 /**
@@ -666,7 +996,11 @@ static int svc_rdma_xdr_decode_req(struc
 	unsigned int hdr_len;
 
 	rdma_argp = rq_arg->head[0].iov_base;
+#ifdef HAVE_XDR_INIT_DECODE_RQST_ARG
 	xdr_init_decode(&rctxt->rc_stream, rq_arg, rdma_argp, NULL);
+#else
+	xdr_init_decode(&rctxt->rc_stream, rq_arg, rdma_argp);
+#endif
 
 	p = xdr_inline_decode(&rctxt->rc_stream,
 			      rpcrdma_fixed_maxsz * sizeof(*p));
@@ -676,8 +1010,12 @@ static int svc_rdma_xdr_decode_req(struc
 	if (*p != rpcrdma_version)
 		goto out_version;
 	p += 2;
+#ifdef HAVE_SVC_RDMA_PCL
 	rctxt->rc_msgtype = *p;
 	switch (rctxt->rc_msgtype) {
+#else
+	switch (*p) {
+#endif
 	case rdma_msg:
 		break;
 	case rdma_nomsg:
@@ -701,27 +1039,39 @@ static int svc_rdma_xdr_decode_req(struc
 	hdr_len = xdr_stream_pos(&rctxt->rc_stream);
 	rq_arg->head[0].iov_len -= hdr_len;
 	rq_arg->len -= hdr_len;
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_decode_rqst(rctxt, rdma_argp, hdr_len);
+#endif
 	return hdr_len;
 
 out_short:
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_decode_short_err(rctxt, rq_arg->len);
+#endif
 	return -EINVAL;
 
 out_version:
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_decode_badvers_err(rctxt, rdma_argp);
+#endif
 	return -EPROTONOSUPPORT;
 
 out_drop:
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_decode_drop_err(rctxt, rdma_argp);
+#endif
 	return 0;
 
 out_proc:
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_decode_badproc_err(rctxt, rdma_argp);
+#endif
 	return -EINVAL;
 
 out_inval:
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_decode_parse_err(rctxt, rdma_argp);
+#endif
 	return -EINVAL;
 }
 
@@ -742,6 +1092,7 @@ static void svc_rdma_send_error(struct s
  * the RPC/RDMA header small and fixed in size, so it is
  * straightforward to check the RPC header's direction field.
  */
+#ifdef HAVE_SVC_RDMA_PCL
 static bool svc_rdma_is_reverse_direction_reply(struct svc_xprt *xprt,
 						struct svc_rdma_recv_ctxt *rctxt)
 {
@@ -768,7 +1119,38 @@ static bool svc_rdma_is_reverse_directio
 
 	return true;
 }
+#else
+static bool svc_rdma_is_backchannel_reply(struct svc_xprt *xprt,
+					  __be32 *rdma_resp)
+{
+	__be32 *p;
+
+	if (!xprt->xpt_bc_xprt)
+		return false;
+
+	p = rdma_resp + 3;
+	if (*p++ != rdma_msg)
+		return false;
+
+	if (*p++ != xdr_zero)
+		return false;
+	if (*p++ != xdr_zero)
+		return false;
+	if (*p++ != xdr_zero)
+		return false;
+
+	/* XID sanity */
+	if (*p++ != *rdma_resp)
+		return false;
+	/* call direction */
+	if (*p == cpu_to_be32(RPC_CALL))
+		return false;
+
+	return true;
+}
+#endif
 
+#ifdef HAVE_SVC_RDMA_PCL
 /* Finish constructing the RPC Call message in rqstp::rq_arg.
  *
  * The incoming RPC/RDMA message is an RDMA_MSG type message
@@ -853,7 +1235,12 @@ static noinline void svc_rdma_read_compl
 	/* Transfer the Read chunk pages into @rqstp.rq_pages, replacing
 	 * the rq_pages that were already allocated for this rqstp.
 	 */
+#ifdef HAVE_RELEASE_PAGES_IN_MM_H
 	release_pages(rqstp->rq_respages, ctxt->rc_page_count);
+#else
+	for (i = 0; i < ctxt->rc_page_count; ++i)
+		put_page(rqstp->rq_respages[i]);
+#endif
 	for (i = 0; i < ctxt->rc_page_count; i++)
 		rqstp->rq_pages[i] = ctxt->rc_pages[i];
 
@@ -882,8 +1269,40 @@ static noinline void svc_rdma_read_compl
 		svc_rdma_read_complete_pzrc(rqstp, ctxt);
 	}
 
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_svcrdma_read_finished(&ctxt->rc_cid);
+#endif
+}
+#else
+static void rdma_read_complete(struct svc_rqst *rqstp,
+                   struct svc_rdma_recv_ctxt *head)
+{
+	int page_no;
+
+	/* Move Read chunk pages to rqstp so that they will be released
+	 * when svc_process is done with them.
+	 */
+	for (page_no = 0; page_no < head->rc_page_count; page_no++) {
+		put_page(rqstp->rq_pages[page_no]);
+		rqstp->rq_pages[page_no] = head->rc_pages[page_no];
+	}
+	head->rc_page_count = 0;
+
+	/* Point rq_arg.pages past header */
+	rqstp->rq_arg.pages = &rqstp->rq_pages[head->rc_hdr_count];
+	rqstp->rq_arg.page_len = head->rc_arg.page_len;
+
+	/* rq_respages starts after the last arg page */
+	rqstp->rq_respages = &rqstp->rq_pages[page_no];
+	rqstp->rq_next_page = rqstp->rq_respages + 1;
+
+	/* Rebuild rq_arg head and tail. */
+	rqstp->rq_arg.head[0] = head->rc_arg.head[0];
+	rqstp->rq_arg.tail[0] = head->rc_arg.tail[0];
+	rqstp->rq_arg.len = head->rc_arg.len;
+	rqstp->rq_arg.buflen = head->rc_arg.buflen;
 }
+#endif
 
 /**
  * svc_rdma_recvfrom - Receive an RPC call
@@ -919,6 +1338,9 @@ int svc_rdma_recvfrom(struct svc_rqst *r
 	struct svcxprt_rdma *rdma_xprt =
 		container_of(xprt, struct svcxprt_rdma, sc_xprt);
 	struct svc_rdma_recv_ctxt *ctxt;
+#ifndef HAVE_SVC_RDMA_PCL
+	__be32 *p;
+#endif
 	int ret;
 
 	/* Prevent svc_xprt_release() from releasing pages in rq_pages
@@ -927,15 +1349,23 @@ int svc_rdma_recvfrom(struct svc_rqst *r
 	rqstp->rq_respages = rqstp->rq_pages;
 	rqstp->rq_next_page = rqstp->rq_respages;
 
+#ifdef HAVE_SVC_RDMA_RELEASE_RQST
 	rqstp->rq_xprt_ctxt = NULL;
+#endif
 
 	spin_lock(&rdma_xprt->sc_rq_dto_lock);
 	ctxt = svc_rdma_next_recv_ctxt(&rdma_xprt->sc_read_complete_q);
 	if (ctxt) {
 		list_del(&ctxt->rc_list);
 		spin_unlock(&rdma_xprt->sc_rq_dto_lock);
+#ifdef HAVE_SVC_RDMA_PCL
+#ifdef HAVE_SVC_XPRT_RECEIVED
 		svc_xprt_received(xprt);
+#endif
 		svc_rdma_read_complete(rqstp, ctxt);
+#else
+		rdma_read_complete(rqstp, ctxt);
+#endif
 		goto complete;
 	}
 	ctxt = svc_rdma_next_recv_ctxt(&rdma_xprt->sc_rq_dto_q);
@@ -946,8 +1376,10 @@ int svc_rdma_recvfrom(struct svc_rqst *r
 		clear_bit(XPT_DATA, &xprt->xpt_flags);
 	spin_unlock(&rdma_xprt->sc_rq_dto_lock);
 
+#ifdef HAVE_SVC_XPRT_RECEIVED
 	/* Unblock the transport for the next receive */
 	svc_xprt_received(xprt);
+#endif
 	if (!ctxt)
 		return 0;
 
@@ -957,33 +1389,60 @@ int svc_rdma_recvfrom(struct svc_rqst *r
 				   DMA_FROM_DEVICE);
 	svc_rdma_build_arg_xdr(rqstp, ctxt);
 
+#ifndef HAVE_SVC_RDMA_PCL
+	p = (__be32 *)rqstp->rq_arg.head[0].iov_base;
+#endif
 	ret = svc_rdma_xdr_decode_req(&rqstp->rq_arg, ctxt);
 	if (ret < 0)
 		goto out_err;
 	if (ret == 0)
 		goto out_drop;
+#ifdef HAVE_SVC_RQST_RQ_XPRT_HLEN
+	rqstp->rq_xprt_hlen = ret;
+#endif
 
+#ifdef HAVE_SVC_RDMA_PCL
 	if (svc_rdma_is_reverse_direction_reply(xprt, ctxt))
+#else
+	if (svc_rdma_is_backchannel_reply(xprt, p))
+#endif
 		goto out_backchannel;
 
 	svc_rdma_get_inv_rkey(rdma_xprt, ctxt);
 
+#ifdef HAVE_SVC_RDMA_PCL
 	if (!pcl_is_empty(&ctxt->rc_read_pcl) ||
 	    !pcl_is_empty(&ctxt->rc_call_pcl))
 		goto out_readlist;
+#else
+	p += rpcrdma_fixed_maxsz;
+	if (*p != xdr_zero)
+		goto out_readchunk;
+#endif
 
 complete:
 	rqstp->rq_xprt_ctxt = ctxt;
 	rqstp->rq_prot = IPPROTO_MAX;
 	svc_xprt_copy_addrs(rqstp, xprt);
+#ifndef HAVE_SVC_XPRT_XPO_SECURE_PORT
 	set_bit(RQ_SECURE, &rqstp->rq_flags);
+#endif
 	return rqstp->rq_arg.len;
 
+#ifndef HAVE_SVC_RDMA_PCL
+out_readchunk:
+	ret = svc_rdma_recv_read_chunk(rdma_xprt, rqstp, ctxt, p);
+	if (ret < 0)
+		goto out_postfail;
+	return 0;
+#endif
+
 out_err:
 	svc_rdma_send_error(rdma_xprt, ctxt, ret);
 	svc_rdma_recv_ctxt_put(rdma_xprt, ctxt);
 	return 0;
 
+#ifdef HAVE_SVC_RDMA_PCL
 out_readlist:
 	/* This @rqstp is about to be recycled. Save the work
 	 * already done constructing the Call message in rq_arg
@@ -997,10 +1456,21 @@ out_readlist:
 		if (ret == -EINVAL)
 			svc_rdma_send_error(rdma_xprt, ctxt, ret);
 		svc_rdma_recv_ctxt_put(rdma_xprt, ctxt);
+#ifdef HAVE_SVC_XPRT_DEFERRED_CLOSE
 		svc_xprt_deferred_close(xprt);
+#else
+		set_bit(XPT_CLOSE, &xprt->xpt_flags);
+#endif
 		return ret;
 	}
 	return 0;
+#else
+out_postfail:
+	if (ret == -EINVAL)
+		svc_rdma_send_error(rdma_xprt, ctxt, ret);
+	svc_rdma_recv_ctxt_put(rdma_xprt, ctxt);
+	return ret;
+#endif
 
 out_backchannel:
 	svc_rdma_handle_bc_reply(rqstp, ctxt);
