ib_user_mad.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR Linux-OpenIB) */
  2. /*
  3. * Copyright (c) 2004 Topspin Communications. All rights reserved.
  4. * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef IB_USER_MAD_H
  35. #define IB_USER_MAD_H
  36. #include <linux/types.h>
  37. #include <rdma/rdma_user_ioctl.h>
  38. /*
  39. * Increment this value if any changes that break userspace ABI
  40. * compatibility are made.
  41. */
  42. #define IB_USER_MAD_ABI_VERSION 5
  43. /*
  44. * Make sure that all structs defined in this file remain laid out so
  45. * that they pack the same way on 32-bit and 64-bit architectures (to
  46. * avoid incompatibility between 32-bit userspace and 64-bit kernels).
  47. */
  48. /**
  49. * ib_user_mad_hdr_old - Old version of MAD packet header without pkey_index
  50. * @id - ID of agent MAD received with/to be sent with
  51. * @status - 0 on successful receive, ETIMEDOUT if no response
  52. * received (transaction ID in data[] will be set to TID of original
  53. * request) (ignored on send)
  54. * @timeout_ms - Milliseconds to wait for response (unset on receive)
  55. * @retries - Number of automatic retries to attempt
  56. * @qpn - Remote QP number received from/to be sent to
  57. * @qkey - Remote Q_Key to be sent with (unset on receive)
  58. * @lid - Remote lid received from/to be sent to
  59. * @sl - Service level received with/to be sent with
  60. * @path_bits - Local path bits received with/to be sent with
  61. * @grh_present - If set, GRH was received/should be sent
  62. * @gid_index - Local GID index to send with (unset on receive)
  63. * @hop_limit - Hop limit in GRH
  64. * @traffic_class - Traffic class in GRH
  65. * @gid - Remote GID in GRH
  66. * @flow_label - Flow label in GRH
  67. */
  68. struct ib_user_mad_hdr_old {
  69. __u32 id;
  70. __u32 status;
  71. __u32 timeout_ms;
  72. __u32 retries;
  73. __u32 length;
  74. __be32 qpn;
  75. __be32 qkey;
  76. __be16 lid;
  77. __u8 sl;
  78. __u8 path_bits;
  79. __u8 grh_present;
  80. __u8 gid_index;
  81. __u8 hop_limit;
  82. __u8 traffic_class;
  83. __u8 gid[16];
  84. __be32 flow_label;
  85. };
  86. /**
  87. * ib_user_mad_hdr - MAD packet header
  88. * This layout allows specifying/receiving the P_Key index. To use
  89. * this capability, an application must call the
  90. * IB_USER_MAD_ENABLE_PKEY ioctl on the user MAD file handle before
  91. * any other actions with the file handle.
  92. * @id - ID of agent MAD received with/to be sent with
  93. * @status - 0 on successful receive, ETIMEDOUT if no response
  94. * received (transaction ID in data[] will be set to TID of original
  95. * request) (ignored on send)
  96. * @timeout_ms - Milliseconds to wait for response (unset on receive)
  97. * @retries - Number of automatic retries to attempt
  98. * @qpn - Remote QP number received from/to be sent to
  99. * @qkey - Remote Q_Key to be sent with (unset on receive)
  100. * @lid - Remote lid received from/to be sent to
  101. * @sl - Service level received with/to be sent with
  102. * @path_bits - Local path bits received with/to be sent with
  103. * @grh_present - If set, GRH was received/should be sent
  104. * @gid_index - Local GID index to send with (unset on receive)
  105. * @hop_limit - Hop limit in GRH
  106. * @traffic_class - Traffic class in GRH
  107. * @gid - Remote GID in GRH
  108. * @flow_label - Flow label in GRH
  109. * @pkey_index - P_Key index
  110. */
  111. struct ib_user_mad_hdr {
  112. __u32 id;
  113. __u32 status;
  114. __u32 timeout_ms;
  115. __u32 retries;
  116. __u32 length;
  117. __be32 qpn;
  118. __be32 qkey;
  119. __be16 lid;
  120. __u8 sl;
  121. __u8 path_bits;
  122. __u8 grh_present;
  123. __u8 gid_index;
  124. __u8 hop_limit;
  125. __u8 traffic_class;
  126. __u8 gid[16];
  127. __be32 flow_label;
  128. __u16 pkey_index;
  129. __u8 reserved[6];
  130. };
  131. /**
  132. * ib_user_mad - MAD packet
  133. * @hdr - MAD packet header
  134. * @data - Contents of MAD
  135. *
  136. */
  137. struct ib_user_mad {
  138. struct ib_user_mad_hdr hdr;
  139. __aligned_u64 data[];
  140. };
  141. /*
  142. * Earlier versions of this interface definition declared the
  143. * method_mask[] member as an array of __u32 but treated it as a
  144. * bitmap made up of longs in the kernel. This ambiguity meant that
  145. * 32-bit big-endian applications that can run on both 32-bit and
  146. * 64-bit kernels had no consistent ABI to rely on, and 64-bit
  147. * big-endian applications that treated method_mask as being made up
  148. * of 32-bit words would have their bitmap misinterpreted.
  149. *
  150. * To clear up this confusion, we change the declaration of
  151. * method_mask[] to use unsigned long and handle the conversion from
  152. * 32-bit userspace to 64-bit kernel for big-endian systems in the
  153. * compat_ioctl method. Unfortunately, to keep the structure layout
  154. * the same, we need the method_mask[] array to be aligned only to 4
  155. * bytes even when long is 64 bits, which forces us into this ugly
  156. * typedef.
  157. */
  158. typedef unsigned long __attribute__((aligned(4))) packed_ulong;
  159. #define IB_USER_MAD_LONGS_PER_METHOD_MASK (128 / (8 * sizeof (long)))
  160. /**
  161. * ib_user_mad_reg_req - MAD registration request
  162. * @id - Set by the kernel; used to identify agent in future requests.
  163. * @qpn - Queue pair number; must be 0 or 1.
  164. * @method_mask - The caller will receive unsolicited MADs for any method
  165. * where @method_mask = 1.
  166. * @mgmt_class - Indicates which management class of MADs should be receive
  167. * by the caller. This field is only required if the user wishes to
  168. * receive unsolicited MADs, otherwise it should be 0.
  169. * @mgmt_class_version - Indicates which version of MADs for the given
  170. * management class to receive.
  171. * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
  172. * in the range from 0x30 to 0x4f. Otherwise not used.
  173. * @rmpp_version: If set, indicates the RMPP version used.
  174. *
  175. */
  176. struct ib_user_mad_reg_req {
  177. __u32 id;
  178. packed_ulong method_mask[IB_USER_MAD_LONGS_PER_METHOD_MASK];
  179. __u8 qpn;
  180. __u8 mgmt_class;
  181. __u8 mgmt_class_version;
  182. __u8 oui[3];
  183. __u8 rmpp_version;
  184. };
  185. /**
  186. * ib_user_mad_reg_req2 - MAD registration request
  187. *
  188. * @id - Set by the _kernel_; used by userspace to identify the
  189. * registered agent in future requests.
  190. * @qpn - Queue pair number; must be 0 or 1.
  191. * @mgmt_class - Indicates which management class of MADs should be
  192. * receive by the caller. This field is only required if
  193. * the user wishes to receive unsolicited MADs, otherwise
  194. * it should be 0.
  195. * @mgmt_class_version - Indicates which version of MADs for the given
  196. * management class to receive.
  197. * @res - Ignored.
  198. * @flags - additional registration flags; Must be in the set of
  199. * flags defined in IB_USER_MAD_REG_FLAGS_CAP
  200. * @method_mask - The caller wishes to receive unsolicited MADs for the
  201. * methods whose bit(s) is(are) set.
  202. * @oui - Indicates IEEE OUI to use when mgmt_class is a vendor
  203. * class in the range from 0x30 to 0x4f. Otherwise not
  204. * used.
  205. * @rmpp_version - If set, indicates the RMPP version to use.
  206. */
  207. enum {
  208. IB_USER_MAD_USER_RMPP = (1 << 0),
  209. };
  210. #define IB_USER_MAD_REG_FLAGS_CAP (IB_USER_MAD_USER_RMPP)
  211. struct ib_user_mad_reg_req2 {
  212. __u32 id;
  213. __u32 qpn;
  214. __u8 mgmt_class;
  215. __u8 mgmt_class_version;
  216. __u16 res;
  217. __u32 flags;
  218. __aligned_u64 method_mask[2];
  219. __u32 oui;
  220. __u8 rmpp_version;
  221. __u8 reserved[3];
  222. };
  223. #endif /* IB_USER_MAD_H */