Skip to content

Commit 997b99e

Browse files
Vidya Sagarbjorn-helgaas
authored andcommitted
PCI: tegra194: Find RAS DES PCIe capability offset
Find RAS DES PCIe capability offset instead of hardcoding the offset for each controller. Link: https://lore.kernel.org/r/20220721142052.25971-10-vidyas@nvidia.com Signed-off-by: Vidya Sagar <vidyas@nvidia.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent f1ab409 commit 997b99e

2 files changed

Lines changed: 35 additions & 37 deletions

File tree

drivers/pci/controller/dwc/pcie-designware.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@
130130
#define PCIE_ATU_UNR_UPPER_TARGET 0x18
131131
#define PCIE_ATU_UNR_UPPER_LIMIT 0x20
132132

133+
/*
134+
* RAS-DES register definitions
135+
*/
136+
#define PCIE_RAS_DES_EVENT_COUNTER_CONTROL 0x8
137+
#define EVENT_COUNTER_ALL_CLEAR 0x3
138+
#define EVENT_COUNTER_ENABLE_ALL 0x7
139+
#define EVENT_COUNTER_ENABLE_SHIFT 2
140+
#define EVENT_COUNTER_EVENT_SEL_MASK GENMASK(7, 0)
141+
#define EVENT_COUNTER_EVENT_SEL_SHIFT 16
142+
#define EVENT_COUNTER_EVENT_Tx_L0S 0x2
143+
#define EVENT_COUNTER_EVENT_Rx_L0S 0x3
144+
#define EVENT_COUNTER_EVENT_L1 0x5
145+
#define EVENT_COUNTER_EVENT_L1_1 0x7
146+
#define EVENT_COUNTER_EVENT_L1_2 0x8
147+
#define EVENT_COUNTER_GROUP_SEL_SHIFT 24
148+
#define EVENT_COUNTER_GROUP_5 0x5
149+
150+
#define PCIE_RAS_DES_EVENT_COUNTER_DATA 0xc
151+
133152
/*
134153
* The default address offset between dbi_base and atu_base. Root controller
135154
* drivers are not required to initialize atu_base if the offset matches this

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

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,6 @@
170170
#define CFG_TIMER_CTRL_MAX_FUNC_NUM_OFF 0x718
171171
#define CFG_TIMER_CTRL_ACK_NAK_SHIFT (19)
172172

173-
#define EVENT_COUNTER_ALL_CLEAR 0x3
174-
#define EVENT_COUNTER_ENABLE_ALL 0x7
175-
#define EVENT_COUNTER_ENABLE_SHIFT 2
176-
#define EVENT_COUNTER_EVENT_SEL_MASK GENMASK(7, 0)
177-
#define EVENT_COUNTER_EVENT_SEL_SHIFT 16
178-
#define EVENT_COUNTER_EVENT_Tx_L0S 0x2
179-
#define EVENT_COUNTER_EVENT_Rx_L0S 0x3
180-
#define EVENT_COUNTER_EVENT_L1 0x5
181-
#define EVENT_COUNTER_EVENT_L1_1 0x7
182-
#define EVENT_COUNTER_EVENT_L1_2 0x8
183-
#define EVENT_COUNTER_GROUP_SEL_SHIFT 24
184-
#define EVENT_COUNTER_GROUP_5 0x5
185-
186173
#define N_FTS_VAL 52
187174
#define FTS_VAL 52
188175

@@ -266,6 +253,7 @@ struct tegra_pcie_dw {
266253
u32 num_lanes;
267254
u32 cid;
268255
u32 cfg_link_cap_l1sub;
256+
u32 ras_des_cap;
269257
u32 pcie_cap_base;
270258
u32 aspm_cmrt;
271259
u32 aspm_pwr_on_t;
@@ -574,24 +562,6 @@ static struct pci_ops tegra_pci_ops = {
574562
};
575563

576564
#if defined(CONFIG_PCIEASPM)
577-
static const u32 event_cntr_ctrl_offset[] = {
578-
0x1d8,
579-
0x1a8,
580-
0x1a8,
581-
0x1a8,
582-
0x1c4,
583-
0x1d8
584-
};
585-
586-
static const u32 event_cntr_data_offset[] = {
587-
0x1dc,
588-
0x1ac,
589-
0x1ac,
590-
0x1ac,
591-
0x1c8,
592-
0x1dc
593-
};
594-
595565
static void disable_aspm_l11(struct tegra_pcie_dw *pcie)
596566
{
597567
u32 val;
@@ -614,13 +584,16 @@ static inline u32 event_counter_prog(struct tegra_pcie_dw *pcie, u32 event)
614584
{
615585
u32 val;
616586

617-
val = dw_pcie_readl_dbi(&pcie->pci, event_cntr_ctrl_offset[pcie->cid]);
587+
val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap +
588+
PCIE_RAS_DES_EVENT_COUNTER_CONTROL);
618589
val &= ~(EVENT_COUNTER_EVENT_SEL_MASK << EVENT_COUNTER_EVENT_SEL_SHIFT);
619590
val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
620591
val |= event << EVENT_COUNTER_EVENT_SEL_SHIFT;
621592
val |= EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
622-
dw_pcie_writel_dbi(&pcie->pci, event_cntr_ctrl_offset[pcie->cid], val);
623-
val = dw_pcie_readl_dbi(&pcie->pci, event_cntr_data_offset[pcie->cid]);
593+
dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
594+
PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
595+
val = dw_pcie_readl_dbi(&pcie->pci, pcie->ras_des_cap +
596+
PCIE_RAS_DES_EVENT_COUNTER_DATA);
624597

625598
return val;
626599
}
@@ -647,13 +620,15 @@ static int aspm_state_cnt(struct seq_file *s, void *data)
647620
event_counter_prog(pcie, EVENT_COUNTER_EVENT_L1_2));
648621

649622
/* Clear all counters */
650-
dw_pcie_writel_dbi(&pcie->pci, event_cntr_ctrl_offset[pcie->cid],
623+
dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
624+
PCIE_RAS_DES_EVENT_COUNTER_CONTROL,
651625
EVENT_COUNTER_ALL_CLEAR);
652626

