thunderbolt: Add trace events support for the control channel
Subsystems (2)
PATCH v2 1/1 thunderbolt: Add trace events support for the control channel
From: Gil Fine <[email protected]>
Sometimes it is useful to see the traffic happening inside the control channel, especially when debugging a possible problem. This adds tracepoints close to the hardware which can be enabled dynamically as needed using the standard Linux trace events facility.
---
Previous version:
https://lore.kernel.org/linux-usb/[email protected]/
Changes from the previous version:
- Add domain number to the trace so we can distinquish from which host controller the record is coming in case there are more than one.
- Correct the year in copyright
drivers/thunderbolt/Makefile | 1 + drivers/thunderbolt/ctl.c | 18 +++- drivers/thunderbolt/ctl.h | 4 +- drivers/thunderbolt/domain.c | 2 +- drivers/thunderbolt/trace.h | 188 +++++++++++++++++++++++++++++++++++ 5 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 drivers/thunderbolt/trace.h
drivers/thunderbolt/Makefile +1 -0
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +ccflags-y := -I$(src) obj-${CONFIG_USB4} := thunderbolt.o thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o eeprom.o thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o tmu.o usb4.o
drivers/thunderbolt/ctl.c +16 -2
@@ -15,6 +15,8 @@#include "ctl.h" +#define CREATE_TRACE_POINTS +#include "trace.h" #define TB_CTL_RX_PKG_COUNT 10#define TB_CTL_RETRIES 4
@@ -22,6 +24,7 @@/** * struct tb_ctl - Thunderbolt control channel * @nhi: Pointer to the NHI structure +* @index: Domain number. This will be output with the trace record. * @tx: Transmit ring * @rx: Receive ring * @frame_pool: DMA pool for control messages
@@ -35,6 +38,7 @@*/ struct tb_ctl {struct tb_nhi *nhi; +int index;struct tb_ring *tx;struct tb_ring *rx;
@@ -369,6 +373,9 @@ static int tb_ctl_tx(struct tb_ctl *ctl, const void *data, size_t len, pkg->frame.size = len +4 ; pkg->frame.sof = type; pkg->frame.eof = type; + +trace_tb_tx (ctl->index, type, data, len); +cpu_to_be32_array (pkg->buffer, data, len /4 ); *(__be32 *) (pkg->buffer + len) =tb_crc (pkg->buffer, len);
@@ -384,6 +391,7 @@ static int tb_ctl_tx(struct tb_ctl *ctl, const void *data, size_t len,static bool tb_ctl_handle_event (struct tb_ctl *ctl,enum tb_cfg_pkg_type type,struct ctl_pkg *pkg,size_t size) { +trace_tb_event (ctl->index, type, pkg->buffer, size);return ctl->callback (ctl->callback_data, type, pkg->buffer, size); }
@@ -489,6 +497,9 @@ static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame,* triggered from messing with the active requests. */ req =tb_cfg_request_find (pkg->ctl, pkg); + +trace_tb_rx (pkg->ctl->index, frame->eof, pkg->buffer, frame->size, !req); +if (req) {if (req->copy (req, pkg))schedule_work (&req->work);
@@ -614,6 +625,7 @@ struct tb_cfg_result tb_cfg_request_sync(struct tb_ctl *ctl,/** * tb_ctl_alloc() - allocate a control channel * @nhi: Pointer to NHI +* @index: Domain number * @timeout_msec: Default timeout used with non-raw control messages * @cb: Callback called for plug events * @cb_data: Data passed to @cb
@@ -622,14 +634,16 @@ struct tb_cfg_result tb_cfg_request_sync(struct tb_ctl *ctl,* * Return: Returns a pointer on success or NULL on failure. */ -struct tb_ctl *tb_ctl_alloc (struct tb_nhi *nhi,int timeout_msec,event_cb cb, -void *cb_data) +struct tb_ctl *tb_ctl_alloc (struct tb_nhi *nhi,int index,int timeout_msec, +event_cb cb,void *cb_data) {int i;struct tb_ctl *ctl =kzalloc (sizeof (*ctl),GFP_KERNEL );if (!ctl)return NULL ; + ctl->nhi = nhi; + ctl->index = index; ctl->timeout_msec = timeout_msec; ctl->callback = cb; ctl->callback_data = cb_data;
drivers/thunderbolt/ctl.h +2 -2
@@ -21,8 +21,8 @@ struct tb_ctl;typedef bool (*event_cb )(void *data,enum tb_cfg_pkg_type type,const void *buf,size_t size); -struct tb_ctl *tb_ctl_alloc (struct tb_nhi *nhi,int timeout_msec,event_cb cb, -void *cb_data); +struct tb_ctl *tb_ctl_alloc (struct tb_nhi *nhi,int index,int timeout_msec, +event_cb cb,void *cb_data);void tb_ctl_start (struct tb_ctl *ctl);void tb_ctl_stop (struct tb_ctl *ctl);void tb_ctl_free (struct tb_ctl *ctl);
drivers/thunderbolt/domain.c +1 -1
@@ -397,7 +397,7 @@ struct tb *tb_domain_alloc(struct tb_nhi *nhi, int timeout_msec, size_t privsizeif (!tb->wq) goto err_remove_ida; - tb->ctl =tb_ctl_alloc (nhi, timeout_msec, tb_domain_event_cb, tb); + tb->ctl =tb_ctl_alloc (nhi, tb->index, timeout_msec, tb_domain_event_cb, tb);if (!tb->ctl) goto err_destroy_wq;
drivers/thunderbolt/trace.h new file +188 -0
188 lines not on this page · raw message
Signature · 1 line
2.43.0
Greg KH
maintainerQuoted 9 lines · Mika Westerberg
drivers/thunderbolt/ctl.c +1
-0@@ -22,6 +24,7 @@/** * struct tb_ctl - Thunderbolt control channel * @nhi: Pointer to the NHI structure +* @index: Domain number. This will be output with the trace record. * @tx: Transmit ring * @rx: Receive ring * @frame_pool: DMA pool for control messages
drivers/thunderbolt/ctl.c line 43
Quoted 6 lines
drivers/thunderbolt/ctl.c +1
-0@@ -35,6 +38,7 @@*/ struct tb_ctl {struct tb_nhi *nhi; +int index;struct tb_ring *tx;struct tb_ring *rx;
Did you mean to put a "hole" in the structure like this? If not, please move it around a bit.
thanks,
greg k-h