int ret; 
int ret, length, hdr_len, data_len, rmpp_hdr_size; int rmpp_active = 0; 
static ssize_t ib_umad_write(struct file *filp, const char __user *buf,			     size_t count, loff_t *pos){	struct ib_umad_file *file = filp->private_data;	struct ib_umad_packet *packet;	struct ib_mad_agent *agent;	struct ib_ah_attr ah_attr;	struct ib_sge      gather_list;	struct ib_send_wr *bad_wr, wr = {		.opcode      = IB_WR_SEND,		.sg_list     = &gather_list,		.num_sge     = 1,		.send_flags  = IB_SEND_SIGNALED,	};	u8 method;	u64 *tid;	int ret;	if (count < sizeof (struct ib_user_mad))		return -EINVAL;	packet = kmalloc(sizeof *packet, GFP_KERNEL);	if (!packet)		return -ENOMEM;	if (copy_from_user(&packet->mad, buf, sizeof packet->mad)) {		kfree(packet);		return -EFAULT;	}	if (packet->mad.id < 0 || packet->mad.id >= IB_UMAD_MAX_AGENTS) {		ret = -EINVAL;		goto err;	}	down_read(&file->agent_mutex);	agent = file->agent[packet->mad.id];	if (!agent) {		ret = -EINVAL;		goto err_up;	}	/*	 * If userspace is generating a request that will generate a	 * response, we need to make sure the high-order part of the	 * transaction ID matches the agent being used to send the	 * MAD.	 */	method = ((struct ib_mad_hdr *) packet->mad.data)->method;	if (!(method & IB_MGMT_METHOD_RESP)       &&	    method != IB_MGMT_METHOD_TRAP_REPRESS &&	    method != IB_MGMT_METHOD_SEND) {		tid = &((struct ib_mad_hdr *) packet->mad.data)->tid;		*tid = cpu_to_be64(((u64) agent->hi_tid) << 32 |				   (be64_to_cpup(tid) & 0xffffffff));	}	memset(&ah_attr, 0, sizeof ah_attr);	ah_attr.dlid          = be16_to_cpu(packet->mad.lid);	ah_attr.sl            = packet->mad.sl;	ah_attr.src_path_bits = packet->mad.path_bits;	ah_attr.port_num      = file->port->port_num;	if (packet->mad.grh_present) {		ah_attr.ah_flags = IB_AH_GRH;		memcpy(ah_attr.grh.dgid.raw, packet->mad.gid, 16);		ah_attr.grh.flow_label 	   = packet->mad.flow_label;		ah_attr.grh.hop_limit  	   = packet->mad.hop_limit;		ah_attr.grh.traffic_class  = packet->mad.traffic_class;	}	packet->ah = ib_create_ah(agent->qp->pd, &ah_attr);	if (IS_ERR(packet->ah)) {		ret = PTR_ERR(packet->ah);		goto err_up;	}	gather_list.addr = dma_map_single(agent->device->dma_device,					  packet->mad.data,					  sizeof packet->mad.data,					  DMA_TO_DEVICE);	gather_list.length = sizeof packet->mad.data;	gather_list.lkey   = file->mr[packet->mad.id]->lkey;	pci_unmap_addr_set(packet, mapping, gather_list.addr);	wr.wr.ud.mad_hdr     = (struct ib_mad_hdr *) packet->mad.data;	wr.wr.ud.ah          = packet->ah;	wr.wr.ud.remote_qpn  = be32_to_cpu(packet->mad.qpn);	wr.wr.ud.remote_qkey = be32_to_cpu(packet->mad.qkey);	wr.wr.ud.timeout_ms  = packet->mad.timeout_ms;	wr.wr.ud.retries     = 0;	wr.wr_id            = (unsigned long) packet;	ret = ib_post_send_mad(agent, &wr, &bad_wr);	if (ret) {		dma_unmap_single(agent->device->dma_device,				 pci_unmap_addr(packet, mapping),				 sizeof packet->mad.data,				 DMA_TO_DEVICE);		goto err_up;	}	up_read(&file->agent_mutex);	return sizeof packet->mad;err_up:	up_read(&file->agent_mutex);err:	kfree(packet);	return ret;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/cb183a06b381652b7637fedfa7ef85ec0baf2a1f/user_mad.c/clean/drivers/infiniband/core/user_mad.c