예제 #1
0
static void sas_ata_task_done(struct sas_task *task)
{
    struct ata_queued_cmd *qc = task->uldd_task;
    struct domain_device *dev;
    struct task_status_struct *stat = &task->task_status;
    struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf;
    struct sas_ha_struct *sas_ha;
    enum ata_completion_errors ac;
    unsigned long flags;
    struct ata_link *link;

    if (!qc)
        goto qc_already_gone;

    dev = qc->ap->private_data;
    sas_ha = dev->port->ha;
    link = &dev->sata_dev.ap->link;

    spin_lock_irqsave(dev->sata_dev.ap->lock, flags);
    if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD ||
            ((stat->stat == SAM_STAT_CHECK_CONDITION &&
              dev->sata_dev.command_set == ATAPI_COMMAND_SET))) {
        memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE);

        if (!link->sactive) {
            qc->err_mask |= ac_err_mask(dev->sata_dev.fis[2]);
        } else {
            link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.fis[2]);
            if (unlikely(link->eh_info.err_mask))
                qc->flags |= ATA_QCFLAG_FAILED;
        }

        dev->sata_dev.sstatus = resp->sstatus;
        dev->sata_dev.serror = resp->serror;
        dev->sata_dev.scontrol = resp->scontrol;
    } else {
        ac = sas_to_ata_err(stat);
        if (ac) {
            SAS_DPRINTK("%s: SAS error %x\n", __func__,
                        stat->stat);
            /* We saw a SAS error. Send a vague error. */
            if (!link->sactive) {
                qc->err_mask = ac;
            } else {
                link->eh_info.err_mask |= AC_ERR_DEV;
                qc->flags |= ATA_QCFLAG_FAILED;
            }

            dev->sata_dev.fis[3] = 0x04; /* status err */
            dev->sata_dev.fis[2] = ATA_ERR;
        }
    }

    qc->lldd_task = NULL;
    if (qc->scsicmd)
        ASSIGN_SAS_TASK(qc->scsicmd, NULL);
    ata_qc_complete(qc);
    spin_unlock_irqrestore(dev->sata_dev.ap->lock, flags);

    /*
     * If the sas_task has an ata qc, a scsi_cmnd and the aborted
     * flag is set, then we must have come in via the libsas EH
     * functions.  When we exit this function, we need to put the
     * scsi_cmnd on the list of finished errors.  The ata_qc_complete
     * call cleans up the libata side of things but we're protected
     * from the scsi_cmnd going away because the scsi_cmnd is owned
     * by the EH, making libata's call to scsi_done a NOP.
     */
    spin_lock_irqsave(&task->task_state_lock, flags);
    if (qc->scsicmd && task->task_state_flags & SAS_TASK_STATE_ABORTED)
        scsi_eh_finish_cmd(qc->scsicmd, &sas_ha->eh_done_q);
    spin_unlock_irqrestore(&task->task_state_lock, flags);

