1249259Sdim/*
2249259Sdim * Copyright (c) 2004 Topspin Communications.  All rights reserved.
3249259Sdim * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
4249259Sdim *
5249259Sdim * This software is available to you under a choice of one of two
6249259Sdim * licenses.  You may choose to be licensed under the terms of the GNU
7249259Sdim * General Public License (GPL) Version 2, available from the file
8249259Sdim * COPYING in the main directory of this source tree, or the
9249259Sdim * OpenIB.org BSD license below:
10249259Sdim *
11249259Sdim *     Redistribution and use in source and binary forms, with or
12249259Sdim *     without modification, are permitted provided that the following
13249259Sdim *     conditions are met:
14249259Sdim *
15249259Sdim *      - Redistributions of source code must retain the above
16249259Sdim *        copyright notice, this list of conditions and the following
17249259Sdim *        disclaimer.
18249259Sdim *
19249259Sdim *      - Redistributions in binary form must reproduce the above
20249259Sdim *        copyright notice, this list of conditions and the following
21249259Sdim *        disclaimer in the documentation and/or other materials
22249259Sdim *        provided with the distribution.
23249259Sdim *
24249259Sdim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25249259Sdim * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26249259Sdim * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27249259Sdim * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28249259Sdim * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29249259Sdim * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30249259Sdim * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31249259Sdim * SOFTWARE.
32249259Sdim */
33249259Sdim
34249259Sdim#ifndef IB_USER_MAD_H
35249259Sdim#define IB_USER_MAD_H
36249259Sdim
37249259Sdim#include <linux/types.h>
38249259Sdim#include <linux/ioctl.h>
39249259Sdim
40249259Sdim/*
41249259Sdim * Increment this value if any changes that break userspace ABI
42249259Sdim * compatibility are made.
43249259Sdim */
44249259Sdim#define IB_USER_MAD_ABI_VERSION	5
45249259Sdim
46249259Sdim/*
47249259Sdim * Make sure that all structs defined in this file remain laid out so
48249259Sdim * that they pack the same way on 32-bit and 64-bit architectures (to
49249259Sdim * avoid incompatibility between 32-bit userspace and 64-bit kernels).
50249259Sdim */
51249259Sdim
52249259Sdim/**
53249259Sdim * ib_user_mad_hdr_old - Old version of MAD packet header without pkey_index
54249259Sdim * @id - ID of agent MAD received with/to be sent with
55249259Sdim * @status - 0 on successful receive, ETIMEDOUT if no response
56249259Sdim *   received (transaction ID in data[] will be set to TID of original
57249259Sdim *   request) (ignored on send)
58249259Sdim * @timeout_ms - Milliseconds to wait for response (unset on receive)
59249259Sdim * @retries - Number of automatic retries to attempt
60249259Sdim * @qpn - Remote QP number received from/to be sent to
61249259Sdim * @qkey - Remote Q_Key to be sent with (unset on receive)
62249259Sdim * @lid - Remote lid received from/to be sent to
63249259Sdim * @sl - Service level received with/to be sent with
64249259Sdim * @path_bits - Local path bits received with/to be sent with
65249259Sdim * @grh_present - If set, GRH was received/should be sent
66249259Sdim * @gid_index - Local GID index to send with (unset on receive)
67249259Sdim * @hop_limit - Hop limit in GRH
68249259Sdim * @traffic_class - Traffic class in GRH
69249259Sdim * @gid - Remote GID in GRH
70 * @flow_label - Flow label in GRH
71 */
72struct ib_user_mad_hdr_old {
73	__u32	id;
74	__u32	status;
75	__u32	timeout_ms;
76	__u32	retries;
77	__u32	length;
78	__be32	qpn;
79	__be32  qkey;
80	__be16	lid;
81	__u8	sl;
82	__u8	path_bits;
83	__u8	grh_present;
84	__u8	gid_index;
85	__u8	hop_limit;
86	__u8	traffic_class;
87	__u8	gid[16];
88	__be32	flow_label;
89};
90
91/**
92 * ib_user_mad_hdr - MAD packet header
93 *   This layout allows specifying/receiving the P_Key index.  To use
94 *   this capability, an application must call the
95 *   IB_USER_MAD_ENABLE_PKEY ioctl on the user MAD file handle before
96 *   any other actions with the file handle.
97 * @id - ID of agent MAD received with/to be sent with
98 * @status - 0 on successful receive, ETIMEDOUT if no response
99 *   received (transaction ID in data[] will be set to TID of original
100 *   request) (ignored on send)
101 * @timeout_ms - Milliseconds to wait for response (unset on receive)
102 * @retries - Number of automatic retries to attempt
103 * @qpn - Remote QP number received from/to be sent to
104 * @qkey - Remote Q_Key to be sent with (unset on receive)
105 * @lid - Remote lid received from/to be sent to
106 * @sl - Service level received with/to be sent with
107 * @path_bits - Local path bits received with/to be sent with
108 * @grh_present - If set, GRH was received/should be sent
109 * @gid_index - Local GID index to send with (unset on receive)
110 * @hop_limit - Hop limit in GRH
111 * @traffic_class - Traffic class in GRH
112 * @gid - Remote GID in GRH
113 * @flow_label - Flow label in GRH
114 * @pkey_index - P_Key index
115 */
116struct ib_user_mad_hdr {
117	__u32	id;
118	__u32	status;
119	__u32	timeout_ms;
120	__u32	retries;
121	__u32	length;
122	__be32	qpn;
123	__be32  qkey;
124	__be16	lid;
125	__u8	sl;
126	__u8	path_bits;
127	__u8	grh_present;
128	__u8	gid_index;
129	__u8	hop_limit;
130	__u8	traffic_class;
131	__u8	gid[16];
132	__be32	flow_label;
133	__u16	pkey_index;
134	__u8	reserved[6];
135};
136
137/**
138 * ib_user_mad - MAD packet
139 * @hdr - MAD packet header
140 * @data - Contents of MAD
141 *
142 */
143struct ib_user_mad {
144	struct ib_user_mad_hdr hdr;
145	__u64	data[0];
146};
147
148/*
149 * Earlier versions of this interface definition declared the
150 * method_mask[] member as an array of __u32 but treated it as a
151 * bitmap made up of longs in the kernel.  This ambiguity meant that
152 * 32-bit big-endian applications that can run on both 32-bit and
153 * 64-bit kernels had no consistent ABI to rely on, and 64-bit
154 * big-endian applications that treated method_mask as being made up
155 * of 32-bit words would have their bitmap misinterpreted.
156 *
157 * To clear up this confusion, we change the declaration of
158 * method_mask[] to use unsigned long and handle the conversion from
159 * 32-bit userspace to 64-bit kernel for big-endian systems in the
160 * compat_ioctl method.  Unfortunately, to keep the structure layout
161 * the same, we need the method_mask[] array to be aligned only to 4
162 * bytes even when long is 64 bits, which forces us into this ugly
163 * typedef.
164 */
165typedef unsigned long __attribute__((aligned(4))) packed_ulong;
166#define IB_USER_MAD_LONGS_PER_METHOD_MASK (128 / (8 * sizeof (long)))
167
168/**
169 * ib_user_mad_reg_req - MAD registration request
170 * @id - Set by the kernel; used to identify agent in future requests.
171 * @qpn - Queue pair number; must be 0 or 1.
172 * @method_mask - The caller will receive unsolicited MADs for any method
173 *   where @method_mask = 1.
174 * @mgmt_class - Indicates which management class of MADs should be receive
175 *   by the caller.  This field is only required if the user wishes to
176 *   receive unsolicited MADs, otherwise it should be 0.
177 * @mgmt_class_version - Indicates which version of MADs for the given
178 *   management class to receive.
179 * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
180 *   in the range from 0x30 to 0x4f. Otherwise not used.
181 * @rmpp_version: If set, indicates the RMPP version used.
182 *
183 */
184struct ib_user_mad_reg_req {
185	__u32	id;
186	packed_ulong method_mask[IB_USER_MAD_LONGS_PER_METHOD_MASK];
187	__u8	qpn;
188	__u8	mgmt_class;
189	__u8	mgmt_class_version;
190	__u8    oui[3];
191	__u8	rmpp_version;
192};
193
194#define IB_IOCTL_MAGIC		0x1b
195
196#define IB_USER_MAD_REGISTER_AGENT	_IO(IB_IOCTL_MAGIC, 1)
197
198#define IB_USER_MAD_UNREGISTER_AGENT	_IO(IB_IOCTL_MAGIC, 2)
199
200#define IB_USER_MAD_ENABLE_PKEY		_IO(IB_IOCTL_MAGIC, 3)
201
202#endif /* IB_USER_MAD_H */
203