hfi1_user.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
  17. /*
  18. *
  19. * This file is provided under a dual BSD/GPLv2 license. When using or
  20. * redistributing this file, you may do so under either license.
  21. *
  22. * GPL LICENSE SUMMARY
  23. *
  24. * Copyright(c) 2015 - 2020 Intel Corporation.
  25. *
  26. * This program is free software; you can redistribute it and/or modify
  27. * it under the terms of version 2 of the GNU General Public License as
  28. * published by the Free Software Foundation.
  29. *
  30. * This program is distributed in the hope that it will be useful, but
  31. * WITHOUT ANY WARRANTY; without even the implied warranty of
  32. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  33. * General Public License for more details.
  34. *
  35. * BSD LICENSE
  36. *
  37. * Copyright(c) 2015 Intel Corporation.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. *
  43. * - Redistributions of source code must retain the above copyright
  44. * notice, this list of conditions and the following disclaimer.
  45. * - Redistributions in binary form must reproduce the above copyright
  46. * notice, this list of conditions and the following disclaimer in
  47. * the documentation and/or other materials provided with the
  48. * distribution.
  49. * - Neither the name of Intel Corporation nor the names of its
  50. * contributors may be used to endorse or promote products derived
  51. * from this software without specific prior written permission.
  52. *
  53. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  54. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  55. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  56. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  57. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  58. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  59. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  60. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  61. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  62. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  63. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  64. *
  65. */
  66. /*
  67. * This file contains defines, structures, etc. that are used
  68. * to communicate between kernel and user code.
  69. */
  70. #ifndef _LINUX__HFI1_USER_H
  71. #define _LINUX__HFI1_USER_H
  72. #include <linux/types.h>
  73. #include <rdma/rdma_user_ioctl.h>
  74. /*
  75. * This version number is given to the driver by the user code during
  76. * initialization in the spu_userversion field of hfi1_user_info, so
  77. * the driver can check for compatibility with user code.
  78. *
  79. * The major version changes when data structures change in an incompatible
  80. * way. The driver must be the same for initialization to succeed.
  81. */
  82. #define HFI1_USER_SWMAJOR 6
  83. /*
  84. * Minor version differences are always compatible
  85. * a within a major version, however if user software is larger
  86. * than driver software, some new features and/or structure fields
  87. * may not be implemented; the user code must deal with this if it
  88. * cares, or it must abort after initialization reports the difference.
  89. */
  90. #define HFI1_USER_SWMINOR 3
  91. /*
  92. * We will encode the major/minor inside a single 32bit version number.
  93. */
  94. #define HFI1_SWMAJOR_SHIFT 16
  95. /*
  96. * Set of HW and driver capability/feature bits.
  97. * These bit values are used to configure enabled/disabled HW and
  98. * driver features. The same set of bits are communicated to user
  99. * space.
  100. */
  101. #define HFI1_CAP_DMA_RTAIL (1UL << 0) /* Use DMA'ed RTail value */
  102. #define HFI1_CAP_SDMA (1UL << 1) /* Enable SDMA support */
  103. #define HFI1_CAP_SDMA_AHG (1UL << 2) /* Enable SDMA AHG support */
  104. #define HFI1_CAP_EXTENDED_PSN (1UL << 3) /* Enable Extended PSN support */
  105. #define HFI1_CAP_HDRSUPP (1UL << 4) /* Enable Header Suppression */
  106. #define HFI1_CAP_TID_RDMA (1UL << 5) /* Enable TID RDMA operations */
  107. #define HFI1_CAP_USE_SDMA_HEAD (1UL << 6) /* DMA Hdr Q tail vs. use CSR */
  108. #define HFI1_CAP_MULTI_PKT_EGR (1UL << 7) /* Enable multi-packet Egr buffs*/
  109. #define HFI1_CAP_NODROP_RHQ_FULL (1UL << 8) /* Don't drop on Hdr Q full */
  110. #define HFI1_CAP_NODROP_EGR_FULL (1UL << 9) /* Don't drop on EGR buffs full */
  111. #define HFI1_CAP_TID_UNMAP (1UL << 10) /* Disable Expected TID caching */
  112. #define HFI1_CAP_PRINT_UNIMPL (1UL << 11) /* Show for unimplemented feats */
  113. #define HFI1_CAP_ALLOW_PERM_JKEY (1UL << 12) /* Allow use of permissive JKEY */
  114. #define HFI1_CAP_NO_INTEGRITY (1UL << 13) /* Enable ctxt integrity checks */
  115. #define HFI1_CAP_PKEY_CHECK (1UL << 14) /* Enable ctxt PKey checking */
  116. #define HFI1_CAP_STATIC_RATE_CTRL (1UL << 15) /* Allow PBC.StaticRateControl */
  117. #define HFI1_CAP_OPFN (1UL << 16) /* Enable the OPFN protocol */
  118. #define HFI1_CAP_SDMA_HEAD_CHECK (1UL << 17) /* SDMA head checking */
  119. #define HFI1_CAP_EARLY_CREDIT_RETURN (1UL << 18) /* early credit return */
  120. #define HFI1_CAP_AIP (1UL << 19) /* Enable accelerated IP */
  121. #define HFI1_RCVHDR_ENTSIZE_2 (1UL << 0)
  122. #define HFI1_RCVHDR_ENTSIZE_16 (1UL << 1)
  123. #define HFI1_RCVDHR_ENTSIZE_32 (1UL << 2)
  124. #define _HFI1_EVENT_FROZEN_BIT 0
  125. #define _HFI1_EVENT_LINKDOWN_BIT 1
  126. #define _HFI1_EVENT_LID_CHANGE_BIT 2
  127. #define _HFI1_EVENT_LMC_CHANGE_BIT 3
  128. #define _HFI1_EVENT_SL2VL_CHANGE_BIT 4
  129. #define _HFI1_EVENT_TID_MMU_NOTIFY_BIT 5
  130. #define _HFI1_MAX_EVENT_BIT _HFI1_EVENT_TID_MMU_NOTIFY_BIT
  131. #define HFI1_EVENT_FROZEN (1UL << _HFI1_EVENT_FROZEN_BIT)
  132. #define HFI1_EVENT_LINKDOWN (1UL << _HFI1_EVENT_LINKDOWN_BIT)
  133. #define HFI1_EVENT_LID_CHANGE (1UL << _HFI1_EVENT_LID_CHANGE_BIT)
  134. #define HFI1_EVENT_LMC_CHANGE (1UL << _HFI1_EVENT_LMC_CHANGE_BIT)
  135. #define HFI1_EVENT_SL2VL_CHANGE (1UL << _HFI1_EVENT_SL2VL_CHANGE_BIT)
  136. #define HFI1_EVENT_TID_MMU_NOTIFY (1UL << _HFI1_EVENT_TID_MMU_NOTIFY_BIT)
  137. /*
  138. * These are the status bits readable (in ASCII form, 64bit value)
  139. * from the "status" sysfs file. For binary compatibility, values
  140. * must remain as is; removed states can be reused for different
  141. * purposes.
  142. */
  143. #define HFI1_STATUS_INITTED 0x1 /* basic initialization done */
  144. /* Chip has been found and initialized */
  145. #define HFI1_STATUS_CHIP_PRESENT 0x20
  146. /* IB link is at ACTIVE, usable for data traffic */
  147. #define HFI1_STATUS_IB_READY 0x40
  148. /* link is configured, LID, MTU, etc. have been set */
  149. #define HFI1_STATUS_IB_CONF 0x80
  150. /* A Fatal hardware error has occurred. */
  151. #define HFI1_STATUS_HWERROR 0x200
  152. /*
  153. * Number of supported shared contexts.
  154. * This is the maximum number of software contexts that can share
  155. * a hardware send/receive context.
  156. */
  157. #define HFI1_MAX_SHARED_CTXTS 8
  158. /*
  159. * Poll types
  160. */
  161. #define HFI1_POLL_TYPE_ANYRCV 0x0
  162. #define HFI1_POLL_TYPE_URGENT 0x1
  163. enum hfi1_sdma_comp_state {
  164. FREE = 0,
  165. QUEUED,
  166. COMPLETE,
  167. ERROR
  168. };
  169. /*
  170. * SDMA completion ring entry
  171. */
  172. struct hfi1_sdma_comp_entry {
  173. __u32 status;
  174. __u32 errcode;
  175. };
  176. /*
  177. * Device status and notifications from driver to user-space.
  178. */
  179. struct hfi1_status {
  180. __aligned_u64 dev; /* device/hw status bits */
  181. __aligned_u64 port; /* port state and status bits */
  182. char freezemsg[];
  183. };
  184. enum sdma_req_opcode {
  185. EXPECTED = 0,
  186. EAGER
  187. };
  188. #define HFI1_SDMA_REQ_VERSION_MASK 0xF
  189. #define HFI1_SDMA_REQ_VERSION_SHIFT 0x0
  190. #define HFI1_SDMA_REQ_OPCODE_MASK 0xF
  191. #define HFI1_SDMA_REQ_OPCODE_SHIFT 0x4
  192. #define HFI1_SDMA_REQ_IOVCNT_MASK 0xFF
  193. #define HFI1_SDMA_REQ_IOVCNT_SHIFT 0x8
  194. struct sdma_req_info {
  195. /*
  196. * bits 0-3 - version (currently unused)
  197. * bits 4-7 - opcode (enum sdma_req_opcode)
  198. * bits 8-15 - io vector count
  199. */
  200. __u16 ctrl;
  201. /*
  202. * Number of fragments contained in this request.
  203. * User-space has already computed how many
  204. * fragment-sized packet the user buffer will be
  205. * split into.
  206. */
  207. __u16 npkts;
  208. /*
  209. * Size of each fragment the user buffer will be
  210. * split into.
  211. */
  212. __u16 fragsize;
  213. /*
  214. * Index of the slot in the SDMA completion ring
  215. * this request should be using. User-space is
  216. * in charge of managing its own ring.
  217. */
  218. __u16 comp_idx;
  219. } __attribute__((__packed__));
  220. /*
  221. * SW KDETH header.
  222. * swdata is SW defined portion.
  223. */
  224. struct hfi1_kdeth_header {
  225. __le32 ver_tid_offset;
  226. __le16 jkey;
  227. __le16 hcrc;
  228. __le32 swdata[7];
  229. } __attribute__((__packed__));
  230. /*
  231. * Structure describing the headers that User space uses. The
  232. * structure above is a subset of this one.
  233. */
  234. struct hfi1_pkt_header {
  235. __le16 pbc[4];
  236. __be16 lrh[4];
  237. __be32 bth[3];
  238. struct hfi1_kdeth_header kdeth;
  239. } __attribute__((__packed__));
  240. /*
  241. * The list of usermode accessible registers.
  242. */
  243. enum hfi1_ureg {
  244. /* (RO) DMA RcvHdr to be used next. */
  245. ur_rcvhdrtail = 0,
  246. /* (RW) RcvHdr entry to be processed next by host. */
  247. ur_rcvhdrhead = 1,
  248. /* (RO) Index of next Eager index to use. */
  249. ur_rcvegrindextail = 2,
  250. /* (RW) Eager TID to be processed next */
  251. ur_rcvegrindexhead = 3,
  252. /* (RO) Receive Eager Offset Tail */
  253. ur_rcvegroffsettail = 4,
  254. /* For internal use only; max register number. */
  255. ur_maxreg,
  256. /* (RW) Receive TID flow table */
  257. ur_rcvtidflowtable = 256
  258. };
  259. #endif /* _LINIUX__HFI1_USER_H */