--- /dev/null
+From 130ff5c8b78e6fd05270a04985c50bce6a3de6c1 Mon Sep 17 00:00:00 2001
+From: Niklas Cassel <cassel@kernel.org>
+Date: Tue, 25 Feb 2025 15:16:12 +0100
+Subject: ata: ahci: Make ahci_ignore_port() handle empty mask_port_map
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Niklas Cassel <cassel@kernel.org>
+
+commit 130ff5c8b78e6fd05270a04985c50bce6a3de6c1 upstream.
+
+Commit 8c87215dd3a2 ("ata: libahci_platform: support non-consecutive port
+numbers") added a skip to ahci_platform_enable_phys() for ports that are
+not in mask_port_map.
+
+The code in ahci_platform_get_resources(), will currently set mask_port_map
+for each child "port" node it finds in the device tree.
+
+However, device trees that do not have any child "port" nodes will not have
+mask_port_map set, and for non-device tree platforms mask_port_map will
+only exist as a quirk for specific PCI device + vendor IDs, or as a kernel
+module parameter, but will not be set by default.
+
+Therefore, the common thing is that mask_port_map is only set if you do not
+want to use all ports (as defined by Offset 0Ch: PI – Ports Implemented
+register), but instead only want to use the ports in mask_port_map. If
+mask_port_map is not set, all ports are available.
+
+Thus, ahci_ignore_port() must be able to handle an empty mask_port_map.
+
+Fixes: 8c87215dd3a2 ("ata: libahci_platform: support non-consecutive port numbers")
+Fixes: 2c202e6c4f4d ("ata: libahci_platform: Do not set mask_port_map when not needed")
+Fixes: c9b5be909e65 ("ahci: Introduce ahci_ignore_port() helper")
+Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
+Closes: https://lore.kernel.org/linux-ide/10b31dd0-d0bb-4f76-9305-2195c3e17670@samsung.com/
+Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
+Co-developed-by: Damien Le Moal <dlemoal@kernel.org>
+Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
+Link: https://lore.kernel.org/r/20250225141612.942170-2-cassel@kernel.org
+Signed-off-by: Niklas Cassel <cassel@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/ata/ahci.h | 8 ++++++--
+ drivers/ata/libahci.c | 1 +
+ 2 files changed, 7 insertions(+), 2 deletions(-)
+
+--- a/drivers/ata/ahci.h
++++ b/drivers/ata/ahci.h
+@@ -388,8 +388,12 @@ struct ahci_host_priv {
+ static inline bool ahci_ignore_port(struct ahci_host_priv *hpriv,
+ unsigned int portid)
+ {
+- return portid >= hpriv->nports ||
+- !(hpriv->mask_port_map & (1 << portid));
++ if (portid >= hpriv->nports)
++ return true;
++ /* mask_port_map not set means that all ports are available */
++ if (!hpriv->mask_port_map)
++ return false;
++ return !(hpriv->mask_port_map & (1 << portid));
+ }
+
+ extern int ahci_ignore_sss;
+--- a/drivers/ata/libahci.c
++++ b/drivers/ata/libahci.c
+@@ -541,6 +541,7 @@ void ahci_save_initial_config(struct dev
+ hpriv->saved_port_map = port_map;
+ }
+
++ /* mask_port_map not set means that all ports are available */
+ if (hpriv->mask_port_map) {
+ dev_warn(dev, "masking port_map 0x%lx -> 0x%lx\n",
+ port_map,
--- /dev/null
+From 2c202e6c4f4dd19d2e8c1dfac9df05170aa3934f Mon Sep 17 00:00:00 2001
+From: Damien Le Moal <dlemoal@kernel.org>
+Date: Sat, 8 Feb 2025 08:29:15 +0900
+Subject: ata: libahci_platform: Do not set mask_port_map when not needed
+
+From: Damien Le Moal <dlemoal@kernel.org>
+
+commit 2c202e6c4f4dd19d2e8c1dfac9df05170aa3934f upstream.
+
+Commit 8c87215dd3a2 ("ata: libahci_platform: support non-consecutive
+port numbers") modified ahci_platform_get_resources() to allow
+identifying the ports of a controller that are defined as child nodes of
+the controller node in order to support non-consecutive port numbers (as
+defined by the platform device tree).
+
+However, this commit also erroneously sets bit 0 of
+hpriv->mask_port_map when the platform devices tree does not define port
+child nodes, to match the fact that the temporary default number of
+ports used in that case is 1 (which is also consistent with the fact
+that only index 0 of hpriv->phys[] is initialized with the call to
+ahci_platform_get_phy(). But doing so causes ahci_platform_init_host()
+to initialize and probe only the first port, even if this function
+determines that the controller has in fact multiple ports using the
+capability register of the controller (through a call to
+ahci_nr_ports()). This can be seen with the ahci_mvebu driver (Armada
+385 SoC) with the second port declared as "dummy":
+
+ahci-mvebu f10a8000.sata: masking port_map 0x3 -> 0x1
+ahci-mvebu f10a8000.sata: AHCI vers 0001.0000, 32 command slots, 6 Gbps, platform mode
+ahci-mvebu f10a8000.sata: 1/2 ports implemented (port mask 0x1)
+ahci-mvebu f10a8000.sata: flags: 64bit ncq sntf led only pmp fbs pio slum part sxs
+scsi host0: ahci-mvebu
+scsi host1: ahci-mvebu
+ata1: SATA max UDMA/133 mmio [mem 0xf10a8000-0xf10a9fff] port 0x100 irq 40 lpm-pol 0
+ata2: DUMMY
+
+Fix this issue by removing setting bit 0 of hpriv->mask_port_map when
+the platform device tree does not define port child nodes.
+
+Reported-by: Klaus Kudielka <klaus.kudielka@gmail.com>
+Fixes: 8c87215dd3a2 ("ata: libahci_platform: support non-consecutive port numbers")
+Tested-by: Klaus Kudielka <klaus.kudielka@gmail.com>
+Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
+Acked-by: Josua Mayer <josua@solid-run.com>
+Link: https://lore.kernel.org/r/20250207232915.1439174-1-dlemoal@kernel.org
+Signed-off-by: Niklas Cassel <cassel@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/ata/libahci_platform.c | 2 --
+ 1 file changed, 2 deletions(-)
+
+--- a/drivers/ata/libahci_platform.c
++++ b/drivers/ata/libahci_platform.c
+@@ -660,8 +660,6 @@ struct ahci_host_priv *ahci_platform_get
+ * If no sub-node was found, keep this for device tree
+ * compatibility
+ */
+- hpriv->mask_port_map |= BIT(0);
+-
+ rc = ahci_platform_get_phy(hpriv, 0, dev, dev->of_node);
+ if (rc)
+ goto err_out;