Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v4.19-rc7 206 lines 7.4 kB view raw
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 <tom@opengridcomputing.com> 41 */ 42 43#ifndef SVC_RDMA_H 44#define SVC_RDMA_H 45#include <linux/sunrpc/xdr.h> 46#include <linux/sunrpc/svcsock.h> 47#include <linux/sunrpc/rpc_rdma.h> 48#include <rdma/ib_verbs.h> 49#include <rdma/rdma_cm.h> 50#define SVCRDMA_DEBUG 51 52/* Default and maximum inline threshold sizes */ 53enum { 54 RPCRDMA_DEF_INLINE_THRESH = 4096, 55 RPCRDMA_MAX_INLINE_THRESH = 65536 56}; 57 58/* RPC/RDMA parameters and stats */ 59extern unsigned int svcrdma_ord; 60extern unsigned int svcrdma_max_requests; 61extern unsigned int svcrdma_max_bc_requests; 62extern unsigned int svcrdma_max_req_size; 63 64extern atomic_t rdma_stat_recv; 65extern atomic_t rdma_stat_read; 66extern atomic_t rdma_stat_write; 67extern atomic_t rdma_stat_sq_starve; 68extern atomic_t rdma_stat_rq_starve; 69extern atomic_t rdma_stat_rq_poll; 70extern atomic_t rdma_stat_rq_prod; 71extern atomic_t rdma_stat_sq_poll; 72extern atomic_t rdma_stat_sq_prod; 73 74struct svcxprt_rdma { 75 struct svc_xprt sc_xprt; /* SVC transport structure */ 76 struct rdma_cm_id *sc_cm_id; /* RDMA connection id */ 77 struct list_head sc_accept_q; /* Conn. waiting accept */ 78 int sc_ord; /* RDMA read limit */ 79 int sc_max_send_sges; 80 bool sc_snd_w_inv; /* OK to use Send With Invalidate */ 81 82 atomic_t sc_sq_avail; /* SQEs ready to be consumed */ 83 unsigned int sc_sq_depth; /* Depth of SQ */ 84 __be32 sc_fc_credits; /* Forward credits */ 85 u32 sc_max_requests; /* Max requests */ 86 u32 sc_max_bc_requests;/* Backward credits */ 87 int sc_max_req_size; /* Size of each RQ WR buf */ 88 u8 sc_port_num; 89 90 struct ib_pd *sc_pd; 91 92 spinlock_t sc_send_lock; 93 struct list_head sc_send_ctxts; 94 spinlock_t sc_rw_ctxt_lock; 95 struct list_head sc_rw_ctxts; 96 97 struct list_head sc_rq_dto_q; 98 spinlock_t sc_rq_dto_lock; 99 struct ib_qp *sc_qp; 100 struct ib_cq *sc_rq_cq; 101 struct ib_cq *sc_sq_cq; 102 103 spinlock_t sc_lock; /* transport lock */ 104 105 wait_queue_head_t sc_send_wait; /* SQ exhaustion waitlist */ 106 unsigned long sc_flags; 107 struct list_head sc_read_complete_q; 108 struct work_struct sc_work; 109 110 spinlock_t sc_recv_lock; 111 struct list_head sc_recv_ctxts; 112}; 113/* sc_flags */ 114#define RDMAXPRT_CONN_PENDING 3 115 116#define RPCRDMA_LISTEN_BACKLOG 10 117#define RPCRDMA_MAX_REQUESTS 32 118 119/* Typical ULP usage of BC requests is NFSv4.1 backchannel. Our 120 * current NFSv4.1 implementation supports one backchannel slot. 121 */ 122#define RPCRDMA_MAX_BC_REQUESTS 2 123 124#define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD 125 126struct svc_rdma_recv_ctxt { 127 struct list_head rc_list; 128 struct ib_recv_wr rc_recv_wr; 129 struct ib_cqe rc_cqe; 130 struct ib_sge rc_recv_sge; 131 void *rc_recv_buf; 132 struct xdr_buf rc_arg; 133 bool rc_temp; 134 u32 rc_byte_len; 135 unsigned int rc_page_count; 136 unsigned int rc_hdr_count; 137 struct page *rc_pages[RPCSVC_MAXPAGES]; 138}; 139 140struct svc_rdma_send_ctxt { 141 struct list_head sc_list; 142 struct ib_send_wr sc_send_wr; 143 struct ib_cqe sc_cqe; 144 void *sc_xprt_buf; 145 int sc_page_count; 146 int sc_cur_sge_no; 147 struct page *sc_pages[RPCSVC_MAXPAGES]; 148 struct ib_sge sc_sges[]; 149}; 150 151/* svc_rdma_backchannel.c */ 152extern int svc_rdma_handle_bc_reply(struct rpc_xprt *xprt, 153 __be32 *rdma_resp, 154 struct xdr_buf *rcvbuf); 155 156/* svc_rdma_recvfrom.c */ 157extern void svc_rdma_recv_ctxts_destroy(struct svcxprt_rdma *rdma); 158extern bool svc_rdma_post_recvs(struct svcxprt_rdma *rdma); 159extern void svc_rdma_recv_ctxt_put(struct svcxprt_rdma *rdma, 160 struct svc_rdma_recv_ctxt *ctxt); 161extern void svc_rdma_flush_recv_queues(struct svcxprt_rdma *rdma); 162extern int svc_rdma_recvfrom(struct svc_rqst *); 163 164/* svc_rdma_rw.c */ 165extern void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma); 166extern int svc_rdma_recv_read_chunk(struct svcxprt_rdma *rdma, 167 struct svc_rqst *rqstp, 168 struct svc_rdma_recv_ctxt *head, __be32 *p); 169extern int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma, 170 __be32 *wr_ch, struct xdr_buf *xdr); 171extern int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma, 172 __be32 *rp_ch, bool writelist, 173 struct xdr_buf *xdr); 174 175/* svc_rdma_sendto.c */ 176extern void svc_rdma_send_ctxts_destroy(struct svcxprt_rdma *rdma); 177extern struct svc_rdma_send_ctxt * 178 svc_rdma_send_ctxt_get(struct svcxprt_rdma *rdma); 179extern void svc_rdma_send_ctxt_put(struct svcxprt_rdma *rdma, 180 struct svc_rdma_send_ctxt *ctxt); 181extern int svc_rdma_send(struct svcxprt_rdma *rdma, struct ib_send_wr *wr); 182extern void svc_rdma_sync_reply_hdr(struct svcxprt_rdma *rdma, 183 struct svc_rdma_send_ctxt *ctxt, 184 unsigned int len); 185extern int svc_rdma_map_reply_msg(struct svcxprt_rdma *rdma, 186 struct svc_rdma_send_ctxt *ctxt, 187 struct xdr_buf *xdr, __be32 *wr_lst); 188extern int svc_rdma_sendto(struct svc_rqst *); 189 190/* svc_rdma_transport.c */ 191extern int svc_rdma_create_listen(struct svc_serv *, int, struct sockaddr *); 192extern void svc_sq_reap(struct svcxprt_rdma *); 193extern void svc_rq_reap(struct svcxprt_rdma *); 194extern void svc_rdma_prep_reply_hdr(struct svc_rqst *); 195 196extern struct svc_xprt_class svc_rdma_class; 197#ifdef CONFIG_SUNRPC_BACKCHANNEL 198extern struct svc_xprt_class svc_rdma_bc_class; 199#endif 200 201/* svc_rdma.c */ 202extern struct workqueue_struct *svc_rdma_wq; 203extern int svc_rdma_init(void); 204extern void svc_rdma_cleanup(void); 205 206#endif