Lines Matching refs:table

221 int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int obj)  in mthca_table_get()  argument
223 int i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE; in mthca_table_get()
226 mutex_lock(&table->mutex); in mthca_table_get()
228 if (table->icm[i]) { in mthca_table_get()
229 ++table->icm[i]->refcount; in mthca_table_get()
233 table->icm[i] = mthca_alloc_icm(dev, MTHCA_TABLE_CHUNK_SIZE >> PAGE_SHIFT, in mthca_table_get()
234 (table->lowmem ? GFP_KERNEL : GFP_HIGHUSER) | in mthca_table_get()
235 __GFP_NOWARN, table->coherent); in mthca_table_get()
236 if (!table->icm[i]) { in mthca_table_get()
241 if (mthca_MAP_ICM(dev, table->icm[i], in mthca_table_get()
242 table->virt + i * MTHCA_TABLE_CHUNK_SIZE)) { in mthca_table_get()
243 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_table_get()
244 table->icm[i] = NULL; in mthca_table_get()
249 ++table->icm[i]->refcount; in mthca_table_get()
252 mutex_unlock(&table->mutex); in mthca_table_get()
256 void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj) in mthca_table_put() argument
263 i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE; in mthca_table_put()
265 mutex_lock(&table->mutex); in mthca_table_put()
267 if (--table->icm[i]->refcount == 0) { in mthca_table_put()
268 mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE, in mthca_table_put()
270 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_table_put()
271 table->icm[i] = NULL; in mthca_table_put()
274 mutex_unlock(&table->mutex); in mthca_table_put()
277 void *mthca_table_find(struct mthca_icm_table *table, int obj, dma_addr_t *dma_handle) in mthca_table_find() argument
284 if (!table->lowmem) in mthca_table_find()
287 mutex_lock(&table->mutex); in mthca_table_find()
289 idx = (obj & (table->num_obj - 1)) * table->obj_size; in mthca_table_find()
290 icm = table->icm[idx / MTHCA_TABLE_CHUNK_SIZE]; in mthca_table_find()
316 mutex_unlock(&table->mutex); in mthca_table_find()
320 int mthca_table_get_range(struct mthca_dev *dev, struct mthca_icm_table *table, in mthca_table_get_range() argument
323 int inc = MTHCA_TABLE_CHUNK_SIZE / table->obj_size; in mthca_table_get_range()
327 err = mthca_table_get(dev, table, i); in mthca_table_get_range()
337 mthca_table_put(dev, table, i); in mthca_table_get_range()
343 void mthca_table_put_range(struct mthca_dev *dev, struct mthca_icm_table *table, in mthca_table_put_range() argument
351 for (i = start; i <= end; i += MTHCA_TABLE_CHUNK_SIZE / table->obj_size) in mthca_table_put_range()
352 mthca_table_put(dev, table, i); in mthca_table_put_range()
360 struct mthca_icm_table *table; in mthca_alloc_icm_table() local
369 table = kmalloc(sizeof *table + num_icm * sizeof *table->icm, GFP_KERNEL); in mthca_alloc_icm_table()
370 if (!table) in mthca_alloc_icm_table()
373 table->virt = virt; in mthca_alloc_icm_table()
374 table->num_icm = num_icm; in mthca_alloc_icm_table()
375 table->num_obj = nobj; in mthca_alloc_icm_table()
376 table->obj_size = obj_size; in mthca_alloc_icm_table()
377 table->lowmem = use_lowmem; in mthca_alloc_icm_table()
378 table->coherent = use_coherent; in mthca_alloc_icm_table()
379 mutex_init(&table->mutex); in mthca_alloc_icm_table()
382 table->icm[i] = NULL; in mthca_alloc_icm_table()
389 table->icm[i] = mthca_alloc_icm(dev, chunk_size >> PAGE_SHIFT, in mthca_alloc_icm_table()
392 if (!table->icm[i]) in mthca_alloc_icm_table()
394 if (mthca_MAP_ICM(dev, table->icm[i], in mthca_alloc_icm_table()
396 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_alloc_icm_table()
397 table->icm[i] = NULL; in mthca_alloc_icm_table()
405 ++table->icm[i]->refcount; in mthca_alloc_icm_table()
408 return table; in mthca_alloc_icm_table()
412 if (table->icm[i]) { in mthca_alloc_icm_table()
415 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_alloc_icm_table()
418 kfree(table); in mthca_alloc_icm_table()
423 void mthca_free_icm_table(struct mthca_dev *dev, struct mthca_icm_table *table) in mthca_free_icm_table() argument
427 for (i = 0; i < table->num_icm; ++i) in mthca_free_icm_table()
428 if (table->icm[i]) { in mthca_free_icm_table()
430 table->virt + i * MTHCA_TABLE_CHUNK_SIZE, in mthca_free_icm_table()
432 mthca_free_icm(dev, table->icm[i], table->coherent); in mthca_free_icm_table()
435 kfree(table); in mthca_free_icm_table()