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/export.h>
42 #include <linux/string.h>
43 #include <linux/slab.h>
45 #include <rdma/ib_verbs.h>
46 #include <rdma/ib_cache.h>
48 int ib_rate_to_mult(enum ib_rate rate
)
51 case IB_RATE_2_5_GBPS
: return 1;
52 case IB_RATE_5_GBPS
: return 2;
53 case IB_RATE_10_GBPS
: return 4;
54 case IB_RATE_20_GBPS
: return 8;
55 case IB_RATE_30_GBPS
: return 12;
56 case IB_RATE_40_GBPS
: return 16;
57 case IB_RATE_60_GBPS
: return 24;
58 case IB_RATE_80_GBPS
: return 32;
59 case IB_RATE_120_GBPS
: return 48;
63 EXPORT_SYMBOL(ib_rate_to_mult
);
65 enum ib_rate
mult_to_ib_rate(int mult
)
68 case 1: return IB_RATE_2_5_GBPS
;
69 case 2: return IB_RATE_5_GBPS
;
70 case 4: return IB_RATE_10_GBPS
;
71 case 8: return IB_RATE_20_GBPS
;
72 case 12: return IB_RATE_30_GBPS
;
73 case 16: return IB_RATE_40_GBPS
;
74 case 24: return IB_RATE_60_GBPS
;
75 case 32: return IB_RATE_80_GBPS
;
76 case 48: return IB_RATE_120_GBPS
;
77 default: return IB_RATE_PORT_CURRENT
;
80 EXPORT_SYMBOL(mult_to_ib_rate
);
82 int ib_rate_to_mbps(enum ib_rate rate
)
85 case IB_RATE_2_5_GBPS
: return 2500;
86 case IB_RATE_5_GBPS
: return 5000;
87 case IB_RATE_10_GBPS
: return 10000;
88 case IB_RATE_20_GBPS
: return 20000;
89 case IB_RATE_30_GBPS
: return 30000;
90 case IB_RATE_40_GBPS
: return 40000;
91 case IB_RATE_60_GBPS
: return 60000;
92 case IB_RATE_80_GBPS
: return 80000;
93 case IB_RATE_120_GBPS
: return 120000;
94 case IB_RATE_14_GBPS
: return 14062;
95 case IB_RATE_56_GBPS
: return 56250;
96 case IB_RATE_112_GBPS
: return 112500;
97 case IB_RATE_168_GBPS
: return 168750;
98 case IB_RATE_25_GBPS
: return 25781;
99 case IB_RATE_100_GBPS
: return 103125;
100 case IB_RATE_200_GBPS
: return 206250;
101 case IB_RATE_300_GBPS
: return 309375;
105 EXPORT_SYMBOL(ib_rate_to_mbps
);
107 enum rdma_transport_type
108 rdma_node_get_transport(enum rdma_node_type node_type
)
111 case RDMA_NODE_IB_CA
:
112 case RDMA_NODE_IB_SWITCH
:
113 case RDMA_NODE_IB_ROUTER
:
114 return RDMA_TRANSPORT_IB
;
116 return RDMA_TRANSPORT_IWARP
;
122 EXPORT_SYMBOL(rdma_node_get_transport
);
124 enum rdma_link_layer
rdma_port_get_link_layer(struct ib_device
*device
, u8 port_num
)
126 if (device
->get_link_layer
)
127 return device
->get_link_layer(device
, port_num
);
129 switch (rdma_node_get_transport(device
->node_type
)) {
130 case RDMA_TRANSPORT_IB
:
131 return IB_LINK_LAYER_INFINIBAND
;
132 case RDMA_TRANSPORT_IWARP
:
133 return IB_LINK_LAYER_ETHERNET
;
135 return IB_LINK_LAYER_UNSPECIFIED
;
138 EXPORT_SYMBOL(rdma_port_get_link_layer
);
140 /* Protection domains */
142 struct ib_pd
*ib_alloc_pd(struct ib_device
*device
)
146 pd
= device
->alloc_pd(device
, NULL
, NULL
);
151 atomic_set(&pd
->usecnt
, 0);
156 EXPORT_SYMBOL(ib_alloc_pd
);
158 int ib_dealloc_pd(struct ib_pd
*pd
)
160 if (atomic_read(&pd
->usecnt
))
163 return pd
->device
->dealloc_pd(pd
);
165 EXPORT_SYMBOL(ib_dealloc_pd
);
167 /* Address handles */
169 struct ib_ah
*ib_create_ah(struct ib_pd
*pd
, struct ib_ah_attr
*ah_attr
)
173 ah
= pd
->device
->create_ah(pd
, ah_attr
);
176 ah
->device
= pd
->device
;
179 atomic_inc(&pd
->usecnt
);
184 EXPORT_SYMBOL(ib_create_ah
);
186 int ib_init_ah_from_wc(struct ib_device
*device
, u8 port_num
, struct ib_wc
*wc
,
187 struct ib_grh
*grh
, struct ib_ah_attr
*ah_attr
)
193 memset(ah_attr
, 0, sizeof *ah_attr
);
194 ah_attr
->dlid
= wc
->slid
;
195 ah_attr
->sl
= wc
->sl
;
196 ah_attr
->src_path_bits
= wc
->dlid_path_bits
;
197 ah_attr
->port_num
= port_num
;
199 if (wc
->wc_flags
& IB_WC_GRH
) {
200 ah_attr
->ah_flags
= IB_AH_GRH
;
201 ah_attr
->grh
.dgid
= grh
->sgid
;
203 ret
= ib_find_cached_gid(device
, &grh
->dgid
, &port_num
,
208 ah_attr
->grh
.sgid_index
= (u8
) gid_index
;
209 flow_class
= be32_to_cpu(grh
->version_tclass_flow
);
210 ah_attr
->grh
.flow_label
= flow_class
& 0xFFFFF;
211 ah_attr
->grh
.hop_limit
= 0xFF;
212 ah_attr
->grh
.traffic_class
= (flow_class
>> 20) & 0xFF;
216 EXPORT_SYMBOL(ib_init_ah_from_wc
);
218 struct ib_ah
*ib_create_ah_from_wc(struct ib_pd
*pd
, struct ib_wc
*wc
,
219 struct ib_grh
*grh
, u8 port_num
)
221 struct ib_ah_attr ah_attr
;
224 ret
= ib_init_ah_from_wc(pd
->device
, port_num
, wc
, grh
, &ah_attr
);
228 return ib_create_ah(pd
, &ah_attr
);
230 EXPORT_SYMBOL(ib_create_ah_from_wc
);
232 int ib_modify_ah(struct ib_ah
*ah
, struct ib_ah_attr
*ah_attr
)
234 return ah
->device
->modify_ah
?
235 ah
->device
->modify_ah(ah
, ah_attr
) :
238 EXPORT_SYMBOL(ib_modify_ah
);
240 int ib_query_ah(struct ib_ah
*ah
, struct ib_ah_attr
*ah_attr
)
242 return ah
->device
->query_ah
?
243 ah
->device
->query_ah(ah
, ah_attr
) :
246 EXPORT_SYMBOL(ib_query_ah
);
248 int ib_destroy_ah(struct ib_ah
*ah
)
254 ret
= ah
->device
->destroy_ah(ah
);
256 atomic_dec(&pd
->usecnt
);
260 EXPORT_SYMBOL(ib_destroy_ah
);
262 /* Shared receive queues */
264 struct ib_srq
*ib_create_srq(struct ib_pd
*pd
,
265 struct ib_srq_init_attr
*srq_init_attr
)
269 if (!pd
->device
->create_srq
)
270 return ERR_PTR(-ENOSYS
);
272 srq
= pd
->device
->create_srq(pd
, srq_init_attr
, NULL
);
275 srq
->device
= pd
->device
;
278 srq
->event_handler
= srq_init_attr
->event_handler
;
279 srq
->srq_context
= srq_init_attr
->srq_context
;
280 srq
->srq_type
= srq_init_attr
->srq_type
;
281 if (srq
->srq_type
== IB_SRQT_XRC
) {
282 srq
->ext
.xrc
.xrcd
= srq_init_attr
->ext
.xrc
.xrcd
;
283 srq
->ext
.xrc
.cq
= srq_init_attr
->ext
.xrc
.cq
;
284 atomic_inc(&srq
->ext
.xrc
.xrcd
->usecnt
);
285 atomic_inc(&srq
->ext
.xrc
.cq
->usecnt
);
287 atomic_inc(&pd
->usecnt
);
288 atomic_set(&srq
->usecnt
, 0);
293 EXPORT_SYMBOL(ib_create_srq
);
295 int ib_modify_srq(struct ib_srq
*srq
,
296 struct ib_srq_attr
*srq_attr
,
297 enum ib_srq_attr_mask srq_attr_mask
)
299 return srq
->device
->modify_srq
?
300 srq
->device
->modify_srq(srq
, srq_attr
, srq_attr_mask
, NULL
) :
303 EXPORT_SYMBOL(ib_modify_srq
);
305 int ib_query_srq(struct ib_srq
*srq
,
306 struct ib_srq_attr
*srq_attr
)
308 return srq
->device
->query_srq
?
309 srq
->device
->query_srq(srq
, srq_attr
) : -ENOSYS
;
311 EXPORT_SYMBOL(ib_query_srq
);
313 int ib_destroy_srq(struct ib_srq
*srq
)
316 enum ib_srq_type srq_type
;
317 struct ib_xrcd
*uninitialized_var(xrcd
);
318 struct ib_cq
*uninitialized_var(cq
);
321 if (atomic_read(&srq
->usecnt
))
325 srq_type
= srq
->srq_type
;
326 if (srq_type
== IB_SRQT_XRC
) {
327 xrcd
= srq
->ext
.xrc
.xrcd
;
328 cq
= srq
->ext
.xrc
.cq
;
331 ret
= srq
->device
->destroy_srq(srq
);
333 atomic_dec(&pd
->usecnt
);
334 if (srq_type
== IB_SRQT_XRC
) {
335 atomic_dec(&xrcd
->usecnt
);
336 atomic_dec(&cq
->usecnt
);
342 EXPORT_SYMBOL(ib_destroy_srq
);
346 static void __ib_shared_qp_event_handler(struct ib_event
*event
, void *context
)
348 struct ib_qp
*qp
= context
;
350 list_for_each_entry(event
->element
.qp
, &qp
->open_list
, open_list
)
351 event
->element
.qp
->event_handler(event
, event
->element
.qp
->qp_context
);
354 static void __ib_insert_xrcd_qp(struct ib_xrcd
*xrcd
, struct ib_qp
*qp
)
356 mutex_lock(&xrcd
->tgt_qp_mutex
);
357 list_add(&qp
->xrcd_list
, &xrcd
->tgt_qp_list
);
358 mutex_unlock(&xrcd
->tgt_qp_mutex
);
361 static struct ib_qp
*__ib_open_qp(struct ib_qp
*real_qp
,
362 void (*event_handler
)(struct ib_event
*, void *),
368 qp
= kzalloc(sizeof *qp
, GFP_KERNEL
);
370 return ERR_PTR(-ENOMEM
);
372 qp
->real_qp
= real_qp
;
373 atomic_inc(&real_qp
->usecnt
);
374 qp
->device
= real_qp
->device
;
375 qp
->event_handler
= event_handler
;
376 qp
->qp_context
= qp_context
;
377 qp
->qp_num
= real_qp
->qp_num
;
378 qp
->qp_type
= real_qp
->qp_type
;
380 spin_lock_irqsave(&real_qp
->device
->event_handler_lock
, flags
);
381 list_add(&qp
->open_list
, &real_qp
->open_list
);
382 spin_unlock_irqrestore(&real_qp
->device
->event_handler_lock
, flags
);
387 struct ib_qp
*ib_open_qp(struct ib_xrcd
*xrcd
,
388 struct ib_qp_open_attr
*qp_open_attr
)
390 struct ib_qp
*qp
, *real_qp
;
392 if (qp_open_attr
->qp_type
!= IB_QPT_XRC_TGT
)
393 return ERR_PTR(-EINVAL
);
395 qp
= ERR_PTR(-EINVAL
);
396 mutex_lock(&xrcd
->tgt_qp_mutex
);
397 list_for_each_entry(real_qp
, &xrcd
->tgt_qp_list
, xrcd_list
) {
398 if (real_qp
->qp_num
== qp_open_attr
->qp_num
) {
399 qp
= __ib_open_qp(real_qp
, qp_open_attr
->event_handler
,
400 qp_open_attr
->qp_context
);
404 mutex_unlock(&xrcd
->tgt_qp_mutex
);
407 EXPORT_SYMBOL(ib_open_qp
);
409 struct ib_qp
*ib_create_qp(struct ib_pd
*pd
,
410 struct ib_qp_init_attr
*qp_init_attr
)
412 struct ib_qp
*qp
, *real_qp
;
413 struct ib_device
*device
;
415 device
= pd
? pd
->device
: qp_init_attr
->xrcd
->device
;
416 qp
= device
->create_qp(pd
, qp_init_attr
, NULL
);
422 qp
->qp_type
= qp_init_attr
->qp_type
;
424 atomic_set(&qp
->usecnt
, 0);
425 if (qp_init_attr
->qp_type
== IB_QPT_XRC_TGT
) {
426 qp
->event_handler
= __ib_shared_qp_event_handler
;
429 qp
->send_cq
= qp
->recv_cq
= NULL
;
431 qp
->xrcd
= qp_init_attr
->xrcd
;
432 atomic_inc(&qp_init_attr
->xrcd
->usecnt
);
433 INIT_LIST_HEAD(&qp
->open_list
);
436 qp
= __ib_open_qp(real_qp
, qp_init_attr
->event_handler
,
437 qp_init_attr
->qp_context
);
439 __ib_insert_xrcd_qp(qp_init_attr
->xrcd
, real_qp
);
441 real_qp
->device
->destroy_qp(real_qp
);
443 qp
->event_handler
= qp_init_attr
->event_handler
;
444 qp
->qp_context
= qp_init_attr
->qp_context
;
445 if (qp_init_attr
->qp_type
== IB_QPT_XRC_INI
) {
449 qp
->recv_cq
= qp_init_attr
->recv_cq
;
450 atomic_inc(&qp_init_attr
->recv_cq
->usecnt
);
451 qp
->srq
= qp_init_attr
->srq
;
453 atomic_inc(&qp_init_attr
->srq
->usecnt
);
457 qp
->send_cq
= qp_init_attr
->send_cq
;
460 atomic_inc(&pd
->usecnt
);
461 atomic_inc(&qp_init_attr
->send_cq
->usecnt
);
467 EXPORT_SYMBOL(ib_create_qp
);
469 static const struct {
471 enum ib_qp_attr_mask req_param
[IB_QPT_MAX
];
472 enum ib_qp_attr_mask opt_param
[IB_QPT_MAX
];
473 } qp_state_table
[IB_QPS_ERR
+ 1][IB_QPS_ERR
+ 1] = {
475 [IB_QPS_RESET
] = { .valid
= 1 },
479 [IB_QPT_UD
] = (IB_QP_PKEY_INDEX
|
482 [IB_QPT_RAW_PACKET
] = IB_QP_PORT
,
483 [IB_QPT_UC
] = (IB_QP_PKEY_INDEX
|
486 [IB_QPT_RC
] = (IB_QP_PKEY_INDEX
|
489 [IB_QPT_XRC_INI
] = (IB_QP_PKEY_INDEX
|
492 [IB_QPT_XRC_TGT
] = (IB_QP_PKEY_INDEX
|
495 [IB_QPT_SMI
] = (IB_QP_PKEY_INDEX
|
497 [IB_QPT_GSI
] = (IB_QP_PKEY_INDEX
|
503 [IB_QPS_RESET
] = { .valid
= 1 },
504 [IB_QPS_ERR
] = { .valid
= 1 },
508 [IB_QPT_UD
] = (IB_QP_PKEY_INDEX
|
511 [IB_QPT_UC
] = (IB_QP_PKEY_INDEX
|
514 [IB_QPT_RC
] = (IB_QP_PKEY_INDEX
|
517 [IB_QPT_XRC_INI
] = (IB_QP_PKEY_INDEX
|
520 [IB_QPT_XRC_TGT
] = (IB_QP_PKEY_INDEX
|
523 [IB_QPT_SMI
] = (IB_QP_PKEY_INDEX
|
525 [IB_QPT_GSI
] = (IB_QP_PKEY_INDEX
|
532 [IB_QPT_UC
] = (IB_QP_AV
|
536 [IB_QPT_RC
] = (IB_QP_AV
|
540 IB_QP_MAX_DEST_RD_ATOMIC
|
541 IB_QP_MIN_RNR_TIMER
),
542 [IB_QPT_XRC_INI
] = (IB_QP_AV
|
546 [IB_QPT_XRC_TGT
] = (IB_QP_AV
|
550 IB_QP_MAX_DEST_RD_ATOMIC
|
551 IB_QP_MIN_RNR_TIMER
),
554 [IB_QPT_UD
] = (IB_QP_PKEY_INDEX
|
556 [IB_QPT_UC
] = (IB_QP_ALT_PATH
|
559 [IB_QPT_RC
] = (IB_QP_ALT_PATH
|
562 [IB_QPT_XRC_INI
] = (IB_QP_ALT_PATH
|
565 [IB_QPT_XRC_TGT
] = (IB_QP_ALT_PATH
|
568 [IB_QPT_SMI
] = (IB_QP_PKEY_INDEX
|
570 [IB_QPT_GSI
] = (IB_QP_PKEY_INDEX
|
576 [IB_QPS_RESET
] = { .valid
= 1 },
577 [IB_QPS_ERR
] = { .valid
= 1 },
581 [IB_QPT_UD
] = IB_QP_SQ_PSN
,
582 [IB_QPT_UC
] = IB_QP_SQ_PSN
,
583 [IB_QPT_RC
] = (IB_QP_TIMEOUT
|
587 IB_QP_MAX_QP_RD_ATOMIC
),
588 [IB_QPT_XRC_INI
] = (IB_QP_TIMEOUT
|
592 IB_QP_MAX_QP_RD_ATOMIC
),
593 [IB_QPT_XRC_TGT
] = (IB_QP_TIMEOUT
|
595 [IB_QPT_SMI
] = IB_QP_SQ_PSN
,
596 [IB_QPT_GSI
] = IB_QP_SQ_PSN
,
599 [IB_QPT_UD
] = (IB_QP_CUR_STATE
|
601 [IB_QPT_UC
] = (IB_QP_CUR_STATE
|
604 IB_QP_PATH_MIG_STATE
),
605 [IB_QPT_RC
] = (IB_QP_CUR_STATE
|
608 IB_QP_MIN_RNR_TIMER
|
609 IB_QP_PATH_MIG_STATE
),
610 [IB_QPT_XRC_INI
] = (IB_QP_CUR_STATE
|
613 IB_QP_PATH_MIG_STATE
),
614 [IB_QPT_XRC_TGT
] = (IB_QP_CUR_STATE
|
617 IB_QP_MIN_RNR_TIMER
|
618 IB_QP_PATH_MIG_STATE
),
619 [IB_QPT_SMI
] = (IB_QP_CUR_STATE
|
621 [IB_QPT_GSI
] = (IB_QP_CUR_STATE
|
627 [IB_QPS_RESET
] = { .valid
= 1 },
628 [IB_QPS_ERR
] = { .valid
= 1 },
632 [IB_QPT_UD
] = (IB_QP_CUR_STATE
|
634 [IB_QPT_UC
] = (IB_QP_CUR_STATE
|
637 IB_QP_PATH_MIG_STATE
),
638 [IB_QPT_RC
] = (IB_QP_CUR_STATE
|
641 IB_QP_PATH_MIG_STATE
|
642 IB_QP_MIN_RNR_TIMER
),
643 [IB_QPT_XRC_INI
] = (IB_QP_CUR_STATE
|
646 IB_QP_PATH_MIG_STATE
),
647 [IB_QPT_XRC_TGT
] = (IB_QP_CUR_STATE
|
650 IB_QP_PATH_MIG_STATE
|
651 IB_QP_MIN_RNR_TIMER
),
652 [IB_QPT_SMI
] = (IB_QP_CUR_STATE
|
654 [IB_QPT_GSI
] = (IB_QP_CUR_STATE
|
661 [IB_QPT_UD
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
662 [IB_QPT_UC
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
663 [IB_QPT_RC
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
664 [IB_QPT_XRC_INI
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
665 [IB_QPT_XRC_TGT
] = IB_QP_EN_SQD_ASYNC_NOTIFY
, /* ??? */
666 [IB_QPT_SMI
] = IB_QP_EN_SQD_ASYNC_NOTIFY
,
667 [IB_QPT_GSI
] = IB_QP_EN_SQD_ASYNC_NOTIFY
672 [IB_QPS_RESET
] = { .valid
= 1 },
673 [IB_QPS_ERR
] = { .valid
= 1 },
677 [IB_QPT_UD
] = (IB_QP_CUR_STATE
|
679 [IB_QPT_UC
] = (IB_QP_CUR_STATE
|
682 IB_QP_PATH_MIG_STATE
),
683 [IB_QPT_RC
] = (IB_QP_CUR_STATE
|
686 IB_QP_MIN_RNR_TIMER
|
687 IB_QP_PATH_MIG_STATE
),
688 [IB_QPT_XRC_INI
] = (IB_QP_CUR_STATE
|
691 IB_QP_PATH_MIG_STATE
),
692 [IB_QPT_XRC_TGT
] = (IB_QP_CUR_STATE
|
695 IB_QP_MIN_RNR_TIMER
|
696 IB_QP_PATH_MIG_STATE
),
697 [IB_QPT_SMI
] = (IB_QP_CUR_STATE
|
699 [IB_QPT_GSI
] = (IB_QP_CUR_STATE
|
706 [IB_QPT_UD
] = (IB_QP_PKEY_INDEX
|
708 [IB_QPT_UC
] = (IB_QP_AV
|
712 IB_QP_PATH_MIG_STATE
),
713 [IB_QPT_RC
] = (IB_QP_PORT
|
718 IB_QP_MAX_QP_RD_ATOMIC
|
719 IB_QP_MAX_DEST_RD_ATOMIC
|
723 IB_QP_MIN_RNR_TIMER
|
724 IB_QP_PATH_MIG_STATE
),
725 [IB_QPT_XRC_INI
] = (IB_QP_PORT
|
730 IB_QP_MAX_QP_RD_ATOMIC
|
734 IB_QP_PATH_MIG_STATE
),
735 [IB_QPT_XRC_TGT
] = (IB_QP_PORT
|
738 IB_QP_MAX_DEST_RD_ATOMIC
|
742 IB_QP_MIN_RNR_TIMER
|
743 IB_QP_PATH_MIG_STATE
),
744 [IB_QPT_SMI
] = (IB_QP_PKEY_INDEX
|
746 [IB_QPT_GSI
] = (IB_QP_PKEY_INDEX
|
752 [IB_QPS_RESET
] = { .valid
= 1 },
753 [IB_QPS_ERR
] = { .valid
= 1 },
757 [IB_QPT_UD
] = (IB_QP_CUR_STATE
|
759 [IB_QPT_UC
] = (IB_QP_CUR_STATE
|
761 [IB_QPT_SMI
] = (IB_QP_CUR_STATE
|
763 [IB_QPT_GSI
] = (IB_QP_CUR_STATE
|
769 [IB_QPS_RESET
] = { .valid
= 1 },
770 [IB_QPS_ERR
] = { .valid
= 1 }
774 int ib_modify_qp_is_ok(enum ib_qp_state cur_state
, enum ib_qp_state next_state
,
775 enum ib_qp_type type
, enum ib_qp_attr_mask mask
)
777 enum ib_qp_attr_mask req_param
, opt_param
;
779 if (cur_state
< 0 || cur_state
> IB_QPS_ERR
||
780 next_state
< 0 || next_state
> IB_QPS_ERR
)
783 if (mask
& IB_QP_CUR_STATE
&&
784 cur_state
!= IB_QPS_RTR
&& cur_state
!= IB_QPS_RTS
&&
785 cur_state
!= IB_QPS_SQD
&& cur_state
!= IB_QPS_SQE
)
788 if (!qp_state_table
[cur_state
][next_state
].valid
)
791 req_param
= qp_state_table
[cur_state
][next_state
].req_param
[type
];
792 opt_param
= qp_state_table
[cur_state
][next_state
].opt_param
[type
];
794 if ((mask
& req_param
) != req_param
)
797 if (mask
& ~(req_param
| opt_param
| IB_QP_STATE
))
802 EXPORT_SYMBOL(ib_modify_qp_is_ok
);
804 int ib_modify_qp(struct ib_qp
*qp
,
805 struct ib_qp_attr
*qp_attr
,
808 return qp
->device
->modify_qp(qp
->real_qp
, qp_attr
, qp_attr_mask
, NULL
);
810 EXPORT_SYMBOL(ib_modify_qp
);
812 int ib_query_qp(struct ib_qp
*qp
,
813 struct ib_qp_attr
*qp_attr
,
815 struct ib_qp_init_attr
*qp_init_attr
)
817 return qp
->device
->query_qp
?
818 qp
->device
->query_qp(qp
->real_qp
, qp_attr
, qp_attr_mask
, qp_init_attr
) :
821 EXPORT_SYMBOL(ib_query_qp
);
823 int ib_close_qp(struct ib_qp
*qp
)
825 struct ib_qp
*real_qp
;
828 real_qp
= qp
->real_qp
;
832 spin_lock_irqsave(&real_qp
->device
->event_handler_lock
, flags
);
833 list_del(&qp
->open_list
);
834 spin_unlock_irqrestore(&real_qp
->device
->event_handler_lock
, flags
);
836 atomic_dec(&real_qp
->usecnt
);
841 EXPORT_SYMBOL(ib_close_qp
);
843 static int __ib_destroy_shared_qp(struct ib_qp
*qp
)
845 struct ib_xrcd
*xrcd
;
846 struct ib_qp
*real_qp
;
849 real_qp
= qp
->real_qp
;
850 xrcd
= real_qp
->xrcd
;
852 mutex_lock(&xrcd
->tgt_qp_mutex
);
854 if (atomic_read(&real_qp
->usecnt
) == 0)
855 list_del(&real_qp
->xrcd_list
);
858 mutex_unlock(&xrcd
->tgt_qp_mutex
);
861 ret
= ib_destroy_qp(real_qp
);
863 atomic_dec(&xrcd
->usecnt
);
865 __ib_insert_xrcd_qp(xrcd
, real_qp
);
871 int ib_destroy_qp(struct ib_qp
*qp
)
874 struct ib_cq
*scq
, *rcq
;
878 if (atomic_read(&qp
->usecnt
))
881 if (qp
->real_qp
!= qp
)
882 return __ib_destroy_shared_qp(qp
);
889 ret
= qp
->device
->destroy_qp(qp
);
892 atomic_dec(&pd
->usecnt
);
894 atomic_dec(&scq
->usecnt
);
896 atomic_dec(&rcq
->usecnt
);
898 atomic_dec(&srq
->usecnt
);
903 EXPORT_SYMBOL(ib_destroy_qp
);
905 /* Completion queues */
907 struct ib_cq
*ib_create_cq(struct ib_device
*device
,
908 ib_comp_handler comp_handler
,
909 void (*event_handler
)(struct ib_event
*, void *),
910 void *cq_context
, int cqe
, int comp_vector
)
914 cq
= device
->create_cq(device
, cqe
, comp_vector
, NULL
, NULL
);
919 cq
->comp_handler
= comp_handler
;
920 cq
->event_handler
= event_handler
;
921 cq
->cq_context
= cq_context
;
922 atomic_set(&cq
->usecnt
, 0);
927 EXPORT_SYMBOL(ib_create_cq
);
929 int ib_modify_cq(struct ib_cq
*cq
, u16 cq_count
, u16 cq_period
)
931 return cq
->device
->modify_cq
?
932 cq
->device
->modify_cq(cq
, cq_count
, cq_period
) : -ENOSYS
;
934 EXPORT_SYMBOL(ib_modify_cq
);
936 int ib_destroy_cq(struct ib_cq
*cq
)
938 if (atomic_read(&cq
->usecnt
))
941 return cq
->device
->destroy_cq(cq
);
943 EXPORT_SYMBOL(ib_destroy_cq
);
945 int ib_resize_cq(struct ib_cq
*cq
, int cqe
)
947 return cq
->device
->resize_cq
?
948 cq
->device
->resize_cq(cq
, cqe
, NULL
) : -ENOSYS
;
950 EXPORT_SYMBOL(ib_resize_cq
);
954 struct ib_mr
*ib_get_dma_mr(struct ib_pd
*pd
, int mr_access_flags
)
958 mr
= pd
->device
->get_dma_mr(pd
, mr_access_flags
);
961 mr
->device
= pd
->device
;
964 atomic_inc(&pd
->usecnt
);
965 atomic_set(&mr
->usecnt
, 0);
970 EXPORT_SYMBOL(ib_get_dma_mr
);
972 struct ib_mr
*ib_reg_phys_mr(struct ib_pd
*pd
,
973 struct ib_phys_buf
*phys_buf_array
,
980 if (!pd
->device
->reg_phys_mr
)
981 return ERR_PTR(-ENOSYS
);
983 mr
= pd
->device
->reg_phys_mr(pd
, phys_buf_array
, num_phys_buf
,
984 mr_access_flags
, iova_start
);
987 mr
->device
= pd
->device
;
990 atomic_inc(&pd
->usecnt
);
991 atomic_set(&mr
->usecnt
, 0);
996 EXPORT_SYMBOL(ib_reg_phys_mr
);
998 int ib_rereg_phys_mr(struct ib_mr
*mr
,
1001 struct ib_phys_buf
*phys_buf_array
,
1003 int mr_access_flags
,
1006 struct ib_pd
*old_pd
;
1009 if (!mr
->device
->rereg_phys_mr
)
1012 if (atomic_read(&mr
->usecnt
))
1017 ret
= mr
->device
->rereg_phys_mr(mr
, mr_rereg_mask
, pd
,
1018 phys_buf_array
, num_phys_buf
,
1019 mr_access_flags
, iova_start
);
1021 if (!ret
&& (mr_rereg_mask
& IB_MR_REREG_PD
)) {
1022 atomic_dec(&old_pd
->usecnt
);
1023 atomic_inc(&pd
->usecnt
);
1028 EXPORT_SYMBOL(ib_rereg_phys_mr
);
1030 int ib_query_mr(struct ib_mr
*mr
, struct ib_mr_attr
*mr_attr
)
1032 return mr
->device
->query_mr
?
1033 mr
->device
->query_mr(mr
, mr_attr
) : -ENOSYS
;
1035 EXPORT_SYMBOL(ib_query_mr
);
1037 int ib_dereg_mr(struct ib_mr
*mr
)
1042 if (atomic_read(&mr
->usecnt
))
1046 ret
= mr
->device
->dereg_mr(mr
);
1048 atomic_dec(&pd
->usecnt
);
1052 EXPORT_SYMBOL(ib_dereg_mr
);
1054 struct ib_mr
*ib_alloc_fast_reg_mr(struct ib_pd
*pd
, int max_page_list_len
)
1058 if (!pd
->device
->alloc_fast_reg_mr
)
1059 return ERR_PTR(-ENOSYS
);
1061 mr
= pd
->device
->alloc_fast_reg_mr(pd
, max_page_list_len
);
1064 mr
->device
= pd
->device
;
1067 atomic_inc(&pd
->usecnt
);
1068 atomic_set(&mr
->usecnt
, 0);
1073 EXPORT_SYMBOL(ib_alloc_fast_reg_mr
);
1075 struct ib_fast_reg_page_list
*ib_alloc_fast_reg_page_list(struct ib_device
*device
,
1076 int max_page_list_len
)
1078 struct ib_fast_reg_page_list
*page_list
;
1080 if (!device
->alloc_fast_reg_page_list
)
1081 return ERR_PTR(-ENOSYS
);
1083 page_list
= device
->alloc_fast_reg_page_list(device
, max_page_list_len
);
1085 if (!IS_ERR(page_list
)) {
1086 page_list
->device
= device
;
1087 page_list
->max_page_list_len
= max_page_list_len
;
1092 EXPORT_SYMBOL(ib_alloc_fast_reg_page_list
);
1094 void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list
*page_list
)
1096 page_list
->device
->free_fast_reg_page_list(page_list
);
1098 EXPORT_SYMBOL(ib_free_fast_reg_page_list
);
1100 /* Memory windows */
1102 struct ib_mw
*ib_alloc_mw(struct ib_pd
*pd
)
1106 if (!pd
->device
->alloc_mw
)
1107 return ERR_PTR(-ENOSYS
);
1109 mw
= pd
->device
->alloc_mw(pd
);
1111 mw
->device
= pd
->device
;
1114 atomic_inc(&pd
->usecnt
);
1119 EXPORT_SYMBOL(ib_alloc_mw
);
1121 int ib_dealloc_mw(struct ib_mw
*mw
)
1127 ret
= mw
->device
->dealloc_mw(mw
);
1129 atomic_dec(&pd
->usecnt
);
1133 EXPORT_SYMBOL(ib_dealloc_mw
);
1135 /* "Fast" memory regions */
1137 struct ib_fmr
*ib_alloc_fmr(struct ib_pd
*pd
,
1138 int mr_access_flags
,
1139 struct ib_fmr_attr
*fmr_attr
)
1143 if (!pd
->device
->alloc_fmr
)
1144 return ERR_PTR(-ENOSYS
);
1146 fmr
= pd
->device
->alloc_fmr(pd
, mr_access_flags
, fmr_attr
);
1148 fmr
->device
= pd
->device
;
1150 atomic_inc(&pd
->usecnt
);
1155 EXPORT_SYMBOL(ib_alloc_fmr
);
1157 int ib_unmap_fmr(struct list_head
*fmr_list
)
1161 if (list_empty(fmr_list
))
1164 fmr
= list_entry(fmr_list
->next
, struct ib_fmr
, list
);
1165 return fmr
->device
->unmap_fmr(fmr_list
);
1167 EXPORT_SYMBOL(ib_unmap_fmr
);
1169 int ib_dealloc_fmr(struct ib_fmr
*fmr
)
1175 ret
= fmr
->device
->dealloc_fmr(fmr
);
1177 atomic_dec(&pd
->usecnt
);
1181 EXPORT_SYMBOL(ib_dealloc_fmr
);
1183 /* Multicast groups */
1185 int ib_attach_mcast(struct ib_qp
*qp
, union ib_gid
*gid
, u16 lid
)
1189 if (!qp
->device
->attach_mcast
)
1191 if (gid
->raw
[0] != 0xff || qp
->qp_type
!= IB_QPT_UD
)
1194 ret
= qp
->device
->attach_mcast(qp
, gid
, lid
);
1196 atomic_inc(&qp
->usecnt
);
1199 EXPORT_SYMBOL(ib_attach_mcast
);
1201 int ib_detach_mcast(struct ib_qp
*qp
, union ib_gid
*gid
, u16 lid
)
1205 if (!qp
->device
->detach_mcast
)
1207 if (gid
->raw
[0] != 0xff || qp
->qp_type
!= IB_QPT_UD
)
1210 ret
= qp
->device
->detach_mcast(qp
, gid
, lid
);
1212 atomic_dec(&qp
->usecnt
);
1215 EXPORT_SYMBOL(ib_detach_mcast
);
1217 struct ib_xrcd
*ib_alloc_xrcd(struct ib_device
*device
)
1219 struct ib_xrcd
*xrcd
;
1221 if (!device
->alloc_xrcd
)
1222 return ERR_PTR(-ENOSYS
);
1224 xrcd
= device
->alloc_xrcd(device
, NULL
, NULL
);
1225 if (!IS_ERR(xrcd
)) {
1226 xrcd
->device
= device
;
1228 atomic_set(&xrcd
->usecnt
, 0);
1229 mutex_init(&xrcd
->tgt_qp_mutex
);
1230 INIT_LIST_HEAD(&xrcd
->tgt_qp_list
);
1235 EXPORT_SYMBOL(ib_alloc_xrcd
);
1237 int ib_dealloc_xrcd(struct ib_xrcd
*xrcd
)
1242 if (atomic_read(&xrcd
->usecnt
))
1245 while (!list_empty(&xrcd
->tgt_qp_list
)) {
1246 qp
= list_entry(xrcd
->tgt_qp_list
.next
, struct ib_qp
, xrcd_list
);
1247 ret
= ib_destroy_qp(qp
);
1252 return xrcd
->device
->dealloc_xrcd(xrcd
);
1254 EXPORT_SYMBOL(ib_dealloc_xrcd
);