xref: /freebsd/sys/ofed/include/uapi/rdma/ib_user_mad.h (revision c1d255d3)
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 #include <rdma/rdma_user_ioctl.h>
42 
43 /*
44  * Increment this value if any changes that break userspace ABI
45  * compatibility are made.
46  */
47 #define IB_USER_MAD_ABI_VERSION	5
48 
49 /*
50  * Make sure that all structs defined in this file remain laid out so
51  * that they pack the same way on 32-bit and 64-bit architectures (to
52  * avoid incompatibility between 32-bit userspace and 64-bit kernels).
53  */
54 
55 /**
56  * ib_user_mad_hdr_old - Old version of MAD packet header without pkey_index
57  * @id - ID of agent MAD received with/to be sent with
58  * @status - 0 on successful receive, ETIMEDOUT if no response
59  *   received (transaction ID in data[] will be set to TID of original
60  *   request) (ignored on send)
61  * @timeout_ms - Milliseconds to wait for response (unset on receive)
62  * @retries - Number of automatic retries to attempt
63  * @qpn - Remote QP number received from/to be sent to
64  * @qkey - Remote Q_Key to be sent with (unset on receive)
65  * @lid - Remote lid received from/to be sent to
66  * @sl - Service level received with/to be sent with
67  * @path_bits - Local path bits received with/to be sent with
68  * @grh_present - If set, GRH was received/should be sent
69  * @gid_index - Local GID index to send with (unset on receive)
70  * @hop_limit - Hop limit in GRH
71  * @traffic_class - Traffic class in GRH
72  * @gid - Remote GID in GRH
73  * @flow_label - Flow label in GRH
74  */
75 struct ib_user_mad_hdr_old {
76 	__u32	id;
77 	__u32	status;
78 	__u32	timeout_ms;
79 	__u32	retries;
80 	__u32	length;
81 	__be32	qpn;
82 	__be32  qkey;
83 	__be16	lid;
84 	__u8	sl;
85 	__u8	path_bits;
86 	__u8	grh_present;
87 	__u8	gid_index;
88 	__u8	hop_limit;
89 	__u8	traffic_class;
90 	__u8	gid[16];
91 	__be32	flow_label;
92 };
93 
94 /**
95  * ib_user_mad_hdr - MAD packet header
96  *   This layout allows specifying/receiving the P_Key index.  To use
97  *   this capability, an application must call the
98  *   IB_USER_MAD_ENABLE_PKEY ioctl on the user MAD file handle before
99  *   any other actions with the file handle.
100  * @id - ID of agent MAD received with/to be sent with
101  * @status - 0 on successful receive, ETIMEDOUT if no response
102  *   received (transaction ID in data[] will be set to TID of original
103  *   request) (ignored on send)
104  * @timeout_ms - Milliseconds to wait for response (unset on receive)
105  * @retries - Number of automatic retries to attempt
106  * @qpn - Remote QP number received from/to be sent to
107  * @qkey - Remote Q_Key to be sent with (unset on receive)
108  * @lid - Remote lid received from/to be sent to
109  * @sl - Service level received with/to be sent with
110  * @path_bits - Local path bits received with/to be sent with
111  * @grh_present - If set, GRH was received/should be sent
112  * @gid_index - Local GID index to send with (unset on receive)
113  * @hop_limit - Hop limit in GRH
114  * @traffic_class - Traffic class in GRH
115  * @gid - Remote GID in GRH
116  * @flow_label - Flow label in GRH
117  * @pkey_index - P_Key index
118  */
119 struct ib_user_mad_hdr {
120 	__u32	id;
121 	__u32	status;
122 	__u32	timeout_ms;
123 	__u32	retries;
124 	__u32	length;
125 	__be32	qpn;
126 	__be32  qkey;
127 	__be16	lid;
128 	__u8	sl;
129 	__u8	path_bits;
130 	__u8	grh_present;
131 	__u8	gid_index;
132 	__u8	hop_limit;
133 	__u8	traffic_class;
134 	__u8	gid[16];
135 	__be32	flow_label;
136 	__u16	pkey_index;
137 	__u8	reserved[6];
138 };
139 
140 /**
141  * ib_user_mad - MAD packet
142  * @hdr - MAD packet header
143  * @data - Contents of MAD
144  *
145  */
146 struct ib_user_mad {
147 	struct ib_user_mad_hdr hdr;
148 	__u64	data[0];
149 };
150 
151 /*
152  * Earlier versions of this interface definition declared the
153  * method_mask[] member as an array of __u32 but treated it as a
154  * bitmap made up of longs in the kernel.  This ambiguity meant that
155  * 32-bit big-endian applications that can run on both 32-bit and
156  * 64-bit kernels had no consistent ABI to rely on, and 64-bit
157  * big-endian applications that treated method_mask as being made up
158  * of 32-bit words would have their bitmap misinterpreted.
159  *
160  * To clear up this confusion, we change the declaration of
161  * method_mask[] to use unsigned long and handle the conversion from
162  * 32-bit userspace to 64-bit kernel for big-endian systems in the
163  * compat_ioctl method.  Unfortunately, to keep the structure layout
164  * the same, we need the method_mask[] array to be aligned only to 4
165  * bytes even when long is 64 bits, which forces us into this ugly
166  * typedef.
167  */
168 typedef unsigned long __attribute__((aligned(4))) packed_ulong;
169 #define IB_USER_MAD_LONGS_PER_METHOD_MASK (128 / (8 * sizeof (long)))
170 
171 /**
172  * ib_user_mad_reg_req - MAD registration request
173  * @id - Set by the kernel; used to identify agent in future requests.
174  * @qpn - Queue pair number; must be 0 or 1.
175  * @method_mask - The caller will receive unsolicited MADs for any method
176  *   where @method_mask = 1.
177  * @mgmt_class - Indicates which management class of MADs should be receive
178  *   by the caller.  This field is only required if the user wishes to
179  *   receive unsolicited MADs, otherwise it should be 0.
180  * @mgmt_class_version - Indicates which version of MADs for the given
181  *   management class to receive.
182  * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
183  *   in the range from 0x30 to 0x4f. Otherwise not used.
184  * @rmpp_version: If set, indicates the RMPP version used.
185  *
186  */
187 struct ib_user_mad_reg_req {
188 	__u32	id;
189 	packed_ulong method_mask[IB_USER_MAD_LONGS_PER_METHOD_MASK];
190 	__u8	qpn;
191 	__u8	mgmt_class;
192 	__u8	mgmt_class_version;
193 	__u8    oui[3];
194 	__u8	rmpp_version;
195 };
196 
197 /**
198  * ib_user_mad_reg_req2 - MAD registration request
199  *
200  * @id                 - Set by the _kernel_; used by userspace to identify the
201  *                       registered agent in future requests.
202  * @qpn                - Queue pair number; must be 0 or 1.
203  * @mgmt_class         - Indicates which management class of MADs should be
204  *                       receive by the caller.  This field is only required if
205  *                       the user wishes to receive unsolicited MADs, otherwise
206  *                       it should be 0.
207  * @mgmt_class_version - Indicates which version of MADs for the given
208  *                       management class to receive.
209  * @res                - Ignored.
210  * @flags              - additional registration flags; Must be in the set of
211  *                       flags defined in IB_USER_MAD_REG_FLAGS_CAP
212  * @method_mask        - The caller wishes to receive unsolicited MADs for the
213  *                       methods whose bit(s) is(are) set.
214  * @oui                - Indicates IEEE OUI to use when mgmt_class is a vendor
215  *                       class in the range from 0x30 to 0x4f. Otherwise not
216  *                       used.
217  * @rmpp_version       - If set, indicates the RMPP version to use.
218  */
219 enum {
220 	IB_USER_MAD_USER_RMPP = (1 << 0),
221 };
222 #define IB_USER_MAD_REG_FLAGS_CAP (IB_USER_MAD_USER_RMPP)
223 struct ib_user_mad_reg_req2 {
224 	__u32	id;
225 	__u32	qpn;
226 	__u8	mgmt_class;
227 	__u8	mgmt_class_version;
228 	__u16   res;
229 	__u32   flags;
230 	__u64   method_mask[2];
231 	__u32   oui;
232 	__u8	rmpp_version;
233 	__u8	reserved[3];
234 };
235 
236 #endif /* IB_USER_MAD_H */
237