Skip to content

Commit bc55afb

Browse files
committed
Merge branch 'pci/controller/dwc-rockchip'
- Add tracepoints for PCIe controller LTSSM transitions and link rate changes (Shawn Lin) - Trace LTSSM events collected by the dw-rockchip debug FIFO (Shawn Lin) * pci/controller/dwc-rockchip: PCI: dw-rockchip: Add pcie_ltssm_state_transition tracepoint support Documentation: tracing: Add PCI controller event documentation PCI: trace: Add PCI controller tracepoint feature
2 parents 1e6df55 + f3ddb8a commit bc55afb

6 files changed

Lines changed: 215 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
======================================
4+
Subsystem Trace Points: PCI Controller
5+
======================================
6+
7+
Overview
8+
========
9+
The PCI controller tracing system provides tracepoints to monitor controller
10+
level information for debugging purpose. The events normally show up here:
11+
12+
/sys/kernel/tracing/events/pci_controller
13+
14+
Cf. include/trace/events/pci_controller.h for the events definitions.
15+
16+
Available Tracepoints
17+
=====================
18+
19+
pcie_ltssm_state_transition
20+
---------------------------
21+
22+
Monitors PCIe LTSSM state transition including state and rate information
23+
::
24+
25+
pcie_ltssm_state_transition "dev: %s state: %s rate: %s\n"
26+
27+
**Parameters**:
28+
29+
* ``dev`` - PCIe controller instance
30+
* ``state`` - PCIe LTSSM state
31+
* ``rate`` - PCIe date rate
32+
33+
**Example Usage**:
34+
35+
.. code-block:: shell
36+
37+
# Enable the tracepoint
38+
echo 1 > /sys/kernel/debug/tracing/events/pci_controller/pcie_ltssm_state_transition/enable
39+
40+
# Monitor events (the following output is generated when a device is linking)
41+
cat /sys/kernel/debug/tracing/trace_pipe
42+
kworker/0:0-9 [000] ..... 5.600221: pcie_ltssm_state_transition: dev: a40000000.pcie state: RCVRY_EQ2 rate: 8.0 GT/s

Documentation/trace/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ applications.
5555
events-nmi
5656
events-msr
5757
events-pci
58+
events-pci-controller
5859
boottime-trace
5960
histogram
6061
histogram-design

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20403,9 +20403,11 @@ C: irc://irc.oftc.net/linux-pci
2040320403
T: git git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git
2040420404
F: Documentation/ABI/testing/debugfs-pcie-ptm
2040520405
F: Documentation/devicetree/bindings/pci/
20406+
F: Documentation/trace/events-pci-controller.rst
2040620407
F: drivers/pci/controller/
2040720408
F: drivers/pci/pci-bridge-emul.c
2040820409
F: drivers/pci/pci-bridge-emul.h
20410+
F: include/trace/events/pci_controller.h
2040920411

2041020412
PCI PEER-TO-PEER DMA (P2PDMA)
2041120413
M: Bjorn Helgaas <bhelgaas@google.com>

drivers/pci/controller/dwc/pcie-dw-rockchip.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <linux/platform_device.h>
2323
#include <linux/regmap.h>
2424
#include <linux/reset.h>
25+
#include <linux/workqueue.h>
26+
#include <trace/events/pci_controller.h>
2527

2628
#include "../../pci.h"
2729
#include "pcie-designware.h"
@@ -73,6 +75,20 @@
7375
#define PCIE_CLIENT_CDM_RASDES_TBA_L1_1 BIT(4)
7476
#define PCIE_CLIENT_CDM_RASDES_TBA_L1_2 BIT(5)
7577

78+
/* Debug FIFO information */
79+
#define PCIE_CLIENT_DBG_FIFO_MODE_CON 0x310
80+
#define PCIE_CLIENT_DBG_EN 0xffff0007
81+
#define PCIE_CLIENT_DBG_DIS 0xffff0000
82+
#define PCIE_CLIENT_DBG_FIFO_PTN_HIT_D0 0x320
83+
#define PCIE_CLIENT_DBG_FIFO_PTN_HIT_D1 0x324
84+
#define PCIE_CLIENT_DBG_FIFO_TRN_HIT_D0 0x328
85+
#define PCIE_CLIENT_DBG_FIFO_TRN_HIT_D1 0x32c
86+
#define PCIE_CLIENT_DBG_TRANSITION_DATA 0xffff0000
87+
#define PCIE_CLIENT_DBG_FIFO_STATUS 0x350
88+
#define PCIE_DBG_FIFO_RATE_MASK GENMASK(22, 20)
89+
#define PCIE_DBG_FIFO_L1SUB_MASK GENMASK(10, 8)
90+
#define PCIE_DBG_LTSSM_HISTORY_CNT 64
91+
7692
/* Hot Reset Control Register */
7793
#define PCIE_CLIENT_HOT_RESET_CTRL 0x180
7894
#define PCIE_LTSSM_APP_DLY2_EN BIT(1)
@@ -98,6 +114,7 @@ struct rockchip_pcie {
98114
struct irq_domain *irq_domain;
99115
const struct rockchip_pcie_of_data *data;
100116
bool supports_clkreq;
117+
struct delayed_work trace_work;
101118
};
102119

