Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE38C4338F for ; Wed, 11 Aug 2021 08:29:24 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 41A01601FE for ; Wed, 11 Aug 2021 08:29:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 41A01601FE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 28E0E82CDE; Wed, 11 Aug 2021 10:29:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1628670561; bh=9S85bYhlG5dR1FwoF00999kT0AUW2JoM6FsA6dfVFV8=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RcfhgzvuvN7lsHMYzbUdQ6vaVyuA3WrkKPxfXS16+w4P4l2lAj6cAjH0qZXFwcHBP IY9tpaYyP7xtDGdLCZv4upuVkZFEr+Cm5I4cuX6N61foVlRPhXUP3neU9bSMq4oIlM qSHy6BAa7+15TaHoiIuFfK/7h7J/u9zW4HqsVxhN+pHoXytH2w3ul+o2eh1kyTRO2Q oWIxYYspHayVhW6sJ9/bdbZtGYc4dZgw+cRO1LxENOOvRMCR+o9WwnINb24X6f7RRT 6QJi6VXwYiSUhqcZx2wjseoYCj8qolGHb10JGJc+pN9tMpWs3J7GyXDUe52GA26x8i hVcUipHTvJjcw== Received: by phobos.denx.de (Postfix, from userid 109) id 5750082CE8; Wed, 11 Aug 2021 10:29:19 +0200 (CEST) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:1::465:107]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 31EC482C89 for ; Wed, 11 Aug 2021 10:29:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4Gl2zZ702VzQjBM; Wed, 11 Aug 2021 10:29:14 +0200 (CEST) Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id twCoo_ZkEnwz; Wed, 11 Aug 2021 10:29:11 +0200 (CEST) Subject: Re: [PATCH] arm: a37xx: pci: Fix handling PIO config error responses To: =?UTF-8?Q?Pali_Roh=c3=a1r?= Cc: =?UTF-8?Q?Marek_Beh=c3=ban?= , Konstantin Porotchkin , u-boot@lists.denx.de References: <20210809075313.24868-1-pali@kernel.org> From: Stefan Roese Message-ID: <49ab72d4-393a-ac29-a491-d61884809e61@denx.de> Date: Wed, 11 Aug 2021 10:29:10 +0200 MIME-Version: 1.0 In-Reply-To: <20210809075313.24868-1-pali@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: BB2BD1840 X-Rspamd-UID: 8b713c X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 09.08.21 09:53, Pali Rohár wrote: > Returning fabricated CRS value (0xFFFF0001) by PCIe Root Complex to OS is > allowed only for 4-byte PCI_VENDOR_ID config read request and only when > CRSSVE bit in Root Port PCIe device is enabled. In all other error PCIe > Root Complex must return all-ones. > > So implement this logic in pci-aardvark.c driver properly. > > aardvark HW does not have Root Port PCIe device and U-Boot does not > implement emulation of this device. So expect that CRSSVE bit is set as > U-Boot can already handle CRS value for PCI_VENDOR_ID config read request. > > More callers of pci_bus_read_config() function in U-Boot do not check for > return value, but check readback value. Therefore always fill readback > value in pcie_advk_read_config() function. On error fill all-ones of > correct size as it is required for PCIe Root Complex. > > And also correctly propagates error from failed config write request to > return value of pcie_advk_write_config() function. Most U-Boot callers > ignores this return value, but it is a good idea to return correct value > from function. > > These issues about return value of failed config read requests, including > special handling of CRS were reported by Lorenzo and Bjorn for Linux kernel > driver pci-aardvark together with quotes from PCIe r4.0 spec, see details: > https://lore.kernel.org/linux-pci/20210624213345.3617-1-pali@kernel.org/t/#u > > Signed-off-by: Pali Rohár Applied to u-boot-marvell/master Thanks, Stefan > --- > drivers/pci/pci-aardvark.c | 52 +++++++++++++++++++------------------- > 1 file changed, 26 insertions(+), 26 deletions(-) > > diff --git a/drivers/pci/pci-aardvark.c b/drivers/pci/pci-aardvark.c > index 1b9bae7cca72..815b26162f15 100644 > --- a/drivers/pci/pci-aardvark.c > +++ b/drivers/pci/pci-aardvark.c > @@ -177,7 +177,6 @@ > #define LINK_MAX_RETRIES 10 > #define LINK_WAIT_TIMEOUT 100000 > > -#define CFG_RD_UR_VAL 0xFFFFFFFF > #define CFG_RD_CRS_VAL 0xFFFF0001 > > /** > @@ -263,12 +262,12 @@ static int pcie_advk_wait_pio(struct pcie_advk *pcie) > * pcie_advk_check_pio_status() - Validate PIO status and get the read result > * > * @pcie: Pointer to the PCI bus > - * @read: Read from or write to configuration space - true(read) false(write) > - * @read_val: Pointer to the read result, only valid when read is true > + * @allow_crs: Only for read requests, if CRS response is allowed > + * @read_val: Pointer to the read result > * > */ > static int pcie_advk_check_pio_status(struct pcie_advk *pcie, > - bool read, > + bool allow_crs, > uint *read_val) > { > uint reg; > @@ -286,22 +285,16 @@ static int pcie_advk_check_pio_status(struct pcie_advk *pcie, > break; > } > /* Get the read result */ > - if (read) > + if (read_val) > *read_val = advk_readl(pcie, PIO_RD_DATA); > /* No error */ > strcomp_status = NULL; > break; > case PIO_COMPLETION_STATUS_UR: > - if (read) { > - /* For reading, UR is not an error status. */ > - *read_val = CFG_RD_UR_VAL; > - strcomp_status = NULL; > - } else { > - strcomp_status = "UR"; > - } > + strcomp_status = "UR"; > break; > case PIO_COMPLETION_STATUS_CRS: > - if (read) { > + if (allow_crs && read_val) { > /* For reading, CRS is not an error status. */ > *read_val = CFG_RD_CRS_VAL; > strcomp_status = NULL; > @@ -352,6 +345,7 @@ static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, > enum pci_size_t size) > { > struct pcie_advk *pcie = dev_get_priv(bus); > + bool allow_crs; > uint reg; > int ret; > > @@ -364,13 +358,17 @@ static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, > return 0; > } > > + allow_crs = (offset == PCI_VENDOR_ID) && (size == 4); > + > if (advk_readl(pcie, PIO_START)) { > dev_err(pcie->dev, > "Previous PIO read/write transfer is still running\n"); > - if (offset != PCI_VENDOR_ID) > - return -EINVAL; > - *valuep = CFG_RD_CRS_VAL; > - return 0; > + if (allow_crs) { > + *valuep = CFG_RD_CRS_VAL; > + return 0; > + } > + *valuep = pci_get_ff(size); > + return -EINVAL; > } > > /* Program the control register */ > @@ -392,16 +390,20 @@ static int pcie_advk_read_config(const struct udevice *bus, pci_dev_t bdf, > advk_writel(pcie, 1, PIO_START); > > if (!pcie_advk_wait_pio(pcie)) { > - if (offset != PCI_VENDOR_ID) > - return -EINVAL; > - *valuep = CFG_RD_CRS_VAL; > - return 0; > + if (allow_crs) { > + *valuep = CFG_RD_CRS_VAL; > + return 0; > + } > + *valuep = pci_get_ff(size); > + return -EINVAL; > } > > /* Check PIO status and get the read result */ > - ret = pcie_advk_check_pio_status(pcie, true, ®); > - if (ret) > + ret = pcie_advk_check_pio_status(pcie, allow_crs, ®); > + if (ret) { > + *valuep = pci_get_ff(size); > return ret; > + } > > dev_dbg(pcie->dev, "(addr,size,val)=(0x%04x, %d, 0x%08x)\n", > offset, size, reg); > @@ -511,9 +513,7 @@ static int pcie_advk_write_config(struct udevice *bus, pci_dev_t bdf, > } > > /* Check PIO status */ > - pcie_advk_check_pio_status(pcie, false, ®); > - > - return 0; > + return pcie_advk_check_pio_status(pcie, false, NULL); > } > > /** > Viele Grüße, Stefan -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de