x86/speculation/mds: Fix documentation typo
[linux/fpc-iii.git] / include / rdma / ib_hdrs.h
blobc124d515f7d545951dfc105d95ba1794a987e2bf
1 /*
2 * Copyright(c) 2016 Intel Corporation.
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
7 * GPL LICENSE SUMMARY
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * BSD LICENSE
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #ifndef IB_HDRS_H
49 #define IB_HDRS_H
51 #include <linux/types.h>
52 #include <asm/unaligned.h>
53 #include <rdma/ib_verbs.h>
55 #define IB_SEQ_NAK (3 << 29)
57 /* AETH NAK opcode values */
58 #define IB_RNR_NAK 0x20
59 #define IB_NAK_PSN_ERROR 0x60
60 #define IB_NAK_INVALID_REQUEST 0x61
61 #define IB_NAK_REMOTE_ACCESS_ERROR 0x62
62 #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
63 #define IB_NAK_INVALID_RD_REQUEST 0x64
65 #define IB_BTH_REQ_ACK BIT(31)
66 #define IB_BTH_SOLICITED BIT(23)
67 #define IB_BTH_MIG_REQ BIT(22)
69 #define IB_GRH_VERSION 6
70 #define IB_GRH_VERSION_MASK 0xF
71 #define IB_GRH_VERSION_SHIFT 28
72 #define IB_GRH_TCLASS_MASK 0xFF
73 #define IB_GRH_TCLASS_SHIFT 20
74 #define IB_GRH_FLOW_MASK 0xFFFFF
75 #define IB_GRH_FLOW_SHIFT 0
76 #define IB_GRH_NEXT_HDR 0x1B
77 #define IB_FECN_SHIFT 31
78 #define IB_FECN_MASK 1
79 #define IB_FECN_SMASK BIT(IB_FECN_SHIFT)
80 #define IB_BECN_SHIFT 30
81 #define IB_BECN_MASK 1
82 #define IB_BECN_SMASK BIT(IB_BECN_SHIFT)
84 #define IB_AETH_CREDIT_SHIFT 24
85 #define IB_AETH_CREDIT_MASK 0x1F
86 #define IB_AETH_CREDIT_INVAL 0x1F
87 #define IB_AETH_NAK_SHIFT 29
88 #define IB_MSN_MASK 0xFFFFFF
90 struct ib_reth {
91 __be64 vaddr; /* potentially unaligned */
92 __be32 rkey;
93 __be32 length;
94 } __packed;
96 struct ib_atomic_eth {
97 __be64 vaddr; /* potentially unaligned */
98 __be32 rkey;
99 __be64 swap_data; /* potentially unaligned */
100 __be64 compare_data; /* potentially unaligned */
101 } __packed;
103 union ib_ehdrs {
104 struct {
105 __be32 deth[2];
106 __be32 imm_data;
107 } ud;
108 struct {
109 struct ib_reth reth;
110 __be32 imm_data;
111 } rc;
112 struct {
113 __be32 aeth;
114 __be64 atomic_ack_eth; /* potentially unaligned */
115 } __packed at;
116 __be32 imm_data;
117 __be32 aeth;
118 __be32 ieth;
119 struct ib_atomic_eth atomic_eth;
120 } __packed;
122 struct ib_other_headers {
123 __be32 bth[3];
124 union ib_ehdrs u;
125 } __packed;
127 struct ib_header {
128 __be16 lrh[4];
129 union {
130 struct {
131 struct ib_grh grh;
132 struct ib_other_headers oth;
133 } l;
134 struct ib_other_headers oth;
135 } u;
136 } __packed;
138 /* accessors for unaligned __be64 items */
140 static inline u64 ib_u64_get(__be64 *p)
142 return get_unaligned_be64(p);
145 static inline void ib_u64_put(u64 val, __be64 *p)
147 put_unaligned_be64(val, p);
150 static inline u64 get_ib_reth_vaddr(struct ib_reth *reth)
152 return ib_u64_get(&reth->vaddr);
155 static inline void put_ib_reth_vaddr(u64 val, struct ib_reth *reth)
157 ib_u64_put(val, &reth->vaddr);
160 static inline u64 get_ib_ateth_vaddr(struct ib_atomic_eth *ateth)
162 return ib_u64_get(&ateth->vaddr);
165 static inline void put_ib_ateth_vaddr(u64 val, struct ib_atomic_eth *ateth)
167 ib_u64_put(val, &ateth->vaddr);
170 static inline u64 get_ib_ateth_swap(struct ib_atomic_eth *ateth)
172 return ib_u64_get(&ateth->swap_data);
175 static inline void put_ib_ateth_swap(u64 val, struct ib_atomic_eth *ateth)
177 ib_u64_put(val, &ateth->swap_data);
180 static inline u64 get_ib_ateth_compare(struct ib_atomic_eth *ateth)
182 return ib_u64_get(&ateth->compare_data);
185 static inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth)
187 ib_u64_put(val, &ateth->compare_data);
191 * 9B/IB Packet Format
193 #define IB_LNH_MASK 3
194 #define IB_SC_MASK 0xf
195 #define IB_SC_SHIFT 12
196 #define IB_SC5_MASK 0x10
197 #define IB_SL_MASK 0xf
198 #define IB_SL_SHIFT 4
199 #define IB_SL_SHIFT 4
200 #define IB_LVER_MASK 0xf
201 #define IB_LVER_SHIFT 8
203 static inline u8 ib_get_lnh(struct ib_header *hdr)
205 return (be16_to_cpu(hdr->lrh[0]) & IB_LNH_MASK);
208 static inline u8 ib_get_sc(struct ib_header *hdr)
210 return ((be16_to_cpu(hdr->lrh[0]) >> IB_SC_SHIFT) & IB_SC_MASK);
213 static inline bool ib_is_sc5(u16 sc5)
215 return !!(sc5 & IB_SC5_MASK);
218 static inline u8 ib_get_sl(struct ib_header *hdr)
220 return ((be16_to_cpu(hdr->lrh[0]) >> IB_SL_SHIFT) & IB_SL_MASK);
223 static inline u16 ib_get_dlid(struct ib_header *hdr)
225 return (be16_to_cpu(hdr->lrh[1]));
228 static inline u16 ib_get_slid(struct ib_header *hdr)
230 return (be16_to_cpu(hdr->lrh[3]));
233 static inline u8 ib_get_lver(struct ib_header *hdr)
235 return (u8)((be16_to_cpu(hdr->lrh[0]) >> IB_LVER_SHIFT) &
236 IB_LVER_MASK);
239 static inline u16 ib_get_len(struct ib_header *hdr)
241 return (u16)(be16_to_cpu(hdr->lrh[2]));
244 static inline u32 ib_get_qkey(struct ib_other_headers *ohdr)
246 return be32_to_cpu(ohdr->u.ud.deth[0]);
249 static inline u32 ib_get_sqpn(struct ib_other_headers *ohdr)
251 return ((be32_to_cpu(ohdr->u.ud.deth[1])) & IB_QPN_MASK);
255 * BTH
257 #define IB_BTH_OPCODE_MASK 0xff
258 #define IB_BTH_OPCODE_SHIFT 24
259 #define IB_BTH_PAD_MASK 3
260 #define IB_BTH_PKEY_MASK 0xffff
261 #define IB_BTH_PAD_SHIFT 20
262 #define IB_BTH_A_MASK 1
263 #define IB_BTH_A_SHIFT 31
264 #define IB_BTH_M_MASK 1
265 #define IB_BTH_M_SHIFT 22
266 #define IB_BTH_SE_MASK 1
267 #define IB_BTH_SE_SHIFT 23
268 #define IB_BTH_TVER_MASK 0xf
269 #define IB_BTH_TVER_SHIFT 16
271 static inline u8 ib_bth_get_pad(struct ib_other_headers *ohdr)
273 return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_PAD_SHIFT) &
274 IB_BTH_PAD_MASK);
277 static inline u16 ib_bth_get_pkey(struct ib_other_headers *ohdr)
279 return (be32_to_cpu(ohdr->bth[0]) & IB_BTH_PKEY_MASK);
282 static inline u8 ib_bth_get_opcode(struct ib_other_headers *ohdr)
284 return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_OPCODE_SHIFT) &
285 IB_BTH_OPCODE_MASK);
288 static inline u8 ib_bth_get_ackreq(struct ib_other_headers *ohdr)
290 return (u8)((be32_to_cpu(ohdr->bth[2]) >> IB_BTH_A_SHIFT) &
291 IB_BTH_A_MASK);
294 static inline u8 ib_bth_get_migreq(struct ib_other_headers *ohdr)
296 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_M_SHIFT) &
297 IB_BTH_M_MASK);
300 static inline u8 ib_bth_get_se(struct ib_other_headers *ohdr)
302 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_SE_SHIFT) &
303 IB_BTH_SE_MASK);
306 static inline u32 ib_bth_get_psn(struct ib_other_headers *ohdr)
308 return (u32)(be32_to_cpu(ohdr->bth[2]));
311 static inline u32 ib_bth_get_qpn(struct ib_other_headers *ohdr)
313 return (u32)((be32_to_cpu(ohdr->bth[1])) & IB_QPN_MASK);
316 static inline u8 ib_bth_get_becn(struct ib_other_headers *ohdr)
318 return (u8)((be32_to_cpu(ohdr->bth[1]) >> IB_BECN_SHIFT) &
319 IB_BECN_MASK);
322 static inline u8 ib_bth_get_fecn(struct ib_other_headers *ohdr)
324 return (u8)((be32_to_cpu(ohdr->bth[1]) >> IB_FECN_SHIFT) &
325 IB_FECN_MASK);
328 static inline u8 ib_bth_get_tver(struct ib_other_headers *ohdr)
330 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_TVER_SHIFT) &
331 IB_BTH_TVER_MASK);
334 #endif /* IB_HDRS_H */