public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sasha Levin <sashal@kernel.org>
Cc: pali@kernel.org, stable@vger.kernel.org,
	"Marek Behún" <kabel@kernel.org>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>
Subject: [PATCH 5.4 18/22] PCI: aardvark: Fix support for bus mastering and PCI_COMMAND on emulated bridge
Date: Thu, 25 Nov 2021 01:26:12 +0100	[thread overview]
Message-ID: <20211125002616.31363-19-kabel@kernel.org> (raw)
In-Reply-To: <20211125002616.31363-1-kabel@kernel.org>

From: Pali Rohár <pali@kernel.org>

commit 771153fc884f566a89af2d30033b7f3bc6e24e84 upstream.

From very vague, ambiguous and incomplete information from Marvell we
deduced that the 32-bit Aardvark register at address 0x4
(PCIE_CORE_CMD_STATUS_REG), which is not documented for Root Complex mode
in the Functional Specification (only for Endpoint mode), controls two
16-bit PCIe registers: Command Register and Status Registers of PCIe Root
Port.

This means that bit 2 controls bus mastering and forwarding of memory and
I/O requests in the upstream direction. According to PCI specifications
bits [0:2] of Command Register, this should be by default disabled on
reset. So explicitly disable these bits at early setup of the Aardvark
driver.

Remove code which unconditionally enables all 3 bits and let kernel code
(via pci_set_master() function) to handle bus mastering of Root PCIe
Bridge via emulated PCI_COMMAND on emulated bridge.

Link: https://lore.kernel.org/r/20211028185659.20329-5-kabel@kernel.org
Fixes: 8a3ebd8de328 ("PCI: aardvark: Implement emulated root PCI bridge config space")
Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Behún <kabel@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: stable@vger.kernel.org # b2a56469d550 ("PCI: aardvark: Add FIXME comment for PCIE_CORE_CMD_STATUS_REG access")
Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/pci/controller/pci-aardvark.c | 47 ++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index 5898e55426c4..2fe6b3aa8919 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -27,9 +27,6 @@
 /* PCIe core registers */
 #define PCIE_CORE_DEV_ID_REG					0x0
 #define PCIE_CORE_CMD_STATUS_REG				0x4
-#define     PCIE_CORE_CMD_IO_ACCESS_EN				BIT(0)
-#define     PCIE_CORE_CMD_MEM_ACCESS_EN				BIT(1)
-#define     PCIE_CORE_CMD_MEM_IO_REQ_EN				BIT(2)
 #define PCIE_CORE_DEV_REV_REG					0x8
 #define PCIE_CORE_PCIEXP_CAP					0xc0
 #define PCIE_CORE_ERR_CAPCTL_REG				0x118
@@ -505,6 +502,11 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
 	reg = (PCI_VENDOR_ID_MARVELL << 16) | PCI_VENDOR_ID_MARVELL;
 	advk_writel(pcie, reg, VENDOR_ID_REG);
 
+	/* Disable Root Bridge I/O space, memory space and bus mastering */
+	reg = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG);
+	reg &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
+	advk_writel(pcie, reg, PCIE_CORE_CMD_STATUS_REG);
+
 	/* Set Advanced Error Capabilities and Control PF0 register */
 	reg = PCIE_CORE_ERR_CAPCTL_ECRC_CHK_TX |
 		PCIE_CORE_ERR_CAPCTL_ECRC_CHK_TX_EN |
@@ -603,12 +605,6 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
 		advk_pcie_disable_ob_win(pcie, i);
 
 	advk_pcie_train_link(pcie);
-
-	reg = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG);
-	reg |= PCIE_CORE_CMD_MEM_ACCESS_EN |
-		PCIE_CORE_CMD_IO_ACCESS_EN |
-		PCIE_CORE_CMD_MEM_IO_REQ_EN;
-	advk_writel(pcie, reg, PCIE_CORE_CMD_STATUS_REG);
 }
 
 static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u32 *val)
@@ -737,6 +733,37 @@ static int advk_pcie_wait_pio(struct advk_pcie *pcie)
 	return -ETIMEDOUT;
 }
 