103120
struct rockchip_pcie_of_data {
@@ -208,6 +225,96 @@ static enum dw_pcie_ltssm rockchip_pcie_get_ltssm(struct dw_pcie *pci)
208225
return rockchip_pcie_get_ltssm_reg(rockchip) & PCIE_LTSSM_STATUS_MASK;
209226
}
210227

228+
#ifdef CONFIG_TRACING
229+
static void rockchip_pcie_ltssm_trace_work(struct work_struct *work)
230+
{
231+
struct rockchip_pcie *rockchip = container_of(work,
232+
struct rockchip_pcie,
233+
trace_work.work);
234+
struct dw_pcie *pci = &rockchip->pci;
235+
enum dw_pcie_ltssm state;
236+
u32 i, l1ss, prev_val = DW_PCIE_LTSSM_UNKNOWN, rate, val;
237+
238+
if (!trace_pcie_ltssm_state_transition_enabled())
239+
goto skip_trace;
240+
241+
for (i = 0; i < PCIE_DBG_LTSSM_HISTORY_CNT; i++) {
242+
val = rockchip_pcie_readl_apb(rockchip,
243+
PCIE_CLIENT_DBG_FIFO_STATUS);
244+
rate = FIELD_GET(PCIE_DBG_FIFO_RATE_MASK, val);
245+
l1ss = FIELD_GET(PCIE_DBG_FIFO_L1SUB_MASK, val);
246+
val = FIELD_GET(PCIE_LTSSM_STATUS_MASK, val);
247+
248+
/*
249+
* Hardware Mechanism: The ring FIFO employs two tracking
250+
* counters:
251+
* - 'last-read-point': maintains the user's last read position
252+
* - 'last-valid-point': tracks the HW's last state update
253+
*
254+
* Software Handling: When two consecutive LTSSM states are
255+
* identical, it indicates invalid subsequent data in the FIFO.
256+
* In this case, we skip the remaining entries. The dual counter
257+
* design ensures that on the next state transition, reading can
258+
* resume from the last user position.
259+
*/
260+
if ((i > 0 && val == prev_val) || val > DW_PCIE_LTSSM_RCVRY_EQ3)
261+
break;
262+
263+
state = prev_val = val;
264+
if (val == DW_PCIE_LTSSM_L1_IDLE) {
265+
if (l1ss == 2)
266+
state = DW_PCIE_LTSSM_L1_2;
267+
else if (l1ss == 1)
268+
state = DW_PCIE_LTSSM_L1_1;
269+
}
270+
271+
trace_pcie_ltssm_state_transition(dev_name(pci->dev),
272+
dw_pcie_ltssm_status_string(state),
273+
((rate + 1) > pci->max_link_speed) ?
274+
PCI_SPEED_UNKNOWN : PCIE_SPEED_2_5GT + rate);
275+
}
276+
277+
skip_trace:
278+
schedule_delayed_work(&rockchip->trace_work, msecs_to_jiffies(5000));
279+
}
280+
281+
static void rockchip_pcie_ltssm_trace(struct rockchip_pcie *rockchip,
282+
bool enable)
283+
{
284+
if (enable) {
285+
rockchip_pcie_writel_apb(rockchip,
286+
PCIE_CLIENT_DBG_TRANSITION_DATA,
287+
PCIE_CLIENT_DBG_FIFO_PTN_HIT_D0);
288+
rockchip_pcie_writel_apb(rockchip,
289+
PCIE_CLIENT_DBG_TRANSITION_DATA,
290+
PCIE_CLIENT_DBG_FIFO_PTN_HIT_D1);
291+
rockchip_pcie_writel_apb(rockchip,
292+
PCIE_CLIENT_DBG_TRANSITION_DATA,
293+
PCIE_CLIENT_DBG_FIFO_TRN_HIT_D0);
294+
rockchip_pcie_writel_apb(rockchip,
295+
PCIE_CLIENT_DBG_TRANSITION_DATA,
296+
PCIE_CLIENT_DBG_FIFO_TRN_HIT_D1);
297+
rockchip_pcie_writel_apb(rockchip,
298+
PCIE_CLIENT_DBG_EN,
299+
PCIE_CLIENT_DBG_FIFO_MODE_CON);
300+
301+
INIT_DELAYED_WORK(&rockchip->trace_work,
302+
rockchip_pcie_ltssm_trace_work);
303+
schedule_delayed_work(&rockchip->trace_work, 0);
304+
} else {
305+
rockchip_pcie_writel_apb(rockchip,
306+
PCIE_CLIENT_DBG_DIS,
307+
PCIE_CLIENT_DBG_FIFO_MODE_CON);
308+
cancel_delayed_work_sync(&rockchip->trace_work);
309+
}
310+
}
311+
#else
312+
static void rockchip_pcie_ltssm_trace(struct rockchip_pcie *rockchip,
313+
bool enable)
314+
{
315+
}
316+
#endif
317+
211318
static void rockchip_pcie_enable_ltssm(struct rockchip_pcie *rockchip)
212319
{
213320
rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_ENABLE_LTSSM,
@@ -291,6 +398,9 @@ static int rockchip_pcie_start_link(struct dw_pcie *pci)
291398
* 100us as we don't know how long should the device need to reset.
292399
*/
293400
msleep(PCIE_T_PVPERL_MS);
401+
402+
rockchip_pcie_ltssm_trace(rockchip, true);
403+
294404
gpiod_set_value_cansleep(rockchip->rst_gpio, 1);
295405

296406
return 0;
@@ -301,6 +411,7 @@ static void rockchip_pcie_stop_link(struct dw_pcie *pci)
301411
struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
302412

303413
rockchip_pcie_disable_ltssm(rockchip);
414+
rockchip_pcie_ltssm_trace(rockchip, false);
304415
}
305416

