Skip to content

Commit 92af77c

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: dwc: Use FIELD_GET/PREP()
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. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent b09d0f9 commit 92af77c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

drivers/pci/controller/dwc/pcie-designware-ep.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Author: Kishon Vijay Abraham I <[email protected]>
77
*/
88

9+
#include <linux/bitfield.h>
910
#include <linux/of.h>
1011
#include <linux/platform_device.h>
1112

@@ -334,7 +335,7 @@ static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
334335
if (!(val & PCI_MSI_FLAGS_ENABLE))
335336
return -EINVAL;
336337

337-
val = (val & PCI_MSI_FLAGS_QSIZE) >> 4;
338+
val = FIELD_GET(PCI_MSI_FLAGS_QSIZE, val);
338339

339340
return val;
340341
}
@@ -357,7 +358,7 @@ static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
357358
reg = ep_func->msi_cap + func_offset + PCI_MSI_FLAGS;
358359
val = dw_pcie_readw_dbi(pci, reg);
359360
val &= ~PCI_MSI_FLAGS_QMASK;
360-
val |= (interrupts << 1) & PCI_MSI_FLAGS_QMASK;
361+
val |= FIELD_PREP(PCI_MSI_FLAGS_QMASK, interrupts);
361362
dw_pcie_dbi_ro_wr_en(pci);
362363
dw_pcie_writew_dbi(pci, reg, val);
363364
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,
584585

585586
reg = ep_func->msix_cap + func_offset + PCI_MSIX_TABLE;
586587
tbl_offset = dw_pcie_readl_dbi(pci, reg);
587-
bir = (tbl_offset & PCI_MSIX_TABLE_BIR);
588+
bir = FIELD_GET(PCI_MSIX_TABLE_BIR, tbl_offset);
588589
tbl_offset &= PCI_MSIX_TABLE_OFFSET;
589590

590591
msix_tbl = ep->epf_bar[bir]->addr + tbl_offset;

drivers/pci/controller/dwc/pcie-tegra194.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126

127127
#define APPL_LTR_MSG_1 0xC4
128128
#define LTR_MSG_REQ BIT(15)
129-
#define LTR_MST_NO_SNOOP_SHIFT 16
129+
#define LTR_NOSNOOP_MSG_REQ BIT(31)
130130

131131
#define APPL_LTR_MSG_2 0xC8
132132
#define APPL_LTR_MSG_2_LTR_MSG_REQ_STATE BIT(3)
@@ -496,8 +496,12 @@ static irqreturn_t tegra_pcie_ep_irq_thread(int irq, void *arg)
496496
ktime_t timeout;
497497

498498
/* 110us for both snoop and no-snoop */
499-
val = 110 | (2 << PCI_LTR_SCALE_SHIFT) | LTR_MSG_REQ;
500-
val |= (val << LTR_MST_NO_SNOOP_SHIFT);
499+
val = FIELD_PREP(PCI_LTR_VALUE_MASK, 110) |
500+
FIELD_PREP(PCI_LTR_SCALE_MASK, 2) |
501+
LTR_MSG_REQ |
502+
FIELD_PREP(PCI_LTR_NOSNOOP_VALUE, 110) |
503+
FIELD_PREP(PCI_LTR_NOSNOOP_SCALE, 2) |
504+
LTR_NOSNOOP_MSG_REQ;
501505
appl_writel(pcie, val, APPL_LTR_MSG_1);
502506

503507
/* Send LTR upstream */

include/uapi/linux/pci_regs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@
975975
#define PCI_LTR_VALUE_MASK 0x000003ff
976976
#define PCI_LTR_SCALE_MASK 0x00001c00
977977
#define PCI_LTR_SCALE_SHIFT 10
978+
#define PCI_LTR_NOSNOOP_VALUE 0x03ff0000 /* Max No-Snoop Latency Value */
979+
#define PCI_LTR_NOSNOOP_SCALE 0x1c000000 /* Scale for Max Value */
978980
#define PCI_EXT_CAP_LTR_SIZEOF 8
979981

980982
/* Access Control Service */

0 commit comments

Comments
 (0)