Skip to content

Commit da9a548

Browse files
tatokisgregkh
authored andcommitted
ata: libata-acpi: Do not assume 40 wire cable if no devices are enabled
[ 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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ac6fd02 commit da9a548

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

drivers/ata/libata-acpi.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,29 +514,37 @@ unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
514514
EXPORT_SYMBOL_GPL(ata_acpi_gtm_xfermask);
515515

516516
/**
517-
* ata_acpi_cbl_80wire - Check for 80 wire cable
517+
* ata_acpi_cbl_pata_type - Return PATA cable type
518518
* @ap: Port to check
519-
* @gtm: GTM data to use
520519
*
521-
* Return 1 if the @gtm indicates the BIOS selected an 80wire mode.
520+
* Return ATA_CBL_PATA* according to the transfer mode selected by BIOS
522521
*/
523-
int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm)
522+
int ata_acpi_cbl_pata_type(struct ata_port *ap)
524523
{
525524
struct ata_device *dev;
525+
int ret = ATA_CBL_PATA_UNK;
526+
const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
527+
528+
if (!gtm)
529+
return ATA_CBL_PATA40;
526530

527531
ata_for_each_dev(dev, &ap->link, ENABLED) {
528532
unsigned int xfer_mask, udma_mask;
529533

530534
xfer_mask = ata_acpi_gtm_xfermask(dev, gtm);
531535
ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask);
532536

533-
if (udma_mask & ~ATA_UDMA_MASK_40C)
534-
return 1;
537+
ret = ATA_CBL_PATA40;
538+
539+
if (udma_mask & ~ATA_UDMA_MASK_40C) {
540+
ret = ATA_CBL_PATA80;
541+
break;
542+
}
535543
}
536544

537-
return 0;
545+
return ret;
538546
}
539-
EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire);
547+
EXPORT_SYMBOL_GPL(ata_acpi_cbl_pata_type);
540548

541549
static void ata_acpi_gtf_to_tf(struct ata_device *dev,
542550
const struct ata_acpi_gtf *gtf,

drivers/ata/pata_via.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,9 @@ static int via_cable_detect(struct ata_port *ap) {
201201
two drives */
202202
if (ata66 & (0x10100000 >> (16 * ap->port_no)))
203203
return ATA_CBL_PATA80;
204+
204205
/* Check with ACPI so we can spot BIOS reported SATA bridges */
205-
if (ata_acpi_init_gtm(ap) &&
206-
ata_acpi_cbl_80wire(ap, ata_acpi_init_gtm(ap)))
207-
return ATA_CBL_PATA80;
208-
return ATA_CBL_PATA40;
206+
return ata_acpi_cbl_pata_type(ap);
209207
}
210208

211209
static int via_pre_reset(struct ata_link *link, unsigned long deadline)

include/linux/libata.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
12931293
int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
12941294
unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
12951295
const struct ata_acpi_gtm *gtm);
1296-
int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
1296+
int ata_acpi_cbl_pata_type(struct ata_port *ap);
12971297
#else
12981298
static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
12991299
{
@@ -1318,10 +1318,9 @@ static inline unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
13181318
return 0;
13191319
}
13201320

1321-
static inline int ata_acpi_cbl_80wire(struct ata_port *ap,
1322-
const struct ata_acpi_gtm *gtm)
1321+
static inline int ata_acpi_cbl_pata_type(struct ata_port *ap)
13231322
{
1324-
return 0;
1323+
return ATA_CBL_PATA40;
13251324
}
13261325
#endif
13271326

0 commit comments

Comments
 (0)