blob: 57c1ac881d08fbff3bd0063adf99a77b0716a886 [file] [log] [blame]
Leon Romanovsky6bf9d8f2020-07-19 10:25:21 +03001/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
Mike Marciniszyn7368ef02016-09-06 04:34:49 -07002/*
Kaike Wan742a3822019-01-23 19:30:40 -08003 * Copyright(c) 2016 - 2018 Intel Corporation.
Mike Marciniszyn7368ef02016-09-06 04:34:49 -07004 */
5
6#ifndef IB_HDRS_H
7#define IB_HDRS_H
8
9#include <linux/types.h>
10#include <asm/unaligned.h>
11#include <rdma/ib_verbs.h>
12
13#define IB_SEQ_NAK (3 << 29)
14
15/* AETH NAK opcode values */
16#define IB_RNR_NAK 0x20
17#define IB_NAK_PSN_ERROR 0x60
18#define IB_NAK_INVALID_REQUEST 0x61
19#define IB_NAK_REMOTE_ACCESS_ERROR 0x62
20#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
21#define IB_NAK_INVALID_RD_REQUEST 0x64
22
23#define IB_BTH_REQ_ACK BIT(31)
24#define IB_BTH_SOLICITED BIT(23)
25#define IB_BTH_MIG_REQ BIT(22)
26
27#define IB_GRH_VERSION 6
28#define IB_GRH_VERSION_MASK 0xF
29#define IB_GRH_VERSION_SHIFT 28
30#define IB_GRH_TCLASS_MASK 0xFF
31#define IB_GRH_TCLASS_SHIFT 20
32#define IB_GRH_FLOW_MASK 0xFFFFF
33#define IB_GRH_FLOW_SHIFT 0
34#define IB_GRH_NEXT_HDR 0x1B
Don Hiatt3d591092017-04-09 10:16:28 -070035#define IB_FECN_SHIFT 31
36#define IB_FECN_MASK 1
37#define IB_FECN_SMASK BIT(IB_FECN_SHIFT)
38#define IB_BECN_SHIFT 30
39#define IB_BECN_MASK 1
40#define IB_BECN_SMASK BIT(IB_BECN_SHIFT)
Mike Marciniszyn7368ef02016-09-06 04:34:49 -070041
Don Hiatt832666c2017-02-08 05:28:25 -080042#define IB_AETH_CREDIT_SHIFT 24
43#define IB_AETH_CREDIT_MASK 0x1F
44#define IB_AETH_CREDIT_INVAL 0x1F
45#define IB_AETH_NAK_SHIFT 29
46#define IB_MSN_MASK 0xFFFFFF
47
Mike Marciniszyn7368ef02016-09-06 04:34:49 -070048struct ib_reth {
49 __be64 vaddr; /* potentially unaligned */
50 __be32 rkey;
51 __be32 length;
52} __packed;
53
54struct ib_atomic_eth {
55 __be64 vaddr; /* potentially unaligned */
56 __be32 rkey;
57 __be64 swap_data; /* potentially unaligned */
58 __be64 compare_data; /* potentially unaligned */
59} __packed;
60
Kaike Wan742a3822019-01-23 19:30:40 -080061#include <rdma/tid_rdma_defs.h>
62
Mike Marciniszyn7368ef02016-09-06 04:34:49 -070063union ib_ehdrs {
64 struct {
65 __be32 deth[2];
66 __be32 imm_data;
67 } ud;
68 struct {
69 struct ib_reth reth;
70 __be32 imm_data;
71 } rc;
72 struct {
73 __be32 aeth;
74 __be64 atomic_ack_eth; /* potentially unaligned */
75 } __packed at;
76 __be32 imm_data;
77 __be32 aeth;
78 __be32 ieth;
79 struct ib_atomic_eth atomic_eth;
Kaike Wan742a3822019-01-23 19:30:40 -080080 /* TID RDMA headers */
81 union {
82 struct tid_rdma_read_req r_req;
83 struct tid_rdma_read_resp r_rsp;
Kaike Wanc098bbb2019-01-23 21:48:28 -080084 struct tid_rdma_write_req w_req;
85 struct tid_rdma_write_resp w_rsp;
86 struct tid_rdma_write_data w_data;
87 struct tid_rdma_resync resync;
88 struct tid_rdma_ack ack;
Kaike Wan742a3822019-01-23 19:30:40 -080089 } tid_rdma;
Mike Marciniszyn7368ef02016-09-06 04:34:49 -070090} __packed;
91
92struct ib_other_headers {
93 __be32 bth[3];
94 union ib_ehdrs u;
95} __packed;
96
97struct ib_header {
98 __be16 lrh[4];
99 union {
100 struct {
101 struct ib_grh grh;
102 struct ib_other_headers oth;
103 } l;
104 struct ib_other_headers oth;
105 } u;
106} __packed;
107
108/* accessors for unaligned __be64 items */
109
110static inline u64 ib_u64_get(__be64 *p)
111{
112 return get_unaligned_be64(p);
113}
114
115static inline void ib_u64_put(u64 val, __be64 *p)
116{
117 put_unaligned_be64(val, p);
118}
119
120static inline u64 get_ib_reth_vaddr(struct ib_reth *reth)
121{
122 return ib_u64_get(&reth->vaddr);
123}
124
125static inline void put_ib_reth_vaddr(u64 val, struct ib_reth *reth)
126{
127 ib_u64_put(val, &reth->vaddr);
128}
129
130static inline u64 get_ib_ateth_vaddr(struct ib_atomic_eth *ateth)
131{
132 return ib_u64_get(&ateth->vaddr);
133}
134
135static inline void put_ib_ateth_vaddr(u64 val, struct ib_atomic_eth *ateth)
136{
137 ib_u64_put(val, &ateth->vaddr);
138}
139
140static inline u64 get_ib_ateth_swap(struct ib_atomic_eth *ateth)
141{
142 return ib_u64_get(&ateth->swap_data);
143}
144
145static inline void put_ib_ateth_swap(u64 val, struct ib_atomic_eth *ateth)
146{
147 ib_u64_put(val, &ateth->swap_data);
148}
149
150static inline u64 get_ib_ateth_compare(struct ib_atomic_eth *ateth)
151{
152 return ib_u64_get(&ateth->compare_data);
153}
154
155static inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth)
156{
157 ib_u64_put(val, &ateth->compare_data);
158}
159
Don Hiattcb4270572017-04-09 10:16:22 -0700160/*
161 * 9B/IB Packet Format
162 */
163#define IB_LNH_MASK 3
164#define IB_SC_MASK 0xf
165#define IB_SC_SHIFT 12
Don Hiatt7dafbab2017-05-12 09:19:55 -0700166#define IB_SC5_MASK 0x10
Don Hiattcb4270572017-04-09 10:16:22 -0700167#define IB_SL_MASK 0xf
168#define IB_SL_SHIFT 4
Don Hiatt7dafbab2017-05-12 09:19:55 -0700169#define IB_SL_SHIFT 4
170#define IB_LVER_MASK 0xf
171#define IB_LVER_SHIFT 8
Don Hiattcb4270572017-04-09 10:16:22 -0700172
173static inline u8 ib_get_lnh(struct ib_header *hdr)
174{
175 return (be16_to_cpu(hdr->lrh[0]) & IB_LNH_MASK);
176}
177
178static inline u8 ib_get_sc(struct ib_header *hdr)
179{
180 return ((be16_to_cpu(hdr->lrh[0]) >> IB_SC_SHIFT) & IB_SC_MASK);
181}
182
Don Hiatt7dafbab2017-05-12 09:19:55 -0700183static inline bool ib_is_sc5(u16 sc5)
184{
185 return !!(sc5 & IB_SC5_MASK);
186}
187
Don Hiattcb4270572017-04-09 10:16:22 -0700188static inline u8 ib_get_sl(struct ib_header *hdr)
189{
190 return ((be16_to_cpu(hdr->lrh[0]) >> IB_SL_SHIFT) & IB_SL_MASK);
191}
192
193static inline u16 ib_get_dlid(struct ib_header *hdr)
194{
195 return (be16_to_cpu(hdr->lrh[1]));
196}
197
198static inline u16 ib_get_slid(struct ib_header *hdr)
199{
200 return (be16_to_cpu(hdr->lrh[3]));
201}
202
Don Hiatt7dafbab2017-05-12 09:19:55 -0700203static inline u8 ib_get_lver(struct ib_header *hdr)
204{
205 return (u8)((be16_to_cpu(hdr->lrh[0]) >> IB_LVER_SHIFT) &
206 IB_LVER_MASK);
207}
208
209static inline u16 ib_get_len(struct ib_header *hdr)
210{
211 return (u16)(be16_to_cpu(hdr->lrh[2]));
212}
213
214static inline u32 ib_get_qkey(struct ib_other_headers *ohdr)
215{
216 return be32_to_cpu(ohdr->u.ud.deth[0]);
217}
218
219static inline u32 ib_get_sqpn(struct ib_other_headers *ohdr)
220{
221 return ((be32_to_cpu(ohdr->u.ud.deth[1])) & IB_QPN_MASK);
222}
223
Don Hiattcb4270572017-04-09 10:16:22 -0700224/*
225 * BTH
226 */
227#define IB_BTH_OPCODE_MASK 0xff
228#define IB_BTH_OPCODE_SHIFT 24
229#define IB_BTH_PAD_MASK 3
230#define IB_BTH_PKEY_MASK 0xffff
231#define IB_BTH_PAD_SHIFT 20
Don Hiatt7dafbab2017-05-12 09:19:55 -0700232#define IB_BTH_A_MASK 1
233#define IB_BTH_A_SHIFT 31
234#define IB_BTH_M_MASK 1
235#define IB_BTH_M_SHIFT 22
236#define IB_BTH_SE_MASK 1
237#define IB_BTH_SE_SHIFT 23
238#define IB_BTH_TVER_MASK 0xf
239#define IB_BTH_TVER_SHIFT 16
Don Hiattcb4270572017-04-09 10:16:22 -0700240
241static inline u8 ib_bth_get_pad(struct ib_other_headers *ohdr)
242{
243 return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_PAD_SHIFT) &
244 IB_BTH_PAD_MASK);
245}
246
247static inline u16 ib_bth_get_pkey(struct ib_other_headers *ohdr)
248{
249 return (be32_to_cpu(ohdr->bth[0]) & IB_BTH_PKEY_MASK);
250}
251
252static inline u8 ib_bth_get_opcode(struct ib_other_headers *ohdr)
253{
254 return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_OPCODE_SHIFT) &
255 IB_BTH_OPCODE_MASK);
256}
257
Don Hiatt7dafbab2017-05-12 09:19:55 -0700258static inline u8 ib_bth_get_ackreq(struct ib_other_headers *ohdr)
259{
260 return (u8)((be32_to_cpu(ohdr->bth[2]) >> IB_BTH_A_SHIFT) &
261 IB_BTH_A_MASK);
262}
263
264static inline u8 ib_bth_get_migreq(struct ib_other_headers *ohdr)
265{
266 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_M_SHIFT) &
267 IB_BTH_M_MASK);
268}
269
270static inline u8 ib_bth_get_se(struct ib_other_headers *ohdr)
271{
272 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_SE_SHIFT) &
273 IB_BTH_SE_MASK);
274}
275
276static inline u32 ib_bth_get_psn(struct ib_other_headers *ohdr)
277{
278 return (u32)(be32_to_cpu(ohdr->bth[2]));
279}
280
281static inline u32 ib_bth_get_qpn(struct ib_other_headers *ohdr)
282{
283 return (u32)((be32_to_cpu(ohdr->bth[1])) & IB_QPN_MASK);
284}
285
Sebastian Sanchezca85bb12018-02-01 10:46:38 -0800286static inline bool ib_bth_get_becn(struct ib_other_headers *ohdr)
Don Hiatt7dafbab2017-05-12 09:19:55 -0700287{
Sebastian Sanchezca85bb12018-02-01 10:46:38 -0800288 return (ohdr->bth[1]) & cpu_to_be32(IB_BECN_SMASK);
Don Hiatt7dafbab2017-05-12 09:19:55 -0700289}
290
Sebastian Sanchezca85bb12018-02-01 10:46:38 -0800291static inline bool ib_bth_get_fecn(struct ib_other_headers *ohdr)
Don Hiatt7dafbab2017-05-12 09:19:55 -0700292{
Sebastian Sanchezca85bb12018-02-01 10:46:38 -0800293 return (ohdr->bth[1]) & cpu_to_be32(IB_FECN_SMASK);
Don Hiatt7dafbab2017-05-12 09:19:55 -0700294}
295
296static inline u8 ib_bth_get_tver(struct ib_other_headers *ohdr)
297{
298 return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_TVER_SHIFT) &
299 IB_BTH_TVER_MASK);
300}
301
Sebastian Sanchezf150e272018-02-01 10:46:15 -0800302static inline bool ib_bth_is_solicited(struct ib_other_headers *ohdr)
303{
304 return ohdr->bth[0] & cpu_to_be32(IB_BTH_SOLICITED);
305}
Sebastian Sanchez6d6b8842018-02-01 10:46:23 -0800306
307static inline bool ib_bth_is_migration(struct ib_other_headers *ohdr)
308{
309 return ohdr->bth[0] & cpu_to_be32(IB_BTH_MIG_REQ);
310}
Mike Marciniszyn7368ef02016-09-06 04:34:49 -0700311#endif /* IB_HDRS_H */