Chuck Lever | bcf3ffd | 2018-05-07 15:26:55 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 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 |
Chuck Lever | 4866073 | 2019-08-16 17:49:38 -0400 | [diff] [blame] | 45 | #include <linux/llist.h> |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 46 | #include <linux/sunrpc/xdr.h> |
| 47 | #include <linux/sunrpc/svcsock.h> |
| 48 | #include <linux/sunrpc/rpc_rdma.h> |
| 49 | #include <rdma/ib_verbs.h> |
| 50 | #include <rdma/rdma_cm.h> |
| 51 | #define SVCRDMA_DEBUG |
| 52 | |
Chuck Lever | ded8d19 | 2017-04-09 13:06:57 -0400 | [diff] [blame] | 53 | /* Default and maximum inline threshold sizes */ |
| 54 | enum { |
Chuck Lever | 0dabe94 | 2020-03-03 13:28:14 -0500 | [diff] [blame] | 55 | RPCRDMA_PULLUP_THRESH = RPCRDMA_V1_DEF_INLINE_SIZE >> 1, |
Chuck Lever | ded8d19 | 2017-04-09 13:06:57 -0400 | [diff] [blame] | 56 | RPCRDMA_DEF_INLINE_THRESH = 4096, |
| 57 | RPCRDMA_MAX_INLINE_THRESH = 65536 |
| 58 | }; |
| 59 | |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 60 | /* RPC/RDMA parameters and stats */ |
| 61 | extern unsigned int svcrdma_ord; |
| 62 | extern unsigned int svcrdma_max_requests; |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 63 | extern unsigned int svcrdma_max_bc_requests; |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 64 | extern unsigned int svcrdma_max_req_size; |
| 65 | |
| 66 | extern atomic_t rdma_stat_recv; |
| 67 | extern atomic_t rdma_stat_read; |
| 68 | extern atomic_t rdma_stat_write; |
| 69 | extern atomic_t rdma_stat_sq_starve; |
| 70 | extern atomic_t rdma_stat_rq_starve; |
| 71 | extern atomic_t rdma_stat_rq_poll; |
| 72 | extern atomic_t rdma_stat_rq_prod; |
| 73 | extern atomic_t rdma_stat_sq_poll; |
| 74 | extern atomic_t rdma_stat_sq_prod; |
| 75 | |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 76 | struct 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 */ |
Chuck Lever | 25fd86e | 2018-05-07 15:28:09 -0400 | [diff] [blame] | 81 | int sc_max_send_sges; |
Chuck Lever | 25d55296 | 2016-09-13 10:53:23 -0400 | [diff] [blame] | 82 | bool sc_snd_w_inv; /* OK to use Send With Invalidate */ |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 83 | |
Chuck Lever | e4eb42c | 2016-11-29 11:04:50 -0500 | [diff] [blame] | 84 | atomic_t sc_sq_avail; /* SQEs ready to be consumed */ |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 85 | unsigned int sc_sq_depth; /* Depth of SQ */ |
Chuck Lever | 98fc21d | 2017-02-07 11:58:23 -0500 | [diff] [blame] | 86 | __be32 sc_fc_credits; /* Forward credits */ |
| 87 | u32 sc_max_requests; /* Max requests */ |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 88 | u32 sc_max_bc_requests;/* Backward credits */ |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 89 | int sc_max_req_size; /* Size of each RQ WR buf */ |
Chuck Lever | f13193f | 2017-04-09 13:06:16 -0400 | [diff] [blame] | 90 | u8 sc_port_num; |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 91 | |
| 92 | struct ib_pd *sc_pd; |
| 93 | |
Chuck Lever | 4201c746 | 2018-05-07 15:28:04 -0400 | [diff] [blame] | 94 | spinlock_t sc_send_lock; |
| 95 | struct list_head sc_send_ctxts; |
Chuck Lever | f13193f | 2017-04-09 13:06:16 -0400 | [diff] [blame] | 96 | spinlock_t sc_rw_ctxt_lock; |
| 97 | struct list_head sc_rw_ctxts; |
Chuck Lever | cc886c9 | 2016-01-07 14:49:12 -0500 | [diff] [blame] | 98 | |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 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; |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 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; |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 109 | struct list_head sc_read_complete_q; |
Tom Tucker | 8da91ea | 2008-04-30 22:00:46 -0500 | [diff] [blame] | 110 | struct work_struct sc_work; |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 111 | |
Chuck Lever | 4866073 | 2019-08-16 17:49:38 -0400 | [diff] [blame] | 112 | struct llist_head sc_recv_ctxts; |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 113 | }; |
| 114 | /* sc_flags */ |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 115 | #define RDMAXPRT_CONN_PENDING 3 |
| 116 | |
Chuck Lever | 3ae2cefb | 2018-10-01 14:16:11 -0400 | [diff] [blame] | 117 | /* |
| 118 | * Default connection parameters |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 119 | */ |
Chuck Lever | 3ae2cefb | 2018-10-01 14:16:11 -0400 | [diff] [blame] | 120 | enum { |
| 121 | RPCRDMA_LISTEN_BACKLOG = 10, |
| 122 | RPCRDMA_MAX_REQUESTS = 64, |
| 123 | RPCRDMA_MAX_BC_REQUESTS = 2, |
| 124 | }; |
Chuck Lever | 03fe993 | 2016-01-07 14:50:02 -0500 | [diff] [blame] | 125 | |
Chuck Lever | cc9a903 | 2015-08-07 16:55:46 -0400 | [diff] [blame] | 126 | #define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD |
| 127 | |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 128 | struct svc_rdma_recv_ctxt { |
Chuck Lever | 4866073 | 2019-08-16 17:49:38 -0400 | [diff] [blame] | 129 | struct llist_node rc_node; |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 130 | struct list_head rc_list; |
| 131 | struct ib_recv_wr rc_recv_wr; |
| 132 | struct ib_cqe rc_cqe; |
Chuck Lever | 3316f06 | 2018-05-07 15:27:43 -0400 | [diff] [blame] | 133 | struct ib_sge rc_recv_sge; |
| 134 | void *rc_recv_buf; |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 135 | struct xdr_buf rc_arg; |
Chuck Lever | e604aad | 2020-03-02 15:01:08 -0500 | [diff] [blame] | 136 | struct xdr_stream rc_stream; |
Chuck Lever | eb5d7a6 | 2018-05-07 15:27:48 -0400 | [diff] [blame] | 137 | bool rc_temp; |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 138 | u32 rc_byte_len; |
| 139 | unsigned int rc_page_count; |
| 140 | unsigned int rc_hdr_count; |
Chuck Lever | 97bce63 | 2018-11-27 11:11:35 -0500 | [diff] [blame] | 141 | u32 rc_inv_rkey; |
Chuck Lever | 2fe8c44 | 2020-03-02 15:01:08 -0500 | [diff] [blame] | 142 | __be32 *rc_write_list; |
| 143 | __be32 *rc_reply_chunk; |
Chuck Lever | 4120553 | 2020-03-02 14:45:53 -0500 | [diff] [blame] | 144 | unsigned int rc_read_payload_offset; |
| 145 | unsigned int rc_read_payload_length; |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 146 | struct page *rc_pages[RPCSVC_MAXPAGES]; |
| 147 | }; |
| 148 | |
Chuck Lever | 4201c746 | 2018-05-07 15:28:04 -0400 | [diff] [blame] | 149 | struct svc_rdma_send_ctxt { |
| 150 | struct list_head sc_list; |
| 151 | struct ib_send_wr sc_send_wr; |
| 152 | struct ib_cqe sc_cqe; |
Chuck Lever | 6fd5034 | 2020-03-02 15:02:20 -0500 | [diff] [blame] | 153 | struct xdr_buf sc_hdrbuf; |
| 154 | struct xdr_stream sc_stream; |
Chuck Lever | 99722fe | 2018-05-07 15:28:25 -0400 | [diff] [blame] | 155 | void *sc_xprt_buf; |
Chuck Lever | 4201c746 | 2018-05-07 15:28:04 -0400 | [diff] [blame] | 156 | int sc_page_count; |
Chuck Lever | 25fd86e | 2018-05-07 15:28:09 -0400 | [diff] [blame] | 157 | int sc_cur_sge_no; |
Chuck Lever | 4201c746 | 2018-05-07 15:28:04 -0400 | [diff] [blame] | 158 | struct page *sc_pages[RPCSVC_MAXPAGES]; |
Chuck Lever | 25fd86e | 2018-05-07 15:28:09 -0400 | [diff] [blame] | 159 | struct ib_sge sc_sges[]; |
Chuck Lever | 4201c746 | 2018-05-07 15:28:04 -0400 | [diff] [blame] | 160 | }; |
| 161 | |
Chuck Lever | 5d252f9 | 2016-01-07 14:50:10 -0500 | [diff] [blame] | 162 | /* svc_rdma_backchannel.c */ |
| 163 | extern int svc_rdma_handle_bc_reply(struct rpc_xprt *xprt, |
Chuck Lever | f5821c7 | 2017-04-09 13:06:49 -0400 | [diff] [blame] | 164 | __be32 *rdma_resp, |
Chuck Lever | 5d252f9 | 2016-01-07 14:50:10 -0500 | [diff] [blame] | 165 | struct xdr_buf *rcvbuf); |
| 166 | |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 167 | /* svc_rdma_recvfrom.c */ |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 168 | extern void svc_rdma_recv_ctxts_destroy(struct svcxprt_rdma *rdma); |
| 169 | extern bool svc_rdma_post_recvs(struct svcxprt_rdma *rdma); |
| 170 | extern void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma, |
Chuck Lever | 1e5f416 | 2018-05-07 15:27:32 -0400 | [diff] [blame] | 171 | struct svc_rdma_recv_ctxt *ctxt); |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 172 | extern void svc_rdma_flush_recv_queues(struct svcxprt_rdma *rdma); |
Chuck Lever | 23cf1ee | 2020-03-31 17:02:33 -0400 | [diff] [blame] | 173 | extern void svc_rdma_release_rqst(struct svc_rqst *rqstp); |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 174 | extern int svc_rdma_recvfrom(struct svc_rqst *); |
| 175 | |
Chuck Lever | f13193f | 2017-04-09 13:06:16 -0400 | [diff] [blame] | 176 | /* svc_rdma_rw.c */ |
| 177 | extern void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma); |
Chuck Lever | 026d958 | 2017-06-23 17:18:24 -0400 | [diff] [blame] | 178 | extern int svc_rdma_recv_read_chunk(struct svcxprt_rdma *rdma, |
| 179 | struct svc_rqst *rqstp, |
Chuck Lever | ecf85b2 | 2018-05-07 15:27:21 -0400 | [diff] [blame] | 180 | struct svc_rdma_recv_ctxt *head, __be32 *p); |
Chuck Lever | f13193f | 2017-04-09 13:06:16 -0400 | [diff] [blame] | 181 | extern int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma, |
Chuck Lever | 4120553 | 2020-03-02 14:45:53 -0500 | [diff] [blame] | 182 | __be32 *wr_ch, struct xdr_buf *xdr, |
| 183 | unsigned int offset, |
| 184 | unsigned long length); |
Chuck Lever | f13193f | 2017-04-09 13:06:16 -0400 | [diff] [blame] | 185 | extern int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma, |
Chuck Lever | 6fa5785 | 2020-03-02 15:02:19 -0500 | [diff] [blame] | 186 | const struct svc_rdma_recv_ctxt *rctxt, |
Chuck Lever | f13193f | 2017-04-09 13:06:16 -0400 | [diff] [blame] | 187 | struct xdr_buf *xdr); |
| 188 | |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 189 | /* svc_rdma_sendto.c */ |
Chuck Lever | 4201c746 | 2018-05-07 15:28:04 -0400 | [diff] [blame] | 190 | extern void svc_rdma_send_ctxts_destroy(struct svcxprt_rdma *rdma); |
| 191 | extern struct svc_rdma_send_ctxt * |
| 192 | svc_rdma_send_ctxt_get(struct svcxprt_rdma *rdma); |
| 193 | extern void svc_rdma_send_ctxt_put(struct svcxprt_rdma *rdma, |
| 194 | struct svc_rdma_send_ctxt *ctxt); |
| 195 | extern int svc_rdma_send(struct svcxprt_rdma *rdma, struct ib_send_wr *wr); |
Chuck Lever | 99722fe | 2018-05-07 15:28:25 -0400 | [diff] [blame] | 196 | extern int svc_rdma_map_reply_msg(struct svcxprt_rdma *rdma, |
Chuck Lever | 4554755 | 2020-03-02 15:02:19 -0500 | [diff] [blame] | 197 | struct svc_rdma_send_ctxt *sctxt, |
| 198 | const struct svc_rdma_recv_ctxt *rctxt, |
| 199 | struct xdr_buf *xdr); |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 200 | extern int svc_rdma_sendto(struct svc_rqst *); |
Chuck Lever | 4120553 | 2020-03-02 14:45:53 -0500 | [diff] [blame] | 201 | extern int svc_rdma_read_payload(struct svc_rqst *rqstp, unsigned int offset, |
| 202 | unsigned int length); |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 203 | |
| 204 | /* svc_rdma_transport.c */ |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 205 | extern int svc_rdma_create_listen(struct svc_serv *, int, struct sockaddr *); |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 206 | extern void svc_sq_reap(struct svcxprt_rdma *); |
| 207 | extern void svc_rq_reap(struct svcxprt_rdma *); |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 208 | |
Chuck Lever | 9468431 | 2015-10-24 17:28:16 -0400 | [diff] [blame] | 209 | extern struct svc_xprt_class svc_rdma_class; |
| 210 | #ifdef CONFIG_SUNRPC_BACKCHANNEL |
| 211 | extern struct svc_xprt_class svc_rdma_bc_class; |
| 212 | #endif |
| 213 | |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 214 | /* svc_rdma.c */ |
| 215 | extern int svc_rdma_init(void); |
| 216 | extern void svc_rdma_cleanup(void); |
| 217 | |
Tom Tucker | d21b05f | 2007-12-12 16:13:17 -0600 | [diff] [blame] | 218 | #endif |