rpc_rdma.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2015-2017 Oracle. All rights reserved.
  3. * Copyright (c) 2003-2007 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. #ifndef _LINUX_SUNRPC_RPC_RDMA_H
  41. #define _LINUX_SUNRPC_RPC_RDMA_H
  42. #include <linux/types.h>
  43. #include <linux/bitops.h>
  44. #define RPCRDMA_VERSION 1
  45. #define rpcrdma_version cpu_to_be32(RPCRDMA_VERSION)
  46. enum {
  47. RPCRDMA_V1_DEF_INLINE_SIZE = 1024,
  48. };
  49. /*
  50. * XDR sizes, in quads
  51. */
  52. enum {
  53. rpcrdma_fixed_maxsz = 4,
  54. rpcrdma_segment_maxsz = 4,
  55. rpcrdma_readchunk_maxsz = 2 + rpcrdma_segment_maxsz,
  56. };
  57. /*
  58. * Smallest RPC/RDMA header: rm_xid through rm_type, then rm_nochunks
  59. */
  60. #define RPCRDMA_HDRLEN_MIN (sizeof(__be32) * 7)
  61. #define RPCRDMA_HDRLEN_ERR (sizeof(__be32) * 5)
  62. enum rpcrdma_errcode {
  63. ERR_VERS = 1,
  64. ERR_CHUNK = 2
  65. };
  66. enum rpcrdma_proc {
  67. RDMA_MSG = 0, /* An RPC call or reply msg */
  68. RDMA_NOMSG = 1, /* An RPC call or reply msg - separate body */
  69. RDMA_MSGP = 2, /* An RPC call or reply msg with padding */
  70. RDMA_DONE = 3, /* Client signals reply completion */
  71. RDMA_ERROR = 4 /* An RPC RDMA encoding error */
  72. };
  73. #define rdma_msg cpu_to_be32(RDMA_MSG)
  74. #define rdma_nomsg cpu_to_be32(RDMA_NOMSG)
  75. #define rdma_msgp cpu_to_be32(RDMA_MSGP)
  76. #define rdma_done cpu_to_be32(RDMA_DONE)
  77. #define rdma_error cpu_to_be32(RDMA_ERROR)
  78. #define err_vers cpu_to_be32(ERR_VERS)
  79. #define err_chunk cpu_to_be32(ERR_CHUNK)
  80. /*
  81. * Private extension to RPC-over-RDMA Version One.
  82. * Message passed during RDMA-CM connection set-up.
  83. *
  84. * Add new fields at the end, and don't permute existing
  85. * fields.
  86. */
  87. struct rpcrdma_connect_private {
  88. __be32 cp_magic;
  89. u8 cp_version;
  90. u8 cp_flags;
  91. u8 cp_send_size;
  92. u8 cp_recv_size;
  93. } __packed;
  94. #define rpcrdma_cmp_magic __cpu_to_be32(0xf6ab0e18)
  95. enum {
  96. RPCRDMA_CMP_VERSION = 1,
  97. RPCRDMA_CMP_F_SND_W_INV_OK = BIT(0),
  98. };
  99. static inline u8
  100. rpcrdma_encode_buffer_size(unsigned int size)
  101. {
  102. return (size >> 10) - 1;
  103. }
  104. static inline unsigned int
  105. rpcrdma_decode_buffer_size(u8 val)
  106. {
  107. return ((unsigned int)val + 1) << 10;
  108. }
  109. #endif /* _LINUX_SUNRPC_RPC_RDMA_H */