svc_rdma.h 7.4 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
T
Tom Tucker 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*
 * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the BSD-type
 * license below:
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *      Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *      Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *
 *      Neither the name of the Network Appliance, Inc. nor the names of
 *      its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written
 *      permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Author: Tom Tucker <tom@opengridcomputing.com>
 */

#ifndef SVC_RDMA_H
#define SVC_RDMA_H
45
#include <linux/llist.h>
T
Tom Tucker 已提交
46 47 48 49 50 51
#include <linux/sunrpc/xdr.h>
#include <linux/sunrpc/svcsock.h>
#include <linux/sunrpc/rpc_rdma.h>
#include <rdma/ib_verbs.h>
#include <rdma/rdma_cm.h>

52 53
/* Default and maximum inline threshold sizes */
enum {
54
	RPCRDMA_PULLUP_THRESH = RPCRDMA_V1_DEF_INLINE_SIZE >> 1,
55 56 57 58
	RPCRDMA_DEF_INLINE_THRESH = 4096,
	RPCRDMA_MAX_INLINE_THRESH = 65536
};

T
Tom Tucker 已提交
59 60 61
/* RPC/RDMA parameters and stats */
extern unsigned int svcrdma_ord;
extern unsigned int svcrdma_max_requests;
62
extern unsigned int svcrdma_max_bc_requests;
T
Tom Tucker 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
extern unsigned int svcrdma_max_req_size;

extern atomic_t rdma_stat_recv;
extern atomic_t rdma_stat_read;
extern atomic_t rdma_stat_write;
extern atomic_t rdma_stat_sq_starve;
extern atomic_t rdma_stat_rq_starve;
extern atomic_t rdma_stat_rq_poll;
extern atomic_t rdma_stat_rq_prod;
extern atomic_t rdma_stat_sq_poll;
extern atomic_t rdma_stat_sq_prod;

struct svcxprt_rdma {
	struct svc_xprt      sc_xprt;		/* SVC transport structure */
	struct rdma_cm_id    *sc_cm_id;		/* RDMA connection id */
	struct list_head     sc_accept_q;	/* Conn. waiting accept */
	int		     sc_ord;		/* RDMA read limit */
80
	int                  sc_max_send_sges;
81
	bool		     sc_snd_w_inv;	/* OK to use Send With Invalidate */
T
Tom Tucker 已提交
82

83
	atomic_t             sc_sq_avail;	/* SQEs ready to be consumed */
84
	unsigned int	     sc_sq_depth;	/* Depth of SQ */
85 86
	__be32		     sc_fc_credits;	/* Forward credits */
	u32		     sc_max_requests;	/* Max requests */
87
	u32		     sc_max_bc_requests;/* Backward credits */
T
Tom Tucker 已提交
88
	int                  sc_max_req_size;	/* Size of each RQ WR buf */
89
	u8		     sc_port_num;
T
Tom Tucker 已提交
90 91 92

	struct ib_pd         *sc_pd;

93 94
	spinlock_t	     sc_send_lock;
	struct list_head     sc_send_ctxts;
95 96
	spinlock_t	     sc_rw_ctxt_lock;
	struct list_head     sc_rw_ctxts;
97

T
Tom Tucker 已提交
98 99 100 101 102 103 104 105 106 107 108
	struct list_head     sc_rq_dto_q;
	spinlock_t	     sc_rq_dto_lock;
	struct ib_qp         *sc_qp;
	struct ib_cq         *sc_rq_cq;
	struct ib_cq         *sc_sq_cq;

	spinlock_t	     sc_lock;		/* transport lock */

	wait_queue_head_t    sc_send_wait;	/* SQ exhaustion waitlist */
	unsigned long	     sc_flags;
	struct list_head     sc_read_complete_q;
109
	struct work_struct   sc_work;
110

111
	struct llist_head    sc_recv_ctxts;
T
Tom Tucker 已提交
112 113 114 115
};
/* sc_flags */
#define RDMAXPRT_CONN_PENDING	3

116 117
/*
 * Default connection parameters
118
 */
119 120 121 122 123
enum {
	RPCRDMA_LISTEN_BACKLOG	= 10,
	RPCRDMA_MAX_REQUESTS	= 64,
	RPCRDMA_MAX_BC_REQUESTS	= 2,
};
124

125 126
#define RPCSVC_MAXPAYLOAD_RDMA	RPCSVC_MAXPAYLOAD

