blob: 58a0a0f99e7f6a7c7094ffa9dcbe7a22b1c821c9 [file] [log] [blame]
Mike Marciniszyn7368ef02016-09-06 04:34:49 -07001/*
Kaike Wan742a3822019-01-23 19:30:40 -08002 * Copyright(c) 2016 - 2018 Intel Corporation.
Mike Marciniszyn7368ef02016-09-06 04:34:49 -07003 *
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.
6 *
7 * GPL LICENSE SUMMARY
8 *
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.
12 *
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.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
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.
33 *
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.
45 *
46 */
47
48#ifndef IB_HDRS_H
49#define IB_HDRS_H
50
51#include <linux/types.h>
52#include <asm/unaligned.h>
53#include <rdma/ib_verbs.h>
54
55#define IB_SEQ_NAK (3 << 29)
56
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
64
65#define IB_BTH_REQ_ACK BIT(31)
66#define IB_BTH_SOLICITED BIT(23)
67#define IB_BTH_MIG_REQ BIT(22)
68
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
Don Hiatt3d591092017-04-09 10:16:28 -070077#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)
Mike Marciniszyn7368ef02016-09-06 04:34:49 -070083
Don Hiatt832666c2017-02-08 05:28:25 -080084#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
89
Mike Marciniszyn7368ef02016-09-06 04:34:49 -070090struct ib_reth {
91 __be64 vaddr; /* potentially unaligned */
92 __be32 rkey;
93 __be32 length;
94} __packed;
95
96struct 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;
102
Kaike Wan742a3822019-01-23 19:30:40 -0800103#include <rdma/tid_rdma_defs.h>
104
Mike Marciniszyn7368ef02016-09-06 04:34:49 -0700105union ib_ehdrs {
106 struct {
107 __be32 deth[2];
108 __be32 imm_data;
109 } ud;
110 struct {
111 struct ib_reth reth;
112 __be32 imm_data;
113 } rc;
114 struct {
115 __be32 aeth;
116 __be64 atomic_ack_eth; /* potentially unaligned */
117 } __packed at;
118 __be32 imm_data;
119 __be32 aeth;
120 __be32 ieth;
121 struct ib_atomic_eth atomic_eth;
Kaike Wan742a3822019-01-23 19:30:40 -0800122 /* TID RDMA headers */
123 union {
124 struct tid_rdma_read_req r_req;
125 struct tid_rdma_read_resp r_rsp;
126 } tid_rdma;
Mike Marciniszyn7368ef02016-09-06 04:34:49 -0700127} __packed;
128
129struct ib_other_headers {
130 __be32 bth[3];
131 union ib_ehdrs u;
132} __packed;
133
134struct ib_header {
135 __be16 lrh[4];
136 union {
137 struct {
138 struct ib_grh grh;
139 struct ib_other_headers oth;
140 } l;
141 struct ib_other_headers oth;
142 } u;
143} __packed;
144
145/* accessors for unaligned __be64 items */
146
147static inline u64 ib_u64_get(__be64 *p)
148{
149 return get_unaligned_be64(p);
150}
151
152static inline void ib_u64_put(u64 val, __be64 *p)
153{
154 put_unaligned_be64(val, p);
155}
156
157static inline u64 get_ib_reth_vaddr(struct ib_reth *reth)
158{
159 return ib_u64_get(&reth->vaddr);
160}
161
162static inline void put_ib_reth_vaddr(u64 val, struct ib_reth *reth)
163{
164 ib_u64_put(val, &reth->vaddr);
165}
166
167static inline u64 get_ib_ateth_vaddr(struct ib_atomic_eth *ateth)
168{
169 return ib_u64_get(&ateth->vaddr);
170}
171
172static inline void put_ib_ateth_vaddr(u64 val, struct ib_atomic_eth *ateth)
173{
174 ib_u64_put(val, &ateth->vaddr);
175}
176
177static inline u64 get_ib_ateth_swap(struct ib_atomic_eth *ateth)
178{
179 return ib_u64_get(&ateth->swap_data);
180}
181
182static inline void put_ib_ateth_swap(u64 val, struct ib_atomic_eth *ateth)
183{
184 ib_u64_put(val, &ateth->swap_data);
185}
186
187static inline u64 get_ib_ateth_compare(struct ib_atomic_eth *ateth)
188{
189 return ib_u64_get(&ateth->compare_data);
190}
191
192static inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth)
193{
194 ib_u64_put(val, &ateth->compare_data);
195}
196
Don Hiattcb4270572017-04-09 10:16:22 -0700197/*
198 * 9B/IB Packet Format
199 */
200#define IB_LNH_MASK 3
201#define IB_SC_MASK 0xf
202#define IB_SC_SHIFT 12
Don Hiatt7dafbab2017-05-12 09:19:55 -0700203#define IB_SC5_MASK 0x10
Don Hiattcb4270572017-04-09 10:16:22 -0700204#define IB_SL_MASK 0xf
205#define IB_SL_SHIFT 4
Don Hiatt7dafbab2017-05-12 09:19:55 -0700206#define IB_SL_SHIFT 4
207#define IB_LVER_MASK 0xf
208#define IB_LVER_SHIFT 8
Don Hiattcb4270572017-04-09 10:16:22 -0700209
210static inline u8 ib_get_lnh(struct ib_header *hdr)
211{
212 return (be16_to_cpu(hdr->lrh[0]) & IB_LNH_MASK);
213}
214
215static inline u8 ib_get_sc(struct ib_header *hdr)
216{
217 return ((be16_to_cpu(hdr->lrh[0]) >> IB_SC_SHIFT) & IB_SC_MASK);
218}
219
Don Hiatt7dafbab2017-05-12 09:19:55 -0700220static inline bool ib_is_sc5(u16 sc5)
221{
222 return !!(sc5 & IB_SC5_MASK);
223}
224
Don Hiattcb4270572017-04-09 10:16:22 -0700225static inline u8 ib_get_sl(struct ib_header *hdr)
226{
227 return ((be16_to_cpu(hdr->lrh[0]) >> IB_SL_SHIFT) & IB_SL_MASK);
228}
229
230static inline u16 ib_get_dlid(struct ib_header *hdr)
231{
232 return (be16_to_cpu(hdr->lrh[1]));
233}
234
235static inline u16 ib_get_slid(struct ib_header *hdr)
236{
237 return (be16_to_cpu(hdr->lrh[3]));
238}
239
Don Hiatt7dafbab2017-05-12 09:19:55 -0700240static inline u8 ib_get_lver(struct ib_header *hdr)
241{
242 return (u8)((be16_to_cpu(hdr->lrh[0]) >> IB_LVER_SHIFT) &
243 IB_LVER_MASK);
244}
245
246static inline u16 ib_get_len(struct ib_header *hdr)
247{
248 return (u16)(be16_to_cpu(hdr->lrh[2]));
249}
250
251static inline u32 ib_get_qkey(struct ib_other_headers *ohdr)
252{
253 return be32_to_cpu(ohdr->u.ud.deth[0]);
254}
255
256static inline u32 ib_get_sqpn(struct ib_other_headers *ohdr)
257{
258 return ((be32_to_cpu(ohdr->u.ud.deth[1])) & IB_QPN_MASK);
259}
260
Don Hiattcb4270572017-04-09 10:16:22 -0700261/*
262 * BTH
263 */
264#define IB_BTH_OPCODE_MASK 0xff
265#define IB_BTH_OPCODE_SHIFT 24
266#define IB_BTH_PAD_MASK 3
267#define IB_BTH_PKEY_MASK 0xffff
268#define IB_BTH_PAD_SHIFT 20
Don Hiatt7dafbab2017-05-12 09:19:55 -0700269#define IB_BTH_A_MASK 1
270#define IB_BTH_A_SHIFT 31
271#define IB_BTH_M_MASK 1
272#define IB_BTH_M_SHIFT 22
273#define IB_BTH_SE_MASK 1
274#define IB_BTH_SE_SHIFT 23
275#define IB_BTH_TVER_MASK 0xf
276#define IB_BTH_TVER_SHIFT 16
Don Hiattcb4270572017-04-09 10:16:22 -0700277
278static inline u8 ib_bth_get_pad(struct ib_other_headers *ohdr)
279{
280 return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_PAD_SHIFT) &
281 IB_BTH_PAD_MASK);
282}
283
284static inline u16 ib_bth_get_pkey(struct ib_other_headers *ohdr)
285{
286 return (be32_to_cpu(ohdr->bth[0]) & IB_BTH_PKEY_MASK);
287}
288
289static inline u8 ib_bth_get_opcode(struct ib_other_headers *ohdr)
290{
291 return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_OPCODE_SHIFT) &
292 IB_BTH_OPCODE_MASK);
293}
294
Don Hiatt7dafbab2017-05-12 09:19:55 -0700295static inline u8 ib_bth_get_ackreq(struct ib_other_headers *ohdr)
296{
297 return (u8)((be32_to_cpu(ohdr->bth[2]) >> IB_BTH_A_SHIFT) &
298 IB_BTH_A_MASK);
299}
300
301static inline u8 ib_bth_get_migreq(struct ib_other_headers *ohdr)
302{
303 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_M_SHIFT) &
304 IB_BTH_M_MASK);
305}
306
307static inline u8 ib_bth_get_se(struct ib_other_headers *ohdr)
308{
309 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_SE_SHIFT) &
310 IB_BTH_SE_MASK);
311}
312
313static inline u32 ib_bth_get_psn(struct ib_other_headers *ohdr)
314{
315 return (u32)(be32_to_cpu(ohdr->bth[2]));
316}
317
318static inline u32 ib_bth_get_qpn(struct ib_other_headers *ohdr)
319{
320 return (u32)((be32_to_cpu(ohdr->bth[1])) & IB_QPN_MASK);
321}
322
Sebastian Sanchezca85bb12018-02-01 10:46:38 -0800323static inline bool ib_bth_get_becn(struct ib_other_headers *ohdr)
Don Hiatt7dafbab2017-05-12 09:19:55 -0700324{
Sebastian Sanchezca85bb12018-02-01 10:46:38 -0800325 return (ohdr->bth[1]) & cpu_to_be32(IB_BECN_SMASK);
Don Hiatt7dafbab2017-05-12 09:19:55 -0700326}
327
Sebastian Sanchezca85bb12018-02-01 10:46:38 -0800328static inline bool ib_bth_get_fecn(struct ib_other_headers *ohdr)
Don Hiatt7dafbab2017-05-12 09:19:55 -0700329{
Sebastian Sanchezca85bb12018-02-01 10:46:38 -0800330 return (ohdr->bth[1]) & cpu_to_be32(IB_FECN_SMASK);
Don Hiatt7dafbab2017-05-12 09:19:55 -0700331}
332
333static inline u8 ib_bth_get_tver(struct ib_other_headers *ohdr)
334{
335 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_TVER_SHIFT) &
336 IB_BTH_TVER_MASK);
337}
338
Sebastian Sanchezf150e272018-02-01 10:46:15 -0800339static inline bool ib_bth_is_solicited(struct ib_other_headers *ohdr)
340{
341 return ohdr->bth[0] & cpu_to_be32(IB_BTH_SOLICITED);
342}
Sebastian Sanchez6d6b8842018-02-01 10:46:23 -0800343
344static inline bool ib_bth_is_migration(struct ib_other_headers *ohdr)
345{
346 return ohdr->bth[0] & cpu_to_be32(IB_BTH_MIG_REQ);
347}
Mike Marciniszyn7368ef02016-09-06 04:34:49 -0700348#endif /* IB_HDRS_H */