int sas_unregister_ha(struct sas_ha_struct *sas_ha)
{
- unsigned long flags;
-
/* Set the state to unregistered to avoid further unchained
- * events to be queued
+ * events to be queued, and flush any in-progress drainers
*/
- spin_lock_irqsave(&sas_ha->state_lock, flags);
+ mutex_lock(&sas_ha->drain_mutex);
+ spin_lock_irq(&sas_ha->state_lock);
clear_bit(SAS_HA_REGISTERED, &sas_ha->state);
- spin_unlock_irqrestore(&sas_ha->state_lock, flags);
- sas_drain_work(sas_ha);
+ spin_unlock_irq(&sas_ha->state_lock);
+ __sas_drain_work(sas_ha);
+ mutex_unlock(&sas_ha->drain_mutex);
sas_unregister_ports(sas_ha);
- sas_drain_work(sas_ha);
+
+ /* flush unregistration work */
+ mutex_lock(&sas_ha->drain_mutex);
+ __sas_drain_work(sas_ha);
+ mutex_unlock(&sas_ha->drain_mutex);
if (sas_ha->lldd_max_execute_num > 1) {
sas_shutdown_queue(sas_ha);
return sas_smp_get_phy_events(phy);
}
+int sas_try_ata_reset(struct asd_sas_phy *asd_phy)
+{
+ struct domain_device *dev = NULL;
+
+ /* try to route user requested link resets through libata */
+ if (asd_phy->port)
+ dev = asd_phy->port->port_dev;
+
+ /* validate that dev has been probed */
+ if (dev)
+ dev = sas_find_dev_by_rphy(dev->rphy);
+
+ if (dev && dev_is_sata(dev)) {
+ sas_ata_schedule_reset(dev);
+ sas_ata_wait_eh(dev);
+ return 0;
+ }
+
+ return -ENODEV;
+}
+
/**
* transport_sas_phy_reset - reset a phy and permit libata to manage the link
*
*/
static int transport_sas_phy_reset(struct sas_phy *phy, int hard_reset)
{
- int ret;
enum phy_func reset_type;
if (hard_reset)
struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
struct sas_internal *i =
to_sas_internal(sas_ha->core.shost->transportt);
- struct domain_device *dev = NULL;
-
- if (asd_phy->port)
- dev = asd_phy->port->port_dev;
-
- /* validate that dev has been probed */
- if (dev)
- dev = sas_find_dev_by_rphy(dev->rphy);
- if (dev && dev_is_sata(dev) && !hard_reset) {
- sas_ata_schedule_reset(dev);
- sas_ata_wait_eh(dev);
- ret = 0;
- } else
- ret = i->dft->lldd_control_phy(asd_phy, reset_type, NULL);
+ if (!hard_reset && sas_try_ata_reset(asd_phy) == 0)
+ return 0;
+ return i->dft->lldd_control_phy(asd_phy, reset_type, NULL);
} else {
struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
struct domain_device *ddev = sas_find_dev_by_rphy(rphy);
if (ata_dev && !hard_reset) {
sas_ata_schedule_reset(ata_dev);
sas_ata_wait_eh(ata_dev);
- ret = 0;
+ return 0;
} else
- ret = sas_smp_phy_control(ddev, phy->number, reset_type, NULL);
+ return sas_smp_phy_control(ddev, phy->number, reset_type, NULL);
}
-
- return ret;
}
static int sas_phy_enable(struct sas_phy *phy, int enable)
if (enable)
ret = transport_sas_phy_reset(phy, 0);
- else {
- sas_phy_disconnected(asd_phy);
- sas_ha->notify_phy_event(asd_phy, PHYE_LOSS_OF_SIGNAL);
+ else
ret = i->dft->lldd_control_phy(asd_phy, cmd, NULL);
- }
} else {
struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
struct domain_device *ddev = sas_find_dev_by_rphy(rphy);
int ret;
enum phy_func reset_type;
+ if (!phy->enabled)
+ return -ENODEV;
+
if (hard_reset)
reset_type = PHY_FUNC_HARD_RESET;
else