aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/mlx4/alloc.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/net/mlx4/alloc.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'drivers/net/mlx4/alloc.c')
-rw-r--r--drivers/net/mlx4/alloc.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/drivers/net/mlx4/alloc.c b/drivers/net/mlx4/alloc.c
index 8c8515619b8e..116cae334dad 100644
--- a/drivers/net/mlx4/alloc.c
+++ b/drivers/net/mlx4/alloc.c
@@ -62,6 +62,9 @@ u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap)
62 } else 62 } else
63 obj = -1; 63 obj = -1;
64 64
65 if (obj != -1)
66 --bitmap->avail;
67
65 spin_unlock(&bitmap->lock); 68 spin_unlock(&bitmap->lock);
66 69
67 return obj; 70 return obj;
@@ -74,7 +77,7 @@ void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj)
74 77
75u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align) 78u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
76{ 79{
77 u32 obj, i; 80 u32 obj;
78 81
79 if (likely(cnt == 1 && align == 1)) 82 if (likely(cnt == 1 && align == 1))
80 return mlx4_bitmap_alloc(bitmap); 83 return mlx4_bitmap_alloc(bitmap);
@@ -91,8 +94,7 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
91 } 94 }
92 95
93 if (obj < bitmap->max) { 96 if (obj < bitmap->max) {
94 for (i = 0; i < cnt; i++) 97 bitmap_set(bitmap->table, obj, cnt);
95 set_bit(obj + i, bitmap->table);
96 if (obj == bitmap->last) { 98 if (obj == bitmap->last) {
97 bitmap->last = (obj + cnt); 99 bitmap->last = (obj + cnt);
98 if (bitmap->last >= bitmap->max) 100 if (bitmap->last >= bitmap->max)
@@ -102,31 +104,35 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
102 } else 104 } else
103 obj = -1; 105 obj = -1;
104 106
107 if (obj != -1)
108 bitmap->avail -= cnt;
109
105 spin_unlock(&bitmap->lock); 110 spin_unlock(&bitmap->lock);
106 111
107 return obj; 112 return obj;
108} 113}
109 114
110void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt) 115u32 mlx4_bitmap_avail(struct mlx4_bitmap *bitmap)
111{ 116{
112 u32 i; 117 return bitmap->avail;
118}
113 119
120void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt)
121{
114 obj &= bitmap->max + bitmap->reserved_top - 1; 122 obj &= bitmap->max + bitmap->reserved_top - 1;
115 123
116 spin_lock(&bitmap->lock); 124 spin_lock(&bitmap->lock);
117 for (i = 0; i < cnt; i++) 125 bitmap_clear(bitmap->table, obj, cnt);
118 clear_bit(obj + i, bitmap->table);
119 bitmap->last = min(bitmap->last, obj); 126 bitmap->last = min(bitmap->last, obj);
120 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) 127 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top)
121 & bitmap->mask; 128 & bitmap->mask;
129 bitmap->avail += cnt;
122 spin_unlock(&bitmap->lock); 130 spin_unlock(&bitmap->lock);
123} 131}
124 132
125int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, 133int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
126 u32 reserved_bot, u32 reserved_top) 134 u32 reserved_bot, u32 reserved_top)
127{ 135{
128 int i;
129
130 /* num must be a power of 2 */ 136 /* num must be a power of 2 */
131 if (num != roundup_pow_of_two(num)) 137 if (num != roundup_pow_of_two(num))
132 return -EINVAL; 138 return -EINVAL;
@@ -136,14 +142,14 @@ int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
136 bitmap->max = num - reserved_top; 142 bitmap->max = num - reserved_top;
137 bitmap->mask = mask; 143 bitmap->mask = mask;
138 bitmap->reserved_top = reserved_top; 144 bitmap->reserved_top = reserved_top;
145 bitmap->avail = num - reserved_top - reserved_bot;
139 spin_lock_init(&bitmap->lock); 146 spin_lock_init(&bitmap->lock);
140 bitmap->table = kzalloc(BITS_TO_LONGS(bitmap->max) * 147 bitmap->table = kzalloc(BITS_TO_LONGS(bitmap->max) *
141 sizeof (long), GFP_KERNEL); 148 sizeof (long), GFP_KERNEL);
142 if (!bitmap->table) 149 if (!bitmap->table)
143 return -ENOMEM; 150 return -ENOMEM;
144 151
145 for (i = 0; i < reserved_bot; ++i) 152 bitmap_set(bitmap->table, 0, reserved_bot);
146 set_bit(i, bitmap->table);
147 153
148 return 0; 154 return 0;
149} 155}
@@ -185,10 +191,11 @@ int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
185 } else { 191 } else {
186 int i; 192 int i;
187 193
194 buf->direct.buf = NULL;
188 buf->nbufs = (size + PAGE_SIZE - 1) / PAGE_SIZE; 195 buf->nbufs = (size + PAGE_SIZE - 1) / PAGE_SIZE;
189 buf->npages = buf->nbufs; 196 buf->npages = buf->nbufs;
190 buf->page_shift = PAGE_SHIFT; 197 buf->page_shift = PAGE_SHIFT;
191 buf->page_list = kzalloc(buf->nbufs * sizeof *buf->page_list, 198 buf->page_list = kcalloc(buf->nbufs, sizeof(*buf->page_list),
192 GFP_KERNEL); 199 GFP_KERNEL);
193 if (!buf->page_list) 200 if (!buf->page_list)
194 return -ENOMEM; 201 return -ENOMEM;
@@ -236,7 +243,7 @@ void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf)
236 dma_free_coherent(&dev->pdev->dev, size, buf->direct.buf, 243 dma_free_coherent(&dev->pdev->dev, size, buf->direct.buf,
237 buf->direct.map); 244 buf->direct.map);
238 else { 245 else {
239 if (BITS_PER_LONG == 64) 246 if (BITS_PER_LONG == 64 && buf->direct.buf)
240 vunmap(buf->direct.buf); 247 vunmap(buf->direct.buf);
241 248
242 for (i = 0; i < buf->nbufs; ++i) 249 for (i = 0; i < buf->nbufs; ++i)