1 /* 2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 3 * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 4 * 5 * This software is available to you under a choice of one of two 6 * licenses. You may choose to be licensed under the terms of the GNU 7 * General Public License (GPL) Version 2, available from the file 8 * COPYING in the main directory of this source tree, or the 9 * OpenIB.org BSD license below: 10 * 11 * Redistribution and use in source and binary forms, with or 12 * without modification, are permitted provided that the following 13 * conditions are met: 14 * 15 * - Redistributions of source code must retain the above 16 * copyright notice, this list of conditions and the following 17 * disclaimer. 18 * 19 * - Redistributions in binary form must reproduce the above 20 * copyright notice, this list of conditions and the following 21 * disclaimer in the documentation and/or other materials 22 * provided with the distribution. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * SOFTWARE. 32 */ 33 34 #ifndef IB_USER_MAD_H 35 #define IB_USER_MAD_H 36 37 #ifdef _KERNEL 38 #include <linux/types.h> 39 #include <linux/ioctl.h> 40 #else 41 #include <infiniband/types.h> 42 #include <sys/ioccom.h> 43 #endif 44 45 /* 46 * Increment this value if any changes that break userspace ABI 47 * compatibility are made. 48 */ 49 #define IB_USER_MAD_ABI_VERSION 5 50 51 /* 52 * Make sure that all structs defined in this file remain laid out so 53 * that they pack the same way on 32-bit and 64-bit architectures (to 54 * avoid incompatibility between 32-bit userspace and 64-bit kernels). 55 */ 56 57 /** 58 * ib_user_mad_hdr_old - Old version of MAD packet header without pkey_index 59 * @id - ID of agent MAD received with/to be sent with 60 * @status - 0 on successful receive, ETIMEDOUT if no response 61 * received (transaction ID in data[] will be set to TID of original 62 * request) (ignored on send) 63 * @timeout_ms - Milliseconds to wait for response (unset on receive) 64 * @retries - Number of automatic retries to attempt 65 * @qpn - Remote QP number received from/to be sent to 66 * @qkey - Remote Q_Key to be sent with (unset on receive) 67 * @lid - Remote lid received from/to be sent to 68 * @sl - Service level received with/to be sent with 69 * @path_bits - Local path bits received with/to be sent with 70 * @grh_present - If set, GRH was received/should be sent 71 * @gid_index - Local GID index to send with (unset on receive) 72 * @hop_limit - Hop limit in GRH 73 * @traffic_class - Traffic class in GRH 74 * @gid - Remote GID in GRH 75 * @flow_label - Flow label in GRH 76 */ 77 struct ib_user_mad_hdr_old { 78 __u32 id; 79 __u32 status; 80 __u32 timeout_ms; 81 __u32 retries; 82 __u32 length; 83 __be32 qpn; 84 __be32 qkey; 85 __be16 lid; 86 __u8 sl; 87 __u8 path_bits; 88 __u8 grh_present; 89 __u8 gid_index; 90 __u8 hop_limit; 91 __u8 traffic_class; 92 __u8 gid[16]; 93 __be32 flow_label; 94 }; 95 96 /** 97 * ib_user_mad_hdr - MAD packet header 98 * This layout allows specifying/receiving the P_Key index. To use 99 * this capability, an application must call the 100 * IB_USER_MAD_ENABLE_PKEY ioctl on the user MAD file handle before 101 * any other actions with the file handle. 102 * @id - ID of agent MAD received with/to be sent with 103 * @status - 0 on successful receive, ETIMEDOUT if no response 104 * received (transaction ID in data[] will be set to TID of original 105 * request) (ignored on send) 106 * @timeout_ms - Milliseconds to wait for response (unset on receive) 107 * @retries - Number of automatic retries to attempt 108 * @qpn - Remote QP number received from/to be sent to 109 * @qkey - Remote Q_Key to be sent with (unset on receive) 110 * @lid - Remote lid received from/to be sent to 111 * @sl - Service level received with/to be sent with 112 * @path_bits - Local path bits received with/to be sent with 113 * @grh_present - If set, GRH was received/should be sent 114 * @gid_index - Local GID index to send with (unset on receive) 115 * @hop_limit - Hop limit in GRH 116 * @traffic_class - Traffic class in GRH 117 * @gid - Remote GID in GRH 118 * @flow_label - Flow label in GRH 119 * @pkey_index - P_Key index 120 */ 121 struct ib_user_mad_hdr { 122 __u32 id; 123 __u32 status; 124 __u32 timeout_ms; 125 __u32 retries; 126 __u32 length; 127 __be32 qpn; 128 __be32 qkey; 129 __be16 lid; 130 __u8 sl; 131 __u8 path_bits; 132 __u8 grh_present; 133 __u8 gid_index; 134 __u8 hop_limit; 135 __u8 traffic_class; 136 __u8 gid[16]; 137 __be32 flow_label; 138 __u16 pkey_index; 139 __u8 reserved[6]; 140 }; 141 142 /** 143 * ib_user_mad - MAD packet 144 * @hdr - MAD packet header 145 * @data - Contents of MAD 146 * 147 */ 148 struct ib_user_mad { 149 struct ib_user_mad_hdr hdr; 150 __u64 data[0]; 151 }; 152 153 /* 154 * Earlier versions of this interface definition declared the 155 * method_mask[] member as an array of __u32 but treated it as a 156 * bitmap made up of longs in the kernel. This ambiguity meant that 157 * 32-bit big-endian applications that can run on both 32-bit and 158 * 64-bit kernels had no consistent ABI to rely on, and 64-bit 159 * big-endian applications that treated method_mask as being made up 160 * of 32-bit words would have their bitmap misinterpreted. 161 * 162 * To clear up this confusion, we change the declaration of 163 * method_mask[] to use unsigned long and handle the conversion from 164 * 32-bit userspace to 64-bit kernel for big-endian systems in the 165 * compat_ioctl method. Unfortunately, to keep the structure layout 166 * the same, we need the method_mask[] array to be aligned only to 4 167 * bytes even when long is 64 bits, which forces us into this ugly 168 * typedef. 169 */ 170 typedef unsigned long __attribute__((aligned(4))) packed_ulong; 171 #define IB_USER_MAD_LONGS_PER_METHOD_MASK (128 / (8 * sizeof (long))) 172 173 /** 174 * ib_user_mad_reg_req - MAD registration request 175 * @id - Set by the kernel; used to identify agent in future requests. 176 * @qpn - Queue pair number; must be 0 or 1. 177 * @method_mask - The caller will receive unsolicited MADs for any method 178 * where @method_mask = 1. 179 * @mgmt_class - Indicates which management class of MADs should be receive 180 * by the caller. This field is only required if the user wishes to 181 * receive unsolicited MADs, otherwise it should be 0. 182 * @mgmt_class_version - Indicates which version of MADs for the given 183 * management class to receive. 184 * @oui: Indicates IEEE OUI when mgmt_class is a vendor class 185 * in the range from 0x30 to 0x4f. Otherwise not used. 186 * @rmpp_version: If set, indicates the RMPP version used. 187 * 188 */ 189 struct ib_user_mad_reg_req { 190 __u32 id; 191 packed_ulong method_mask[IB_USER_MAD_LONGS_PER_METHOD_MASK]; 192 __u8 qpn; 193 __u8 mgmt_class; 194 __u8 mgmt_class_version; 195 __u8 oui[3]; 196 __u8 rmpp_version; 197 }; 198 199 /** 200 * ib_user_mad_reg_req2 - MAD registration request 201 * 202 * @id - Set by the _kernel_; used by userspace to identify the 203 * registered agent in future requests. 204 * @qpn - Queue pair number; must be 0 or 1. 205 * @mgmt_class - Indicates which management class of MADs should be 206 * receive by the caller. This field is only required if 207 * the user wishes to receive unsolicited MADs, otherwise 208 * it should be 0. 209 * @mgmt_class_version - Indicates which version of MADs for the given 210 * management class to receive. 211 * @res - Ignored. 212 * @flags - additional registration flags; Must be in the set of 213 * flags defined in IB_USER_MAD_REG_FLAGS_CAP 214 * @method_mask - The caller wishes to receive unsolicited MADs for the 215 * methods whose bit(s) is(are) set. 216 * @oui - Indicates IEEE OUI to use when mgmt_class is a vendor 217 * class in the range from 0x30 to 0x4f. Otherwise not 218 * used. 219 * @rmpp_version - If set, indicates the RMPP version to use. 220 */ 221 enum { 222 IB_USER_MAD_USER_RMPP = (1 << 0), 223 }; 224 #define IB_USER_MAD_REG_FLAGS_CAP (IB_USER_MAD_USER_RMPP) 225 struct ib_user_mad_reg_req2 { 226 __u32 id; 227 __u32 qpn; 228 __u8 mgmt_class; 229 __u8 mgmt_class_version; 230 __u16 res; 231 __u32 flags; 232 __u64 method_mask[2]; 233 __u32 oui; 234 __u8 rmpp_version; 235 __u8 reserved[3]; 236 }; 237 238 #define IB_IOCTL_MAGIC 0x1b 239 240 #define IB_USER_MAD_REGISTER_AGENT _IOWR(IB_IOCTL_MAGIC, 1, \ 241 struct ib_user_mad_reg_req) 242 243 #define IB_USER_MAD_UNREGISTER_AGENT _IOW(IB_IOCTL_MAGIC, 2, __u32) 244 245 #define IB_USER_MAD_ENABLE_PKEY _IO(IB_IOCTL_MAGIC, 3) 246 247 #define IB_USER_MAD_REGISTER_AGENT2 _IOWR(IB_IOCTL_MAGIC, 4, \ 248 struct ib_user_mad_reg_req2) 249 250 #endif /* IB_USER_MAD_H */ 251