From affccb16c117d188eb09495cbdea149cecbf00b9 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Wed, 6 Sep 2023 11:22:32 +0200 Subject: ata: ahci: print the lpm policy on boot The target LPM policy can be set using either a Kconfig or a kernel module parameter. However, if the board type is set to anything but board_ahci_low_power, then the LPM policy will overridden and set to ATA_LPM_UNKNOWN. Additionally, if the default suspend is suspend to idle, depending on the hardware capabilities of the HBA, ahci_update_initial_lpm_policy() might override the LPM policy to either ATA_LPM_MIN_POWER_WITH_PARTIAL or ATA_LPM_MIN_POWER. All this means that it is very hard to know which LPM policy a user will actually be using on a given system. In order to make it easier to debug LPM related issues, print the LPM policy on boot. One common LPM related issue is that the device fails to link up. Because of that, we cannot add this print to ata_dev_configure(), as that function is only called after a successful link up. Instead, add the info using ata_port_desc(), with the help of a new ata_port_desc_misc() helper. The port description is printed once per port during boot. Before changes: ata1: SATA max UDMA/133 abar m524288@0xa5780000 port 0xa5780100 irq 170 ata2: SATA max UDMA/133 abar m524288@0xa5780000 port 0xa5780180 irq 170 After changes: ata1: SATA max UDMA/133 abar m524288@0xa5780000 port 0xa5780100 irq 170 lpm-pol 4 ata2: SATA max UDMA/133 abar m524288@0xa5780000 port 0xa5780180 irq 170 lpm-pol 4 Signed-off-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/libahci.c | 2 +- drivers/ata/libata-core.c | 2 +- drivers/ata/libata-sff.c | 10 +++++----- drivers/ata/pata_cs5520.c | 2 +- include/linux/libata.h | 5 +++++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index f1263364fa97..1a63200ea437 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2730,7 +2730,7 @@ static int ahci_host_activate_multi_irqs(struct ata_host *host, if (rc) return rc; - ata_port_desc(host->ports[i], "irq %d", irq); + ata_port_desc_misc(host->ports[i], irq); } return ata_host_register(host, sht); diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index d8cc1e27a125..0f63f805c78c 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6026,7 +6026,7 @@ int ata_host_activate(struct ata_host *host, int irq, return rc; for (i = 0; i < host->n_ports; i++) - ata_port_desc(host->ports[i], "irq %d", irq); + ata_port_desc_misc(host->ports[i], irq); rc = ata_host_register(host, sht); /* if failed, just free the IRQ and leave ports alone */ diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c index 8fcc622fcb3d..95a19c4ef2a1 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c @@ -2316,7 +2316,7 @@ int ata_pci_sff_activate_host(struct ata_host *host, for (i = 0; i < 2; i++) { if (ata_port_is_dummy(host->ports[i])) continue; - ata_port_desc(host->ports[i], "irq %d", pdev->irq); + ata_port_desc_misc(host->ports[i], pdev->irq); } } else if (legacy_mode) { if (!ata_port_is_dummy(host->ports[0])) { @@ -2326,8 +2326,8 @@ int ata_pci_sff_activate_host(struct ata_host *host, if (rc) goto out; - ata_port_desc(host->ports[0], "irq %d", - ATA_PRIMARY_IRQ(pdev)); + ata_port_desc_misc(host->ports[0], + ATA_PRIMARY_IRQ(pdev)); } if (!ata_port_is_dummy(host->ports[1])) { @@ -2337,8 +2337,8 @@ int ata_pci_sff_activate_host(struct ata_host *host, if (rc) goto out; - ata_port_desc(host->ports[1], "irq %d", - ATA_SECONDARY_IRQ(pdev)); + ata_port_desc_misc(host->ports[1], + ATA_SECONDARY_IRQ(pdev)); } } diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c index 422d42761a1d..38795508c2e9 100644 --- a/drivers/ata/pata_cs5520.c +++ b/drivers/ata/pata_cs5520.c @@ -212,7 +212,7 @@ static int cs5520_init_one(struct pci_dev *pdev, const struct pci_device_id *id) if (rc) return rc; - ata_port_desc(ap, "irq %d", irq[i]); + ata_port_desc_misc(ap, irq[i]); } return ata_host_register(host, &cs5520_sht); diff --git a/include/linux/libata.h b/include/linux/libata.h index 2a7d2af0ed80..54a217868ad0 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1561,6 +1561,11 @@ void ata_port_desc(struct ata_port *ap, const char *fmt, ...); extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset, const char *name); #endif +static inline void ata_port_desc_misc(struct ata_port *ap, int irq) +{ + ata_port_desc(ap, "irq %d", irq); + ata_port_desc(ap, "lpm-pol %d", ap->target_lpm_policy); +} static inline bool ata_tag_internal(unsigned int tag) { -- cgit From 3bf6141060948e27b62b13beb216887f2e54591e Mon Sep 17 00:00:00 2001 From: Szuying Chen Date: Thu, 21 Sep 2023 17:33:51 +0800 Subject: ata: ahci: add identifiers for ASM2116 series adapters Add support for PCIe SATA adapter cards based on Asmedia 2116 controllers. These cards can provide up to 10 SATA ports on PCIe card. Signed-off-by: Szuying Chen Signed-off-by: Damien Le Moal --- drivers/ata/ahci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 08745e7db820..99b3d3e60774 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -604,6 +604,11 @@ static const struct pci_device_id ahci_pci_tbl[] = { { PCI_VDEVICE(ASMEDIA, 0x0621), board_ahci }, /* ASM1061R */ { PCI_VDEVICE(ASMEDIA, 0x0622), board_ahci }, /* ASM1062R */ { PCI_VDEVICE(ASMEDIA, 0x0624), board_ahci }, /* ASM1062+JMB575 */ + { PCI_VDEVICE(ASMEDIA, 0x1062), board_ahci }, /* ASM1062A */ + { PCI_VDEVICE(ASMEDIA, 0x1064), board_ahci }, /* ASM1064 */ + { PCI_VDEVICE(ASMEDIA, 0x1164), board_ahci }, /* ASM1164 */ + { PCI_VDEVICE(ASMEDIA, 0x1165), board_ahci }, /* ASM1165 */ + { PCI_VDEVICE(ASMEDIA, 0x1166), board_ahci }, /* ASM1166 */ /* * Samsung SSDs found on some macbooks. NCQ times out if MSI is -- cgit From 0e19548145d863c48c6562add768a05231d768c9 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 22 Sep 2023 10:52:11 -0700 Subject: ata: libata: Annotate struct ata_cpr_log with __counted_by Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct ata_cpr_log. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Damien Le Moal Cc: linux-ide@vger.kernel.org Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Signed-off-by: Damien Le Moal --- include/linux/libata.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/libata.h b/include/linux/libata.h index 54a217868ad0..b39891320271 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -656,7 +656,7 @@ struct ata_cpr { struct ata_cpr_log { u8 nr_cpr; - struct ata_cpr cpr[]; + struct ata_cpr cpr[] __counted_by(nr_cpr); }; struct ata_device { -- cgit From c4367ac83805a2322268c9736cd8ef9124063424 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Sat, 26 Aug 2023 12:48:33 +0900 Subject: scsi: Remove scsi device no_start_on_resume flag The scsi device flag no_start_on_resume is not set by any scsi low level driver. Remove it. This reverts the changes introduced by commit 0a8589055936 ("ata,scsi: do not issue START STOP UNIT on resume"). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/scsi/sd.c | 9 +++------ include/scsi/scsi_device.h | 1 - 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 83b6a3f3863b..194ca15930e6 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3895,7 +3895,7 @@ static int sd_suspend_runtime(struct device *dev) static int sd_resume(struct device *dev, bool runtime) { struct scsi_disk *sdkp = dev_get_drvdata(dev); - int ret = 0; + int ret; if (!sdkp) /* E.g.: runtime resume at the start of sd_probe() */ return 0; @@ -3905,11 +3905,8 @@ static int sd_resume(struct device *dev, bool runtime) return 0; } - if (!sdkp->device->no_start_on_resume) { - sd_printk(KERN_NOTICE, sdkp, "Starting disk\n"); - ret = sd_start_stop_device(sdkp, 1); - } - + sd_printk(KERN_NOTICE, sdkp, "Starting disk\n"); + ret = sd_start_stop_device(sdkp, 1); if (!ret) { opal_unlock_from_suspend(sdkp->opal_dev); sdkp->suspended = false; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index fd41fdac0a8e..e6e476fe2272 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -197,7 +197,6 @@ struct scsi_device { unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */ unsigned no_start_on_add:1; /* do not issue start on add */ unsigned allow_restart:1; /* issue START_UNIT in error handler */ - unsigned no_start_on_resume:1; /* Do not issue START_STOP_UNIT on resume */ unsigned start_stop_pwr_cond:1; /* Set power cond. in START_STOP_UNIT */ unsigned no_uld_attach:1; /* disable connecting to upper level drivers */ unsigned select_no_atn:1; -- cgit From 8c1f08170694f50216f0e336ccfc589d3430a339 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Tue, 29 Aug 2023 10:18:34 +0900 Subject: ata: libata-scsi: Cleanup ata_scsi_start_stop_xlat() Now that libata does its own internal device power mode management through libata EH, the scsi disk driver will not issue START STOP UNIT commands anymore. We can receive this command only from user passthrough operations. So there is no need to consider the system state and ATA port flags for suspend to translate the command. Since setting up the taskfile for the verify and standby immediate commands is the same as done in ata_dev_power_set_active() and ata_dev_power_set_standby(), factor out this code into the helper function ata_dev_power_init_tf() to simplify ata_scsi_start_stop_xlat() as well as ata_dev_power_set_active() and ata_dev_power_set_standby(). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-core.c | 55 ++++++++++++++++++++++++++++------------------- drivers/ata/libata-scsi.c | 53 ++++++++------------------------------------- drivers/ata/libata.h | 2 ++ 3 files changed, 44 insertions(+), 66 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 0f63f805c78c..5afd30d76f0b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1972,6 +1972,35 @@ retry: return rc; } +bool ata_dev_power_init_tf(struct ata_device *dev, struct ata_taskfile *tf, + bool set_active) +{ + /* Only applies to ATA and ZAC devices */ + if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) + return false; + + ata_tf_init(dev, tf); + tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; + tf->protocol = ATA_PROT_NODATA; + + if (set_active) { + /* VERIFY for 1 sector at lba=0 */ + tf->command = ATA_CMD_VERIFY; + tf->nsect = 1; + if (dev->flags & ATA_DFLAG_LBA) { + tf->flags |= ATA_TFLAG_LBA; + tf->device |= ATA_LBA; + } else { + /* CHS */ + tf->lbal = 0x1; /* sect */ + } + } else { + tf->command = ATA_CMD_STANDBYNOW1; + } + + return true; +} + /** * ata_dev_power_set_standby - Set a device power mode to standby * @dev: target device @@ -1988,10 +2017,6 @@ void ata_dev_power_set_standby(struct ata_device *dev) struct ata_taskfile tf; unsigned int err_mask; - /* Issue STANDBY IMMEDIATE command only if supported by the device */ - if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) - return; - /* * Some odd clown BIOSes issue spindown on power off (ACPI S4 or S5) * causing some drives to spin up and down again. For these, do nothing @@ -2005,10 +2030,9 @@ void ata_dev_power_set_standby(struct ata_device *dev) system_entering_hibernation()) return; - ata_tf_init(dev, &tf); - tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; - tf.protocol = ATA_PROT_NODATA; - tf.command = ATA_CMD_STANDBYNOW1; + /* Issue STANDBY IMMEDIATE command only if supported by the device */ + if (!ata_dev_power_init_tf(dev, &tf, false)) + return; ata_dev_notice(dev, "Entering standby power mode\n"); @@ -2038,22 +2062,9 @@ void ata_dev_power_set_active(struct ata_device *dev) * Issue READ VERIFY SECTORS command for 1 sector at lba=0 only * if supported by the device. */ - if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) + if (!ata_dev_power_init_tf(dev, &tf, true)) return; - ata_tf_init(dev, &tf); - tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; - tf.protocol = ATA_PROT_NODATA; - tf.command = ATA_CMD_VERIFY; - tf.nsect = 1; - if (dev->flags & ATA_DFLAG_LBA) { - tf.flags |= ATA_TFLAG_LBA; - tf.device |= ATA_LBA; - } else { - /* CHS */ - tf.lbal = 0x1; /* sect */ - } - ata_dev_notice(dev, "Entering active power mode\n"); err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a371b497035e..63b4c09e15df 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1202,7 +1202,6 @@ EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy); static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) { struct scsi_cmnd *scmd = qc->scsicmd; - struct ata_taskfile *tf = &qc->tf; const u8 *cdb = scmd->cmnd; u16 fp; u8 bp = 0xff; @@ -1212,54 +1211,24 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) goto invalid_fld; } - tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; - tf->protocol = ATA_PROT_NODATA; - if (cdb[1] & 0x1) { - ; /* ignore IMMED bit, violates sat-r05 */ - } + /* LOEJ bit set not supported */ if (cdb[4] & 0x2) { fp = 4; bp = 1; - goto invalid_fld; /* LOEJ bit set not supported */ + goto invalid_fld; } + + /* Power conditions not supported */ if (((cdb[4] >> 4) & 0xf) != 0) { fp = 4; bp = 3; - goto invalid_fld; /* power conditions not supported */ + goto invalid_fld; } - if (cdb[4] & 0x1) { - tf->nsect = 1; /* 1 sector, lba=0 */ - - if (qc->dev->flags & ATA_DFLAG_LBA) { - tf->flags |= ATA_TFLAG_LBA; - - tf->lbah = 0x0; - tf->lbam = 0x0; - tf->lbal = 0x0; - tf->device |= ATA_LBA; - } else { - /* CHS */ - tf->lbal = 0x1; /* sect */ - tf->lbam = 0x0; /* cyl low */ - tf->lbah = 0x0; /* cyl high */ - } - - tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ - } else { - /* Some odd clown BIOSen issue spindown on power off (ACPI S4 - * or S5) causing some drives to spin up and down again. - */ - if ((qc->ap->flags & ATA_FLAG_NO_POWEROFF_SPINDOWN) && - system_state == SYSTEM_POWER_OFF) - goto skip; - - if ((qc->ap->flags & ATA_FLAG_NO_HIBERNATE_SPINDOWN) && - system_entering_hibernation()) - goto skip; - - /* Issue ATA STANDBY IMMEDIATE command */ - tf->command = ATA_CMD_STANDBYNOW1; + /* Ignore IMMED bit (cdb[1] & 0x1), violates sat-r05 */ + if (!ata_dev_power_init_tf(qc->dev, &qc->tf, cdb[4] & 0x1)) { + ata_scsi_set_sense(qc->dev, scmd, ABORTED_COMMAND, 0, 0); + return 1; } /* @@ -1274,12 +1243,8 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) invalid_fld: ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp); return 1; - skip: - scmd->result = SAM_STAT_GOOD; - return 1; } - /** * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command * @qc: Storage for translated ATA taskfile diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 05ac80da8ebc..5c685bb1939e 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -62,6 +62,8 @@ extern int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags); extern int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class, unsigned int readid_flags); extern int ata_dev_configure(struct ata_device *dev); +extern bool ata_dev_power_init_tf(struct ata_device *dev, + struct ata_taskfile *tf, bool set_active); extern void ata_dev_power_set_standby(struct ata_device *dev); extern void ata_dev_power_set_active(struct ata_device *dev); extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); -- cgit From cfead0dd81de95f52f416a676d4697484e093c8b Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Mon, 28 Aug 2023 15:57:11 +0900 Subject: ata: libata-core: Synchronize ata_port_detach() with hotplug The call to async_synchronize_cookie() to synchronize a port removal and hotplug probe is done in ata_host_detach() right before calling ata_port_detach(). Move this call at the beginning of ata_port_detach() to ensure that this operation is always synchronized with probe. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 5afd30d76f0b..2b7b88e74c2b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6065,6 +6065,9 @@ static void ata_port_detach(struct ata_port *ap) struct ata_link *link; struct ata_device *dev; + /* Ensure ata_port probe has completed */ + async_synchronize_cookie(ap->cookie + 1); + /* Wait for any ongoing EH */ ata_port_wait_eh(ap); @@ -6129,11 +6132,8 @@ void ata_host_detach(struct ata_host *host) { int i; - for (i = 0; i < host->n_ports; i++) { - /* Ensure ata_port probe has completed */ - async_synchronize_cookie(host->ports[i]->cookie + 1); + for (i = 0; i < host->n_ports; i++) ata_port_detach(host->ports[i]); - } /* the host is dead now, dissociate ACPI */ ata_acpi_dissociate(host); -- cgit From 5b6fba546da246b3d0dd8465c07783e22629cc53 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Mon, 28 Aug 2023 16:01:58 +0900 Subject: ata: libata-core: Detach a port devices on shutdown Modify ata_pci_shutdown_one() to schedule EH to unload a port devices before freezing and thawing the port. This ensures that drives are cleanly disabled and transitioned to standby power mode when a PCI adapter is removed or the system is powered off. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 2b7b88e74c2b..a4d5d2fcf3b9 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6164,10 +6164,24 @@ EXPORT_SYMBOL_GPL(ata_pci_remove_one); void ata_pci_shutdown_one(struct pci_dev *pdev) { struct ata_host *host = pci_get_drvdata(pdev); + struct ata_port *ap; + unsigned long flags; int i; + /* Tell EH to disable all devices */ for (i = 0; i < host->n_ports; i++) { - struct ata_port *ap = host->ports[i]; + ap = host->ports[i]; + spin_lock_irqsave(ap->lock, flags); + ap->pflags |= ATA_PFLAG_UNLOADING; + ata_port_schedule_eh(ap); + spin_unlock_irqrestore(ap->lock, flags); + } + + for (i = 0; i < host->n_ports; i++) { + ap = host->ports[i]; + + /* Wait for EH to complete before freezing the port */ + ata_port_wait_eh(ap); ap->pflags |= ATA_PFLAG_FROZEN; -- cgit From 6702255d700a6b41413d6701454cac320f2a9a42 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Mon, 4 Sep 2023 20:46:23 +0900 Subject: ata: libata-core: Remove ata_port_suspend_async() ata_port_suspend_async() is only called by ata_sas_port_suspend(). Modify ata_port_suspend() with an additional bool argument indicating an asynchronous or synchronous suspend to allow removing that helper function. With this change, the variable ata_port_resume_ehi can also be removed and its value (ATA_EHI_XXX flags passed directly to ata_port_request_pm(). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-core.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index a4d5d2fcf3b9..d72a2a2a61fd 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5166,18 +5166,8 @@ static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg, ata_port_wait_eh(ap); } -/* - * On some hardware, device fails to respond after spun down for suspend. As - * the device won't be used before being resumed, we don't need to touch the - * device. Ask EH to skip the usual stuff and proceed directly to suspend. - * - * http://thread.gmane.org/gmane.linux.ide/46764 - */ -static const unsigned int ata_port_suspend_ehi = ATA_EHI_QUIET - | ATA_EHI_NO_AUTOPSY - | ATA_EHI_NO_RECOVERY; - -static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg) +static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg, + bool async) { /* * We are about to suspend the port, so we do not care about @@ -5187,20 +5177,18 @@ static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg) */ cancel_delayed_work_sync(&ap->scsi_rescan_task); - ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, false); -} - -static void ata_port_suspend_async(struct ata_port *ap, pm_message_t mesg) -{ /* - * We are about to suspend the port, so we do not care about - * scsi_rescan_device() calls scheduled by previous resume operations. - * The next resume will schedule the rescan again. So cancel any rescan - * that is not done yet. + * On some hardware, device fails to respond after spun down for + * suspend. As the device will not be used until being resumed, we + * do not need to touch the device. Ask EH to skip the usual stuff + * and proceed directly to suspend. + * + * http://thread.gmane.org/gmane.linux.ide/46764 */ - cancel_delayed_work_sync(&ap->scsi_rescan_task); - - ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, true); + ata_port_request_pm(ap, mesg, 0, + ATA_EHI_QUIET | ATA_EHI_NO_AUTOPSY | + ATA_EHI_NO_RECOVERY, + async); } static int ata_port_pm_suspend(struct device *dev) @@ -5210,7 +5198,7 @@ static int ata_port_pm_suspend(struct device *dev) if (pm_runtime_suspended(dev)) return 0; - ata_port_suspend(ap, PMSG_SUSPEND); + ata_port_suspend(ap, PMSG_SUSPEND, false); return 0; } @@ -5221,13 +5209,13 @@ static int ata_port_pm_freeze(struct device *dev) if (pm_runtime_suspended(dev)) return 0; - ata_port_suspend(ap, PMSG_FREEZE); + ata_port_suspend(ap, PMSG_FREEZE, false); return 0; } static int ata_port_pm_poweroff(struct device *dev) { - ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE); + ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE, false); return 0; } @@ -5279,7 +5267,7 @@ static int ata_port_runtime_idle(struct device *dev) static int ata_port_runtime_suspend(struct device *dev) { - ata_port_suspend(to_ata_port(dev), PMSG_AUTO_SUSPEND); + ata_port_suspend(to_ata_port(dev), PMSG_AUTO_SUSPEND, false); return 0; } @@ -5309,7 +5297,7 @@ static const struct dev_pm_ops ata_port_pm_ops = { */ void ata_sas_port_suspend(struct ata_port *ap) { - ata_port_suspend_async(ap, PMSG_SUSPEND); + ata_port_suspend(ap, PMSG_SUSPEND, true); } EXPORT_SYMBOL_GPL(ata_sas_port_suspend); -- cgit From 09b055cfb0e9a337938f7a47681b2203bd7b85d2 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Mon, 4 Sep 2023 20:59:35 +0900 Subject: ata: libata-core: Remove ata_port_resume_async() Remove ata_port_resume_async() and replace it with a modified ata_port_resume() taking an additional bool argument indicating if ata EH resume operation should be executed synchronously or asynchronously. With this change, the variable ata_port_resume_ehi is not longer necessary and its value (ATA_EHI_XXX flags) passed directly to ata_port_request_pm(). Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-core.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index d72a2a2a61fd..c249016a5998 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5219,22 +5219,17 @@ static int ata_port_pm_poweroff(struct device *dev) return 0; } -static const unsigned int ata_port_resume_ehi = ATA_EHI_NO_AUTOPSY - | ATA_EHI_QUIET; - -static void ata_port_resume(struct ata_port *ap, pm_message_t mesg) +static void ata_port_resume(struct ata_port *ap, pm_message_t mesg, + bool async) { - ata_port_request_pm(ap, mesg, ATA_EH_RESET, ata_port_resume_ehi, false); -} - -static void ata_port_resume_async(struct ata_port *ap, pm_message_t mesg) -{ - ata_port_request_pm(ap, mesg, ATA_EH_RESET, ata_port_resume_ehi, true); + ata_port_request_pm(ap, mesg, ATA_EH_RESET, + ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, + async); } static int ata_port_pm_resume(struct device *dev) { - ata_port_resume_async(to_ata_port(dev), PMSG_RESUME); + ata_port_resume(to_ata_port(dev), PMSG_RESUME, true); pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -5273,7 +5268,7 @@ static int ata_port_runtime_suspend(struct device *dev) static int ata_port_runtime_resume(struct device *dev) { - ata_port_resume(to_ata_port(dev), PMSG_AUTO_RESUME); + ata_port_resume(to_ata_port(dev), PMSG_AUTO_RESUME, false); return 0; } @@ -5303,7 +5298,7 @@ EXPORT_SYMBOL_GPL(ata_sas_port_suspend); void ata_sas_port_resume(struct ata_port *ap) { - ata_port_resume_async(ap, PMSG_RESUME); + ata_port_resume(ap, PMSG_RESUME, true); } EXPORT_SYMBOL_GPL(ata_sas_port_resume); -- cgit From 3a94af2488bfe7dfe70fd9277d4548f971b06ec8 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Thu, 31 Aug 2023 15:23:37 +0900 Subject: ata: libata-core: Do not poweroff runtime suspended ports When powering off, there is no need to suspend a port that has already been runtime suspended. Skip the EH PM request in ata_port_pm_poweroff() in this case. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index c249016a5998..c9db2da582b7 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5215,7 +5215,8 @@ static int ata_port_pm_freeze(struct device *dev) static int ata_port_pm_poweroff(struct device *dev) { - ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE, false); + if (!pm_runtime_suspended(dev)) + ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE, false); return 0; } -- cgit From 3341b82368fb26dcf75f2c60320dc7442dac7075 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Sat, 2 Sep 2023 16:32:21 +0900 Subject: ata: libata-core: Do not resume runtime suspended ports The scsi disk driver does not resume disks that have been runtime suspended by the user. To be consistent with this behavior, do the same for ata ports and skip the PM request in ata_port_pm_resume() if the port was already runtime suspended. With this change, it is no longer necessary to force the PM state of the port to ACTIVE as the PM core code will take care of that when handling runtime resume. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index c9db2da582b7..83613280928b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5230,10 +5230,8 @@ static void ata_port_resume(struct ata_port *ap, pm_message_t mesg, static int ata_port_pm_resume(struct device *dev) { - ata_port_resume(to_ata_port(dev), PMSG_RESUME, true); - pm_runtime_disable(dev); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); + if (!pm_runtime_suspended(dev)) + ata_port_resume(to_ata_port(dev), PMSG_RESUME, true); return 0; } -- cgit From 88b9f89286781ebfd3931867f6a6f037236bbeab Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Wed, 30 Aug 2023 16:59:04 +0900 Subject: ata: libata-sata: Improve ata_sas_slave_configure() Change ata_sas_slave_configure() to return the return value of ata_scsi_dev_config() to ensure that any error from that function is propagated to libsas. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: John Garry Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-sata.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index a701e1538482..83a9497e48e1 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1182,8 +1182,8 @@ EXPORT_SYMBOL_GPL(ata_sas_tport_delete); int ata_sas_slave_configure(struct scsi_device *sdev, struct ata_port *ap) { ata_scsi_sdev_config(sdev); - ata_scsi_dev_config(sdev, ap->link.device); - return 0; + + return ata_scsi_dev_config(sdev, ap->link.device); } EXPORT_SYMBOL_GPL(ata_sas_slave_configure); -- cgit From 7f95731c74d73d07958889a685bbfc13e8d82721 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Tue, 29 Aug 2023 11:25:47 +0900 Subject: ata: libata-eh: Improve reset error messages Some drives are really slow to spinup on resume, resulting is a very slow response to COMRESET and to error messages such as: ata1: COMRESET failed (errno=-16) ata1: link is slow to respond, please be patient (ready=0) ata1: SATA link up 6.0 Gbps (SStatus 133 SControl 300) ata1.00: configured for UDMA/133 Given that the slowness of the response is indicated with the message "link is slow to respond..." and that resets are retried until the device is detected as online after up to 1min (ata_eh_reset_timeouts), there is no point in printing the "COMRESET failed" error message. Let's not scare the user with non fatal errors and only warn about reset failures in ata_eh_reset() when all reset retries have been exhausted. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-eh.c | 2 ++ drivers/ata/libata-sata.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 5686353e442c..67387d602735 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -2909,6 +2909,8 @@ int ata_eh_reset(struct ata_link *link, int classify, */ if (ata_is_host_link(link)) ata_eh_thaw_port(ap); + ata_link_warn(link, "%s failed\n", + reset == hardreset ? "hardreset" : "softreset"); goto out; } diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 83a9497e48e1..b6656c287175 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -621,7 +621,6 @@ int sata_link_hardreset(struct ata_link *link, const unsigned int *timing, /* online is set iff link is online && reset succeeded */ if (online) *online = false; - ata_link_err(link, "COMRESET failed (errno=%d)\n", rc); } return rc; } -- cgit From 0fecb50891aa8731f39c65ab59c3f5d3cf2ce468 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Tue, 29 Aug 2023 11:44:10 +0900 Subject: ata: libata-eh: Reduce "disable device" message verbosity There is no point in warning about a device being disabled when we expect it to be, that is, on suspend, shutdown or when detaching the device. Suppress the message "disable device" for these cases by introducing the EH static function ata_eh_dev_disable() and by using it in ata_eh_unload() and ata_eh_detach_dev(). ata_dev_disable() code is modified to call this new function after printing the "disable device" message. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- drivers/ata/libata-eh.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 67387d602735..945675f6b822 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -494,6 +494,18 @@ void ata_eh_release(struct ata_port *ap) mutex_unlock(&ap->host->eh_mutex); } +static void ata_eh_dev_disable(struct ata_device *dev) +{ + ata_acpi_on_disable(dev); + ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | ATA_DNXFER_QUIET); + dev->class++; + + /* From now till the next successful probe, ering is used to + * track probe failures. Clear accumulated device error info. + */ + ata_ering_clear(&dev->ering); +} + static void ata_eh_unload(struct ata_port *ap) { struct ata_link *link; @@ -517,8 +529,8 @@ static void ata_eh_unload(struct ata_port *ap) */ ata_for_each_link(link, ap, PMP_FIRST) { sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0); - ata_for_each_dev(dev, link, ALL) - ata_dev_disable(dev); + ata_for_each_dev(dev, link, ENABLED) + ata_eh_dev_disable(dev); } /* freeze and set UNLOADED */ @@ -1211,14 +1223,8 @@ void ata_dev_disable(struct ata_device *dev) return; ata_dev_warn(dev, "disable device\n"); - ata_acpi_on_disable(dev); - ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | ATA_DNXFER_QUIET); - dev->class++; - /* From now till the next successful probe, ering is used to - * track probe failures. Clear accumulated device error info. - */ - ata_ering_clear(&dev->ering); + ata_eh_dev_disable(dev); } EXPORT_SYMBOL_GPL(ata_dev_disable); @@ -1240,12 +1246,12 @@ void ata_eh_detach_dev(struct ata_device *dev) /* * If the device is still enabled, transition it to standby power mode - * (i.e. spin down HDDs). + * (i.e. spin down HDDs) and disable it. */ - if (ata_dev_enabled(dev)) + if (ata_dev_enabled(dev)) { ata_dev_power_set_standby(dev); - - ata_dev_disable(dev); + ata_eh_dev_disable(dev); + } spin_lock_irqsave(ap->lock, flags); -- cgit From 1b947279798fd51bef46e8241102f5b896add021 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Mon, 28 Aug 2023 13:10:28 +0900 Subject: ata: libata: Cleanup inline DMA helper functions Simplify the inline DMA helper functions ata_using_mwdma(), ata_using_udma() and ata_dma_enabled() to directly return as a boolean the result of their test condition. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Tested-by: Chia-Lin Kao (AceLan) Tested-by: Geert Uytterhoeven Reviewed-by: Martin K. Petersen --- include/linux/libata.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/linux/libata.h b/include/linux/libata.h index b39891320271..1dbb14daccfa 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1886,23 +1886,21 @@ static inline unsigned long ata_deadline(unsigned long from_jiffies, change in future hardware and specs, secondly 0xFF means 'no DMA' but is > UDMA_0. Dyma ddreigiau */ -static inline int ata_using_mwdma(struct ata_device *adev) +static inline bool ata_using_mwdma(struct ata_device *adev) { - if (adev->dma_mode >= XFER_MW_DMA_0 && adev->dma_mode <= XFER_MW_DMA_4) - return 1; - return 0; + return adev->dma_mode >= XFER_MW_DMA_0 && + adev->dma_mode <= XFER_MW_DMA_4; } -static inline int ata_using_udma(struct ata_device *adev) +static inline bool ata_using_udma(struct ata_device *adev) { - if (adev->dma_mode >= XFER_UDMA_0 && adev->dma_mode <= XFER_UDMA_7) - return 1; - return 0; + return adev->dma_mode >= XFER_UDMA_0 && + adev->dma_mode <= XFER_UDMA_7; } -static inline int ata_dma_enabled(struct ata_device *adev) +static inline bool ata_dma_enabled(struct ata_device *adev) { - return (adev->dma_mode == 0xFF ? 0 : 1); + return adev->dma_mode != 0xFF; } /************************************************************************** -- cgit From b8b8b4e0c052b2c06e1c4820a8001f4e0f77900f Mon Sep 17 00:00:00 2001 From: Mika Westerberg Date: Mon, 25 Sep 2023 11:05:38 +0300 Subject: ata: ahci: Add Intel Alder Lake-P AHCI controller to low power chipsets list Intel Alder Lake-P AHCI controller needs to be added to the mobile chipsets list in order to have link power management enabled. Without this the CPU cannot enter lower power C-states making idle power consumption high. Cc: Koba Ko Signed-off-by: Mika Westerberg Signed-off-by: Damien Le Moal --- drivers/ata/ahci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 99b3d3e60774..3a5f3255f51b 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -423,6 +423,7 @@ static const struct pci_device_id ahci_pci_tbl[] = { { PCI_VDEVICE(INTEL, 0x02d7), board_ahci_low_power }, /* Comet Lake PCH RAID */ /* Elkhart Lake IDs 0x4b60 & 0x4b62 https://sata-io.org/product/8803 not tested yet */ { PCI_VDEVICE(INTEL, 0x4b63), board_ahci_low_power }, /* Elkhart Lake AHCI */ + { PCI_VDEVICE(INTEL, 0x7ae2), board_ahci_low_power }, /* Alder Lake-P AHCI */ /* JMicron 360/1/3/5/6, match class to avoid IDE function */ { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, -- cgit From 2267d5a146c8fe7fcad812aed93b44d4ae148789 Mon Sep 17 00:00:00 2001 From: Ma Ke Date: Tue, 10 Oct 2023 20:29:16 +0800 Subject: ata: sata_mv: aspeed: fix value check in mv_platform_probe() In mv_platform_probe(), check the return value of clk_prepare_enable() and return the error code if clk_prepare_enable() returns an unexpected value. Signed-off-by: Ma Ke Reviewed-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/sata_mv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index 45e48d653c60..e82786c63fbd 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c @@ -4123,10 +4123,13 @@ static int mv_platform_probe(struct platform_device *pdev) hpriv->base -= SATAHC0_REG_BASE; hpriv->clk = clk_get(&pdev->dev, NULL); - if (IS_ERR(hpriv->clk)) + if (IS_ERR(hpriv->clk)) { dev_notice(&pdev->dev, "cannot get optional clkdev\n"); - else - clk_prepare_enable(hpriv->clk); + } else { + rc = clk_prepare_enable(hpriv->clk); + if (rc) + goto err; + } for (port = 0; port < n_ports; port++) { char port_number[16]; -- cgit From 0ecbef3125510002f521e950a38d95f49e772f00 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Fri, 6 Oct 2023 16:44:33 -0500 Subject: ata: xgene: Use of_device_get_match_data() Use preferred of_device_get_match_data() instead of of_match_device() to get the driver match data. With this, adjust the includes to explicitly include the correct headers. Signed-off-by: Rob Herring Reviewed-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/ahci_xgene.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/ata/ahci_xgene.c b/drivers/ata/ahci_xgene.c index ccef5e63bdf9..81a1d838c0fc 100644 --- a/drivers/ata/ahci_xgene.c +++ b/drivers/ata/ahci_xgene.c @@ -13,9 +13,7 @@ #include #include #include -#include -#include -#include +#include #include #include "ahci.h" @@ -735,7 +733,6 @@ static int xgene_ahci_probe(struct platform_device *pdev) struct ahci_host_priv *hpriv; struct xgene_ahci_context *ctx; struct resource *res; - const struct of_device_id *of_devid; enum xgene_ahci_version version = XGENE_AHCI_V1; const struct ata_port_info *ppi[] = { &xgene_ahci_v1_port_info, &xgene_ahci_v2_port_info }; @@ -778,10 +775,8 @@ static int xgene_ahci_probe(struct platform_device *pdev) ctx->csr_mux = csr; } - of_devid = of_match_device(xgene_ahci_of_match, dev); - if (of_devid) { - if (of_devid->data) - version = (unsigned long) of_devid->data; + if (dev->of_node) { + version = (enum xgene_ahci_version)of_device_get_match_data(dev); } #ifdef CONFIG_ACPI else { -- cgit From 0e7ad4bba2965f777b5fd618734642eb5a19ddcc Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Fri, 6 Oct 2023 16:44:42 -0500 Subject: ata: imx: Use device_get_match_data() Use preferred device_get_match_data() instead of of_match_device() to get the driver match data. With this, adjust the includes to explicitly include the correct headers. Signed-off-by: Rob Herring Reviewed-by: Niklas Cassel Signed-off-by: Damien Le Moal --- drivers/ata/ahci_imx.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c index 9fa005965f3b..cb768f66f0a7 100644 --- a/drivers/ata/ahci_imx.c +++ b/drivers/ata/ahci_imx.c @@ -9,10 +9,11 @@ #include #include #include +#include #include #include #include -#include +#include #include #include #include @@ -1050,16 +1051,11 @@ static int imx8_sata_probe(struct device *dev, struct imx_ahci_priv *imxpriv) static int imx_ahci_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - const struct of_device_id *of_id; struct ahci_host_priv *hpriv; struct imx_ahci_priv *imxpriv; unsigned int reg_val; int ret; - of_id = of_match_device(imx_ahci_of_match, dev); - if (!of_id) - return -EINVAL; - imxpriv = devm_kzalloc(dev, sizeof(*imxpriv), GFP_KERNEL); if (!imxpriv) return -ENOMEM; @@ -1067,7 +1063,7 @@ static int imx_ahci_probe(struct platform_device *pdev) imxpriv->ahci_pdev = pdev; imxpriv->no_device = false; imxpriv->first_time = true; - imxpriv->type = (unsigned long)of_id->data; + imxpriv->type = (enum ahci_imx_type)device_get_match_data(dev); imxpriv->sata_clk = devm_clk_get(dev, "sata"); if (IS_ERR(imxpriv->sata_clk)) { -- cgit From 54d7211da7cd8fbd286532b25f4f0b688fcf94a3 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Thu, 12 Oct 2023 15:53:16 +0900 Subject: ata: libata-eh: Spinup disk on resume after revalidation Move the call to ata_dev_power_set_active() to transition a disk in standby power mode to the active power mode from ata_eh_revalidate_and_attach() before doing revalidation to the end of ata_eh_recover(), after the link speed for the device is reconfigured (if that was necessary). This is safer as this ensure that the VERIFY command executed to spinup the disk is executed with the drive properly reconfigured first. Signed-off-by: Damien Le Moal Reviewed-by: Niklas Cassel Tested-by: Geert Uytterhoeven --- drivers/ata/libata-eh.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 945675f6b822..b0d6e69c4a5b 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -3051,15 +3051,6 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link, if (ehc->i.flags & ATA_EHI_DID_RESET) readid_flags |= ATA_READID_POSTRESET; - /* - * When resuming, before executing any command, make sure to - * transition the device to the active power mode. - */ - if ((action & ATA_EH_SET_ACTIVE) && ata_dev_enabled(dev)) { - ata_dev_power_set_active(dev); - ata_eh_done(link, dev, ATA_EH_SET_ACTIVE); - } - if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { WARN_ON(dev->class == ATA_DEV_PMP); @@ -3856,6 +3847,17 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, } } + /* + * Make sure to transition devices to the active power mode + * if needed (e.g. if we were scheduled on system resume). + */ + ata_for_each_dev(dev, link, ENABLED) { + if (ehc->i.dev_action[dev->devno] & ATA_EH_SET_ACTIVE) { + ata_dev_power_set_active(dev); + ata_eh_done(link, dev, ATA_EH_SET_ACTIVE); + } + } + /* retry flush if necessary */ ata_for_each_dev(dev, link, ALL) { if (dev->class != ATA_DEV_ATA && -- cgit From 2da4c5e24e86313fc09596ae775123b41055fd54 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Thu, 12 Oct 2023 15:56:34 +0900 Subject: ata: libata-core: Improve ata_dev_power_set_active() Improve the function ata_dev_power_set_active() by having it do nothing for a disk that is already in the active power state. To do that, introduce the function ata_dev_power_is_active() to test the current power state of the disk and return true if the disk is in the PM0: active or PM1: idle state (0xff value for the count field of the CHECK POWER MODE command output). To preserve the existing behavior, if the CHECK POWER MODE command issued in ata_dev_power_is_active() fails, the drive is assumed to be in standby mode and false is returned. With this change, issuing the VERIFY command to access the disk media to spin it up becomes unnecessary most of the time during system resume as the port reset done by libata-eh on resume often result in the drive to spin-up (this behavior is not clearly defined by the ACS specifications and may thus vary between disk models). Signed-off-by: Damien Le Moal Tested-by: Geert Uytterhoeven Reviewed-by: Niklas Cassel --- drivers/ata/libata-core.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 83613280928b..6fb4e8dc8c3c 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2042,6 +2042,33 @@ void ata_dev_power_set_standby(struct ata_device *dev) err_mask); } +static bool ata_dev_power_is_active(struct ata_device *dev) +{ + struct ata_taskfile tf; + unsigned int err_mask; + + ata_tf_init(dev, &tf); + tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; + tf.protocol = ATA_PROT_NODATA; + tf.command = ATA_CMD_CHK_POWER; + + err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); + if (err_mask) { + ata_dev_err(dev, "Check power mode failed (err_mask=0x%x)\n", + err_mask); + /* + * Assume we are in standby mode so that we always force a + * spinup in ata_dev_power_set_active(). + */ + return false; + } + + ata_dev_dbg(dev, "Power mode: 0x%02x\n", tf.nsect); + + /* Active or idle */ + return tf.nsect == 0xff; +} + /** * ata_dev_power_set_active - Set a device power mode to active * @dev: target device @@ -2065,6 +2092,13 @@ void ata_dev_power_set_active(struct ata_device *dev) if (!ata_dev_power_init_tf(dev, &tf, true)) return; + /* + * Check the device power state & condition and force a spinup with + * VERIFY command only if the drive is not already ACTIVE or IDLE. + */ + if (ata_dev_power_is_active(dev)) + return; + ata_dev_notice(dev, "Entering active power mode\n"); err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); -- cgit From 0e533cba38011457b51f13b3b5afd33c693bfcca Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Mon, 16 Oct 2023 10:55:54 -0500 Subject: dt-bindings: ata: tegra: Disallow undefined properties Device specific bindings should not allow undefined properties. This is accomplished in json-schema with 'additionalProperties: false'. Signed-off-by: Rob Herring Acked-by: Conor Dooley Signed-off-by: Damien Le Moal --- Documentation/devicetree/bindings/ata/nvidia,tegra-ahci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/ata/nvidia,tegra-ahci.yaml b/Documentation/devicetree/bindings/ata/nvidia,tegra-ahci.yaml index 3c7a2425f3e6..a17297cbefcb 100644 --- a/Documentation/devicetree/bindings/ata/nvidia,tegra-ahci.yaml +++ b/Documentation/devicetree/bindings/ata/nvidia,tegra-ahci.yaml @@ -151,7 +151,7 @@ allOf: - interconnects - power-domains -additionalProperties: true +additionalProperties: false examples: - | -- cgit