^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Support for SATA devices on Serial Attached SCSI (SAS) controllers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2006 IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Written by: Darrick J. Wong <djwong@us.ibm.com>, IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/async.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <scsi/sas_ata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "sas_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <scsi/scsi_tcq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <scsi/scsi_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <scsi/scsi_transport_sas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "../scsi_sas_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "../scsi_transport_api.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static enum ata_completion_errors sas_to_ata_err(struct task_status_struct *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* Cheesy attempt to translate SAS errors into ATA. Hah! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* transport error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (ts->resp == SAS_TASK_UNDELIVERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return AC_ERR_ATA_BUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* ts->resp == SAS_TASK_COMPLETE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* task delivered, what happened afterwards? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) switch (ts->stat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) case SAS_DEV_NO_RESPONSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return AC_ERR_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) case SAS_INTERRUPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) case SAS_PHY_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) case SAS_NAK_R_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return AC_ERR_ATA_BUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) case SAS_DATA_UNDERRUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Some programs that use the taskfile interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * (smartctl in particular) can cause underrun
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * problems. Ignore these errors, perhaps at our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * peril.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) case SAS_DATA_OVERRUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) case SAS_QUEUE_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) case SAS_DEVICE_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) case SAS_SG_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return AC_ERR_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) case SAS_OPEN_TO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) case SAS_OPEN_REJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) pr_warn("%s: Saw error %d. What to do?\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) __func__, ts->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return AC_ERR_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) case SAM_STAT_CHECK_CONDITION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) case SAS_ABORTED_TASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return AC_ERR_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) case SAS_PROTO_RESPONSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* This means the ending_fis has the error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * value; return 0 here to collect it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static void sas_ata_task_done(struct sas_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct ata_queued_cmd *qc = task->uldd_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct domain_device *dev = task->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct task_status_struct *stat = &task->task_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct sas_ha_struct *sas_ha = dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) enum ata_completion_errors ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct ata_port *ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) spin_lock_irqsave(&dev->done_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (test_bit(SAS_HA_FROZEN, &sas_ha->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) else if (qc && qc->scsicmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ASSIGN_SAS_TASK(qc->scsicmd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) spin_unlock_irqrestore(&dev->done_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* check if libsas-eh got to the task before us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (unlikely(!task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (!qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) goto qc_already_gone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ap = qc->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) link = &ap->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* check if we lost the race with libata/sas_ata_post_internal() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (qc->scsicmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) goto qc_already_gone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* if eh is not involved and the port is frozen then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * ata internal abort process has taken responsibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * for this sas_task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ((stat->stat == SAM_STAT_CHECK_CONDITION &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) dev->sata_dev.class == ATA_DEV_ATAPI))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!link->sactive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) qc->err_mask |= ac_err_mask(dev->sata_dev.fis[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) link->eh_info.err_mask |= ac_err_mask(dev->sata_dev.fis[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (unlikely(link->eh_info.err_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) qc->flags |= ATA_QCFLAG_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ac = sas_to_ata_err(stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) pr_warn("%s: SAS error 0x%x\n", __func__, stat->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* We saw a SAS error. Send a vague error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!link->sactive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) qc->err_mask = ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) link->eh_info.err_mask |= AC_ERR_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) qc->flags |= ATA_QCFLAG_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) dev->sata_dev.fis[3] = 0x04; /* status err */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) dev->sata_dev.fis[2] = ATA_ERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) qc->lldd_task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ata_qc_complete(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) qc_already_gone:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) sas_free_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) __must_hold(ap->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct sas_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int ret = AC_ERR_SYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) unsigned int si, xfer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct ata_port *ap = qc->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct domain_device *dev = ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct sas_ha_struct *sas_ha = dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct Scsi_Host *host = sas_ha->core.shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct sas_internal *i = to_sas_internal(host->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* TODO: we should try to remove that unlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) spin_unlock(ap->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* If the device fell off, no sense in issuing commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (test_bit(SAS_DEV_GONE, &dev->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) task = sas_alloc_task(GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) task->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) task->task_proto = SAS_PROTOCOL_STP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) task->task_done = sas_ata_task_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (qc->tf.command == ATA_CMD_FPDMA_WRITE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) qc->tf.command == ATA_CMD_FPDMA_READ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) qc->tf.command == ATA_CMD_FPDMA_RECV ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) qc->tf.command == ATA_CMD_FPDMA_SEND ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) qc->tf.command == ATA_CMD_NCQ_NON_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Need to zero out the tag libata assigned us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) qc->tf.nsect = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, (u8 *)&task->ata_task.fis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) task->uldd_task = qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (ata_is_atapi(qc->tf.protocol)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) task->total_xfer_len = qc->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) task->num_scatter = qc->n_elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) task->data_dir = qc->dma_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) } else if (!ata_is_data(qc->tf.protocol)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) task->data_dir = DMA_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) for_each_sg(qc->sg, sg, qc->n_elem, si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) xfer += sg_dma_len(sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) task->total_xfer_len = xfer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) task->num_scatter = si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) task->data_dir = qc->dma_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) task->scatter = qc->sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) task->ata_task.retry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) task->task_state_flags = SAS_TASK_STATE_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) qc->lldd_task = task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) task->ata_task.use_ncq = ata_is_ncq(qc->tf.protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) task->ata_task.dma_xfer = ata_is_dma(qc->tf.protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (qc->scsicmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ASSIGN_SAS_TASK(qc->scsicmd, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ret = i->dft->lldd_execute_task(task, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) pr_debug("lldd_execute_task returned: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (qc->scsicmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ASSIGN_SAS_TASK(qc->scsicmd, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) sas_free_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) qc->lldd_task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ret = AC_ERR_SYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) spin_lock(ap->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static bool sas_ata_qc_fill_rtf(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct domain_device *dev = qc->ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) ata_tf_from_fis(dev->sata_dev.fis, &qc->result_tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static struct sas_internal *dev_to_sas_internal(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return to_sas_internal(dev->port->ha->core.shost->transportt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int sas_get_ata_command_set(struct domain_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int sas_get_ata_info(struct domain_device *dev, struct ex_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (phy->attached_tproto & SAS_PROTOCOL_STP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) dev->tproto = phy->attached_tproto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (phy->attached_sata_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) dev->tproto |= SAS_SATA_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (phy->attached_dev_type == SAS_SATA_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) dev->dev_type = SAS_SATA_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) dev->dev_type = SAS_SATA_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) res = sas_get_report_phy_sata(dev->parent, phy->phy_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) &dev->sata_dev.rps_resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) pr_debug("report phy sata to %016llx:%02d returned 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) SAS_ADDR(dev->parent->sas_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) phy->phy_id, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) memcpy(dev->frame_rcvd, &dev->sata_dev.rps_resp.rps.fis,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) sizeof(struct dev_to_host_fis));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) dev->sata_dev.class = sas_get_ata_command_set(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static int sas_ata_clear_pending(struct domain_device *dev, struct ex_phy *phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* we weren't pending, so successfully end the reset sequence now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (dev->dev_type != SAS_SATA_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* hmmm, if this succeeds do we need to repost the domain_device to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * lldd so it can pick up new parameters?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) res = sas_get_ata_info(dev, phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return 0; /* retry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int smp_ata_check_ready(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct domain_device *dev = ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct domain_device *ex_dev = dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct sas_phy *phy = sas_get_local_phy(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct ex_phy *ex_phy = &ex_dev->ex_dev.ex_phy[phy->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) res = sas_ex_phy_discover(ex_dev, phy->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) sas_put_local_phy(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* break the wait early if the expander is unreachable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * otherwise keep polling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (res == -ECOMM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (res != SMP_RESP_FUNC_ACC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) switch (ex_phy->attached_dev_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) case SAS_SATA_PENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) case SAS_END_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (ex_phy->attached_sata_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return sas_ata_clear_pending(dev, ex_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static int local_ata_check_ready(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct domain_device *dev = ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct sas_internal *i = dev_to_sas_internal(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (i->dft->lldd_ata_check_ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return i->dft->lldd_ata_check_ready(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* lldd's that don't implement 'ready' checking get the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * old default behavior of not coordinating reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * recovery with libata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static int sas_ata_printk(const char *level, const struct domain_device *ddev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct ata_port *ap = ddev->sata_dev.ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct device *dev = &ddev->rphy->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) r = printk("%s" SAS_FMT "ata%u: %s: %pV",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) level, ap->print_id, dev_name(dev), &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int sas_ata_hard_reset(struct ata_link *link, unsigned int *class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) unsigned long deadline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) int ret = 0, res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct sas_phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) int (*check_ready)(struct ata_link *link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct domain_device *dev = ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) struct sas_internal *i = dev_to_sas_internal(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) res = i->dft->lldd_I_T_nexus_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (res == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (res != TMF_RESP_FUNC_COMPLETE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) sas_ata_printk(KERN_DEBUG, dev, "Unable to reset ata device?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) phy = sas_get_local_phy(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (scsi_is_sas_phy_local(phy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) check_ready = local_ata_check_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) check_ready = smp_ata_check_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) sas_put_local_phy(phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ret = ata_wait_after_reset(link, deadline, check_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (ret && ret != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) sas_ata_printk(KERN_ERR, dev, "reset failed (errno=%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) *class = dev->sata_dev.class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) ap->cbl = ATA_CBL_SATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * notify the lldd to forget the sas_task for this internal ata command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * that bypasses scsi-eh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static void sas_ata_internal_abort(struct sas_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct sas_internal *si = dev_to_sas_internal(task->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) spin_lock_irqsave(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (task->task_state_flags & SAS_TASK_STATE_ABORTED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) task->task_state_flags & SAS_TASK_STATE_DONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) pr_debug("%s: Task %p already finished.\n", __func__, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) task->task_state_flags |= SAS_TASK_STATE_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) res = si->dft->lldd_abort_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) spin_lock_irqsave(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (task->task_state_flags & SAS_TASK_STATE_DONE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) res == TMF_RESP_FUNC_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /* XXX we are not prepared to deal with ->lldd_abort_task()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * failures. TODO: lldds need to unconditionally forget about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * aborted ata tasks, otherwise we (likely) leak the sas task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) pr_warn("%s: Task %p leaked.\n", __func__, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) task->task_state_flags &= ~SAS_TASK_STATE_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) spin_unlock_irqrestore(&task->task_state_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) sas_free_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static void sas_ata_post_internal(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (qc->flags & ATA_QCFLAG_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) qc->err_mask |= AC_ERR_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (qc->err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * Find the sas_task and kill it. By this point, libata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * has decided to kill the qc and has frozen the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * In this state sas_ata_task_done() will no longer free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * the sas_task, so we need to notify the lldd (via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * ->lldd_abort_task) that the task is dead and free it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * ourselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct sas_task *task = qc->lldd_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) qc->lldd_task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) task->uldd_task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) sas_ata_internal_abort(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static void sas_ata_set_dmamode(struct ata_port *ap, struct ata_device *ata_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct domain_device *dev = ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct sas_internal *i = dev_to_sas_internal(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (i->dft->lldd_ata_set_dmamode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) i->dft->lldd_ata_set_dmamode(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static void sas_ata_sched_eh(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) struct domain_device *dev = ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct sas_ha_struct *ha = dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) spin_lock_irqsave(&ha->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (!test_and_set_bit(SAS_DEV_EH_PENDING, &dev->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ha->eh_active++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) ata_std_sched_eh(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) spin_unlock_irqrestore(&ha->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) void sas_ata_end_eh(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct domain_device *dev = ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct sas_ha_struct *ha = dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) spin_lock_irqsave(&ha->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (test_and_clear_bit(SAS_DEV_EH_PENDING, &dev->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ha->eh_active--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) spin_unlock_irqrestore(&ha->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static int sas_ata_prereset(struct ata_link *link, unsigned long deadline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct domain_device *dev = ap->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct sas_phy *local_phy = sas_get_local_phy(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (!local_phy->enabled || test_bit(SAS_DEV_GONE, &dev->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) res = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) sas_put_local_phy(local_phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static struct ata_port_operations sas_sata_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) .prereset = sas_ata_prereset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .hardreset = sas_ata_hard_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) .error_handler = ata_std_error_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) .post_internal_cmd = sas_ata_post_internal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) .qc_defer = ata_std_qc_defer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) .qc_prep = ata_noop_qc_prep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) .qc_issue = sas_ata_qc_issue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) .qc_fill_rtf = sas_ata_qc_fill_rtf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) .port_start = ata_sas_port_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) .port_stop = ata_sas_port_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) .set_dmamode = sas_ata_set_dmamode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) .sched_eh = sas_ata_sched_eh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) .end_eh = sas_ata_end_eh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) static struct ata_port_info sata_port_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) ATA_FLAG_SAS_HOST | ATA_FLAG_FPDMA_AUX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) .pio_mask = ATA_PIO4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) .mwdma_mask = ATA_MWDMA2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) .udma_mask = ATA_UDMA6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) .port_ops = &sas_sata_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) int sas_ata_init(struct domain_device *found_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct sas_ha_struct *ha = found_dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct Scsi_Host *shost = ha->core.shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct ata_host *ata_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct ata_port *ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) ata_host = kzalloc(sizeof(*ata_host), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) if (!ata_host) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) pr_err("ata host alloc failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) ata_host_init(ata_host, ha->dev, &sas_sata_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) ap = ata_sas_port_alloc(ata_host, &sata_port_info, shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (!ap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) pr_err("ata_sas_port_alloc failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) goto free_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) ap->private_data = found_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) ap->cbl = ATA_CBL_SATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) ap->scsi_host = shost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) rc = ata_sas_port_init(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) goto destroy_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) rc = ata_sas_tport_add(ata_host->dev, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) goto destroy_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) found_dev->sata_dev.ata_host = ata_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) found_dev->sata_dev.ap = ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) destroy_port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) ata_sas_port_destroy(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) free_host:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ata_host_put(ata_host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) void sas_ata_task_abort(struct sas_task *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct ata_queued_cmd *qc = task->uldd_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct completion *waiting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /* Bounce SCSI-initiated commands to the SCSI EH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (qc->scsicmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) blk_abort_request(qc->scsicmd->request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /* Internal command, fake a timeout and complete. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) qc->flags &= ~ATA_QCFLAG_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) qc->flags |= ATA_QCFLAG_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) qc->err_mask |= AC_ERR_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) waiting = qc->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) complete(waiting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static int sas_get_ata_command_set(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct dev_to_host_fis *fis =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) (struct dev_to_host_fis *) dev->frame_rcvd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) struct ata_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (dev->dev_type == SAS_SATA_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return ATA_DEV_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) ata_tf_from_fis((const u8 *)fis, &tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return ata_dev_classify(&tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) void sas_probe_sata(struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct domain_device *dev, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) mutex_lock(&port->ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) list_for_each_entry(dev, &port->disco_list, disco_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (!dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) ata_sas_async_probe(dev->sata_dev.ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) mutex_unlock(&port->ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (!dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) sas_ata_wait_eh(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) /* if libata could not bring the link up, don't surface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (!ata_dev_enabled(sas_to_ata_dev(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) sas_fail_probe(dev, __func__, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static void sas_ata_flush_pm_eh(struct asd_sas_port *port, const char *func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct domain_device *dev, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if (!dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) sas_ata_wait_eh(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* if libata failed to power manage the device, tear it down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (ata_dev_disabled(sas_to_ata_dev(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) sas_fail_probe(dev, func, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) void sas_suspend_sata(struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) struct domain_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) mutex_lock(&port->ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) list_for_each_entry(dev, &port->dev_list, dev_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) struct sata_device *sata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (!dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) sata = &dev->sata_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) if (sata->ap->pm_mesg.event == PM_EVENT_SUSPEND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) ata_sas_port_suspend(sata->ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) mutex_unlock(&port->ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) sas_ata_flush_pm_eh(port, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) void sas_resume_sata(struct asd_sas_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) struct domain_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) mutex_lock(&port->ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) list_for_each_entry(dev, &port->dev_list, dev_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) struct sata_device *sata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (!dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) sata = &dev->sata_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (sata->ap->pm_mesg.event == PM_EVENT_ON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) ata_sas_port_resume(sata->ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) mutex_unlock(&port->ha->disco_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) sas_ata_flush_pm_eh(port, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) * sas_discover_sata - discover an STP/SATA domain device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) * @dev: pointer to struct domain_device of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * Devices directly attached to a HA port, have no parents. All other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * devices do, and should have their "parent" pointer set appropriately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) * before calling this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) int sas_discover_sata(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (dev->dev_type == SAS_SATA_PM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) dev->sata_dev.class = sas_get_ata_command_set(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) sas_fill_in_rphy(dev, dev->rphy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) return sas_notify_lldd_dev_found(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) static void async_sas_ata_eh(void *data, async_cookie_t cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct domain_device *dev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct ata_port *ap = dev->sata_dev.ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct sas_ha_struct *ha = dev->port->ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) sas_ata_printk(KERN_DEBUG, dev, "dev error handler\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) ata_scsi_port_error_handler(ha->core.shost, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) sas_put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) void sas_ata_strategy_handler(struct Scsi_Host *shost)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) ASYNC_DOMAIN_EXCLUSIVE(async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* it's ok to defer revalidation events during ata eh, these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * disks are in one of three states:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) * 1/ present for initial domain discovery, and these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) * resets will cause bcn flutters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * 2/ hot removed, we'll discover that after eh fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * 3/ hot added after initial discovery, lost the race, and need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * to catch the next train.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) sas_disable_revalidation(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) spin_lock_irq(&sas_ha->phy_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) for (i = 0; i < sas_ha->num_phys; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) struct asd_sas_port *port = sas_ha->sas_port[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) struct domain_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) spin_lock(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) list_for_each_entry(dev, &port->dev_list, dev_list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) if (!dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) /* hold a reference over eh since we may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) * racing with final remove once all commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * are completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) kref_get(&dev->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) async_schedule_domain(async_sas_ata_eh, dev, &async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) spin_unlock(&port->dev_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) spin_unlock_irq(&sas_ha->phy_port_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) async_synchronize_full_domain(&async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) sas_enable_revalidation(sas_ha);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) void sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) struct list_head *done_q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct scsi_cmnd *cmd, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct domain_device *eh_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) LIST_HEAD(sata_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) eh_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) list_for_each_entry_safe(cmd, n, work_q, eh_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) struct domain_device *ddev = cmd_to_domain_dev(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (!dev_is_sata(ddev) || TO_SAS_TASK(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) if (eh_dev && eh_dev != ddev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) eh_dev = ddev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) list_move(&cmd->eh_entry, &sata_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (!list_empty(&sata_q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct ata_port *ap = eh_dev->sata_dev.ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) sas_ata_printk(KERN_DEBUG, eh_dev, "cmd error handler\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) ata_scsi_cmd_error_handler(shost, ap, &sata_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * ata's error handler may leave the cmd on the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * so make sure they don't remain on a stack list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * about to go out of scope.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * This looks strange, since the commands are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * now part of no list, but the next error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) * action will be ata_port_error_handler()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) * which takes no list and sweeps them up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) * anyway from the ata tag array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) while (!list_empty(&sata_q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) list_del_init(sata_q.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) } while (eh_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) void sas_ata_schedule_reset(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) struct ata_eh_info *ehi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) struct ata_port *ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (!dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) ap = dev->sata_dev.ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) ehi = &ap->link.eh_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) ehi->err_mask |= AC_ERR_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) ehi->action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) ata_port_schedule_eh(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) EXPORT_SYMBOL_GPL(sas_ata_schedule_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) void sas_ata_wait_eh(struct domain_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct ata_port *ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (!dev_is_sata(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) ap = dev->sata_dev.ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) ata_port_wait_eh(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }