diff options
author | Yevgeny Petrilin <yevgenyp@mellanox.co.il> | 2008-10-22 13:25:29 -0400 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2008-10-22 13:25:29 -0400 |
commit | 93fc9e1bb6507dde945c2eab68c93e1066ac3691 (patch) | |
tree | aa495ec31b7372580f9ec50acead1d170fd70aab /drivers/net/mlx4/alloc.c | |
parent | a3cdcbfa8fb1fccfe48d359da86e99546610c562 (diff) |
mlx4_core: Support multiple pre-reserved QP regions
For ethernet support, we need to reserve QPs for the ethernet and
fibre channel driver. The QPs are reserved at the end of the QP
table. (This way we assure that they are aligned to their size)
We need to consider these reserved ranges in bitmap creation, so we
extend the mlx4 bitmap utility functions to allow reserved ranges at
both the bottom and the top of the range.
Signed-off-by: Yevgeny Petrilin <yevgenyp@mellanox.co.il>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/net/mlx4/alloc.c')
-rw-r--r-- | drivers/net/mlx4/alloc.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/drivers/net/mlx4/alloc.c b/drivers/net/mlx4/alloc.c index e6c0d5bb5dcb..e2bc7ecf162d 100644 --- a/drivers/net/mlx4/alloc.c +++ b/drivers/net/mlx4/alloc.c | |||
@@ -47,13 +47,16 @@ u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap) | |||
47 | 47 | ||
48 | obj = find_next_zero_bit(bitmap->table, bitmap->max, bitmap->last); | 48 | obj = find_next_zero_bit(bitmap->table, bitmap->max, bitmap->last); |
49 | if (obj >= bitmap->max) { | 49 | if (obj >= bitmap->max) { |
50 | bitmap->top = (bitmap->top + bitmap->max) & bitmap->mask; | 50 | bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) |
51 | & bitmap->mask; | ||
51 | obj = find_first_zero_bit(bitmap->table, bitmap->max); | 52 | obj = find_first_zero_bit(bitmap->table, bitmap->max); |
52 | } | 53 | } |
53 | 54 | ||
54 | if (obj < bitmap->max) { | 55 | if (obj < bitmap->max) { |
55 | set_bit(obj, bitmap->table); | 56 | set_bit(obj, bitmap->table); |
56 | bitmap->last = (obj + 1) & (bitmap->max - 1); | 57 | bitmap->last = (obj + 1); |
58 | if (bitmap->last == bitmap->max) | ||
59 | bitmap->last = 0; | ||
57 | obj |= bitmap->top; | 60 | obj |= bitmap->top; |
58 | } else | 61 | } else |
59 | obj = -1; | 62 | obj = -1; |
@@ -109,9 +112,9 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align) | |||
109 | obj = find_aligned_range(bitmap->table, bitmap->last, | 112 | obj = find_aligned_range(bitmap->table, bitmap->last, |
110 | bitmap->max, cnt, align); | 113 | bitmap->max, cnt, align); |
111 | if (obj >= bitmap->max) { | 114 | if (obj >= bitmap->max) { |
112 | bitmap->top = (bitmap->top + bitmap->max) & bitmap->mask; | 115 | bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) |
113 | obj = find_aligned_range(bitmap->table, 0, | 116 | & bitmap->mask; |
114 | bitmap->max, | 117 | obj = find_aligned_range(bitmap->table, 0, bitmap->max, |
115 | cnt, align); | 118 | cnt, align); |
116 | } | 119 | } |
117 | 120 | ||
@@ -136,17 +139,19 @@ void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt) | |||
136 | { | 139 | { |
137 | u32 i; | 140 | u32 i; |
138 | 141 | ||
139 | obj &= bitmap->max - 1; | 142 | obj &= bitmap->max + bitmap->reserved_top - 1; |
140 | 143 | ||
141 | spin_lock(&bitmap->lock); | 144 | spin_lock(&bitmap->lock); |
142 | for (i = 0; i < cnt; i++) | 145 | for (i = 0; i < cnt; i++) |
143 | clear_bit(obj + i, bitmap->table); | 146 | clear_bit(obj + i, bitmap->table); |
144 | bitmap->last = min(bitmap->last, obj); | 147 | bitmap->last = min(bitmap->last, obj); |
145 | bitmap->top = (bitmap->top + bitmap->max) & bitmap->mask; | 148 | bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) |
149 | & bitmap->mask; | ||
146 | spin_unlock(&bitmap->lock); | 150 | spin_unlock(&bitmap->lock); |
147 | } | 151 | } |
148 | 152 | ||
149 | int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, u32 reserved) | 153 | int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, |
154 | u32 reserved_bot, u32 reserved_top) | ||
150 | { | 155 | { |
151 | int i; | 156 | int i; |
152 | 157 | ||
@@ -156,14 +161,16 @@ int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, u32 reserved | |||
156 | 161 | ||
157 | bitmap->last = 0; | 162 | bitmap->last = 0; |
158 | bitmap->top = 0; | 163 | bitmap->top = 0; |
159 | bitmap->max = num; | 164 | bitmap->max = num - reserved_top; |
160 | bitmap->mask = mask; | 165 | bitmap->mask = mask; |
166 | bitmap->reserved_top = reserved_top; | ||
161 | spin_lock_init(&bitmap->lock); | 167 | spin_lock_init(&bitmap->lock); |
162 | bitmap->table = kzalloc(BITS_TO_LONGS(num) * sizeof (long), GFP_KERNEL); | 168 | bitmap->table = kzalloc(BITS_TO_LONGS(bitmap->max) * |
169 | sizeof (long), GFP_KERNEL); | ||
163 | if (!bitmap->table) | 170 | if (!bitmap->table) |
164 | return -ENOMEM; | 171 | return -ENOMEM; |
165 | 172 | ||
166 | for (i = 0; i < reserved; ++i) | 173 | for (i = 0; i < reserved_bot; ++i) |
167 | set_bit(i, bitmap->table); | 174 | set_bit(i, bitmap->table); |
168 | 175 | ||
169 | return 0; | 176 | return 0; |