1 /* 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 3 * Copyright (c) 2005, 2006 Cisco Systems, Inc. All rights reserved. 4 * Copyright (c) 2005 PathScale, Inc. All rights reserved. 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 * OpenIB.org 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 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 * SOFTWARE. 33 */ 34 35 #ifndef INFINIBAND_DRIVER_H 36 #define INFINIBAND_DRIVER_H 37 38 #include <infiniband/verbs.h> 39 #include <infiniband/kern-abi.h> 40 41 #ifdef __cplusplus 42 # define BEGIN_C_DECLS extern "C" { 43 # define END_C_DECLS } 44 #else /* !__cplusplus */ 45 # define BEGIN_C_DECLS 46 # define END_C_DECLS 47 #endif /* __cplusplus */ 48 49 /* 50 * Extension that low-level drivers should add to their .so filename 51 * (probably via libtool "-release" option). For example a low-level 52 * driver named "libfoo" should build a plug-in named "libfoo-rdmav2.so". 53 */ 54 #define IBV_DEVICE_LIBRARY_EXTENSION rdmav2 55 56 struct verbs_device; 57 58 enum verbs_xrcd_mask { 59 VERBS_XRCD_HANDLE = 1 << 0, 60 VERBS_XRCD_RESERVED = 1 << 1 61 }; 62 63 struct verbs_xrcd { 64 struct ibv_xrcd xrcd; 65 uint32_t comp_mask; 66 uint32_t handle; 67 }; 68 69 enum verbs_srq_mask { 70 VERBS_SRQ_TYPE = 1 << 0, 71 VERBS_SRQ_XRCD = 1 << 1, 72 VERBS_SRQ_CQ = 1 << 2, 73 VERBS_SRQ_NUM = 1 << 3, 74 VERBS_SRQ_RESERVED = 1 << 4 75 }; 76 77 struct verbs_srq { 78 struct ibv_srq srq; 79 uint32_t comp_mask; 80 enum ibv_srq_type srq_type; 81 struct verbs_xrcd *xrcd; 82 struct ibv_cq *cq; 83 uint32_t srq_num; 84 }; 85 86 enum verbs_qp_mask { 87 VERBS_QP_XRCD = 1 << 0, 88 VERBS_QP_RESERVED = 1 << 1 89 }; 90 91 enum ibv_gid_type { 92 IBV_GID_TYPE_IB_ROCE_V1, 93 IBV_GID_TYPE_ROCE_V2, 94 }; 95 96 struct verbs_qp { 97 struct ibv_qp qp; 98 uint32_t comp_mask; 99 struct verbs_xrcd *xrcd; 100 }; 101 102 /* Must change the PRIVATE IBVERBS_PRIVATE_ symbol if this is changed */ 103 struct verbs_device_ops { 104 /* Old interface, do not use in new code. */ 105 struct ibv_context *(*alloc_context)(struct ibv_device *device, 106 int cmd_fd); 107 void (*free_context)(struct ibv_context *context); 108 109 /* New interface */ 110 int (*init_context)(struct verbs_device *device, 111 struct ibv_context *ctx, int cmd_fd); 112 void (*uninit_context)(struct verbs_device *device, 113 struct ibv_context *ctx); 114 }; 115 116 /* Must change the PRIVATE IBVERBS_PRIVATE_ symbol if this is changed */ 117 struct verbs_device { 118 struct ibv_device device; /* Must be first */ 119 const struct verbs_device_ops *ops; 120 size_t sz; 121 size_t size_of_context; 122 }; 123 124 static inline struct verbs_device * 125 verbs_get_device(const struct ibv_device *dev) 126 { 127 return container_of(dev, struct verbs_device, device); 128 } 129 130 typedef struct verbs_device *(*verbs_driver_init_func)(const char *uverbs_sys_path, 131 int abi_version); 132 void verbs_register_driver(const char *name, verbs_driver_init_func init_func); 133 void verbs_init_cq(struct ibv_cq *cq, struct ibv_context *context, 134 struct ibv_comp_channel *channel, 135 void *cq_context); 136 137 int ibv_cmd_get_context(struct ibv_context *context, struct ibv_get_context *cmd, 138 size_t cmd_size, struct ibv_get_context_resp *resp, 139 size_t resp_size); 140 int ibv_cmd_query_device(struct ibv_context *context, 141 struct ibv_device_attr *device_attr, 142 uint64_t *raw_fw_ver, 143 struct ibv_query_device *cmd, size_t cmd_size); 144 int ibv_cmd_query_device_ex(struct ibv_context *context, 145 const struct ibv_query_device_ex_input *input, 146 struct ibv_device_attr_ex *attr, size_t attr_size, 147 uint64_t *raw_fw_ver, 148 struct ibv_query_device_ex *cmd, 149 size_t cmd_core_size, 150 size_t cmd_size, 151 struct ibv_query_device_resp_ex *resp, 152 size_t resp_core_size, 153 size_t resp_size); 154 int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num, 155 struct ibv_port_attr *port_attr, 156 struct ibv_query_port *cmd, size_t cmd_size); 157 int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd, 158 struct ibv_alloc_pd *cmd, size_t cmd_size, 159 struct ibv_alloc_pd_resp *resp, size_t resp_size); 160 int ibv_cmd_dealloc_pd(struct ibv_pd *pd); 161 int ibv_cmd_open_xrcd(struct ibv_context *context, struct verbs_xrcd *xrcd, 162 int vxrcd_size, 163 struct ibv_xrcd_init_attr *attr, 164 struct ibv_open_xrcd *cmd, size_t cmd_size, 165 struct ibv_open_xrcd_resp *resp, size_t resp_size); 166 int ibv_cmd_close_xrcd(struct verbs_xrcd *xrcd); 167 #define IBV_CMD_REG_MR_HAS_RESP_PARAMS 168 int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length, 169 uint64_t hca_va, int access, 170 struct ibv_mr *mr, struct ibv_reg_mr *cmd, 171 size_t cmd_size, 172 struct ibv_reg_mr_resp *resp, size_t resp_size); 173 int ibv_cmd_rereg_mr(struct ibv_mr *mr, uint32_t flags, void *addr, 174 size_t length, uint64_t hca_va, int access, 175 struct ibv_pd *pd, struct ibv_rereg_mr *cmd, 176 size_t cmd_sz, struct ibv_rereg_mr_resp *resp, 177 size_t resp_sz); 178 int ibv_cmd_dereg_mr(struct ibv_mr *mr); 179 int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type, 180 struct ibv_mw *mw, struct ibv_alloc_mw *cmd, 181 size_t cmd_size, 182 struct ibv_alloc_mw_resp *resp, size_t resp_size); 183 int ibv_cmd_dealloc_mw(struct ibv_mw *mw, 184 struct ibv_dealloc_mw *cmd, size_t cmd_size); 185 int ibv_cmd_create_cq(struct ibv_context *context, int cqe, 186 struct ibv_comp_channel *channel, 187 int comp_vector, struct ibv_cq *cq, 188 struct ibv_create_cq *cmd, size_t cmd_size, 189 struct ibv_create_cq_resp *resp, size_t resp_size); 190 int ibv_cmd_create_cq_ex(struct ibv_context *context, 191 struct ibv_cq_init_attr_ex *cq_attr, 192 struct ibv_cq_ex *cq, 193 struct ibv_create_cq_ex *cmd, 194 size_t cmd_core_size, 195 size_t cmd_size, 196 struct ibv_create_cq_resp_ex *resp, 197 size_t resp_core_size, 198 size_t resp_size); 199 int ibv_cmd_poll_cq(struct ibv_cq *cq, int ne, struct ibv_wc *wc); 200 int ibv_cmd_req_notify_cq(struct ibv_cq *cq, int solicited_only); 201 #define IBV_CMD_RESIZE_CQ_HAS_RESP_PARAMS 202 int ibv_cmd_resize_cq(struct ibv_cq *cq, int cqe, 203 struct ibv_resize_cq *cmd, size_t cmd_size, 204 struct ibv_resize_cq_resp *resp, size_t resp_size); 205 int ibv_cmd_destroy_cq(struct ibv_cq *cq); 206 207 int ibv_cmd_create_srq(struct ibv_pd *pd, 208 struct ibv_srq *srq, struct ibv_srq_init_attr *attr, 209 struct ibv_create_srq *cmd, size_t cmd_size, 210 struct ibv_create_srq_resp *resp, size_t resp_size); 211 int ibv_cmd_create_srq_ex(struct ibv_context *context, 212 struct verbs_srq *srq, int vsrq_sz, 213 struct ibv_srq_init_attr_ex *attr_ex, 214 struct ibv_create_xsrq *cmd, size_t cmd_size, 215 struct ibv_create_srq_resp *resp, size_t resp_size); 216 int ibv_cmd_modify_srq(struct ibv_srq *srq, 217 struct ibv_srq_attr *srq_attr, 218 int srq_attr_mask, 219 struct ibv_modify_srq *cmd, size_t cmd_size); 220 int ibv_cmd_query_srq(struct ibv_srq *srq, 221 struct ibv_srq_attr *srq_attr, 222 struct ibv_query_srq *cmd, size_t cmd_size); 223 int ibv_cmd_destroy_srq(struct ibv_srq *srq); 224 225 int ibv_cmd_create_qp(struct ibv_pd *pd, 226 struct ibv_qp *qp, struct ibv_qp_init_attr *attr, 227 struct ibv_create_qp *cmd, size_t cmd_size, 228 struct ibv_create_qp_resp *resp, size_t resp_size); 229 int ibv_cmd_create_qp_ex(struct ibv_context *context, 230 struct verbs_qp *qp, int vqp_sz, 231 struct ibv_qp_init_attr_ex *attr_ex, 232 struct ibv_create_qp *cmd, size_t cmd_size, 233 struct ibv_create_qp_resp *resp, size_t resp_size); 234 int ibv_cmd_create_qp_ex2(struct ibv_context *context, 235 struct verbs_qp *qp, int vqp_sz, 236 struct ibv_qp_init_attr_ex *qp_attr, 237 struct ibv_create_qp_ex *cmd, 238 size_t cmd_core_size, 239 size_t cmd_size, 240 struct ibv_create_qp_resp_ex *resp, 241 size_t resp_core_size, 242 size_t resp_size); 243 int ibv_cmd_open_qp(struct ibv_context *context, 244 struct verbs_qp *qp, int vqp_sz, 245 struct ibv_qp_open_attr *attr, 246 struct ibv_open_qp *cmd, size_t cmd_size, 247 struct ibv_create_qp_resp *resp, size_t resp_size); 248 int ibv_cmd_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *qp_attr, 249 int attr_mask, 250 struct ibv_qp_init_attr *qp_init_attr, 251 struct ibv_query_qp *cmd, size_t cmd_size); 252 int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, 253 int attr_mask, 254 struct ibv_modify_qp *cmd, size_t cmd_size); 255 int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr, 256 int attr_mask, struct ibv_modify_qp_ex *cmd, 257 size_t cmd_core_size, size_t cmd_size, 258 struct ibv_modify_qp_resp_ex *resp, 259 size_t resp_core_size, size_t resp_size); 260 int ibv_cmd_destroy_qp(struct ibv_qp *qp); 261 int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, 262 struct ibv_send_wr **bad_wr); 263 int ibv_cmd_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr, 264 struct ibv_recv_wr **bad_wr); 265 int ibv_cmd_post_srq_recv(struct ibv_srq *srq, struct ibv_recv_wr *wr, 266 struct ibv_recv_wr **bad_wr); 267 int ibv_cmd_create_ah(struct ibv_pd *pd, struct ibv_ah *ah, 268 struct ibv_ah_attr *attr, 269 struct ibv_create_ah_resp *resp, 270 size_t resp_size); 271 int ibv_cmd_destroy_ah(struct ibv_ah *ah); 272 int ibv_cmd_attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid); 273 int ibv_cmd_detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid); 274 275 struct ibv_flow *ibv_cmd_create_flow(struct ibv_qp *qp, 276 struct ibv_flow_attr *flow_attr); 277 int ibv_cmd_destroy_flow(struct ibv_flow *flow_id); 278 int ibv_cmd_create_wq(struct ibv_context *context, 279 struct ibv_wq_init_attr *wq_init_attr, 280 struct ibv_wq *wq, 281 struct ibv_create_wq *cmd, 282 size_t cmd_core_size, 283 size_t cmd_size, 284 struct ibv_create_wq_resp *resp, 285 size_t resp_core_size, 286 size_t resp_size); 287 288 int ibv_cmd_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr, 289 struct ibv_modify_wq *cmd, size_t cmd_core_size, 290 size_t cmd_size); 291 int ibv_cmd_destroy_wq(struct ibv_wq *wq); 292 int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, 293 struct ibv_rwq_ind_table_init_attr *init_attr, 294 struct ibv_rwq_ind_table *rwq_ind_table, 295 struct ibv_create_rwq_ind_table *cmd, 296 size_t cmd_core_size, 297 size_t cmd_size, 298 struct ibv_create_rwq_ind_table_resp *resp, 299 size_t resp_core_size, 300 size_t resp_size); 301 int ibv_cmd_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table); 302 int ibv_dontfork_range(void *base, size_t size); 303 int ibv_dofork_range(void *base, size_t size); 304 305 /* 306 * sysfs helper functions 307 */ 308 const char *ibv_get_sysfs_path(void); 309 310 int ibv_read_sysfs_file(const char *dir, const char *file, 311 char *buf, size_t size); 312 313 static inline int verbs_get_srq_num(struct ibv_srq *srq, uint32_t *srq_num) 314 { 315 struct verbs_srq *vsrq = container_of(srq, struct verbs_srq, srq); 316 if (vsrq->comp_mask & VERBS_SRQ_NUM) { 317 *srq_num = vsrq->srq_num; 318 return 0; 319 } 320 return ENOSYS; 321 } 322 323 int ibv_query_gid_type(struct ibv_context *context, uint8_t port_num, 324 unsigned int index, enum ibv_gid_type *type); 325 #endif /* INFINIBAND_DRIVER_H */ 326