diff mbox series

[PATCHv2] pci: layerscape: Fix the LUT and msi-map mismatch issue

Message ID 20210910074240.3719-1-Zhiqiang.Hou@nxp.com
State Awaiting Upstream
Delegated to: Priyanka Jain
Headers show
Series [PATCHv2] pci: layerscape: Fix the LUT and msi-map mismatch issue | expand

Commit Message

Z.Q. Hou Sept. 10, 2021, 7:42 a.m. UTC
From: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>

In the current code, it doesn't reset the cursors of LUT entry and
StreamID at the beginning of the fixup, so it can result in LUT entry
setup and msi-map mismatch and LUT entries and StreamID leaking
when reload and fixup the DTB.
This patch move the initialization of LUT entry and StreamID cursors
to the beginning of the fixup to resolve the issues.

Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
---
V2:
 - Add fix for gen4 driver.

 drivers/pci/pcie_layerscape_fixup.c        | 8 +++++++-
 drivers/pci/pcie_layerscape_fixup_common.c | 6 +++---
 drivers/pci/pcie_layerscape_gen4.c         | 4 +---
 drivers/pci/pcie_layerscape_gen4_fixup.c   | 5 ++++-
 drivers/pci/pcie_layerscape_rc.c           | 3 +--
 5 files changed, 16 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/pcie_layerscape_fixup.c b/drivers/pci/pcie_layerscape_fixup.c
index a58e7a3892..8a2a0e1f4a 100644
--- a/drivers/pci/pcie_layerscape_fixup.c
+++ b/drivers/pci/pcie_layerscape_fixup.c
@@ -1,6 +1,6 @@ 
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2017-2020 NXP
+ * Copyright 2017-2021 NXP
  * Copyright 2014-2015 Freescale Semiconductor, Inc.
  * Layerscape PCIe driver
  */
@@ -24,6 +24,8 @@ 
 #include "pcie_layerscape.h"
 #include "pcie_layerscape_fixup_common.h"
 
+int next_stream_id;
+
 static int fdt_pcie_get_nodeoffset(void *blob, struct ls_pcie_rc *pcie_rc)
 {
 	int nodeoffset;
@@ -607,6 +609,9 @@  static void ft_pcie_ls_setup(void *blob, struct ls_pcie_rc *pcie_rc)
 {
 	ft_pcie_ep_fix(blob, pcie_rc);
 	ft_pcie_rc_fix(blob, pcie_rc);
+
+	pcie_rc->stream_id_cur = 0;
+	pcie_rc->next_lut_index = 0;
 }
 
 /* Fixup Kernel DT for PCIe */
@@ -618,6 +623,7 @@  void ft_pci_setup_ls(void *blob, struct bd_info *bd)
 		ft_pcie_ls_setup(blob, pcie_rc);
 
 #if defined(CONFIG_FSL_LSCH3) || defined(CONFIG_FSL_LSCH2)
+	next_stream_id = FSL_PEX_STREAM_ID_START;
 	fdt_fixup_pcie_ls(blob);
 #endif
 }
diff --git a/drivers/pci/pcie_layerscape_fixup_common.c b/drivers/pci/pcie_layerscape_fixup_common.c
index 8b924d404c..257b4241a9 100644
--- a/drivers/pci/pcie_layerscape_fixup_common.c
+++ b/drivers/pci/pcie_layerscape_fixup_common.c
@@ -1,6 +1,6 @@ 
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2019-2020 NXP
+ * Copyright 2019-2021 NXP
  *
  * PCIe DT fixup for NXP Layerscape SoCs
  * Author: Wasim Khan <wasim.khan@nxp.com>
@@ -14,6 +14,8 @@ 
 #include <linux/libfdt.h>
 #include "pcie_layerscape_fixup_common.h"
 
+extern int next_stream_id;
+
 void ft_pci_setup(void *blob, struct bd_info *bd)
 {
 #if defined(CONFIG_PCIE_LAYERSCAPE_GEN4)
@@ -146,8 +148,6 @@  int pcie_next_streamid(int currentid, int idx)
 /* returns the next available streamid for pcie, -errno if failed */
 int pcie_next_streamid(int currentid, int idx)
 {
-	static int next_stream_id = FSL_PEX_STREAM_ID_START;
-
 	if (next_stream_id > FSL_PEX_STREAM_ID_END)
 		return -EINVAL;
 
diff --git a/drivers/pci/pcie_layerscape_gen4.c b/drivers/pci/pcie_layerscape_gen4.c
index 255e73181d..6ecdd6af40 100644
--- a/drivers/pci/pcie_layerscape_gen4.c
+++ b/drivers/pci/pcie_layerscape_gen4.c
@@ -1,6 +1,6 @@ 
 // SPDX-License-Identifier: GPL-2.0+ OR X11
 /*
- * Copyright 2018-2020 NXP
+ * Copyright 2018-2021 NXP
  *
  * PCIe Gen4 driver for NXP Layerscape SoCs
  * Author: Hou Zhiqiang <Minder.Hou@gmail.com>
@@ -305,8 +305,6 @@  static void ls_pcie_g4_setup_ctrl(struct ls_pcie_g4 *pcie)
 	ccsr_writel(pcie, PAB_AXI_PIO_CTRL(0), val);
 
 	ls_pcie_g4_setup_wins(pcie);
-
-	pcie->stream_id_cur = 0;
 }
 
 static void ls_pcie_g4_ep_inbound_win_set(struct ls_pcie_g4 *pcie, int pf,
diff --git a/drivers/pci/pcie_layerscape_gen4_fixup.c b/drivers/pci/pcie_layerscape_gen4_fixup.c
index e9ee15558e..7d11234106 100644
--- a/drivers/pci/pcie_layerscape_gen4_fixup.c
+++ b/drivers/pci/pcie_layerscape_gen4_fixup.c
@@ -1,6 +1,6 @@ 
 // SPDX-License-Identifier: GPL-2.0+ OR X11
 /*
- * Copyright 2018-2020 NXP
+ * Copyright 2018-2021 NXP
  *
  * PCIe Gen4 driver for NXP Layerscape SoCs
  * Author: Hou Zhiqiang <Minder.Hou@gmail.com>
@@ -223,6 +223,9 @@  static void ft_pcie_layerscape_gen4_setup(void *blob, struct ls_pcie_g4 *pcie)
 {
 	ft_pcie_rc_layerscape_gen4_fix(blob, pcie);
 	ft_pcie_ep_layerscape_gen4_fix(blob, pcie);
+
+	pcie->stream_id_cur = 0;
+	pcie->next_lut_index = 0;
 }
 
 /* Fixup Kernel DT for PCIe */
diff --git a/drivers/pci/pcie_layerscape_rc.c b/drivers/pci/pcie_layerscape_rc.c
index bd2c19f7f0..5dc71fc75a 100644
--- a/drivers/pci/pcie_layerscape_rc.c
+++ b/drivers/pci/pcie_layerscape_rc.c
@@ -1,6 +1,6 @@ 
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2020 NXP
+ * Copyright 2020,2021 NXP
  * Layerscape PCIe driver
  */
 
@@ -238,7 +238,6 @@  static void ls_pcie_setup_ctrl(struct ls_pcie_rc *pcie_rc)
 	ls_pcie_dbi_ro_wr_dis(pcie);
 
 	ls_pcie_disable_bars(pcie_rc);
-	pcie_rc->stream_id_cur = 0;
 }
 
 static int ls_pcie_probe(struct udevice *dev)