blob: 9dc3a3b88391b9911c1744a47cba00bd42dfce64 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2/*
3 * Copyright (c) 2005-2006 Network Appliance, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the BSD-type
9 * license below:
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials provided
21 * with the distribution.
22 *
23 * Neither the name of the Network Appliance, Inc. nor the names of
24 * its contributors may be used to endorse or promote products
25 * derived from this software without specific prior written
26 * permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Author: Tom Tucker <tom@opengridcomputing.com>
41 */
42
43#ifndef SVC_RDMA_H
44#define SVC_RDMA_H
David Brazdil0f672f62019-12-10 10:32:29 +000045#include <linux/llist.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000046#include <linux/sunrpc/xdr.h>
47#include <linux/sunrpc/svcsock.h>
48#include <linux/sunrpc/rpc_rdma.h>
Olivier Deprez157378f2022-04-04 15:47:50 +020049#include <linux/sunrpc/rpc_rdma_cid.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000050#include <rdma/ib_verbs.h>
51#include <rdma/rdma_cm.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000052
53/* Default and maximum inline threshold sizes */
54enum {
Olivier Deprez157378f2022-04-04 15:47:50 +020055 RPCRDMA_PULLUP_THRESH = RPCRDMA_V1_DEF_INLINE_SIZE >> 1,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000056 RPCRDMA_DEF_INLINE_THRESH = 4096,
57 RPCRDMA_MAX_INLINE_THRESH = 65536
58};
59
60/* RPC/RDMA parameters and stats */
61extern unsigned int svcrdma_ord;
62extern unsigned int svcrdma_max_requests;
63extern unsigned int svcrdma_max_bc_requests;
64extern unsigned int svcrdma_max_req_size;
65
66extern atomic_t rdma_stat_recv;
67extern atomic_t rdma_stat_read;
68extern atomic_t rdma_stat_write;
69extern atomic_t rdma_stat_sq_starve;
70extern atomic_t rdma_stat_rq_starve;
71extern atomic_t rdma_stat_rq_poll;
72extern atomic_t rdma_stat_rq_prod;
73extern atomic_t rdma_stat_sq_poll;
74extern atomic_t rdma_stat_sq_prod;
75
76struct svcxprt_rdma {
77 struct svc_xprt sc_xprt; /* SVC transport structure */
78 struct rdma_cm_id *sc_cm_id; /* RDMA connection id */
79 struct list_head sc_accept_q; /* Conn. waiting accept */
80 int sc_ord; /* RDMA read limit */
81 int sc_max_send_sges;
82 bool sc_snd_w_inv; /* OK to use Send With Invalidate */
83
84 atomic_t sc_sq_avail; /* SQEs ready to be consumed */
85 unsigned int sc_sq_depth; /* Depth of SQ */
86 __be32 sc_fc_credits; /* Forward credits */
87 u32 sc_max_requests; /* Max requests */
88 u32 sc_max_bc_requests;/* Backward credits */
89 int sc_max_req_size; /* Size of each RQ WR buf */
90 u8 sc_port_num;
91
92 struct ib_pd *sc_pd;
93
94 spinlock_t sc_send_lock;
95 struct list_head sc_send_ctxts;
96 spinlock_t sc_rw_ctxt_lock;
97 struct list_head sc_rw_ctxts;
98
99 struct list_head sc_rq_dto_q;
100 spinlock_t sc_rq_dto_lock;
101 struct ib_qp *sc_qp;
102 struct ib_cq *sc_rq_cq;
103 struct ib_cq *sc_sq_cq;
104
105 spinlock_t sc_lock; /* transport lock */
106
107 wait_queue_head_t sc_send_wait; /* SQ exhaustion waitlist */
108 unsigned long sc_flags;
109 struct list_head sc_read_complete_q;
110 struct work_struct sc_work;
111
David Brazdil0f672f62019-12-10 10:32:29 +0000112 struct llist_head sc_recv_ctxts;
Olivier Deprez157378f2022-04-04 15:47:50 +0200113
114 atomic_t sc_completion_ids;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000115};
116/* sc_flags */
117#define RDMAXPRT_CONN_PENDING 3
118
David Brazdil0f672f62019-12-10 10:32:29 +0000119/*
120 * Default connection parameters
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000121 */
David Brazdil0f672f62019-12-10 10:32:29 +0000122enum {
123 RPCRDMA_LISTEN_BACKLOG = 10,
124 RPCRDMA_MAX_REQUESTS = 64,
125 RPCRDMA_MAX_BC_REQUESTS = 2,
126};
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000127
128#define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD
129
130struct svc_rdma_recv_ctxt {
David Brazdil0f672f62019-12-10 10:32:29 +0000131 struct llist_node rc_node;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000132 struct list_head rc_list;
133 struct ib_recv_wr rc_recv_wr;
134 struct ib_cqe rc_cqe;
Olivier Deprez157378f2022-04-04 15:47:50 +0200135 struct rpc_rdma_cid rc_cid;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000136 struct ib_sge rc_recv_sge;
137 void *rc_recv_buf;
138 struct xdr_buf rc_arg;
Olivier Deprez157378f2022-04-04 15:47:50 +0200139 struct xdr_stream rc_stream;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000140 bool rc_temp;
141 u32 rc_byte_len;
142 unsigned int rc_page_count;
143 unsigned int rc_hdr_count;
David Brazdil0f672f62019-12-10 10:32:29 +0000144 u32 rc_inv_rkey;
Olivier Deprez157378f2022-04-04 15:47:50 +0200145 __be32 *rc_write_list;
146 __be32 *rc_reply_chunk;
Olivier Deprez0e641232021-09-23 10:07:05 +0200147 unsigned int rc_read_payload_offset;
148 unsigned int rc_read_payload_length;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000149 struct page *rc_pages[RPCSVC_MAXPAGES];
150};
151
152struct svc_rdma_send_ctxt {
153 struct list_head sc_list;
Olivier Deprez157378f2022-04-04 15:47:50 +0200154 struct rpc_rdma_cid sc_cid;
155
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000156 struct ib_send_wr sc_send_wr;
157 struct ib_cqe sc_cqe;
Olivier Deprez157378f2022-04-04 15:47:50 +0200158 struct xdr_buf sc_hdrbuf;
159 struct xdr_stream sc_stream;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000160 void *sc_xprt_buf;
161 int sc_page_count;
162 int sc_cur_sge_no;
163 struct page *sc_pages[RPCSVC_MAXPAGES];
164 struct ib_sge sc_sges[];
165};
166
167/* svc_rdma_backchannel.c */
Olivier Deprez0e641232021-09-23 10:07:05 +0200168extern void svc_rdma_handle_bc_reply(struct svc_rqst *rqstp,
169 struct svc_rdma_recv_ctxt *rctxt);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000170
171/* svc_rdma_recvfrom.c */
172extern void svc_rdma_recv_ctxts_destroy(struct svcxprt_rdma *rdma);
173extern bool svc_rdma_post_recvs(struct svcxprt_rdma *rdma);
174extern void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma,
175 struct svc_rdma_recv_ctxt *ctxt);
176extern void svc_rdma_flush_recv_queues(struct svcxprt_rdma *rdma);
Olivier Deprez0e641232021-09-23 10:07:05 +0200177extern void svc_rdma_release_rqst(struct svc_rqst *rqstp);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000178extern int svc_rdma_recvfrom(struct svc_rqst *);
179
180/* svc_rdma_rw.c */
181extern void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma);
182extern int svc_rdma_recv_read_chunk(struct svcxprt_rdma *rdma,
183 struct svc_rqst *rqstp,
184 struct svc_rdma_recv_ctxt *head, __be32 *p);
185extern int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma,
Olivier Deprez0e641232021-09-23 10:07:05 +0200186 __be32 *wr_ch, struct xdr_buf *xdr,
187 unsigned int offset,
188 unsigned long length);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000189extern int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,
Olivier Deprez157378f2022-04-04 15:47:50 +0200190 const struct svc_rdma_recv_ctxt *rctxt,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000191 struct xdr_buf *xdr);
192
193/* svc_rdma_sendto.c */
194extern void svc_rdma_send_ctxts_destroy(struct svcxprt_rdma *rdma);
195extern struct svc_rdma_send_ctxt *
196 svc_rdma_send_ctxt_get(struct svcxprt_rdma *rdma);
197extern void svc_rdma_send_ctxt_put(struct svcxprt_rdma *rdma,
198 struct svc_rdma_send_ctxt *ctxt);
Olivier Deprez157378f2022-04-04 15:47:50 +0200199extern int svc_rdma_send(struct svcxprt_rdma *rdma,
200 struct svc_rdma_send_ctxt *ctxt);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000201extern int svc_rdma_map_reply_msg(struct svcxprt_rdma *rdma,
Olivier Deprez157378f2022-04-04 15:47:50 +0200202 struct svc_rdma_send_ctxt *sctxt,
203 const struct svc_rdma_recv_ctxt *rctxt,
204 struct xdr_buf *xdr);
205extern void svc_rdma_send_error_msg(struct svcxprt_rdma *rdma,
206 struct svc_rdma_send_ctxt *sctxt,
207 struct svc_rdma_recv_ctxt *rctxt,
208 int status);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000209extern int svc_rdma_sendto(struct svc_rqst *);
Olivier Deprez0e641232021-09-23 10:07:05 +0200210extern int svc_rdma_read_payload(struct svc_rqst *rqstp, unsigned int offset,
211 unsigned int length);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000212
213/* svc_rdma_transport.c */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000214extern struct svc_xprt_class svc_rdma_class;
215#ifdef CONFIG_SUNRPC_BACKCHANNEL
216extern struct svc_xprt_class svc_rdma_bc_class;
217#endif
218
219/* svc_rdma.c */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000220extern int svc_rdma_init(void);
221extern void svc_rdma_cleanup(void);
222
223#endif