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.
7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
8 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
10 * This software is available to you under a choice of one of two
11 * licenses. You may choose to be licensed under the terms of the GNU
12 * General Public License (GPL) Version 2, available from the file
13 * COPYING in the main directory of this source tree, or the
14 * OpenIB.org BSD license below:
16 * Redistribution and use in source and binary forms, with or
17 * without modification, are permitted provided that the following
20 * - Redistributions of source code must retain the above
21 * copyright notice, this list of conditions and the following
24 * - Redistributions in binary form must reproduce the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer in the documentation and/or other materials
27 * provided with the distribution.
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 #include <linux/errno.h>
40 #include <linux/err.h>
41 #include <linux/string.h>
43 #include <rdma/ib_verbs.h>
44 #include <rdma/ib_cache.h>
46 int ib_rate_to_mult(enum ib_rate rate
)
49 case IB_RATE_2_5_GBPS
: return 1;
50 case IB_RATE_5_GBPS
: return 2;
51 case IB_RATE_10_GBPS
: return 4;
52 case IB_RATE_20_GBPS
: return 8;
53 case IB_RATE_30_GBPS
: return 12;
54 case IB_RATE_40_GBPS
: return 16;
55 case IB_RATE_60_GBPS
: return 24;
56 case IB_RATE_80_GBPS
: return 32;
57 case IB_RATE_120_GBPS
: return 48;
61 EXPORT_SYMBOL(ib_rate_to_mult
);
63 enum ib_rate
mult_to_ib_rate(int mult
)
66 case 1: return IB_RATE_2_5_GBPS
;
67 case 2: return IB_RATE_5_GBPS
;
68 case 4: return IB_RATE_10_GBPS
;
69 case 8: return IB_RATE_20_GBPS
;
70 case 12: return IB_RATE_30_GBPS
;
71 case 16: return IB_RATE_40_GBPS
;
72 case 24: return IB_RATE_60_GBPS
;
73 case 32: return IB_RATE_80_GBPS
;
74 case 48: return IB_RATE_120_GBPS
;
75 default: return IB_RATE_PORT_CURRENT
;
78 EXPORT_SYMBOL(mult_to_ib_rate
);
80 enum rdma_transport_type
81 rdma_node_get_transport(enum rdma_node_type node_type
)
85 case RDMA_NODE_IB_SWITCH
:
86 case RDMA_NODE_IB_ROUTER
:
87 return RDMA_TRANSPORT_IB
;
89 return RDMA_TRANSPORT_IWARP
;
95 EXPORT_SYMBOL(rdma_node_get_transport
);
97 enum rdma_link_layer
rdma_port_get_link_layer(struct ib_device
*device
, u8 port_num
)
99 if (device
->get_link_layer
)
100 return device
->get_link_layer(device
, port_num
);
102 switch (rdma_node_get_transport(device
->node_type
)) {
103 case RDMA_TRANSPORT_IB
:
104 return IB_LINK_LAYER_INFINIBAND
;
105 case RDMA_TRANSPORT_IWARP
:
106 return IB_LINK_LAYER_ETHERNET
;
108 return IB_LINK_LAYER_UNSPECIFIED
;
111 EXPORT_SYMBOL(rdma_port_get_link_layer
);
113 /* Protection domains */
115 struct ib_pd
*ib_alloc_pd(struct ib_device
*device
)
119 pd
= device
->alloc_pd(device
, NULL
, NULL
);
124 atomic_set(&pd
->usecnt
, 0);
129 EXPORT_SYMBOL(ib_alloc_pd
);
131 int ib_dealloc_pd(struct ib_pd
*pd
)
133 if (atomic_read(&pd
->usecnt
))
136 return pd
->device
->dealloc_pd(pd
);
138 EXPORT_SYMBOL(ib_dealloc_pd
);
140 /* Address handles */
142 struct ib_ah
*ib_create_ah(struct ib_pd
*pd
, struct ib_ah_attr
*ah_attr
)
146 ah
= pd
->device
->create_ah(pd
, ah_attr
);
149 ah
->device
= pd
->device
;
152 atomic_inc(&pd
->usecnt
);
157 EXPORT_SYMBOL(ib_create_ah
);
159 int ib_init_ah_from_wc(struct ib_device
*device
, u8 port_num
, struct ib_wc
*wc
,
160 struct ib_grh
*grh
, struct ib_ah_attr
*ah_attr
)
166 memset(ah_attr
, 0, sizeof *ah_attr
);
167 ah_attr
->dlid
= wc
->slid
;
168 ah_attr
->sl
= wc
->sl
;
169 ah_attr
->src_path_bits
= wc
->dlid_path_bits
;
170 ah_attr
->port_num
= port_num
;
172 if (wc
->wc_flags
& IB_WC_GRH
) {
173 ah_attr
->ah_flags
= IB_AH_GRH
;
174 ah_attr
->grh
.dgid
= grh
->sgid
;
176 ret
= ib_find_cached_gid(device
, &grh
->dgid
, &port_num
,
181 ah_attr
->grh
.sgid_index
= (u8
) gid_index
;
182 flow_class
= be32_to_cpu(grh
->version_tclass_flow
);
183 ah_attr
->grh
.flow_label
= flow_class
& 0xFFFFF;
184 ah_attr
->grh
.hop_limit
= 0xFF;
185 ah_attr
->grh
.traffic_class
= (flow_class
>> 20) & 0xFF;
189 EXPORT_SYMBOL(ib_init_ah_from_wc
);
191 struct ib_ah
*ib_create_ah_from_wc(struct ib_pd
*pd
, struct ib_wc
*wc
,
192 struct ib_grh
*grh
, u8 port_num
)
194 struct ib_ah_attr ah_attr
;
197 ret
= ib_init_ah_from_wc(pd
->device
, port_num
, wc
, grh
, &ah_attr
);
201 return ib_create_ah(pd
, &ah_attr
);
203 EXPORT_SYMBOL(ib_create_ah_from_wc
);
205 int ib_modify_ah(struct ib_ah
*ah
, struct ib_ah_attr
*ah_attr
)
207 return ah
->device
->modify_ah
?
208 ah
->device
->modify_ah(ah
, ah_attr
) :
211 EXPORT_SYMBOL(ib_modify_ah
);
213 int ib_query_ah(struct ib_ah
*ah
, struct ib_ah_attr
*ah_attr
)
215 return ah
->device
->query_ah
?
216 ah
->device
->query_ah(ah
, ah_attr
) :
219 EXPORT_SYMBOL(ib_query_ah
);
221 int ib_destroy_ah(struct ib_ah
*ah
)
227 ret
= ah
->device
->destroy_ah(ah
);
229 atomic_dec(&pd
->usecnt
);
233 EXPORT_SYMBOL(ib_destroy_ah
);
235 /* Shared receive queues */
237 struct ib_srq
*ib_create_srq(struct ib_pd
*pd
,
238 struct ib_srq_init_attr
*srq_init_attr
)
242 if (!pd
->device
->create_srq
)
243 return ERR_PTR(-ENOSYS
);
245 srq
= pd
->device
->create_srq(pd
, srq_init_attr
, NULL
);
248 srq
->device
= pd
->device
;
251 srq
->event_handler
= srq_init_attr
->event_handler
;
252 srq
->srq_context
= srq_init_attr
->srq_context
;
253 atomic_inc(&pd
->usecnt
);
254 atomic_set(&srq
->usecnt
, 0);
259 EXPORT_SYMBOL(ib_create_srq
);
261 int ib_modify_srq(struct ib_srq
*srq
,
262 struct ib_srq_attr
*srq_attr
,
263 enum ib_srq_attr_mask srq_attr_mask
)
265 return srq
->device
->modify_srq
?
266 srq
->device
->modify_srq(srq
, srq_attr
, srq_attr_mask
, NULL
) :
269 EXPORT_SYMBOL(ib_modify_srq
);
271 int ib_query_srq(struct ib_srq
*srq
,
272 struct ib_srq_attr
*srq_attr
)
274 return srq
->device
->query_srq
?
275 srq
->device
->query_srq(srq
, srq_attr
) : -ENOSYS
;
277 EXPORT_SYMBOL(ib_query_srq
);
279 int ib_destroy_srq(struct ib_srq
*srq
)
284 if (atomic_read(&srq
->usecnt
))
289 ret
= srq
->device
->destroy_srq(srq
);
291 atomic_dec(&pd
->usecnt
);
295 EXPORT_SYMBOL(ib_destroy_srq
);
299 struct ib_qp
*ib_create_qp(struct ib_pd
*pd
,
300 struct ib_qp_init_attr
*qp_init_attr
)
304 qp
= pd
->device
->create_qp(pd
, qp_init_attr
, NULL
);
307 qp
->device
= pd
->device
;
309 qp
->send_cq
= qp_init_attr
->send_cq
;
310 qp
->recv_cq
= qp_init_attr
->recv_cq
;
311 qp
->srq
= qp_init_attr
->srq
;
313 qp
->event_handler
= qp_init_attr
->event_handler
;
314 qp
->qp_context
= qp_init_attr
->qp_context
;
315 qp
->qp_type
= qp_init_attr
->qp_type
;
316 atomic_inc(&pd
->usecnt
);
317 atomic_inc(&qp_init_attr
->send_cq
->usecnt
);
318 atomic_inc(&qp_init_attr
->recv_cq
->usecnt
);
319 if (qp_init_attr
->srq
)
320 atomic_inc(&qp_init_attr
->srq
->usecnt
);
325 EXPORT_SYMBOL(ib_create_qp
);
327 static const struct {
329 enum ib_qp_attr_mask req_param
[IB_QPT_RAW_ETHERTYPE
+ 1];
330 enum ib_qp_attr_mask opt_param
[IB_QPT_RAW_ETHERTYPE
+ 1];
331 } qp_state_table
[IB_QPS_ERR
+ 1][IB_QPS_ERR
+ 1] = {
333 [IB_QPS_RESET
] = { .valid
= 1 },
337 [IB_QPT_UD
] = (IB_QP_PKEY_INDEX
|
340 [IB_QPT_UC
] = (IB_QP_PKEY_INDEX
|
343 [IB_QPT_RC
] = (IB_QP_PKEY_INDEX
|
346 [IB_QPT_SMI
] = (IB_QP_PKEY_INDEX
|
348 [IB_QPT_GSI
] = (IB_QP_PKEY_INDEX
|
354 [IB_QPS_RESET
] = { .valid
= 1 },
355 [IB_QPS_ERR
] = { .valid
= 1 },
359 [IB_QPT_UD
] = (IB_QP_PKEY_INDEX
|
362 [IB_QPT_UC
] = (IB_QP_PKEY_INDEX
|
365 [IB_QPT_RC
] = (IB_QP_PKEY_INDEX
|
368 [IB_QPT_SMI
] = (IB_QP_PKEY_INDEX
|
370 [IB_QPT_GSI
] = (IB_QP_PKEY_INDEX
|
377 [IB_QPT_UC
] = (IB_QP_AV
|
381 [IB_QPT_RC
] = (IB_QP_AV
|
385 IB_QP_MAX_DEST_RD_ATOMIC
|
386 IB_QP_MIN_RNR_TIMER
),
389 [IB_QPT_UD
] = (IB_QP_PKEY_INDEX
|
391 [IB_QPT_UC
] = (IB_QP_ALT_PATH
|
394 [IB_QPT_RC
] = (IB_QP_ALT_PATH
|
397 [IB_QPT_SMI
] = (IB_QP_PKEY_INDEX
|
399 [IB_QPT_GSI
] = (IB_QP_PKEY_INDEX
|
405 [IB_QPS_RESET
] = { .valid
= 1 },
406 [IB_QPS_ERR
] = { .valid
= 1 },
410 [IB_QPT_UD
] = IB_QP_SQ_PSN
,
411 [IB_QPT_UC
] = IB_QP_SQ_PSN
,
412 [IB_QPT_RC
] = (IB_QP_TIMEOUT
|
416 IB_QP_MAX_QP_RD_ATOMIC
),
417 [IB_QPT_SMI
] = IB_QP_SQ_PSN
,
418 [IB_QPT_GSI
] = IB_QP_SQ_PSN
,
421 [IB_QPT_UD
] = (IB_QP_CUR_STATE
|
423 [IB_QPT_UC
] = (IB_QP_CUR_STATE
|
426 IB_QP_PATH_MIG_STATE
),
427 [IB_QPT_RC
] = (IB_QP_CUR_STATE
|
430 IB_QP_MIN_RNR_TIMER
|
431 IB_QP_PATH_MIG_STATE
),
432 [IB_QPT_SMI
] = (IB_QP_CUR_STATE
|
434 [IB_QPT_GSI
] = (IB_QP_CUR_STATE
|
440 [IB_QPS_RESET
] = { .valid
= 1 },
441 [IB_QPS_ERR
] = { .valid
= 1 },
445 [IB_QPT_UD
] = (IB_QP_CUR_STATE
|
447 [IB_QPT_UC
] = (IB_QP_CUR_STATE
|
450 IB_QP_PATH_MIG_STATE
),
451 [IB_QPT_RC
] = (IB_QP_CUR_STATE
|
454 IB_QP_PATH_MIG_STATE
|
455 IB_QP_MIN_RNR_TIMER
),
456 [IB_QPT_SMI
] = (IB_QP_CUR_STATE
|
458 [IB_QPT_GSI
] = (IB_QP_CUR_STATE
|
465 [IB_QPT_UD
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
466 [IB_QPT_UC
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
467 [IB_QPT_RC
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
468 [IB_QPT_SMI
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
469 [IB_QPT_GSI
] = IB_QP_EN_SQD_ASYNC_NOTIFY
474 [IB_QPS_RESET
] = { .valid
= 1 },
475 [IB_QPS_ERR
] = { .valid
= 1 },
479 [IB_QPT_UD
] = (IB_QP_CUR_STATE
|
481 [IB_QPT_UC
] = (IB_QP_CUR_STATE
|
484 IB_QP_PATH_MIG_STATE
),
485 [IB_QPT_RC
] = (IB_QP_CUR_STATE
|
488 IB_QP_MIN_RNR_TIMER
|
489 IB_QP_PATH_MIG_STATE
),
490 [IB_QPT_SMI
] = (IB_QP_CUR_STATE
|
492 [IB_QPT_GSI
] = (IB_QP_CUR_STATE
|
499 [IB_QPT_UD
] = (IB_QP_PKEY_INDEX
|
501 [IB_QPT_UC
] = (IB_QP_AV
|
505 IB_QP_PATH_MIG_STATE
),
506 [IB_QPT_RC
] = (IB_QP_PORT
|
511 IB_QP_MAX_QP_RD_ATOMIC
|
512 IB_QP_MAX_DEST_RD_ATOMIC
|
516 IB_QP_MIN_RNR_TIMER
|
517 IB_QP_PATH_MIG_STATE
),
518 [IB_QPT_SMI
] = (IB_QP_PKEY_INDEX
|
520 [IB_QPT_GSI
] = (IB_QP_PKEY_INDEX
|
526 [IB_QPS_RESET
] = { .valid
= 1 },
527 [IB_QPS_ERR
] = { .valid
= 1 },
531 [IB_QPT_UD
] = (IB_QP_CUR_STATE
|
533 [IB_QPT_UC
] = (IB_QP_CUR_STATE
|
535 [IB_QPT_SMI
] = (IB_QP_CUR_STATE
|
537 [IB_QPT_GSI
] = (IB_QP_CUR_STATE
|
543 [IB_QPS_RESET
] = { .valid
= 1 },
544 [IB_QPS_ERR
] = { .valid
= 1 }
548 int ib_modify_qp_is_ok(enum ib_qp_state cur_state
, enum ib_qp_state next_state
,
549 enum ib_qp_type type
, enum ib_qp_attr_mask mask
)
551 enum ib_qp_attr_mask req_param
, opt_param
;
553 if (cur_state
< 0 || cur_state
> IB_QPS_ERR
||
554 next_state
< 0 || next_state
> IB_QPS_ERR
)
557 if (mask
& IB_QP_CUR_STATE
&&
558 cur_state
!= IB_QPS_RTR
&& cur_state
!= IB_QPS_RTS
&&
559 cur_state
!= IB_QPS_SQD
&& cur_state
!= IB_QPS_SQE
)
562 if (!qp_state_table
[cur_state
][next_state
].valid
)
565 req_param
= qp_state_table
[cur_state
][next_state
].req_param
[type
];
566 opt_param
= qp_state_table
[cur_state
][next_state
].opt_param
[type
];
568 if ((mask
& req_param
) != req_param
)
571 if (mask
& ~(req_param
| opt_param
| IB_QP_STATE
))
576 EXPORT_SYMBOL(ib_modify_qp_is_ok
);
578 int ib_modify_qp(struct ib_qp
*qp
,
579 struct ib_qp_attr
*qp_attr
,
582 return qp
->device
->modify_qp(qp
, qp_attr
, qp_attr_mask
, NULL
);
584 EXPORT_SYMBOL(ib_modify_qp
);
586 int ib_query_qp(struct ib_qp
*qp
,
587 struct ib_qp_attr
*qp_attr
,
589 struct ib_qp_init_attr
*qp_init_attr
)
591 return qp
->device
->query_qp
?
592 qp
->device
->query_qp(qp
, qp_attr
, qp_attr_mask
, qp_init_attr
) :
595 EXPORT_SYMBOL(ib_query_qp
);
597 int ib_destroy_qp(struct ib_qp
*qp
)
600 struct ib_cq
*scq
, *rcq
;
609 ret
= qp
->device
->destroy_qp(qp
);
611 atomic_dec(&pd
->usecnt
);
612 atomic_dec(&scq
->usecnt
);
613 atomic_dec(&rcq
->usecnt
);
615 atomic_dec(&srq
->usecnt
);
620 EXPORT_SYMBOL(ib_destroy_qp
);
622 /* Completion queues */
624 struct ib_cq
*ib_create_cq(struct ib_device
*device
,
625 ib_comp_handler comp_handler
,
626 void (*event_handler
)(struct ib_event
*, void *),
627 void *cq_context
, int cqe
, int comp_vector
)
631 cq
= device
->create_cq(device
, cqe
, comp_vector
, NULL
, NULL
);
636 cq
->comp_handler
= comp_handler
;
637 cq
->event_handler
= event_handler
;
638 cq
->cq_context
= cq_context
;
639 atomic_set(&cq
->usecnt
, 0);
644 EXPORT_SYMBOL(ib_create_cq
);
646 int ib_modify_cq(struct ib_cq
*cq
, u16 cq_count
, u16 cq_period
)
648 return cq
->device
->modify_cq
?
649 cq
->device
->modify_cq(cq
, cq_count
, cq_period
) : -ENOSYS
;
651 EXPORT_SYMBOL(ib_modify_cq
);
653 int ib_destroy_cq(struct ib_cq
*cq
)
655 if (atomic_read(&cq
->usecnt
))
658 return cq
->device
->destroy_cq(cq
);
660 EXPORT_SYMBOL(ib_destroy_cq
);
662 int ib_resize_cq(struct ib_cq
*cq
, int cqe
)
664 return cq
->device
->resize_cq
?
665 cq
->device
->resize_cq(cq
, cqe
, NULL
) : -ENOSYS
;
667 EXPORT_SYMBOL(ib_resize_cq
);
671 struct ib_mr
*ib_get_dma_mr(struct ib_pd
*pd
, int mr_access_flags
)
675 mr
= pd
->device
->get_dma_mr(pd
, mr_access_flags
);
678 mr
->device
= pd
->device
;
681 atomic_inc(&pd
->usecnt
);
682 atomic_set(&mr
->usecnt
, 0);
687 EXPORT_SYMBOL(ib_get_dma_mr
);
689 struct ib_mr
*ib_reg_phys_mr(struct ib_pd
*pd
,
690 struct ib_phys_buf
*phys_buf_array
,
697 if (!pd
->device
->reg_phys_mr
)
698 return ERR_PTR(-ENOSYS
);
700 mr
= pd
->device
->reg_phys_mr(pd
, phys_buf_array
, num_phys_buf
,
701 mr_access_flags
, iova_start
);
704 mr
->device
= pd
->device
;
707 atomic_inc(&pd
->usecnt
);
708 atomic_set(&mr
->usecnt
, 0);
713 EXPORT_SYMBOL(ib_reg_phys_mr
);
715 int ib_rereg_phys_mr(struct ib_mr
*mr
,
718 struct ib_phys_buf
*phys_buf_array
,
723 struct ib_pd
*old_pd
;
726 if (!mr
->device
->rereg_phys_mr
)
729 if (atomic_read(&mr
->usecnt
))
734 ret
= mr
->device
->rereg_phys_mr(mr
, mr_rereg_mask
, pd
,
735 phys_buf_array
, num_phys_buf
,
736 mr_access_flags
, iova_start
);
738 if (!ret
&& (mr_rereg_mask
& IB_MR_REREG_PD
)) {
739 atomic_dec(&old_pd
->usecnt
);
740 atomic_inc(&pd
->usecnt
);
745 EXPORT_SYMBOL(ib_rereg_phys_mr
);
747 int ib_query_mr(struct ib_mr
*mr
, struct ib_mr_attr
*mr_attr
)
749 return mr
->device
->query_mr
?
750 mr
->device
->query_mr(mr
, mr_attr
) : -ENOSYS
;
752 EXPORT_SYMBOL(ib_query_mr
);
754 int ib_dereg_mr(struct ib_mr
*mr
)
759 if (atomic_read(&mr
->usecnt
))
763 ret
= mr
->device
->dereg_mr(mr
);
765 atomic_dec(&pd
->usecnt
);
769 EXPORT_SYMBOL(ib_dereg_mr
);
771 struct ib_mr
*ib_alloc_fast_reg_mr(struct ib_pd
*pd
, int max_page_list_len
)
775 if (!pd
->device
->alloc_fast_reg_mr
)
776 return ERR_PTR(-ENOSYS
);
778 mr
= pd
->device
->alloc_fast_reg_mr(pd
, max_page_list_len
);
781 mr
->device
= pd
->device
;
784 atomic_inc(&pd
->usecnt
);
785 atomic_set(&mr
->usecnt
, 0);
790 EXPORT_SYMBOL(ib_alloc_fast_reg_mr
);
792 struct ib_fast_reg_page_list
*ib_alloc_fast_reg_page_list(struct ib_device
*device
,
793 int max_page_list_len
)
795 struct ib_fast_reg_page_list
*page_list
;
797 if (!device
->alloc_fast_reg_page_list
)
798 return ERR_PTR(-ENOSYS
);
800 page_list
= device
->alloc_fast_reg_page_list(device
, max_page_list_len
);
802 if (!IS_ERR(page_list
)) {
803 page_list
->device
= device
;
804 page_list
->max_page_list_len
= max_page_list_len
;
809 EXPORT_SYMBOL(ib_alloc_fast_reg_page_list
);
811 void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list
*page_list
)
813 page_list
->device
->free_fast_reg_page_list(page_list
);
815 EXPORT_SYMBOL(ib_free_fast_reg_page_list
);
819 struct ib_mw
*ib_alloc_mw(struct ib_pd
*pd
)
823 if (!pd
->device
->alloc_mw
)
824 return ERR_PTR(-ENOSYS
);
826 mw
= pd
->device
->alloc_mw(pd
);
828 mw
->device
= pd
->device
;
831 atomic_inc(&pd
->usecnt
);
836 EXPORT_SYMBOL(ib_alloc_mw
);
838 int ib_dealloc_mw(struct ib_mw
*mw
)
844 ret
= mw
->device
->dealloc_mw(mw
);
846 atomic_dec(&pd
->usecnt
);
850 EXPORT_SYMBOL(ib_dealloc_mw
);
852 /* "Fast" memory regions */
854 struct ib_fmr
*ib_alloc_fmr(struct ib_pd
*pd
,
856 struct ib_fmr_attr
*fmr_attr
)
860 if (!pd
->device
->alloc_fmr
)
861 return ERR_PTR(-ENOSYS
);
863 fmr
= pd
->device
->alloc_fmr(pd
, mr_access_flags
, fmr_attr
);
865 fmr
->device
= pd
->device
;
867 atomic_inc(&pd
->usecnt
);
872 EXPORT_SYMBOL(ib_alloc_fmr
);
874 int ib_unmap_fmr(struct list_head
*fmr_list
)
878 if (list_empty(fmr_list
))
881 fmr
= list_entry(fmr_list
->next
, struct ib_fmr
, list
);
882 return fmr
->device
->unmap_fmr(fmr_list
);
884 EXPORT_SYMBOL(ib_unmap_fmr
);
886 int ib_dealloc_fmr(struct ib_fmr
*fmr
)
892 ret
= fmr
->device
->dealloc_fmr(fmr
);
894 atomic_dec(&pd
->usecnt
);
898 EXPORT_SYMBOL(ib_dealloc_fmr
);
900 /* Multicast groups */
902 int ib_attach_mcast(struct ib_qp
*qp
, union ib_gid
*gid
, u16 lid
)
904 if (!qp
->device
->attach_mcast
)
906 if (gid
->raw
[0] != 0xff || qp
->qp_type
!= IB_QPT_UD
)
909 return qp
->device
->attach_mcast(qp
, gid
, lid
);
911 EXPORT_SYMBOL(ib_attach_mcast
);
913 int ib_detach_mcast(struct ib_qp
*qp
, union ib_gid
*gid
, u16 lid
)
915 if (!qp
->device
->detach_mcast
)
917 if (gid
->raw
[0] != 0xff || qp
->qp_type
!= IB_QPT_UD
)
920 return qp
->device
->detach_mcast(qp
, gid
, lid
);
922 EXPORT_SYMBOL(ib_detach_mcast
);