Lines Matching defs:table

258 int mlx4_table_get(struct mlx4_dev *dev, struct mlx4_icm_table *table, u32 obj)
260 u32 i = (obj & (table->num_obj - 1)) /
261 (MLX4_TABLE_CHUNK_SIZE / table->obj_size);
264 mutex_lock(&table->mutex);
266 if (table->icm[i]) {
267 ++table->icm[i]->refcount;
271 table->icm[i] = mlx4_alloc_icm(dev, MLX4_TABLE_CHUNK_SIZE >> PAGE_SHIFT,
272 (table->lowmem ? GFP_KERNEL : GFP_HIGHUSER) |
273 __GFP_NOWARN, table->coherent);
274 if (!table->icm[i]) {
279 if (mlx4_MAP_ICM(dev, table->icm[i], table->virt +
281 mlx4_free_icm(dev, table->icm[i], table->coherent);
282 table->icm[i] = NULL;
287 ++table->icm[i]->refcount;
290 mutex_unlock(&table->mutex);
294 void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, u32 obj)
299 i = (obj & (table->num_obj - 1)) / (MLX4_TABLE_CHUNK_SIZE / table->obj_size);
301 mutex_lock(&table->mutex);
303 if (--table->icm[i]->refcount == 0) {
305 mlx4_UNMAP_ICM(dev, table->virt + offset,
307 mlx4_free_icm(dev, table->icm[i], table->coherent);
308 table->icm[i] = NULL;
311 mutex_unlock(&table->mutex);
314 void *mlx4_table_find(struct mlx4_icm_table *table, u32 obj,
323 if (!table->lowmem)
326 mutex_lock(&table->mutex);
328 idx = (u64) (obj & (table->num_obj - 1)) * table->obj_size;
329 icm = table->icm[idx / MLX4_TABLE_CHUNK_SIZE];
340 if (table->coherent) {
378 mutex_unlock(&table->mutex);
382 int mlx4_table_get_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
385 int inc = MLX4_TABLE_CHUNK_SIZE / table->obj_size;
390 err = mlx4_table_get(dev, table, i);
400 mlx4_table_put(dev, table, i);
406 void mlx4_table_put_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
411 for (i = start; i <= end; i += MLX4_TABLE_CHUNK_SIZE / table->obj_size)
412 mlx4_table_put(dev, table, i);
415 int mlx4_init_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table,
430 table->icm = kvcalloc(num_icm, sizeof(*table->icm), GFP_KERNEL);
431 if (!table->icm)
433 table->virt = virt;
434 table->num_icm = num_icm;
435 table->num_obj = nobj;
436 table->obj_size = obj_size;
437 table->lowmem = use_lowmem;
438 table->coherent = use_coherent;
439 mutex_init(&table->mutex);
448 table->icm[i] = mlx4_alloc_icm(dev, chunk_size >> PAGE_SHIFT,
451 if (!table->icm[i])
453 if (mlx4_MAP_ICM(dev, table->icm[i], virt + i * MLX4_TABLE_CHUNK_SIZE)) {
454 mlx4_free_icm(dev, table->icm[i], use_coherent);
455 table->icm[i] = NULL;
463 ++table->icm[i]->refcount;
470 if (table->icm[i]) {
473 mlx4_free_icm(dev, table->icm[i], use_coherent);
476 kvfree(table->icm);
481 void mlx4_cleanup_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table)
485 for (i = 0; i < table->num_icm; ++i)
486 if (table->icm[i]) {
487 mlx4_UNMAP_ICM(dev, table->virt + i * MLX4_TABLE_CHUNK_SIZE,
489 mlx4_free_icm(dev, table->icm[i], table->coherent);
492 kvfree(table->icm);