xref: /freebsd/contrib/ofed/libibverbs/compat-1_0.c (revision 87181516ef48be852d5e5fee53c6e0dbfc62f21e)
1*d6b92ffaSHans Petter Selasky /*
2*d6b92ffaSHans Petter Selasky  * Copyright (c) 2007 Cisco Systems, Inc.  All rights reserved.
3*d6b92ffaSHans Petter Selasky  *
4*d6b92ffaSHans Petter Selasky  * This software is available to you under a choice of one of two
5*d6b92ffaSHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
6*d6b92ffaSHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
7*d6b92ffaSHans Petter Selasky  * COPYING in the main directory of this source tree, or the
8*d6b92ffaSHans Petter Selasky  * OpenIB.org BSD license below:
9*d6b92ffaSHans Petter Selasky  *
10*d6b92ffaSHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
11*d6b92ffaSHans Petter Selasky  *     without modification, are permitted provided that the following
12*d6b92ffaSHans Petter Selasky  *     conditions are met:
13*d6b92ffaSHans Petter Selasky  *
14*d6b92ffaSHans Petter Selasky  *      - Redistributions of source code must retain the above
15*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
16*d6b92ffaSHans Petter Selasky  *        disclaimer.
17*d6b92ffaSHans Petter Selasky  *
18*d6b92ffaSHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
19*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
20*d6b92ffaSHans Petter Selasky  *        disclaimer in the documentation and/or other materials
21*d6b92ffaSHans Petter Selasky  *        provided with the distribution.
22*d6b92ffaSHans Petter Selasky  *
23*d6b92ffaSHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24*d6b92ffaSHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25*d6b92ffaSHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26*d6b92ffaSHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27*d6b92ffaSHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28*d6b92ffaSHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29*d6b92ffaSHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30*d6b92ffaSHans Petter Selasky  * SOFTWARE.
31*d6b92ffaSHans Petter Selasky  */
32*d6b92ffaSHans Petter Selasky 
33*d6b92ffaSHans Petter Selasky #include <config.h>
34*d6b92ffaSHans Petter Selasky 
35*d6b92ffaSHans Petter Selasky #include <string.h>
36*d6b92ffaSHans Petter Selasky #include <stddef.h>
37*d6b92ffaSHans Petter Selasky #include <stdlib.h>
38*d6b92ffaSHans Petter Selasky #include <unistd.h>
39*d6b92ffaSHans Petter Selasky #include <alloca.h>
40*d6b92ffaSHans Petter Selasky 
41*d6b92ffaSHans Petter Selasky #include "ibverbs.h"
42*d6b92ffaSHans Petter Selasky 
43*d6b92ffaSHans Petter Selasky struct ibv_pd_1_0 {
44*d6b92ffaSHans Petter Selasky 	struct ibv_context_1_0 *context;
45*d6b92ffaSHans Petter Selasky 	uint32_t		handle;
46*d6b92ffaSHans Petter Selasky 
47*d6b92ffaSHans Petter Selasky 	struct ibv_pd	       *real_pd;
48*d6b92ffaSHans Petter Selasky };
49*d6b92ffaSHans Petter Selasky 
50*d6b92ffaSHans Petter Selasky struct ibv_mr_1_0 {
51*d6b92ffaSHans Petter Selasky 	struct ibv_context_1_0 *context;
52*d6b92ffaSHans Petter Selasky 	struct ibv_pd_1_0      *pd;
53*d6b92ffaSHans Petter Selasky 	uint32_t		handle;
54*d6b92ffaSHans Petter Selasky 	uint32_t		lkey;
55*d6b92ffaSHans Petter Selasky 	uint32_t		rkey;
56*d6b92ffaSHans Petter Selasky 
57*d6b92ffaSHans Petter Selasky 	struct ibv_mr	       *real_mr;
58*d6b92ffaSHans Petter Selasky };
59*d6b92ffaSHans Petter Selasky 
60*d6b92ffaSHans Petter Selasky struct ibv_srq_1_0 {
61*d6b92ffaSHans Petter Selasky 	struct ibv_context_1_0 *context;
62*d6b92ffaSHans Petter Selasky 	void		       *srq_context;
63*d6b92ffaSHans Petter Selasky 	struct ibv_pd_1_0      *pd;
64*d6b92ffaSHans Petter Selasky 	uint32_t		handle;
65*d6b92ffaSHans Petter Selasky 
66*d6b92ffaSHans Petter Selasky 	pthread_mutex_t		mutex;
67*d6b92ffaSHans Petter Selasky 	pthread_cond_t		cond;
68*d6b92ffaSHans Petter Selasky 	uint32_t		events_completed;
69*d6b92ffaSHans Petter Selasky 
70*d6b92ffaSHans Petter Selasky 	struct ibv_srq	       *real_srq;
71*d6b92ffaSHans Petter Selasky };
72*d6b92ffaSHans Petter Selasky 
73*d6b92ffaSHans Petter Selasky struct ibv_qp_init_attr_1_0 {
74*d6b92ffaSHans Petter Selasky 	void		       *qp_context;
75*d6b92ffaSHans Petter Selasky 	struct ibv_cq_1_0      *send_cq;
76*d6b92ffaSHans Petter Selasky 	struct ibv_cq_1_0      *recv_cq;
77*d6b92ffaSHans Petter Selasky 	struct ibv_srq_1_0     *srq;
78*d6b92ffaSHans Petter Selasky 	struct ibv_qp_cap	cap;
79*d6b92ffaSHans Petter Selasky 	enum ibv_qp_type	qp_type;
80*d6b92ffaSHans Petter Selasky 	int			sq_sig_all;
81*d6b92ffaSHans Petter Selasky };
82*d6b92ffaSHans Petter Selasky 
83*d6b92ffaSHans Petter Selasky struct ibv_send_wr_1_0 {
84*d6b92ffaSHans Petter Selasky 	struct ibv_send_wr_1_0 *next;
85*d6b92ffaSHans Petter Selasky 	uint64_t		wr_id;
86*d6b92ffaSHans Petter Selasky 	struct ibv_sge	       *sg_list;
87*d6b92ffaSHans Petter Selasky 	int			num_sge;
88*d6b92ffaSHans Petter Selasky 	enum ibv_wr_opcode	opcode;
89*d6b92ffaSHans Petter Selasky 	int			send_flags;
90*d6b92ffaSHans Petter Selasky 	__be32			imm_data;
91*d6b92ffaSHans Petter Selasky 	union {
92*d6b92ffaSHans Petter Selasky 		struct {
93*d6b92ffaSHans Petter Selasky 			uint64_t	remote_addr;
94*d6b92ffaSHans Petter Selasky 			uint32_t	rkey;
95*d6b92ffaSHans Petter Selasky 		} rdma;
96*d6b92ffaSHans Petter Selasky 		struct {
97*d6b92ffaSHans Petter Selasky 			uint64_t	remote_addr;
98*d6b92ffaSHans Petter Selasky 			uint64_t	compare_add;
99*d6b92ffaSHans Petter Selasky 			uint64_t	swap;
100*d6b92ffaSHans Petter Selasky 			uint32_t	rkey;
101*d6b92ffaSHans Petter Selasky 		} atomic;
102*d6b92ffaSHans Petter Selasky 		struct {
103*d6b92ffaSHans Petter Selasky 			struct ibv_ah_1_0 *ah;
104*d6b92ffaSHans Petter Selasky 			uint32_t	remote_qpn;
105*d6b92ffaSHans Petter Selasky 			uint32_t	remote_qkey;
106*d6b92ffaSHans Petter Selasky 		} ud;
107*d6b92ffaSHans Petter Selasky 	} wr;
108*d6b92ffaSHans Petter Selasky };
109*d6b92ffaSHans Petter Selasky 
110*d6b92ffaSHans Petter Selasky struct ibv_recv_wr_1_0 {
111*d6b92ffaSHans Petter Selasky 	struct ibv_recv_wr_1_0 *next;
112*d6b92ffaSHans Petter Selasky 	uint64_t		wr_id;
113*d6b92ffaSHans Petter Selasky 	struct ibv_sge	       *sg_list;
114*d6b92ffaSHans Petter Selasky 	int			num_sge;
115*d6b92ffaSHans Petter Selasky };
116*d6b92ffaSHans Petter Selasky 
117*d6b92ffaSHans Petter Selasky struct ibv_qp_1_0 {
118*d6b92ffaSHans Petter Selasky 	struct ibv_context_1_0 *context;
119*d6b92ffaSHans Petter Selasky 	void		       *qp_context;
120*d6b92ffaSHans Petter Selasky 	struct ibv_pd_1_0      *pd;
121*d6b92ffaSHans Petter Selasky 	struct ibv_cq_1_0      *send_cq;
122*d6b92ffaSHans Petter Selasky 	struct ibv_cq_1_0      *recv_cq;
123*d6b92ffaSHans Petter Selasky 	struct ibv_srq_1_0     *srq;
124*d6b92ffaSHans Petter Selasky 	uint32_t		handle;
125*d6b92ffaSHans Petter Selasky 	uint32_t		qp_num;
126*d6b92ffaSHans Petter Selasky 	enum ibv_qp_state       state;
127*d6b92ffaSHans Petter Selasky 	enum ibv_qp_type	qp_type;
128*d6b92ffaSHans Petter Selasky 
129*d6b92ffaSHans Petter Selasky 	pthread_mutex_t		mutex;
130*d6b92ffaSHans Petter Selasky 	pthread_cond_t		cond;
131*d6b92ffaSHans Petter Selasky 	uint32_t		events_completed;
132*d6b92ffaSHans Petter Selasky 
133*d6b92ffaSHans Petter Selasky 	struct ibv_qp	       *real_qp;
134*d6b92ffaSHans Petter Selasky };
135*d6b92ffaSHans Petter Selasky 
136*d6b92ffaSHans Petter Selasky struct ibv_cq_1_0 {
137*d6b92ffaSHans Petter Selasky 	struct ibv_context_1_0 *context;
138*d6b92ffaSHans Petter Selasky 	void		       *cq_context;
139*d6b92ffaSHans Petter Selasky 	uint32_t		handle;
140*d6b92ffaSHans Petter Selasky 	int			cqe;
141*d6b92ffaSHans Petter Selasky 
142*d6b92ffaSHans Petter Selasky 	pthread_mutex_t		mutex;
143*d6b92ffaSHans Petter Selasky 	pthread_cond_t		cond;
144*d6b92ffaSHans Petter Selasky 	uint32_t		comp_events_completed;
145*d6b92ffaSHans Petter Selasky 	uint32_t		async_events_completed;
146*d6b92ffaSHans Petter Selasky 
147*d6b92ffaSHans Petter Selasky 	struct ibv_cq	       *real_cq;
148*d6b92ffaSHans Petter Selasky };
149*d6b92ffaSHans Petter Selasky 
150*d6b92ffaSHans Petter Selasky struct ibv_ah_1_0 {
151*d6b92ffaSHans Petter Selasky 	struct ibv_context_1_0 *context;
152*d6b92ffaSHans Petter Selasky 	struct ibv_pd_1_0      *pd;
153*d6b92ffaSHans Petter Selasky 	uint32_t		handle;
154*d6b92ffaSHans Petter Selasky 
155*d6b92ffaSHans Petter Selasky 	struct ibv_ah	       *real_ah;
156*d6b92ffaSHans Petter Selasky };
157*d6b92ffaSHans Petter Selasky 
158*d6b92ffaSHans Petter Selasky struct ibv_device_1_0 {
159*d6b92ffaSHans Petter Selasky 	void		       *obsolete_sysfs_dev;
160*d6b92ffaSHans Petter Selasky 	void		       *obsolete_sysfs_ibdev;
161*d6b92ffaSHans Petter Selasky 	struct ibv_device      *real_device; /* was obsolete driver member */
162*d6b92ffaSHans Petter Selasky 	struct _ibv_device_ops	_ops;
163*d6b92ffaSHans Petter Selasky };
164*d6b92ffaSHans Petter Selasky 
165*d6b92ffaSHans Petter Selasky struct ibv_context_ops_1_0 {
166*d6b92ffaSHans Petter Selasky 	int			(*query_device)(struct ibv_context *context,
167*d6b92ffaSHans Petter Selasky 					      struct ibv_device_attr *device_attr);
168*d6b92ffaSHans Petter Selasky 	int			(*query_port)(struct ibv_context *context, uint8_t port_num,
169*d6b92ffaSHans Petter Selasky 					      struct ibv_port_attr *port_attr);
170*d6b92ffaSHans Petter Selasky 	struct ibv_pd *		(*alloc_pd)(struct ibv_context *context);
171*d6b92ffaSHans Petter Selasky 	int			(*dealloc_pd)(struct ibv_pd *pd);
172*d6b92ffaSHans Petter Selasky 	struct ibv_mr *		(*reg_mr)(struct ibv_pd *pd, void *addr, size_t length,
173*d6b92ffaSHans Petter Selasky 					  int access);
174*d6b92ffaSHans Petter Selasky 	int			(*dereg_mr)(struct ibv_mr *mr);
175*d6b92ffaSHans Petter Selasky 	struct ibv_cq *		(*create_cq)(struct ibv_context *context, int cqe,
176*d6b92ffaSHans Petter Selasky 					     struct ibv_comp_channel *channel,
177*d6b92ffaSHans Petter Selasky 					     int comp_vector);
178*d6b92ffaSHans Petter Selasky 	int			(*poll_cq)(struct ibv_cq_1_0 *cq, int num_entries,
179*d6b92ffaSHans Petter Selasky 					   struct ibv_wc *wc);
180*d6b92ffaSHans Petter Selasky 	int			(*req_notify_cq)(struct ibv_cq_1_0 *cq,
181*d6b92ffaSHans Petter Selasky 						 int solicited_only);
182*d6b92ffaSHans Petter Selasky 	void			(*cq_event)(struct ibv_cq *cq);
183*d6b92ffaSHans Petter Selasky 	int			(*resize_cq)(struct ibv_cq *cq, int cqe);
184*d6b92ffaSHans Petter Selasky 	int			(*destroy_cq)(struct ibv_cq *cq);
185*d6b92ffaSHans Petter Selasky 	struct ibv_srq *	(*create_srq)(struct ibv_pd *pd,
186*d6b92ffaSHans Petter Selasky 					      struct ibv_srq_init_attr *srq_init_attr);
187*d6b92ffaSHans Petter Selasky 	int			(*modify_srq)(struct ibv_srq *srq,
188*d6b92ffaSHans Petter Selasky 					      struct ibv_srq_attr *srq_attr,
189*d6b92ffaSHans Petter Selasky 					      int srq_attr_mask);
190*d6b92ffaSHans Petter Selasky 	int			(*query_srq)(struct ibv_srq *srq,
191*d6b92ffaSHans Petter Selasky 					     struct ibv_srq_attr *srq_attr);
192*d6b92ffaSHans Petter Selasky 	int			(*destroy_srq)(struct ibv_srq *srq);
193*d6b92ffaSHans Petter Selasky 	int			(*post_srq_recv)(struct ibv_srq_1_0 *srq,
194*d6b92ffaSHans Petter Selasky 						 struct ibv_recv_wr_1_0 *recv_wr,
195*d6b92ffaSHans Petter Selasky 						 struct ibv_recv_wr_1_0 **bad_recv_wr);
196*d6b92ffaSHans Petter Selasky 	struct ibv_qp *		(*create_qp)(struct ibv_pd *pd, struct ibv_qp_init_attr *attr);
197*d6b92ffaSHans Petter Selasky 	int			(*query_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
198*d6b92ffaSHans Petter Selasky 					    int attr_mask,
199*d6b92ffaSHans Petter Selasky 					    struct ibv_qp_init_attr *init_attr);
200*d6b92ffaSHans Petter Selasky 	int			(*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
201*d6b92ffaSHans Petter Selasky 					     int attr_mask);
202*d6b92ffaSHans Petter Selasky 	int			(*destroy_qp)(struct ibv_qp *qp);
203*d6b92ffaSHans Petter Selasky 	int			(*post_send)(struct ibv_qp_1_0 *qp,
204*d6b92ffaSHans Petter Selasky 					     struct ibv_send_wr_1_0 *wr,
205*d6b92ffaSHans Petter Selasky 					     struct ibv_send_wr_1_0 **bad_wr);
206*d6b92ffaSHans Petter Selasky 	int			(*post_recv)(struct ibv_qp_1_0 *qp,
207*d6b92ffaSHans Petter Selasky 					     struct ibv_recv_wr_1_0 *wr,
208*d6b92ffaSHans Petter Selasky 					     struct ibv_recv_wr_1_0 **bad_wr);
209*d6b92ffaSHans Petter Selasky 	struct ibv_ah *		(*create_ah)(struct ibv_pd *pd, struct ibv_ah_attr *attr);
210*d6b92ffaSHans Petter Selasky 	int			(*destroy_ah)(struct ibv_ah *ah);
211*d6b92ffaSHans Petter Selasky 	int			(*attach_mcast)(struct ibv_qp *qp, union ibv_gid *gid,
212*d6b92ffaSHans Petter Selasky 						uint16_t lid);
213*d6b92ffaSHans Petter Selasky 	int			(*detach_mcast)(struct ibv_qp *qp, union ibv_gid *gid,
214*d6b92ffaSHans Petter Selasky 						uint16_t lid);
215*d6b92ffaSHans Petter Selasky };
216*d6b92ffaSHans Petter Selasky 
217*d6b92ffaSHans Petter Selasky struct ibv_context_1_0 {
218*d6b92ffaSHans Petter Selasky 	struct ibv_device_1_0	       *device;
219*d6b92ffaSHans Petter Selasky 	struct ibv_context_ops_1_0	ops;
220*d6b92ffaSHans Petter Selasky 	int				cmd_fd;
221*d6b92ffaSHans Petter Selasky 	int				async_fd;
222*d6b92ffaSHans Petter Selasky 	int				num_comp_vectors;
223*d6b92ffaSHans Petter Selasky 
224*d6b92ffaSHans Petter Selasky 	struct ibv_context	       *real_context; /* was abi_compat member */
225*d6b92ffaSHans Petter Selasky };
226*d6b92ffaSHans Petter Selasky 
227*d6b92ffaSHans Petter Selasky typedef struct ibv_device *(*ibv_driver_init_func_1_1)(const char *uverbs_sys_path,
228*d6b92ffaSHans Petter Selasky 						       int abi_version);
229*d6b92ffaSHans Petter Selasky 
230*d6b92ffaSHans Petter Selasky /* Hack to avoid GCC's -Wmissing-prototypes and the similar error from sparse
231*d6b92ffaSHans Petter Selasky    with these prototypes. Symbol versionining requires the goofy names, the
232*d6b92ffaSHans Petter Selasky    prototype must match the version in the historical 1.0 verbs.h.
233*d6b92ffaSHans Petter Selasky  */
234*d6b92ffaSHans Petter Selasky struct ibv_device_1_0 **__ibv_get_device_list_1_0(int *num);
235*d6b92ffaSHans Petter Selasky void __ibv_free_device_list_1_0(struct ibv_device_1_0 **list);
236*d6b92ffaSHans Petter Selasky const char *__ibv_get_device_name_1_0(struct ibv_device_1_0 *device);
237*d6b92ffaSHans Petter Selasky __be64 __ibv_get_device_guid_1_0(struct ibv_device_1_0 *device);
238*d6b92ffaSHans Petter Selasky struct ibv_context_1_0 *__ibv_open_device_1_0(struct ibv_device_1_0 *device);
239*d6b92ffaSHans Petter Selasky int __ibv_close_device_1_0(struct ibv_context_1_0 *context);
240*d6b92ffaSHans Petter Selasky int __ibv_get_async_event_1_0(struct ibv_context_1_0 *context,
241*d6b92ffaSHans Petter Selasky 			      struct ibv_async_event *event);
242*d6b92ffaSHans Petter Selasky void __ibv_ack_async_event_1_0(struct ibv_async_event *event);
243*d6b92ffaSHans Petter Selasky int __ibv_query_device_1_0(struct ibv_context_1_0 *context,
244*d6b92ffaSHans Petter Selasky 			   struct ibv_device_attr *device_attr);
245*d6b92ffaSHans Petter Selasky int __ibv_query_port_1_0(struct ibv_context_1_0 *context, uint8_t port_num,
246*d6b92ffaSHans Petter Selasky 			 struct ibv_port_attr *port_attr);
247*d6b92ffaSHans Petter Selasky int __ibv_query_gid_1_0(struct ibv_context_1_0 *context, uint8_t port_num,
248*d6b92ffaSHans Petter Selasky 			int index, union ibv_gid *gid);
249*d6b92ffaSHans Petter Selasky int __ibv_query_pkey_1_0(struct ibv_context_1_0 *context, uint8_t port_num,
250*d6b92ffaSHans Petter Selasky 			 int index, __be16 *pkey);
251*d6b92ffaSHans Petter Selasky struct ibv_pd_1_0 *__ibv_alloc_pd_1_0(struct ibv_context_1_0 *context);
252*d6b92ffaSHans Petter Selasky int __ibv_dealloc_pd_1_0(struct ibv_pd_1_0 *pd);
253*d6b92ffaSHans Petter Selasky struct ibv_mr_1_0 *__ibv_reg_mr_1_0(struct ibv_pd_1_0 *pd, void *addr,
254*d6b92ffaSHans Petter Selasky 				    size_t length, int access);
255*d6b92ffaSHans Petter Selasky int __ibv_dereg_mr_1_0(struct ibv_mr_1_0 *mr);
256*d6b92ffaSHans Petter Selasky struct ibv_cq_1_0 *__ibv_create_cq_1_0(struct ibv_context_1_0 *context, int cqe,
257*d6b92ffaSHans Petter Selasky 				       void *cq_context,
258*d6b92ffaSHans Petter Selasky 				       struct ibv_comp_channel *channel,
259*d6b92ffaSHans Petter Selasky 				       int comp_vector);
260*d6b92ffaSHans Petter Selasky int __ibv_resize_cq_1_0(struct ibv_cq_1_0 *cq, int cqe);
261*d6b92ffaSHans Petter Selasky int __ibv_destroy_cq_1_0(struct ibv_cq_1_0 *cq);
262*d6b92ffaSHans Petter Selasky int __ibv_get_cq_event_1_0(struct ibv_comp_channel *channel,
263*d6b92ffaSHans Petter Selasky 			   struct ibv_cq_1_0 **cq, void **cq_context);
264*d6b92ffaSHans Petter Selasky void __ibv_ack_cq_events_1_0(struct ibv_cq_1_0 *cq, unsigned int nevents);
265*d6b92ffaSHans Petter Selasky struct ibv_srq_1_0 *
266*d6b92ffaSHans Petter Selasky __ibv_create_srq_1_0(struct ibv_pd_1_0 *pd,
267*d6b92ffaSHans Petter Selasky 		     struct ibv_srq_init_attr *srq_init_attr);
268*d6b92ffaSHans Petter Selasky int __ibv_modify_srq_1_0(struct ibv_srq_1_0 *srq, struct ibv_srq_attr *srq_attr,
269*d6b92ffaSHans Petter Selasky 			 int srq_attr_mask);
270*d6b92ffaSHans Petter Selasky int __ibv_query_srq_1_0(struct ibv_srq_1_0 *srq, struct ibv_srq_attr *srq_attr);
271*d6b92ffaSHans Petter Selasky int __ibv_destroy_srq_1_0(struct ibv_srq_1_0 *srq);
272*d6b92ffaSHans Petter Selasky struct ibv_qp_1_0 *
273*d6b92ffaSHans Petter Selasky __ibv_create_qp_1_0(struct ibv_pd_1_0 *pd,
274*d6b92ffaSHans Petter Selasky 		    struct ibv_qp_init_attr_1_0 *qp_init_attr);
275*d6b92ffaSHans Petter Selasky int __ibv_query_qp_1_0(struct ibv_qp_1_0 *qp, struct ibv_qp_attr *attr,
276*d6b92ffaSHans Petter Selasky 		       int attr_mask, struct ibv_qp_init_attr_1_0 *init_attr);
277*d6b92ffaSHans Petter Selasky int __ibv_modify_qp_1_0(struct ibv_qp_1_0 *qp, struct ibv_qp_attr *attr,
278*d6b92ffaSHans Petter Selasky 			int attr_mask);
279*d6b92ffaSHans Petter Selasky int __ibv_destroy_qp_1_0(struct ibv_qp_1_0 *qp);
280*d6b92ffaSHans Petter Selasky struct ibv_ah_1_0 *__ibv_create_ah_1_0(struct ibv_pd_1_0 *pd,
281*d6b92ffaSHans Petter Selasky 				       struct ibv_ah_attr *attr);
282*d6b92ffaSHans Petter Selasky int __ibv_destroy_ah_1_0(struct ibv_ah_1_0 *ah);
283*d6b92ffaSHans Petter Selasky int __ibv_attach_mcast_1_0(struct ibv_qp_1_0 *qp, union ibv_gid *gid,
284*d6b92ffaSHans Petter Selasky 			   uint16_t lid);
285*d6b92ffaSHans Petter Selasky int __ibv_detach_mcast_1_0(struct ibv_qp_1_0 *qp, union ibv_gid *gid,
286*d6b92ffaSHans Petter Selasky 			   uint16_t lid);
287*d6b92ffaSHans Petter Selasky void __ibv_register_driver_1_1(const char *name,
288*d6b92ffaSHans Petter Selasky 			       ibv_driver_init_func_1_1 init_func);
289*d6b92ffaSHans Petter Selasky 
__ibv_get_device_list_1_0(int * num)290*d6b92ffaSHans Petter Selasky struct ibv_device_1_0 **__ibv_get_device_list_1_0(int *num)
291*d6b92ffaSHans Petter Selasky {
292*d6b92ffaSHans Petter Selasky 	struct ibv_device **real_list;
293*d6b92ffaSHans Petter Selasky 	struct ibv_device_1_0 **l;
294*d6b92ffaSHans Petter Selasky 	int i, n;
295*d6b92ffaSHans Petter Selasky 
296*d6b92ffaSHans Petter Selasky 	real_list = ibv_get_device_list(&n);
297*d6b92ffaSHans Petter Selasky 	if (!real_list)
298*d6b92ffaSHans Petter Selasky 		return NULL;
299*d6b92ffaSHans Petter Selasky 
300*d6b92ffaSHans Petter Selasky 	l = calloc(n + 2, sizeof (struct ibv_device_1_0 *));
301*d6b92ffaSHans Petter Selasky 	if (!l)
302*d6b92ffaSHans Petter Selasky 		goto free_device_list;
303*d6b92ffaSHans Petter Selasky 
304*d6b92ffaSHans Petter Selasky 	l[0] = (void *) real_list;
305*d6b92ffaSHans Petter Selasky 
306*d6b92ffaSHans Petter Selasky 	for (i = 0; i < n; ++i) {
307*d6b92ffaSHans Petter Selasky 		l[i + 1] = calloc(1, sizeof (struct ibv_device_1_0));
308*d6b92ffaSHans Petter Selasky 		if (!l[i + 1])
309*d6b92ffaSHans Petter Selasky 			goto fail;
310*d6b92ffaSHans Petter Selasky 		l[i + 1]->real_device = real_list[i];
311*d6b92ffaSHans Petter Selasky 	}
312*d6b92ffaSHans Petter Selasky 
313*d6b92ffaSHans Petter Selasky 	if (num)
314*d6b92ffaSHans Petter Selasky 		*num = n;
315*d6b92ffaSHans Petter Selasky 
316*d6b92ffaSHans Petter Selasky 	return l + 1;
317*d6b92ffaSHans Petter Selasky 
318*d6b92ffaSHans Petter Selasky fail:
319*d6b92ffaSHans Petter Selasky 	for (i = 1; i <= n; ++i)
320*d6b92ffaSHans Petter Selasky 		if (l[i])
321*d6b92ffaSHans Petter Selasky 			free(l[i]);
322*d6b92ffaSHans Petter Selasky 	free(l);
323*d6b92ffaSHans Petter Selasky 
324*d6b92ffaSHans Petter Selasky free_device_list:
325*d6b92ffaSHans Petter Selasky 	ibv_free_device_list(real_list);
326*d6b92ffaSHans Petter Selasky 	return NULL;
327*d6b92ffaSHans Petter Selasky }
328*d6b92ffaSHans Petter Selasky symver(__ibv_get_device_list_1_0, ibv_get_device_list, IBVERBS_1.0);
329*d6b92ffaSHans Petter Selasky 
__ibv_free_device_list_1_0(struct ibv_device_1_0 ** list)330*d6b92ffaSHans Petter Selasky void __ibv_free_device_list_1_0(struct ibv_device_1_0 **list)
331*d6b92ffaSHans Petter Selasky {
332*d6b92ffaSHans Petter Selasky 	struct ibv_device_1_0 **l = list;
333*d6b92ffaSHans Petter Selasky 
334*d6b92ffaSHans Petter Selasky 	while (*l) {
335*d6b92ffaSHans Petter Selasky 		free(*l);
336*d6b92ffaSHans Petter Selasky 		++l;
337*d6b92ffaSHans Petter Selasky 	}
338*d6b92ffaSHans Petter Selasky 
339*d6b92ffaSHans Petter Selasky 	ibv_free_device_list((void *) list[-1]);
340*d6b92ffaSHans Petter Selasky 	free(list - 1);
341*d6b92ffaSHans Petter Selasky }
342*d6b92ffaSHans Petter Selasky symver(__ibv_free_device_list_1_0, ibv_free_device_list, IBVERBS_1.0);
343*d6b92ffaSHans Petter Selasky 
__ibv_get_device_name_1_0(struct ibv_device_1_0 * device)344*d6b92ffaSHans Petter Selasky const char *__ibv_get_device_name_1_0(struct ibv_device_1_0 *device)
345*d6b92ffaSHans Petter Selasky {
346*d6b92ffaSHans Petter Selasky 	return ibv_get_device_name(device->real_device);
347*d6b92ffaSHans Petter Selasky }
348*d6b92ffaSHans Petter Selasky symver(__ibv_get_device_name_1_0, ibv_get_device_name, IBVERBS_1.0);
349*d6b92ffaSHans Petter Selasky 
__ibv_get_device_guid_1_0(struct ibv_device_1_0 * device)350*d6b92ffaSHans Petter Selasky __be64 __ibv_get_device_guid_1_0(struct ibv_device_1_0 *device)
351*d6b92ffaSHans Petter Selasky {
352*d6b92ffaSHans Petter Selasky 	return ibv_get_device_guid(device->real_device);
353*d6b92ffaSHans Petter Selasky }
354*d6b92ffaSHans Petter Selasky symver(__ibv_get_device_guid_1_0, ibv_get_device_guid, IBVERBS_1.0);
355*d6b92ffaSHans Petter Selasky 
poll_cq_wrapper_1_0(struct ibv_cq_1_0 * cq,int num_entries,struct ibv_wc * wc)356*d6b92ffaSHans Petter Selasky static int poll_cq_wrapper_1_0(struct ibv_cq_1_0 *cq, int num_entries,
357*d6b92ffaSHans Petter Selasky 			       struct ibv_wc *wc)
358*d6b92ffaSHans Petter Selasky {
359*d6b92ffaSHans Petter Selasky 	return cq->context->real_context->ops.poll_cq(cq->real_cq, num_entries, wc);
360*d6b92ffaSHans Petter Selasky }
361*d6b92ffaSHans Petter Selasky 
req_notify_cq_wrapper_1_0(struct ibv_cq_1_0 * cq,int sol_only)362*d6b92ffaSHans Petter Selasky static int req_notify_cq_wrapper_1_0(struct ibv_cq_1_0 *cq, int sol_only)
363*d6b92ffaSHans Petter Selasky {
364*d6b92ffaSHans Petter Selasky 	return cq->context->real_context->ops.req_notify_cq(cq->real_cq, sol_only);
365*d6b92ffaSHans Petter Selasky }
366*d6b92ffaSHans Petter Selasky 
post_srq_recv_wrapper_1_0(struct ibv_srq_1_0 * srq,struct ibv_recv_wr_1_0 * wr,struct ibv_recv_wr_1_0 ** bad_wr)367*d6b92ffaSHans Petter Selasky static int post_srq_recv_wrapper_1_0(struct ibv_srq_1_0 *srq, struct ibv_recv_wr_1_0 *wr,
368*d6b92ffaSHans Petter Selasky 				 struct ibv_recv_wr_1_0 **bad_wr)
369*d6b92ffaSHans Petter Selasky {
370*d6b92ffaSHans Petter Selasky 	struct ibv_recv_wr_1_0 *w;
371*d6b92ffaSHans Petter Selasky 	struct ibv_recv_wr *real_wr, *head_wr = NULL, *tail_wr = NULL, *real_bad_wr;
372*d6b92ffaSHans Petter Selasky 	int ret;
373*d6b92ffaSHans Petter Selasky 
374*d6b92ffaSHans Petter Selasky 	for (w = wr; w; w = w->next) {
375*d6b92ffaSHans Petter Selasky 		real_wr = alloca(sizeof *real_wr);
376*d6b92ffaSHans Petter Selasky 		real_wr->wr_id   = w->wr_id;
377*d6b92ffaSHans Petter Selasky 		real_wr->sg_list = w->sg_list;
378*d6b92ffaSHans Petter Selasky 		real_wr->num_sge = w->num_sge;
379*d6b92ffaSHans Petter Selasky 		real_wr->next    = NULL;
380*d6b92ffaSHans Petter Selasky 		if (tail_wr)
381*d6b92ffaSHans Petter Selasky 			tail_wr->next = real_wr;
382*d6b92ffaSHans Petter Selasky 		else
383*d6b92ffaSHans Petter Selasky 			head_wr = real_wr;
384*d6b92ffaSHans Petter Selasky 
385*d6b92ffaSHans Petter Selasky 		tail_wr = real_wr;
386*d6b92ffaSHans Petter Selasky 	}
387*d6b92ffaSHans Petter Selasky 
388*d6b92ffaSHans Petter Selasky 	ret = srq->context->real_context->ops.post_srq_recv(srq->real_srq, head_wr,
389*d6b92ffaSHans Petter Selasky 							    &real_bad_wr);
390*d6b92ffaSHans Petter Selasky 
391*d6b92ffaSHans Petter Selasky 	if (ret) {
392*d6b92ffaSHans Petter Selasky 		for (real_wr = head_wr, w = wr;
393*d6b92ffaSHans Petter Selasky 		     real_wr;
394*d6b92ffaSHans Petter Selasky 		     real_wr = real_wr->next, w = w->next)
395*d6b92ffaSHans Petter Selasky 			if (real_wr == real_bad_wr) {
396*d6b92ffaSHans Petter Selasky 				*bad_wr = w;
397*d6b92ffaSHans Petter Selasky 				break;
398*d6b92ffaSHans Petter Selasky 			}
399*d6b92ffaSHans Petter Selasky 	}
400*d6b92ffaSHans Petter Selasky 
401*d6b92ffaSHans Petter Selasky 	return ret;
402*d6b92ffaSHans Petter Selasky }
403*d6b92ffaSHans Petter Selasky 
post_send_wrapper_1_0(struct ibv_qp_1_0 * qp,struct ibv_send_wr_1_0 * wr,struct ibv_send_wr_1_0 ** bad_wr)404*d6b92ffaSHans Petter Selasky static int post_send_wrapper_1_0(struct ibv_qp_1_0 *qp, struct ibv_send_wr_1_0 *wr,
405*d6b92ffaSHans Petter Selasky 				 struct ibv_send_wr_1_0 **bad_wr)
406*d6b92ffaSHans Petter Selasky {
407*d6b92ffaSHans Petter Selasky 	struct ibv_send_wr_1_0 *w;
408*d6b92ffaSHans Petter Selasky 	struct ibv_send_wr *real_wr, *head_wr = NULL, *tail_wr = NULL, *real_bad_wr;
409*d6b92ffaSHans Petter Selasky 	int is_ud = qp->qp_type == IBV_QPT_UD;
410*d6b92ffaSHans Petter Selasky 	int ret;
411*d6b92ffaSHans Petter Selasky 
412*d6b92ffaSHans Petter Selasky 	for (w = wr; w; w = w->next) {
413*d6b92ffaSHans Petter Selasky 		real_wr = alloca(sizeof *real_wr);
414*d6b92ffaSHans Petter Selasky 		real_wr->wr_id = w->wr_id;
415*d6b92ffaSHans Petter Selasky 		real_wr->next  = NULL;
416*d6b92ffaSHans Petter Selasky 
417*d6b92ffaSHans Petter Selasky #define TEST_SIZE_2_POINT(f1, f2)					\
418*d6b92ffaSHans Petter Selasky 		((offsetof(struct ibv_send_wr, f1) - offsetof(struct ibv_send_wr, f2)) \
419*d6b92ffaSHans Petter Selasky 		 == offsetof(struct ibv_send_wr_1_0, f1) - offsetof(struct ibv_send_wr_1_0, f2))
420*d6b92ffaSHans Petter Selasky #define TEST_SIZE_TO_END(f1)					    \
421*d6b92ffaSHans Petter Selasky 		((sizeof(struct ibv_send_wr) - offsetof(struct ibv_send_wr, f1)) == \
422*d6b92ffaSHans Petter Selasky 		 (sizeof(struct ibv_send_wr_1_0) - offsetof(struct ibv_send_wr_1_0, f1)))
423*d6b92ffaSHans Petter Selasky 
424*d6b92ffaSHans Petter Selasky 		if (TEST_SIZE_TO_END (sg_list))
425*d6b92ffaSHans Petter Selasky 			memcpy(&real_wr->sg_list, &w->sg_list, sizeof *real_wr
426*d6b92ffaSHans Petter Selasky 			       - offsetof(struct ibv_send_wr, sg_list));
427*d6b92ffaSHans Petter Selasky 		else if (TEST_SIZE_2_POINT (imm_data, sg_list) &&
428*d6b92ffaSHans Petter Selasky 			 TEST_SIZE_TO_END (wr)) {
429*d6b92ffaSHans Petter Selasky 			/* we have alignment up to wr, but padding between
430*d6b92ffaSHans Petter Selasky 			 * imm_data and wr, and we know wr itself is the
431*d6b92ffaSHans Petter Selasky 			 * same size */
432*d6b92ffaSHans Petter Selasky 			memcpy(&real_wr->sg_list, &w->sg_list,
433*d6b92ffaSHans Petter Selasky 			       offsetof(struct ibv_send_wr, imm_data) -
434*d6b92ffaSHans Petter Selasky 			       offsetof(struct ibv_send_wr, sg_list) +
435*d6b92ffaSHans Petter Selasky 			       sizeof real_wr->imm_data);
436*d6b92ffaSHans Petter Selasky 			memcpy(&real_wr->wr, &w->wr, sizeof real_wr->wr);
437*d6b92ffaSHans Petter Selasky 		} else {
438*d6b92ffaSHans Petter Selasky 			real_wr->sg_list = w->sg_list;
439*d6b92ffaSHans Petter Selasky 			real_wr->num_sge = w->num_sge;
440*d6b92ffaSHans Petter Selasky 			real_wr->opcode = w->opcode;
441*d6b92ffaSHans Petter Selasky 			real_wr->send_flags = w->send_flags;
442*d6b92ffaSHans Petter Selasky 			real_wr->imm_data = w->imm_data;
443*d6b92ffaSHans Petter Selasky 			if (TEST_SIZE_TO_END (wr))
444*d6b92ffaSHans Petter Selasky 				memcpy(&real_wr->wr, &w->wr,
445*d6b92ffaSHans Petter Selasky 				       sizeof real_wr->wr);
446*d6b92ffaSHans Petter Selasky 			else {
447*d6b92ffaSHans Petter Selasky 				real_wr->wr.atomic.remote_addr =
448*d6b92ffaSHans Petter Selasky 					w->wr.atomic.remote_addr;
449*d6b92ffaSHans Petter Selasky 				real_wr->wr.atomic.compare_add =
450*d6b92ffaSHans Petter Selasky 					w->wr.atomic.compare_add;
451*d6b92ffaSHans Petter Selasky 				real_wr->wr.atomic.swap =
452*d6b92ffaSHans Petter Selasky 					w->wr.atomic.swap;
453*d6b92ffaSHans Petter Selasky 				real_wr->wr.atomic.rkey =
454*d6b92ffaSHans Petter Selasky 					w->wr.atomic.rkey;
455*d6b92ffaSHans Petter Selasky 			}
456*d6b92ffaSHans Petter Selasky 		}
457*d6b92ffaSHans Petter Selasky 
458*d6b92ffaSHans Petter Selasky 		if (is_ud)
459*d6b92ffaSHans Petter Selasky 			real_wr->wr.ud.ah = w->wr.ud.ah->real_ah;
460*d6b92ffaSHans Petter Selasky 
461*d6b92ffaSHans Petter Selasky 		if (tail_wr)
462*d6b92ffaSHans Petter Selasky 			tail_wr->next = real_wr;
463*d6b92ffaSHans Petter Selasky 		else
464*d6b92ffaSHans Petter Selasky 			head_wr = real_wr;
465*d6b92ffaSHans Petter Selasky 
466*d6b92ffaSHans Petter Selasky 		tail_wr = real_wr;
467*d6b92ffaSHans Petter Selasky 	}
468*d6b92ffaSHans Petter Selasky 
469*d6b92ffaSHans Petter Selasky 	ret = qp->context->real_context->ops.post_send(qp->real_qp, head_wr,
470*d6b92ffaSHans Petter Selasky 						       &real_bad_wr);
471*d6b92ffaSHans Petter Selasky 
472*d6b92ffaSHans Petter Selasky 	if (ret) {
473*d6b92ffaSHans Petter Selasky 		for (real_wr = head_wr, w = wr;
474*d6b92ffaSHans Petter Selasky 		     real_wr;
475*d6b92ffaSHans Petter Selasky 		     real_wr = real_wr->next, w = w->next)
476*d6b92ffaSHans Petter Selasky 			if (real_wr == real_bad_wr) {
477*d6b92ffaSHans Petter Selasky 				*bad_wr = w;
478*d6b92ffaSHans Petter Selasky 				break;
479*d6b92ffaSHans Petter Selasky 			}
480*d6b92ffaSHans Petter Selasky 	}
481*d6b92ffaSHans Petter Selasky 
482*d6b92ffaSHans Petter Selasky 	return ret;
483*d6b92ffaSHans Petter Selasky }
484*d6b92ffaSHans Petter Selasky 
post_recv_wrapper_1_0(struct ibv_qp_1_0 * qp,struct ibv_recv_wr_1_0 * wr,struct ibv_recv_wr_1_0 ** bad_wr)485*d6b92ffaSHans Petter Selasky static int post_recv_wrapper_1_0(struct ibv_qp_1_0 *qp, struct ibv_recv_wr_1_0 *wr,
486*d6b92ffaSHans Petter Selasky 				 struct ibv_recv_wr_1_0 **bad_wr)
487*d6b92ffaSHans Petter Selasky {
488*d6b92ffaSHans Petter Selasky 	struct ibv_recv_wr_1_0 *w;
489*d6b92ffaSHans Petter Selasky 	struct ibv_recv_wr *real_wr, *head_wr = NULL, *tail_wr = NULL, *real_bad_wr;
490*d6b92ffaSHans Petter Selasky 	int ret;
491*d6b92ffaSHans Petter Selasky 
492*d6b92ffaSHans Petter Selasky 	for (w = wr; w; w = w->next) {
493*d6b92ffaSHans Petter Selasky 		real_wr = alloca(sizeof *real_wr);
494*d6b92ffaSHans Petter Selasky 		real_wr->wr_id   = w->wr_id;
495*d6b92ffaSHans Petter Selasky 		real_wr->sg_list = w->sg_list;
496*d6b92ffaSHans Petter Selasky 		real_wr->num_sge = w->num_sge;
497*d6b92ffaSHans Petter Selasky 		real_wr->next    = NULL;
498*d6b92ffaSHans Petter Selasky 		if (tail_wr)
499*d6b92ffaSHans Petter Selasky 			tail_wr->next = real_wr;
500*d6b92ffaSHans Petter Selasky 		else
501*d6b92ffaSHans Petter Selasky 			head_wr = real_wr;
502*d6b92ffaSHans Petter Selasky 
503*d6b92ffaSHans Petter Selasky 		tail_wr = real_wr;
504*d6b92ffaSHans Petter Selasky 	}
505*d6b92ffaSHans Petter Selasky 
506*d6b92ffaSHans Petter Selasky 	ret = qp->context->real_context->ops.post_recv(qp->real_qp, head_wr,
507*d6b92ffaSHans Petter Selasky 						       &real_bad_wr);
508*d6b92ffaSHans Petter Selasky 
509*d6b92ffaSHans Petter Selasky 	if (ret) {
510*d6b92ffaSHans Petter Selasky 		for (real_wr = head_wr, w = wr;
511*d6b92ffaSHans Petter Selasky 		     real_wr;
512*d6b92ffaSHans Petter Selasky 		     real_wr = real_wr->next, w = w->next)
513*d6b92ffaSHans Petter Selasky 			if (real_wr == real_bad_wr) {
514*d6b92ffaSHans Petter Selasky 				*bad_wr = w;
515*d6b92ffaSHans Petter Selasky 				break;
516*d6b92ffaSHans Petter Selasky 			}
517*d6b92ffaSHans Petter Selasky 	}
518*d6b92ffaSHans Petter Selasky 
519*d6b92ffaSHans Petter Selasky 	return ret;
520*d6b92ffaSHans Petter Selasky }
521*d6b92ffaSHans Petter Selasky 
__ibv_open_device_1_0(struct ibv_device_1_0 * device)522*d6b92ffaSHans Petter Selasky struct ibv_context_1_0 *__ibv_open_device_1_0(struct ibv_device_1_0 *device)
523*d6b92ffaSHans Petter Selasky {
524*d6b92ffaSHans Petter Selasky 	struct ibv_context     *real_ctx;
525*d6b92ffaSHans Petter Selasky 	struct ibv_context_1_0 *ctx;
526*d6b92ffaSHans Petter Selasky 
527*d6b92ffaSHans Petter Selasky 	ctx = malloc(sizeof *ctx);
528*d6b92ffaSHans Petter Selasky 	if (!ctx)
529*d6b92ffaSHans Petter Selasky 		return NULL;
530*d6b92ffaSHans Petter Selasky 
531*d6b92ffaSHans Petter Selasky 	real_ctx = ibv_open_device(device->real_device);
532*d6b92ffaSHans Petter Selasky 	if (!real_ctx) {
533*d6b92ffaSHans Petter Selasky 		free(ctx);
534*d6b92ffaSHans Petter Selasky 		return NULL;
535*d6b92ffaSHans Petter Selasky 	}
536*d6b92ffaSHans Petter Selasky 
537*d6b92ffaSHans Petter Selasky 	ctx->device       = device;
538*d6b92ffaSHans Petter Selasky 	ctx->real_context = real_ctx;
539*d6b92ffaSHans Petter Selasky 
540*d6b92ffaSHans Petter Selasky 	ctx->ops.poll_cq       = poll_cq_wrapper_1_0;
541*d6b92ffaSHans Petter Selasky 	ctx->ops.req_notify_cq = req_notify_cq_wrapper_1_0;
542*d6b92ffaSHans Petter Selasky 	ctx->ops.post_send     = post_send_wrapper_1_0;
543*d6b92ffaSHans Petter Selasky 	ctx->ops.post_recv     = post_recv_wrapper_1_0;
544*d6b92ffaSHans Petter Selasky 	ctx->ops.post_srq_recv = post_srq_recv_wrapper_1_0;
545*d6b92ffaSHans Petter Selasky 
546*d6b92ffaSHans Petter Selasky 	return ctx;
547*d6b92ffaSHans Petter Selasky }
548*d6b92ffaSHans Petter Selasky symver(__ibv_open_device_1_0, ibv_open_device, IBVERBS_1.0);
549*d6b92ffaSHans Petter Selasky 
__ibv_close_device_1_0(struct ibv_context_1_0 * context)550*d6b92ffaSHans Petter Selasky int __ibv_close_device_1_0(struct ibv_context_1_0 *context)
551*d6b92ffaSHans Petter Selasky {
552*d6b92ffaSHans Petter Selasky 	int ret;
553*d6b92ffaSHans Petter Selasky 
554*d6b92ffaSHans Petter Selasky 	ret = ibv_close_device(context->real_context);
555*d6b92ffaSHans Petter Selasky 	if (ret)
556*d6b92ffaSHans Petter Selasky 		return ret;
557*d6b92ffaSHans Petter Selasky 
558*d6b92ffaSHans Petter Selasky 	free(context);
559*d6b92ffaSHans Petter Selasky 	return 0;
560*d6b92ffaSHans Petter Selasky }
561*d6b92ffaSHans Petter Selasky symver(__ibv_close_device_1_0, ibv_close_device, IBVERBS_1.0);
562*d6b92ffaSHans Petter Selasky 
__ibv_get_async_event_1_0(struct ibv_context_1_0 * context,struct ibv_async_event * event)563*d6b92ffaSHans Petter Selasky int __ibv_get_async_event_1_0(struct ibv_context_1_0 *context,
564*d6b92ffaSHans Petter Selasky 			      struct ibv_async_event *event)
565*d6b92ffaSHans Petter Selasky {
566*d6b92ffaSHans Petter Selasky 	int ret;
567*d6b92ffaSHans Petter Selasky 
568*d6b92ffaSHans Petter Selasky 	ret = ibv_get_async_event(context->real_context, event);
569*d6b92ffaSHans Petter Selasky 	if (ret)
570*d6b92ffaSHans Petter Selasky 		return ret;
571*d6b92ffaSHans Petter Selasky 
572*d6b92ffaSHans Petter Selasky 	switch (event->event_type) {
573*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_CQ_ERR:
574*d6b92ffaSHans Petter Selasky 		event->element.cq = event->element.cq->cq_context;
575*d6b92ffaSHans Petter Selasky 		break;
576*d6b92ffaSHans Petter Selasky 
577*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_QP_FATAL:
578*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_QP_REQ_ERR:
579*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_QP_ACCESS_ERR:
580*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_COMM_EST:
581*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_SQ_DRAINED:
582*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_PATH_MIG:
583*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_PATH_MIG_ERR:
584*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_QP_LAST_WQE_REACHED:
585*d6b92ffaSHans Petter Selasky 		event->element.qp = event->element.qp->qp_context;
586*d6b92ffaSHans Petter Selasky 		break;
587*d6b92ffaSHans Petter Selasky 
588*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_SRQ_ERR:
589*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_SRQ_LIMIT_REACHED:
590*d6b92ffaSHans Petter Selasky 		event->element.srq = event->element.srq->srq_context;
591*d6b92ffaSHans Petter Selasky 		break;
592*d6b92ffaSHans Petter Selasky 
593*d6b92ffaSHans Petter Selasky 	default:
594*d6b92ffaSHans Petter Selasky 		break;
595*d6b92ffaSHans Petter Selasky 	}
596*d6b92ffaSHans Petter Selasky 
597*d6b92ffaSHans Petter Selasky 	return ret;
598*d6b92ffaSHans Petter Selasky }
599*d6b92ffaSHans Petter Selasky symver(__ibv_get_async_event_1_0, ibv_get_async_event, IBVERBS_1.0);
600*d6b92ffaSHans Petter Selasky 
__ibv_ack_async_event_1_0(struct ibv_async_event * event)601*d6b92ffaSHans Petter Selasky void __ibv_ack_async_event_1_0(struct ibv_async_event *event)
602*d6b92ffaSHans Petter Selasky {
603*d6b92ffaSHans Petter Selasky 	struct ibv_async_event real_event = *event;
604*d6b92ffaSHans Petter Selasky 
605*d6b92ffaSHans Petter Selasky 	switch (event->event_type) {
606*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_CQ_ERR:
607*d6b92ffaSHans Petter Selasky 		real_event.element.cq =
608*d6b92ffaSHans Petter Selasky 			((struct ibv_cq_1_0 *) event->element.cq)->real_cq;
609*d6b92ffaSHans Petter Selasky 		break;
610*d6b92ffaSHans Petter Selasky 
611*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_QP_FATAL:
612*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_QP_REQ_ERR:
613*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_QP_ACCESS_ERR:
614*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_COMM_EST:
615*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_SQ_DRAINED:
616*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_PATH_MIG:
617*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_PATH_MIG_ERR:
618*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_QP_LAST_WQE_REACHED:
619*d6b92ffaSHans Petter Selasky 		real_event.element.qp =
620*d6b92ffaSHans Petter Selasky 			((struct ibv_qp_1_0 *) event->element.qp)->real_qp;
621*d6b92ffaSHans Petter Selasky 		break;
622*d6b92ffaSHans Petter Selasky 
623*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_SRQ_ERR:
624*d6b92ffaSHans Petter Selasky 	case IBV_EVENT_SRQ_LIMIT_REACHED:
625*d6b92ffaSHans Petter Selasky 		real_event.element.srq =
626*d6b92ffaSHans Petter Selasky 			((struct ibv_srq_1_0 *) event->element.srq)->real_srq;
627*d6b92ffaSHans Petter Selasky 		break;
628*d6b92ffaSHans Petter Selasky 
629*d6b92ffaSHans Petter Selasky 	default:
630*d6b92ffaSHans Petter Selasky 		break;
631*d6b92ffaSHans Petter Selasky 	}
632*d6b92ffaSHans Petter Selasky 
633*d6b92ffaSHans Petter Selasky 	ibv_ack_async_event(&real_event);
634*d6b92ffaSHans Petter Selasky }
635*d6b92ffaSHans Petter Selasky symver(__ibv_ack_async_event_1_0, ibv_ack_async_event, IBVERBS_1.0);
636*d6b92ffaSHans Petter Selasky 
__ibv_query_device_1_0(struct ibv_context_1_0 * context,struct ibv_device_attr * device_attr)637*d6b92ffaSHans Petter Selasky int __ibv_query_device_1_0(struct ibv_context_1_0 *context,
638*d6b92ffaSHans Petter Selasky 			   struct ibv_device_attr *device_attr)
639*d6b92ffaSHans Petter Selasky {
640*d6b92ffaSHans Petter Selasky 	return ibv_query_device(context->real_context, device_attr);
641*d6b92ffaSHans Petter Selasky }
642*d6b92ffaSHans Petter Selasky symver(__ibv_query_device_1_0, ibv_query_device, IBVERBS_1.0);
643*d6b92ffaSHans Petter Selasky 
__ibv_query_port_1_0(struct ibv_context_1_0 * context,uint8_t port_num,struct ibv_port_attr * port_attr)644*d6b92ffaSHans Petter Selasky int __ibv_query_port_1_0(struct ibv_context_1_0 *context, uint8_t port_num,
645*d6b92ffaSHans Petter Selasky 			 struct ibv_port_attr *port_attr)
646*d6b92ffaSHans Petter Selasky {
647*d6b92ffaSHans Petter Selasky 	return ibv_query_port(context->real_context, port_num, port_attr);
648*d6b92ffaSHans Petter Selasky }
649*d6b92ffaSHans Petter Selasky symver(__ibv_query_port_1_0, ibv_query_port, IBVERBS_1.0);
650*d6b92ffaSHans Petter Selasky 
__ibv_query_gid_1_0(struct ibv_context_1_0 * context,uint8_t port_num,int index,union ibv_gid * gid)651*d6b92ffaSHans Petter Selasky int __ibv_query_gid_1_0(struct ibv_context_1_0 *context, uint8_t port_num,
652*d6b92ffaSHans Petter Selasky 			int index, union ibv_gid *gid)
653*d6b92ffaSHans Petter Selasky {
654*d6b92ffaSHans Petter Selasky 	return ibv_query_gid(context->real_context, port_num, index, gid);
655*d6b92ffaSHans Petter Selasky }
656*d6b92ffaSHans Petter Selasky symver(__ibv_query_gid_1_0, ibv_query_gid, IBVERBS_1.0);
657*d6b92ffaSHans Petter Selasky 
__ibv_query_pkey_1_0(struct ibv_context_1_0 * context,uint8_t port_num,int index,__be16 * pkey)658*d6b92ffaSHans Petter Selasky int __ibv_query_pkey_1_0(struct ibv_context_1_0 *context, uint8_t port_num,
659*d6b92ffaSHans Petter Selasky 			 int index, __be16 *pkey)
660*d6b92ffaSHans Petter Selasky {
661*d6b92ffaSHans Petter Selasky 	return ibv_query_pkey(context->real_context, port_num, index, pkey);
662*d6b92ffaSHans Petter Selasky }
663*d6b92ffaSHans Petter Selasky symver(__ibv_query_pkey_1_0, ibv_query_pkey, IBVERBS_1.0);
664*d6b92ffaSHans Petter Selasky 
__ibv_alloc_pd_1_0(struct ibv_context_1_0 * context)665*d6b92ffaSHans Petter Selasky struct ibv_pd_1_0 *__ibv_alloc_pd_1_0(struct ibv_context_1_0 *context)
666*d6b92ffaSHans Petter Selasky {
667*d6b92ffaSHans Petter Selasky 	struct ibv_pd *real_pd;
668*d6b92ffaSHans Petter Selasky 	struct ibv_pd_1_0 *pd;
669*d6b92ffaSHans Petter Selasky 
670*d6b92ffaSHans Petter Selasky 	pd = malloc(sizeof *pd);
671*d6b92ffaSHans Petter Selasky 	if (!pd)
672*d6b92ffaSHans Petter Selasky 		return NULL;
673*d6b92ffaSHans Petter Selasky 
674*d6b92ffaSHans Petter Selasky 	real_pd = ibv_alloc_pd(context->real_context);
675*d6b92ffaSHans Petter Selasky 	if (!real_pd) {
676*d6b92ffaSHans Petter Selasky 		free(pd);
677*d6b92ffaSHans Petter Selasky 		return NULL;
678*d6b92ffaSHans Petter Selasky 	}
679*d6b92ffaSHans Petter Selasky 
680*d6b92ffaSHans Petter Selasky 	pd->context = context;
681*d6b92ffaSHans Petter Selasky 	pd->real_pd = real_pd;
682*d6b92ffaSHans Petter Selasky 
683*d6b92ffaSHans Petter Selasky 	return pd;
684*d6b92ffaSHans Petter Selasky }
685*d6b92ffaSHans Petter Selasky symver(__ibv_alloc_pd_1_0, ibv_alloc_pd, IBVERBS_1.0);
686*d6b92ffaSHans Petter Selasky 
__ibv_dealloc_pd_1_0(struct ibv_pd_1_0 * pd)687*d6b92ffaSHans Petter Selasky int __ibv_dealloc_pd_1_0(struct ibv_pd_1_0 *pd)
688*d6b92ffaSHans Petter Selasky {
689*d6b92ffaSHans Petter Selasky 	int ret;
690*d6b92ffaSHans Petter Selasky 
691*d6b92ffaSHans Petter Selasky 	ret = ibv_dealloc_pd(pd->real_pd);
692*d6b92ffaSHans Petter Selasky 	if (ret)
693*d6b92ffaSHans Petter Selasky 		return ret;
694*d6b92ffaSHans Petter Selasky 
695*d6b92ffaSHans Petter Selasky 	free(pd);
696*d6b92ffaSHans Petter Selasky 	return 0;
697*d6b92ffaSHans Petter Selasky }
698*d6b92ffaSHans Petter Selasky symver(__ibv_dealloc_pd_1_0, ibv_dealloc_pd, IBVERBS_1.0);
699*d6b92ffaSHans Petter Selasky 
__ibv_reg_mr_1_0(struct ibv_pd_1_0 * pd,void * addr,size_t length,int access)700*d6b92ffaSHans Petter Selasky struct ibv_mr_1_0 *__ibv_reg_mr_1_0(struct ibv_pd_1_0 *pd, void *addr,
701*d6b92ffaSHans Petter Selasky 				    size_t length, int access)
702*d6b92ffaSHans Petter Selasky {
703*d6b92ffaSHans Petter Selasky 	struct ibv_mr *real_mr;
704*d6b92ffaSHans Petter Selasky 	struct ibv_mr_1_0 *mr;
705*d6b92ffaSHans Petter Selasky 
706*d6b92ffaSHans Petter Selasky 	mr = malloc(sizeof *mr);
707*d6b92ffaSHans Petter Selasky 	if (!mr)
708*d6b92ffaSHans Petter Selasky 		return NULL;
709*d6b92ffaSHans Petter Selasky 
710*d6b92ffaSHans Petter Selasky 	real_mr = ibv_reg_mr(pd->real_pd, addr, length, access);
711*d6b92ffaSHans Petter Selasky 	if (!real_mr) {
712*d6b92ffaSHans Petter Selasky 		free(mr);
713*d6b92ffaSHans Petter Selasky 		return NULL;
714*d6b92ffaSHans Petter Selasky 	}
715*d6b92ffaSHans Petter Selasky 
716*d6b92ffaSHans Petter Selasky 	mr->context = pd->context;
717*d6b92ffaSHans Petter Selasky 	mr->pd      = pd;
718*d6b92ffaSHans Petter Selasky 	mr->lkey    = real_mr->lkey;
719*d6b92ffaSHans Petter Selasky 	mr->rkey    = real_mr->rkey;
720*d6b92ffaSHans Petter Selasky 	mr->real_mr = real_mr;
721*d6b92ffaSHans Petter Selasky 
722*d6b92ffaSHans Petter Selasky 	return mr;
723*d6b92ffaSHans Petter Selasky }
724*d6b92ffaSHans Petter Selasky symver(__ibv_reg_mr_1_0, ibv_reg_mr, IBVERBS_1.0);
725*d6b92ffaSHans Petter Selasky 
__ibv_dereg_mr_1_0(struct ibv_mr_1_0 * mr)726*d6b92ffaSHans Petter Selasky int __ibv_dereg_mr_1_0(struct ibv_mr_1_0 *mr)
727*d6b92ffaSHans Petter Selasky {
728*d6b92ffaSHans Petter Selasky 	int ret;
729*d6b92ffaSHans Petter Selasky 
730*d6b92ffaSHans Petter Selasky 	ret = ibv_dereg_mr(mr->real_mr);
731*d6b92ffaSHans Petter Selasky 	if (ret)
732*d6b92ffaSHans Petter Selasky 		return ret;
733*d6b92ffaSHans Petter Selasky 
734*d6b92ffaSHans Petter Selasky 	free(mr);
735*d6b92ffaSHans Petter Selasky 	return 0;
736*d6b92ffaSHans Petter Selasky }
737*d6b92ffaSHans Petter Selasky symver(__ibv_dereg_mr_1_0, ibv_dereg_mr, IBVERBS_1.0);
738*d6b92ffaSHans Petter Selasky 
__ibv_create_cq_1_0(struct ibv_context_1_0 * context,int cqe,void * cq_context,struct ibv_comp_channel * channel,int comp_vector)739*d6b92ffaSHans Petter Selasky struct ibv_cq_1_0 *__ibv_create_cq_1_0(struct ibv_context_1_0 *context, int cqe,
740*d6b92ffaSHans Petter Selasky 				       void *cq_context,
741*d6b92ffaSHans Petter Selasky 				       struct ibv_comp_channel *channel,
742*d6b92ffaSHans Petter Selasky 				       int comp_vector)
743*d6b92ffaSHans Petter Selasky {
744*d6b92ffaSHans Petter Selasky 	struct ibv_cq *real_cq;
745*d6b92ffaSHans Petter Selasky 	struct ibv_cq_1_0 *cq;
746*d6b92ffaSHans Petter Selasky 
747*d6b92ffaSHans Petter Selasky 	cq = malloc(sizeof *cq);
748*d6b92ffaSHans Petter Selasky 	if (!cq)
749*d6b92ffaSHans Petter Selasky 		return NULL;
750*d6b92ffaSHans Petter Selasky 
751*d6b92ffaSHans Petter Selasky 	real_cq = ibv_create_cq(context->real_context, cqe, cq_context,
752*d6b92ffaSHans Petter Selasky 				channel, comp_vector);
753*d6b92ffaSHans Petter Selasky 	if (!real_cq) {
754*d6b92ffaSHans Petter Selasky 		free(cq);
755*d6b92ffaSHans Petter Selasky 		return NULL;
756*d6b92ffaSHans Petter Selasky 	}
757*d6b92ffaSHans Petter Selasky 
758*d6b92ffaSHans Petter Selasky 	cq->context    = context;
759*d6b92ffaSHans Petter Selasky 	cq->cq_context = cq_context;
760*d6b92ffaSHans Petter Selasky 	cq->cqe        = cqe;
761*d6b92ffaSHans Petter Selasky 	cq->real_cq    = real_cq;
762*d6b92ffaSHans Petter Selasky 
763*d6b92ffaSHans Petter Selasky 	real_cq->cq_context = cq;
764*d6b92ffaSHans Petter Selasky 
765*d6b92ffaSHans Petter Selasky 	return cq;
766*d6b92ffaSHans Petter Selasky }
767*d6b92ffaSHans Petter Selasky symver(__ibv_create_cq_1_0, ibv_create_cq, IBVERBS_1.0);
768*d6b92ffaSHans Petter Selasky 
__ibv_resize_cq_1_0(struct ibv_cq_1_0 * cq,int cqe)769*d6b92ffaSHans Petter Selasky int __ibv_resize_cq_1_0(struct ibv_cq_1_0 *cq, int cqe)
770*d6b92ffaSHans Petter Selasky {
771*d6b92ffaSHans Petter Selasky 	return ibv_resize_cq(cq->real_cq, cqe);
772*d6b92ffaSHans Petter Selasky }
773*d6b92ffaSHans Petter Selasky symver(__ibv_resize_cq_1_0, ibv_resize_cq, IBVERBS_1.0);
774*d6b92ffaSHans Petter Selasky 
__ibv_destroy_cq_1_0(struct ibv_cq_1_0 * cq)775*d6b92ffaSHans Petter Selasky int __ibv_destroy_cq_1_0(struct ibv_cq_1_0 *cq)
776*d6b92ffaSHans Petter Selasky {
777*d6b92ffaSHans Petter Selasky 	int ret;
778*d6b92ffaSHans Petter Selasky 
779*d6b92ffaSHans Petter Selasky 	ret = ibv_destroy_cq(cq->real_cq);
780*d6b92ffaSHans Petter Selasky 	if (ret)
781*d6b92ffaSHans Petter Selasky 		return ret;
782*d6b92ffaSHans Petter Selasky 
783*d6b92ffaSHans Petter Selasky 	free(cq);
784*d6b92ffaSHans Petter Selasky 	return 0;
785*d6b92ffaSHans Petter Selasky }
786*d6b92ffaSHans Petter Selasky symver(__ibv_destroy_cq_1_0, ibv_destroy_cq, IBVERBS_1.0);
787*d6b92ffaSHans Petter Selasky 
__ibv_get_cq_event_1_0(struct ibv_comp_channel * channel,struct ibv_cq_1_0 ** cq,void ** cq_context)788*d6b92ffaSHans Petter Selasky int __ibv_get_cq_event_1_0(struct ibv_comp_channel *channel,
789*d6b92ffaSHans Petter Selasky 			   struct ibv_cq_1_0 **cq, void **cq_context)
790*d6b92ffaSHans Petter Selasky {
791*d6b92ffaSHans Petter Selasky 	struct ibv_cq *real_cq;
792*d6b92ffaSHans Petter Selasky 	void *cq_ptr;
793*d6b92ffaSHans Petter Selasky 	int ret;
794*d6b92ffaSHans Petter Selasky 
795*d6b92ffaSHans Petter Selasky 	ret = ibv_get_cq_event(channel, &real_cq, &cq_ptr);
796*d6b92ffaSHans Petter Selasky 	if (ret)
797*d6b92ffaSHans Petter Selasky 		return ret;
798*d6b92ffaSHans Petter Selasky 
799*d6b92ffaSHans Petter Selasky 	*cq         = cq_ptr;
800*d6b92ffaSHans Petter Selasky 	*cq_context = (*cq)->cq_context;
801*d6b92ffaSHans Petter Selasky 
802*d6b92ffaSHans Petter Selasky 	return 0;
803*d6b92ffaSHans Petter Selasky }
804*d6b92ffaSHans Petter Selasky symver(__ibv_get_cq_event_1_0, ibv_get_cq_event, IBVERBS_1.0);
805*d6b92ffaSHans Petter Selasky 
__ibv_ack_cq_events_1_0(struct ibv_cq_1_0 * cq,unsigned int nevents)806*d6b92ffaSHans Petter Selasky void __ibv_ack_cq_events_1_0(struct ibv_cq_1_0 *cq, unsigned int nevents)
807*d6b92ffaSHans Petter Selasky {
808*d6b92ffaSHans Petter Selasky 	ibv_ack_cq_events(cq->real_cq, nevents);
809*d6b92ffaSHans Petter Selasky }
810*d6b92ffaSHans Petter Selasky symver(__ibv_ack_cq_events_1_0, ibv_ack_cq_events, IBVERBS_1.0);
811*d6b92ffaSHans Petter Selasky 
__ibv_create_srq_1_0(struct ibv_pd_1_0 * pd,struct ibv_srq_init_attr * srq_init_attr)812*d6b92ffaSHans Petter Selasky struct ibv_srq_1_0 *__ibv_create_srq_1_0(struct ibv_pd_1_0 *pd,
813*d6b92ffaSHans Petter Selasky 					 struct ibv_srq_init_attr *srq_init_attr)
814*d6b92ffaSHans Petter Selasky {
815*d6b92ffaSHans Petter Selasky 	struct ibv_srq *real_srq;
816*d6b92ffaSHans Petter Selasky 	struct ibv_srq_1_0 *srq;
817*d6b92ffaSHans Petter Selasky 
818*d6b92ffaSHans Petter Selasky 	srq = malloc(sizeof *srq);
819*d6b92ffaSHans Petter Selasky 	if (!srq)
820*d6b92ffaSHans Petter Selasky 		return NULL;
821*d6b92ffaSHans Petter Selasky 
822*d6b92ffaSHans Petter Selasky 	real_srq = ibv_create_srq(pd->real_pd, srq_init_attr);
823*d6b92ffaSHans Petter Selasky 	if (!real_srq) {
824*d6b92ffaSHans Petter Selasky 		free(srq);
825*d6b92ffaSHans Petter Selasky 		return NULL;
826*d6b92ffaSHans Petter Selasky 	}
827*d6b92ffaSHans Petter Selasky 
828*d6b92ffaSHans Petter Selasky 	srq->context     = pd->context;
829*d6b92ffaSHans Petter Selasky 	srq->srq_context = srq_init_attr->srq_context;
830*d6b92ffaSHans Petter Selasky 	srq->pd          = pd;
831*d6b92ffaSHans Petter Selasky 	srq->real_srq    = real_srq;
832*d6b92ffaSHans Petter Selasky 
833*d6b92ffaSHans Petter Selasky 	real_srq->srq_context = srq;
834*d6b92ffaSHans Petter Selasky 
835*d6b92ffaSHans Petter Selasky 	return srq;
836*d6b92ffaSHans Petter Selasky }
837*d6b92ffaSHans Petter Selasky symver(__ibv_create_srq_1_0, ibv_create_srq, IBVERBS_1.0);
838*d6b92ffaSHans Petter Selasky 
__ibv_modify_srq_1_0(struct ibv_srq_1_0 * srq,struct ibv_srq_attr * srq_attr,int srq_attr_mask)839*d6b92ffaSHans Petter Selasky int __ibv_modify_srq_1_0(struct ibv_srq_1_0 *srq,
840*d6b92ffaSHans Petter Selasky 			 struct ibv_srq_attr *srq_attr,
841*d6b92ffaSHans Petter Selasky 			 int srq_attr_mask)
842*d6b92ffaSHans Petter Selasky {
843*d6b92ffaSHans Petter Selasky 	return ibv_modify_srq(srq->real_srq, srq_attr, srq_attr_mask);
844*d6b92ffaSHans Petter Selasky }
845*d6b92ffaSHans Petter Selasky symver(__ibv_modify_srq_1_0, ibv_modify_srq, IBVERBS_1.0);
846*d6b92ffaSHans Petter Selasky 
__ibv_query_srq_1_0(struct ibv_srq_1_0 * srq,struct ibv_srq_attr * srq_attr)847*d6b92ffaSHans Petter Selasky int __ibv_query_srq_1_0(struct ibv_srq_1_0 *srq, struct ibv_srq_attr *srq_attr)
848*d6b92ffaSHans Petter Selasky {
849*d6b92ffaSHans Petter Selasky 	return ibv_query_srq(srq->real_srq, srq_attr);
850*d6b92ffaSHans Petter Selasky }
851*d6b92ffaSHans Petter Selasky symver(__ibv_query_srq_1_0, ibv_query_srq, IBVERBS_1.0);
852*d6b92ffaSHans Petter Selasky 
__ibv_destroy_srq_1_0(struct ibv_srq_1_0 * srq)853*d6b92ffaSHans Petter Selasky int __ibv_destroy_srq_1_0(struct ibv_srq_1_0 *srq)
854*d6b92ffaSHans Petter Selasky {
855*d6b92ffaSHans Petter Selasky 	int ret;
856*d6b92ffaSHans Petter Selasky 
857*d6b92ffaSHans Petter Selasky 	ret = ibv_destroy_srq(srq->real_srq);
858*d6b92ffaSHans Petter Selasky 	if (ret)
859*d6b92ffaSHans Petter Selasky 		return ret;
860*d6b92ffaSHans Petter Selasky 
861*d6b92ffaSHans Petter Selasky 	free(srq);
862*d6b92ffaSHans Petter Selasky 	return 0;
863*d6b92ffaSHans Petter Selasky }
864*d6b92ffaSHans Petter Selasky symver(__ibv_destroy_srq_1_0, ibv_destroy_srq, IBVERBS_1.0);
865*d6b92ffaSHans Petter Selasky 
__ibv_create_qp_1_0(struct ibv_pd_1_0 * pd,struct ibv_qp_init_attr_1_0 * qp_init_attr)866*d6b92ffaSHans Petter Selasky struct ibv_qp_1_0 *__ibv_create_qp_1_0(struct ibv_pd_1_0 *pd,
867*d6b92ffaSHans Petter Selasky 				       struct ibv_qp_init_attr_1_0 *qp_init_attr)
868*d6b92ffaSHans Petter Selasky {
869*d6b92ffaSHans Petter Selasky 	struct ibv_qp *real_qp;
870*d6b92ffaSHans Petter Selasky 	struct ibv_qp_1_0 *qp;
871*d6b92ffaSHans Petter Selasky 	struct ibv_qp_init_attr real_init_attr;
872*d6b92ffaSHans Petter Selasky 
873*d6b92ffaSHans Petter Selasky 	qp = malloc(sizeof *qp);
874*d6b92ffaSHans Petter Selasky 	if (!qp)
875*d6b92ffaSHans Petter Selasky 		return NULL;
876*d6b92ffaSHans Petter Selasky 
877*d6b92ffaSHans Petter Selasky 	real_init_attr.qp_context = qp_init_attr->qp_context;
878*d6b92ffaSHans Petter Selasky 	real_init_attr.send_cq    = qp_init_attr->send_cq->real_cq;
879*d6b92ffaSHans Petter Selasky 	real_init_attr.recv_cq    = qp_init_attr->recv_cq->real_cq;
880*d6b92ffaSHans Petter Selasky 	real_init_attr.srq        = qp_init_attr->srq ?
881*d6b92ffaSHans Petter Selasky 		qp_init_attr->srq->real_srq : NULL;
882*d6b92ffaSHans Petter Selasky 	real_init_attr.cap        = qp_init_attr->cap;
883*d6b92ffaSHans Petter Selasky 	real_init_attr.qp_type    = qp_init_attr->qp_type;
884*d6b92ffaSHans Petter Selasky 	real_init_attr.sq_sig_all = qp_init_attr->sq_sig_all;
885*d6b92ffaSHans Petter Selasky 
886*d6b92ffaSHans Petter Selasky 	real_qp = ibv_create_qp(pd->real_pd, &real_init_attr);
887*d6b92ffaSHans Petter Selasky 	if (!real_qp) {
888*d6b92ffaSHans Petter Selasky 		free(qp);
889*d6b92ffaSHans Petter Selasky 		return NULL;
890*d6b92ffaSHans Petter Selasky 	}
891*d6b92ffaSHans Petter Selasky 
892*d6b92ffaSHans Petter Selasky 	qp->context    = pd->context;
893*d6b92ffaSHans Petter Selasky 	qp->qp_context = qp_init_attr->qp_context;
894*d6b92ffaSHans Petter Selasky 	qp->pd         = pd;
895*d6b92ffaSHans Petter Selasky 	qp->send_cq    = qp_init_attr->send_cq;
896*d6b92ffaSHans Petter Selasky 	qp->recv_cq    = qp_init_attr->recv_cq;
897*d6b92ffaSHans Petter Selasky 	qp->srq        = qp_init_attr->srq;
898*d6b92ffaSHans Petter Selasky 	qp->qp_type    = qp_init_attr->qp_type;
899*d6b92ffaSHans Petter Selasky 	qp->qp_num     = real_qp->qp_num;
900*d6b92ffaSHans Petter Selasky 	qp->real_qp    = real_qp;
901*d6b92ffaSHans Petter Selasky 
902*d6b92ffaSHans Petter Selasky 	qp_init_attr->cap = real_init_attr.cap;
903*d6b92ffaSHans Petter Selasky 
904*d6b92ffaSHans Petter Selasky 	real_qp->qp_context = qp;
905*d6b92ffaSHans Petter Selasky 
906*d6b92ffaSHans Petter Selasky 	return qp;
907*d6b92ffaSHans Petter Selasky }
908*d6b92ffaSHans Petter Selasky symver(__ibv_create_qp_1_0, ibv_create_qp, IBVERBS_1.0);
909*d6b92ffaSHans Petter Selasky 
__ibv_query_qp_1_0(struct ibv_qp_1_0 * qp,struct ibv_qp_attr * attr,int attr_mask,struct ibv_qp_init_attr_1_0 * init_attr)910*d6b92ffaSHans Petter Selasky int __ibv_query_qp_1_0(struct ibv_qp_1_0 *qp, struct ibv_qp_attr *attr,
911*d6b92ffaSHans Petter Selasky 		       int attr_mask,
912*d6b92ffaSHans Petter Selasky 		       struct ibv_qp_init_attr_1_0 *init_attr)
913*d6b92ffaSHans Petter Selasky {
914*d6b92ffaSHans Petter Selasky 	struct ibv_qp_init_attr real_init_attr;
915*d6b92ffaSHans Petter Selasky 	int ret;
916*d6b92ffaSHans Petter Selasky 
917*d6b92ffaSHans Petter Selasky 	ret = ibv_query_qp(qp->real_qp, attr, attr_mask, &real_init_attr);
918*d6b92ffaSHans Petter Selasky 	if (ret)
919*d6b92ffaSHans Petter Selasky 		return ret;
920*d6b92ffaSHans Petter Selasky 
921*d6b92ffaSHans Petter Selasky 	init_attr->qp_context = qp->qp_context;
922*d6b92ffaSHans Petter Selasky 	init_attr->send_cq    = real_init_attr.send_cq->cq_context;
923*d6b92ffaSHans Petter Selasky 	init_attr->recv_cq    = real_init_attr.recv_cq->cq_context;
924*d6b92ffaSHans Petter Selasky 	init_attr->srq        = real_init_attr.srq->srq_context;
925*d6b92ffaSHans Petter Selasky 	init_attr->qp_type    = real_init_attr.qp_type;
926*d6b92ffaSHans Petter Selasky 	init_attr->cap        = real_init_attr.cap;
927*d6b92ffaSHans Petter Selasky 	init_attr->sq_sig_all = real_init_attr.sq_sig_all;
928*d6b92ffaSHans Petter Selasky 
929*d6b92ffaSHans Petter Selasky 	return 0;
930*d6b92ffaSHans Petter Selasky }
931*d6b92ffaSHans Petter Selasky symver(__ibv_query_qp_1_0, ibv_query_qp, IBVERBS_1.0);
932*d6b92ffaSHans Petter Selasky 
__ibv_modify_qp_1_0(struct ibv_qp_1_0 * qp,struct ibv_qp_attr * attr,int attr_mask)933*d6b92ffaSHans Petter Selasky int __ibv_modify_qp_1_0(struct ibv_qp_1_0 *qp, struct ibv_qp_attr *attr,
934*d6b92ffaSHans Petter Selasky 			int attr_mask)
935*d6b92ffaSHans Petter Selasky {
936*d6b92ffaSHans Petter Selasky 	return ibv_modify_qp(qp->real_qp, attr, attr_mask);
937*d6b92ffaSHans Petter Selasky }
938*d6b92ffaSHans Petter Selasky symver(__ibv_modify_qp_1_0, ibv_modify_qp, IBVERBS_1.0);
939*d6b92ffaSHans Petter Selasky 
__ibv_destroy_qp_1_0(struct ibv_qp_1_0 * qp)940*d6b92ffaSHans Petter Selasky int __ibv_destroy_qp_1_0(struct ibv_qp_1_0 *qp)
941*d6b92ffaSHans Petter Selasky {
942*d6b92ffaSHans Petter Selasky 	int ret;
943*d6b92ffaSHans Petter Selasky 
944*d6b92ffaSHans Petter Selasky 	ret = ibv_destroy_qp(qp->real_qp);
945*d6b92ffaSHans Petter Selasky 	if (ret)
946*d6b92ffaSHans Petter Selasky 		return ret;
947*d6b92ffaSHans Petter Selasky 
948*d6b92ffaSHans Petter Selasky 	free(qp);
949*d6b92ffaSHans Petter Selasky 	return 0;
950*d6b92ffaSHans Petter Selasky }
951*d6b92ffaSHans Petter Selasky symver(__ibv_destroy_qp_1_0, ibv_destroy_qp, IBVERBS_1.0);
952*d6b92ffaSHans Petter Selasky 
__ibv_create_ah_1_0(struct ibv_pd_1_0 * pd,struct ibv_ah_attr * attr)953*d6b92ffaSHans Petter Selasky struct ibv_ah_1_0 *__ibv_create_ah_1_0(struct ibv_pd_1_0 *pd,
954*d6b92ffaSHans Petter Selasky 				       struct ibv_ah_attr *attr)
955*d6b92ffaSHans Petter Selasky {
956*d6b92ffaSHans Petter Selasky 	struct ibv_ah *real_ah;
957*d6b92ffaSHans Petter Selasky 	struct ibv_ah_1_0 *ah;
958*d6b92ffaSHans Petter Selasky 
959*d6b92ffaSHans Petter Selasky 	ah = malloc(sizeof *ah);
960*d6b92ffaSHans Petter Selasky 	if (!ah)
961*d6b92ffaSHans Petter Selasky 		return NULL;
962*d6b92ffaSHans Petter Selasky 
963*d6b92ffaSHans Petter Selasky 	real_ah = ibv_create_ah(pd->real_pd, attr);
964*d6b92ffaSHans Petter Selasky 	if (!real_ah) {
965*d6b92ffaSHans Petter Selasky 		free(ah);
966*d6b92ffaSHans Petter Selasky 		return NULL;
967*d6b92ffaSHans Petter Selasky 	}
968*d6b92ffaSHans Petter Selasky 
969*d6b92ffaSHans Petter Selasky 	ah->context = pd->context;
970*d6b92ffaSHans Petter Selasky 	ah->pd      = pd;
971*d6b92ffaSHans Petter Selasky 	ah->real_ah = real_ah;
972*d6b92ffaSHans Petter Selasky 
973*d6b92ffaSHans Petter Selasky 	return ah;
974*d6b92ffaSHans Petter Selasky }
975*d6b92ffaSHans Petter Selasky symver(__ibv_create_ah_1_0, ibv_create_ah, IBVERBS_1.0);
976*d6b92ffaSHans Petter Selasky 
__ibv_destroy_ah_1_0(struct ibv_ah_1_0 * ah)977*d6b92ffaSHans Petter Selasky int __ibv_destroy_ah_1_0(struct ibv_ah_1_0 *ah)
978*d6b92ffaSHans Petter Selasky {
979*d6b92ffaSHans Petter Selasky 	int ret;
980*d6b92ffaSHans Petter Selasky 
981*d6b92ffaSHans Petter Selasky 	ret = ibv_destroy_ah(ah->real_ah);
982*d6b92ffaSHans Petter Selasky 	if (ret)
983*d6b92ffaSHans Petter Selasky 		return ret;
984*d6b92ffaSHans Petter Selasky 
985*d6b92ffaSHans Petter Selasky 	free(ah);
986*d6b92ffaSHans Petter Selasky 	return 0;
987*d6b92ffaSHans Petter Selasky }
988*d6b92ffaSHans Petter Selasky symver(__ibv_destroy_ah_1_0, ibv_destroy_ah, IBVERBS_1.0);
989*d6b92ffaSHans Petter Selasky 
__ibv_attach_mcast_1_0(struct ibv_qp_1_0 * qp,union ibv_gid * gid,uint16_t lid)990*d6b92ffaSHans Petter Selasky int __ibv_attach_mcast_1_0(struct ibv_qp_1_0 *qp, union ibv_gid *gid, uint16_t lid)
991*d6b92ffaSHans Petter Selasky {
992*d6b92ffaSHans Petter Selasky 	return ibv_attach_mcast(qp->real_qp, gid, lid);
993*d6b92ffaSHans Petter Selasky }
994*d6b92ffaSHans Petter Selasky symver(__ibv_attach_mcast_1_0, ibv_attach_mcast, IBVERBS_1.0);
995*d6b92ffaSHans Petter Selasky 
__ibv_detach_mcast_1_0(struct ibv_qp_1_0 * qp,union ibv_gid * gid,uint16_t lid)996*d6b92ffaSHans Petter Selasky int __ibv_detach_mcast_1_0(struct ibv_qp_1_0 *qp, union ibv_gid *gid, uint16_t lid)
997*d6b92ffaSHans Petter Selasky {
998*d6b92ffaSHans Petter Selasky 	return ibv_detach_mcast(qp->real_qp, gid, lid);
999*d6b92ffaSHans Petter Selasky }
1000*d6b92ffaSHans Petter Selasky symver(__ibv_detach_mcast_1_0, ibv_detach_mcast, IBVERBS_1.0);
1001*d6b92ffaSHans Petter Selasky 
__ibv_register_driver_1_1(const char * name,ibv_driver_init_func_1_1 init_func)1002*d6b92ffaSHans Petter Selasky void __ibv_register_driver_1_1(const char *name, ibv_driver_init_func_1_1 init_func)
1003*d6b92ffaSHans Petter Selasky {
1004*d6b92ffaSHans Petter Selasky 	/* The driver interface is private as of rdma-core 13. This stub is
1005*d6b92ffaSHans Petter Selasky 	 * left to preserve dynamic-link compatibility with old libfabrics
1006*d6b92ffaSHans Petter Selasky 	 * usnic providers which use this function only to suppress a fprintf
1007*d6b92ffaSHans Petter Selasky 	 * in old versions of libibverbs. */
1008*d6b92ffaSHans Petter Selasky }
1009*d6b92ffaSHans Petter Selasky symver(__ibv_register_driver_1_1, ibv_register_driver, IBVERBS_1.1);
1010