From patchwork Sun Oct 31 18:12:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12595439 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50F7EC433EF for ; Sun, 31 Oct 2021 18:12:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20A1160E98 for ; Sun, 31 Oct 2021 18:12:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229853AbhJaSPN (ORCPT ); Sun, 31 Oct 2021 14:15:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:60430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229898AbhJaSPK (ORCPT ); Sun, 31 Oct 2021 14:15:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 618BD60F45; Sun, 31 Oct 2021 18:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635703958; bh=7dWtS7IabxxufChgE1lrOYtnRbIhcoqfnxK0McNkq24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLy6yAthvy38X+aTHC9r+BCkcY1HQOlTSkNBmRDh6dlekg2a31qSTotZSxHUusgPo sHHRvOHiPmb8XFIwJghrGDJX8g7ebFur725naPux1rza8CNxK/RJaJWbiRcGXG17Lz gltU0S8o7CqNzabkvv+c6ihjeEH35rnwzrYS71CR2sIJetxPLIoVbaTkJJP0adocRH fByYs0A5wIV33RrbyUZgqvu8zMoQ2pv1wYbpFt3tw3ow8UWB/laJ3AbDPPO24M1TGp cXXS/YS5rEOCJfbOUHfKViGfn54i0w2vIsjU2p9QTW4T/rd+V26QQPBWt7idJWsWEE CYAUxKr+2/UfQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, pali@kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 1/7] PCI: pci-bridge-emul: Add description for class_revision field Date: Sun, 31 Oct 2021 19:12:27 +0100 Message-Id: <20211031181233.9976-2-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211031181233.9976-1-kabel@kernel.org> References: <20211031181233.9976-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Pali Rohár The current assignment to the class_revision member class_revision |= cpu_to_le32(PCI_CLASS_BRIDGE_PCI << 16); can make the reader think that class is at high 16 bits of the member and revision at low 16 bits. In reality, class is at high 24 bits, but the class for PCI Bridge Normal Decode is PCI_CLASS_BRIDGE_PCI << 8. Change the assignment and add a comment to make this clearer. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún --- drivers/pci/pci-bridge-emul.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-bridge-emul.c b/drivers/pci/pci-bridge-emul.c index db97cddfc85e..a4af1a533d71 100644 --- a/drivers/pci/pci-bridge-emul.c +++ b/drivers/pci/pci-bridge-emul.c @@ -265,7 +265,11 @@ int pci_bridge_emul_init(struct pci_bridge_emul *bridge, { BUILD_BUG_ON(sizeof(bridge->conf) != PCI_BRIDGE_CONF_END); - bridge->conf.class_revision |= cpu_to_le32(PCI_CLASS_BRIDGE_PCI << 16); + /* + * class_revision: Class is high 24 bits and revision is low 8 bit of this member, + * while class for PCI Bridge Normal Decode has the 24-bit value: PCI_CLASS_BRIDGE_PCI << 8 + */ + bridge->conf.class_revision |= cpu_to_le32((PCI_CLASS_BRIDGE_PCI << 8) << 8); bridge->conf.header_type = PCI_HEADER_TYPE_BRIDGE; bridge->conf.cache_line_size = 0x10; bridge->conf.status = cpu_to_le16(PCI_STATUS_CAP_LIST); From patchwork Sun Oct 31 18:12:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12595441 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ACE2C433FE for ; Sun, 31 Oct 2021 18:12:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD3CD61076 for ; Sun, 31 Oct 2021 18:12:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbhJaSPN (ORCPT ); Sun, 31 Oct 2021 14:15:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:60438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbhJaSPM (ORCPT ); Sun, 31 Oct 2021 14:15:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9EEC760FD9; Sun, 31 Oct 2021 18:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635703959; bh=xeJkfWErmROj9EmP/rG5eXcTOcFyWTWYURdeAcOO5mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYBsrKO3gNRsETbrpzlZjC7xlWFVLctNImvmi46DqkIEAdBXiYb37V80cxaKTm3py oRHVK28+pygQIzwAp23ygthMi6ePqGiDXYy8k0o7OjuSCy6DJINbWU/uQh6MElqqex iyVqvIpMDAgMJ0gS/2eNP0XWaQGFWTGNbj97fXc0hatA9DP/AcV2UVjTcPHmLFQldS +1hG5lvSq868goKRr/oZKw01UxaEP4gD1HZCl75mo0lDF77P7d/dvZFlVee7zE7wk/ XyWLP3KYP7fmCxbVlZznRwDsiZDQKEyDLMx0leyERhO2uBZ2jutk7jmDEX7dca9aK0 UL70CpSml5Dig== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, pali@kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 2/7] PCI: pci-bridge-emul: Add definitions for missing capabilities registers Date: Sun, 31 Oct 2021 19:12:28 +0100 Message-Id: <20211031181233.9976-3-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211031181233.9976-1-kabel@kernel.org> References: <20211031181233.9976-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Pali Rohár pci-bridge-emul driver already allocates buffer for capabilities up to the PCI_EXP_SLTSTA2 register, but does not define bit access behavior for these registers. Add these missing definitions. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Cc: stable@vger.kernel.org --- drivers/pci/pci-bridge-emul.c | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/pci/pci-bridge-emul.c b/drivers/pci/pci-bridge-emul.c index a4af1a533d71..aa3320e3c469 100644 --- a/drivers/pci/pci-bridge-emul.c +++ b/drivers/pci/pci-bridge-emul.c @@ -251,6 +251,45 @@ struct pci_bridge_reg_behavior pcie_cap_regs_behavior[PCI_CAP_PCIE_SIZEOF / 4] = .ro = GENMASK(15, 0) | PCI_EXP_RTSTA_PENDING, .w1c = PCI_EXP_RTSTA_PME, }, + + [PCI_EXP_DEVCAP2 / 4] = { + /* Device capabilities 2 register has reserved bits [30:27]. */ + .ro = BIT(31) | GENMASK(26, 0), + }, + + [PCI_EXP_DEVCTL2 / 4] = { + /* + * Device control 2 register is RW. + * + * Device status 2 register is reserved. + */ + .rw = GENMASK(15, 0), + }, + + [PCI_EXP_LNKCAP2 / 4] = { + /* Link capabilities 2 register has reserved bits [30:25] and 0. */ + .ro = BIT(31) | GENMASK(24, 1), + }, + + [PCI_EXP_LNKCTL2 / 4] = { + /* + * Link control 2 register is RW. + * + * Link status 2 register has bits 5, 15 W1C; + * bits 10, 11 reserved and others are RO. + */ + .rw = GENMASK(15, 0), + .w1c = (BIT(15) | BIT(5)) << 16, + .ro = (GENMASK(14, 12) | GENMASK(9, 6) | GENMASK(4, 0)) << 16, + }, + + [PCI_EXP_SLTCAP2 / 4] = { + /* Slot capabilities 2 register is reserved. */ + }, + + [PCI_EXP_SLTCTL2 / 4] = { + /* Both Slot control 2 and Slot status 2 registers are reserved. */ + }, }; /* From patchwork Sun Oct 31 18:12:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12595443 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C23DCC4332F for ; Sun, 31 Oct 2021 18:12:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CBF46108B for ; Sun, 31 Oct 2021 18:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230316AbhJaSPN (ORCPT ); Sun, 31 Oct 2021 14:15:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:60446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbhJaSPM (ORCPT ); Sun, 31 Oct 2021 14:15:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DB9366008E; Sun, 31 Oct 2021 18:12:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635703960; bh=9dM76M9XEIIztu5mu1NSelGDvR5GAnVYzI3VNuO0YD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hfrb1md5lGUnjPW0rjOQWbKCWcKPAHunRrqOE3eVYDtlXuqWKNphK+DrNM84KPdE9 zF+QzW6/dXouk3j3+JjjRZDkMF8Dp/vJctAdbFBlRGEsBp5/bYLiiLT3VthKzK4l/d EycIhQCSRYTJrNdLYRr40Df6XH7L2LVENgfh1e0lJ/E6sACtbGeUGoCd2yAxImoTpa Q7OaxJQFaXaxoauyjRl0uP/yHmTuzVe3l0Qo2zCoZuBr9U55OJMXA/iJxX/+w4x1Pd tPoJQsOmfaEfclQjRT6LoO9BZ/aog14FeafJmlawAFZw+TzZ46iqNMz/NQR66RU5Ng va0gUslAaW2sw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, pali@kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 3/7] PCI: aardvark: Add support for DEVCAP2, DEVCTL2, LNKCAP2 and LNKCTL2 registers on emulated bridge Date: Sun, 31 Oct 2021 19:12:29 +0100 Message-Id: <20211031181233.9976-4-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211031181233.9976-1-kabel@kernel.org> References: <20211031181233.9976-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Pali Rohár PCI aardvark hardware supports access to DEVCAP2, DEVCTL2, LNKCAP2 and LNKCTL2 configuration registers of PCIe core via PCIE_CORE_PCIEXP_CAP. Export them via emulated software root bridge. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-aardvark.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index c5300d49807a..25af189a1052 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -884,8 +884,13 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, case PCI_CAP_LIST_ID: case PCI_EXP_DEVCAP: case PCI_EXP_DEVCTL: + case PCI_EXP_DEVCAP2: + case PCI_EXP_DEVCTL2: + case PCI_EXP_LNKCAP2: + case PCI_EXP_LNKCTL2: *value = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg); return PCI_BRIDGE_EMUL_HANDLED; + default: return PCI_BRIDGE_EMUL_NOT_HANDLED; } @@ -899,10 +904,6 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, struct advk_pcie *pcie = bridge->data; switch (reg) { - case PCI_EXP_DEVCTL: - advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg); - break; - case PCI_EXP_LNKCTL: advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg); if (new & PCI_EXP_LNKCTL_RL) @@ -924,6 +925,12 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, advk_writel(pcie, new, PCIE_ISR0_REG); break; + case PCI_EXP_DEVCTL: + case PCI_EXP_DEVCTL2: + case PCI_EXP_LNKCTL2: + advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg); + break; + default: break; } From patchwork Sun Oct 31 18:12:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12595445 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6778CC433EF for ; Sun, 31 Oct 2021 18:12:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D1566008E for ; Sun, 31 Oct 2021 18:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbhJaSPO (ORCPT ); Sun, 31 Oct 2021 14:15:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:60480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbhJaSPO (ORCPT ); Sun, 31 Oct 2021 14:15:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 26C9460F45; Sun, 31 Oct 2021 18:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635703962; bh=FOR7h87fDZ5fw1ufiq0gLxkODh8V3QbGeOrwOXnN2CU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VjYT0kuQuHEbAYDAQnmjDjiiutzZ3cLxbhgwvKMEMXyWe0zkqbq0nXsel887oOEP/ jOkf2HPsAOeeDla3pGymSSKMgVp5gnoSIcOfhzqP/COReS1zOYLW58XEkziPzl1gRH A4WPe0Z7tPh10IukwOIAiP74IBNouv1fqP5J0ifBj6kvCwZTfQa1pd6FYNuKZZRu9x yHjSOfb1Wbrj7aM2WV+D+8wMso3x56DNFUaIrgUQHgSj7UbwohVXCAS+ZIVZRm4Re7 9AqU0NzwCBm2emx5vE1SOfzwm6H5THLBx3dgwXrUw1x2u8MCpyCQiOZwJl8IK2HtjW ZrQG2OZtTIVRw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, pali@kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 4/7] PCI: aardvark: Clear all MSIs at setup Date: Sun, 31 Oct 2021 19:12:30 +0100 Message-Id: <20211031181233.9976-5-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211031181233.9976-1-kabel@kernel.org> References: <20211031181233.9976-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Pali Rohár We already clear all the other interrupts (ISR0, ISR1, HOST_CTRL_INT). Define a new macro PCIE_MSI_ALL_MASK and do the same clearing for MSIs, to ensure that we don't start receiving spurious interrupts. Use this new mask in advk_pcie_handle_msi(); Fixes: 8c39d710363c ("PCI: aardvark: Add Aardvark PCI host controller driver") Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-aardvark.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 25af189a1052..71ce9f02d596 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -116,6 +116,7 @@ #define PCIE_MSI_ADDR_HIGH_REG (CONTROL_BASE_ADDR + 0x54) #define PCIE_MSI_STATUS_REG (CONTROL_BASE_ADDR + 0x58) #define PCIE_MSI_MASK_REG (CONTROL_BASE_ADDR + 0x5C) +#define PCIE_MSI_ALL_MASK GENMASK(31, 0) #define PCIE_MSI_PAYLOAD_REG (CONTROL_BASE_ADDR + 0x9C) #define PCIE_MSI_DATA_MASK GENMASK(15, 0) @@ -571,6 +572,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) advk_writel(pcie, reg, PCIE_CORE_CTRL2_REG); /* Clear all interrupts */ + advk_writel(pcie, PCIE_MSI_ALL_MASK, PCIE_MSI_STATUS_REG); advk_writel(pcie, PCIE_ISR0_ALL_MASK, PCIE_ISR0_REG); advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_REG); advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_STATUS_REG); @@ -583,7 +585,7 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_MASK_REG); /* Unmask all MSIs */ - advk_writel(pcie, 0, PCIE_MSI_MASK_REG); + advk_writel(pcie, ~(u32)PCIE_MSI_ALL_MASK, PCIE_MSI_MASK_REG); /* Enable summary interrupt for GIC SPI source */ reg = PCIE_IRQ_ALL_MASK & (~PCIE_IRQ_ENABLE_INTS_MASK); @@ -1399,7 +1401,7 @@ static void advk_pcie_handle_msi(struct advk_pcie *pcie) msi_mask = advk_readl(pcie, PCIE_MSI_MASK_REG); msi_val = advk_readl(pcie, PCIE_MSI_STATUS_REG); - msi_status = msi_val & ~msi_mask; + msi_status = msi_val & ((~msi_mask) & PCIE_MSI_ALL_MASK); for (msi_idx = 0; msi_idx < MSI_IRQ_NUM; msi_idx++) { if (!(BIT(msi_idx) & msi_status)) From patchwork Sun Oct 31 18:12:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12595447 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C623DC43217 for ; Sun, 31 Oct 2021 18:12:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF296610CA for ; Sun, 31 Oct 2021 18:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230303AbhJaSPP (ORCPT ); Sun, 31 Oct 2021 14:15:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:60534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230337AbhJaSPP (ORCPT ); Sun, 31 Oct 2021 14:15:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6335B60E98; Sun, 31 Oct 2021 18:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635703963; bh=GcirBOdhWa2HZ1FienGtqUqNm9Cjo2uMfY7X9yTo63o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PrAOAiWRVVkdMJZg+LAyV2BUqAZ0efGQNJgoC9eCGq4QlTqwYlSu36h4hQdU+fP2k q198QmPRUGKMMm+OA+KG9aV7sC+53FzHwf3basg5w0mGLPjVblmDPos74Jed8sLm5k IGrn2VABPLpWqv4pGz0x8bJ93yrkqGe/yAEOMQYMDeB2q75AlNL41U4UZ4xf8JVphQ Z+CNIGds92GyvNauY/x1R8Ifw+5i0v+buP+S3BJNcdBSWXHtXvmYTox0EyrqduUmRC qojhksoWOsS+/1ywEiguz+smNLMrIuxOY66ZQtCIQzGgHSlbGcREs/pVk5UCCKG0zE YZzRKtG0fEAyw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, pali@kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 5/7] PCI: aardvark: Disable bus mastering and mask all interrupts when unbinding driver Date: Sun, 31 Oct 2021 19:12:31 +0100 Message-Id: <20211031181233.9976-6-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211031181233.9976-1-kabel@kernel.org> References: <20211031181233.9976-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Pali Rohár Ensure that after driver unbinding PCIe cards are not be able to forward memory and I/O requests in the upstream direction and that no interrupt can be triggered. Fixes: 526a76991b7b ("PCI: aardvark: Implement driver 'remove' function and allow to build it as module") Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-aardvark.c | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 71ce9f02d596..08b34accfe2f 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -1695,13 +1695,42 @@ static int advk_pcie_remove(struct platform_device *pdev) { struct advk_pcie *pcie = platform_get_drvdata(pdev); struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); + u32 val; int i; + /* Remove PCI bus with all devices */ pci_lock_rescan_remove(); pci_stop_root_bus(bridge->bus); pci_remove_root_bus(bridge->bus); pci_unlock_rescan_remove(); + /* Disable Root Bridge I/O space, memory space and bus mastering */ + val = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG); + val &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); + advk_writel(pcie, val, PCIE_CORE_CMD_STATUS_REG); + + /* Disable MSI */ + val = advk_readl(pcie, PCIE_CORE_CTRL2_REG); + val &= ~PCIE_CORE_CTRL2_MSI_ENABLE; + advk_writel(pcie, val, PCIE_CORE_CTRL2_REG); + + /* Clear MSI address */ + advk_writel(pcie, 0, PCIE_MSI_ADDR_LOW_REG); + advk_writel(pcie, 0, PCIE_MSI_ADDR_HIGH_REG); + + /* Mask all interrupts */ + advk_writel(pcie, PCIE_MSI_ALL_MASK, PCIE_MSI_MASK_REG); + advk_writel(pcie, PCIE_ISR0_ALL_MASK, PCIE_ISR0_MASK_REG); + advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_MASK_REG); + advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_MASK_REG); + + /* Clear all interrupts */ + advk_writel(pcie, PCIE_MSI_ALL_MASK, PCIE_MSI_STATUS_REG); + advk_writel(pcie, PCIE_ISR0_ALL_MASK, PCIE_ISR0_REG); + advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_REG); + advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_STATUS_REG); + + /* Remove IRQ domains */ advk_pcie_remove_msi_irq_domain(pcie); advk_pcie_remove_irq_domain(pcie); From patchwork Sun Oct 31 18:12:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12595449 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B85C6C4332F for ; Sun, 31 Oct 2021 18:12:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A23A461038 for ; Sun, 31 Oct 2021 18:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230337AbhJaSPQ (ORCPT ); Sun, 31 Oct 2021 14:15:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:60608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbhJaSPQ (ORCPT ); Sun, 31 Oct 2021 14:15:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9F87661075; Sun, 31 Oct 2021 18:12:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635703964; bh=CFz1ww2PxVubKvD/m4QlsyAK29ZspECeJ2f5FC4F+GM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s/FXG7SI1EESSKL8O8cMVPJLSexDVQi9sGTeAXRwXF28Be5BvvDRGuUv8jNI+J5qq JtTtm6LAorQSoiAA+0ru0ZTxbJJtE3ciBR3IOrDBFCero9eAK8Bs8NzEoyiDvY9BoH kRh10TTGZhmi84lXtsV9Zvc2vlyHBjMrVBRFx+yN1OtBxrahp0uw9q1Su5bViDLKeZ DSrAUdpDXUn1Gj4ypEkFOFcKPF/yn9Yjtvz9IiPqcCygSDUxnj+DHhWK8d77jh63Yq e8FL9erSX5EMAuEUxgcz5Auee9yXg6xHSCjChqJAA+BrIzW6neRia+JeiKFQLQqedD OVCSHKlz41EGg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, pali@kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 6/7] PCI: aardvark: Free config space for emulated root bridge when unbinding driver to fix memory leak Date: Sun, 31 Oct 2021 19:12:32 +0100 Message-Id: <20211031181233.9976-7-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211031181233.9976-1-kabel@kernel.org> References: <20211031181233.9976-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Pali Rohár Do it after disabling and masking all interrupts, since aardvark interrupt handler accesses config space of emulated root bridge. Fixes: 526a76991b7b ("PCI: aardvark: Implement driver 'remove' function and allow to build it as module") Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-aardvark.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 08b34accfe2f..b3d89cb449b6 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -1734,6 +1734,9 @@ static int advk_pcie_remove(struct platform_device *pdev) advk_pcie_remove_msi_irq_domain(pcie); advk_pcie_remove_irq_domain(pcie); + /* Free config space for emulated root bridge */ + pci_bridge_emul_cleanup(&pcie->bridge); + /* Disable outbound address windows mapping */ for (i = 0; i < OB_WIN_COUNT; i++) advk_pcie_disable_ob_win(pcie, i); From patchwork Sun Oct 31 18:12:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12595451 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93779C433EF for ; Sun, 31 Oct 2021 18:12:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73B9560E98 for ; Sun, 31 Oct 2021 18:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230388AbhJaSPS (ORCPT ); Sun, 31 Oct 2021 14:15:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:60638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230395AbhJaSPR (ORCPT ); Sun, 31 Oct 2021 14:15:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC552610A0; Sun, 31 Oct 2021 18:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635703965; bh=BNLhJywoeFLXl5q+k6L7aZxoFEFa6oZ2PA7HV2xNlwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ew8K373UsAAzGRCvYNiqhmIbuOcfEqbsO3LuU4ri88UdV8gJ58DEwHXHiEvjc6GbA HsqjhJWXMzXyr7bc+AIQnBYGgdL50035Q8STUI8DAGXuSBfcGOZYSTuMebVrrEguRl 08M3MRdcWNYeSuq0T4OgqNAEhSUYzj6xlFVFHdZJyHkyEpbJZUyNuLa3mPqq+N7BJJ QnU/Tdwrg6me/Y2mssJ2XWo2ECgJTpWT9YV6DjlShrxKsfAnElSeNe33k981oas7bf mP0ly3Dy93OlxlYAgOXTKekt9ly0BOCHNX6uZ3tePWtQizt9Yw2VMdVCjWzWc/5d8+ qHp3EUYlmLSyA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, pali@kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 7/7] PCI: aardvark: Reset PCIe card and disable PHY at driver unbind Date: Sun, 31 Oct 2021 19:12:33 +0100 Message-Id: <20211031181233.9976-8-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211031181233.9976-1-kabel@kernel.org> References: <20211031181233.9976-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Pali Rohár When unbinding driver, assert PERST# signal which prepares PCIe card for power down. Then disable link training and PHY. Fixes: 526a76991b7b ("PCI: aardvark: Implement driver 'remove' function and allow to build it as module") Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Cc: stable@vger.kernel.org --- drivers/pci/controller/pci-aardvark.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index b3d89cb449b6..2a82c4652c28 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -1737,10 +1737,22 @@ static int advk_pcie_remove(struct platform_device *pdev) /* Free config space for emulated root bridge */ pci_bridge_emul_cleanup(&pcie->bridge); + /* Assert PERST# signal which prepares PCIe card for power down */ + if (pcie->reset_gpio) + gpiod_set_value_cansleep(pcie->reset_gpio, 1); + + /* Disable link training */ + val = advk_readl(pcie, PCIE_CORE_CTRL0_REG); + val &= ~LINK_TRAINING_EN; + advk_writel(pcie, val, PCIE_CORE_CTRL0_REG); + /* Disable outbound address windows mapping */ for (i = 0; i < OB_WIN_COUNT; i++) advk_pcie_disable_ob_win(pcie, i); + /* Disable phy */ + advk_pcie_disable_phy(pcie); + return 0; }