From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Serge Semin <fancer.lancer@gmail.com>
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
linux-pci@vger.kernel.org,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
"Jingoo Han" <jingoohan1@gmail.com>,
"Gustavo Pimentel" <gustavo.pimentel@synopsys.com>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-tegra@vger.kernel.org
Subject: Re: [PATCH 2/7] PCI: dwc: Use FIELD_GET/PREP()
Date: Wed, 18 Oct 2023 17:16:36 +0300 (EEST) [thread overview]
Message-ID: <293b90ca-dab1-eef3-e718-c93295442d9@linux.intel.com> (raw)
In-Reply-To: <3o4neokfqofk42zrx5t5su72qmdu2x62rq5u2ywfobqyyg23rc@aksd3afajhwr>
[-- Attachment #1: Type: text/plain, Size: 5003 bytes --]
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 <ilpo.jarvinen@linux.intel.com>
> > ---
> > 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 <kishon@ti.com>
> > */
> >
> > +#include <linux/bitfield.h>
> > #include <linux/of.h>
> > #include <linux/platform_device.h>
> >
> > @@ -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
> >
>
next prev parent reply other threads:[~2023-10-18 14:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 11:32 [PATCH 0/7] PCI: Use FIELD_GET/PREP() & other reg field cleanups Ilpo Järvinen
2023-10-18 11:32 ` [PATCH 1/7] PCI: cadence: Use FIELD_GET() Ilpo Järvinen
2023-10-18 11:32 ` [PATCH 2/7] PCI: dwc: Use FIELD_GET/PREP() Ilpo Järvinen
2023-10-18 11:58 ` Serge Semin
2023-10-18 14:16 ` Ilpo Järvinen [this message]
2023-10-18 11:32 ` [PATCH 3/7] PCI: hotplug: " Ilpo Järvinen
2023-10-18 11:32 ` [PATCH 4/7] PCI/DPC: Use FIELD_GET() Ilpo Järvinen
2023-10-18 11:32 ` [PATCH 5/7] PCI/DPC: Use defined fields with DPC_CTL register Ilpo Järvinen
2023-10-18 11:32 ` [PATCH 6/7] PCI/DPC: Use defines with DPC reason fields Ilpo Järvinen
2023-10-18 11:32 ` [PATCH 7/7] PCI/MSI: Use FIELD_GET/PREP() Ilpo Järvinen
2023-10-18 16:23 ` [PATCH 0/7] PCI: Use FIELD_GET/PREP() & other reg field cleanups Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=293b90ca-dab1-eef3-e718-c93295442d9@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=bhelgaas@google.com \
--cc=fancer.lancer@gmail.com \
--cc=gustavo.pimentel@synopsys.com \
--cc=jingoohan1@gmail.com \
--cc=jonathanh@nvidia.com \
--cc=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@kernel.org \
--cc=thierry.reding@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.