|
36 | 36 | #include "hns_roce_device.h"
|
37 | 37 | #include <rdma/ib_umem.h>
|
38 | 38 |
|
39 |
| -int hns_roce_bitmap_alloc(struct hns_roce_bitmap *bitmap, unsigned long *obj) |
40 |
| -{ |
41 |
| - int ret = 0; |
42 |
| - |
43 |
| - spin_lock(&bitmap->lock); |
44 |
| - *obj = find_next_zero_bit(bitmap->table, bitmap->max, bitmap->last); |
45 |
| - if (*obj >= bitmap->max) { |
46 |
| - bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) |
47 |
| - & bitmap->mask; |
48 |
| - *obj = find_first_zero_bit(bitmap->table, bitmap->max); |
49 |
| - } |
50 |
| - |
51 |
| - if (*obj < bitmap->max) { |
52 |
| - set_bit(*obj, bitmap->table); |
53 |
| - bitmap->last = (*obj + 1); |
54 |
| - if (bitmap->last == bitmap->max) |
55 |
| - bitmap->last = 0; |
56 |
| - *obj |= bitmap->top; |
57 |
| - } else { |
58 |
| - ret = -EINVAL; |
59 |
| - } |
60 |
| - |
61 |
| - spin_unlock(&bitmap->lock); |
62 |
| - |
63 |
| - return ret; |
64 |
| -} |
65 |
| - |
66 |
| -void hns_roce_bitmap_free(struct hns_roce_bitmap *bitmap, unsigned long obj) |
67 |
| -{ |
68 |
| - obj &= bitmap->max + bitmap->reserved_top - 1; |
69 |
| - |
70 |
| - spin_lock(&bitmap->lock); |
71 |
| - clear_bit(obj, bitmap->table); |
72 |
| - |
73 |
| - bitmap->last = min(bitmap->last, obj); |
74 |
| - bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) |
75 |
| - & bitmap->mask; |
76 |
| - spin_unlock(&bitmap->lock); |
77 |
| -} |
78 |
| - |
79 |
| -int hns_roce_bitmap_init(struct hns_roce_bitmap *bitmap, u32 num, u32 mask, |
80 |
| - u32 reserved_bot, u32 reserved_top) |
81 |
| -{ |
82 |
| - u32 i; |
83 |
| - |
84 |
| - if (num != roundup_pow_of_two(num)) |
85 |
| - return -EINVAL; |
86 |
| - |
87 |
| - bitmap->last = 0; |
88 |
| - bitmap->top = 0; |
89 |
| - bitmap->max = num - reserved_top; |
90 |
| - bitmap->mask = mask; |
91 |
| - bitmap->reserved_top = reserved_top; |
92 |
| - spin_lock_init(&bitmap->lock); |
93 |
| - bitmap->table = kcalloc(BITS_TO_LONGS(bitmap->max), sizeof(long), |
94 |
| - GFP_KERNEL); |
95 |
| - if (!bitmap->table) |
96 |
| - return -ENOMEM; |
97 |
| - |
98 |
| - for (i = 0; i < reserved_bot; ++i) |
99 |
| - set_bit(i, bitmap->table); |
100 |
| - |
101 |
| - return 0; |
102 |
| -} |
103 |
| - |
104 |
| -void hns_roce_bitmap_cleanup(struct hns_roce_bitmap *bitmap) |
105 |
| -{ |
106 |
| - kfree(bitmap->table); |
107 |
| -} |
108 |
| - |
109 | 39 | void hns_roce_buf_free(struct hns_roce_dev *hr_dev, struct hns_roce_buf *buf)
|
110 | 40 | {
|
111 | 41 | struct hns_roce_buf_list *trunks;
|
|
0 commit comments