/* This routine stalls the driver until all outstanding commands are returned. Caller must release the Hardware Lock prior to calling this routine.  */
static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
/* This routine stalls the driver until all outstanding commands are returned. Caller must release the Hardware Lock prior to calling this routine.  */
static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
{
	uint32_t index = 0;
	int stat = QLA_SUCCESS;
	unsigned long flags;
	struct scsi_cmnd *cmd;
	int wait_cnt = WAIT_CMD_TOV;
	while (wait_cnt) {
		spin_lock_irqsave(&ha->hardware_lock, flags);
		for (index = 0; index < ha->host->can_queue; index++) {
			cmd = scsi_host_find_tag(ha->host, index);
			if (cmd != NULL)
				break;
		}
		spin_unlock_irqrestore(&ha->hardware_lock, flags);
		if (index == ha->host->can_queue) {
			break;
		}
		wait_cnt--;
		if (wait_cnt == 0)
			stat = QLA_ERROR;
		else {
			msleep(1000);
		}
	}
	return stat;
}