653627
/* Re-enable counting */
654628
val = EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
655629
val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
656-
dw_pcie_writel_dbi(&pcie->pci, event_cntr_ctrl_offset[pcie->cid], val);
630+
dw_pcie_writel_dbi(&pcie->pci, pcie->ras_des_cap +
631+
PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
657632

658633
return 0;
659634
}
@@ -666,10 +641,14 @@ static void init_host_aspm(struct tegra_pcie_dw *pcie)
666641
val = dw_pcie_find_ext_capability(pci, PCI_EXT_CAP_ID_L1SS);
667642
pcie->cfg_link_cap_l1sub = val + PCI_L1SS_CAP;
668643

644+
pcie->ras_des_cap = dw_pcie_find_ext_capability(&pcie->pci,
645+
PCI_EXT_CAP_ID_VNDR);
646+
669647
/* Enable ASPM counters */
670648
val = EVENT_COUNTER_ENABLE_ALL << EVENT_COUNTER_ENABLE_SHIFT;
671649
val |= EVENT_COUNTER_GROUP_5 << EVENT_COUNTER_GROUP_SEL_SHIFT;
672-
dw_pcie_writel_dbi(pci, event_cntr_ctrl_offset[pcie->cid], val);
650+
dw_pcie_writel_dbi(pci, pcie->ras_des_cap +
651+
PCIE_RAS_DES_EVENT_COUNTER_CONTROL, val);
673652

674653
/* Program T_cmrt and T_pwr_on values */
675654
val = dw_pcie_readl_dbi(pci, pcie->cfg_link_cap_l1sub);

0 commit comments

Comments
 (0)