rpc_rdma.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /*
  3. * Copyright (c) 2015-2017 Oracle. All rights reserved.
  4. * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the BSD-type
  10. * license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * Neither the name of the Network Appliance, Inc. nor the names of
  25. * its contributors may be used to endorse or promote products
  26. * derived from this software without specific prior written
  27. * permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. */
  41. #ifndef _LINUX_SUNRPC_RPC_RDMA_H
  42. #define _LINUX_SUNRPC_RPC_RDMA_H
  43. #include <linux/types.h>
  44. #include <linux/bitops.h>
  45. #define RPCRDMA_VERSION 1
  46. #define rpcrdma_version cpu_to_be32(RPCRDMA_VERSION)
  47. enum {
  48. RPCRDMA_V1_DEF_INLINE_SIZE = 1024,
  49. };
  50. /*
  51. * XDR sizes, in quads
  52. */
  53. enum {
  54. rpcrdma_fixed_maxsz = 4,
  55. rpcrdma_segment_maxsz = 4,
  56. rpcrdma_readseg_maxsz = 1 + rpcrdma_segment_maxsz,
  57. rpcrdma_readchunk_maxsz = 1 + rpcrdma_readseg_maxsz,
  58. };
  59. /*
  60. * Smallest RPC/RDMA header: rm_xid through rm_type, then rm_nochunks
  61. */
  62. #define RPCRDMA_HDRLEN_MIN (sizeof(__be32) * 7)
  63. #define RPCRDMA_HDRLEN_ERR (sizeof(__be32) * 5)
  64. enum rpcrdma_errcode {
  65. ERR_VERS = 1,
  66. ERR_CHUNK = 2
  67. };
  68. enum rpcrdma_proc {
  69. RDMA_MSG = 0, /* An RPC call or reply msg */
  70. RDMA_NOMSG = 1, /* An RPC call or reply msg - separate body */
  71. RDMA_MSGP = 2, /* An RPC call or reply msg with padding */
  72. RDMA_DONE = 3, /* Client signals reply completion */
  73. RDMA_ERROR = 4 /* An RPC RDMA encoding error */
  74. };
  75. #define rdma_msg cpu_to_be32(RDMA_MSG)
  76. #define rdma_nomsg cpu_to_be32(RDMA_NOMSG)
  77. #define rdma_msgp cpu_to_be32(RDMA_MSGP)
  78. #define rdma_done cpu_to_be32(RDMA_DONE)
  79. #define rdma_error cpu_to_be32(RDMA_ERROR)
  80. #define err_vers cpu_to_be32(ERR_VERS)
  81. #define err_chunk cpu_to_be32(ERR_CHUNK)
  82. /*
  83. * Private extension to RPC-over-RDMA Version One.
  84. * Message passed during RDMA-CM connection set-up.
  85. *
  86. * Add new fields at the end, and don't permute existing
  87. * fields.
  88. */
  89. struct rpcrdma_connect_private {
  90. __be32 cp_magic;
  91. u8 cp_version;
  92. u8 cp_flags;
  93. u8 cp_send_size;
  94. u8 cp_recv_size;
  95. } __packed;
  96. #define rpcrdma_cmp_magic __cpu_to_be32(0xf6ab0e18)
  97. enum {
  98. RPCRDMA_CMP_VERSION = 1,
  99. RPCRDMA_CMP_F_SND_W_INV_OK = BIT(0),
  100. };
  101. static inline u8
  102. rpcrdma_encode_buffer_size(unsigned int size)
  103. {
  104. return (size >> 10) - 1;
  105. }
  106. static inline unsigned int
  107. rpcrdma_decode_buffer_size(u8 val)
  108. {
  109. return ((unsigned int)val + 1) << 10;
  110. }
  111. /**
  112. * xdr_encode_rdma_segment - Encode contents of an RDMA segment
  113. * @p: Pointer into a send buffer
  114. * @handle: The RDMA handle to encode
  115. * @length: The RDMA length to encode
  116. * @offset: The RDMA offset to encode
  117. *
  118. * Return value:
  119. * Pointer to the XDR position that follows the encoded RDMA segment
  120. */
  121. static inline __be32 *xdr_encode_rdma_segment(__be32 *p, u32 handle,
  122. u32 length, u64 offset)
  123. {
  124. *p++ = cpu_to_be32(handle);
  125. *p++ = cpu_to_be32(length);
  126. return xdr_encode_hyper(p, offset);
  127. }
  128. /**
  129. * xdr_encode_read_segment - Encode contents of a Read segment
  130. * @p: Pointer into a send buffer
  131. * @position: The position to encode
  132. * @handle: The RDMA handle to encode
  133. * @length: The RDMA length to encode
  134. * @offset: The RDMA offset to encode
  135. *
  136. * Return value:
  137. * Pointer to the XDR position that follows the encoded Read segment
  138. */
  139. static inline __be32 *xdr_encode_read_segment(__be32 *p, u32 position,
  140. u32 handle, u32 length,
  141. u64 offset)
  142. {
  143. *p++ = cpu_to_be32(position);
  144. return xdr_encode_rdma_segment(p, handle, length, offset);
  145. }
  146. /**
  147. * xdr_decode_rdma_segment - Decode contents of an RDMA segment
  148. * @p: Pointer to the undecoded RDMA segment
  149. * @handle: Upon return, the RDMA handle
  150. * @length: Upon return, the RDMA length
  151. * @offset: Upon return, the RDMA offset
  152. *
  153. * Return value:
  154. * Pointer to the XDR item that follows the RDMA segment
  155. */
  156. static inline __be32 *xdr_decode_rdma_segment(__be32 *p, u32 *handle,
  157. u32 *length, u64 *offset)
  158. {
  159. *handle = be32_to_cpup(p++);
  160. *length = be32_to_cpup(p++);
  161. return xdr_decode_hyper(p, offset);
  162. }
  163. /**
  164. * xdr_decode_read_segment - Decode contents of a Read segment
  165. * @p: Pointer to the undecoded Read segment
  166. * @position: Upon return, the segment's position
  167. * @handle: Upon return, the RDMA handle
  168. * @length: Upon return, the RDMA length
  169. * @offset: Upon return, the RDMA offset
  170. *
  171. * Return value:
  172. * Pointer to the XDR item that follows the Read segment
  173. */
  174. static inline __be32 *xdr_decode_read_segment(__be32 *p, u32 *position,
  175. u32 *handle, u32 *length,
  176. u64 *offset)
  177. {
  178. *position = be32_to_cpup(p++);
  179. return xdr_decode_rdma_segment(p, handle, length, offset);
  180. }
  181. #endif /* _LINUX_SUNRPC_RPC_RDMA_H */