+static pci_bridge_emul_read_status_t
+advk_pci_bridge_emul_base_conf_read(struct pci_bridge_emul *bridge,
+				    int reg, u32 *value)
+{
+	struct advk_pcie *pcie = bridge->data;
+
+	switch (reg) {
+	case PCI_COMMAND:
+		*value = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG);
+		return PCI_BRIDGE_EMUL_HANDLED;
+
+	default:
+		return PCI_BRIDGE_EMUL_NOT_HANDLED;
+	}
+}
+
+static void
+advk_pci_bridge_emul_base_conf_write(struct pci_bridge_emul *bridge,
+				     int reg, u32 old, u32 new, u32 mask)
+{
+	struct advk_pcie *pcie = bridge->data;
+
+	switch (reg) {
+	case PCI_COMMAND:
+		advk_writel(pcie, new, PCIE_CORE_CMD_STATUS_REG);
+		break;
+
+	default:
+		break;
+	}
+}
 
 static pci_bridge_emul_read_status_t
 advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
@@ -838,6 +865,8 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
 }
 
 static struct pci_bridge_emul_ops advk_pci_bridge_emul_ops = {
+	.read_base = advk_pci_bridge_emul_base_conf_read,
+	.write_base = advk_pci_bridge_emul_base_conf_write,
 	.read_pcie = advk_pci_bridge_emul_pcie_conf_read,
 	.write_pcie = advk_pci_bridge_emul_pcie_conf_write,
 };
-- 
2.32.0


  parent reply	other threads:[~2021-11-25  0:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-25  0:25 [PATCH 5.4 00/22] Armada 3720 PCIe fixes for 5.4 Marek Behún
2021-11-25  0:25 ` [PATCH 5.4 01/22] PCI: aardvark: Wait for endpoint to be ready before training link Marek Behún
2021-11-25  0:25 ` [PATCH 5.4 02/22] PCI: aardvark: Fix big endian support Marek Behún
2021-11-25  0:25 ` [PATCH 5.4 03/22] PCI: aardvark: Train link immediately after enabling training Marek Behún
2021-11-25  0:25 ` [PATCH 5.4 04/22] PCI: aardvark: Improve link training Marek Behún
2021-11-25  0:25 ` [PATCH 5.4 05/22] PCI: aardvark: Issue PERST via GPIO Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 06/22] PCI: aardvark: Replace custom macros by standard linux/pci_regs.h macros Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 07/22] PCI: aardvark: Don't touch PCIe registers if no card connected Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 08/22] PCI: aardvark: Fix compilation on s390 Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 09/22] PCI: aardvark: Move PCIe reset card code to advk_pcie_train_link() Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 10/22] PCI: aardvark: Update comment about disabling link training Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 11/22] PCI: pci-bridge-emul: Fix array overruns, improve safety Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 12/22] PCI: aardvark: Configure PCIe resources from 'ranges' DT property Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 13/22] PCI: aardvark: Fix PCIe Max Payload Size setting Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 14/22] PCI: aardvark: Deduplicate code in advk_pcie_rd_conf() Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 15/22] PCI: aardvark: Implement re-issuing config requests on CRS response Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 16/22] PCI: aardvark: Simplify initialization of rootcap on virtual bridge Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 17/22] PCI: aardvark: Fix link training Marek Behún
2021-11-25  0:26 ` Marek Behún [this message]
2021-11-25  0:26 ` [PATCH 5.4 19/22] PCI: aardvark: Set PCI Bridge Class Code to PCI Bridge Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 20/22] PCI: aardvark: Fix support for PCI_BRIDGE_CTL_BUS_RESET on emulated bridge Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 21/22] pinctrl: armada-37xx: Correct PWM pins definitions Marek Behún
2021-11-25  0:26 ` [PATCH 5.4 22/22] arm64: dts: marvell: armada-37xx: Set pcie_reset_pin to gpio function Marek Behún
2021-11-28 13:00 ` [PATCH 5.4 00/22] Armada 3720 PCIe fixes for 5.4 Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211125002616.31363-19-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=pali@kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox