xref: /freebsd/sys/ofed/include/rdma/ib_hdrs.h (revision 47dd1d1b619cc035b82b49a91a25544309ff95ae)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3  *
4  * Copyright(c) 2016 Intel Corporation.
5  *
6  * This file is provided under a dual BSD/GPLv2 license.  When using or
7  * redistributing this file, you may do so under either license.
8  *
9  * GPL LICENSE SUMMARY
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of version 2 of the GNU General Public License as
13  * published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * BSD LICENSE
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  *
26  *  - Redistributions of source code must retain the above copyright
27  *    notice, this list of conditions and the following disclaimer.
28  *  - Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in
30  *    the documentation and/or other materials provided with the
31  *    distribution.
32  *  - Neither the name of Intel Corporation nor the names of its
33  *    contributors may be used to endorse or promote products derived
34  *    from this software without specific prior written permission.
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  *
48  * $FreeBSD$
49  */
50 
51 #ifndef IB_HDRS_H
52 #define IB_HDRS_H
53 
54 #include <linux/types.h>
55 #include <asm/unaligned.h>
56 #include <rdma/ib_verbs.h>
57 
58 #define IB_SEQ_NAK	(3 << 29)
59 
60 /* AETH NAK opcode values */
61 #define IB_RNR_NAK                      0x20
62 #define IB_NAK_PSN_ERROR                0x60
63 #define IB_NAK_INVALID_REQUEST          0x61
64 #define IB_NAK_REMOTE_ACCESS_ERROR      0x62
65 #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
66 #define IB_NAK_INVALID_RD_REQUEST       0x64
67 
68 #define IB_BTH_REQ_ACK		BIT(31)
69 #define IB_BTH_SOLICITED	BIT(23)
70 #define IB_BTH_MIG_REQ		BIT(22)
71 
72 #define IB_GRH_VERSION		6
73 #define IB_GRH_VERSION_MASK	0xF
74 #define IB_GRH_VERSION_SHIFT	28
75 #define IB_GRH_TCLASS_MASK	0xFF
76 #define IB_GRH_TCLASS_SHIFT	20
77 #define IB_GRH_FLOW_MASK	0xFFFFF
78 #define IB_GRH_FLOW_SHIFT	0
79 #define IB_GRH_NEXT_HDR		0x1B
80 
81 struct ib_reth {
82 	__be64 vaddr;        /* potentially unaligned */
83 	__be32 rkey;
84 	__be32 length;
85 } __packed;
86 
87 struct ib_atomic_eth {
88 	__be64 vaddr;        /* potentially unaligned */
89 	__be32 rkey;
90 	__be64 swap_data;    /* potentially unaligned */
91 	__be64 compare_data; /* potentially unaligned */
92 } __packed;
93 
94 union ib_ehdrs {
95 	struct {
96 		__be32 deth[2];
97 		__be32 imm_data;
98 	} ud;
99 	struct {
100 		struct ib_reth reth;
101 		__be32 imm_data;
102 	} rc;
103 	struct {
104 		__be32 aeth;
105 		__be64 atomic_ack_eth; /* potentially unaligned */
106 	} __packed at;
107 	__be32 imm_data;
108 	__be32 aeth;
109 	__be32 ieth;
110 	struct ib_atomic_eth atomic_eth;
111 }  __packed;
112 
113 struct ib_other_headers {
114 	__be32 bth[3];
115 	union ib_ehdrs u;
116 } __packed;
117 
118 struct ib_header {
119 	__be16 lrh[4];
120 	union {
121 		struct {
122 			struct ib_grh grh;
123 			struct ib_other_headers oth;
124 		} l;
125 		struct ib_other_headers oth;
126 	} u;
127 } __packed;
128 
129 /* accessors for unaligned __be64 items */
130 
131 static inline u64 ib_u64_get(__be64 *p)
132 {
133 	return get_unaligned_be64(p);
134 }
135 
136 static inline void ib_u64_put(u64 val, __be64 *p)
137 {
138 	put_unaligned_be64(val, p);
139 }
140 
141 static inline u64 get_ib_reth_vaddr(struct ib_reth *reth)
142 {
143 	return ib_u64_get(&reth->vaddr);
144 }
145 
146 static inline void put_ib_reth_vaddr(u64 val, struct ib_reth *reth)
147 {
148 	ib_u64_put(val, &reth->vaddr);
149 }
150 
151 static inline u64 get_ib_ateth_vaddr(struct ib_atomic_eth *ateth)
152 {
153 	return ib_u64_get(&ateth->vaddr);
154 }
155 
156 static inline void put_ib_ateth_vaddr(u64 val, struct ib_atomic_eth *ateth)
157 {
158 	ib_u64_put(val, &ateth->vaddr);
159 }
160 
161 static inline u64 get_ib_ateth_swap(struct ib_atomic_eth *ateth)
162 {
163 	return ib_u64_get(&ateth->swap_data);
164 }
165 
166 static inline void put_ib_ateth_swap(u64 val, struct ib_atomic_eth *ateth)
167 {
168 	ib_u64_put(val, &ateth->swap_data);
169 }
170 
171 static inline u64 get_ib_ateth_compare(struct ib_atomic_eth *ateth)
172 {
173 	return ib_u64_get(&ateth->compare_data);
174 }
175 
176 static inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth)
177 {
178 	ib_u64_put(val, &ateth->compare_data);
179 }
180 
181 #endif                          /* IB_HDRS_H */
182