svc_rdma.h 7.6 KB

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