Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5343405ybi; Wed, 12 Jun 2019 00:35:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMtT3C5GaaxCJIbcYOc3l6mvGDfO7+m3IX/c0NE75npImcGOG+M39X+JUfMK9ffwp8HMVe X-Received: by 2002:a17:902:8c83:: with SMTP id t3mr54095585plo.93.1560324951765; Wed, 12 Jun 2019 00:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560324951; cv=none; d=google.com; s=arc-20160816; b=uRwaLOtDI0+v5ISBCCnZ6fyGr5ty8UmPPPdO/4nZrIhs9afIrkJ9BMt8jle6BuAlai 7ZP9bkodtlLbJEk3u7Sdc4T+xJM+1vbsPPxyHeG17TxOSu8IwBnv3+pNtDNHoimsT47U 4HtOmhxHS2f+n40yH5shPEfamTteiuBZrY9wp3LLLfcdbi8iO7ijAvpwySxBvQ9sjrlS ZRA8uKgn9girBipz0z8qUOgVWc3EdPFTWcleer0YJFsaP61mGApCfwt23ITAmKXHd4h8 qtORdWeC83wPRNGQMgg7RXqN3HudrlflH/iyNRPU/td06QvaJvqmgaZeB0+phgUTI34v RfYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=z4yiZSQ99ENhZHrlff4q5E1G1jFsIl+eTmojhdm+HwU=; b=S8KvAFxghPLbBe+6BK/VVJtGJk7amMONJDWli/c4pzzVKAqSPgR7+Okfl91FAzZTxx NIQjSWXk1NGGLumXwbP6sUxuXnkCnHSAh+6xX8VXwPub+OSFjEi7gI5tQd5Q9BZcFfxZ 9jD/PXyzFs5r27yWrHll0/k5JTV8gJwR0XknJFsvaKO9ln/VbWGNO9CXGUo505AnV721 n6xaEuOYmRfTLDAcSwBIEupP9U+z6LeYnpcCMJXHKYl3OuRIAXBabDbRd5+GTodTKd// 7bkVVaNVNkBhR/MeVYyCjek9WTNIXo+xhYjRHA+h9byf8nyj4YhHBX2L6G0YGPhM/Je8 sczw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V8reibrh; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si15595767pfa.253.2019.06.12.00.35.32; Wed, 12 Jun 2019 00:35:51 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V8reibrh; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408426AbfFLCXd (ORCPT + 99 others); Tue, 11 Jun 2019 22:23:33 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:50485 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408418AbfFLCXc (ORCPT ); Tue, 11 Jun 2019 22:23:32 -0400 Received: by mail-it1-f195.google.com with SMTP id j194so8376521ite.0; Tue, 11 Jun 2019 19:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=z4yiZSQ99ENhZHrlff4q5E1G1jFsIl+eTmojhdm+HwU=; b=V8reibrhUHw2gShqHRDeccOb27V+px/0LSyyh6pXic42k9lka9mR5WTZxN1laDtfwU ipiIxqbrlvzwVsaBcbsEkRLFC78otUYZpmUubFnwW+YGcNogMK9lUVIZ1ts2uleI+6s9 4EqAQmUXst9DUl2MkB9FT0yry0GNJfH4iXwICAnGPhTNqaj3nvtU/1DOBJIN+jKsLqVf awye1V2XPhvMBZPEQ3ZLRHVZDjCQ07FO9Tm1ceQNaC6IMvvNG7i9BSmEZ4haEfTpL0Mk N1lin4CTKuO+eugkrbWTZa/W4l5mC5uteY6X6247c3ND0xr8QTz4yTJ8+Id9q1nJTsaW MmRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=z4yiZSQ99ENhZHrlff4q5E1G1jFsIl+eTmojhdm+HwU=; b=rjVoZULGSfLEXYwxvcFQPmCv4M6zVLOj1a9N8hXFGmVF+i9R6z2L0eG9iAyHVOcAxE 714eh5HLN+izHugu7EeTTVwzrEkhIaAIfpxMfoDrWBwwrgxh3+GjKiC343Ds7SWke1O8 J/mMJumSHasO83fRCfJPkj0RyrdsKwuUfyDWPoZNav4PQ+mQqwu0l3doEIZ0AliDsqjo iF8nZbIDyEAuJnC1eKsqD64kS2GePhazy8n3IepYIl+GNfP7DFjrO+sZ+FhlwrgWhPh0 EBgX7f0OAmJ/kYncrtmdK32r9cAd3Yk1BxA4sJqbasXd5M63vNppzF4b4aahm1HfjiMj 2Dkw== X-Gm-Message-State: APjAAAVlZ82yaXpZzhP5ZOpgumMOlxSoEdCmETF/MRoR8EPbtDAU0YbT LJe5LNHPnsNSQ01AonoSP/Lx9Cd9ebR2hHaU3Fk= X-Received: by 2002:a05:660c:101:: with SMTP id w1mr3410942itj.49.1560306211305; Tue, 11 Jun 2019 19:23:31 -0700 (PDT) MIME-Version: 1.0 References: <1558678046-4052-1-git-send-email-ley.foon.tan@intel.com> <1558678046-4052-2-git-send-email-ley.foon.tan@intel.com> <20190530152548.GD13993@redmoon> In-Reply-To: <20190530152548.GD13993@redmoon> From: Ley Foon Tan Date: Wed, 12 Jun 2019 10:23:20 +0800 Message-ID: Subject: Re: [PATCH 1/2] PCI: altera: Fix configuration type based on secondary number To: Lorenzo Pieralisi Cc: Ley Foon Tan , Bjorn Helgaas , linux-kernel@vger.kernel.org, linux-pci Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 30, 2019 at 11:25 PM Lorenzo Pieralisi wrote: > > 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 ? > Okay, will change this. Thanks. Regards Ley Foon