misc LPM related fixes
Niklas Cassel
maintainercover misc LPM related fixes
Hello there,
we had a recent bug report on the mailing list related to LPM, which made me review the LPM related code.
While doing so, I found some issues. This series fixes those issues.
The most serious issue is that ATA_QUIRK_NOLPM was not getting applied for ATAPI devices.
Kind regards,
Niklas
Niklas Cassel (5):
ata: libata: Call ata_dev_config_lpm() for ATAPI devices
ata: libata: Fix ata_dev_print_features() early return
ata: libata: Print features also for ATAPI devices
ata: libata-sata: Improve link_power_management_supported sysfs
attribute
ata: ahci: Do not read per port area for unimplemented ports
drivers/ata/ahci.c | 10 +++++----- drivers/ata/libata-core.c | 8 +++++++- drivers/ata/libata-sata.c | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-)
base-commit: 97e01439e902b743b8f89497e9c144e3ddda5e59
Signature · 1 line
2.52.0
Niklas Cassel
maintainerPATCH 1/5 ata: libata: Call ata_dev_config_lpm() for ATAPI devices
Commit d360121832d8 ("ata: libata-core: Introduce ata_dev_config_lpm()") introduced ata_dev_config_lpm(). However, it only called this function for ATA_DEV_ATA and ATA_DEV_ZAC devices, not for ATA_DEV_ATAPI devices.
Additionally, commit d99a9142e782 ("ata: libata-core: Move device LPM quirk settings to ata_dev_config_lpm()") moved the LPM quirk application from ata_dev_configure() to ata_dev_config_lpm(), causing LPM quirks for ATAPI devices to no longer be applied.
Call ata_dev_config_lpm() also for ATAPI devices, such that LPM quirks are applied for ATAPI devices with an entry in __ata_dev_quirks once again.
--- drivers/ata/libata-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/ata/libata-core.c +2 -0
@@ -3148,6 +3148,8 @@ int ata_dev_configure(struct ata_device *dev)ata_mode_string (xfer_mask), cdb_intr_string, atapi_an_string, dma_dir_string); + +ata_dev_config_lpm (dev); }/* determine max_sectors */
Signature · 1 line
2.52.0
Niklas Cassel
maintainerPATCH 2/5 ata: libata: Fix ata_dev_print_features() early return
In reply to Niklas Casselata_dev_print_features() is supposed to return early and not print anything if there are no features supported.
However, commit fe22e1c2f705 ("libata: support concurrent positioning ranges log") added another feature to ata_dev_print_features() without updating the early return conditional.
Likewise, commit b1f5af54f1f5 ("ata: libata-core: Advertize device support for DIPM and HIPM features") added additional features to ata_dev_print_features() without updating the early return conditional.
Add the missing features to the early return conditional.
--- drivers/ata/libata-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ata/libata-core.c +2 -1
@@ -2904,7 +2904,8 @@ static void ata_dev_config_lpm(struct ata_device *dev)static void ata_dev_print_features (struct ata_device *dev) { -if (!(dev->flags &ATA_DFLAG_FEATURES_MASK )) +if (!(dev->flags &ATA_DFLAG_FEATURES_MASK ) && !dev->cpr_log && + !ata_id_has_hipm (dev->id) && !ata_id_has_dipm (dev->id))return ; ata_dev_info(dev,
Signature · 1 line
2.52.0
Niklas Cassel
maintainerPATCH 3/5 ata: libata: Print features also for ATAPI devices
In reply to Niklas CasselCommit d633b8a702ab ("libata: print feature list on device scan") added a print of the features supported by the device for ATA_DEV_ATA and ATA_DEV_ZAC devices, but not for ATA_DEV_ATAPI devices.
Fix this by printing the features also for ATAPI devices.
Before changes:
ata1.00: ATAPI: Slimtype DVD A DU8AESH, 6C2M, max UDMA/133
After changes:
ata1.00: ATAPI: Slimtype DVD A DU8AESH, 6C2M, max UDMA/133 ata1.00: Features: Dev-Attention HIPM DIPM
--- drivers/ata/libata-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/ata/libata-core.c +3 -0
@@ -3151,6 +3151,9 @@ int ata_dev_configure(struct ata_device *dev) dma_dir_string);ata_dev_config_lpm (dev); + +if (print_info) +ata_dev_print_features (dev); }/* determine max_sectors */
Signature · 1 line
2.52.0
Niklas Cassel
maintainerPATCH 4/5 ata: libata-sata: Improve link_power_management_supported sysfs attribute
In reply to Niklas CasselThe link_power_management_supported sysfs attribute is currently set as true even for ata ports that lack a .set_lpm() callback, e.g. dummy ports.
This is a bit silly, because while writing to the link_power_management_policy sysfs attribute will make ata_scsi_lpm_store() update ap->target_lpm_policy (thus sysfs will reflect the new value) and call ata_port_schedule_eh() for the port, it is essentially a no-op.
This is because for a port without a .set_lpm() callback, once EH gets to run, the ata_eh_link_set_lpm() will simply return, since the port does not provide a .set_lpm() callback.
Thus, make sure that the link_power_management_supported sysfs attribute is set to false for ports that lack a .set_lpm() callback. This way the link_power_management_policy sysfs attribute will no longer be writable, so we will no longer be misleading users to think that their sysfs write actually does something.
--- drivers/ata/libata-sata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libata-sata.c +1 -1
@@ -909,7 +909,7 @@ static bool ata_scsi_lpm_supported(struct ata_port *ap)struct ata_link *link;struct ata_device *dev; -if (ap->flags &ATA_FLAG_NO_LPM ) +if ((ap->flags &ATA_FLAG_NO_LPM ) || !ap->ops->set_lpm)return false;ata_for_each_link (link, ap,EDGE ) {
Signature · 1 line
2.52.0
Niklas Cassel
maintainerPATCH 5/5 ata: ahci: Do not read per port area for unimplemented ports
In reply to Niklas CasselAn AHCI HBA specifies the number of ports is supports using CAP.NP. The HBA is free to only make a subset of the number of ports available using the PI (Ports Implemented) register.
libata currently creates dummy ports for HBA ports that are provided by the HBA, but which are marked as "unavailable" using the PI register.
Each port will have per port area of registers in the HBA, regardless if the port is marked as "unavailable" or not using the PI register.
ahci_mark_external_port() currently reads this per port area or registers using readl() to see if the port is marked as external/hotplug-capable.
However, AHCI 1.3.1, section "3.1.4 Offset 0Ch: PI – Ports Implemented"
states: "Software must not read or write to registers within unavailable ports."
Thus, make sure that we only call ahci_mark_external_port() and ahci_update_initial_lpm_policy() for ports that are implemented.
For a libata perspective, this should not change anything related to LPM, as dummy ports do not provide any ap->ops (they do not have a .set_lpm() callback), so even if EH were to call .set_lpm() on a dummy port, it was already a no-op.
--- drivers/ata/ahci.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/ata/ahci.c +5 -5
@@ -2094,13 +2094,13 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)if (ap->flags &ATA_FLAG_EM ) ap->em_message_type = hpriv->em_msg_type; -ahci_mark_external_port (ap); - -ahci_update_initial_lpm_policy (ap); -/* disabled/not-implemented port */ -if (!(hpriv->port_map & (1 << i))) +if (!(hpriv->port_map & (1 << i))) { ap->ops = &ata_dummy_port_ops; + }else { +ahci_mark_external_port (ap); +ahci_update_initial_lpm_policy (ap); + } }/* apply workaround for ASUS P5W DH Deluxe mainboard */
Signature · 1 line
2.52.0