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