2 * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
4 * Copyright (c) 2004 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * OpenIB.org BSD license below:
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
22 * - Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials
25 * provided with the distribution.
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 * $Id: verbs.c 1349 2004-12-16 21:09:43Z roland $
39 #include <linux/errno.h>
40 #include <linux/err.h>
44 /* Protection domains */
46 struct ib_pd
*ib_alloc_pd(struct ib_device
*device
)
50 pd
= device
->alloc_pd(device
);
54 atomic_set(&pd
->usecnt
, 0);
59 EXPORT_SYMBOL(ib_alloc_pd
);
61 int ib_dealloc_pd(struct ib_pd
*pd
)
63 if (atomic_read(&pd
->usecnt
))
66 return pd
->device
->dealloc_pd(pd
);
68 EXPORT_SYMBOL(ib_dealloc_pd
);
72 struct ib_ah
*ib_create_ah(struct ib_pd
*pd
, struct ib_ah_attr
*ah_attr
)
76 ah
= pd
->device
->create_ah(pd
, ah_attr
);
79 ah
->device
= pd
->device
;
81 atomic_inc(&pd
->usecnt
);
86 EXPORT_SYMBOL(ib_create_ah
);
88 int ib_modify_ah(struct ib_ah
*ah
, struct ib_ah_attr
*ah_attr
)
90 return ah
->device
->modify_ah
?
91 ah
->device
->modify_ah(ah
, ah_attr
) :
94 EXPORT_SYMBOL(ib_modify_ah
);
96 int ib_query_ah(struct ib_ah
*ah
, struct ib_ah_attr
*ah_attr
)
98 return ah
->device
->query_ah
?
99 ah
->device
->query_ah(ah
, ah_attr
) :
102 EXPORT_SYMBOL(ib_query_ah
);
104 int ib_destroy_ah(struct ib_ah
*ah
)
110 ret
= ah
->device
->destroy_ah(ah
);
112 atomic_dec(&pd
->usecnt
);
116 EXPORT_SYMBOL(ib_destroy_ah
);
120 struct ib_qp
*ib_create_qp(struct ib_pd
*pd
,
121 struct ib_qp_init_attr
*qp_init_attr
)
125 qp
= pd
->device
->create_qp(pd
, qp_init_attr
);
128 qp
->device
= pd
->device
;
130 qp
->send_cq
= qp_init_attr
->send_cq
;
131 qp
->recv_cq
= qp_init_attr
->recv_cq
;
132 qp
->srq
= qp_init_attr
->srq
;
133 qp
->event_handler
= qp_init_attr
->event_handler
;
134 qp
->qp_context
= qp_init_attr
->qp_context
;
135 qp
->qp_type
= qp_init_attr
->qp_type
;
136 atomic_inc(&pd
->usecnt
);
137 atomic_inc(&qp_init_attr
->send_cq
->usecnt
);
138 atomic_inc(&qp_init_attr
->recv_cq
->usecnt
);
139 if (qp_init_attr
->srq
)
140 atomic_inc(&qp_init_attr
->srq
->usecnt
);
145 EXPORT_SYMBOL(ib_create_qp
);
147 int ib_modify_qp(struct ib_qp
*qp
,
148 struct ib_qp_attr
*qp_attr
,
151 return qp
->device
->modify_qp(qp
, qp_attr
, qp_attr_mask
);
153 EXPORT_SYMBOL(ib_modify_qp
);
155 int ib_query_qp(struct ib_qp
*qp
,
156 struct ib_qp_attr
*qp_attr
,
158 struct ib_qp_init_attr
*qp_init_attr
)
160 return qp
->device
->query_qp
?
161 qp
->device
->query_qp(qp
, qp_attr
, qp_attr_mask
, qp_init_attr
) :
164 EXPORT_SYMBOL(ib_query_qp
);
166 int ib_destroy_qp(struct ib_qp
*qp
)
169 struct ib_cq
*scq
, *rcq
;
178 ret
= qp
->device
->destroy_qp(qp
);
180 atomic_dec(&pd
->usecnt
);
181 atomic_dec(&scq
->usecnt
);
182 atomic_dec(&rcq
->usecnt
);
184 atomic_dec(&srq
->usecnt
);
189 EXPORT_SYMBOL(ib_destroy_qp
);
191 /* Completion queues */
193 struct ib_cq
*ib_create_cq(struct ib_device
*device
,
194 ib_comp_handler comp_handler
,
195 void (*event_handler
)(struct ib_event
*, void *),
196 void *cq_context
, int cqe
)
200 cq
= device
->create_cq(device
, cqe
);
204 cq
->comp_handler
= comp_handler
;
205 cq
->event_handler
= event_handler
;
206 cq
->cq_context
= cq_context
;
207 atomic_set(&cq
->usecnt
, 0);
212 EXPORT_SYMBOL(ib_create_cq
);
214 int ib_destroy_cq(struct ib_cq
*cq
)
216 if (atomic_read(&cq
->usecnt
))
219 return cq
->device
->destroy_cq(cq
);
221 EXPORT_SYMBOL(ib_destroy_cq
);
223 int ib_resize_cq(struct ib_cq
*cq
,
228 if (!cq
->device
->resize_cq
)
231 ret
= cq
->device
->resize_cq(cq
, &cqe
);
237 EXPORT_SYMBOL(ib_resize_cq
);
241 struct ib_mr
*ib_get_dma_mr(struct ib_pd
*pd
, int mr_access_flags
)
245 mr
= pd
->device
->get_dma_mr(pd
, mr_access_flags
);
248 mr
->device
= pd
->device
;
250 atomic_inc(&pd
->usecnt
);
251 atomic_set(&mr
->usecnt
, 0);
256 EXPORT_SYMBOL(ib_get_dma_mr
);
258 struct ib_mr
*ib_reg_phys_mr(struct ib_pd
*pd
,
259 struct ib_phys_buf
*phys_buf_array
,
266 mr
= pd
->device
->reg_phys_mr(pd
, phys_buf_array
, num_phys_buf
,
267 mr_access_flags
, iova_start
);
270 mr
->device
= pd
->device
;
272 atomic_inc(&pd
->usecnt
);
273 atomic_set(&mr
->usecnt
, 0);
278 EXPORT_SYMBOL(ib_reg_phys_mr
);
280 int ib_rereg_phys_mr(struct ib_mr
*mr
,
283 struct ib_phys_buf
*phys_buf_array
,
288 struct ib_pd
*old_pd
;
291 if (!mr
->device
->rereg_phys_mr
)
294 if (atomic_read(&mr
->usecnt
))
299 ret
= mr
->device
->rereg_phys_mr(mr
, mr_rereg_mask
, pd
,
300 phys_buf_array
, num_phys_buf
,
301 mr_access_flags
, iova_start
);
303 if (!ret
&& (mr_rereg_mask
& IB_MR_REREG_PD
)) {
304 atomic_dec(&old_pd
->usecnt
);
305 atomic_inc(&pd
->usecnt
);
310 EXPORT_SYMBOL(ib_rereg_phys_mr
);
312 int ib_query_mr(struct ib_mr
*mr
, struct ib_mr_attr
*mr_attr
)
314 return mr
->device
->query_mr
?
315 mr
->device
->query_mr(mr
, mr_attr
) : -ENOSYS
;
317 EXPORT_SYMBOL(ib_query_mr
);
319 int ib_dereg_mr(struct ib_mr
*mr
)
324 if (atomic_read(&mr
->usecnt
))
328 ret
= mr
->device
->dereg_mr(mr
);
330 atomic_dec(&pd
->usecnt
);
334 EXPORT_SYMBOL(ib_dereg_mr
);
338 struct ib_mw
*ib_alloc_mw(struct ib_pd
*pd
)
342 if (!pd
->device
->alloc_mw
)
343 return ERR_PTR(-ENOSYS
);
345 mw
= pd
->device
->alloc_mw(pd
);
347 mw
->device
= pd
->device
;
349 atomic_inc(&pd
->usecnt
);
354 EXPORT_SYMBOL(ib_alloc_mw
);
356 int ib_dealloc_mw(struct ib_mw
*mw
)
362 ret
= mw
->device
->dealloc_mw(mw
);
364 atomic_dec(&pd
->usecnt
);
368 EXPORT_SYMBOL(ib_dealloc_mw
);
370 /* "Fast" memory regions */
372 struct ib_fmr
*ib_alloc_fmr(struct ib_pd
*pd
,
374 struct ib_fmr_attr
*fmr_attr
)
378 if (!pd
->device
->alloc_fmr
)
379 return ERR_PTR(-ENOSYS
);
381 fmr
= pd
->device
->alloc_fmr(pd
, mr_access_flags
, fmr_attr
);
383 fmr
->device
= pd
->device
;
385 atomic_inc(&pd
->usecnt
);
390 EXPORT_SYMBOL(ib_alloc_fmr
);
392 int ib_unmap_fmr(struct list_head
*fmr_list
)
396 if (list_empty(fmr_list
))
399 fmr
= list_entry(fmr_list
->next
, struct ib_fmr
, list
);
400 return fmr
->device
->unmap_fmr(fmr_list
);
402 EXPORT_SYMBOL(ib_unmap_fmr
);
404 int ib_dealloc_fmr(struct ib_fmr
*fmr
)
410 ret
= fmr
->device
->dealloc_fmr(fmr
);
412 atomic_dec(&pd
->usecnt
);
416 EXPORT_SYMBOL(ib_dealloc_fmr
);
418 /* Multicast groups */
420 int ib_attach_mcast(struct ib_qp
*qp
, union ib_gid
*gid
, u16 lid
)
422 return qp
->device
->attach_mcast
?
423 qp
->device
->attach_mcast(qp
, gid
, lid
) :
426 EXPORT_SYMBOL(ib_attach_mcast
);
428 int ib_detach_mcast(struct ib_qp
*qp
, union ib_gid
*gid
, u16 lid
)
430 return qp
->device
->detach_mcast
?
431 qp
->device
->detach_mcast(qp
, gid
, lid
) :
434 EXPORT_SYMBOL(ib_detach_mcast
);