]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ata: libata-acpi: Do not assume 40 wire cable if no devices are enabled
authorTasos Sahanidis <tasos@tasossah.com>
Mon, 19 May 2025 08:56:55 +0000 (11:56 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Jul 2025 13:59:49 +0000 (15:59 +0200)
[ Upstream commit 33877220b8641b4cde474a4229ea92c0e3637883 ]

On at least an ASRock 990FX Extreme 4 with a VIA VT6330, the devices
have not yet been enabled by the first time ata_acpi_cbl_80wire() is
called. This means that the ata_for_each_dev loop is never entered,
and a 40 wire cable is assumed.

The VIA controller on this board does not report the cable in the PCI
config space, thus having to fall back to ACPI even though no SATA
bridge is present.

The _GTM values are correctly reported by the firmware through ACPI,
which has already set up faster transfer modes, but due to the above
the controller is forced down to a maximum of UDMA/33.

Resolve this by modifying ata_acpi_cbl_80wire() to directly return the
cable type. First, an unknown cable is assumed which preserves the mode
set by the firmware, and then on subsequent calls when the devices have
been enabled, an 80 wire cable is correctly detected.

Since the function now directly returns the cable type, it is renamed
to ata_acpi_cbl_pata_type().

Signed-off-by: Tasos Sahanidis <tasos@tasossah.com>
Link: https://lore.kernel.org/r/20250519085945.1399466-1-tasos@tasossah.com
Signed-off-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/ata/libata-acpi.c
drivers/ata/pata_via.c
include/linux/libata.h

index 61b4ccf88bf1e6afae9281d76de18b71b17df015..1ad682d88c866d58207645327738e5d099ee79a6 100644 (file)
@@ -514,15 +514,19 @@ unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
 EXPORT_SYMBOL_GPL(ata_acpi_gtm_xfermask);
 
 /**
- * ata_acpi_cbl_80wire         -       Check for 80 wire cable
+ * ata_acpi_cbl_pata_type - Return PATA cable type
  * @ap: Port to check
- * @gtm: GTM data to use
  *
- * Return 1 if the @gtm indicates the BIOS selected an 80wire mode.
+ * Return ATA_CBL_PATA* according to the transfer mode selected by BIOS
  */
-int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm)
+int ata_acpi_cbl_pata_type(struct ata_port *ap)
 {
        struct ata_device *dev;
+       int ret = ATA_CBL_PATA_UNK;
+       const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
+
+       if (!gtm)
+               return ATA_CBL_PATA40;
 
        ata_for_each_dev(dev, &ap->link, ENABLED) {
                unsigned int xfer_mask, udma_mask;
@@ -530,13 +534,17 @@ int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm)
                xfer_mask = ata_acpi_gtm_xfermask(dev, gtm);
                ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask);
 
-               if (udma_mask & ~ATA_UDMA_MASK_40C)
-                       return 1;
+               ret = ATA_CBL_PATA40;
+
+               if (udma_mask & ~ATA_UDMA_MASK_40C) {
+                       ret = ATA_CBL_PATA80;
+                       break;
+               }
        }
 
-       return 0;
+       return ret;
 }
-EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire);
+EXPORT_SYMBOL_GPL(ata_acpi_cbl_pata_type);
 
 static void ata_acpi_gtf_to_tf(struct ata_device *dev,
                               const struct ata_acpi_gtf *gtf,
index 5e2666b71aaff648a61fef8755227267fe5cb302..31d39038f020f5d096f6895a2541c4ee3ee4364a 100644 (file)
@@ -201,11 +201,9 @@ static int via_cable_detect(struct ata_port *ap) {
           two drives */
        if (ata66 & (0x10100000 >> (16 * ap->port_no)))
                return ATA_CBL_PATA80;
+
        /* Check with ACPI so we can spot BIOS reported SATA bridges */
-       if (ata_acpi_init_gtm(ap) &&
-           ata_acpi_cbl_80wire(ap, ata_acpi_init_gtm(ap)))
-               return ATA_CBL_PATA80;
-       return ATA_CBL_PATA40;
+       return ata_acpi_cbl_pata_type(ap);
 }
 
 static int via_pre_reset(struct ata_link *link, unsigned long deadline)
index 6645259be1438d385386141f41691c210a0d094c..363462d3f077393ebf940aaed750297f0ddc44c2 100644 (file)
@@ -1293,7 +1293,7 @@ int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
 int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
 unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
                                   const struct ata_acpi_gtm *gtm);
-int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
+int ata_acpi_cbl_pata_type(struct ata_port *ap);
 #else
 static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
 {
@@ -1318,10 +1318,9 @@ static inline unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
        return 0;
 }
 
-static inline int ata_acpi_cbl_80wire(struct ata_port *ap,
-                                     const struct ata_acpi_gtm *gtm)
+static inline int ata_acpi_cbl_pata_type(struct ata_port *ap)
 {
-       return 0;
+       return ATA_CBL_PATA40;
 }
 #endif