// SPDX-License-Identifier: GPL-2.0-or-later /* * Support for SATA devices on Serial Attached SCSI (SAS) controllers * * Copyright (C) 2006 IBM Corporation * * Written by: Darrick J. Wong <djwong@us.ibm.com>, IBM Corporation
*/
staticenum ata_completion_errors sas_to_ata_err(struct task_status_struct *ts)
{ /* Cheesy attempt to translate SAS errors into ATA. Hah! */
/* transport error */ if (ts->resp == SAS_TASK_UNDELIVERED) return AC_ERR_ATA_BUS;
/* ts->resp == SAS_TASK_COMPLETE */ /* task delivered, what happened afterwards? */ switch (ts->stat) { case SAS_DEV_NO_RESPONSE: return AC_ERR_TIMEOUT; case SAS_INTERRUPTED: case SAS_PHY_DOWN: case SAS_NAK_R_ERR: return AC_ERR_ATA_BUS; case SAS_DATA_UNDERRUN: /* * Some programs that use the taskfile interface * (smartctl in particular) can cause underrun * problems. Ignore these errors, perhaps at our * peril.
*/ return 0; case SAS_DATA_OVERRUN: case SAS_QUEUE_FULL: case SAS_DEVICE_UNKNOWN: case SAS_OPEN_TO: case SAS_OPEN_REJECT:
pr_warn("%s: Saw error %d. What to do?\n",
__func__, ts->stat); return AC_ERR_OTHER; case SAM_STAT_CHECK_CONDITION: case SAS_ABORTED_TASK: return AC_ERR_DEV; case SAS_PROTO_RESPONSE: /* This means the ending_fis has the error * value; return 0 here to collect it
*/ return 0; default: return 0;
}
}
/* 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(ata_port_is_frozen(ap))) {
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 (dev->dev_type == SAS_SATA_PENDING) return ATA_DEV_UNKNOWN;
ata_tf_from_fis(dev->frame_rcvd, &tf);
return ata_dev_classify(&tf);
}
staticint sas_get_ata_info(struct domain_device *dev, struct ex_phy *phy)
{ if (phy->attached_tproto & SAS_PROTOCOL_STP)
dev->tproto = phy->attached_tproto; if (phy->attached_sata_dev)
dev->tproto |= SAS_SATA_DEV;
if (phy->attached_dev_type == SAS_SATA_PENDING)
dev->dev_type = SAS_SATA_PENDING; else { int res;
dev->dev_type = SAS_SATA_DEV;
res = sas_get_report_phy_sata(dev->parent, phy->phy_id,
&dev->sata_dev.rps_resp); if (res) {
pr_debug("report phy sata to %016llx:%02d returned 0x%x\n",
SAS_ADDR(dev->parent->sas_addr),
phy->phy_id, res); return res;
}
memcpy(dev->frame_rcvd, &dev->sata_dev.rps_resp.rps.fis, sizeof(struct dev_to_host_fis));
dev->sata_dev.class = sas_get_ata_command_set(dev);
} return 0;
}
staticint sas_ata_clear_pending(struct domain_device *dev, struct ex_phy *phy)
{ int res;
/* we weren't pending, so successfully end the reset sequence now */ if (dev->dev_type != SAS_SATA_PENDING) return 1;
/* hmmm, if this succeeds do we need to repost the domain_device to the * lldd so it can pick up new parameters?
*/
res = sas_get_ata_info(dev, phy); if (res) return 0; /* retry */ else return 1;
}
int smp_ata_check_ready_type(struct ata_link *link)
{ struct domain_device *dev = link->ap->private_data; struct sas_phy *phy = sas_get_local_phy(dev); struct domain_device *ex_dev = dev->parent; enum sas_device_type type = SAS_PHY_UNUSED;
u8 sas_addr[SAS_ADDR_SIZE]; int res;
res = sas_get_phy_attached_dev(ex_dev, phy->number, sas_addr, &type);
sas_put_local_phy(phy); if (res) return res;
switch (type) { case SAS_SATA_PENDING: return 0; case SAS_END_DEVICE: return 1; default: return -ENODEV;
}
}
EXPORT_SYMBOL_GPL(smp_ata_check_ready_type);
res = sas_ex_phy_discover(ex_dev, phy->number);
sas_put_local_phy(phy);
/* break the wait early if the expander is unreachable, * otherwise keep polling
*/ if (res == -ECOMM) return res; if (res != SMP_RESP_FUNC_ACC) return 0;
switch (ex_phy->attached_dev_type) { case SAS_SATA_PENDING: return 0; case SAS_END_DEVICE: if (ex_phy->attached_sata_dev) return sas_ata_clear_pending(dev, ex_phy);
fallthrough; default: return -ENODEV;
}
}
if (i->dft->lldd_ata_check_ready) return i->dft->lldd_ata_check_ready(dev); else { /* lldd's that don't implement 'ready' checking get the * old default behavior of not coordinating reset * recovery with libata
*/ return 1;
}
}
ret = i->dft->lldd_I_T_nexus_reset(dev); if (ret == -ENODEV) return ret;
if (ret != TMF_RESP_FUNC_COMPLETE)
sas_ata_printk(KERN_DEBUG, dev, "Unable to reset ata device?\n");
ret = sas_ata_wait_after_reset(dev, deadline);
*class = dev->sata_dev.class;
ap->cbl = ATA_CBL_SATA; return ret;
}
/* * notify the lldd to forget the sas_task for this internal ata command * that bypasses scsi-eh
*/ staticvoid sas_ata_internal_abort(struct sas_task *task)
{ struct sas_internal *si = dev_to_sas_internal(task->dev); unsignedlong flags; int res;
spin_lock_irqsave(&task->task_state_lock, flags); if (task->task_state_flags & SAS_TASK_STATE_DONE ||
res == TMF_RESP_FUNC_COMPLETE) {
spin_unlock_irqrestore(&task->task_state_lock, flags); goto out;
}
/* XXX we are not prepared to deal with ->lldd_abort_task() * failures. TODO: lldds need to unconditionally forget about * aborted ata tasks, otherwise we (likely) leak the sas task * here
*/
pr_warn("%s: Task %p leaked.\n", __func__, task);
if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
task->task_state_flags &= ~SAS_TASK_STATE_ABORTED;
spin_unlock_irqrestore(&task->task_state_lock, flags);
if (qc->err_mask) { /* * Find the sas_task and kill it. By this point, libata * has decided to kill the qc and has frozen the port. * In this state sas_ata_task_done() will no longer free * the sas_task, so we need to notify the lldd (via * ->lldd_abort_task) that the task is dead and free it * ourselves.
*/ struct sas_task *task = qc->lldd_task;
list_for_each_entry_safe(dev, n, &port->disco_list, disco_list_node) { if (!dev_is_sata(dev)) continue;
sas_ata_wait_eh(dev);
/* if libata could not bring the link up, don't surface * the device
*/ if (!ata_dev_enabled(sas_to_ata_dev(dev)))
sas_fail_probe(dev, __func__, -ENODEV);
}
}
int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *phy, struct domain_device *child, int phy_id)
{ struct sas_rphy *rphy; int ret;
pr_notice("ex %016llx phy%02d SATA device linkrate > min pathway connection rate, attempting to lower device linkrate\n",
SAS_ADDR(child->sas_addr), phy_id);
ret = sas_smp_phy_control(parent, phy_id,
PHY_FUNC_LINK_RESET, &rates); if (ret) {
pr_err("ex %016llx phy%02d SATA device could not set linkrate (%d)\n",
SAS_ADDR(child->sas_addr), phy_id, ret); return ret;
}
pr_notice("ex %016llx phy%02d SATA device set linkrate successfully\n",
SAS_ADDR(child->sas_addr), phy_id);
child->linkrate = child->min_linkrate;
}
ret = sas_get_ata_info(child, phy); if (ret) return ret;
sas_init_dev(child);
ret = sas_ata_init(child); if (ret) return ret;
rphy = sas_end_device_alloc(phy->port); if (!rphy) return -ENOMEM;
ret = sas_discover_sata(child); if (ret) {
pr_notice("sas_discover_sata() for device %16llx at %016llx:%02d returned 0x%x\n",
SAS_ADDR(child->sas_addr),
SAS_ADDR(parent->sas_addr), phy_id, ret);
sas_rphy_free(child->rphy);
list_del(&child->disco_list_node); return ret;
}
/** * sas_discover_sata - discover an STP/SATA domain device * @dev: pointer to struct domain_device of interest * * Devices directly attached to a HA port, have no parents. All other * devices do, and should have their "parent" pointer set appropriately * before calling this function.
*/ int sas_discover_sata(struct domain_device *dev)
{ if (dev->dev_type == SAS_SATA_PM) return -ENODEV;
/* it's ok to defer revalidation events during ata eh, these * disks are in one of three states: * 1/ present for initial domain discovery, and these * resets will cause bcn flutters * 2/ hot removed, we'll discover that after eh fails * 3/ hot added after initial discovery, lost the race, and need * to catch the next train.
*/
sas_disable_revalidation(sas_ha);
spin_lock_irq(&sas_ha->phy_port_lock); for (i = 0; i < sas_ha->num_phys; i++) { struct asd_sas_port *port = sas_ha->sas_port[i]; struct domain_device *dev;
spin_lock(&port->dev_list_lock);
list_for_each_entry(dev, &port->dev_list, dev_list_node) { if (!dev_is_sata(dev)) continue;
/* hold a reference over eh since we may be * racing with final remove once all commands * are completed
*/
kref_get(&dev->kref);
list_for_each_entry_safe(cmd, n, work_q, eh_entry) { struct domain_device *ddev = cmd_to_domain_dev(cmd);
if (!dev_is_sata(ddev) || TO_SAS_TASK(cmd)) continue; if (eh_dev && eh_dev != ddev) continue;
eh_dev = ddev;
list_move(&cmd->eh_entry, &sata_q);
}
if (!list_empty(&sata_q)) { struct ata_port *ap = eh_dev->sata_dev.ap;
sas_ata_printk(KERN_DEBUG, eh_dev, "cmd error handler\n");
ata_scsi_cmd_error_handler(shost, ap, &sata_q); /* * ata's error handler may leave the cmd on the list * so make sure they don't remain on a stack list * about to go out of scope. * * This looks strange, since the commands are * now part of no list, but the next error * action will be ata_port_error_handler() * which takes no list and sweeps them up * anyway from the ata tag array.
*/ while (!list_empty(&sata_q))
list_del_init(sata_q.next);
}
} while (eh_dev);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.