From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: net/sunrpc/xprtrdma/xprt_rdma.h

Change-Id: I6aa2f3174e853844afaffa9321b3aa73319c34b5
---
 net/sunrpc/xprtrdma/xprt_rdma.h | 86 +++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

--- a/net/sunrpc/xprtrdma/xprt_rdma.h
+++ b/net/sunrpc/xprtrdma/xprt_rdma.h
@@ -310,7 +310,9 @@ enum {
 struct rpcrdma_buffer;
 struct rpcrdma_req {
 	struct list_head	rl_list;
+#ifdef HAVE_RPC_XPRT_OPS_FREE_SLOT
 	struct rpc_rqst		rl_slot;
+#endif
 	struct rpcrdma_rep	*rl_reply;
 	struct xdr_stream	rl_stream;
 	struct xdr_buf		rl_hdrbuf;
@@ -320,6 +322,10 @@ struct rpcrdma_req {
 	struct rpcrdma_regbuf	*rl_sendbuf;	/* rq_snd_buf */
 	struct rpcrdma_regbuf	*rl_recvbuf;	/* rq_rcv_buf */
 
+#if !defined(HAVE_RPC_XPRT_OPS_FREE_SLOT) || !defined(HAVE_XPRT_PIN_RQST)
+	__be32			    rl_xid;
+#endif
+
 	struct list_head	rl_all;
 	struct kref		rl_kref;
 
@@ -328,10 +334,22 @@ struct rpcrdma_req {
 	struct rpcrdma_mr_seg	rl_segments[RPCRDMA_MAX_SEGS];
 };
 
+#ifndef HAVE_RPC_XPRT_OPS_FREE_SLOT
+static inline void
+rpcrdma_set_xprtdata(struct rpc_rqst *rqst, struct rpcrdma_req *req)
+{
+	rqst->rq_xprtdata = req;
+}
+#endif
+
 static inline struct rpcrdma_req *
 rpcr_to_rdmar(const struct rpc_rqst *rqst)
 {
+#ifdef HAVE_RPC_XPRT_OPS_FREE_SLOT
 	return container_of(rqst, struct rpcrdma_req, rl_slot);
+#else
+	return rqst->rq_xprtdata;
+#endif
 }
 
 static inline void
@@ -362,11 +380,18 @@ struct rpcrdma_buffer {
 	struct list_head	rb_send_bufs;
 	struct list_head	rb_mrs;
 
+#ifndef HAVE_XPRT_WAIT_FOR_BUFFER_SPACE_RQST_ARG
+	unsigned long		rb_flags;
+#endif
 	unsigned long		rb_sc_head;
 	unsigned long		rb_sc_tail;
 	unsigned long		rb_sc_last;
 	struct rpcrdma_sendctx	**rb_sc_ctxs;
 
+#ifndef HAVE_XPRT_PIN_RQST
+	struct list_head	rb_pending;
+#endif
+
 	struct list_head	rb_allreqs;
 	struct list_head	rb_all_mrs;
 	struct list_head	rb_all_reps;
@@ -382,6 +407,38 @@ struct rpcrdma_buffer {
 	struct work_struct	rb_refresh_worker;
 };
 
+#ifndef HAVE_XPRT_PIN_RQST
+static inline void
+rpcrdma_insert_req(struct rpcrdma_buffer *buffers, struct rpcrdma_req *req)
+{
+	spin_lock(&buffers->rb_lock);
+	if (list_empty(&req->rl_list))
+		list_add_tail(&req->rl_list, &buffers->rb_pending);
+	spin_unlock(&buffers->rb_lock);
+}
+
+static inline struct rpcrdma_req *
+rpcrdma_lookup_req_locked(struct rpcrdma_buffer *buffers, __be32 xid)
+{
+	struct rpcrdma_req *pos;
+
+	list_for_each_entry(pos, &buffers->rb_pending, rl_list)
+	if (pos->rl_xid == xid)
+		return pos;
+	return NULL;
+}
+
+static inline void
+rpcrdma_remove_req(struct rpcrdma_buffer *buffers, struct rpcrdma_req *req)
+{
+	spin_lock(&buffers->rb_lock);
+	list_del(&req->rl_list);
+	spin_unlock(&buffers->rb_lock);
+}
+
+void rpcrdma_recv_buffer_put_locked(struct rpcrdma_rep *rep);
+#endif
+
 /*
  * Statistics for RPCRDMA
  */
@@ -426,7 +483,9 @@ struct rpcrdma_xprt {
 	struct rpcrdma_ep	*rx_ep;
 	struct rpcrdma_buffer	rx_buf;
 	struct delayed_work	rx_connect_worker;
+#ifdef HAVE_XPRT_RECONNECT_DELAY
 	struct rpc_timeout	rx_timeout;
+#endif
 	struct rpcrdma_stats	rx_stats;
 };
 
@@ -454,6 +513,13 @@ extern int xprt_rdma_pad_optimize;
  */
 extern unsigned int xprt_rdma_memreg_strategy;
 
+#ifndef HAVE_XPRT_WAIT_FOR_BUFFER_SPACE_RQST_ARG
+/* rb_flags */
+enum {
+	RPCRDMA_BUF_F_EMPTY_SCQ = 0,
+};
+#endif
+
 /*
  * Endpoint calls - xprtrdma/verbs.c
  */
@@ -572,6 +638,21 @@ static inline void rpcrdma_set_xdrlen(st
 	xdr->len = len;
 }
 
+#ifndef HAVE_XDR_STREAM_REMAINING
+/**
+ * xdr_stream_remaining - Return the number of bytes remaining in the stream
+ * @xdr: pointer to struct xdr_stream
+ *
+ * Return value:
+ *   Number of bytes remaining in @xdr before xdr->end
+ */
+static inline size_t
+xdr_stream_remaining(const struct xdr_stream *xdr)
+{
+	return xdr->nwords << 2;
+}
+#endif
+
 /* RPC/RDMA module init - xprtrdma/transport.c
  */
 extern unsigned int xprt_rdma_max_inline_read;
@@ -587,8 +668,13 @@ void xprt_rdma_cleanup(void);
  */
 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
 int xprt_rdma_bc_setup(struct rpc_xprt *, unsigned int);
+#ifdef HAVE_RPC_XPRT_OPS_BC_UP
+int xprt_rdma_bc_up(struct svc_serv *, struct net *);
+#endif
 size_t xprt_rdma_bc_maxpayload(struct rpc_xprt *);
+#ifdef HAVE_RPC_XPRT_OPS_BC_NUM_SLOTS
 unsigned int xprt_rdma_bc_max_slots(struct rpc_xprt *);
+#endif
 int rpcrdma_bc_post_recv(struct rpcrdma_xprt *, unsigned int);
 void rpcrdma_bc_receive_call(struct rpcrdma_xprt *, struct rpcrdma_rep *);
 int xprt_rdma_bc_send_reply(struct rpc_rqst *rqst);
