ahci: handle non-contiguous implemented ports
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
@@ -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