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
56typedef struct ibv_device *(*ibv_driver_init_func)(const char *uverbs_sys_path,
57						   int abi_version);
58
59void ibv_register_driver(const char *name, ibv_driver_init_func init_func);
60int ibv_cmd_get_context(struct ibv_context *context, struct ibv_get_context *cmd,
61			size_t cmd_size, struct ibv_get_context_resp *resp,
62			size_t resp_size);
63int ibv_cmd_query_device(struct ibv_context *context,
64			 struct ibv_device_attr *device_attr,
65			 uint64_t *raw_fw_ver,
66			 struct ibv_query_device *cmd, size_t cmd_size);
67int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num,
68		       struct ibv_port_attr *port_attr,
69		       struct ibv_query_port *cmd, size_t cmd_size);
70int ibv_cmd_query_gid(struct ibv_context *context, uint8_t port_num,
71		      int index, union ibv_gid *gid);
72int ibv_cmd_query_pkey(struct ibv_context *context, uint8_t port_num,
73		       int index, uint16_t *pkey);
74int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd,
75		     struct ibv_alloc_pd *cmd, size_t cmd_size,
76		     struct ibv_alloc_pd_resp *resp, size_t resp_size);
77int ibv_cmd_dealloc_pd(struct ibv_pd *pd);
78#define IBV_CMD_REG_MR_HAS_RESP_PARAMS
79int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
80		   uint64_t hca_va, int access,
81		   struct ibv_mr *mr, struct ibv_reg_mr *cmd,
82		   size_t cmd_size,
83		   struct ibv_reg_mr_resp *resp, size_t resp_size);
84int ibv_cmd_dereg_mr(struct ibv_mr *mr);
85int ibv_cmd_create_cq(struct ibv_context *context, int cqe,
86		      struct ibv_comp_channel *channel,
87		      int comp_vector, struct ibv_cq *cq,
88		      struct ibv_create_cq *cmd, size_t cmd_size,
89		      struct ibv_create_cq_resp *resp, size_t resp_size);
90int ibv_cmd_poll_cq(struct ibv_cq *cq, int ne, struct ibv_wc *wc);
91int ibv_cmd_req_notify_cq(struct ibv_cq *cq, int solicited_only);
92#define IBV_CMD_RESIZE_CQ_HAS_RESP_PARAMS
93int ibv_cmd_resize_cq(struct ibv_cq *cq, int cqe,
94		      struct ibv_resize_cq *cmd, size_t cmd_size,
95		      struct ibv_resize_cq_resp *resp, size_t resp_size);
96int ibv_cmd_destroy_cq(struct ibv_cq *cq);
97
98int ibv_cmd_create_srq(struct ibv_pd *pd,
99		       struct ibv_srq *srq, struct ibv_srq_init_attr *attr,
100		       struct ibv_create_srq *cmd, size_t cmd_size,
101		       struct ibv_create_srq_resp *resp, size_t resp_size);
102int ibv_cmd_create_xrc_srq(struct ibv_pd *pd,
103		       struct ibv_srq *srq, struct ibv_srq_init_attr *attr,
104		       uint32_t xrc_domain, uint32_t xrc_cq,
105		       struct ibv_create_xrc_srq *cmd, size_t cmd_size,
106		       struct ibv_create_srq_resp *resp, size_t resp_size);
107int ibv_cmd_modify_srq(struct ibv_srq *srq,
108		       struct ibv_srq_attr *srq_attr,
109		       int srq_attr_mask,
110		       struct ibv_modify_srq *cmd, size_t cmd_size);
111int ibv_cmd_query_srq(struct ibv_srq *srq,
112		      struct ibv_srq_attr *srq_attr,
113		      struct ibv_query_srq *cmd, size_t cmd_size);
114int ibv_cmd_destroy_srq(struct ibv_srq *srq);
115
116int ibv_cmd_create_qp(struct ibv_pd *pd,
117		      struct ibv_qp *qp, struct ibv_qp_init_attr *attr,
118		      struct ibv_create_qp *cmd, size_t cmd_size,
119		      struct ibv_create_qp_resp *resp, size_t resp_size);
120int ibv_cmd_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *qp_attr,
121		     int attr_mask,
122		     struct ibv_qp_init_attr *qp_init_attr,
123		     struct ibv_query_qp *cmd, size_t cmd_size);
124int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
125		      int attr_mask,
126		      struct ibv_modify_qp *cmd, size_t cmd_size);
127int ibv_cmd_destroy_qp(struct ibv_qp *qp);
128int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
129		      struct ibv_send_wr **bad_wr);
130int ibv_cmd_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr,
131		      struct ibv_recv_wr **bad_wr);
132int ibv_cmd_post_srq_recv(struct ibv_srq *srq, struct ibv_recv_wr *wr,
133			  struct ibv_recv_wr **bad_wr);
134int ibv_cmd_create_ah(struct ibv_pd *pd, struct ibv_ah *ah,
135		      struct ibv_ah_attr *attr);
136int ibv_cmd_destroy_ah(struct ibv_ah *ah);
137int ibv_cmd_attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid);
138int ibv_cmd_detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid);
139
140int ibv_dontfork_range(void *base, size_t size);
141int ibv_dofork_range(void *base, size_t size);
142int ibv_cmd_open_xrc_domain(struct ibv_context *context, int fd, int oflag,
143			    struct ibv_xrc_domain *d,
144			    struct ibv_open_xrc_domain_resp *resp,
145			    size_t resp_size);
146int ibv_cmd_close_xrc_domain(struct ibv_xrc_domain *d);
147int ibv_cmd_create_xrc_rcv_qp(struct ibv_qp_init_attr *init_attr,
148			      uint32_t *xrc_rcv_qpn);
149int ibv_cmd_modify_xrc_rcv_qp(struct ibv_xrc_domain *d, uint32_t xrc_rcv_qpn,
150			      struct ibv_qp_attr *attr, int attr_mask);
151int ibv_cmd_query_xrc_rcv_qp(struct ibv_xrc_domain *d, uint32_t xrc_rcv_qpn,
152			     struct ibv_qp_attr *attr, int attr_mask,
153			     struct ibv_qp_init_attr *init_attr);
154int ibv_cmd_reg_xrc_rcv_qp(struct ibv_xrc_domain *xrc_domain,
155			   uint32_t xrc_qp_num);
156int ibv_cmd_unreg_xrc_rcv_qp(struct ibv_xrc_domain *xrc_domain,
157			     uint32_t xrc_qp_num);
158
159/*
160 * sysfs helper functions
161 */
162const char *ibv_get_sysfs_path(void);
163
164int ibv_read_sysfs_file(const char *dir, const char *file,
165			char *buf, size_t size);
166
167int ibv_resolve_eth_gid(const struct ibv_pd *pd, uint8_t port_num,
168			union ibv_gid *dgid, uint8_t sgid_index,
169			uint8_t mac[], uint16_t *vlan, uint8_t *tagged,
170			uint8_t *is_mcast);
171
172#endif /* INFINIBAND_DRIVER_H */
173