mr->first_seg = mthca_alloc_mtt(dev, mr->order); 
mr->first_seg = mthca_alloc_mtt(dev, mr->order, &dev->mr_table.mtt_buddy); 
int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,			u64 *buffer_list, int buffer_size_shift,			int list_len, u64 iova, u64 total_size,			u32 access, struct mthca_mr *mr){	void *mailbox;	u64 *mtt_entry;	struct mthca_mpt_entry *mpt_entry;	u32 key;	int err = -ENOMEM;	u8 status;	int i;	might_sleep();	WARN_ON(buffer_size_shift >= 32);	key = mthca_alloc(&dev->mr_table.mpt_alloc);	if (key == -1)		return -ENOMEM;	mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);	if (dev->hca_type == ARBEL_NATIVE) {		err = mthca_table_get(dev, dev->mr_table.mpt_table, key);		if (err)			goto err_out_mpt_free;	}	for (i = MTHCA_MTT_SEG_SIZE / 8, mr->order = 0;	     i < list_len;	     i <<= 1, ++mr->order)		; /* nothing */	mr->first_seg = mthca_alloc_mtt(dev, mr->order);	if (mr->first_seg == -1)		goto err_out_table;	/*	 * If list_len is odd, we add one more dummy entry for	 * firmware efficiency.	 */	mailbox = kmalloc(max(sizeof *mpt_entry,			      (size_t) 8 * (list_len + (list_len & 1) + 2)) +			  MTHCA_CMD_MAILBOX_EXTRA,			  GFP_KERNEL);	if (!mailbox)		goto err_out_free_mtt;	mtt_entry = MAILBOX_ALIGN(mailbox);	mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base +				   mr->first_seg * MTHCA_MTT_SEG_SIZE);	mtt_entry[1] = 0;	for (i = 0; i < list_len; ++i)		mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] |					       MTHCA_MTT_FLAG_PRESENT);	if (list_len & 1) {		mtt_entry[i + 2] = 0;		++list_len;	}	if (0) {		mthca_dbg(dev, "Dumping MPT entry\n");		for (i = 0; i < list_len + 2; ++i)			printk(KERN_ERR "[%2d] %016llx\n",			       i, (unsigned long long) be64_to_cpu(mtt_entry[i]));	}	err = mthca_WRITE_MTT(dev, mtt_entry, list_len, &status);	if (err) {		mthca_warn(dev, "WRITE_MTT failed (%d)\n", err);		goto err_out_mailbox_free;	}	if (status) {		mthca_warn(dev, "WRITE_MTT returned status 0x%02x\n",			   status);		err = -EINVAL;		goto err_out_mailbox_free;	}	mpt_entry = MAILBOX_ALIGN(mailbox);	mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS     |				       MTHCA_MPT_FLAG_MIO         |				       MTHCA_MPT_FLAG_REGION      |				       access);	mpt_entry->page_size = cpu_to_be32(buffer_size_shift - 12);	mpt_entry->key       = cpu_to_be32(key);	mpt_entry->pd        = cpu_to_be32(pd);	mpt_entry->start     = cpu_to_be64(iova);	mpt_entry->length    = cpu_to_be64(total_size);	memset(&mpt_entry->lkey, 0,	       sizeof *mpt_entry - offsetof(struct mthca_mpt_entry, lkey));	mpt_entry->mtt_seg   = cpu_to_be64(dev->mr_table.mtt_base +					   mr->first_seg * MTHCA_MTT_SEG_SIZE);	if (0) {		mthca_dbg(dev, "Dumping MPT entry %08x:\n", mr->ibmr.lkey);		for (i = 0; i < sizeof (struct mthca_mpt_entry) / 4; ++i) {			if (i % 4 == 0)				printk("[%02x] ", i * 4);			printk(" %08x", be32_to_cpu(((u32 *) mpt_entry)[i]));			if ((i + 1) % 4 == 0)				printk("\n");		}	}	err = mthca_SW2HW_MPT(dev, mpt_entry,			      key & (dev->limits.num_mpts - 1),			      &status);	if (err)		mthca_warn(dev, "SW2HW_MPT failed (%d)\n", err);	else if (status) {		mthca_warn(dev, "SW2HW_MPT returned status 0x%02x\n",			   status);		err = -EINVAL;	}	kfree(mailbox);	return err;err_out_mailbox_free:	kfree(mailbox);err_out_free_mtt:	mthca_free_mtt(dev, mr->first_seg, mr->order);err_out_table:	if (dev->hca_type == ARBEL_NATIVE)		mthca_table_put(dev, dev->mr_table.mpt_table, key);err_out_mpt_free:	mthca_free(&dev->mr_table.mpt_alloc, key);	return err;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/9095e208d84c349193fa19245cd5a8bc1a9774b8/mthca_mr.c/clean/drivers/infiniband/hw/mthca/mthca_mr.c