Commit 677ceae1 authored by Takashi Sakamoto's avatar Takashi Sakamoto
Browse files

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: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
parent 1ccfd1a4
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -95,7 +95,8 @@ static inline struct fw_node *fw_node(struct list_head *l)
 * internally consistent.  On success this function returns the
 * fw_node corresponding to the local card otherwise NULL.
 */
static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, int self_id_count)
static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, int self_id_count,
				  unsigned int generation)
{
	struct self_id_sequence_enumerator enumerator = {
		.cursor = sid,
@@ -139,6 +140,8 @@ static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, int self
		}

		port_capacity = self_id_sequence_get_port_capacity(quadlet_count);
		trace_self_id_sequence(self_id_sequence, quadlet_count, generation);

		for (port_index = 0; port_index < port_capacity; ++port_index) {
			port_status = self_id_sequence_get_port_status(self_id_sequence, quadlet_count,
								       port_index);
@@ -482,7 +485,7 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation,
	card->bm_abdicate = bm_abdicate;
	fw_schedule_bm_work(card, 0);

	local_node = build_tree(card, self_ids, self_id_count);
	local_node = build_tree(card, self_ids, self_id_count, generation);

	update_topology_map(card, self_ids, self_id_count);

+15 −0
Original line number Diff line number Diff line
@@ -2,7 +2,22 @@
// Copyright (c) 2024 Takashi Sakamoto

#include <linux/types.h>
#include <linux/err.h>
#include "packet-header-definitions.h"
#include "phy-packet-definitions.h"

#define CREATE_TRACE_POINTS
#include <trace/events/firewire.h>

#ifdef TRACEPOINTS_ENABLED
void copy_port_status(u8 *port_status, unsigned int port_capacity,
		      const u32 *self_id_sequence, unsigned int quadlet_count)
{
	unsigned int port_index;

	for (port_index = 0; port_index < port_capacity; ++port_index) {
		port_status[port_index] =
			self_id_sequence_get_port_status(self_id_sequence, quadlet_count, port_index);
	}
}
#endif
+59 −0
Original line number Diff line number Diff line
@@ -366,6 +366,65 @@ TRACE_EVENT(bus_reset_handle,
	)
);

// Some macros are defined in 'drivers/firewire/phy-packet-definitions.h'.

// The content of TP_printk field is preprocessed, then put to the module binary.

#define PHY_PACKET_SELF_ID_GET_PHY_ID(quads)		\
	((((const u32 *)quads)[0] & SELF_ID_PHY_ID_MASK) >> SELF_ID_PHY_ID_SHIFT)

#define PHY_PACKET_SELF_ID_GET_LINK_ACTIVE(quads)	\
	((((const u32 *)quads)[0] & SELF_ID_ZERO_LINK_ACTIVE_MASK) >> SELF_ID_ZERO_LINK_ACTIVE_SHIFT)

#define PHY_PACKET_SELF_ID_GET_GAP_COUNT(quads)		\
	((((const u32 *)quads)[0] & SELF_ID_ZERO_GAP_COUNT_MASK) >> SELF_ID_ZERO_GAP_COUNT_SHIFT)

#define PHY_PACKET_SELF_ID_GET_SCODE(quads)		\
	((((const u32 *)quads)[0] & SELF_ID_ZERO_SCODE_MASK) >> SELF_ID_ZERO_SCODE_SHIFT)

#define PHY_PACKET_SELF_ID_GET_CONTENDER(quads)		\
	((((const u32 *)quads)[0] & SELF_ID_ZERO_CONTENDER_MASK) >> SELF_ID_ZERO_CONTENDER_SHIFT)

#define PHY_PACKET_SELF_ID_GET_POWER_CLASS(quads)	\
	((((const u32 *)quads)[0] & SELF_ID_ZERO_POWER_CLASS_MASK) >> SELF_ID_ZERO_POWER_CLASS_SHIFT)

#define PHY_PACKET_SELF_ID_GET_INITIATED_RESET(quads)	\
	((((const u32 *)quads)[0] & SELF_ID_ZERO_INITIATED_RESET_MASK) >> SELF_ID_ZERO_INITIATED_RESET_SHIFT)

void copy_port_status(u8 *port_status, unsigned int port_capacity, const u32 *self_id_sequence,
		      unsigned int quadlet_count);

TRACE_EVENT(self_id_sequence,
	TP_PROTO(const u32 *self_id_sequence, unsigned int quadlet_count, unsigned int generation),
	TP_ARGS(self_id_sequence, quadlet_count, generation),
	TP_STRUCT__entry(
		__field(u8, generation)
		__dynamic_array(u8, port_status, self_id_sequence_get_port_capacity(quadlet_count))
		__dynamic_array(u32, self_id_sequence, quadlet_count)
	),
	TP_fast_assign(
		__entry->generation = generation;
		copy_port_status(__get_dynamic_array(port_status), __get_dynamic_array_len(port_status),
				 self_id_sequence, quadlet_count);
		memcpy(__get_dynamic_array(self_id_sequence), self_id_sequence,
					   __get_dynamic_array_len(self_id_sequence));
	),
	TP_printk(
		"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",
		__entry->generation,
		PHY_PACKET_SELF_ID_GET_PHY_ID(__get_dynamic_array(self_id_sequence)),
		PHY_PACKET_SELF_ID_GET_LINK_ACTIVE(__get_dynamic_array(self_id_sequence)) ? "true" : "false",
		PHY_PACKET_SELF_ID_GET_GAP_COUNT(__get_dynamic_array(self_id_sequence)),
		PHY_PACKET_SELF_ID_GET_SCODE(__get_dynamic_array(self_id_sequence)),
		PHY_PACKET_SELF_ID_GET_CONTENDER(__get_dynamic_array(self_id_sequence)) ? "true" : "false",
		PHY_PACKET_SELF_ID_GET_POWER_CLASS(__get_dynamic_array(self_id_sequence)),
		PHY_PACKET_SELF_ID_GET_INITIATED_RESET(__get_dynamic_array(self_id_sequence)) ? "true" : "false",
		__print_array(__get_dynamic_array(port_status), __get_dynamic_array_len(port_status), 1),
		__print_array(__get_dynamic_array(self_id_sequence),
			      __get_dynamic_array_len(self_id_sequence) / QUADLET_SIZE, QUADLET_SIZE)
	)
);

#undef QUADLET_SIZE

#endif // _FIREWIRE_TRACE_EVENT_H