1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
3 * Copyright(c) 2016 - 2018 Intel Corporation.
9 #include <linux/types.h>
10 #include <linux/unaligned.h>
11 #include <rdma/ib_verbs.h>
13 #define IB_SEQ_NAK (3 << 29)
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
23 #define IB_BTH_REQ_ACK BIT(31)
24 #define IB_BTH_SOLICITED BIT(23)
25 #define IB_BTH_MIG_REQ BIT(22)
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
35 #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)
42 #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
49 __be64 vaddr
; /* potentially unaligned */
54 struct ib_atomic_eth
{
55 __be64 vaddr
; /* potentially unaligned */
57 __be64 swap_data
; /* potentially unaligned */
58 __be64 compare_data
; /* potentially unaligned */
61 #include <rdma/tid_rdma_defs.h>
74 __be64 atomic_ack_eth
; /* potentially unaligned */
79 struct ib_atomic_eth atomic_eth
;
80 /* TID RDMA headers */
82 struct tid_rdma_read_req r_req
;
83 struct tid_rdma_read_resp r_rsp
;
84 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
;
92 struct ib_other_headers
{
102 struct ib_other_headers oth
;
104 struct ib_other_headers oth
;
108 /* accessors for unaligned __be64 items */
110 static inline u64
ib_u64_get(__be64
*p
)
112 return get_unaligned_be64(p
);
115 static inline void ib_u64_put(u64 val
, __be64
*p
)
117 put_unaligned_be64(val
, p
);
120 static inline u64
get_ib_reth_vaddr(struct ib_reth
*reth
)
122 return ib_u64_get(&reth
->vaddr
);
125 static inline void put_ib_reth_vaddr(u64 val
, struct ib_reth
*reth
)
127 ib_u64_put(val
, &reth
->vaddr
);
130 static inline u64
get_ib_ateth_vaddr(struct ib_atomic_eth
*ateth
)
132 return ib_u64_get(&ateth
->vaddr
);
135 static inline void put_ib_ateth_vaddr(u64 val
, struct ib_atomic_eth
*ateth
)
137 ib_u64_put(val
, &ateth
->vaddr
);
140 static inline u64
get_ib_ateth_swap(struct ib_atomic_eth
*ateth
)
142 return ib_u64_get(&ateth
->swap_data
);
145 static inline void put_ib_ateth_swap(u64 val
, struct ib_atomic_eth
*ateth
)
147 ib_u64_put(val
, &ateth
->swap_data
);
150 static inline u64
get_ib_ateth_compare(struct ib_atomic_eth
*ateth
)
152 return ib_u64_get(&ateth
->compare_data
);
155 static inline void put_ib_ateth_compare(u64 val
, struct ib_atomic_eth
*ateth
)
157 ib_u64_put(val
, &ateth
->compare_data
);
161 * 9B/IB Packet Format
163 #define IB_LNH_MASK 3
164 #define IB_SC_MASK 0xf
165 #define IB_SC_SHIFT 12
166 #define IB_SC5_MASK 0x10
167 #define IB_SL_MASK 0xf
168 #define IB_SL_SHIFT 4
169 #define IB_SL_SHIFT 4
170 #define IB_LVER_MASK 0xf
171 #define IB_LVER_SHIFT 8
173 static inline u8
ib_get_lnh(struct ib_header
*hdr
)
175 return (be16_to_cpu(hdr
->lrh
[0]) & IB_LNH_MASK
);
178 static inline u8
ib_get_sc(struct ib_header
*hdr
)
180 return ((be16_to_cpu(hdr
->lrh
[0]) >> IB_SC_SHIFT
) & IB_SC_MASK
);
183 static inline bool ib_is_sc5(u16 sc5
)
185 return !!(sc5
& IB_SC5_MASK
);
188 static inline u8
ib_get_sl(struct ib_header
*hdr
)
190 return ((be16_to_cpu(hdr
->lrh
[0]) >> IB_SL_SHIFT
) & IB_SL_MASK
);
193 static inline u16
ib_get_dlid(struct ib_header
*hdr
)
195 return (be16_to_cpu(hdr
->lrh
[1]));
198 static inline u16
ib_get_slid(struct ib_header
*hdr
)
200 return (be16_to_cpu(hdr
->lrh
[3]));
203 static inline u8
ib_get_lver(struct ib_header
*hdr
)
205 return (u8
)((be16_to_cpu(hdr
->lrh
[0]) >> IB_LVER_SHIFT
) &
209 static inline u32
ib_get_qkey(struct ib_other_headers
*ohdr
)
211 return be32_to_cpu(ohdr
->u
.ud
.deth
[0]);
214 static inline u32
ib_get_sqpn(struct ib_other_headers
*ohdr
)
216 return ((be32_to_cpu(ohdr
->u
.ud
.deth
[1])) & IB_QPN_MASK
);
222 #define IB_BTH_OPCODE_MASK 0xff
223 #define IB_BTH_OPCODE_SHIFT 24
224 #define IB_BTH_PAD_MASK 3
225 #define IB_BTH_PKEY_MASK 0xffff
226 #define IB_BTH_PAD_SHIFT 20
227 #define IB_BTH_A_MASK 1
228 #define IB_BTH_A_SHIFT 31
229 #define IB_BTH_M_MASK 1
230 #define IB_BTH_M_SHIFT 22
231 #define IB_BTH_SE_MASK 1
232 #define IB_BTH_SE_SHIFT 23
233 #define IB_BTH_TVER_MASK 0xf
234 #define IB_BTH_TVER_SHIFT 16
235 #define IB_BTH_OPCODE_CNP 0x81
237 static inline u8
ib_bth_get_pad(struct ib_other_headers
*ohdr
)
239 return ((be32_to_cpu(ohdr
->bth
[0]) >> IB_BTH_PAD_SHIFT
) &
243 static inline u16
ib_bth_get_pkey(struct ib_other_headers
*ohdr
)
245 return (be32_to_cpu(ohdr
->bth
[0]) & IB_BTH_PKEY_MASK
);
248 static inline u8
ib_bth_get_opcode(struct ib_other_headers
*ohdr
)
250 return ((be32_to_cpu(ohdr
->bth
[0]) >> IB_BTH_OPCODE_SHIFT
) &
254 static inline u8
ib_bth_get_ackreq(struct ib_other_headers
*ohdr
)
256 return (u8
)((be32_to_cpu(ohdr
->bth
[2]) >> IB_BTH_A_SHIFT
) &
260 static inline u8
ib_bth_get_migreq(struct ib_other_headers
*ohdr
)
262 return (u8
)((be32_to_cpu(ohdr
->bth
[0]) >> IB_BTH_M_SHIFT
) &
266 static inline u8
ib_bth_get_se(struct ib_other_headers
*ohdr
)
268 return (u8
)((be32_to_cpu(ohdr
->bth
[0]) >> IB_BTH_SE_SHIFT
) &
272 static inline u32
ib_bth_get_psn(struct ib_other_headers
*ohdr
)
274 return (u32
)(be32_to_cpu(ohdr
->bth
[2]));
277 static inline u32
ib_bth_get_qpn(struct ib_other_headers
*ohdr
)
279 return (u32
)((be32_to_cpu(ohdr
->bth
[1])) & IB_QPN_MASK
);
282 static inline bool ib_bth_get_becn(struct ib_other_headers
*ohdr
)
284 return (ohdr
->bth
[1]) & cpu_to_be32(IB_BECN_SMASK
);
287 static inline bool ib_bth_get_fecn(struct ib_other_headers
*ohdr
)
289 return (ohdr
->bth
[1]) & cpu_to_be32(IB_FECN_SMASK
);
292 static inline u8
ib_bth_get_tver(struct ib_other_headers
*ohdr
)
294 return (u8
)((be32_to_cpu(ohdr
->bth
[0]) >> IB_BTH_TVER_SHIFT
) &
298 static inline bool ib_bth_is_solicited(struct ib_other_headers
*ohdr
)
300 return ohdr
->bth
[0] & cpu_to_be32(IB_BTH_SOLICITED
);
303 static inline bool ib_bth_is_migration(struct ib_other_headers
*ohdr
)
305 return ohdr
->bth
[0] & cpu_to_be32(IB_BTH_MIG_REQ
);
307 #endif /* IB_HDRS_H */