uint32_t        timeout; 
qla2x00_start_scsi(srb_t *sp){	int		ret;	unsigned long   flags;	scsi_qla_host_t	*ha;	fc_lun_t	*fclun;	struct scsi_cmnd *cmd;	uint32_t	*clr_ptr;	uint32_t        index;	uint32_t	handle;	cmd_entry_t	*cmd_pkt;	uint32_t        timeout;	struct scatterlist *sg;	uint16_t	cnt;	uint16_t	req_cnt;	uint16_t	tot_dsds;	device_reg_t __iomem *reg;	char		tag[2];	/* Setup device pointers. */	ret = 0;	fclun = sp->lun_queue->fclun;	ha = fclun->fcport->ha;	reg = ha->iobase;	cmd = sp->cmd;	/* Send marker if required */	if (ha->marker_needed != 0) {		if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) {			return (QLA_FUNCTION_FAILED);		}		ha->marker_needed = 0;	}	/* Acquire ring specific lock */	spin_lock_irqsave(&ha->hardware_lock, flags);	/* Check for room in outstanding command list. */	handle = ha->current_outstanding_cmd;	for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {		handle++;		if (handle == MAX_OUTSTANDING_COMMANDS)			handle = 1;		if (ha->outstanding_cmds[handle] == 0)			break;	}	if (index == MAX_OUTSTANDING_COMMANDS)		goto queuing_error;	/* Calculate the number of request entries needed. */	req_cnt = (ha->calc_request_entries)(cmd->request->nr_hw_segments);	if (ha->req_q_cnt < (req_cnt + 2)) {		cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg));		if (ha->req_ring_index < cnt)			ha->req_q_cnt = cnt - ha->req_ring_index;		else			ha->req_q_cnt = ha->request_q_length -			    (ha->req_ring_index - cnt);	}	if (ha->req_q_cnt < (req_cnt + 2))		goto queuing_error;	/* Finally, we have enough space, now perform mappings. */	tot_dsds = 0;	if (cmd->use_sg) {		sg = (struct scatterlist *) cmd->request_buffer;		tot_dsds = pci_map_sg(ha->pdev, sg, cmd->use_sg,		    cmd->sc_data_direction);		if (tot_dsds == 0)			goto queuing_error;	} else if (cmd->request_bufflen) {	    tot_dsds++;	}	req_cnt = (ha->calc_request_entries)(tot_dsds);	/* Build command packet */	ha->current_outstanding_cmd = handle;	ha->outstanding_cmds[handle] = sp;	sp->ha = ha;	sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle;	ha->req_q_cnt -= req_cnt;	cmd_pkt = (cmd_entry_t *)ha->request_ring_ptr;	cmd_pkt->handle = handle;	/* Zero out remaining portion of packet. */	clr_ptr = (uint32_t *)cmd_pkt + 2;	memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);	cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);	/* Set target ID */	SET_TARGET_ID(ha, cmd_pkt->target, fclun->fcport->loop_id);	/* Set LUN number*/	cmd_pkt->lun = cpu_to_le16(fclun->lun);	/* Update tagged queuing modifier */	cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG);	if (scsi_populate_tag_msg(cmd, tag)) {		switch (tag[0]) {		case MSG_HEAD_TAG:			cmd_pkt->control_flags =			    __constant_cpu_to_le16(CF_HEAD_TAG);			break;		case MSG_ORDERED_TAG:			cmd_pkt->control_flags =			    __constant_cpu_to_le16(CF_ORDERED_TAG);			break;		}	}	/*	 * Allocate at least 5 (+ QLA_CMD_TIMER_DELTA) seconds for RISC timeout.	 */	timeout = (uint32_t)(cmd->timeout_per_command / HZ);	if (timeout > 65535)		cmd_pkt->timeout = __constant_cpu_to_le16(0);	else if (timeout > 25)		cmd_pkt->timeout = cpu_to_le16((uint16_t)timeout -		    (5 + QLA_CMD_TIMER_DELTA));	else		cmd_pkt->timeout = cpu_to_le16((uint16_t)timeout);	/* Load SCSI command packet. */	memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);	cmd_pkt->byte_count = cpu_to_le32((uint32_t)cmd->request_bufflen);	/* Build IOCB segments */	(ha->build_scsi_iocbs)(sp, cmd_pkt, tot_dsds);	/* Set total data segment count. */	cmd_pkt->entry_count = (uint8_t)req_cnt;	wmb();	/* Adjust ring index. */	ha->req_ring_index++;	if (ha->req_ring_index == ha->request_q_length) {		ha->req_ring_index = 0;		ha->request_ring_ptr = ha->request_ring;	} else		ha->request_ring_ptr++;	ha->actthreads++;	ha->total_ios++;	sp->lun_queue->out_cnt++;	sp->flags |= SRB_DMA_VALID;	sp->state = SRB_ACTIVE_STATE;	sp->u_start = jiffies;	/* Set chip new ring index. */	WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), ha->req_ring_index);	RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg));	/* PCI Posting. */	spin_unlock_irqrestore(&ha->hardware_lock, flags);	return (QLA_SUCCESS);queuing_error:	spin_unlock_irqrestore(&ha->hardware_lock, flags);	return (QLA_FUNCTION_FAILED);}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/f4f051ebb40e74ad0ba02d2cb3a6c16b0393472b/qla_iocb.c/buggy/drivers/scsi/qla2xxx/qla_iocb.c