if (!list_empty(&ha->done_queue)) qla2x00_done(ha);  /* Process commands in retry queue */ if (test_and_clear_bit(PORT_RESTART_NEEDED, &ha->dpc_flags)) { DEBUG(printk("scsi(%ld): DPC checking retry_q. " "total=%d\n", ha->host_no, ha->retry_q_cnt));  spin_lock_irqsave(&ha->list_lock, flags); dead_cnt = online_cnt = 0; list_for_each_safe(list, templist, &ha->retry_queue) { sp = list_entry(list, srb_t, list); q = sp->lun_queue; DEBUG3(printk("scsi(%ld): pid=%ld sp=%p, " "spflags=0x%x, q_flag= 0x%lx\n", ha->host_no, sp->cmd->serial_number, sp, sp->flags, q->q_flag));  if (q == NULL) continue; fcport = q->fclun->fcport;  if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {  __del_from_retry_queue(ha, sp); sp->cmd->result = DID_NO_CONNECT << 16; if (atomic_read(&fcport->ha->loop_state) == LOOP_DOWN) sp->err_id = SRB_ERR_LOOP; else sp->err_id = SRB_ERR_PORT; sp->cmd->host_scribble = (unsigned char *) NULL; __add_to_done_queue(ha, sp); dead_cnt++; } else if (atomic_read(&fcport->state) != FCS_DEVICE_LOST) {  __del_from_retry_queue(ha, sp); sp->cmd->result = DID_BUS_BUSY << 16; sp->cmd->host_scribble = (unsigned char *) NULL; __add_to_done_queue(ha, sp); online_cnt++; } } /* list_for_each_safe() */ spin_unlock_irqrestore(&ha->list_lock, flags);  DEBUG(printk("scsi(%ld): done processing retry queue " "- dead=%d, online=%d\n ", ha->host_no, dead_cnt, online_cnt)); }  /* Process commands in scsi retry queue */ if (test_and_clear_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags)) { /* * Any requests we want to delay for some period is put * in the scsi retry queue with a delay added. The * timer will schedule a "scsi_restart_needed" every * second as long as there are requests in the scsi * queue. */ DEBUG(printk("scsi(%ld): DPC checking scsi " "retry_q.total=%d\n", ha->host_no, ha->scsi_retry_q_cnt));  online_cnt = 0; spin_lock_irqsave(&ha->list_lock, flags); list_for_each_safe(list, templist, &ha->scsi_retry_queue) {  sp = list_entry(list, srb_t, list); q = sp->lun_queue; tq = sp->tgt_queue;  DEBUG3(printk("scsi(%ld): scsi_retry_q: " "pid=%ld sp=%p, spflags=0x%x, " "q_flag= 0x%lx,q_state=%d\n", ha->host_no, sp->cmd->serial_number, sp, sp->flags, q->q_flag, q->q_state));  /* Was this lun suspended */ if (q->q_state != LUN_STATE_WAIT) { online_cnt++; __del_from_scsi_retry_queue(ha, sp);  if (test_bit(TQF_RETRY_CMDS, &tq->flags)) { qla2x00_extend_timeout(sp->cmd, (sp->cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA); __add_to_pending_queue(ha, sp); retry_cmds++; } else __add_to_retry_queue(ha, sp); }  /* Was this command suspended for N secs */ if (sp->delay != 0) { sp->delay--; if (sp->delay == 0) { online_cnt++; __del_from_scsi_retry_queue( ha, sp); __add_to_retry_queue(ha,sp); } } } spin_unlock_irqrestore(&ha->list_lock, flags);  /* Clear all Target Unsuspended bits */ for (t = 0; t < ha->max_targets; t++) { if ((tq = ha->otgt[t]) == NULL) continue;  if (test_bit(TQF_RETRY_CMDS, &tq->flags)) clear_bit(TQF_RETRY_CMDS, &tq->flags); } if (retry_cmds) qla2x00_next(ha);  DEBUG(if (online_cnt > 0)) DEBUG(printk("scsi(%ld): dpc() found scsi reqs to " "restart= %d\n", ha->host_no, online_cnt)); }  
qla2x00_do_dpc(void *data){	DECLARE_MUTEX_LOCKED(sem);	scsi_qla_host_t *ha;	fc_port_t	*fcport;	os_lun_t        *q;	srb_t           *sp;	uint8_t		status;	unsigned long	flags = 0;	struct list_head *list, *templist;	int	dead_cnt, online_cnt;	int	retry_cmds = 0;	uint16_t	next_loopid;	int t;	os_tgt_t *tq;	ha = (scsi_qla_host_t *)data;	lock_kernel();	daemonize("%s_dpc", ha->host_str);	allow_signal(SIGHUP);	ha->dpc_wait = &sem;	set_user_nice(current, -20);	unlock_kernel();	complete(&ha->dpc_inited);	while (1) {		DEBUG3(printk("qla2x00: DPC handler sleeping\n"));		if (down_interruptible(&sem))			break;		if (ha->dpc_should_die)			break;		DEBUG3(printk("qla2x00: DPC handler waking up\n"));		/* Initialization not yet finished. Don't do anything yet. */		if (!ha->flags.init_done || ha->dpc_active)			continue;		DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no));		ha->dpc_active = 1;		if (!list_empty(&ha->done_queue))			qla2x00_done(ha);		/* Process commands in retry queue */		if (test_and_clear_bit(PORT_RESTART_NEEDED, &ha->dpc_flags)) {			DEBUG(printk("scsi(%ld): DPC checking retry_q. "			    "total=%d\n",			    ha->host_no, ha->retry_q_cnt));			spin_lock_irqsave(&ha->list_lock, flags);			dead_cnt = online_cnt = 0;			list_for_each_safe(list, templist, &ha->retry_queue) {				sp = list_entry(list, srb_t, list);				q = sp->lun_queue;				DEBUG3(printk("scsi(%ld): pid=%ld sp=%p, "				    "spflags=0x%x, q_flag= 0x%lx\n",				    ha->host_no, sp->cmd->serial_number, sp,				    sp->flags, q->q_flag));				if (q == NULL)					continue;				fcport = q->fclun->fcport;				if (atomic_read(&fcport->state) ==				    FCS_DEVICE_DEAD ||				    atomic_read(&fcport->ha->loop_state) == LOOP_DEAD) {					__del_from_retry_queue(ha, sp);					sp->cmd->result = DID_NO_CONNECT << 16;					if (atomic_read(&fcport->ha->loop_state) ==					    LOOP_DOWN) 						sp->err_id = SRB_ERR_LOOP;					else						sp->err_id = SRB_ERR_PORT;					sp->cmd->host_scribble =					    (unsigned char *) NULL;					__add_to_done_queue(ha, sp);					dead_cnt++;				} else if (atomic_read(&fcport->state) !=				    FCS_DEVICE_LOST) {					__del_from_retry_queue(ha, sp);					sp->cmd->result = DID_BUS_BUSY << 16;					sp->cmd->host_scribble =					    (unsigned char *) NULL;					__add_to_done_queue(ha, sp);					online_cnt++;				}			} /* list_for_each_safe() */			spin_unlock_irqrestore(&ha->list_lock, flags);			DEBUG(printk("scsi(%ld): done processing retry queue "			    "- dead=%d, online=%d\n ",			    ha->host_no, dead_cnt, online_cnt));		}		/* Process commands in scsi retry queue */		if (test_and_clear_bit(SCSI_RESTART_NEEDED, &ha->dpc_flags)) {			/*			 * Any requests we want to delay for some period is put			 * in the scsi retry queue with a delay added. The			 * timer will schedule a "scsi_restart_needed" every 			 * second as long as there are requests in the scsi			 * queue. 			 */			DEBUG(printk("scsi(%ld): DPC checking scsi "			    "retry_q.total=%d\n",			    ha->host_no, ha->scsi_retry_q_cnt));			online_cnt = 0;			spin_lock_irqsave(&ha->list_lock, flags);			list_for_each_safe(list, templist,			    &ha->scsi_retry_queue) {				sp = list_entry(list, srb_t, list);				q = sp->lun_queue;				tq = sp->tgt_queue;				DEBUG3(printk("scsi(%ld): scsi_retry_q: "				    "pid=%ld sp=%p, spflags=0x%x, "				    "q_flag= 0x%lx,q_state=%d\n",				    ha->host_no, sp->cmd->serial_number,				    sp, sp->flags, q->q_flag, q->q_state));				/* Was this lun suspended */				if (q->q_state != LUN_STATE_WAIT) {					online_cnt++;					__del_from_scsi_retry_queue(ha, sp);					if (test_bit(TQF_RETRY_CMDS,					    &tq->flags)) {						qla2x00_extend_timeout(sp->cmd,						    (sp->cmd->timeout_per_command / HZ) - QLA_CMD_TIMER_DELTA);						__add_to_pending_queue(ha, sp);						retry_cmds++;					} else						__add_to_retry_queue(ha, sp);				}				/* Was this command suspended for N secs */				if (sp->delay != 0) {					sp->delay--;					if (sp->delay == 0) {						online_cnt++;						__del_from_scsi_retry_queue(						    ha, sp);						__add_to_retry_queue(ha,sp);					}				}			}			spin_unlock_irqrestore(&ha->list_lock, flags);			/* Clear all Target Unsuspended bits */			for (t = 0; t < ha->max_targets; t++) {				if ((tq = ha->otgt[t]) == NULL)					continue;				if (test_bit(TQF_RETRY_CMDS, &tq->flags))					clear_bit(TQF_RETRY_CMDS, &tq->flags);			}			if (retry_cmds)				qla2x00_next(ha);			DEBUG(if (online_cnt > 0))			DEBUG(printk("scsi(%ld): dpc() found scsi reqs to "			    "restart= %d\n",			    ha->host_no, online_cnt));		}		if (ha->flags.mbox_busy) {			if (!list_empty(&ha->done_queue))				qla2x00_done(ha);			ha->dpc_active = 0;			continue;		}		if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {			DEBUG(printk("scsi(%ld): dpc: sched "			    "qla2x00_abort_isp ha = %p\n",			    ha->host_no, ha));			if (!(test_and_set_bit(ABORT_ISP_ACTIVE,			    &ha->dpc_flags))) {				if (qla2x00_abort_isp(ha)) {					/* failed. retry later */					set_bit(ISP_ABORT_NEEDED,					    &ha->dpc_flags);				}				clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);			}			DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",			    ha->host_no));		}		if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) &&		    (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) {			DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",			    ha->host_no));			qla2x00_rst_aen(ha);			clear_bit(RESET_ACTIVE, &ha->dpc_flags);		}		/* Retry each device up to login retry count */		if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) &&		    !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) &&		    atomic_read(&ha->loop_state) != LOOP_DOWN) {			DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",			    ha->host_no));			next_loopid = 0;			list_for_each_entry(fcport, &ha->fcports, list) {				if (fcport->port_type != FCT_TARGET)					continue;				/*				 * If the port is not ONLINE then try to login				 * to it if we haven't run out of retries.				 */				if (atomic_read(&fcport->state) != FCS_ONLINE &&				    fcport->login_retry) {					fcport->login_retry--;					if (fcport->flags & FCF_FABRIC_DEVICE) {						if (fcport->flags &						    FCF_TAPE_PRESENT)							qla2x00_fabric_logout(							    ha,							    fcport->loop_id);						status = qla2x00_fabric_login(						    ha, fcport, &next_loopid);					} else						status =						    qla2x00_local_device_login(							ha, fcport->loop_id);					if (status == QLA_SUCCESS) {						fcport->old_loop_id = fcport->loop_id;						DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",						    ha->host_no, fcport->loop_id));												fcport->port_login_retry_count =						    ha->port_down_retry_count * PORT_RETRY_TIME;						atomic_set(&fcport->state, FCS_ONLINE);						atomic_set(&fcport->port_down_timer,						    ha->port_down_retry_count * PORT_RETRY_TIME);						fcport->login_retry = 0;					} else if (status == 1) {						set_bit(RELOGIN_NEEDED, &ha->dpc_flags);						/* retry the login again */						DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",						    ha->host_no,						    fcport->login_retry, fcport->loop_id));					} else {						fcport->login_retry = 0;					}				}				if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))					break;			}			DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",			    ha->host_no));		}		if ((test_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags)) &&		    atomic_read(&ha->loop_state) != LOOP_DOWN) {			clear_bit(LOGIN_RETRY_NEEDED, &ha->dpc_flags);			DEBUG(printk("scsi(%ld): qla2x00_login_retry()\n",			    ha->host_no));							set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);			DEBUG(printk("scsi(%ld): qla2x00_login_retry - end\n",			    ha->host_no));		}		if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {			DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",			    ha->host_no));			if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,			    &ha->dpc_flags))) {				qla2x00_loop_resync(ha);				clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);			}			DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",			    ha->host_no));		}		if (test_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags)) {			DEBUG(printk("scsi(%ld): qla2x00_restart_queues()\n",			    ha->host_no));			qla2x00_restart_queues(ha, 0);			DEBUG(printk("scsi(%ld): qla2x00_restart_queues - end\n",			    ha->host_no));		}		if (test_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags)) {			DEBUG(printk("scsi(%ld): qla2x00_abort_queues()\n",			    ha->host_no));							qla2x00_abort_queues(ha, 0);			DEBUG(printk("scsi(%ld): qla2x00_abort_queues - end\n",			    ha->host_no));		}		if (test_and_clear_bit(FCPORT_RESCAN_NEEDED, &ha->dpc_flags)) {			DEBUG(printk("scsi(%ld): Rescan flagged fcports...\n",			    ha->host_no));			qla2x00_rescan_fcports(ha);			DEBUG(printk("scsi(%ld): Rescan flagged fcports..."			    "end.\n",			    ha->host_no));		}		if (!ha->interrupts_on)			qla2x00_enable_intrs(ha);		if (!list_empty(&ha->done_queue))			qla2x00_done(ha);		ha->dpc_active = 0;	} /* End of while(1) */	DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no));	/*	 * Make sure that nobody tries to wake us up again.	 */	ha->dpc_wait = NULL;	ha->dpc_active = 0;	complete_and_exit(&ha->dpc_exited, 0);}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/f4f051ebb40e74ad0ba02d2cb3a6c16b0393472b/qla_os.c/clean/drivers/scsi/qla2xxx/qla_os.c