libata: restore SControl on detach

Save SControl during probing and restore it on detach. This prevents
adjustments made by libata drivers to seep into the next driver which
gets attached (be it a libata one or not).

It's not clear whether SControl also needs to be restored on suspend.
The next system to have control (ACPI or kexec'd kernel) would
probably like to see the original SControl value but there's no
guarantee that a link is gonna keep working after SControl is adjusted
without a reset and adding a reset and modified recovery cycle soley
for this is an overkill. For now, do it only for detach.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>

authored by

Tejun Heo and committed by
Jeff Garzik
d127ea7b da0e21d3

+6 -5
+5 -5
drivers/ata/libata-core.c
··· 5199 */ 5200 int sata_link_init_spd(struct ata_link *link) 5201 { 5202 - u32 scontrol; 5203 u8 spd; 5204 int rc; 5205 5206 - rc = sata_scr_read(link, SCR_CONTROL, &scontrol); 5207 if (rc) 5208 return rc; 5209 5210 - spd = (scontrol >> 4) & 0xf; 5211 if (spd) 5212 link->hw_sata_spd_limit &= (1 << spd) - 1; 5213 ··· 5793 ata_port_wait_eh(ap); 5794 5795 /* EH is now guaranteed to see UNLOADING - EH context belongs 5796 - * to us. Disable all existing devices. 5797 */ 5798 - ata_port_for_each_link(link, ap) { 5799 ata_link_for_each_dev(dev, link) 5800 ata_dev_disable(dev); 5801 }
··· 5199 */ 5200 int sata_link_init_spd(struct ata_link *link) 5201 { 5202 u8 spd; 5203 int rc; 5204 5205 + rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol); 5206 if (rc) 5207 return rc; 5208 5209 + spd = (link->saved_scontrol >> 4) & 0xf; 5210 if (spd) 5211 link->hw_sata_spd_limit &= (1 << spd) - 1; 5212 ··· 5794 ata_port_wait_eh(ap); 5795 5796 /* EH is now guaranteed to see UNLOADING - EH context belongs 5797 + * to us. Restore SControl and disable all existing devices. 5798 */ 5799 + __ata_port_for_each_link(link, ap) { 5800 + sata_scr_write(link, SCR_CONTROL, link->saved_scontrol); 5801 ata_link_for_each_dev(dev, link) 5802 ata_dev_disable(dev); 5803 }
+1
include/linux/libata.h
··· 647 648 unsigned int flags; /* ATA_LFLAG_xxx */ 649 650 unsigned int hw_sata_spd_limit; 651 unsigned int sata_spd_limit; 652 unsigned int sata_spd; /* current SATA PHY speed */
··· 647 648 unsigned int flags; /* ATA_LFLAG_xxx */ 649 650 + u32 saved_scontrol; /* SControl on probe */ 651 unsigned int hw_sata_spd_limit; 652 unsigned int sata_spd_limit; 653 unsigned int sata_spd; /* current SATA PHY speed */