Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566496lkm; Mon, 20 Sep 2021 18:53:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOwxWMJZjT2ErRqO8NESdwUFieaZRy7RoE/6vmxAzfIlkirKCPeqo8qgucuHwZKTsQSdrE X-Received: by 2002:a50:d989:: with SMTP id w9mr33177633edj.99.1632189107384; Mon, 20 Sep 2021 18:51:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189107; cv=none; d=google.com; s=arc-20160816; b=xmsupfrlLabRAbNw9v/ACoU0s4BCz7r0VXMFyMaoRVElUgHhhe7sujL5hPjxOvUvus IXH2ViPrBzvWdr5pu0AoHhhIWCBVDCto/PvYDHe445y7y9hxlbDfX65h6QE/vP9hVf+1 hXjVdER4UT2Jd31+I6GtD5ivujBLCiwnzefH1n0RZvpMgqF15RBdM1OXryo9ZerrfYq7 Y6EHe6840bCM+CAPFnjYj9laiK4vKP2tlTQ2XGnjsKfCTOaCF++2JemsTTJEW9yprJiL f0lfH3KPNiJs2X41flShsngRCOLQ2v0vwsd2F+SXpnCmEqtCjaq93M3z95aSBWSoPEaW 4dWQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1lZxsuH7840/jBIoPgH6UO8ZaRm343TPc+7hyFQ7BgQ=; b=v0slYLPby3hq1zjLE1aj7B6+qZs+vMO+zxOushIH5oCodUu27BsuVWzYZrB3JNO0HE 42qrtQmr2Uzqf5oK0iDbn2YmsMOx4r8TpfvoMt6yGnX+l1slL6uQ7REI7okyJpDN3kVq ejNi16tL3NMpYlSK2QaCfuJj+Fa0kM2axmIpV/sUZmXC364WH7OjsgXU9H2Ktj3iM4rb YuyPspdV3WukdBpzLLCXx5q1LXQjAxgHVxz2I97od24C6w2qDu/KQb9mXHxGQViKoLkz cVk9cneA/5ScxsSf4nmPd38LNESGdt3VI/nv3/u6CFWdtTMcN2hdxBc/KdxW/HAKE/wl E4Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X7LfOtGW; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r24si9757772ejy.194.2021.09.20.18.51.24; Mon, 20 Sep 2021 18:51:47 -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=@linuxfoundation.org header.s=korg header.b=X7LfOtGW; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358843AbhITSIS (ORCPT + 99 others); Mon, 20 Sep 2021 14:08:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:60150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349996AbhITSBz (ORCPT ); Mon, 20 Sep 2021 14:01:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3B608613BD; Mon, 20 Sep 2021 17:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158171; bh=1pb6JtBLzjcJDoxUCZ/FysfWLh7sM5qxK/N4zJC2x6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X7LfOtGWAk4I4KVZ92EaQu+WpgZBHELy+uoAab+R3RMApOkFZkjLLtlhZub87xzAL bLC5R1FzUShKSUqXyFbOWTE7lukg4XNYvdGAxEJyTI1+XXXI2c7C2Wy5HGiuZCZjOS GksU//O/1HTqmDo5NkJpPiZFdzQ+zOGuH+GDM8BE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Victor Gu , Evan Wang , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Lorenzo Pieralisi , =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH 5.4 033/260] PCI: aardvark: Fix checking for PIO status Date: Mon, 20 Sep 2021 18:40:51 +0200 Message-Id: <20210920163932.251474246@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 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: Evan Wang commit fcb461e2bc8b83b7eaca20cb2221e8b940f2189c upstream. There is an issue that when PCIe switch is connected to an Armada 3700 board, there will be lots of warnings about PIO errors when reading the config space. According to Aardvark PIO read and write sequence in HW specification, the current way to check PIO status has the following issues: 1) For PIO read operation, it reports the error message, which should be avoided according to HW specification. 2) For PIO read and write operations, it only checks PIO operation complete status, which is not enough, and error status should also be checked. This patch aligns the code with Aardvark PIO read and write sequence in HW specification on PIO status check and fix the warnings when reading config space. [pali: Fix CRS handling when CRSSVE is not enabled] Link: https://lore.kernel.org/r/20210722144041.12661-2-pali@kernel.org Tested-by: Victor Gu Signed-off-by: Evan Wang Signed-off-by: Pali Rohár Signed-off-by: Lorenzo Pieralisi Reviewed-by: Victor Gu Reviewed-by: Marek Behún Cc: stable@vger.kernel.org # b1bd5714472c ("PCI: aardvark: Indicate error in 'val' when config read fails") Signed-off-by: Greg Kroah-Hartman --- drivers/pci/controller/pci-aardvark.c | 62 +++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -62,6 +62,7 @@ #define PIO_COMPLETION_STATUS_CRS 2 #define PIO_COMPLETION_STATUS_CA 4 #define PIO_NON_POSTED_REQ BIT(10) +#define PIO_ERR_STATUS BIT(11) #define PIO_ADDR_LS (PIO_BASE_ADDR + 0x8) #define PIO_ADDR_MS (PIO_BASE_ADDR + 0xc) #define PIO_WR_DATA (PIO_BASE_ADDR + 0x10) @@ -363,7 +364,7 @@ static void advk_pcie_setup_hw(struct ad advk_writel(pcie, reg, PCIE_CORE_CMD_STATUS_REG); } -static void advk_pcie_check_pio_status(struct advk_pcie *pcie) +static int advk_pcie_check_pio_status(struct advk_pcie *pcie, u32 *val) { struct device *dev = &pcie->pdev->dev; u32 reg; @@ -374,14 +375,49 @@ static void advk_pcie_check_pio_status(s status = (reg & PIO_COMPLETION_STATUS_MASK) >> PIO_COMPLETION_STATUS_SHIFT; - if (!status) - return; - + /* + * According to HW spec, the PIO status check sequence as below: + * 1) even if COMPLETION_STATUS(bit9:7) indicates successful, + * it still needs to check Error Status(bit11), only when this bit + * indicates no error happen, the operation is successful. + * 2) value Unsupported Request(1) of COMPLETION_STATUS(bit9:7) only + * means a PIO write error, and for PIO read it is successful with + * a read value of 0xFFFFFFFF. + * 3) value Completion Retry Status(CRS) of COMPLETION_STATUS(bit9:7) + * only means a PIO write error, and for PIO read it is successful + * with a read value of 0xFFFF0001. + * 4) value Completer Abort (CA) of COMPLETION_STATUS(bit9:7) means + * error for both PIO read and PIO write operation. + * 5) other errors are indicated as 'unknown'. + */ switch (status) { + case PIO_COMPLETION_STATUS_OK: + if (reg & PIO_ERR_STATUS) { + strcomp_status = "COMP_ERR"; + break; + } + /* Get the read result */ + if (val) + *val = advk_readl(pcie, PIO_RD_DATA); + /* No error */ + strcomp_status = NULL; + break; case PIO_COMPLETION_STATUS_UR: strcomp_status = "UR"; break; case PIO_COMPLETION_STATUS_CRS: + /* PCIe r4.0, sec 2.3.2, says: + * If CRS Software Visibility is not enabled, the Root Complex + * must re-issue the Configuration Request as a new Request. + * A Root Complex implementation may choose to limit the number + * of Configuration Request/CRS Completion Status loops before + * determining that something is wrong with the target of the + * Request and taking appropriate action, e.g., complete the + * Request to the host as a failed transaction. + * + * To simplify implementation do not re-issue the Configuration + * Request and complete the Request as a failed transaction. + */ strcomp_status = "CRS"; break; case PIO_COMPLETION_STATUS_CA: @@ -392,6 +428,9 @@ static void advk_pcie_check_pio_status(s break; } + if (!strcomp_status) + return 0; + if (reg & PIO_NON_POSTED_REQ) str_posted = "Non-posted"; else @@ -399,6 +438,8 @@ static void advk_pcie_check_pio_status(s dev_err(dev, "%s PIO Response Status: %s, %#x @ %#x\n", str_posted, strcomp_status, reg, advk_readl(pcie, PIO_ADDR_LS)); + + return -EFAULT; } static int advk_pcie_wait_pio(struct advk_pcie *pcie) @@ -625,10 +666,13 @@ static int advk_pcie_rd_conf(struct pci_ if (ret < 0) return PCIBIOS_SET_FAILED; - advk_pcie_check_pio_status(pcie); + /* Check PIO status and get the read result */ + ret = advk_pcie_check_pio_status(pcie, val); + if (ret < 0) { + *val = 0xffffffff; + return PCIBIOS_SET_FAILED; + } - /* Get the read result */ - *val = advk_readl(pcie, PIO_RD_DATA); if (size == 1) *val = (*val >> (8 * (where & 3))) & 0xff; else if (size == 2) @@ -692,7 +736,9 @@ static int advk_pcie_wr_conf(struct pci_ if (ret < 0) return PCIBIOS_SET_FAILED; - advk_pcie_check_pio_status(pcie); + ret = advk_pcie_check_pio_status(pcie, NULL); + if (ret < 0) + return PCIBIOS_SET_FAILED; return PCIBIOS_SUCCESSFUL; }