Lines Matching refs:table

222 int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int obj)  in mthca_table_get()  argument
224 int i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE; in mthca_table_get()
227 mutex_lock(&table->mutex); in mthca_table_get()
229 if (table->icm[i]) { in mthca_table_get()
230 ++table->icm[i]->refcount; in mthca_table_get()
234 table->icm[i] = mthca_alloc_icm(dev, MTHCA_TABLE_CHUNK_SIZE >> PAGE_SHIFT, in mthca_table_get()
235 (table->lowmem ? GFP_KERNEL : GFP_HIGHUSER) | in mthca_table_get()
236 __GFP_NOWARN, table->coherent); in mthca_table_get()
237 if (!table->icm[i]) { in mthca_table_get()
242 if (mthca_MAP_ICM(dev, table->icm[i], in mthca_table_get()
243 table->virt + i * MTHCA_TABLE_CHUNK_SIZE)) { in mthca_table_get()
244 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_table_get()
245 table->icm[i] = NULL; in mthca_table_get()
250 ++table->icm[i]->refcount; in mthca_table_get()
253 mutex_unlock(&table->mutex); in mthca_table_get()
257 void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj) in mthca_table_put() argument
264 i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE; in mthca_table_put()
266 mutex_lock(&table->mutex); in mthca_table_put()
268 if (--table->icm[i]->refcount == 0) { in mthca_table_put()
269 mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE, in mthca_table_put()
271 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_table_put()
272 table->icm[i] = NULL; in mthca_table_put()
275 mutex_unlock(&table->mutex); in mthca_table_put()
278 void *mthca_table_find(struct mthca_icm_table *table, int obj, dma_addr_t *dma_handle) in mthca_table_find() argument
285 if (!table->lowmem) in mthca_table_find()
288 mutex_lock(&table->mutex); in mthca_table_find()
290 idx = (obj & (table->num_obj - 1)) * table->obj_size; in mthca_table_find()
291 icm = table->icm[idx / MTHCA_TABLE_CHUNK_SIZE]; in mthca_table_find()
317 mutex_unlock(&table->mutex); in mthca_table_find()
321 int mthca_table_get_range(struct mthca_dev *dev, struct mthca_icm_table *table, in mthca_table_get_range() argument
324 int inc = MTHCA_TABLE_CHUNK_SIZE / table->obj_size; in mthca_table_get_range()
328 err = mthca_table_get(dev, table, i); in mthca_table_get_range()
338 mthca_table_put(dev, table, i); in mthca_table_get_range()
344 void mthca_table_put_range(struct mthca_dev *dev, struct mthca_icm_table *table, in mthca_table_put_range() argument
352 for (i = start; i <= end; i += MTHCA_TABLE_CHUNK_SIZE / table->obj_size) in mthca_table_put_range()
353 mthca_table_put(dev, table, i); in mthca_table_put_range()
361 struct mthca_icm_table *table; in mthca_alloc_icm_table() local
370 table = kmalloc(struct_size(table, icm, num_icm), GFP_KERNEL); in mthca_alloc_icm_table()
371 if (!table) in mthca_alloc_icm_table()
374 table->virt = virt; in mthca_alloc_icm_table()
375 table->num_icm = num_icm; in mthca_alloc_icm_table()
376 table->num_obj = nobj; in mthca_alloc_icm_table()
377 table->obj_size = obj_size; in mthca_alloc_icm_table()
378 table->lowmem = use_lowmem; in mthca_alloc_icm_table()
379 table->coherent = use_coherent; in mthca_alloc_icm_table()
380 mutex_init(&table->mutex); in mthca_alloc_icm_table()
383 table->icm[i] = NULL; in mthca_alloc_icm_table()
390 table->icm[i] = mthca_alloc_icm(dev, chunk_size >> PAGE_SHIFT, in mthca_alloc_icm_table()
393 if (!table->icm[i]) in mthca_alloc_icm_table()
395 if (mthca_MAP_ICM(dev, table->icm[i], in mthca_alloc_icm_table()
397 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_alloc_icm_table()
398 table->icm[i] = NULL; in mthca_alloc_icm_table()
406 ++table->icm[i]->refcount; in mthca_alloc_icm_table()
409 return table; in mthca_alloc_icm_table()
413 if (table->icm[i]) { in mthca_alloc_icm_table()
416 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_alloc_icm_table()
419 kfree(table); in mthca_alloc_icm_table()
424 void mthca_free_icm_table(struct mthca_dev *dev, struct mthca_icm_table *table) in mthca_free_icm_table() argument
428 for (i = 0; i < table->num_icm; ++i) in mthca_free_icm_table()
429 if (table->icm[i]) { in mthca_free_icm_table()
431 table->virt + i * MTHCA_TABLE_CHUNK_SIZE, in mthca_free_icm_table()
433 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_free_icm_table()
436 kfree(table); in mthca_free_icm_table()