Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1651355pxy; Thu, 6 May 2021 12:21:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHUpAn79EnvLD7BIMMRFWyioereasY+ZdDeBH9KQSHZ1Koz2sKbUjRoFez844GDJlWLDZx X-Received: by 2002:a05:6a00:162b:b029:27f:f30e:f0db with SMTP id e11-20020a056a00162bb029027ff30ef0dbmr6343709pfc.73.1620328889012; Thu, 06 May 2021 12:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620328889; cv=none; d=google.com; s=arc-20160816; b=wp0TIs0n5a0hw3cMNuIeVIsIO3jVEQgcBHviG7TlR0vh0r/dSx7OmE/lt30hnRxPtQ /meKTETaZwdw37DO1wxs9R0MGdCzfxPWQg/YGNtXWF2wsyw4w5Gd75lFLFsWlkMRG50V PYFNJkofLwakieB/KDaos9hMoZtffCVMEwzJk/U2MtmZTNRpZcrNIwXGnAsaNvHGFb2i mT0yVRXBGSghBSt5HluOBhcoY9DFs+pZYA9CHgYakfFXkDJWGZ/cR+0d8hYhv23sflpr ZVMPZAUJxS0hez24tnoGJuAY+w+t1wyCOXDMSiOJGEDAQxJqYj19qXP0dGv7oPOU0IwB slRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NlPdLa0mFoh+Y1pq7/6fZEnNWdOCnsGrlu1byzl595k=; b=DfVIilH40ZH5rLySQPY4tPN+N4B5d5OMCqo2JAq7lOxzgzGkkZQ1UC5F/BTKiNdznv 0y+rIFQjC1beU7hRADaWjeivCMUPhELgvGZXzu0gc0YVnCr8pIvvFT32+YKWeC5pCwlp x8tCOq7ZgOoMaN9wdYadyVNs8VMUMvnkHNQKOxa54zahtWy4jI9SaTZ70x2wn68RPqnn Nte67ZBVw+p+jM7yksAh1HwT2Fb1A6NejNMHXTz7KlEWxN9o5JPqWMYGllDf0g3Ie+vD 1rpTJlUn1fovkrTUHK48oO8Onx5J6i+7yBRusN09PqbaPKef4TbkatApK+oUMnbbOfB0 Gpzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dBuxXdS0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r11si3835044pld.262.2021.05.06.12.21.16; Thu, 06 May 2021 12:21:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dBuxXdS0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236030AbhEFPhR (ORCPT + 99 others); Thu, 6 May 2021 11:37:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:45940 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235617AbhEFPdu (ORCPT ); Thu, 6 May 2021 11:33:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2E94961480; Thu, 6 May 2021 15:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620315172; bh=/uVqlvC9txwPNmX/K1BcG3NATkDFNCdhia5CIYift7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dBuxXdS0DcNxAUVlQGA8WlWK2UBZKsMVW+M9m1tAYBBL2XUeymhG+EmZ0SGdP4aMt 2Q28Xl640HLK+GktyhLOmLI/N5wnXZSW1JdFv6kfEvXYObYgu76dQDufTc1H0Zpthe 24O/VGYlsz605MqNLxeqeE+kEq6iRm52b1VZvRCssS73mp29n07mL2H5cGv0IOlpdi f5TmoaJ7A1CUdev0lAVHoCq0TMQN5VktfylGYIlPJEtae0sD6QUjhs7twWt/Dq6WjY QUCp0PiXKGsiIw/m74+NDw4480jXJtvEckew4cZpO+9IuJUCHfxX366gQhn4328IZ4 AIJ/NArF3yY4g== Received: by pali.im (Postfix) id D67758A1; Thu, 6 May 2021 17:32:51 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Lorenzo Pieralisi , Thomas Petazzoni , Rob Herring , Bjorn Helgaas Cc: Russell King , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Remi Pommarel , Xogium , Tomasz Maciej Nowak , Marc Zyngier , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 26/42] PCI: aardvark: Fix support for bus mastering and PCI_COMMAND on emulated bridge Date: Thu, 6 May 2021 17:31:37 +0200 Message-Id: <20210506153153.30454-27-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210506153153.30454-1-pali@kernel.org> References: <20210506153153.30454-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From very vague, ambiguous and incomplete information from Marvell we deduced that the 32-bit aardvark register 0x4 (PCIE_CORE_CMD_STATUS_REG), which is not documented in Armada 3700 Functional Specifications for PCIe Root Complex mode, should control two 16-bit PCIe registers: Command Register and Status Registers of virtual PCIe Root Bridge. 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 beginning of aardvark initialization. Also 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. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún Fixes: 8a3ebd8de328 ("PCI: aardvark: Implement emulated root PCI bridge config space") Cc: stable@vger.kernel.org # b2a56469d550 ("PCI: aardvark: Add FIXME comment for PCIE_CORE_CMD_STATUS_REG access") --- drivers/pci/controller/pci-aardvark.c | 54 +++++++++++++++++++-------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 6c860e67e5a2..92f93ec48d6b 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -31,9 +31,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 @@ -365,6 +362,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 | @@ -443,19 +445,6 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) advk_writel(pcie, reg, PIO_CTRL); advk_pcie_train_link(pcie); - - /* - * FIXME: The following register update is suspicious. This register is - * applicable only when the PCI controller is configured for Endpoint - * mode, not as a Root Complex. But apparently when this code is - * removed, some cards stop working. This should be investigated and - * a comment explaining this should be put here. - */ - 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, u32 *val) @@ -555,6 +544,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, @@ -624,6 +644,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.20.1