Ejemplo n.º 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;

	if (!qc)
		goto qc_already_gone;

	dev = qc->ap->private_data;
	sas_ha = dev->port->ha;

	spin_lock_irqsave(dev->sata_dev.ap->lock, flags);
	if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_GOOD) {
		ata_tf_from_fis(resp->ending_fis, &dev->sata_dev.tf);
		qc->err_mask |= ac_err_mask(dev->sata_dev.tf.command);
		dev->sata_dev.sstatus = resp->sstatus;
		dev->sata_dev.serror = resp->serror;
		dev->sata_dev.scontrol = resp->scontrol;
	} else if (stat->stat != SAM_STAT_GOOD) {
		ac = sas_to_ata_err(stat);
		if (ac) {
			SAS_DPRINTK("%s: SAS error %x\n", __FUNCTION__,
				    stat->stat);
			/* We saw a SAS error. Send a vague error. */
			qc->err_mask = ac;
			dev->sata_dev.tf.feature = 0x04; /* status err */
			dev->sata_dev.tf.command = 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);
}
Ejemplo n.º 2
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);
}