306417
static int rockchip_pcie_host_init(struct dw_pcie_rp *pp)

drivers/pci/trace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99

1010
#define CREATE_TRACE_POINTS
1111
#include <trace/events/pci.h>
12+
#include <trace/events/pci_controller.h>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#undef TRACE_SYSTEM
3+
#define TRACE_SYSTEM pci_controller
4+
5+
#if !defined(_TRACE_HW_EVENT_PCI_CONTROLLER_H) || defined(TRACE_HEADER_MULTI_READ)
6+
#define _TRACE_HW_EVENT_PCI_CONTROLLER_H
7+
8+
#include <uapi/linux/pci_regs.h>
9+
#include <linux/tracepoint.h>
10+
11+
#define RATE \
12+
EM(PCIE_SPEED_2_5GT, "2.5 GT/s") \
13+
EM(PCIE_SPEED_5_0GT, "5.0 GT/s") \
14+
EM(PCIE_SPEED_8_0GT, "8.0 GT/s") \
15+
EM(PCIE_SPEED_16_0GT, "16.0 GT/s") \
16+
EM(PCIE_SPEED_32_0GT, "32.0 GT/s") \
17+
EM(PCIE_SPEED_64_0GT, "64.0 GT/s") \
18+
EMe(PCI_SPEED_UNKNOWN, "Unknown")
19+
20+
21+
#undef EM
22+
#undef EMe
23+
#define EM(a, b) TRACE_DEFINE_ENUM(a);
24+
#define EMe(a, b) TRACE_DEFINE_ENUM(a);
25+
26+
RATE
27+
28+
#undef EM
29+
#undef EMe
30+
#define EM(a, b) {a, b},
31+
#define EMe(a, b) {a, b}
32+
33+
TRACE_EVENT(pcie_ltssm_state_transition,
34+
TP_PROTO(const char *dev_name, const char *state, u32 rate),
35+
TP_ARGS(dev_name, state, rate),
36+
37+
TP_STRUCT__entry(
38+
__string(dev_name, dev_name)
39+
__string(state, state)
40+
__field(u32, rate)
41+
),
42+
43+
TP_fast_assign(
44+
__assign_str(dev_name);
45+
__assign_str(state);
46+
__entry->rate = rate;
47+
),
48+
49+
TP_printk("dev: %s state: %s rate: %s",
50+
__get_str(dev_name), __get_str(state),
51+
__print_symbolic(__entry->rate, RATE)
52+
)
53+
);
54+
55+
#endif /* _TRACE_HW_EVENT_PCI_CONTROLLER_H */
56+
57+
/* This part must be outside protection */
58+
#include <trace/define_trace.h>

0 commit comments

Comments
 (0)