18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR Linux-OpenIB) */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2004 Topspin Communications.  All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
78c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
88c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
98c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
108c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
138c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
148c2ecf20Sopenharmony_ci *     conditions are met:
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
178c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
188c2ecf20Sopenharmony_ci *        disclaimer.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
218c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
228c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
238c2ecf20Sopenharmony_ci *        provided with the distribution.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
268c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
278c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
288c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
298c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
308c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
318c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
328c2ecf20Sopenharmony_ci * SOFTWARE.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#ifndef IB_USER_MAD_H
368c2ecf20Sopenharmony_ci#define IB_USER_MAD_H
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include <linux/types.h>
398c2ecf20Sopenharmony_ci#include <rdma/rdma_user_ioctl.h>
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * Increment this value if any changes that break userspace ABI
438c2ecf20Sopenharmony_ci * compatibility are made.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci#define IB_USER_MAD_ABI_VERSION	5
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/*
488c2ecf20Sopenharmony_ci * Make sure that all structs defined in this file remain laid out so
498c2ecf20Sopenharmony_ci * that they pack the same way on 32-bit and 64-bit architectures (to
508c2ecf20Sopenharmony_ci * avoid incompatibility between 32-bit userspace and 64-bit kernels).
518c2ecf20Sopenharmony_ci */
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/**
548c2ecf20Sopenharmony_ci * ib_user_mad_hdr_old - Old version of MAD packet header without pkey_index
558c2ecf20Sopenharmony_ci * @id - ID of agent MAD received with/to be sent with
568c2ecf20Sopenharmony_ci * @status - 0 on successful receive, ETIMEDOUT if no response
578c2ecf20Sopenharmony_ci *   received (transaction ID in data[] will be set to TID of original
588c2ecf20Sopenharmony_ci *   request) (ignored on send)
598c2ecf20Sopenharmony_ci * @timeout_ms - Milliseconds to wait for response (unset on receive)
608c2ecf20Sopenharmony_ci * @retries - Number of automatic retries to attempt
618c2ecf20Sopenharmony_ci * @qpn - Remote QP number received from/to be sent to
628c2ecf20Sopenharmony_ci * @qkey - Remote Q_Key to be sent with (unset on receive)
638c2ecf20Sopenharmony_ci * @lid - Remote lid received from/to be sent to
648c2ecf20Sopenharmony_ci * @sl - Service level received with/to be sent with
658c2ecf20Sopenharmony_ci * @path_bits - Local path bits received with/to be sent with
668c2ecf20Sopenharmony_ci * @grh_present - If set, GRH was received/should be sent
678c2ecf20Sopenharmony_ci * @gid_index - Local GID index to send with (unset on receive)
688c2ecf20Sopenharmony_ci * @hop_limit - Hop limit in GRH
698c2ecf20Sopenharmony_ci * @traffic_class - Traffic class in GRH
708c2ecf20Sopenharmony_ci * @gid - Remote GID in GRH
718c2ecf20Sopenharmony_ci * @flow_label - Flow label in GRH
728c2ecf20Sopenharmony_ci */
738c2ecf20Sopenharmony_cistruct ib_user_mad_hdr_old {
748c2ecf20Sopenharmony_ci	__u32	id;
758c2ecf20Sopenharmony_ci	__u32	status;
768c2ecf20Sopenharmony_ci	__u32	timeout_ms;
778c2ecf20Sopenharmony_ci	__u32	retries;
788c2ecf20Sopenharmony_ci	__u32	length;
798c2ecf20Sopenharmony_ci	__be32	qpn;
808c2ecf20Sopenharmony_ci	__be32  qkey;
818c2ecf20Sopenharmony_ci	__be16	lid;
828c2ecf20Sopenharmony_ci	__u8	sl;
838c2ecf20Sopenharmony_ci	__u8	path_bits;
848c2ecf20Sopenharmony_ci	__u8	grh_present;
858c2ecf20Sopenharmony_ci	__u8	gid_index;
868c2ecf20Sopenharmony_ci	__u8	hop_limit;
878c2ecf20Sopenharmony_ci	__u8	traffic_class;
888c2ecf20Sopenharmony_ci	__u8	gid[16];
898c2ecf20Sopenharmony_ci	__be32	flow_label;
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/**
938c2ecf20Sopenharmony_ci * ib_user_mad_hdr - MAD packet header
948c2ecf20Sopenharmony_ci *   This layout allows specifying/receiving the P_Key index.  To use
958c2ecf20Sopenharmony_ci *   this capability, an application must call the
968c2ecf20Sopenharmony_ci *   IB_USER_MAD_ENABLE_PKEY ioctl on the user MAD file handle before
978c2ecf20Sopenharmony_ci *   any other actions with the file handle.
988c2ecf20Sopenharmony_ci * @id - ID of agent MAD received with/to be sent with
998c2ecf20Sopenharmony_ci * @status - 0 on successful receive, ETIMEDOUT if no response
1008c2ecf20Sopenharmony_ci *   received (transaction ID in data[] will be set to TID of original
1018c2ecf20Sopenharmony_ci *   request) (ignored on send)
1028c2ecf20Sopenharmony_ci * @timeout_ms - Milliseconds to wait for response (unset on receive)
1038c2ecf20Sopenharmony_ci * @retries - Number of automatic retries to attempt
1048c2ecf20Sopenharmony_ci * @qpn - Remote QP number received from/to be sent to
1058c2ecf20Sopenharmony_ci * @qkey - Remote Q_Key to be sent with (unset on receive)
1068c2ecf20Sopenharmony_ci * @lid - Remote lid received from/to be sent to
1078c2ecf20Sopenharmony_ci * @sl - Service level received with/to be sent with
1088c2ecf20Sopenharmony_ci * @path_bits - Local path bits received with/to be sent with
1098c2ecf20Sopenharmony_ci * @grh_present - If set, GRH was received/should be sent
1108c2ecf20Sopenharmony_ci * @gid_index - Local GID index to send with (unset on receive)
1118c2ecf20Sopenharmony_ci * @hop_limit - Hop limit in GRH
1128c2ecf20Sopenharmony_ci * @traffic_class - Traffic class in GRH
1138c2ecf20Sopenharmony_ci * @gid - Remote GID in GRH
1148c2ecf20Sopenharmony_ci * @flow_label - Flow label in GRH
1158c2ecf20Sopenharmony_ci * @pkey_index - P_Key index
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_cistruct ib_user_mad_hdr {
1188c2ecf20Sopenharmony_ci	__u32	id;
1198c2ecf20Sopenharmony_ci	__u32	status;
1208c2ecf20Sopenharmony_ci	__u32	timeout_ms;
1218c2ecf20Sopenharmony_ci	__u32	retries;
1228c2ecf20Sopenharmony_ci	__u32	length;
1238c2ecf20Sopenharmony_ci	__be32	qpn;
1248c2ecf20Sopenharmony_ci	__be32  qkey;
1258c2ecf20Sopenharmony_ci	__be16	lid;
1268c2ecf20Sopenharmony_ci	__u8	sl;
1278c2ecf20Sopenharmony_ci	__u8	path_bits;
1288c2ecf20Sopenharmony_ci	__u8	grh_present;
1298c2ecf20Sopenharmony_ci	__u8	gid_index;
1308c2ecf20Sopenharmony_ci	__u8	hop_limit;
1318c2ecf20Sopenharmony_ci	__u8	traffic_class;
1328c2ecf20Sopenharmony_ci	__u8	gid[16];
1338c2ecf20Sopenharmony_ci	__be32	flow_label;
1348c2ecf20Sopenharmony_ci	__u16	pkey_index;
1358c2ecf20Sopenharmony_ci	__u8	reserved[6];
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/**
1398c2ecf20Sopenharmony_ci * ib_user_mad - MAD packet
1408c2ecf20Sopenharmony_ci * @hdr - MAD packet header
1418c2ecf20Sopenharmony_ci * @data - Contents of MAD
1428c2ecf20Sopenharmony_ci *
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_cistruct ib_user_mad {
1458c2ecf20Sopenharmony_ci	struct ib_user_mad_hdr hdr;
1468c2ecf20Sopenharmony_ci	__aligned_u64	data[0];
1478c2ecf20Sopenharmony_ci};
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/*
1508c2ecf20Sopenharmony_ci * Earlier versions of this interface definition declared the
1518c2ecf20Sopenharmony_ci * method_mask[] member as an array of __u32 but treated it as a
1528c2ecf20Sopenharmony_ci * bitmap made up of longs in the kernel.  This ambiguity meant that
1538c2ecf20Sopenharmony_ci * 32-bit big-endian applications that can run on both 32-bit and
1548c2ecf20Sopenharmony_ci * 64-bit kernels had no consistent ABI to rely on, and 64-bit
1558c2ecf20Sopenharmony_ci * big-endian applications that treated method_mask as being made up
1568c2ecf20Sopenharmony_ci * of 32-bit words would have their bitmap misinterpreted.
1578c2ecf20Sopenharmony_ci *
1588c2ecf20Sopenharmony_ci * To clear up this confusion, we change the declaration of
1598c2ecf20Sopenharmony_ci * method_mask[] to use unsigned long and handle the conversion from
1608c2ecf20Sopenharmony_ci * 32-bit userspace to 64-bit kernel for big-endian systems in the
1618c2ecf20Sopenharmony_ci * compat_ioctl method.  Unfortunately, to keep the structure layout
1628c2ecf20Sopenharmony_ci * the same, we need the method_mask[] array to be aligned only to 4
1638c2ecf20Sopenharmony_ci * bytes even when long is 64 bits, which forces us into this ugly
1648c2ecf20Sopenharmony_ci * typedef.
1658c2ecf20Sopenharmony_ci */
1668c2ecf20Sopenharmony_citypedef unsigned long __attribute__((aligned(4))) packed_ulong;
1678c2ecf20Sopenharmony_ci#define IB_USER_MAD_LONGS_PER_METHOD_MASK (128 / (8 * sizeof (long)))
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/**
1708c2ecf20Sopenharmony_ci * ib_user_mad_reg_req - MAD registration request
1718c2ecf20Sopenharmony_ci * @id - Set by the kernel; used to identify agent in future requests.
1728c2ecf20Sopenharmony_ci * @qpn - Queue pair number; must be 0 or 1.
1738c2ecf20Sopenharmony_ci * @method_mask - The caller will receive unsolicited MADs for any method
1748c2ecf20Sopenharmony_ci *   where @method_mask = 1.
1758c2ecf20Sopenharmony_ci * @mgmt_class - Indicates which management class of MADs should be receive
1768c2ecf20Sopenharmony_ci *   by the caller.  This field is only required if the user wishes to
1778c2ecf20Sopenharmony_ci *   receive unsolicited MADs, otherwise it should be 0.
1788c2ecf20Sopenharmony_ci * @mgmt_class_version - Indicates which version of MADs for the given
1798c2ecf20Sopenharmony_ci *   management class to receive.
1808c2ecf20Sopenharmony_ci * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
1818c2ecf20Sopenharmony_ci *   in the range from 0x30 to 0x4f. Otherwise not used.
1828c2ecf20Sopenharmony_ci * @rmpp_version: If set, indicates the RMPP version used.
1838c2ecf20Sopenharmony_ci *
1848c2ecf20Sopenharmony_ci */
1858c2ecf20Sopenharmony_cistruct ib_user_mad_reg_req {
1868c2ecf20Sopenharmony_ci	__u32	id;
1878c2ecf20Sopenharmony_ci	packed_ulong method_mask[IB_USER_MAD_LONGS_PER_METHOD_MASK];
1888c2ecf20Sopenharmony_ci	__u8	qpn;
1898c2ecf20Sopenharmony_ci	__u8	mgmt_class;
1908c2ecf20Sopenharmony_ci	__u8	mgmt_class_version;
1918c2ecf20Sopenharmony_ci	__u8    oui[3];
1928c2ecf20Sopenharmony_ci	__u8	rmpp_version;
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/**
1968c2ecf20Sopenharmony_ci * ib_user_mad_reg_req2 - MAD registration request
1978c2ecf20Sopenharmony_ci *
1988c2ecf20Sopenharmony_ci * @id                 - Set by the _kernel_; used by userspace to identify the
1998c2ecf20Sopenharmony_ci *                       registered agent in future requests.
2008c2ecf20Sopenharmony_ci * @qpn                - Queue pair number; must be 0 or 1.
2018c2ecf20Sopenharmony_ci * @mgmt_class         - Indicates which management class of MADs should be
2028c2ecf20Sopenharmony_ci *                       receive by the caller.  This field is only required if
2038c2ecf20Sopenharmony_ci *                       the user wishes to receive unsolicited MADs, otherwise
2048c2ecf20Sopenharmony_ci *                       it should be 0.
2058c2ecf20Sopenharmony_ci * @mgmt_class_version - Indicates which version of MADs for the given
2068c2ecf20Sopenharmony_ci *                       management class to receive.
2078c2ecf20Sopenharmony_ci * @res                - Ignored.
2088c2ecf20Sopenharmony_ci * @flags              - additional registration flags; Must be in the set of
2098c2ecf20Sopenharmony_ci *                       flags defined in IB_USER_MAD_REG_FLAGS_CAP
2108c2ecf20Sopenharmony_ci * @method_mask        - The caller wishes to receive unsolicited MADs for the
2118c2ecf20Sopenharmony_ci *                       methods whose bit(s) is(are) set.
2128c2ecf20Sopenharmony_ci * @oui                - Indicates IEEE OUI to use when mgmt_class is a vendor
2138c2ecf20Sopenharmony_ci *                       class in the range from 0x30 to 0x4f. Otherwise not
2148c2ecf20Sopenharmony_ci *                       used.
2158c2ecf20Sopenharmony_ci * @rmpp_version       - If set, indicates the RMPP version to use.
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_cienum {
2188c2ecf20Sopenharmony_ci	IB_USER_MAD_USER_RMPP = (1 << 0),
2198c2ecf20Sopenharmony_ci};
2208c2ecf20Sopenharmony_ci#define IB_USER_MAD_REG_FLAGS_CAP (IB_USER_MAD_USER_RMPP)
2218c2ecf20Sopenharmony_cistruct ib_user_mad_reg_req2 {
2228c2ecf20Sopenharmony_ci	__u32	id;
2238c2ecf20Sopenharmony_ci	__u32	qpn;
2248c2ecf20Sopenharmony_ci	__u8	mgmt_class;
2258c2ecf20Sopenharmony_ci	__u8	mgmt_class_version;
2268c2ecf20Sopenharmony_ci	__u16   res;
2278c2ecf20Sopenharmony_ci	__u32   flags;
2288c2ecf20Sopenharmony_ci	__aligned_u64 method_mask[2];
2298c2ecf20Sopenharmony_ci	__u32   oui;
2308c2ecf20Sopenharmony_ci	__u8	rmpp_version;
2318c2ecf20Sopenharmony_ci	__u8	reserved[3];
2328c2ecf20Sopenharmony_ci};
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci#endif /* IB_USER_MAD_H */
235