Skip to contentSkip to conversation

ahci: handle non-contiguous implemented ports

PATCH New Benedikt Lang 1 participant 1 message Dec 1 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ahci: handle non-contiguous implemented ports

An implemented port can be skipped during SCSI scanning if its physical port index is outside the range derived from CAP.NP.

This issue was found on a device where only SATA port 1 is implemented, with an SSD containing the operating system connected to it. CAP.NP reports 0, which means one supported port. The existing loop only checks port 0 and misses port 1.

This patch uses fls(port_map) to include the highest implemented port index in the initialization and scan range. The range is determined using the larger value of CAP.NP + 1 and fls(port_map).

Tested on hardware with non-contiguous SATA ports, where ports 0 and 2 are not implemented and only port 1 is implemented. With this change, U-Boot successfully detects the SSD on port 1 during SCSI scanning.

Build-tested with mainline U-Boot using qemu_arm64_defconfig.

The Linux kernel AHCI platform driver uses a similar approach to determine the port range. See ahci_platform_init_host() in drivers/ata/libahci_platform.c.

---
 drivers/ata/ahci.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/ata/ahci.c +8 -1
index 38e953ee79cef8773de82bd88199d297a3a133a5..4de13fd7a47bf3726278a68fb7aac3ca852489fc 100644
@@ -188,7 +188,14 @@ static int ahci_host_init(struct ahci_uc_priv *uc_priv)
 	uc_priv->cap = readl(mmio + HOST_CAP);
 	uc_priv->port_map = readl(mmio + HOST_PORTS_IMPL);
 	port_map = uc_priv->port_map;
-	uc_priv->n_ports = (uc_priv->cap & 0x1f) + 1;
+
+	/*
+	 * CAP.NP reports the number of supported ports, while PI may contain
+	 * non-contiguous physical port numbers. Account for the highest
+	 * implemented port when determining the initialization and scan range.
+	 */
+	uc_priv->n_ports = max_t(unsigned int, (uc_priv->cap & 0x1f) + 1,
+				 fls(port_map));
 
 	debug("cap 0x%x  port_map 0x%x  n_ports %d\n",
 	      uc_priv->cap, uc_priv->port_map, uc_priv->n_ports);

---
base-commit: ece349ade2973e220f524ce59e59711cc919263f
change-id: 20261109-ahci-sparse-ports-03e383ebfe4e

Best regards,

Signature · 11 lines
Benedikt Lang
hexDEV GmbH

[email protected]
https://hexdev.de

Sitz der Gesellschaft:  Stuttgart
Registergericht: Amtsgericht Stuttgart, HRB 777539
Anschrift: Sautterweg 20, 70565 Stuttgart
Geschäftsführer: Christoph Fritz, Konstantin Hristozov
USt-IdNr.: DE340452004