int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db) 
int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db) 
int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db){	int group;	int start, end, dir;	int i, j;	struct mthca_db_page *page;	int ret = 0;	u8 status;	down(&dev->db_tab->mutex);	switch (type) {	case MTHCA_DB_TYPE_CQ_ARM:	case MTHCA_DB_TYPE_SQ:		group = 0;		start = 0;		end   = dev->db_tab->max_group1;		dir   = 1;		break;	case MTHCA_DB_TYPE_CQ_SET_CI:	case MTHCA_DB_TYPE_RQ:	case MTHCA_DB_TYPE_SRQ:		group = 1;		start = dev->db_tab->npages - 1;		end   = dev->db_tab->min_group2;		dir   = -1;		break;	default:		ret = -EINVAL;		goto out;	}	for (i = start; i != end; i += dir)		if (dev->db_tab->page[i].db_rec &&		    !bitmap_full(dev->db_tab->page[i].used,				 MTHCA_DB_REC_PER_PAGE)) {			page = dev->db_tab->page + i;			goto found;		}	if (dev->db_tab->max_group1 >= dev->db_tab->min_group2 - 1) {		ret = -ENOMEM;		goto out;	}	page = dev->db_tab->page + end;	page->db_rec = dma_alloc_coherent(&dev->pdev->dev, 4096,					  &page->mapping, GFP_KERNEL);	if (!page->db_rec) {		ret = -ENOMEM;		goto out;	}	memset(page->db_rec, 0, 4096);	ret = mthca_MAP_ICM_page(dev, page->mapping,				 mthca_uarc_virt(dev, &dev->driver_uar, i), &status);	if (!ret && status)		ret = -EINVAL;	if (ret) {		dma_free_coherent(&dev->pdev->dev, 4096,				  page->db_rec, page->mapping);		goto out;	}	bitmap_zero(page->used, MTHCA_DB_REC_PER_PAGE);	if (group == 0)		++dev->db_tab->max_group1;	else		--dev->db_tab->min_group2;found:	j = find_first_zero_bit(page->used, MTHCA_DB_REC_PER_PAGE);	set_bit(j, page->used);	if (group == 1)		j = MTHCA_DB_REC_PER_PAGE - 1 - j;	ret = i * MTHCA_DB_REC_PER_PAGE + j;	page->db_rec[j] = cpu_to_be64((qn << 8) | (type << 5));	*db = (u32 *) &page->db_rec[j];out:	up(&dev->db_tab->mutex);	return ret;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/97f52eb438be7caebe026421545619d8a0c1398a/mthca_memfree.c/clean/drivers/infiniband/hw/mthca/mthca_memfree.c