qc_already_gone:
    list_del_init(&task->list);
    sas_free_task(task);
}
예제 #2
0
static void sas_ata_task_done(struct sas_task *task)
{
	struct ata_queued_cmd *qc = task->uldd_task;
	struct domain_device *dev = task->dev;
	struct task_status_struct *stat = &task->task_status;
	struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf;
	struct sas_ha_struct *sas_ha = dev->port->ha;
	enum ata_completion_errors ac;
	unsigned long flags;
	struct ata_link *link;
	struct ata_port *ap;

	spin_lock_irqsave(&dev->done_lock, flags);
	if (test_bit(SAS_HA_FROZEN, &sas_ha->state))
		task = NULL;
	else if (qc && qc->scsicmd)
		ASSIGN_SAS_TASK(qc->scsicmd, NULL);
	spin_unlock_irqrestore(&dev->done_lock, flags);

	/* check if libsas-eh got to the task before us */
	if (unlikely(!task))
		return;

	if (!qc)
		goto qc_already_gone;

	ap = qc->ap;
	link = &ap->link;

	spin_lock_irqsave(ap->lock, flags);
	/* check if we lost the race with libata/sas_ata_post_internal() */
	if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) {
		spin_unlock_irqrestore(ap->lock, flags);
		if (qc->scsicmd)
			goto qc_already_gone;
		else {
			/* if eh is not involved and the port is frozen then the
			 * ata internal abort process has taken responsibility
			 * for this sas_task
			 */
			return;
		}
	}

	if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD ||
	    ((stat->stat == SAM_STAT_CHECK_CONDITION &&
	      dev->sata_dev.command_set == ATAPI_COMMAND_SET))) {
		memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE);

		if (!link->sactive) {
			qc->err_mask |= ac_err_mask(dev->sata_dev.fis[2]);
		} else {
			link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.fis[2]);
			if (unlikely(link->eh_info.err_mask))
				qc->flags |= ATA_QCFLAG_FAILED;
		}
	} else {
		ac = sas_to_ata_err(stat);
		if (ac) {
			SAS_DPRINTK("%s: SAS error %x\n", __func__,
				    stat->stat);
			/* We saw a SAS error. Send a vague error. */
			if (!link->sactive) {
				qc->err_mask = ac;
			} else {
				link->eh_info.err_mask |= AC_ERR_DEV;
				qc->flags |= ATA_QCFLAG_FAILED;
			}

			dev->sata_dev.fis[3] = 0x04; /* status err */
			dev->sata_dev.fis[2] = ATA_ERR;
		}
	}

	qc->lldd_task = NULL;
	ata_qc_complete(qc);
	spin_unlock_irqrestore(ap->lock, flags);

qc_already_gone:
	list_del_init(&task->list);
	sas_free_task(task);
}
예제 #3
0
static void sas_ata_task_done(struct sas_task *task)
{
	struct ata_queued_cmd *qc = task->uldd_task;
	struct domain_device *dev = task->dev;
	struct task_status_struct *stat = &task->task_status;
	struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf;
	struct sas_ha_struct *sas_ha = dev->port->ha;
	enum ata_completion_errors ac;
	unsigned long flags;
	struct ata_link *link;
	struct ata_port *ap;

	spin_lock_irqsave(&dev->done_lock, flags);
	if (test_bit(SAS_HA_FROZEN, &sas_ha->state))
		task = NULL;
	else if (qc && qc->scsicmd)
		ASSIGN_SAS_TASK(qc->scsicmd, NULL);
	spin_unlock_irqrestore(&dev->done_lock, flags);

	
	if (unlikely(!task))
		return;

	if (!qc)
		goto qc_already_gone;

	ap = qc->ap;
	link = &ap->link;

	spin_lock_irqsave(ap->lock, flags);
	
	if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) {
		spin_unlock_irqrestore(ap->lock, flags);
		if (qc->scsicmd)
			goto qc_already_gone;
		else {
			return;
		}
	}

	if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD ||
	    ((stat->stat == SAM_STAT_CHECK_CONDITION &&
	      dev->sata_dev.command_set == ATAPI_COMMAND_SET))) {
		ata_tf_from_fis(resp->ending_fis, &dev->sata_dev.tf);

		if (!link->sactive) {
			qc->err_mask |= ac_err_mask(dev->sata_dev.tf.command);
		} else {
			link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.tf.command);
			if (unlikely(link->eh_info.err_mask))
				qc->flags |= ATA_QCFLAG_FAILED;
		}
	} else {
		ac = sas_to_ata_err(stat);
		if (ac) {
			SAS_DPRINTK("%s: SAS error %x\n", __func__,
				    stat->stat);
			
			if (!link->sactive) {
				qc->err_mask = ac;
			} else {
				link->eh_info.err_mask |= AC_ERR_DEV;
				qc->flags |= ATA_QCFLAG_FAILED;
			}

			dev->sata_dev.tf.feature = 0x04; 
			dev->sata_dev.tf.command = ATA_ERR;
		}
	}

	qc->lldd_task = NULL;
	ata_qc_complete(qc);
	spin_unlock_irqrestore(ap->lock, flags);

qc_already_gone:
	list_del_init(&task->list);
	sas_free_task(task);
}