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