srq->last	= get_wqe(srq, srq->max - 1); 
int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,		    struct ib_srq_attr *attr, struct mthca_srq *srq){	struct mthca_mailbox *mailbox;	u8 status;	int ds;	int err;	/* Sanity check SRQ size before proceeding */	if (attr->max_wr > 16 << 20 || attr->max_sge > 64)		return -EINVAL;	srq->max      = attr->max_wr;	srq->max_gs   = attr->max_sge;	srq->counter  = 0;	if (mthca_is_memfree(dev))		srq->max = roundup_pow_of_two(srq->max + 1);	ds = min(64UL,		 roundup_pow_of_two(sizeof (struct mthca_next_seg) +				    srq->max_gs * sizeof (struct mthca_data_seg)));	srq->wqe_shift = long_log2(ds);	srq->srqn = mthca_alloc(&dev->srq_table.alloc);	if (srq->srqn == -1)		return -ENOMEM;	if (mthca_is_memfree(dev)) {		err = mthca_table_get(dev, dev->srq_table.table, srq->srqn);		if (err)			goto err_out;		if (!pd->ibpd.uobject) {			srq->db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SRQ,						       srq->srqn, &srq->db);			if (srq->db_index < 0) {				err = -ENOMEM;				goto err_out_icm;			}		}	}	mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);	if (IS_ERR(mailbox)) {		err = PTR_ERR(mailbox);		goto err_out_db;	}	err = mthca_alloc_srq_buf(dev, pd, srq);	if (err)		goto err_out_mailbox;	spin_lock_init(&srq->lock);	atomic_set(&srq->refcount, 1);	init_waitqueue_head(&srq->wait);	if (mthca_is_memfree(dev))		mthca_arbel_init_srq_context(dev, pd, srq, mailbox->buf);	else		mthca_tavor_init_srq_context(dev, pd, srq, mailbox->buf);	err = mthca_SW2HW_SRQ(dev, mailbox, srq->srqn, &status);	if (err) {		mthca_warn(dev, "SW2HW_SRQ failed (%d)\n", err);		goto err_out_free_buf;	}	if (status) {		mthca_warn(dev, "SW2HW_SRQ returned status 0x%02x\n",			   status);		err = -EINVAL;		goto err_out_free_buf;	}	spin_lock_irq(&dev->srq_table.lock);	if (mthca_array_set(&dev->srq_table.srq,			    srq->srqn & (dev->limits.num_srqs - 1),			    srq)) {		spin_unlock_irq(&dev->srq_table.lock);		goto err_out_free_srq;	}	spin_unlock_irq(&dev->srq_table.lock);	mthca_free_mailbox(dev, mailbox);	srq->first_free = 0;	srq->last_free  = srq->max - 1;	srq->last	= get_wqe(srq, srq->max - 1);	return 0;err_out_free_srq:	err = mthca_HW2SW_SRQ(dev, mailbox, srq->srqn, &status);	if (err)		mthca_warn(dev, "HW2SW_SRQ failed (%d)\n", err);	else if (status)		mthca_warn(dev, "HW2SW_SRQ returned status 0x%02x\n", status);err_out_free_buf:	if (!pd->ibpd.uobject)		mthca_free_srq_buf(dev, srq);err_out_mailbox:	mthca_free_mailbox(dev, mailbox);err_out_db:	if (!pd->ibpd.uobject && mthca_is_memfree(dev))		mthca_free_db(dev, MTHCA_DB_TYPE_SRQ, srq->db_index);err_out_icm:	mthca_table_put(dev, dev->srq_table.table, srq->srqn);err_out:	mthca_free(&dev->srq_table.alloc, srq->srqn);	return err;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/6577ae51cf52f5fb0e4a85e673dd7bf2d0074e3e/mthca_srq.c/buggy/drivers/infiniband/hw/mthca/mthca_srq.c