ib_hdrs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /*
  3. * Copyright(c) 2016 - 2018 Intel Corporation.
  4. */
  5. #ifndef IB_HDRS_H
  6. #define IB_HDRS_H
  7. #include <linux/types.h>
  8. #include <asm/unaligned.h>
  9. #include <rdma/ib_verbs.h>
  10. #define IB_SEQ_NAK (3 << 29)
  11. /* AETH NAK opcode values */
  12. #define IB_RNR_NAK 0x20
  13. #define IB_NAK_PSN_ERROR 0x60
  14. #define IB_NAK_INVALID_REQUEST 0x61
  15. #define IB_NAK_REMOTE_ACCESS_ERROR 0x62
  16. #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
  17. #define IB_NAK_INVALID_RD_REQUEST 0x64
  18. #define IB_BTH_REQ_ACK BIT(31)
  19. #define IB_BTH_SOLICITED BIT(23)
  20. #define IB_BTH_MIG_REQ BIT(22)
  21. #define IB_GRH_VERSION 6
  22. #define IB_GRH_VERSION_MASK 0xF
  23. #define IB_GRH_VERSION_SHIFT 28
  24. #define IB_GRH_TCLASS_MASK 0xFF
  25. #define IB_GRH_TCLASS_SHIFT 20
  26. #define IB_GRH_FLOW_MASK 0xFFFFF
  27. #define IB_GRH_FLOW_SHIFT 0
  28. #define IB_GRH_NEXT_HDR 0x1B
  29. #define IB_FECN_SHIFT 31
  30. #define IB_FECN_MASK 1
  31. #define IB_FECN_SMASK BIT(IB_FECN_SHIFT)
  32. #define IB_BECN_SHIFT 30
  33. #define IB_BECN_MASK 1
  34. #define IB_BECN_SMASK BIT(IB_BECN_SHIFT)
  35. #define IB_AETH_CREDIT_SHIFT 24
  36. #define IB_AETH_CREDIT_MASK 0x1F
  37. #define IB_AETH_CREDIT_INVAL 0x1F
  38. #define IB_AETH_NAK_SHIFT 29
  39. #define IB_MSN_MASK 0xFFFFFF
  40. struct ib_reth {
  41. __be64 vaddr; /* potentially unaligned */
  42. __be32 rkey;
  43. __be32 length;
  44. } __packed;
  45. struct ib_atomic_eth {
  46. __be64 vaddr; /* potentially unaligned */
  47. __be32 rkey;
  48. __be64 swap_data; /* potentially unaligned */
  49. __be64 compare_data; /* potentially unaligned */
  50. } __packed;
  51. #include <rdma/tid_rdma_defs.h>
  52. union ib_ehdrs {
  53. struct {
  54. __be32 deth[2];
  55. __be32 imm_data;
  56. } ud;
  57. struct {
  58. struct ib_reth reth;
  59. __be32 imm_data;
  60. } rc;
  61. struct {
  62. __be32 aeth;
  63. __be64 atomic_ack_eth; /* potentially unaligned */
  64. } __packed at;
  65. __be32 imm_data;
  66. __be32 aeth;
  67. __be32 ieth;
  68. struct ib_atomic_eth atomic_eth;
  69. /* TID RDMA headers */
  70. union {
  71. struct tid_rdma_read_req r_req;
  72. struct tid_rdma_read_resp r_rsp;
  73. struct tid_rdma_write_req w_req;
  74. struct tid_rdma_write_resp w_rsp;
  75. struct tid_rdma_write_data w_data;
  76. struct tid_rdma_resync resync;
  77. struct tid_rdma_ack ack;
  78. } tid_rdma;
  79. } __packed;
  80. struct ib_other_headers {
  81. __be32 bth[3];
  82. union ib_ehdrs u;
  83. } __packed;
  84. struct ib_header {
  85. __be16 lrh[4];
  86. union {
  87. struct {
  88. struct ib_grh grh;
  89. struct ib_other_headers oth;
  90. } l;
  91. struct ib_other_headers oth;
  92. } u;
  93. } __packed;
  94. /* accessors for unaligned __be64 items */
  95. static inline u64 ib_u64_get(__be64 *p)
  96. {
  97. return get_unaligned_be64(p);
  98. }
  99. static inline void ib_u64_put(u64 val, __be64 *p)
  100. {
  101. put_unaligned_be64(val, p);
  102. }
  103. static inline u64 get_ib_reth_vaddr(struct ib_reth *reth)
  104. {
  105. return ib_u64_get(&reth->vaddr);
  106. }
  107. static inline void put_ib_reth_vaddr(u64 val, struct ib_reth *reth)
  108. {
  109. ib_u64_put(val, &reth->vaddr);
  110. }
  111. static inline u64 get_ib_ateth_vaddr(struct ib_atomic_eth *ateth)
  112. {
  113. return ib_u64_get(&ateth->vaddr);
  114. }
  115. static inline void put_ib_ateth_vaddr(u64 val, struct ib_atomic_eth *ateth)
  116. {
  117. ib_u64_put(val, &ateth->vaddr);
  118. }
  119. static inline u64 get_ib_ateth_swap(struct ib_atomic_eth *ateth)
  120. {
  121. return ib_u64_get(&ateth->swap_data);
  122. }
  123. static inline void put_ib_ateth_swap(u64 val, struct ib_atomic_eth *ateth)
  124. {
  125. ib_u64_put(val, &ateth->swap_data);
  126. }
  127. static inline u64 get_ib_ateth_compare(struct ib_atomic_eth *ateth)
  128. {
  129. return ib_u64_get(&ateth->compare_data);
  130. }
  131. static inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth)
  132. {
  133. ib_u64_put(val, &ateth->compare_data);
  134. }
  135. /*
  136. * 9B/IB Packet Format
  137. */
  138. #define IB_LNH_MASK 3
  139. #define IB_SC_MASK 0xf
  140. #define IB_SC_SHIFT 12
  141. #define IB_SC5_MASK 0x10
  142. #define IB_SL_MASK 0xf
  143. #define IB_SL_SHIFT 4
  144. #define IB_SL_SHIFT 4
  145. #define IB_LVER_MASK 0xf
  146. #define IB_LVER_SHIFT 8
  147. static inline u8 ib_get_lnh(struct ib_header *hdr)
  148. {
  149. return (be16_to_cpu(hdr->lrh[0]) & IB_LNH_MASK);
  150. }
  151. static inline u8 ib_get_sc(struct ib_header *hdr)
  152. {
  153. return ((be16_to_cpu(hdr->lrh[0]) >> IB_SC_SHIFT) & IB_SC_MASK);
  154. }
  155. static inline bool ib_is_sc5(u16 sc5)
  156. {
  157. return !!(sc5 & IB_SC5_MASK);
  158. }
  159. static inline u8 ib_get_sl(struct ib_header *hdr)
  160. {
  161. return ((be16_to_cpu(hdr->lrh[0]) >> IB_SL_SHIFT) & IB_SL_MASK);
  162. }
  163. static inline u16 ib_get_dlid(struct ib_header *hdr)
  164. {
  165. return (be16_to_cpu(hdr->lrh[1]));
  166. }
  167. static inline u16 ib_get_slid(struct ib_header *hdr)
  168. {
  169. return (be16_to_cpu(hdr->lrh[3]));
  170. }
  171. static inline u8 ib_get_lver(struct ib_header *hdr)
  172. {
  173. return (u8)((be16_to_cpu(hdr->lrh[0]) >> IB_LVER_SHIFT) &
  174. IB_LVER_MASK);
  175. }
  176. static inline u32 ib_get_qkey(struct ib_other_headers *ohdr)
  177. {
  178. return be32_to_cpu(ohdr->u.ud.deth[0]);
  179. }
  180. static inline u32 ib_get_sqpn(struct ib_other_headers *ohdr)
  181. {
  182. return ((be32_to_cpu(ohdr->u.ud.deth[1])) & IB_QPN_MASK);
  183. }
  184. /*
  185. * BTH
  186. */
  187. #define IB_BTH_OPCODE_MASK 0xff
  188. #define IB_BTH_OPCODE_SHIFT 24
  189. #define IB_BTH_PAD_MASK 3
  190. #define IB_BTH_PKEY_MASK 0xffff
  191. #define IB_BTH_PAD_SHIFT 20
  192. #define IB_BTH_A_MASK 1
  193. #define IB_BTH_A_SHIFT 31
  194. #define IB_BTH_M_MASK 1
  195. #define IB_BTH_M_SHIFT 22
  196. #define IB_BTH_SE_MASK 1
  197. #define IB_BTH_SE_SHIFT 23
  198. #define IB_BTH_TVER_MASK 0xf
  199. #define IB_BTH_TVER_SHIFT 16
  200. #define IB_BTH_OPCODE_CNP 0x81
  201. static inline u8 ib_bth_get_pad(struct ib_other_headers *ohdr)
  202. {
  203. return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_PAD_SHIFT) &
  204. IB_BTH_PAD_MASK);
  205. }
  206. static inline u16 ib_bth_get_pkey(struct ib_other_headers *ohdr)
  207. {
  208. return (be32_to_cpu(ohdr->bth[0]) & IB_BTH_PKEY_MASK);
  209. }
  210. static inline u8 ib_bth_get_opcode(struct ib_other_headers *ohdr)
  211. {
  212. return ((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_OPCODE_SHIFT) &
  213. IB_BTH_OPCODE_MASK);
  214. }
  215. static inline u8 ib_bth_get_ackreq(struct ib_other_headers *ohdr)
  216. {
  217. return (u8)((be32_to_cpu(ohdr->bth[2]) >> IB_BTH_A_SHIFT) &
  218. IB_BTH_A_MASK);
  219. }
  220. static inline u8 ib_bth_get_migreq(struct ib_other_headers *ohdr)
  221. {
  222. return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_M_SHIFT) &
  223. IB_BTH_M_MASK);
  224. }
  225. static inline u8 ib_bth_get_se(struct ib_other_headers *ohdr)
  226. {
  227. return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_SE_SHIFT) &
  228. IB_BTH_SE_MASK);
  229. }
  230. static inline u32 ib_bth_get_psn(struct ib_other_headers *ohdr)
  231. {
  232. return (u32)(be32_to_cpu(ohdr->bth[2]));
  233. }
  234. static inline u32 ib_bth_get_qpn(struct ib_other_headers *ohdr)
  235. {
  236. return (u32)((be32_to_cpu(ohdr->bth[1])) & IB_QPN_MASK);
  237. }
  238. static inline bool ib_bth_get_becn(struct ib_other_headers *ohdr)
  239. {
  240. return (ohdr->bth[1]) & cpu_to_be32(IB_BECN_SMASK);
  241. }
  242. static inline bool ib_bth_get_fecn(struct ib_other_headers *ohdr)
  243. {
  244. return (ohdr->bth[1]) & cpu_to_be32(IB_FECN_SMASK);
  245. }
  246. static inline u8 ib_bth_get_tver(struct ib_other_headers *ohdr)
  247. {
  248. return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_TVER_SHIFT) &
  249. IB_BTH_TVER_MASK);
  250. }
  251. static inline bool ib_bth_is_solicited(struct ib_other_headers *ohdr)
  252. {
  253. return ohdr->bth[0] & cpu_to_be32(IB_BTH_SOLICITED);
  254. }
  255. static inline bool ib_bth_is_migration(struct ib_other_headers *ohdr)
  256. {
  257. return ohdr->bth[0] & cpu_to_be32(IB_BTH_MIG_REQ);
  258. }
  259. #endif /* IB_HDRS_H */