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