Skip to content

Commit 677ceae

Browse files
committed
firewire: core: add tracepoints event for self_id_sequence
It is helpful to trace the content of self ID sequence when the core function building bus topology. This commit adds a tracepoints event fot the purpose. It seems not to achieve printing variable length of array in print time without any storage, thus the structure of event includes a superfluous array to store the state of port. Additionally, there is no helper function to print symbol array, thus the state of port is printed as raw value. Link: https://lore.kernel.org/r/20240605235155.116468-12-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent 1ccfd1a commit 677ceae

3 files changed

Lines changed: 79 additions & 2 deletions

File tree

drivers/firewire/core-topology.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ static inline struct fw_node *fw_node(struct list_head *l)
9595
* internally consistent. On success this function returns the
9696
* fw_node corresponding to the local card otherwise NULL.
9797
*/
98-
static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, int self_id_count)
98+
static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, int self_id_count,
99+
unsigned int generation)
99100
{
100101
struct self_id_sequence_enumerator enumerator = {
101102
.cursor = sid,
@@ -139,6 +140,8 @@ static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, int self
139140
}
140141

141142
port_capacity = self_id_sequence_get_port_capacity(quadlet_count);
143+
trace_self_id_sequence(self_id_sequence, quadlet_count, generation);
144+
142145
for (port_index = 0; port_index < port_capacity; ++port_index) {
143146
port_status = self_id_sequence_get_port_status(self_id_sequence, quadlet_count,
144147
port_index);
@@ -482,7 +485,7 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation,
482485
card->bm_abdicate = bm_abdicate;
483486
fw_schedule_bm_work(card, 0);
484487

485-
local_node = build_tree(card, self_ids, self_id_count);
488+
local_node = build_tree(card, self_ids, self_id_count, generation);
486489

487490
update_topology_map(card, self_ids, self_id_count);
488491

drivers/firewire/core-trace.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22
// Copyright (c) 2024 Takashi Sakamoto
33

44
#include <linux/types.h>
5+
#include <linux/err.h>
56
#include "packet-header-definitions.h"
7+
#include "phy-packet-definitions.h"
68

79
#define CREATE_TRACE_POINTS
810
#include <trace/events/firewire.h>
11+
12+
#ifdef TRACEPOINTS_ENABLED
13+
void copy_port_status(u8 *port_status, unsigned int port_capacity,
14+
const u32 *self_id_sequence, unsigned int quadlet_count)
15+
{
16+
unsigned int port_index;
17+
18+
for (port_index = 0; port_index < port_capacity; ++port_index) {
19+
port_status[port_index] =
20+
self_id_sequence_get_port_status(self_id_sequence, quadlet_count, port_index);
21+
}
22+
}
23+
#endif

include/trace/events/firewire.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,65 @@ TRACE_EVENT(bus_reset_handle,
366366
)
367367
);
368368

369+
// Some macros are defined in 'drivers/firewire/phy-packet-definitions.h'.
370+
371+
// The content of TP_printk field is preprocessed, then put to the module binary.
372+
373+
#define PHY_PACKET_SELF_ID_GET_PHY_ID(quads) \
374+
((((const u32 *)quads)[0] & SELF_ID_PHY_ID_MASK) >> SELF_ID_PHY_ID_SHIFT)
375+
376+
#define PHY_PACKET_SELF_ID_GET_LINK_ACTIVE(quads) \
377+
((((const u32 *)quads)[0] & SELF_ID_ZERO_LINK_ACTIVE_MASK) >> SELF_ID_ZERO_LINK_ACTIVE_SHIFT)
378+
379+
#define PHY_PACKET_SELF_ID_GET_GAP_COUNT(quads) \
380+
((((const u32 *)quads)[0] & SELF_ID_ZERO_GAP_COUNT_MASK) >> SELF_ID_ZERO_GAP_COUNT_SHIFT)
381+
382+
#define PHY_PACKET_SELF_ID_GET_SCODE(quads) \
383+
((((const u32 *)quads)[0] & SELF_ID_ZERO_SCODE_MASK) >> SELF_ID_ZERO_SCODE_SHIFT)
384+
385+
#define PHY_PACKET_SELF_ID_GET_CONTENDER(quads) \
386+
((((const u32 *)quads)[0] & SELF_ID_ZERO_CONTENDER_MASK) >> SELF_ID_ZERO_CONTENDER_SHIFT)
387+
388+
#define PHY_PACKET_SELF_ID_GET_POWER_CLASS(quads) \
389+
((((const u32 *)quads)[0] & SELF_ID_ZERO_POWER_CLASS_MASK) >> SELF_ID_ZERO_POWER_CLASS_SHIFT)
390+
391+
#define PHY_PACKET_SELF_ID_GET_INITIATED_RESET(quads) \
392+
((((const u32 *)quads)[0] & SELF_ID_ZERO_INITIATED_RESET_MASK) >> SELF_ID_ZERO_INITIATED_RESET_SHIFT)
393+
394+
void copy_port_status(u8 *port_status, unsigned int port_capacity, const u32 *self_id_sequence,
395+
unsigned int quadlet_count);
396+
397+
TRACE_EVENT(self_id_sequence,
398+
TP_PROTO(const u32 *self_id_sequence, unsigned int quadlet_count, unsigned int generation),
399+
TP_ARGS(self_id_sequence, quadlet_count, generation),
400+
TP_STRUCT__entry(
401+
__field(u8, generation)
402+
__dynamic_array(u8, port_status, self_id_sequence_get_port_capacity(quadlet_count))
403+
__dynamic_array(u32, self_id_sequence, quadlet_count)
404+
),
405+
TP_fast_assign(
406+
__entry->generation = generation;
407+
copy_port_status(__get_dynamic_array(port_status), __get_dynamic_array_len(port_status),
408+
self_id_sequence, quadlet_count);
409+
memcpy(__get_dynamic_array(self_id_sequence), self_id_sequence,
410+
__get_dynamic_array_len(self_id_sequence));
411+
),
412+
TP_printk(
413+
"generation=%u phy_id=0x%02x link_active=%s gap_count=%u scode=%u contender=%s power_class=%u initiated_reset=%s port_status=%s self_id_sequence=%s",
414+
__entry->generation,
415+
PHY_PACKET_SELF_ID_GET_PHY_ID(__get_dynamic_array(self_id_sequence)),
416+
PHY_PACKET_SELF_ID_GET_LINK_ACTIVE(__get_dynamic_array(self_id_sequence)) ? "true" : "false",
417+
PHY_PACKET_SELF_ID_GET_GAP_COUNT(__get_dynamic_array(self_id_sequence)),
418+
PHY_PACKET_SELF_ID_GET_SCODE(__get_dynamic_array(self_id_sequence)),
419+
PHY_PACKET_SELF_ID_GET_CONTENDER(__get_dynamic_array(self_id_sequence)) ? "true" : "false",
420+
PHY_PACKET_SELF_ID_GET_POWER_CLASS(__get_dynamic_array(self_id_sequence)),
421+
PHY_PACKET_SELF_ID_GET_INITIATED_RESET(__get_dynamic_array(self_id_sequence)) ? "true" : "false",
422+
__print_array(__get_dynamic_array(port_status), __get_dynamic_array_len(port_status), 1),
423+
__print_array(__get_dynamic_array(self_id_sequence),
424+
__get_dynamic_array_len(self_id_sequence) / QUADLET_SIZE, QUADLET_SIZE)
425+
)
426+
);
427+
369428
#undef QUADLET_SIZE
370429

371430
#endif // _FIREWIRE_TRACE_EVENT_H

0 commit comments

Comments
 (0)