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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DE8EBC7619A for ; Wed, 12 Apr 2023 09:48:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0E8F785FC0; Wed, 12 Apr 2023 11:48:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=starfivetech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 3AC3185FAA; Wed, 12 Apr 2023 11:48:42 +0200 (CEST) Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by phobos.denx.de (Postfix) with ESMTP id 5021F85FAA for ; Wed, 12 Apr 2023 11:48:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=starfivetech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=minda.chen@starfivetech.com Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id D5F1324DFFD; Wed, 12 Apr 2023 17:48:36 +0800 (CST) Received: from EXMBX171.cuchost.com (172.16.6.91) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 12 Apr 2023 17:48:36 +0800 Received: from [192.168.125.108] (113.72.145.176) by EXMBX171.cuchost.com (172.16.6.91) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 12 Apr 2023 17:48:36 +0800 Message-ID: Date: Wed, 12 Apr 2023 17:48:35 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH v4 1/3] starfive: pci: Add StarFive JH7110 pcie driver Content-Language: en-US To: =?UTF-8?Q?Pali_Roh=c3=a1r?= CC: Simon Glass , Stefan Roese , Andrew Scull , Mark Kettenis , , Rick Chen , Leo , Mason Huo , Yanhong Wang , Leyfoon Tan , Kevin Xie References: <20230411010209.76561-1-minda.chen@starfivetech.com> <20230411010209.76561-2-minda.chen@starfivetech.com> <20230411212956.hbcy76a5pfkjcdlb@pali> From: Minda Chen In-Reply-To: <20230411212956.hbcy76a5pfkjcdlb@pali> Content-Type: text/plain; charset="UTF-8" X-Originating-IP: [113.72.145.176] X-ClientProxiedBy: EXCAS064.cuchost.com (172.16.6.24) To EXMBX171.cuchost.com (172.16.6.91) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean On 2023/4/12 5:29, Pali Roh=C3=A1r wrote: > Hello! >=20 > On Tuesday 11 April 2023 09:02:07 Minda Chen wrote: >> +int starfive_pcie_config_write(struct udevice *udev, pci_dev_t bdf, >> + uint offset, ulong value, >> + enum pci_size_t size) >> +{ >> + struct starfive_pcie *priv =3D dev_get_priv(udev); >> + int ret; >> + >> + ret =3D pci_generic_mmap_write_config(udev, starfive_pcie_conf_addre= ss, >> + bdf, offset, value, size); >> + >> + if (!ret && offset =3D=3D PCI_SECONDARY_BUS) { >> + priv->sec_busno =3D value & 0xff; >> + debug("Secondary bus number was changed to %d\n", >> + priv->sec_busno); >> + } >=20 > This block of code contains two issues: >=20 > 1) If secondary bus is changed by the 16-bit or 32-bit write operation > then this condition does not catch it. >=20 > 2) priv->sec_busno is used just for checking if driver is going to > access device on secondary bus of the Root Port. But this code > updates priv->sec_busno also for write to _any_ device on any bus, > not just when updating Root Port device. So it breaks support for > non-trivial PCIe hierarchy which contains e.g. PCIe switch (e.g. whe= n > changing configuration of the virtual PCI-to-PCI bridge device of > PCIe switch, which is behind the secondary bus of the Root Port). >=20 > So you need something like this: >=20 > if (!ret && > PCI_BUS(bdf) =3D=3D dev_seq(udev) && PCI_DEV(bdf) =3D=3D 0 && P= CI_FUNC(bdf) =3D=3D 0 && > (offset =3D=3D PCI_SECONDARY_BUS || (offset =3D=3D PCI_PRIMARY_= BUS && size !=3D PCI_SIZE_8)) { > priv->sec_busno =3D ((offset =3D=3D PCI_PRIMARY_BUS) ? (value >= > 8) : value) & 0xff; > debug("Secondary bus number was changed to %d\n", pcie->sec_bus= no); > } >=20 > You have to update priv->sec_busno only when write request is for the > Root Port. And you need to catch also 16-bit or 32-bit write operation > to the PCI_PRIMARY_BUS register. It is because PCI_SECONDARY_BUS reg > is (PCI_PRIMARY_BUS+2) and (PCI_SECONDARY_BUS & ~3) =3D=3D PCI_PRIMARY_= BUS >=20 I will change like this. Thank you very much. >> + return ret; >> +}