1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016 HGST, a Western Digital Company.
5 #include <rdma/ib_verbs.h>
6 #include <rdma/mr_pool.h>
8 struct ib_mr
*ib_mr_pool_get(struct ib_qp
*qp
, struct list_head
*list
)
13 spin_lock_irqsave(&qp
->mr_lock
, flags
);
14 mr
= list_first_entry_or_null(list
, struct ib_mr
, qp_entry
);
16 list_del(&mr
->qp_entry
);
19 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
23 EXPORT_SYMBOL(ib_mr_pool_get
);
25 void ib_mr_pool_put(struct ib_qp
*qp
, struct list_head
*list
, struct ib_mr
*mr
)
29 spin_lock_irqsave(&qp
->mr_lock
, flags
);
30 list_add(&mr
->qp_entry
, list
);
32 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
34 EXPORT_SYMBOL(ib_mr_pool_put
);
36 int ib_mr_pool_init(struct ib_qp
*qp
, struct list_head
*list
, int nr
,
37 enum ib_mr_type type
, u32 max_num_sg
, u32 max_num_meta_sg
)
43 for (i
= 0; i
< nr
; i
++) {
44 if (type
== IB_MR_TYPE_INTEGRITY
)
45 mr
= ib_alloc_mr_integrity(qp
->pd
, max_num_sg
,
48 mr
= ib_alloc_mr(qp
->pd
, type
, max_num_sg
);
54 spin_lock_irqsave(&qp
->mr_lock
, flags
);
55 list_add_tail(&mr
->qp_entry
, list
);
56 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
61 ib_mr_pool_destroy(qp
, list
);
64 EXPORT_SYMBOL(ib_mr_pool_init
);
66 void ib_mr_pool_destroy(struct ib_qp
*qp
, struct list_head
*list
)
71 spin_lock_irqsave(&qp
->mr_lock
, flags
);
72 while (!list_empty(list
)) {
73 mr
= list_first_entry(list
, struct ib_mr
, qp_entry
);
74 list_del(&mr
->qp_entry
);
76 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
78 spin_lock_irqsave(&qp
->mr_lock
, flags
);
80 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
82 EXPORT_SYMBOL(ib_mr_pool_destroy
);