Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp901773ybi; Thu, 30 May 2019 08:27:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqx38PpyYeft2GsN/wLekFHbDL6nqIYfYB3BJ9mczjcCL5sLbtpJ3a/yrjwvq0fJy5JjM0Y/ X-Received: by 2002:a17:902:a505:: with SMTP id s5mr4047829plq.54.1559230038612; Thu, 30 May 2019 08:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559230038; cv=none; d=google.com; s=arc-20160816; b=D3snQ++LJ9UKbuojvXX4sJF1btaJGnzSk+zHQa6mq/4Ls1nm9MeGDXlm1rGvimv1AH K13llBNtSNQFyh7FKekVZnFrU4T4Yq1paz5kK17Svxg7sFYlAJvPysszD/JchjNn5WJn 2LXkIyq6FTxkgmpPmhpJp8BGV3CCqqkTz4xT5kuhmwTxSfzEDOzVIy6/nx2TC7sp16cn AJwh9nRIudw9pwmy4JAOHYLV3cVd8j5MXUJjeSRUMSI6YqndTWFYLjfQIyFwvrQ3hFII xQ2xQ3aUvtEu0lfEq2UXSvjDj+q8gzKWwu1k8o91hfxipyfHDqnbeOyMCq7ljbop5Omq mi8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=vgUur3VeB5U1jrXMyb7vCsWQ1ewtW1zLY5NkmQ+C7QY=; b=jIcLh4/fBo7a2osVWt7zNvmjoONe0ELgA/DdTxNz26reTfBh0yhxFDqiELid7/yY7r D97CG2s72VNbu6aHJ/oNoQGrVk5dJCasIKWpZd5mbOlZgjSmXY3tnG9DT/sUtGO9qumI N/aFP48duwNVjysUymA71FohDAB4yzn4uE7sRVNYxykvtbQoNRzq8AUGK3y7c3N6KE3R dd0LbHBnkDGMLZLdwTKG85l6t4a5wUvWWTFi80bQnqdxwR82iLq1biWxjbE3FcjC1ZUC VQAEnGzLA5wEZLeuG3ekKAGh9vaZ8hH+7BB4RQfu9OrEHWw1pvqf6S3APy32C/fy8x62 o8Ww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 129si3621455pfb.270.2019.05.30.08.27.02; Thu, 30 May 2019 08:27:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726828AbfE3PZx (ORCPT + 99 others); Thu, 30 May 2019 11:25:53 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:38712 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726015AbfE3PZx (ORCPT ); Thu, 30 May 2019 11:25:53 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5F61E341; Thu, 30 May 2019 08:25:52 -0700 (PDT) Received: from redmoon (e121166-lin.cambridge.arm.com [10.1.196.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4D0CC3F59C; Thu, 30 May 2019 08:25:51 -0700 (PDT) Date: Thu, 30 May 2019 16:25:48 +0100 From: Lorenzo Pieralisi To: Ley Foon Tan Cc: Bjorn Helgaas , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lftan.linux@gmail.com Subject: Re: [PATCH 1/2] PCI: altera: Fix configuration type based on secondary number Message-ID: <20190530152548.GD13993@redmoon> References: <1558678046-4052-1-git-send-email-ley.foon.tan@intel.com> <1558678046-4052-2-git-send-email-ley.foon.tan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1558678046-4052-2-git-send-email-ley.foon.tan@intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 24, 2019 at 02:07:25PM +0800, Ley Foon Tan wrote: > This fix issue when access config from PCIe switch. > > Stratix 10 PCIe controller does not support Type 1 to Type 0 conversion > as previous version (V1) does. > > The PCIe controller need to send Type 0 config TLP if the targeting bus > matches with the secondary bus number, which is when the TLP is targeting > the immediate device on the link. > > The PCIe controller send Type 1 config TLP if the targeting bus is > larger than the secondary bus, which is when the TLP is targeting the > device not immediate on the link. > > Signed-off-by: Ley Foon Tan > --- > drivers/pci/controller/pcie-altera.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/drivers/pci/controller/pcie-altera.c b/drivers/pci/controller/pcie-altera.c > index 27222071ace7..047bcc214f9b 100644 > --- a/drivers/pci/controller/pcie-altera.c > +++ b/drivers/pci/controller/pcie-altera.c > @@ -44,6 +44,8 @@ > #define S10_RP_RXCPL_STATUS 0x200C > #define S10_RP_CFG_ADDR(pcie, reg) \ > (((pcie)->hip_base) + (reg) + (1 << 20)) > +#define S10_RP_SECONDARY(pcie) \ > + readb(S10_RP_CFG_ADDR(pcie, PCI_SECONDARY_BUS)) > > /* TLP configuration type 0 and 1 */ > #define TLP_FMTTYPE_CFGRD0 0x04 /* Configuration Read Type 0 */ > @@ -63,6 +65,14 @@ > ((((bus == pcie->root_bus_nr) ? pcie->pcie_data->cfgwr0 \ > : pcie->pcie_data->cfgwr1) << 24) | \ > TLP_PAYLOAD_SIZE) > +#define S10_TLP_CFGRD_DW0(pcie, bus) \ > + (((((bus) > S10_RP_SECONDARY(pcie)) ? pcie->pcie_data->cfgrd0 \ > + : pcie->pcie_data->cfgrd1) << 24) | \ > + TLP_PAYLOAD_SIZE) > +#define S10_TLP_CFGWR_DW0(pcie, bus) \ > + (((((bus) > S10_RP_SECONDARY(pcie)) ? pcie->pcie_data->cfgwr0 \ > + : pcie->pcie_data->cfgwr1) << 24) | \ > + TLP_PAYLOAD_SIZE) > #define TLP_CFG_DW1(pcie, tag, be) \ > (((TLP_REQ_ID(pcie->root_bus_nr, RP_DEVFN)) << 16) | (tag << 8) | (be)) > #define TLP_CFG_DW2(bus, devfn, offset) \ > @@ -327,7 +337,11 @@ static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn, > { > u32 headers[TLP_HDR_SIZE]; > > - headers[0] = TLP_CFGRD_DW0(pcie, bus); > + if (pcie->pcie_data->version == ALTERA_PCIE_V1) > + headers[0] = TLP_CFGRD_DW0(pcie, bus); > + else > + headers[0] = S10_TLP_CFGRD_DW0(pcie, bus); > + > headers[1] = TLP_CFG_DW1(pcie, TLP_READ_TAG, byte_en); > headers[2] = TLP_CFG_DW2(bus, devfn, where); > > @@ -342,7 +356,11 @@ static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn, > u32 headers[TLP_HDR_SIZE]; > int ret; > > - headers[0] = TLP_CFGWR_DW0(pcie, bus); > + if (pcie->pcie_data->version == ALTERA_PCIE_V1) > + headers[0] = TLP_CFGWR_DW0(pcie, bus); > + else > + headers[0] = S10_TLP_CFGWR_DW0(pcie, bus); > + Why don't you rewrite all these macros as an eg: static inline u32 get_tlp_header() {} where you can also handle the version and everything needed to detect what header should be set-up ? Lorenzo > headers[1] = TLP_CFG_DW1(pcie, TLP_WRITE_TAG, byte_en); > headers[2] = TLP_CFG_DW2(bus, devfn, where); > > -- > 2.19.0 >