]> Git Repo - linux.git/blob - include/linux/sunrpc/svc_rdma.h
scsi: ibmvfc: Complete commands outside the host/queue lock
[linux.git] / include / linux / sunrpc / svc_rdma.h
1 /* 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 <[email protected]>
41  */
42
43 #ifndef SVC_RDMA_H
44 #define SVC_RDMA_H
45 #include <linux/llist.h>
46 #include <linux/sunrpc/xdr.h>
47 #include <linux/sunrpc/svcsock.h>
48 #include <linux/sunrpc/rpc_rdma.h>
49 #include <linux/sunrpc/rpc_rdma_cid.h>
50 #include <linux/sunrpc/svc_rdma_pcl.h>
51
52 #include <rdma/ib_verbs.h>
53 #include <rdma/rdma_cm.h>
54
55 /* Default and maximum inline threshold sizes */
56 enum {
57         RPCRDMA_PULLUP_THRESH = RPCRDMA_V1_DEF_INLINE_SIZE >> 1,
58         RPCRDMA_DEF_INLINE_THRESH = 4096,
59         RPCRDMA_MAX_INLINE_THRESH = 65536
60 };
61
62 /* RPC/RDMA parameters and stats */
63 extern unsigned int svcrdma_ord;
64 extern unsigned int svcrdma_max_requests;
65 extern unsigned int svcrdma_max_bc_requests;
66 extern unsigned int svcrdma_max_req_size;
67
68 extern atomic_t rdma_stat_recv;
69 extern atomic_t rdma_stat_read;
70 extern atomic_t rdma_stat_write;
71 extern atomic_t rdma_stat_sq_starve;
72 extern atomic_t rdma_stat_rq_starve;
73 extern atomic_t rdma_stat_rq_poll;
74 extern atomic_t rdma_stat_rq_prod;
75 extern atomic_t rdma_stat_sq_poll;
76 extern atomic_t rdma_stat_sq_prod;
77
78 struct svcxprt_rdma {
79         struct svc_xprt      sc_xprt;           /* SVC transport structure */
80         struct rdma_cm_id    *sc_cm_id;         /* RDMA connection id */
81         struct list_head     sc_accept_q;       /* Conn. waiting accept */
82         int                  sc_ord;            /* RDMA read limit */
83         int                  sc_max_send_sges;
84         bool                 sc_snd_w_inv;      /* OK to use Send With Invalidate */
85
86         atomic_t             sc_sq_avail;       /* SQEs ready to be consumed */
87         unsigned int         sc_sq_depth;       /* Depth of SQ */
88         __be32               sc_fc_credits;     /* Forward credits */
89         u32                  sc_max_requests;   /* Max requests */
90         u32                  sc_max_bc_requests;/* Backward credits */
91         int                  sc_max_req_size;   /* Size of each RQ WR buf */
92         u8                   sc_port_num;
93
94         struct ib_pd         *sc_pd;
95
96         spinlock_t           sc_send_lock;
97         struct list_head     sc_send_ctxts;
98         spinlock_t           sc_rw_ctxt_lock;
99         struct list_head     sc_rw_ctxts;
100
101         struct list_head     sc_rq_dto_q;
102         spinlock_t           sc_rq_dto_lock;
103         struct ib_qp         *sc_qp;
104         struct ib_cq         *sc_rq_cq;
105         struct ib_cq         *sc_sq_cq;
106
107         spinlock_t           sc_lock;           /* transport lock */
108
109         wait_queue_head_t    sc_send_wait;      /* SQ exhaustion waitlist */
110         unsigned long        sc_flags;
111         struct list_head     sc_read_complete_q;
112         struct work_struct   sc_work;
113
114         struct llist_head    sc_recv_ctxts;
115
116         atomic_t             sc_completion_ids;
117 };
118 /* sc_flags */
119 #define RDMAXPRT_CONN_PENDING   3
120
121 /*
122  * Default connection parameters
123  */
124 enum {
125         RPCRDMA_LISTEN_BACKLOG  = 10,
126         RPCRDMA_MAX_REQUESTS    = 64,
127         RPCRDMA_MAX_BC_REQUESTS = 2,
128 };
129
130 #define RPCSVC_MAXPAYLOAD_RDMA  RPCSVC_MAXPAYLOAD
131
132 struct svc_rdma_recv_ctxt {
133         struct llist_node       rc_node;
134         struct list_head        rc_list;
135         struct ib_recv_wr       rc_recv_wr;
136         struct ib_cqe           rc_cqe;
137         struct rpc_rdma_cid     rc_cid;
138         struct ib_sge           rc_recv_sge;
139         void                    *rc_recv_buf;
140         struct xdr_buf          rc_arg;
141         struct xdr_stream       rc_stream;
142         bool                    rc_temp;
143         u32                     rc_byte_len;
144         unsigned int            rc_page_count;
145         unsigned int            rc_hdr_count;
146         u32                     rc_inv_rkey;
147         __be32                  rc_msgtype;
148
149         struct svc_rdma_pcl     rc_call_pcl;
150
151         struct svc_rdma_pcl     rc_read_pcl;
152         struct svc_rdma_chunk   *rc_cur_result_payload;
153         struct svc_rdma_pcl     rc_write_pcl;
154         struct svc_rdma_pcl     rc_reply_pcl;
155
156         struct page             *rc_pages[RPCSVC_MAXPAGES];
157 };
158
159 struct svc_rdma_send_ctxt {
160         struct list_head        sc_list;
161         struct rpc_rdma_cid     sc_cid;
162
163         struct ib_send_wr       sc_send_wr;
164         struct ib_cqe           sc_cqe;
165         struct xdr_buf          sc_hdrbuf;
166         struct xdr_stream       sc_stream;
167         void                    *sc_xprt_buf;
168         int                     sc_page_count;
169         int                     sc_cur_sge_no;
170         struct page             *sc_pages[RPCSVC_MAXPAGES];
171         struct ib_sge           sc_sges[];
172 };
173
174 /* svc_rdma_backchannel.c */
175 extern void svc_rdma_handle_bc_reply(struct svc_rqst *rqstp,
176                                      struct svc_rdma_recv_ctxt *rctxt);
177
178 /* svc_rdma_recvfrom.c */
179 extern void svc_rdma_recv_ctxts_destroy(struct svcxprt_rdma *rdma);
180 extern bool svc_rdma_post_recvs(struct svcxprt_rdma *rdma);
181 extern struct svc_rdma_recv_ctxt *
182                 svc_rdma_recv_ctxt_get(struct svcxprt_rdma *rdma);
183 extern void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma,
184                                    struct svc_rdma_recv_ctxt *ctxt);
185 extern void svc_rdma_flush_recv_queues(struct svcxprt_rdma *rdma);
186 extern void svc_rdma_release_rqst(struct svc_rqst *rqstp);
187 extern int svc_rdma_recvfrom(struct svc_rqst *);
188
189 /* svc_rdma_rw.c */
190 extern void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma);
191 extern int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma,
192                                      const struct svc_rdma_chunk *chunk,
193                                      const struct xdr_buf *xdr);
194 extern int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,
195                                      const struct svc_rdma_recv_ctxt *rctxt,
196                                      const struct xdr_buf *xdr);
197 extern int svc_rdma_process_read_list(struct svcxprt_rdma *rdma,
198                                       struct svc_rqst *rqstp,
199                                       struct svc_rdma_recv_ctxt *head);
200
201 /* svc_rdma_sendto.c */
202 extern void svc_rdma_send_ctxts_destroy(struct svcxprt_rdma *rdma);
203 extern struct svc_rdma_send_ctxt *
204                 svc_rdma_send_ctxt_get(struct svcxprt_rdma *rdma);
205 extern void svc_rdma_send_ctxt_put(struct svcxprt_rdma *rdma,
206                                    struct svc_rdma_send_ctxt *ctxt);
207 extern int svc_rdma_send(struct svcxprt_rdma *rdma,
208                          struct svc_rdma_send_ctxt *ctxt);
209 extern int svc_rdma_map_reply_msg(struct svcxprt_rdma *rdma,
210                                   struct svc_rdma_send_ctxt *sctxt,
211                                   const struct svc_rdma_recv_ctxt *rctxt,
212                                   const struct xdr_buf *xdr);
213 extern void svc_rdma_send_error_msg(struct svcxprt_rdma *rdma,
214                                     struct svc_rdma_send_ctxt *sctxt,
215                                     struct svc_rdma_recv_ctxt *rctxt,
216                                     int status);
217 extern int svc_rdma_sendto(struct svc_rqst *);
218 extern int svc_rdma_result_payload(struct svc_rqst *rqstp, unsigned int offset,
219                                    unsigned int length);
220
221 /* svc_rdma_transport.c */
222 extern struct svc_xprt_class svc_rdma_class;
223 #ifdef CONFIG_SUNRPC_BACKCHANNEL
224 extern struct svc_xprt_class svc_rdma_bc_class;
225 #endif
226
227 /* svc_rdma.c */
228 extern int svc_rdma_init(void);
229 extern void svc_rdma_cleanup(void);
230
231 #endif
This page took 0.046611 seconds and 4 git commands to generate.