aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2010-08-27 15:08:13 -0400
committerDavid S. Miller <davem@davemloft.net>2010-08-28 18:37:04 -0400
commite27cd4f8ca9dde7938f4f83ef75b6fae8d46dd5f (patch)
tree7a1ddef5bf95ea0892c9aa7bf9462b52506b6ef5 /drivers/net
parent762c29164e2850d8c5e4c258cef0077b2584d111 (diff)
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: Akinobu 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: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/mlx4/alloc.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/drivers/net/mlx4/alloc.c b/drivers/net/mlx4/alloc.c
index 537997f9443e..8f4bf1f07c11 100644
--- a/drivers/net/mlx4/alloc.c
+++ b/drivers/net/mlx4/alloc.c
@@ -74,7 +74,7 @@ void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj)
74 74
75u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align) 75u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
76{ 76{
77 u32 obj, i; 77 u32 obj;
78 78
79 if (likely(cnt == 1 && align == 1)) 79 if (likely(cnt == 1 && align == 1))
80 return mlx4_bitmap_alloc(bitmap); 80 return mlx4_bitmap_alloc(bitmap);
@@ -91,8 +91,7 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
91 } 91 }
92 92
93 if (obj < bitmap->max) { 93 if (obj < bitmap->max) {
94 for (i = 0; i < cnt; i++) 94 bitmap_set(bitmap->table, obj, cnt);
95 set_bit(obj + i, bitmap->table);
96 if (obj == bitmap->last) { 95 if (obj == bitmap->last) {
97 bitmap->last = (obj + cnt); 96 bitmap->last = (obj + cnt);
98 if (bitmap->last >= bitmap->max) 97 if (bitmap->last >= bitmap->max)
@@ -109,13 +108,10 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
109 108
110void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt) 109void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
111{ 110{
112 u32 i;
113
114 obj &= bitmap->max + bitmap->reserved_top - 1; 111 obj &= bitmap->max + bitmap->reserved_top - 1;
115 112
116 spin_lock(&bitmap->lock); 113 spin_lock(&bitmap->lock);
117 for (i = 0; i < cnt; i++) 114 bitmap_clear(bitmap->table, obj, cnt);
118 clear_bit(obj + i, bitmap->table);
119 bitmap->last = min(bitmap->last, obj); 115 bitmap->last = min(bitmap->last, obj);
120 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) 116 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top)
121 & bitmap->mask; 117 & bitmap->mask;
@@ -125,8 +121,6 @@ void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
125int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, 121int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
126 u32 reserved_bot, u32 reserved_top) 122 u32 reserved_bot, u32 reserved_top)
127{ 123{
128 int i;
129
130 /* num must be a power of 2 */ 124 /* num must be a power of 2 */
131 if (num != roundup_pow_of_two(num)) 125 if (num != roundup_pow_of_two(num))
132 return -EINVAL; 126 return -EINVAL;
@@ -142,8 +136,7 @@ int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
142 if (!bitmap->table) 136 if (!bitmap->table)
143 return -ENOMEM; 137 return -ENOMEM;
144 138
145 for (i = 0; i < reserved_bot; ++i) 139 bitmap_set(bitmap->table, 0, reserved_bot);
146 set_bit(i, bitmap->table);
147 140
148 return 0; 141 return 0;
149} 142}