34 #include <linux/errno.h>
35 #include <linux/slab.h>
37 #include <linux/export.h>
38 #include <linux/bitmap.h>
48 spin_lock(&bitmap->
lock);
51 if (obj >= bitmap->
max) {
57 if (obj < bitmap->
max) {
59 bitmap->
last = (obj + 1);
60 if (bitmap->
last == bitmap->
max)
69 spin_unlock(&bitmap->
lock);
83 if (
likely(cnt == 1 && align == 1))
86 spin_lock(&bitmap->
lock);
89 bitmap->
last, cnt, align - 1);
90 if (obj >= bitmap->
max) {
97 if (obj < bitmap->
max) {
99 if (obj == bitmap->
last) {
101 if (bitmap->
last >= bitmap->
max)
111 spin_unlock(&bitmap->
lock);
118 return bitmap->
avail;
125 spin_lock(&bitmap->
lock);
128 spin_unlock(&bitmap->
lock);
132 u32 reserved_bot,
u32 reserved_top)
140 bitmap->
max = num - reserved_top;
143 bitmap->
avail = num - reserved_top - reserved_bot;
172 if (size <= max_direct) {
201 for (i = 0; i < buf->
nbufs; ++
i) {
218 for (i = 0; i < buf->
nbufs; ++
i)
247 for (i = 0; i < buf->
nbufs; ++
i)
266 pgdir->
bits[0] = pgdir->order0;
267 pgdir->
bits[1] = pgdir->order1;
278 static int mlx4_alloc_db_from_pgdir(
struct mlx4_db_pgdir *pgdir,
284 for (o = order; o <= 1; ++o) {
286 if (i < MLX4_DB_PER_PAGE >> o)
318 if (!mlx4_alloc_db_from_pgdir(pgdir, db, order))
321 pgdir = mlx4_alloc_db_pgdir(&(dev->
pdev->dev));
330 WARN_ON(mlx4_alloc_db_from_pgdir(pgdir, db, order));
369 int size,
int max_direct)