1 /* 2 * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved. 3 * 4 * LICENSE_BEGIN 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 * 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 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 * 38 * LICENSE_END 39 * 40 * 41 */ 42 43 44 #ifndef USNIC_ABI_H 45 #define USNIC_ABI_H 46 47 /* ABI between userspace and kernel */ 48 #define USNIC_UVERBS_ABI_VERSION 4 49 50 #define USNIC_QP_GRP_MAX_WQS 8 51 #define USNIC_QP_GRP_MAX_RQS 8 52 #define USNIC_QP_GRP_MAX_CQS 16 53 54 #define USNIC_DECODE_PGOFF_VFID(pgoff) ((pgoff) & ((1ULL << 32) - 1)) 55 #define USNIC_DECODE_PGOFF_TYPE(pgoff) ((pgoff) >> 48) 56 #define USNIC_DECODE_PGOFF_RES(pgoff) (((pgoff) >> 32) & ((1ULL << 16) - 1)) 57 #define USNIC_DECODE_PGOFF_BAR(pgoff) (((pgoff) >> 32) & ((1ULL << 16) - 1)) 58 59 #define USNIC_ENCODE_PGOFF(vfid, map_type, res_type_bar_id) \ 60 (((((uint64_t)map_type & 0xffff) << 48) | \ 61 (((uint64_t)res_type_bar_id & 0xffff) << 32) | \ 62 ((uint64_t)vfid & ((1ULL << 32) - 1))) * sysconf(_SC_PAGE_SIZE)) 63 64 /* 65 * The kernel module eventually issues proxy the devcmd through enic and the 66 * maximum number of devcmd arguments supported for a vnic is VNIC_DEVCMD_NARGS 67 * (= 15). Among them, 2 arguments are consumed by proxy command for 68 * proxy_index and proxy devcmd. Hence, only a maximum of 13 arguments are 69 * supported on input in practice, even though the ABI between user space and 70 * the kernel has space for 15. 71 * 72 * Keep _NARGS as 15 for backwards compatibility (newer user space with older 73 * kernel), otherwise usnic_ucmd_devcmd() on the older kernel will fail with 74 * -EINVAL. 75 */ 76 #define USNIC_UDEVCMD_NARGS 15 77 #define USNIC_UDEVCMD_MAX_IN_ARGS (USNIC_UDEVCMD_NARGS - 2) 78 79 enum usnic_mmap_type { 80 USNIC_MMAP_BAR = 0, 81 USNIC_MMAP_RES = 1, 82 USNIC_MMAP_BARHEAD = 2, 83 USNIC_MMAP_GRPVECT = 3, 84 }; 85 86 enum usnic_transport_type { 87 USNIC_TRANSPORT_UNKNOWN = 0, 88 USNIC_TRANSPORT_ROCE_CUSTOM = 1, 89 USNIC_TRANSPORT_IPV4_UDP = 2, 90 USNIC_TRANSPORT_IPV4_TCP_3T = 3, 91 USNIC_TRANSPORT_ROCEV2 = 4, 92 USNIC_TRANSPORT_MAX = 5, 93 }; 94 95 #define ROCEV2_PORT 4791 96 97 enum usnic_ucmd_type { 98 USNIC_USER_CMD_DEVCMD, 99 USNIC_USER_CMD_MAX, 100 }; 101 102 struct usnic_user_cmd { 103 u32 ucmd; 104 u32 pad_to_8byte; 105 u64 inbuf; 106 u64 outbuf; 107 u32 inlen; 108 u32 outlen; 109 }; 110 111 struct usnic_udevcmd_cmd { 112 u32 vnic_idx; 113 u32 devcmd; 114 u32 wait; 115 u32 num_args; 116 u64 args[USNIC_UDEVCMD_NARGS]; 117 }; 118 119 struct usnic_udevcmd_resp { 120 u32 num_args; 121 u64 args[USNIC_UDEVCMD_NARGS]; 122 }; 123 124 /* 125 * This is the version of the transport_spec structure that is used 126 * in CREATE_QP versions 0..2 127 */ 128 struct usnic_transport_spec_v2 { 129 enum usnic_transport_type trans_type; 130 union { 131 struct { 132 uint16_t port_num; 133 } usnic_roce; 134 struct { 135 uint32_t sock_fd; 136 } ip; 137 }; 138 }; 139 140 /* 141 * This is the version of the transport_spec structure that is used 142 * in CREATE_QP versions 3.. 143 */ 144 struct usnic_transport_spec { 145 enum usnic_transport_type trans_type; 146 union { 147 struct { 148 uint16_t port_num; 149 } usnic_roce; 150 struct { 151 uint32_t sock_fd; 152 } ip; 153 struct { 154 uint32_t qpn; 155 uint32_t ipaddr_be; 156 } rocev2; 157 u_int8_t pad[256]; 158 }; 159 }; 160 161 #define USNIC_IB_ALLOC_PD_VERSION 1 162 163 struct usnic_ib_alloc_pd_cmd { 164 u32 resp_version; /* response version requested */ 165 u32 pad_to_8byte; 166 }; 167 168 struct usnic_ib_alloc_pd_resp { 169 u32 resp_version; 170 u32 pad_to_8byte; 171 union { 172 struct { 173 u32 vfid; 174 u32 grp_vect_buf_len; 175 } cur; /* v1 */ 176 }; 177 }; 178 179 #define USNIC_IB_CREATE_QP_VERSION 3 180 181 struct usnic_ib_create_qp_cmd_v0 { 182 struct usnic_transport_spec_v2 spec_v2; 183 }; 184 185 struct usnic_ib_create_qp_cmd_v2 { 186 struct usnic_transport_spec_v2 spec_v2; 187 u32 cmd_version; 188 union { 189 struct { 190 /* length in bytes of resources array */ 191 u32 resources_len; 192 193 /* ptr to array of struct usnic_vnic_barres_info */ 194 u64 resources; 195 } cur; /* v1 and v2 cmd */ 196 } u; 197 }; 198 199 struct usnic_ib_create_qp_cmd { 200 /* 201 * This is the old transport spec struct that must stay as the 202 * first member of this struct for backwards compatibility/ABI 203 * reasons.. It is "v2" because it is used with CREATE_QP 204 * versions 0, 1, and 2. 205 */ 206 struct usnic_transport_spec_v2 spec_v2; 207 u32 cmd_version; 208 union { 209 struct { 210 /* length in bytes of resources array */ 211 u32 resources_len; 212 213 /* ptr to array of struct usnic_vnic_barres_info */ 214 u64 resources; 215 } cur; /* v1 and v2 cmd */ 216 } u; 217 /* 218 * This is the current version of the transport spec struct. 219 */ 220 struct usnic_transport_spec spec; 221 }; 222 223 224 /* 225 * infomation of vnic bar resource 226 */ 227 struct usnic_vnic_barres_info { 228 int32_t type; 229 uint32_t padding; 230 uint64_t bus_addr; 231 uint64_t len; 232 }; 233 234 /* 235 * All create_qp responses must start with this for backwards compatability 236 */ 237 #define USNIC_IB_CREATE_QP_RESP_V0_FIELDS \ 238 u32 vfid; \ 239 u32 qp_grp_id; \ 240 u64 bar_bus_addr; \ 241 u32 bar_len; \ 242 u32 wq_cnt; \ 243 u32 rq_cnt; \ 244 u32 cq_cnt; \ 245 u32 wq_idx[USNIC_QP_GRP_MAX_WQS]; \ 246 u32 rq_idx[USNIC_QP_GRP_MAX_RQS]; \ 247 u32 cq_idx[USNIC_QP_GRP_MAX_CQS]; \ 248 u32 transport; 249 250 struct usnic_ib_create_qp_resp_v0 { 251 USNIC_IB_CREATE_QP_RESP_V0_FIELDS 252 u32 reserved[9]; 253 }; 254 255 struct usnic_ib_create_qp_resp { 256 USNIC_IB_CREATE_QP_RESP_V0_FIELDS 257 /* the above fields end on 4-byte alignment boundary */ 258 u32 cmd_version; 259 union { 260 struct { 261 u32 num_barres; 262 u32 pad_to_8byte; 263 } v1; 264 struct { 265 u32 num_barres; 266 u32 wq_err_intr_offset; 267 u32 rq_err_intr_offset; 268 u32 wcq_intr_offset; 269 u32 rcq_intr_offset; 270 u32 barhead_len; 271 } cur; /* v2 */ 272 } u; 273 274 /* v0 had a "reserved[9]" field, must not shrink the response or we can 275 * corrupt newer clients running on older kernels */ 276 u32 reserved[2]; 277 }; 278 279 #define USNIC_CTX_RESP_VERSION 2 280 281 /* 282 * Make this structure packed in order to make sure v1.num_caps not aligned 283 * at 8 byte boundary, hence still being able to support user libary 284 * requesting version 1 response. 285 */ 286 struct __attribute__((__packed__)) usnic_ib_get_context_cmd { 287 u32 resp_version; /* response version requested */ 288 union { 289 struct { 290 u32 num_caps; /* number of capabilities requested */ 291 } v1; 292 struct { 293 u32 encap_subcmd; /* whether encapsulate subcmd */ 294 union { 295 u32 num_caps; 296 struct usnic_user_cmd usnic_ucmd; 297 }; 298 } v2; 299 }; 300 }; 301 302 /* 303 * Note that this enum must never have members removed or re-ordered in order 304 * to retain backwards compatability 305 */ 306 enum usnic_capability { 307 USNIC_CAP_CQ_SHARING, /* CQ sharing version */ 308 USNIC_CAP_MAP_PER_RES, /* Map individual RES */ 309 USNIC_CAP_PIO, /* PIO send */ 310 USNIC_CAP_CQ_INTR, /* CQ interrupts (via comp channels) */ 311 USNIC_CAP_GRP_INTR, /* Group interrupt */ 312 USNIC_CAP_DPKT, /* Direct Packet Interface */ 313 USNIC_CAP_CNT 314 }; 315 316 /* 317 * If and when there become multiple versions of this struct, it will 318 * become a union for cross-version compatability to make sure there is always 319 * space for older and larger versions of the contents. 320 */ 321 struct usnic_ib_get_context_resp { 322 u32 resp_version; /* response version returned */ 323 u32 num_caps; /* number of capabilities returned */ 324 u32 cap_info[USNIC_CAP_CNT]; 325 }; 326 327 #define USNIC_IB_CREATE_CQ_VERSION 2 328 329 struct usnic_ib_create_cq_v0 { 330 u64 reserved; 331 }; 332 333 #define USNIC_CQ_COMP_SIGNAL_VERBS 0x1 /* whether to signal cq 334 * completion event via verbs 335 */ 336 337 struct usnic_ib_create_cq { 338 u32 resp_version; /* response version requested */ 339 union { 340 struct { 341 u32 intr_arm_mode; 342 } v1; 343 struct { 344 u32 flags; 345 __s64 comp_event_fd; /* wait fd for cq completion */ 346 u64 affinity_mask_ptr; /* process affinity mask ptr*/ 347 u64 affinity_mask_len; 348 } cur; /* v2 */ 349 }; 350 }; 351 352 struct usnic_ib_create_cq_resp_v0 { 353 u64 reserved; 354 }; 355 356 struct usnic_ib_create_cq_resp { 357 u32 resp_version; /* response version returned */ 358 u32 pad_to_8byte; 359 }; 360 361 #endif /* USNIC_ABI_H */ 362