xref: /openbmc/linux/include/uapi/rdma/ib_user_mad.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1d50e14abSJason Gunthorpe /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR Linux-OpenIB) */
27235aa79SDavid Howells /*
37235aa79SDavid Howells  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
47235aa79SDavid Howells  * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
57235aa79SDavid Howells  *
67235aa79SDavid Howells  * This software is available to you under a choice of one of two
77235aa79SDavid Howells  * licenses.  You may choose to be licensed under the terms of the GNU
87235aa79SDavid Howells  * General Public License (GPL) Version 2, available from the file
97235aa79SDavid Howells  * COPYING in the main directory of this source tree, or the
107235aa79SDavid Howells  * OpenIB.org BSD license below:
117235aa79SDavid Howells  *
127235aa79SDavid Howells  *     Redistribution and use in source and binary forms, with or
137235aa79SDavid Howells  *     without modification, are permitted provided that the following
147235aa79SDavid Howells  *     conditions are met:
157235aa79SDavid Howells  *
167235aa79SDavid Howells  *      - Redistributions of source code must retain the above
177235aa79SDavid Howells  *        copyright notice, this list of conditions and the following
187235aa79SDavid Howells  *        disclaimer.
197235aa79SDavid Howells  *
207235aa79SDavid Howells  *      - Redistributions in binary form must reproduce the above
217235aa79SDavid Howells  *        copyright notice, this list of conditions and the following
227235aa79SDavid Howells  *        disclaimer in the documentation and/or other materials
237235aa79SDavid Howells  *        provided with the distribution.
247235aa79SDavid Howells  *
257235aa79SDavid Howells  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
267235aa79SDavid Howells  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
277235aa79SDavid Howells  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
287235aa79SDavid Howells  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
297235aa79SDavid Howells  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
307235aa79SDavid Howells  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
317235aa79SDavid Howells  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
327235aa79SDavid Howells  * SOFTWARE.
337235aa79SDavid Howells  */
347235aa79SDavid Howells 
357235aa79SDavid Howells #ifndef IB_USER_MAD_H
367235aa79SDavid Howells #define IB_USER_MAD_H
377235aa79SDavid Howells 
387235aa79SDavid Howells #include <linux/types.h>
39843debb8SLeon Romanovsky #include <rdma/rdma_user_ioctl.h>
407235aa79SDavid Howells 
417235aa79SDavid Howells /*
427235aa79SDavid Howells  * Increment this value if any changes that break userspace ABI
437235aa79SDavid Howells  * compatibility are made.
447235aa79SDavid Howells  */
457235aa79SDavid Howells #define IB_USER_MAD_ABI_VERSION	5
467235aa79SDavid Howells 
477235aa79SDavid Howells /*
487235aa79SDavid Howells  * Make sure that all structs defined in this file remain laid out so
497235aa79SDavid Howells  * that they pack the same way on 32-bit and 64-bit architectures (to
507235aa79SDavid Howells  * avoid incompatibility between 32-bit userspace and 64-bit kernels).
517235aa79SDavid Howells  */
527235aa79SDavid Howells 
537235aa79SDavid Howells /**
547235aa79SDavid Howells  * ib_user_mad_hdr_old - Old version of MAD packet header without pkey_index
557235aa79SDavid Howells  * @id - ID of agent MAD received with/to be sent with
567235aa79SDavid Howells  * @status - 0 on successful receive, ETIMEDOUT if no response
577235aa79SDavid Howells  *   received (transaction ID in data[] will be set to TID of original
587235aa79SDavid Howells  *   request) (ignored on send)
597235aa79SDavid Howells  * @timeout_ms - Milliseconds to wait for response (unset on receive)
607235aa79SDavid Howells  * @retries - Number of automatic retries to attempt
617235aa79SDavid Howells  * @qpn - Remote QP number received from/to be sent to
627235aa79SDavid Howells  * @qkey - Remote Q_Key to be sent with (unset on receive)
637235aa79SDavid Howells  * @lid - Remote lid received from/to be sent to
647235aa79SDavid Howells  * @sl - Service level received with/to be sent with
657235aa79SDavid Howells  * @path_bits - Local path bits received with/to be sent with
667235aa79SDavid Howells  * @grh_present - If set, GRH was received/should be sent
677235aa79SDavid Howells  * @gid_index - Local GID index to send with (unset on receive)
687235aa79SDavid Howells  * @hop_limit - Hop limit in GRH
697235aa79SDavid Howells  * @traffic_class - Traffic class in GRH
707235aa79SDavid Howells  * @gid - Remote GID in GRH
717235aa79SDavid Howells  * @flow_label - Flow label in GRH
727235aa79SDavid Howells  */
737235aa79SDavid Howells struct ib_user_mad_hdr_old {
747235aa79SDavid Howells 	__u32	id;
757235aa79SDavid Howells 	__u32	status;
767235aa79SDavid Howells 	__u32	timeout_ms;
777235aa79SDavid Howells 	__u32	retries;
787235aa79SDavid Howells 	__u32	length;
797235aa79SDavid Howells 	__be32	qpn;
807235aa79SDavid Howells 	__be32  qkey;
817235aa79SDavid Howells 	__be16	lid;
827235aa79SDavid Howells 	__u8	sl;
837235aa79SDavid Howells 	__u8	path_bits;
847235aa79SDavid Howells 	__u8	grh_present;
857235aa79SDavid Howells 	__u8	gid_index;
867235aa79SDavid Howells 	__u8	hop_limit;
877235aa79SDavid Howells 	__u8	traffic_class;
887235aa79SDavid Howells 	__u8	gid[16];
897235aa79SDavid Howells 	__be32	flow_label;
907235aa79SDavid Howells };
917235aa79SDavid Howells 
927235aa79SDavid Howells /**
937235aa79SDavid Howells  * ib_user_mad_hdr - MAD packet header
947235aa79SDavid Howells  *   This layout allows specifying/receiving the P_Key index.  To use
957235aa79SDavid Howells  *   this capability, an application must call the
967235aa79SDavid Howells  *   IB_USER_MAD_ENABLE_PKEY ioctl on the user MAD file handle before
977235aa79SDavid Howells  *   any other actions with the file handle.
987235aa79SDavid Howells  * @id - ID of agent MAD received with/to be sent with
997235aa79SDavid Howells  * @status - 0 on successful receive, ETIMEDOUT if no response
1007235aa79SDavid Howells  *   received (transaction ID in data[] will be set to TID of original
1017235aa79SDavid Howells  *   request) (ignored on send)
1027235aa79SDavid Howells  * @timeout_ms - Milliseconds to wait for response (unset on receive)
1037235aa79SDavid Howells  * @retries - Number of automatic retries to attempt
1047235aa79SDavid Howells  * @qpn - Remote QP number received from/to be sent to
1057235aa79SDavid Howells  * @qkey - Remote Q_Key to be sent with (unset on receive)
1067235aa79SDavid Howells  * @lid - Remote lid received from/to be sent to
1077235aa79SDavid Howells  * @sl - Service level received with/to be sent with
1087235aa79SDavid Howells  * @path_bits - Local path bits received with/to be sent with
1097235aa79SDavid Howells  * @grh_present - If set, GRH was received/should be sent
1107235aa79SDavid Howells  * @gid_index - Local GID index to send with (unset on receive)
1117235aa79SDavid Howells  * @hop_limit - Hop limit in GRH
1127235aa79SDavid Howells  * @traffic_class - Traffic class in GRH
1137235aa79SDavid Howells  * @gid - Remote GID in GRH
1147235aa79SDavid Howells  * @flow_label - Flow label in GRH
1157235aa79SDavid Howells  * @pkey_index - P_Key index
1167235aa79SDavid Howells  */
1177235aa79SDavid Howells struct ib_user_mad_hdr {
1187235aa79SDavid Howells 	__u32	id;
1197235aa79SDavid Howells 	__u32	status;
1207235aa79SDavid Howells 	__u32	timeout_ms;
1217235aa79SDavid Howells 	__u32	retries;
1227235aa79SDavid Howells 	__u32	length;
1237235aa79SDavid Howells 	__be32	qpn;
1247235aa79SDavid Howells 	__be32  qkey;
1257235aa79SDavid Howells 	__be16	lid;
1267235aa79SDavid Howells 	__u8	sl;
1277235aa79SDavid Howells 	__u8	path_bits;
1287235aa79SDavid Howells 	__u8	grh_present;
1297235aa79SDavid Howells 	__u8	gid_index;
1307235aa79SDavid Howells 	__u8	hop_limit;
1317235aa79SDavid Howells 	__u8	traffic_class;
1327235aa79SDavid Howells 	__u8	gid[16];
1337235aa79SDavid Howells 	__be32	flow_label;
1347235aa79SDavid Howells 	__u16	pkey_index;
1357235aa79SDavid Howells 	__u8	reserved[6];
1367235aa79SDavid Howells };
1377235aa79SDavid Howells 
1387235aa79SDavid Howells /**
1397235aa79SDavid Howells  * ib_user_mad - MAD packet
1407235aa79SDavid Howells  * @hdr - MAD packet header
1417235aa79SDavid Howells  * @data - Contents of MAD
1427235aa79SDavid Howells  *
1437235aa79SDavid Howells  */
1447235aa79SDavid Howells struct ib_user_mad {
1457235aa79SDavid Howells 	struct ib_user_mad_hdr hdr;
146*6d33cabfSKees Cook 	__aligned_u64	data[];
1477235aa79SDavid Howells };
1487235aa79SDavid Howells 
1497235aa79SDavid Howells /*
1507235aa79SDavid Howells  * Earlier versions of this interface definition declared the
1517235aa79SDavid Howells  * method_mask[] member as an array of __u32 but treated it as a
1527235aa79SDavid Howells  * bitmap made up of longs in the kernel.  This ambiguity meant that
1537235aa79SDavid Howells  * 32-bit big-endian applications that can run on both 32-bit and
1547235aa79SDavid Howells  * 64-bit kernels had no consistent ABI to rely on, and 64-bit
1557235aa79SDavid Howells  * big-endian applications that treated method_mask as being made up
1567235aa79SDavid Howells  * of 32-bit words would have their bitmap misinterpreted.
1577235aa79SDavid Howells  *
1587235aa79SDavid Howells  * To clear up this confusion, we change the declaration of
1597235aa79SDavid Howells  * method_mask[] to use unsigned long and handle the conversion from
1607235aa79SDavid Howells  * 32-bit userspace to 64-bit kernel for big-endian systems in the
1617235aa79SDavid Howells  * compat_ioctl method.  Unfortunately, to keep the structure layout
1627235aa79SDavid Howells  * the same, we need the method_mask[] array to be aligned only to 4
1637235aa79SDavid Howells  * bytes even when long is 64 bits, which forces us into this ugly
1647235aa79SDavid Howells  * typedef.
1657235aa79SDavid Howells  */
1667235aa79SDavid Howells typedef unsigned long __attribute__((aligned(4))) packed_ulong;
1677235aa79SDavid Howells #define IB_USER_MAD_LONGS_PER_METHOD_MASK (128 / (8 * sizeof (long)))
1687235aa79SDavid Howells 
1697235aa79SDavid Howells /**
1707235aa79SDavid Howells  * ib_user_mad_reg_req - MAD registration request
1717235aa79SDavid Howells  * @id - Set by the kernel; used to identify agent in future requests.
1727235aa79SDavid Howells  * @qpn - Queue pair number; must be 0 or 1.
1737235aa79SDavid Howells  * @method_mask - The caller will receive unsolicited MADs for any method
1747235aa79SDavid Howells  *   where @method_mask = 1.
1757235aa79SDavid Howells  * @mgmt_class - Indicates which management class of MADs should be receive
1767235aa79SDavid Howells  *   by the caller.  This field is only required if the user wishes to
1777235aa79SDavid Howells  *   receive unsolicited MADs, otherwise it should be 0.
1787235aa79SDavid Howells  * @mgmt_class_version - Indicates which version of MADs for the given
1797235aa79SDavid Howells  *   management class to receive.
1807235aa79SDavid Howells  * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
1817235aa79SDavid Howells  *   in the range from 0x30 to 0x4f. Otherwise not used.
1827235aa79SDavid Howells  * @rmpp_version: If set, indicates the RMPP version used.
1837235aa79SDavid Howells  *
1847235aa79SDavid Howells  */
1857235aa79SDavid Howells struct ib_user_mad_reg_req {
1867235aa79SDavid Howells 	__u32	id;
1877235aa79SDavid Howells 	packed_ulong method_mask[IB_USER_MAD_LONGS_PER_METHOD_MASK];
1887235aa79SDavid Howells 	__u8	qpn;
1897235aa79SDavid Howells 	__u8	mgmt_class;
1907235aa79SDavid Howells 	__u8	mgmt_class_version;
1917235aa79SDavid Howells 	__u8    oui[3];
1927235aa79SDavid Howells 	__u8	rmpp_version;
1937235aa79SDavid Howells };
1947235aa79SDavid Howells 
1950f29b46dSIra Weiny /**
1960f29b46dSIra Weiny  * ib_user_mad_reg_req2 - MAD registration request
1970f29b46dSIra Weiny  *
1980f29b46dSIra Weiny  * @id                 - Set by the _kernel_; used by userspace to identify the
1990f29b46dSIra Weiny  *                       registered agent in future requests.
2000f29b46dSIra Weiny  * @qpn                - Queue pair number; must be 0 or 1.
2010f29b46dSIra Weiny  * @mgmt_class         - Indicates which management class of MADs should be
2020f29b46dSIra Weiny  *                       receive by the caller.  This field is only required if
2030f29b46dSIra Weiny  *                       the user wishes to receive unsolicited MADs, otherwise
2040f29b46dSIra Weiny  *                       it should be 0.
2050f29b46dSIra Weiny  * @mgmt_class_version - Indicates which version of MADs for the given
2060f29b46dSIra Weiny  *                       management class to receive.
2070f29b46dSIra Weiny  * @res                - Ignored.
2080f29b46dSIra Weiny  * @flags              - additional registration flags; Must be in the set of
2090f29b46dSIra Weiny  *                       flags defined in IB_USER_MAD_REG_FLAGS_CAP
2100f29b46dSIra Weiny  * @method_mask        - The caller wishes to receive unsolicited MADs for the
2110f29b46dSIra Weiny  *                       methods whose bit(s) is(are) set.
2120f29b46dSIra Weiny  * @oui                - Indicates IEEE OUI to use when mgmt_class is a vendor
2130f29b46dSIra Weiny  *                       class in the range from 0x30 to 0x4f. Otherwise not
2140f29b46dSIra Weiny  *                       used.
2150f29b46dSIra Weiny  * @rmpp_version       - If set, indicates the RMPP version to use.
2160f29b46dSIra Weiny  */
2171471cb6cSIra Weiny enum {
2181471cb6cSIra Weiny 	IB_USER_MAD_USER_RMPP = (1 << 0),
2191471cb6cSIra Weiny };
2201471cb6cSIra Weiny #define IB_USER_MAD_REG_FLAGS_CAP (IB_USER_MAD_USER_RMPP)
2210f29b46dSIra Weiny struct ib_user_mad_reg_req2 {
2220f29b46dSIra Weiny 	__u32	id;
2230f29b46dSIra Weiny 	__u32	qpn;
2240f29b46dSIra Weiny 	__u8	mgmt_class;
2250f29b46dSIra Weiny 	__u8	mgmt_class_version;
2260f29b46dSIra Weiny 	__u16   res;
2270f29b46dSIra Weiny 	__u32   flags;
22826b99066SJason Gunthorpe 	__aligned_u64 method_mask[2];
2290f29b46dSIra Weiny 	__u32   oui;
2300f29b46dSIra Weiny 	__u8	rmpp_version;
2310f29b46dSIra Weiny 	__u8	reserved[3];
2320f29b46dSIra Weiny };
2330f29b46dSIra Weiny 
2347235aa79SDavid Howells #endif /* IB_USER_MAD_H */
235