Lines Matching refs:db_tab

447 		      struct mthca_user_db_table *db_tab, int index, u64 uaddr)  in mthca_map_user_db()  argument
459 mutex_lock(&db_tab->mutex); in mthca_map_user_db()
463 if ((db_tab->page[i].refcount >= MTHCA_DB_REC_PER_PAGE) || in mthca_map_user_db()
464 (db_tab->page[i].uvirt && db_tab->page[i].uvirt != uaddr) || in mthca_map_user_db()
470 if (db_tab->page[i].refcount) { in mthca_map_user_db()
471 ++db_tab->page[i].refcount; in mthca_map_user_db()
480 sg_set_page(&db_tab->page[i].mem, pages[0], MTHCA_ICM_PAGE_SIZE, in mthca_map_user_db()
483 ret = dma_map_sg(&dev->pdev->dev, &db_tab->page[i].mem, 1, in mthca_map_user_db()
490 ret = mthca_MAP_ICM_page(dev, sg_dma_address(&db_tab->page[i].mem), in mthca_map_user_db()
493 dma_unmap_sg(&dev->pdev->dev, &db_tab->page[i].mem, 1, in mthca_map_user_db()
495 unpin_user_page(sg_page(&db_tab->page[i].mem)); in mthca_map_user_db()
499 db_tab->page[i].uvirt = uaddr; in mthca_map_user_db()
500 db_tab->page[i].refcount = 1; in mthca_map_user_db()
503 mutex_unlock(&db_tab->mutex); in mthca_map_user_db()
508 struct mthca_user_db_table *db_tab, int index) in mthca_unmap_user_db() argument
518 mutex_lock(&db_tab->mutex); in mthca_unmap_user_db()
520 --db_tab->page[index / MTHCA_DB_REC_PER_PAGE].refcount; in mthca_unmap_user_db()
522 mutex_unlock(&db_tab->mutex); in mthca_unmap_user_db()
527 struct mthca_user_db_table *db_tab; in mthca_init_user_db_tab() local
535 db_tab = kmalloc(struct_size(db_tab, page, npages), GFP_KERNEL); in mthca_init_user_db_tab()
536 if (!db_tab) in mthca_init_user_db_tab()
539 mutex_init(&db_tab->mutex); in mthca_init_user_db_tab()
541 db_tab->page[i].refcount = 0; in mthca_init_user_db_tab()
542 db_tab->page[i].uvirt = 0; in mthca_init_user_db_tab()
543 sg_init_table(&db_tab->page[i].mem, 1); in mthca_init_user_db_tab()
546 return db_tab; in mthca_init_user_db_tab()
550 struct mthca_user_db_table *db_tab) in mthca_cleanup_user_db_tab() argument
558 if (db_tab->page[i].uvirt) { in mthca_cleanup_user_db_tab()
560 dma_unmap_sg(&dev->pdev->dev, &db_tab->page[i].mem, 1, in mthca_cleanup_user_db_tab()
562 unpin_user_page(sg_page(&db_tab->page[i].mem)); in mthca_cleanup_user_db_tab()
566 kfree(db_tab); in mthca_cleanup_user_db_tab()
578 mutex_lock(&dev->db_tab->mutex); in mthca_alloc_db()
585 end = dev->db_tab->max_group1; in mthca_alloc_db()
593 start = dev->db_tab->npages - 1; in mthca_alloc_db()
594 end = dev->db_tab->min_group2; in mthca_alloc_db()
604 if (dev->db_tab->page[i].db_rec && in mthca_alloc_db()
605 !bitmap_full(dev->db_tab->page[i].used, in mthca_alloc_db()
607 page = dev->db_tab->page + i; in mthca_alloc_db()
612 if (!dev->db_tab->page[i].db_rec) { in mthca_alloc_db()
613 page = dev->db_tab->page + i; in mthca_alloc_db()
617 if (dev->db_tab->max_group1 >= dev->db_tab->min_group2 - 1) { in mthca_alloc_db()
623 ++dev->db_tab->max_group1; in mthca_alloc_db()
625 --dev->db_tab->min_group2; in mthca_alloc_db()
627 page = dev->db_tab->page + end; in mthca_alloc_db()
662 mutex_unlock(&dev->db_tab->mutex); in mthca_alloc_db()
675 page = dev->db_tab->page + i; in mthca_free_db()
677 mutex_lock(&dev->db_tab->mutex); in mthca_free_db()
680 if (i >= dev->db_tab->min_group2) in mthca_free_db()
685 i >= dev->db_tab->max_group1 - 1) { in mthca_free_db()
692 if (i == dev->db_tab->max_group1) { in mthca_free_db()
693 --dev->db_tab->max_group1; in mthca_free_db()
696 if (i == dev->db_tab->min_group2) in mthca_free_db()
697 ++dev->db_tab->min_group2; in mthca_free_db()
700 mutex_unlock(&dev->db_tab->mutex); in mthca_free_db()
710 dev->db_tab = kmalloc(sizeof *dev->db_tab, GFP_KERNEL); in mthca_init_db_tab()
711 if (!dev->db_tab) in mthca_init_db_tab()
714 mutex_init(&dev->db_tab->mutex); in mthca_init_db_tab()
716 dev->db_tab->npages = dev->uar_table.uarc_size / MTHCA_ICM_PAGE_SIZE; in mthca_init_db_tab()
717 dev->db_tab->max_group1 = 0; in mthca_init_db_tab()
718 dev->db_tab->min_group2 = dev->db_tab->npages - 1; in mthca_init_db_tab()
720 dev->db_tab->page = kmalloc_array(dev->db_tab->npages, in mthca_init_db_tab()
721 sizeof(*dev->db_tab->page), in mthca_init_db_tab()
723 if (!dev->db_tab->page) { in mthca_init_db_tab()
724 kfree(dev->db_tab); in mthca_init_db_tab()
728 for (i = 0; i < dev->db_tab->npages; ++i) in mthca_init_db_tab()
729 dev->db_tab->page[i].db_rec = NULL; in mthca_init_db_tab()
747 for (i = 0; i < dev->db_tab->npages; ++i) { in mthca_cleanup_db_tab()
748 if (!dev->db_tab->page[i].db_rec) in mthca_cleanup_db_tab()
751 if (!bitmap_empty(dev->db_tab->page[i].used, MTHCA_DB_REC_PER_PAGE)) in mthca_cleanup_db_tab()
757 dev->db_tab->page[i].db_rec, in mthca_cleanup_db_tab()
758 dev->db_tab->page[i].mapping); in mthca_cleanup_db_tab()
761 kfree(dev->db_tab->page); in mthca_cleanup_db_tab()
762 kfree(dev->db_tab); in mthca_cleanup_db_tab()