Commit e27cd4f8 authored by Akinobu Mita's avatar Akinobu Mita Committed by David S. Miller

mlx4: use bitmap library

Replace loops calling set_bit() and clear_bit() with bitmap_set() and
bitmap_clear().

Unlike loops calling set_bit() and clear_bit(), bitmap_set() and
bitmap_clear() are not atomic. But this is ok.
Because the bitmap operations are protected by bitmap->lock
except for initialization of the bitmap in mlx4_bitmap_init().
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Cc: Roland Dreier <rolandd@cisco.com>
Cc: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 762c2916
...@@ -74,7 +74,7 @@ void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj) ...@@ -74,7 +74,7 @@ void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj)
u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align) u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
{ {
u32 obj, i; u32 obj;
if (likely(cnt == 1 && align == 1)) if (likely(cnt == 1 && align == 1))
return mlx4_bitmap_alloc(bitmap); return mlx4_bitmap_alloc(bitmap);
...@@ -91,8 +91,7 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align) ...@@ -91,8 +91,7 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
} }
if (obj < bitmap->max) { if (obj < bitmap->max) {
for (i = 0; i < cnt; i++) bitmap_set(bitmap->table, obj, cnt);
set_bit(obj + i, bitmap->table);
if (obj == bitmap->last) { if (obj == bitmap->last) {
bitmap->last = (obj + cnt); bitmap->last = (obj + cnt);
if (bitmap->last >= bitmap->max) if (bitmap->last >= bitmap->max)
...@@ -109,13 +108,10 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align) ...@@ -109,13 +108,10 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt) void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
{ {
u32 i;
obj &= bitmap->max + bitmap->reserved_top - 1; obj &= bitmap->max + bitmap->reserved_top - 1;
spin_lock(&bitmap->lock); spin_lock(&bitmap->lock);
for (i = 0; i < cnt; i++) bitmap_clear(bitmap->table, obj, cnt);
clear_bit(obj + i, bitmap->table);
bitmap->last = min(bitmap->last, obj); bitmap->last = min(bitmap->last, obj);
bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top)
& bitmap->mask; & bitmap->mask;
...@@ -125,8 +121,6 @@ void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt) ...@@ -125,8 +121,6 @@ void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
u32 reserved_bot, u32 reserved_top) u32 reserved_bot, u32 reserved_top)
{ {
int i;
/* num must be a power of 2 */ /* num must be a power of 2 */
if (num != roundup_pow_of_two(num)) if (num != roundup_pow_of_two(num))
return -EINVAL; return -EINVAL;
...@@ -142,8 +136,7 @@ int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, ...@@ -142,8 +136,7 @@ int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
if (!bitmap->table) if (!bitmap->table)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < reserved_bot; ++i) bitmap_set(bitmap->table, 0, reserved_bot);
set_bit(i, bitmap->table);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment