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