CMD_SP(cmd) = (void *)sp; 
sp->tgt_queue = tq;  sp->lun_queue = lq; lq->io_cnt++; sp->fclun = lq->fclun; 
qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *)){	fc_port_t	*fcport;	os_lun_t	*lq;	os_tgt_t	*tq;	scsi_qla_host_t	*ha, *ha2;	srb_t		*sp;	struct Scsi_Host *host;	unsigned int	b, t, l;	unsigned long	handle;	int		was_empty;	host = cmd->device->host;	ha = (scsi_qla_host_t *) host->hostdata;	was_empty = 1;	cmd->scsi_done = fn;	spin_unlock_irq(ha->host->host_lock);	/*	 * Allocate a command packet from the "sp" pool.  If we cant get back	 * one then let scsi layer come back later.	 */	if ((sp = qla2x00_get_new_sp(ha)) == NULL) {		qla_printk(KERN_WARNING, ha,		    "Couldn't allocate memory for sp - retried.\n");		spin_lock_irq(ha->host->host_lock);		return (1);	}	sp->cmd = cmd;	CMD_SP(cmd) = (void *)sp;	sp->flags = 0;	if (CMD_RESID_LEN(cmd) & SRB_IOCTL) {		/* Need to set sp->flags */		sp->flags |= SRB_IOCTL;		CMD_RESID_LEN(cmd) = 0; /* Clear it since no more use. */	}	sp->fo_retry_cnt = 0;	sp->err_id = 0;	/* Generate LU queue on bus, target, LUN */	b = cmd->device->channel;	t = cmd->device->id;	l = cmd->device->lun;	/*	 * Start Command Timer. Typically it will be 2 seconds less than what	 * is requested by the Host such that we can return the IO before	 * aborts are called.	 */	if ((cmd->timeout_per_command / HZ) > QLA_CMD_TIMER_DELTA)		qla2x00_add_timer_to_cmd(sp,		    (cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);	else		qla2x00_add_timer_to_cmd(sp, cmd->timeout_per_command / HZ);	if (l >= ha->max_luns) {		cmd->result = DID_NO_CONNECT << 16;		sp->err_id = SRB_ERR_PORT;		spin_lock_irq(ha->host->host_lock);		sp_put(ha, sp);		return (0);	}	if ((tq = (os_tgt_t *) TGT_Q(ha, t)) != NULL &&	    (lq = (os_lun_t *) LUN_Q(ha, t, l)) != NULL) {		fcport = lq->fclun->fcport;		ha2 = fcport->ha;	} else {		lq = NULL;		fcport = NULL;		ha2 = ha;	}	/* Set an invalid handle until we issue the command to ISP */	/* then we will set the real handle value.                 */	handle = INVALID_HANDLE;	cmd->host_scribble = (unsigned char *)handle;	/* Bookkeeping information */	sp->r_start = jiffies;		/* Time the request was recieved. */	sp->u_start = 0;	/* Setup device queue pointers. */	sp->tgt_queue = tq;	sp->lun_queue = lq;	/*	 * NOTE : q is NULL	 *	 * 1. When device is added from persistent binding but has not been	 *    discovered yet.The state of loopid == PORT_AVAIL.	 * 2. When device is never found on the bus.(loopid == UNUSED)	 *	 * IF Device Queue is not created, or device is not in a valid state	 * and link down error reporting is enabled, reject IO.	 */	if (fcport == NULL) {		DEBUG3(printk("scsi(%ld:%2d:%2d): port unavailable\n",		    ha->host_no,t,l));		cmd->result = DID_NO_CONNECT << 16;		sp->err_id = SRB_ERR_PORT;		spin_lock_irq(ha->host->host_lock);		sp_put(ha, sp);		return (0);	}	/* Only modify the allowed count if the target is a *non* tape device */	if ((fcport->flags & FCF_TAPE_PRESENT) == 0) {		sp->flags &= ~SRB_TAPE;		if (cmd->allowed < ql2xretrycount) {			cmd->allowed = ql2xretrycount;		}	} else		sp->flags |= SRB_TAPE;	DEBUG5(printk("scsi(%ld:%2d:%2d): (queuecmd) queue sp = %p, "	    "flags=0x%x fo retry=%d, pid=%ld\n",	    ha->host_no, t, l, sp, sp->flags, sp->fo_retry_cnt,	    cmd->serial_number));	DEBUG5(qla2x00_print_scsi_cmd(cmd));	sp->fclun = lq->fclun;	sp->ha = ha2;	if (cmd->sc_data_direction == DMA_BIDIRECTIONAL &&	    cmd->request_bufflen != 0) {		DEBUG2(printk(KERN_WARNING		    "scsi(%ld): Incorrect data direction - transfer "		    "length=%d, direction=%d, pid=%ld, opcode=%x\n",		    ha->host_no, cmd->request_bufflen, cmd->sc_data_direction,		    cmd->serial_number, cmd->cmnd[0]));	}	/* Final pre-check :	 *	 *	Either PORT_DOWN_TIMER OR LINK_DOWN_TIMER Expired.	 */	if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||	    atomic_read(&ha2->loop_state) == LOOP_DEAD) {		/*		 * Add the command to the done-queue for later failover		 * processing.		 */		cmd->result = DID_NO_CONNECT << 16;		if (atomic_read(&ha2->loop_state) == LOOP_DOWN) 			sp->err_id = SRB_ERR_LOOP;		else			sp->err_id = SRB_ERR_PORT;		add_to_done_queue(ha, sp);		qla2x00_done(ha);		spin_lock_irq(ha->host->host_lock);		return (0);	}	if (tq && test_bit(TQF_SUSPENDED, &tq->flags) &&	    (sp->flags & SRB_TAPE) == 0) {		/* If target suspended put incoming I/O in retry_q. */		qla2x00_extend_timeout(sp->cmd, 10);		add_to_scsi_retry_queue(ha, sp);	} else		was_empty = add_to_pending_queue(ha, sp);	if ((IS_QLA2100(ha) || IS_QLA2200(ha)) && ha->flags.online) {		if (ha->response_ring_ptr->signature != RESPONSE_PROCESSED) {			unsigned long flags;			spin_lock_irqsave(&ha->hardware_lock, flags);				qla2x00_process_response_queue(ha);			spin_unlock_irqrestore(&ha->hardware_lock, flags);		}	}	/* We submit to the hardware if:	 *	 *	1) we're on the cpu the irq's arrive on or	 *	2) there are very few io's outstanding.	 *	 * In all other cases we'll let an irq pick up our IO and submit it	 * to the controller to improve affinity.	 */	if (_smp_processor_id() == ha->last_irq_cpu || was_empty)		qla2x00_next(ha);	spin_lock_irq(ha->host->host_lock);	return (0);}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/f4f051ebb40e74ad0ba02d2cb3a6c16b0393472b/qla_os.c/clean/drivers/scsi/qla2xxx/qla_os.c