2 * Copyright (c) 2016 HGST, a Western Digital Company.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 #include <rdma/ib_verbs.h>
14 #include <rdma/mr_pool.h>
16 struct ib_mr
*ib_mr_pool_get(struct ib_qp
*qp
, struct list_head
*list
)
21 spin_lock_irqsave(&qp
->mr_lock
, flags
);
22 mr
= list_first_entry_or_null(list
, struct ib_mr
, qp_entry
);
24 list_del(&mr
->qp_entry
);
27 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
31 EXPORT_SYMBOL(ib_mr_pool_get
);
33 void ib_mr_pool_put(struct ib_qp
*qp
, struct list_head
*list
, struct ib_mr
*mr
)
37 spin_lock_irqsave(&qp
->mr_lock
, flags
);
38 list_add(&mr
->qp_entry
, list
);
40 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
42 EXPORT_SYMBOL(ib_mr_pool_put
);
44 int ib_mr_pool_init(struct ib_qp
*qp
, struct list_head
*list
, int nr
,
45 enum ib_mr_type type
, u32 max_num_sg
)
51 for (i
= 0; i
< nr
; i
++) {
52 mr
= ib_alloc_mr(qp
->pd
, type
, max_num_sg
);
58 spin_lock_irqsave(&qp
->mr_lock
, flags
);
59 list_add_tail(&mr
->qp_entry
, list
);
60 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
65 ib_mr_pool_destroy(qp
, list
);
68 EXPORT_SYMBOL(ib_mr_pool_init
);
70 void ib_mr_pool_destroy(struct ib_qp
*qp
, struct list_head
*list
)
75 spin_lock_irqsave(&qp
->mr_lock
, flags
);
76 while (!list_empty(list
)) {
77 mr
= list_first_entry(list
, struct ib_mr
, qp_entry
);
78 list_del(&mr
->qp_entry
);
80 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
82 spin_lock_irqsave(&qp
->mr_lock
, flags
);
84 spin_unlock_irqrestore(&qp
->mr_lock
, flags
);
86 EXPORT_SYMBOL(ib_mr_pool_destroy
);