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

Change-Id: I096359a74420bf3dce63ff47c25ba590b45ea117
Signed-off-by: Tom Wu <tomwu@nvidia.com>
---
 net/sunrpc/xprtrdma/backchannel.c | 58 +++++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 2 deletions(-)

--- a/net/sunrpc/xprtrdma/backchannel.c
+++ b/net/sunrpc/xprtrdma/backchannel.c
@@ -11,10 +11,18 @@
 #include <linux/sunrpc/svc_rdma.h>
 
 #include "xprt_rdma.h"
+#ifdef HAVE_TRACE_RPCRDMA_H
 #include <trace/events/rpcrdma.h>
+#endif
 
 #undef RPCRDMA_BACKCHANNEL_DEBUG
 
+#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
+#ifndef RPCDBG_FACILITY
+#define RPCDBG_FACILITY    RPCDBG_TRANS
+#endif
+#endif
+
 /**
  * xprt_rdma_bc_setup - Pre-allocate resources for handling backchannel requests
  * @xprt: transport associated with these backchannel resources
@@ -27,10 +35,34 @@ int xprt_rdma_bc_setup(struct rpc_xprt *
 	struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
 
 	r_xprt->rx_buf.rb_bc_srv_max_requests = RPCRDMA_BACKWARD_WRS >> 1;
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_xprtrdma_cb_setup(r_xprt, reqs);
+#endif
 	return 0;
 }
 
+#if defined(CONFIG_SUNRPC_BACKCHANNEL) && defined(HAVE_RPC_XPRT_OPS_BC_UP)
+/**
+ * xprt_rdma_bc_up - Create transport endpoint for backchannel service
+ * @serv: server endpoint
+ * @net: network namespace
+ *
+ * The "xprt" is an implied argument: it supplies the name of the
+ * backchannel transport class.
+ *
+ * Returns zero on success, negative errno on failure
+ */
+int xprt_rdma_bc_up(struct svc_serv *serv, struct net *net)
+{
+    int ret;
+
+    ret = svc_create_xprt(serv, "rdma-bc", net, PF_INET, 0, 0);
+    if (ret < 0)
+        return ret;
+    return 0;
+}
+#endif
+
 /**
  * xprt_rdma_bc_maxpayload - Return maximum backchannel message size
  * @xprt: transport
@@ -48,10 +80,12 @@ size_t xprt_rdma_bc_maxpayload(struct rp
 	return maxmsg - RPCRDMA_HDRLEN_MIN;
 }
 
+#ifdef HAVE_RPC_XPRT_OPS_BC_NUM_SLOTS
 unsigned int xprt_rdma_bc_max_slots(struct rpc_xprt *xprt)
 {
 	return RPCRDMA_BACKWARD_WRS >> 1;
 }
+#endif
 
 static int rpcrdma_bc_marshal_reply(struct rpc_rqst *rqst)
 {
@@ -60,8 +94,13 @@ static int rpcrdma_bc_marshal_reply(stru
 	__be32 *p;
 
 	rpcrdma_set_xdrlen(&req->rl_hdrbuf, 0);
+#ifdef HAVE_XDR_INIT_ENCODE_RQST_ARG
 	xdr_init_encode(&req->rl_stream, &req->rl_hdrbuf,
 			rdmab_data(req->rl_rdmabuf), rqst);
+#else
+	xdr_init_encode(&req->rl_stream, &req->rl_hdrbuf,
+			rdmab_data(req->rl_rdmabuf));
+#endif
 
 	p = xdr_reserve_space(&req->rl_stream, 28);
 	if (unlikely(!p))
@@ -78,7 +117,9 @@ static int rpcrdma_bc_marshal_reply(stru
 				      &rqst->rq_snd_buf, rpcrdma_noch_pullup))
 		return -EIO;
 
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_xprtrdma_cb_reply(r_xprt, rqst);
+#endif
 	return 0;
 }
 
@@ -104,8 +145,10 @@ int xprt_rdma_bc_send_reply(struct rpc_r
 	if (!xprt_connected(xprt))
 		return -ENOTCONN;
 
+#ifdef HAVE_XPRT_REQUEST_GET_CONG
 	if (!xprt_request_get_cong(xprt, rqst))
 		return -EBADSLT;
+#endif
 
 	rc = rpcrdma_bc_marshal_reply(rqst);
 	if (rc < 0)
@@ -138,7 +181,6 @@ void xprt_rdma_bc_destroy(struct rpc_xpr
 		spin_unlock(&xprt->bc_pa_lock);
 
 		rpcrdma_req_destroy(rpcr_to_rdmar(rqst));
-
 		spin_lock(&xprt->bc_pa_lock);
 	}
 	spin_unlock(&xprt->bc_pa_lock);
@@ -239,7 +281,6 @@ void rpcrdma_bc_receive_call(struct rpcr
 	rqst = rpcrdma_bc_rqst_get(r_xprt);
 	if (!rqst)
 		goto out_overflow;
-
 	rqst->rq_reply_bytes_recvd = 0;
 	rqst->rq_xid = *p;
 
@@ -258,14 +299,27 @@ void rpcrdma_bc_receive_call(struct rpcr
 	 */
 	req = rpcr_to_rdmar(rqst);
 	req->rl_reply = rep;
+#ifdef HAVE_TRACE_RPCRDMA_H
 	trace_xprtrdma_cb_call(r_xprt, rqst);
+#endif
 
 	/* Queue rqst for ULP's callback service */
 	bc_serv = xprt->bc_serv;
 	xprt_get(xprt);
+#ifdef HAVE_SVC_SERV_SV_CB_LIST_LWQ
 	lwq_enqueue(&rqst->rq_bc_list, &bc_serv->sv_cb_list);
+#endif
+#ifdef HAVE_SVC_SERV_SV_CB_LIST_LIST_HEAD
+ 	spin_lock(&bc_serv->sv_cb_lock);
+ 	list_add(&rqst->rq_bc_list, &bc_serv->sv_cb_list);
+ 	spin_unlock(&bc_serv->sv_cb_lock);
+#endif
 
+#ifdef HAVE_SVC_POOL_WAKE_IDLE_THREAD
 	svc_pool_wake_idle_thread(&bc_serv->sv_pools[0]);
+#else
+ 	wake_up(&bc_serv->sv_cb_waitq);
+#endif
 
 	r_xprt->rx_stats.bcall_count++;
 	return;
