common.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /*
  2. * Copyright(c) 2015, 2016 Intel Corporation.
  3. *
  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. #ifndef _COMMON_H
  48. #define _COMMON_H
  49. #include <rdma/hfi/hfi1_user.h>
  50. /*
  51. * This file contains defines, structures, etc. that are used
  52. * to communicate between kernel and user code.
  53. */
  54. /* version of protocol header (known to chip also). In the long run,
  55. * we should be able to generate and accept a range of version numbers;
  56. * for now we only accept one, and it's compiled in.
  57. */
  58. #define IPS_PROTO_VERSION 2
  59. /*
  60. * These are compile time constants that you may want to enable or disable
  61. * if you are trying to debug problems with code or performance.
  62. * HFI1_VERBOSE_TRACING define as 1 if you want additional tracing in
  63. * fast path code
  64. * HFI1_TRACE_REGWRITES define as 1 if you want register writes to be
  65. * traced in fast path code
  66. * _HFI1_TRACING define as 0 if you want to remove all tracing in a
  67. * compilation unit
  68. */
  69. /*
  70. * If a packet's QP[23:16] bits match this value, then it is
  71. * a PSM packet and the hardware will expect a KDETH header
  72. * following the BTH.
  73. */
  74. #define DEFAULT_KDETH_QP 0x80
  75. /* driver/hw feature set bitmask */
  76. #define HFI1_CAP_USER_SHIFT 24
  77. #define HFI1_CAP_MASK ((1UL << HFI1_CAP_USER_SHIFT) - 1)
  78. /* locked flag - if set, only HFI1_CAP_WRITABLE_MASK bits can be set */
  79. #define HFI1_CAP_LOCKED_SHIFT 63
  80. #define HFI1_CAP_LOCKED_MASK 0x1ULL
  81. #define HFI1_CAP_LOCKED_SMASK (HFI1_CAP_LOCKED_MASK << HFI1_CAP_LOCKED_SHIFT)
  82. /* extra bits used between kernel and user processes */
  83. #define HFI1_CAP_MISC_SHIFT (HFI1_CAP_USER_SHIFT * 2)
  84. #define HFI1_CAP_MISC_MASK ((1ULL << (HFI1_CAP_LOCKED_SHIFT - \
  85. HFI1_CAP_MISC_SHIFT)) - 1)
  86. #define HFI1_CAP_KSET(cap) ({ hfi1_cap_mask |= HFI1_CAP_##cap; hfi1_cap_mask; })
  87. #define HFI1_CAP_KCLEAR(cap) \
  88. ({ \
  89. hfi1_cap_mask &= ~HFI1_CAP_##cap; \
  90. hfi1_cap_mask; \
  91. })
  92. #define HFI1_CAP_USET(cap) \
  93. ({ \
  94. hfi1_cap_mask |= (HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT); \
  95. hfi1_cap_mask; \
  96. })
  97. #define HFI1_CAP_UCLEAR(cap) \
  98. ({ \
  99. hfi1_cap_mask &= ~(HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT); \
  100. hfi1_cap_mask; \
  101. })
  102. #define HFI1_CAP_SET(cap) \
  103. ({ \
  104. hfi1_cap_mask |= (HFI1_CAP_##cap | (HFI1_CAP_##cap << \
  105. HFI1_CAP_USER_SHIFT)); \
  106. hfi1_cap_mask; \
  107. })
  108. #define HFI1_CAP_CLEAR(cap) \
  109. ({ \
  110. hfi1_cap_mask &= ~(HFI1_CAP_##cap | \
  111. (HFI1_CAP_##cap << HFI1_CAP_USER_SHIFT)); \
  112. hfi1_cap_mask; \
  113. })
  114. #define HFI1_CAP_LOCK() \
  115. ({ hfi1_cap_mask |= HFI1_CAP_LOCKED_SMASK; hfi1_cap_mask; })
  116. #define HFI1_CAP_LOCKED() (!!(hfi1_cap_mask & HFI1_CAP_LOCKED_SMASK))
  117. /*
  118. * The set of capability bits that can be changed after initial load
  119. * This set is the same for kernel and user contexts. However, for
  120. * user contexts, the set can be further filtered by using the
  121. * HFI1_CAP_RESERVED_MASK bits.
  122. */
  123. #define HFI1_CAP_WRITABLE_MASK (HFI1_CAP_SDMA_AHG | \
  124. HFI1_CAP_HDRSUPP | \
  125. HFI1_CAP_MULTI_PKT_EGR | \
  126. HFI1_CAP_NODROP_RHQ_FULL | \
  127. HFI1_CAP_NODROP_EGR_FULL | \
  128. HFI1_CAP_ALLOW_PERM_JKEY | \
  129. HFI1_CAP_STATIC_RATE_CTRL | \
  130. HFI1_CAP_PRINT_UNIMPL | \
  131. HFI1_CAP_TID_UNMAP)
  132. /*
  133. * A set of capability bits that are "global" and are not allowed to be
  134. * set in the user bitmask.
  135. */
  136. #define HFI1_CAP_RESERVED_MASK ((HFI1_CAP_SDMA | \
  137. HFI1_CAP_USE_SDMA_HEAD | \
  138. HFI1_CAP_EXTENDED_PSN | \
  139. HFI1_CAP_PRINT_UNIMPL | \
  140. HFI1_CAP_NO_INTEGRITY | \
  141. HFI1_CAP_PKEY_CHECK) << \
  142. HFI1_CAP_USER_SHIFT)
  143. /*
  144. * Set of capabilities that need to be enabled for kernel context in
  145. * order to be allowed for user contexts, as well.
  146. */
  147. #define HFI1_CAP_MUST_HAVE_KERN (HFI1_CAP_STATIC_RATE_CTRL)
  148. /* Default enabled capabilities (both kernel and user) */
  149. #define HFI1_CAP_MASK_DEFAULT (HFI1_CAP_HDRSUPP | \
  150. HFI1_CAP_NODROP_RHQ_FULL | \
  151. HFI1_CAP_NODROP_EGR_FULL | \
  152. HFI1_CAP_SDMA | \
  153. HFI1_CAP_PRINT_UNIMPL | \
  154. HFI1_CAP_STATIC_RATE_CTRL | \
  155. HFI1_CAP_PKEY_CHECK | \
  156. HFI1_CAP_MULTI_PKT_EGR | \
  157. HFI1_CAP_EXTENDED_PSN | \
  158. ((HFI1_CAP_HDRSUPP | \
  159. HFI1_CAP_MULTI_PKT_EGR | \
  160. HFI1_CAP_STATIC_RATE_CTRL | \
  161. HFI1_CAP_PKEY_CHECK | \
  162. HFI1_CAP_EARLY_CREDIT_RETURN) << \
  163. HFI1_CAP_USER_SHIFT))
  164. /*
  165. * A bitmask of kernel/global capabilities that should be communicated
  166. * to user level processes.
  167. */
  168. #define HFI1_CAP_K2U (HFI1_CAP_SDMA | \
  169. HFI1_CAP_EXTENDED_PSN | \
  170. HFI1_CAP_PKEY_CHECK | \
  171. HFI1_CAP_NO_INTEGRITY)
  172. #define HFI1_USER_SWVERSION ((HFI1_USER_SWMAJOR << HFI1_SWMAJOR_SHIFT) | \
  173. HFI1_USER_SWMINOR)
  174. #ifndef HFI1_KERN_TYPE
  175. #define HFI1_KERN_TYPE 0
  176. #endif
  177. /*
  178. * Similarly, this is the kernel version going back to the user. It's
  179. * slightly different, in that we want to tell if the driver was built as
  180. * part of a Intel release, or from the driver from openfabrics.org,
  181. * kernel.org, or a standard distribution, for support reasons.
  182. * The high bit is 0 for non-Intel and 1 for Intel-built/supplied.
  183. *
  184. * It's returned by the driver to the user code during initialization in the
  185. * spi_sw_version field of hfi1_base_info, so the user code can in turn
  186. * check for compatibility with the kernel.
  187. */
  188. #define HFI1_KERN_SWVERSION ((HFI1_KERN_TYPE << 31) | HFI1_USER_SWVERSION)
  189. /*
  190. * Define the driver version number. This is something that refers only
  191. * to the driver itself, not the software interfaces it supports.
  192. */
  193. #ifndef HFI1_DRIVER_VERSION_BASE
  194. #define HFI1_DRIVER_VERSION_BASE "0.9-294"
  195. #endif
  196. /* create the final driver version string */
  197. #ifdef HFI1_IDSTR
  198. #define HFI1_DRIVER_VERSION HFI1_DRIVER_VERSION_BASE " " HFI1_IDSTR
  199. #else
  200. #define HFI1_DRIVER_VERSION HFI1_DRIVER_VERSION_BASE
  201. #endif
  202. /*
  203. * Diagnostics can send a packet by writing the following
  204. * struct to the diag packet special file.
  205. *
  206. * This allows a custom PBC qword, so that special modes and deliberate
  207. * changes to CRCs can be used.
  208. */
  209. #define _DIAG_PKT_VERS 1
  210. struct diag_pkt {
  211. __u16 version; /* structure version */
  212. __u16 unit; /* which device */
  213. __u16 sw_index; /* send sw index to use */
  214. __u16 len; /* data length, in bytes */
  215. __u16 port; /* port number */
  216. __u16 unused;
  217. __u32 flags; /* call flags */
  218. __u64 data; /* user data pointer */
  219. __u64 pbc; /* PBC for the packet */
  220. };
  221. /* diag_pkt flags */
  222. #define F_DIAGPKT_WAIT 0x1 /* wait until packet is sent */
  223. /*
  224. * The next set of defines are for packet headers, and chip register
  225. * and memory bits that are visible to and/or used by user-mode software.
  226. */
  227. /*
  228. * Receive Header Flags
  229. */
  230. #define RHF_PKT_LEN_SHIFT 0
  231. #define RHF_PKT_LEN_MASK 0xfffull
  232. #define RHF_PKT_LEN_SMASK (RHF_PKT_LEN_MASK << RHF_PKT_LEN_SHIFT)
  233. #define RHF_RCV_TYPE_SHIFT 12
  234. #define RHF_RCV_TYPE_MASK 0x7ull
  235. #define RHF_RCV_TYPE_SMASK (RHF_RCV_TYPE_MASK << RHF_RCV_TYPE_SHIFT)
  236. #define RHF_USE_EGR_BFR_SHIFT 15
  237. #define RHF_USE_EGR_BFR_MASK 0x1ull
  238. #define RHF_USE_EGR_BFR_SMASK (RHF_USE_EGR_BFR_MASK << RHF_USE_EGR_BFR_SHIFT)
  239. #define RHF_EGR_INDEX_SHIFT 16
  240. #define RHF_EGR_INDEX_MASK 0x7ffull
  241. #define RHF_EGR_INDEX_SMASK (RHF_EGR_INDEX_MASK << RHF_EGR_INDEX_SHIFT)
  242. #define RHF_DC_INFO_SHIFT 27
  243. #define RHF_DC_INFO_MASK 0x1ull
  244. #define RHF_DC_INFO_SMASK (RHF_DC_INFO_MASK << RHF_DC_INFO_SHIFT)
  245. #define RHF_RCV_SEQ_SHIFT 28
  246. #define RHF_RCV_SEQ_MASK 0xfull
  247. #define RHF_RCV_SEQ_SMASK (RHF_RCV_SEQ_MASK << RHF_RCV_SEQ_SHIFT)
  248. #define RHF_EGR_OFFSET_SHIFT 32
  249. #define RHF_EGR_OFFSET_MASK 0xfffull
  250. #define RHF_EGR_OFFSET_SMASK (RHF_EGR_OFFSET_MASK << RHF_EGR_OFFSET_SHIFT)
  251. #define RHF_HDRQ_OFFSET_SHIFT 44
  252. #define RHF_HDRQ_OFFSET_MASK 0x1ffull
  253. #define RHF_HDRQ_OFFSET_SMASK (RHF_HDRQ_OFFSET_MASK << RHF_HDRQ_OFFSET_SHIFT)
  254. #define RHF_K_HDR_LEN_ERR (0x1ull << 53)
  255. #define RHF_DC_UNC_ERR (0x1ull << 54)
  256. #define RHF_DC_ERR (0x1ull << 55)
  257. #define RHF_RCV_TYPE_ERR_SHIFT 56
  258. #define RHF_RCV_TYPE_ERR_MASK 0x7ul
  259. #define RHF_RCV_TYPE_ERR_SMASK (RHF_RCV_TYPE_ERR_MASK << RHF_RCV_TYPE_ERR_SHIFT)
  260. #define RHF_TID_ERR (0x1ull << 59)
  261. #define RHF_LEN_ERR (0x1ull << 60)
  262. #define RHF_ECC_ERR (0x1ull << 61)
  263. #define RHF_VCRC_ERR (0x1ull << 62)
  264. #define RHF_ICRC_ERR (0x1ull << 63)
  265. #define RHF_ERROR_SMASK 0xffe0000000000000ull /* bits 63:53 */
  266. /* RHF receive types */
  267. #define RHF_RCV_TYPE_EXPECTED 0
  268. #define RHF_RCV_TYPE_EAGER 1
  269. #define RHF_RCV_TYPE_IB 2 /* normal IB, IB Raw, or IPv6 */
  270. #define RHF_RCV_TYPE_ERROR 3
  271. #define RHF_RCV_TYPE_BYPASS 4
  272. #define RHF_RCV_TYPE_INVALID5 5
  273. #define RHF_RCV_TYPE_INVALID6 6
  274. #define RHF_RCV_TYPE_INVALID7 7
  275. /* RHF receive type error - expected packet errors */
  276. #define RHF_RTE_EXPECTED_FLOW_SEQ_ERR 0x2
  277. #define RHF_RTE_EXPECTED_FLOW_GEN_ERR 0x4
  278. /* RHF receive type error - eager packet errors */
  279. #define RHF_RTE_EAGER_NO_ERR 0x0
  280. /* RHF receive type error - IB packet errors */
  281. #define RHF_RTE_IB_NO_ERR 0x0
  282. /* RHF receive type error - error packet errors */
  283. #define RHF_RTE_ERROR_NO_ERR 0x0
  284. #define RHF_RTE_ERROR_OP_CODE_ERR 0x1
  285. #define RHF_RTE_ERROR_KHDR_MIN_LEN_ERR 0x2
  286. #define RHF_RTE_ERROR_KHDR_HCRC_ERR 0x3
  287. #define RHF_RTE_ERROR_KHDR_KVER_ERR 0x4
  288. #define RHF_RTE_ERROR_CONTEXT_ERR 0x5
  289. #define RHF_RTE_ERROR_KHDR_TID_ERR 0x6
  290. /* RHF receive type error - bypass packet errors */
  291. #define RHF_RTE_BYPASS_NO_ERR 0x0
  292. /* IB - LRH header constants */
  293. #define HFI1_LRH_GRH 0x0003 /* 1. word of IB LRH - next header: GRH */
  294. #define HFI1_LRH_BTH 0x0002 /* 1. word of IB LRH - next header: BTH */
  295. /* misc. */
  296. #define SC15_PACKET 0xF
  297. #define SIZE_OF_CRC 1
  298. #define SIZE_OF_LT 1
  299. #define MAX_16B_PADDING 12 /* CRC = 4, LT = 1, Pad = 0 to 7 bytes */
  300. #define LIM_MGMT_P_KEY 0x7FFF
  301. #define FULL_MGMT_P_KEY 0xFFFF
  302. #define DEFAULT_P_KEY LIM_MGMT_P_KEY
  303. #define HFI1_PSM_IOC_BASE_SEQ 0x0
  304. static inline __u64 rhf_to_cpu(const __le32 *rbuf)
  305. {
  306. return __le64_to_cpu(*((__le64 *)rbuf));
  307. }
  308. static inline u64 rhf_err_flags(u64 rhf)
  309. {
  310. return rhf & RHF_ERROR_SMASK;
  311. }
  312. static inline u32 rhf_rcv_type(u64 rhf)
  313. {
  314. return (rhf >> RHF_RCV_TYPE_SHIFT) & RHF_RCV_TYPE_MASK;
  315. }
  316. static inline u32 rhf_rcv_type_err(u64 rhf)
  317. {
  318. return (rhf >> RHF_RCV_TYPE_ERR_SHIFT) & RHF_RCV_TYPE_ERR_MASK;
  319. }
  320. /* return size is in bytes, not DWORDs */
  321. static inline u32 rhf_pkt_len(u64 rhf)
  322. {
  323. return ((rhf & RHF_PKT_LEN_SMASK) >> RHF_PKT_LEN_SHIFT) << 2;
  324. }
  325. static inline u32 rhf_egr_index(u64 rhf)
  326. {
  327. return (rhf >> RHF_EGR_INDEX_SHIFT) & RHF_EGR_INDEX_MASK;
  328. }
  329. static inline u32 rhf_rcv_seq(u64 rhf)
  330. {
  331. return (rhf >> RHF_RCV_SEQ_SHIFT) & RHF_RCV_SEQ_MASK;
  332. }
  333. /* returned offset is in DWORDS */
  334. static inline u32 rhf_hdrq_offset(u64 rhf)
  335. {
  336. return (rhf >> RHF_HDRQ_OFFSET_SHIFT) & RHF_HDRQ_OFFSET_MASK;
  337. }
  338. static inline u64 rhf_use_egr_bfr(u64 rhf)
  339. {
  340. return rhf & RHF_USE_EGR_BFR_SMASK;
  341. }
  342. static inline u64 rhf_dc_info(u64 rhf)
  343. {
  344. return rhf & RHF_DC_INFO_SMASK;
  345. }
  346. static inline u32 rhf_egr_buf_offset(u64 rhf)
  347. {
  348. return (rhf >> RHF_EGR_OFFSET_SHIFT) & RHF_EGR_OFFSET_MASK;
  349. }
  350. #endif /* _COMMON_H */