common.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
  2. /*
  3. * Copyright(c) 2015 - 2020 Intel Corporation.
  4. */
  5. #ifndef _COMMON_H
  6. #define _COMMON_H
  7. #include <rdma/hfi/hfi1_user.h>
  8. /*
  9. * This file contains defines, structures, etc. that are used
  10. * to communicate between kernel and user code.
  11. */
  12. /* version of protocol header (known to chip also). In the long run,
  13. * we should be able to generate and accept a range of version numbers;
  14. * for now we only accept one, and it's compiled in.
  15. */
  16. #define IPS_PROTO_VERSION 2
  17. /*
  18. * These are compile time constants that you may want to enable or disable
  19. * if you are trying to debug problems with code or performance.
  20. * HFI1_VERBOSE_TRACING define as 1 if you want additional tracing in
  21. * fast path code
  22. * HFI1_TRACE_REGWRITES define as 1 if you want register writes to be
  23. * traced in fast path code
  24. * _HFI1_TRACING define as 0 if you want to remove all tracing in a
  25. * compilation unit
  26. */
  27. /* driver/hw feature set bitmask */
  28. #define HFI1_CAP_USER_SHIFT 24
  29. #define HFI1_CAP_MASK ((1UL << HFI1_CAP_USER_SHIFT) - 1)
  30. /* locked flag - if set, only HFI1_CAP_WRITABLE_MASK bits can be set */
  31. #define HFI1_CAP_LOCKED_SHIFT 63
  32. #define HFI1_CAP_LOCKED_MASK 0x1ULL
  33. #define HFI1_CAP_LOCKED_SMASK (HFI1_CAP_LOCKED_MASK << HFI1_CAP_LOCKED_SHIFT)
  34. /* extra bits used between kernel and user processes */
  35. #define HFI1_CAP_MISC_SHIFT (HFI1_CAP_USER_SHIFT * 2)
  36. #define HFI1_CAP_MISC_MASK ((1ULL << (HFI1_CAP_LOCKED_SHIFT - \
  37. HFI1_CAP_MISC_SHIFT)) - 1)
  38. #define HFI1_CAP_KSET(cap) ({ hfi1_cap_mask |= HFI1_CAP_##cap; hfi1_cap_mask; })
  39. #define HFI1_CAP_KCLEAR(cap) \
  40. ({ \
  41. hfi1_cap_mask &= ~HFI1_CAP_##cap; \
  42. hfi1_cap_mask; \
  43. })
  44. #define HFI1_CAP_USET(cap) \
  45. ({ \
  46. hfi1_cap_mask |= (HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT); \
  47. hfi1_cap_mask; \
  48. })
  49. #define HFI1_CAP_UCLEAR(cap) \
  50. ({ \
  51. hfi1_cap_mask &= ~(HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT); \
  52. hfi1_cap_mask; \
  53. })
  54. #define HFI1_CAP_SET(cap) \
  55. ({ \
  56. hfi1_cap_mask |= (HFI1_CAP_##cap | (HFI1_CAP_##cap << \
  57. HFI1_CAP_USER_SHIFT)); \
  58. hfi1_cap_mask; \
  59. })
  60. #define HFI1_CAP_CLEAR(cap) \
  61. ({ \
  62. hfi1_cap_mask &= ~(HFI1_CAP_##cap | \
  63. (HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT)); \
  64. hfi1_cap_mask; \
  65. })
  66. #define HFI1_CAP_LOCK() \
  67. ({ hfi1_cap_mask |= HFI1_CAP_LOCKED_SMASK; hfi1_cap_mask; })
  68. #define HFI1_CAP_LOCKED() (!!(hfi1_cap_mask & HFI1_CAP_LOCKED_SMASK))
  69. /*
  70. * The set of capability bits that can be changed after initial load
  71. * This set is the same for kernel and user contexts. However, for
  72. * user contexts, the set can be further filtered by using the
  73. * HFI1_CAP_RESERVED_MASK bits.
  74. */
  75. #define HFI1_CAP_WRITABLE_MASK (HFI1_CAP_SDMA_AHG | \
  76. HFI1_CAP_HDRSUPP | \
  77. HFI1_CAP_MULTI_PKT_EGR | \
  78. HFI1_CAP_NODROP_RHQ_FULL | \
  79. HFI1_CAP_NODROP_EGR_FULL | \
  80. HFI1_CAP_ALLOW_PERM_JKEY | \
  81. HFI1_CAP_STATIC_RATE_CTRL | \
  82. HFI1_CAP_PRINT_UNIMPL | \
  83. HFI1_CAP_TID_UNMAP | \
  84. HFI1_CAP_OPFN)
  85. /*
  86. * A set of capability bits that are "global" and are not allowed to be
  87. * set in the user bitmask.
  88. */
  89. #define HFI1_CAP_RESERVED_MASK ((HFI1_CAP_SDMA | \
  90. HFI1_CAP_USE_SDMA_HEAD | \
  91. HFI1_CAP_EXTENDED_PSN | \
  92. HFI1_CAP_PRINT_UNIMPL | \
  93. HFI1_CAP_NO_INTEGRITY | \
  94. HFI1_CAP_PKEY_CHECK | \
  95. HFI1_CAP_TID_RDMA | \
  96. HFI1_CAP_OPFN | \
  97. HFI1_CAP_AIP) << \
  98. HFI1_CAP_USER_SHIFT)
  99. /*
  100. * Set of capabilities that need to be enabled for kernel context in
  101. * order to be allowed for user contexts, as well.
  102. */
  103. #define HFI1_CAP_MUST_HAVE_KERN (HFI1_CAP_STATIC_RATE_CTRL)
  104. /* Default enabled capabilities (both kernel and user) */
  105. #define HFI1_CAP_MASK_DEFAULT (HFI1_CAP_HDRSUPP | \
  106. HFI1_CAP_NODROP_RHQ_FULL | \
  107. HFI1_CAP_NODROP_EGR_FULL | \
  108. HFI1_CAP_SDMA | \
  109. HFI1_CAP_PRINT_UNIMPL | \
  110. HFI1_CAP_STATIC_RATE_CTRL | \
  111. HFI1_CAP_PKEY_CHECK | \
  112. HFI1_CAP_MULTI_PKT_EGR | \
  113. HFI1_CAP_EXTENDED_PSN | \
  114. HFI1_CAP_AIP | \
  115. ((HFI1_CAP_HDRSUPP | \
  116. HFI1_CAP_MULTI_PKT_EGR | \
  117. HFI1_CAP_STATIC_RATE_CTRL | \
  118. HFI1_CAP_PKEY_CHECK | \
  119. HFI1_CAP_EARLY_CREDIT_RETURN) << \
  120. HFI1_CAP_USER_SHIFT))
  121. /*
  122. * A bitmask of kernel/global capabilities that should be communicated
  123. * to user level processes.
  124. */
  125. #define HFI1_CAP_K2U (HFI1_CAP_SDMA | \
  126. HFI1_CAP_EXTENDED_PSN | \
  127. HFI1_CAP_PKEY_CHECK | \
  128. HFI1_CAP_NO_INTEGRITY)
  129. #define HFI1_USER_SWVERSION ((HFI1_USER_SWMAJOR << HFI1_SWMAJOR_SHIFT) | \
  130. HFI1_USER_SWMINOR)
  131. /*
  132. * The next set of defines are for packet headers, and chip register
  133. * and memory bits that are visible to and/or used by user-mode software.
  134. */
  135. /*
  136. * Receive Header Flags
  137. */
  138. #define RHF_PKT_LEN_SHIFT 0
  139. #define RHF_PKT_LEN_MASK 0xfffull
  140. #define RHF_PKT_LEN_SMASK (RHF_PKT_LEN_MASK << RHF_PKT_LEN_SHIFT)
  141. #define RHF_RCV_TYPE_SHIFT 12
  142. #define RHF_RCV_TYPE_MASK 0x7ull
  143. #define RHF_RCV_TYPE_SMASK (RHF_RCV_TYPE_MASK << RHF_RCV_TYPE_SHIFT)
  144. #define RHF_USE_EGR_BFR_SHIFT 15
  145. #define RHF_USE_EGR_BFR_MASK 0x1ull
  146. #define RHF_USE_EGR_BFR_SMASK (RHF_USE_EGR_BFR_MASK << RHF_USE_EGR_BFR_SHIFT)
  147. #define RHF_EGR_INDEX_SHIFT 16
  148. #define RHF_EGR_INDEX_MASK 0x7ffull
  149. #define RHF_EGR_INDEX_SMASK (RHF_EGR_INDEX_MASK << RHF_EGR_INDEX_SHIFT)
  150. #define RHF_DC_INFO_SHIFT 27
  151. #define RHF_DC_INFO_MASK 0x1ull
  152. #define RHF_DC_INFO_SMASK (RHF_DC_INFO_MASK << RHF_DC_INFO_SHIFT)
  153. #define RHF_RCV_SEQ_SHIFT 28
  154. #define RHF_RCV_SEQ_MASK 0xfull
  155. #define RHF_RCV_SEQ_SMASK (RHF_RCV_SEQ_MASK << RHF_RCV_SEQ_SHIFT)
  156. #define RHF_EGR_OFFSET_SHIFT 32
  157. #define RHF_EGR_OFFSET_MASK 0xfffull
  158. #define RHF_EGR_OFFSET_SMASK (RHF_EGR_OFFSET_MASK << RHF_EGR_OFFSET_SHIFT)
  159. #define RHF_HDRQ_OFFSET_SHIFT 44
  160. #define RHF_HDRQ_OFFSET_MASK 0x1ffull
  161. #define RHF_HDRQ_OFFSET_SMASK (RHF_HDRQ_OFFSET_MASK << RHF_HDRQ_OFFSET_SHIFT)
  162. #define RHF_K_HDR_LEN_ERR (0x1ull << 53)
  163. #define RHF_DC_UNC_ERR (0x1ull << 54)
  164. #define RHF_DC_ERR (0x1ull << 55)
  165. #define RHF_RCV_TYPE_ERR_SHIFT 56
  166. #define RHF_RCV_TYPE_ERR_MASK 0x7ul
  167. #define RHF_RCV_TYPE_ERR_SMASK (RHF_RCV_TYPE_ERR_MASK << RHF_RCV_TYPE_ERR_SHIFT)
  168. #define RHF_TID_ERR (0x1ull << 59)
  169. #define RHF_LEN_ERR (0x1ull << 60)
  170. #define RHF_ECC_ERR (0x1ull << 61)
  171. #define RHF_RESERVED (0x1ull << 62)
  172. #define RHF_ICRC_ERR (0x1ull << 63)
  173. #define RHF_ERROR_SMASK 0xffe0000000000000ull /* bits 63:53 */
  174. /* RHF receive types */
  175. #define RHF_RCV_TYPE_EXPECTED 0
  176. #define RHF_RCV_TYPE_EAGER 1
  177. #define RHF_RCV_TYPE_IB 2 /* normal IB, IB Raw, or IPv6 */
  178. #define RHF_RCV_TYPE_ERROR 3
  179. #define RHF_RCV_TYPE_BYPASS 4
  180. #define RHF_RCV_TYPE_INVALID5 5
  181. #define RHF_RCV_TYPE_INVALID6 6
  182. #define RHF_RCV_TYPE_INVALID7 7
  183. /* RHF receive type error - expected packet errors */
  184. #define RHF_RTE_EXPECTED_FLOW_SEQ_ERR 0x2
  185. #define RHF_RTE_EXPECTED_FLOW_GEN_ERR 0x4
  186. /* RHF receive type error - eager packet errors */
  187. #define RHF_RTE_EAGER_NO_ERR 0x0
  188. /* RHF receive type error - IB packet errors */
  189. #define RHF_RTE_IB_NO_ERR 0x0
  190. /* RHF receive type error - error packet errors */
  191. #define RHF_RTE_ERROR_NO_ERR 0x0
  192. #define RHF_RTE_ERROR_OP_CODE_ERR 0x1
  193. #define RHF_RTE_ERROR_KHDR_MIN_LEN_ERR 0x2
  194. #define RHF_RTE_ERROR_KHDR_HCRC_ERR 0x3
  195. #define RHF_RTE_ERROR_KHDR_KVER_ERR 0x4
  196. #define RHF_RTE_ERROR_CONTEXT_ERR 0x5
  197. #define RHF_RTE_ERROR_KHDR_TID_ERR 0x6
  198. /* RHF receive type error - bypass packet errors */
  199. #define RHF_RTE_BYPASS_NO_ERR 0x0
  200. /* MAX RcvSEQ */
  201. #define RHF_MAX_SEQ 13
  202. /* IB - LRH header constants */
  203. #define HFI1_LRH_GRH 0x0003 /* 1. word of IB LRH - next header: GRH */
  204. #define HFI1_LRH_BTH 0x0002 /* 1. word of IB LRH - next header: BTH */
  205. /* misc. */
  206. #define SC15_PACKET 0xF
  207. #define SIZE_OF_CRC 1
  208. #define SIZE_OF_LT 1
  209. #define MAX_16B_PADDING 12 /* CRC = 4, LT = 1, Pad = 0 to 7 bytes */
  210. #define LIM_MGMT_P_KEY 0x7FFF
  211. #define FULL_MGMT_P_KEY 0xFFFF
  212. #define DEFAULT_P_KEY LIM_MGMT_P_KEY
  213. #define HFI1_PSM_IOC_BASE_SEQ 0x0
  214. /* Number of BTH.PSN bits used for sequence number in expected rcvs */
  215. #define HFI1_KDETH_BTH_SEQ_SHIFT 11
  216. #define HFI1_KDETH_BTH_SEQ_MASK (BIT(HFI1_KDETH_BTH_SEQ_SHIFT) - 1)
  217. static inline __u64 rhf_to_cpu(const __le32 *rbuf)
  218. {
  219. return __le64_to_cpu(*((__le64 *)rbuf));
  220. }
  221. static inline u64 rhf_err_flags(u64 rhf)
  222. {
  223. return rhf & RHF_ERROR_SMASK;
  224. }
  225. static inline u32 rhf_rcv_type(u64 rhf)
  226. {
  227. return (rhf >> RHF_RCV_TYPE_SHIFT) & RHF_RCV_TYPE_MASK;
  228. }
  229. static inline u32 rhf_rcv_type_err(u64 rhf)
  230. {
  231. return (rhf >> RHF_RCV_TYPE_ERR_SHIFT) & RHF_RCV_TYPE_ERR_MASK;
  232. }
  233. /* return size is in bytes, not DWORDs */
  234. static inline u32 rhf_pkt_len(u64 rhf)
  235. {
  236. return ((rhf & RHF_PKT_LEN_SMASK) >> RHF_PKT_LEN_SHIFT) << 2;
  237. }
  238. static inline u32 rhf_egr_index(u64 rhf)
  239. {
  240. return (rhf >> RHF_EGR_INDEX_SHIFT) & RHF_EGR_INDEX_MASK;
  241. }
  242. static inline u32 rhf_rcv_seq(u64 rhf)
  243. {
  244. return (rhf >> RHF_RCV_SEQ_SHIFT) & RHF_RCV_SEQ_MASK;
  245. }
  246. /* returned offset is in DWORDS */
  247. static inline u32 rhf_hdrq_offset(u64 rhf)
  248. {
  249. return (rhf >> RHF_HDRQ_OFFSET_SHIFT) & RHF_HDRQ_OFFSET_MASK;
  250. }
  251. static inline u64 rhf_use_egr_bfr(u64 rhf)
  252. {
  253. return rhf & RHF_USE_EGR_BFR_SMASK;
  254. }
  255. static inline u64 rhf_dc_info(u64 rhf)
  256. {
  257. return rhf & RHF_DC_INFO_SMASK;
  258. }
  259. static inline u32 rhf_egr_buf_offset(u64 rhf)
  260. {
  261. return (rhf >> RHF_EGR_OFFSET_SHIFT) & RHF_EGR_OFFSET_MASK;
  262. }
  263. #endif /* _COMMON_H */