127
struct svc_rdma_recv_ctxt {
128
	struct llist_node	rc_node;
129 130 131
	struct list_head	rc_list;
	struct ib_recv_wr	rc_recv_wr;
	struct ib_cqe		rc_cqe;
132 133
	struct ib_sge		rc_recv_sge;
	void			*rc_recv_buf;
134
	struct xdr_buf		rc_arg;
135
	struct xdr_stream	rc_stream;
136
	bool			rc_temp;
137 138 139
	u32			rc_byte_len;
	unsigned int		rc_page_count;
	unsigned int		rc_hdr_count;
140
	u32			rc_inv_rkey;
141 142
	__be32			*rc_write_list;
	__be32			*rc_reply_chunk;
143 144
	unsigned int		rc_read_payload_offset;
	unsigned int		rc_read_payload_length;
145 146 147
	struct page		*rc_pages[RPCSVC_MAXPAGES];
};

148 149 150 151
struct svc_rdma_send_ctxt {
	struct list_head	sc_list;
	struct ib_send_wr	sc_send_wr;
	struct ib_cqe		sc_cqe;
152 153
	struct xdr_buf		sc_hdrbuf;
	struct xdr_stream	sc_stream;
154
	void			*sc_xprt_buf;
155
	int			sc_page_count;
156
	int			sc_cur_sge_no;
157
	struct page		*sc_pages[RPCSVC_MAXPAGES];
158
	struct ib_sge		sc_sges[];
159 160
};

161
/* svc_rdma_backchannel.c */
162 163
extern void svc_rdma_handle_bc_reply(struct svc_rqst *rqstp,
				     struct svc_rdma_recv_ctxt *rctxt);
164

T
Tom Tucker 已提交
165
/* svc_rdma_recvfrom.c */
166 167 168
extern void svc_rdma_recv_ctxts_destroy(struct svcxprt_rdma *rdma);
extern bool svc_rdma_post_recvs(struct svcxprt_rdma *rdma);
extern void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma,
169
				   struct svc_rdma_recv_ctxt *ctxt);
170
extern void svc_rdma_flush_recv_queues(struct svcxprt_rdma *rdma);
171
extern void svc_rdma_release_rqst(struct svc_rqst *rqstp);
T
Tom Tucker 已提交
172 173
extern int svc_rdma_recvfrom(struct svc_rqst *);

174 175
/* svc_rdma_rw.c */
extern void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma);
176 177
extern int svc_rdma_recv_read_chunk(struct svcxprt_rdma *rdma,
				    struct svc_rqst *rqstp,
178
				    struct svc_rdma_recv_ctxt *head, __be32 *p);
179
extern int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma,
180 181 182
				     __be32 *wr_ch, struct xdr_buf *xdr,
				     unsigned int offset,
				     unsigned long length);
183
extern int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,
184
				     const struct svc_rdma_recv_ctxt *rctxt,
185 186
				     struct xdr_buf *xdr);

T
Tom Tucker 已提交
187
/* svc_rdma_sendto.c */
188 189 190 191 192 193
extern void svc_rdma_send_ctxts_destroy(struct svcxprt_rdma *rdma);
extern struct svc_rdma_send_ctxt *
		svc_rdma_send_ctxt_get(struct svcxprt_rdma *rdma);
extern void svc_rdma_send_ctxt_put(struct svcxprt_rdma *rdma,
				   struct svc_rdma_send_ctxt *ctxt);
extern int svc_rdma_send(struct svcxprt_rdma *rdma, struct ib_send_wr *wr);
194
extern int svc_rdma_map_reply_msg(struct svcxprt_rdma *rdma,
195 196 197
				  struct svc_rdma_send_ctxt *sctxt,
				  const struct svc_rdma_recv_ctxt *rctxt,
				  struct xdr_buf *xdr);
198 199 200 201
extern void svc_rdma_send_error_msg(struct svcxprt_rdma *rdma,
				    struct svc_rdma_send_ctxt *sctxt,
				    struct svc_rdma_recv_ctxt *rctxt,
				    int status);
T
Tom Tucker 已提交
202
extern int svc_rdma_sendto(struct svc_rqst *);
203 204
extern int svc_rdma_read_payload(struct svc_rqst *rqstp, unsigned int offset,
				 unsigned int length);
T
Tom Tucker 已提交
205 206

/* svc_rdma_transport.c */
207 208 209 210 211
extern struct svc_xprt_class svc_rdma_class;
#ifdef CONFIG_SUNRPC_BACKCHANNEL
extern struct svc_xprt_class svc_rdma_bc_class;
#endif

T
Tom Tucker 已提交
212 213 214 215 216
/* svc_rdma.c */
extern int svc_rdma_init(void);
extern void svc_rdma_cleanup(void);

#endif