Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3838004rdg; Wed, 18 Oct 2023 07:30:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEVbPS/oAbZH+no4wqf/a8w/7drfoSuQAKqQIlR5tvVPJKgoOoCfx6zLeZZypgwAVFXfvu X-Received: by 2002:a05:6870:212:b0:1e9:a770:61eb with SMTP id j18-20020a056870021200b001e9a77061ebmr6409327oad.29.1697639404503; Wed, 18 Oct 2023 07:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697639404; cv=none; d=google.com; s=arc-20160816; b=g6xcLsdvaAvp34Jc8maDYZRfNj1zwilL8IhtaEFgdYIDhEM837vtZicIp4SAOCHJOE RD3LSC2oSuV6LDz0QPUcX7DjxX4AlTszHPct+MGyORCNYESVsXIzYP9demJgRMhNst+9 0hQs4DnVnqD3J/ednfeqUSPsHzec+sDUegNts2rwgbUy5AYq6Y4S/LU6jp9tcvV4lT8e LHgyu+I3T8e94fzVqHu+eWQV2xuUSxxPjc+ob3otdcIwr3SrMNFhOBQ4mMbdvQTsyxE7 ZUW4qHSbdiRz3DUSizKkhQNMA6QTjzDeWZF1Llj058Rdw8vTkPD07EqxtJH8PL/3NcKt k8FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=Vl5Q7sMXLw3/g8J3ovxOrNC+O6rIZHlufEnX+oIzoc4=; fh=7cfINgaE0ymtoLwWetKI8ZCpIeqwceKuouitB+oM/BI=; b=nMVOCLNihGU1OdWkqcOL5MoAcVMYqhmeu/RBbZKgn7cYm5HUqq7375mS3Ki9qhWhPv 2jQcsW2zsG3wcaooa9OP1o7nSdvlrc0bvIqebDIz40Yj9KG40HsC2aCVVKhyxQyN4mfo wdiUhfNWgo1SEjK/fNZuEzu6AWaeADhS2nc6bYkZ1CwtTJMYA39FgW3yvY+eTdfNxKbX Z39oewyWZsZ7tA/L2fGGZJPgxWKoktxhoYu8f2pHYPo2S76mqcviehyrTBnHONRB4usV y3HM01XawJ9EwvDE0iRPBpaR20xjI933Aokm9KO63VWAtejXEfXgdAWXPLnTI8whk9dD Sr7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JWndZsc0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id l19-20020a637013000000b005ad1edab539si2168759pgc.319.2023.10.18.07.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 07:30:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JWndZsc0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 855478211427; Wed, 18 Oct 2023 07:30:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345727AbjJRO3k (ORCPT + 99 others); Wed, 18 Oct 2023 10:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345659AbjJRO3T (ORCPT ); Wed, 18 Oct 2023 10:29:19 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26B828256; Wed, 18 Oct 2023 07:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697638797; x=1729174797; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=XjapHZdAAIXb/r8LmmNmC/q9/lNmCHm8wGhPv3dzY2Q=; b=JWndZsc0XLQmqFOb5jaJjcDjpUbYzO1Sbe6+yNEC2zniuCyO+LYHL+jI I7DRAotzHN+hukxOuuicNWNpmQriutc2rc93/KKmCLCuaHguMeev3w5f/ EU48s/d5dHlhZfJqblVoSgSBXSo7zIgz/MFkPoyadwR+UNPMzMsdBjGB5 7h+CIozq6E6dmD6gHPJurt2pllHgWQ1Kexp0x/VbFOLS81uGRo/5DX9d8 +N8wmD39f1VyRC75Z4wVK7Y2texfOG7vLiCxAg1qlQYeqbdK/a3vLyeU4 RsWQOLb14lZ3Jzvw+jcqB3r7+WK1dJuRpxrH4/Kg2b1ZLr1uGevyWDiUL Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="389898425" X-IronPort-AV: E=Sophos;i="6.03,235,1694761200"; d="scan'208";a="389898425" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 07:16:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10867"; a="873034283" X-IronPort-AV: E=Sophos;i="6.03,235,1694761200"; d="scan'208";a="873034283" Received: from gruberda-mobl1.ger.corp.intel.com ([10.252.62.52]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2023 07:16:39 -0700 Date: Wed, 18 Oct 2023 17:16:36 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Serge Semin cc: Bjorn Helgaas , linux-pci@vger.kernel.org, Lorenzo Pieralisi , Rob Herring , =?ISO-8859-2?Q?Krzysztof_Wilczy=F1ski?= , Jonathan Cameron , Jingoo Han , Gustavo Pimentel , Manivannan Sadhasivam , Lorenzo Pieralisi , Thierry Reding , Jonathan Hunter , LKML , linux-tegra@vger.kernel.org Subject: Re: [PATCH 2/7] PCI: dwc: Use FIELD_GET/PREP() In-Reply-To: <3o4neokfqofk42zrx5t5su72qmdu2x62rq5u2ywfobqyyg23rc@aksd3afajhwr> Message-ID: <293b90ca-dab1-eef3-e718-c93295442d9@linux.intel.com> References: <20231018113254.17616-1-ilpo.jarvinen@linux.intel.com> <20231018113254.17616-3-ilpo.jarvinen@linux.intel.com> <3o4neokfqofk42zrx5t5su72qmdu2x62rq5u2ywfobqyyg23rc@aksd3afajhwr> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-849054604-1697638602=:2178" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 18 Oct 2023 07:30:01 -0700 (PDT) This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-849054604-1697638602=:2178 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT On Wed, 18 Oct 2023, Serge Semin wrote: > On Wed, Oct 18, 2023 at 02:32:49PM +0300, Ilpo J?rvinen wrote: > > Convert open-coded variants of PCI field access into FIELD_GET/PREP() > > to make the code easier to understand. > > > > Add two missing defines into pci_regs.h. Logically, the Max No-Snoop > > Latency Register is a separate word sized register in the PCIe spec, > > but the pre-existing LTR defines in pci_regs.h with dword long values > > seem to consider the registers together (the same goes for the only > > user). Thus, follow the custom and make the new values also take both > > word long LTR registers as a joint dword register. > > Nice work. Thanks! Could you also have a look at > drivers/pci/controller/dwc/pcie-designware.c > ? > It contains two open-coded patterns: > (bar << 8) - FIELD_PREP() > next_cap_ptr = (reg & 0xff00) >> 8; - FIELD_GET(). > next_cap_ptr = (reg & 0x00ff); - FIELD_GET(). > At least the later two statements concern the generic PCIe capability CSR. The problem with cap id / next cap is that there are currently no defines for them AFAICT, at least not in pci_regs.h. And pci_regs.h defines those as different registers so if I'm to add defines from them, I don't know which size would be the most appropriate since that 0xff00 goes across that register boundary. I've not had time to study the related core code yet but I intend to take a look at it to see what's the best course of action forward. -- i. > > Signed-off-by: Ilpo J?rvinen > > --- > > drivers/pci/controller/dwc/pcie-designware-ep.c | 7 ++++--- > > drivers/pci/controller/dwc/pcie-tegra194.c | 5 ++--- > > include/uapi/linux/pci_regs.h | 2 ++ > > 3 files changed, 8 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c > > index f9182f8d552f..20bef1436bfb 100644 > > --- a/drivers/pci/controller/dwc/pcie-designware-ep.c > > +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c > > @@ -6,6 +6,7 @@ > > * Author: Kishon Vijay Abraham I > > */ > > > > +#include > > #include > > #include > > > > @@ -334,7 +335,7 @@ static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no) > > if (!(val & PCI_MSI_FLAGS_ENABLE)) > > return -EINVAL; > > > > - val = (val & PCI_MSI_FLAGS_QSIZE) >> 4; > > + val = FIELD_GET(PCI_MSI_FLAGS_QSIZE, val); > > > > return val; > > } > > @@ -357,7 +358,7 @@ static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, > > reg = ep_func->msi_cap + func_offset + PCI_MSI_FLAGS; > > val = dw_pcie_readw_dbi(pci, reg); > > val &= ~PCI_MSI_FLAGS_QMASK; > > - val |= (interrupts << 1) & PCI_MSI_FLAGS_QMASK; > > + val |= FIELD_PREP(PCI_MSI_FLAGS_QMASK, interrupts); > > dw_pcie_dbi_ro_wr_en(pci); > > dw_pcie_writew_dbi(pci, reg, val); > > dw_pcie_dbi_ro_wr_dis(pci); > > @@ -584,7 +585,7 @@ int dw_pcie_ep_raise_msix_irq(struct dw_pcie_ep *ep, u8 func_no, > > > > reg = ep_func->msix_cap + func_offset + PCI_MSIX_TABLE; > > tbl_offset = dw_pcie_readl_dbi(pci, reg); > > - bir = (tbl_offset & PCI_MSIX_TABLE_BIR); > > + bir = FIELD_GET(PCI_MSIX_TABLE_BIR, tbl_offset); > > tbl_offset &= PCI_MSIX_TABLE_OFFSET; > > > > msix_tbl = ep->epf_bar[bir]->addr + tbl_offset; > > diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c > > index 248cd9347e8f..12d5ab2f5219 100644 > > --- a/drivers/pci/controller/dwc/pcie-tegra194.c > > +++ b/drivers/pci/controller/dwc/pcie-tegra194.c > > @@ -126,7 +126,6 @@ > > > > #define APPL_LTR_MSG_1 0xC4 > > #define LTR_MSG_REQ BIT(15) > > -#define LTR_MST_NO_SNOOP_SHIFT 16 > > > > #define APPL_LTR_MSG_2 0xC8 > > #define APPL_LTR_MSG_2_LTR_MSG_REQ_STATE BIT(3) > > @@ -496,8 +495,8 @@ static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg) > > ktime_t timeout; > > > > /* 110us for both snoop and no-snoop */ > > - val = 110 | (2 << PCI_LTR_SCALE_SHIFT) | LTR_MSG_REQ; > > - val |= (val << LTR_MST_NO_SNOOP_SHIFT); > > + val = 110 | FIELD_PREP(PCI_LTR_SCALE_SHIFT, 2) | LTR_MSG_REQ; > > + val |= FIELD_PREP(PCI_LTR_NOSNOOP_VALUE, val); > > appl_writel(pcie, val, APPL_LTR_MSG_1); > > > > /* Send LTR upstream */ > > diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h > > index e5f558d96493..495f0ae4ecd5 100644 > > --- a/include/uapi/linux/pci_regs.h > > +++ b/include/uapi/linux/pci_regs.h > > @@ -975,6 +975,8 @@ > > #define PCI_LTR_VALUE_MASK 0x000003ff > > #define PCI_LTR_SCALE_MASK 0x00001c00 > > #define PCI_LTR_SCALE_SHIFT 10 > > +#define PCI_LTR_NOSNOOP_VALUE 0x03ff0000 /* Max No-Snoop Latency Value */ > > +#define PCI_LTR_NOSNOOP_SCALE 0x1c000000 /* Scale for Max Value */ > > #define PCI_EXT_CAP_LTR_SIZEOF 8 > > > > /* Access Control Service */ > > -- > > 2.30.2 > > > --8323329-849054604-1697638602=:2178--