linux/drivers/net/wireless/silabs/wfx/traces.h

/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Tracepoints definitions.
 *
 * Copyright (c) 2018-2020, Silicon Laboratories, Inc.
 */

#undef TRACE_SYSTEM
#define TRACE_SYSTEM

#if !defined(_WFX_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
#define _WFX_TRACE_H

#include <linux/tracepoint.h>
#include <net/mac80211.h>

#include "bus.h"
#include "hif_api_cmd.h"
#include "hif_api_mib.h"

/* The hell below need some explanations. For each symbolic number, we need to define it with
 * TRACE_DEFINE_ENUM() and in a list for __print_symbolic.
 *
 *   1. Define a new macro that call TRACE_DEFINE_ENUM():
 *
 *          #define xxx_name(sym) TRACE_DEFINE_ENUM(sym);
 *
 *   2. Define list of all symbols:
 *
 *          #define list_names     \
 *             ...                 \
 *             xxx_name(XXX)       \
 *             ...
 *
 *   3. Instantiate that list_names:
 *
 *          list_names
 *
 *   4. Redefine xxx_name() as an entry of array for __print_symbolic()
 *
 *          #undef xxx_name
 *          #define xxx_name(msg) { msg, #msg },
 *
 *   5. list_name can now nearly be used with __print_symbolic() but, __print_symbolic() dislike
 *      last comma of list. So we define a new list with a dummy element:
 *
 *          #define list_for_print_symbolic list_names { -1, NULL }
 */

#define _hif_msg_list

#define hif_msg_list_enum

#undef hif_cnf_name
#undef hif_ind_name
#define hif_cnf_name(msg)
#define hif_ind_name(msg)
hif_msg_list_enum
#undef hif_cnf_name
#undef hif_ind_name
#define hif_cnf_name(msg)
#define hif_ind_name(msg)
#define hif_msg_list

#define _hif_mib_list

#define hif_mib_list_enum

#undef hif_mib_name
#define hif_mib_name(mib)
hif_mib_list_enum
#undef hif_mib_name
#define hif_mib_name(mib)
#define hif_mib_list

DECLARE_EVENT_CLASS(hif_data,
	TP_PROTO(const struct wfx_hif_msg *hif, int tx_fill_level, bool is_recv),
	TP_ARGS(hif, tx_fill_level, is_recv),
	TP_STRUCT__entry(
		__field(int, tx_fill_level)
		__field(int, msg_id)
		__field(const char *, msg_type)
		__field(int, msg_len)
		__field(int, buf_len)
		__field(int, if_id)
		__field(int, mib)
		__array(u8, buf, 128)
	),
	TP_fast_assign(
		int header_len;

		__entry->tx_fill_level = tx_fill_level;
		__entry->msg_len = le16_to_cpu(hif->len);
		__entry->msg_id = hif->id;
		__entry->if_id = hif->interface;
		if (is_recv)
			__entry->msg_type = __entry->msg_id & 0x80 ? "IND" : "CNF";
		else
			__entry->msg_type = "REQ";
		if (!is_recv &&
		    (__entry->msg_id == HIF_REQ_ID_READ_MIB ||
		     __entry->msg_id == HIF_REQ_ID_WRITE_MIB)) {
			__entry->mib = le16_to_cpup((__le16 *)hif->body);
			header_len = 4;
		} else {
			__entry->mib = -1;
			header_len = 0;
		}
		__entry->buf_len = min_t(int, __entry->msg_len, sizeof(__entry->buf))
				   - sizeof(struct wfx_hif_msg) - header_len;
		memcpy(__entry->buf, hif->body + header_len, __entry->buf_len);
	),
	TP_printk("%d:%d:%s_%s%s%s: %s%s (%d bytes)",
		__entry->tx_fill_level,
		__entry->if_id,
		__entry->msg_type,
		__print_symbolic(__entry->msg_id, hif_msg_list),
		__entry->mib != -1 ? "/" : "",
		__entry->mib != -1 ? __print_symbolic(__entry->mib, hif_mib_list) : "",
		__print_hex(__entry->buf, __entry->buf_len),
		__entry->msg_len > sizeof(__entry->buf) ? " ..." : "",
		__entry->msg_len
	)
);
DEFINE_EVENT(hif_data, hif_send,
	TP_PROTO(const struct wfx_hif_msg *hif, int tx_fill_level, bool is_recv),
	TP_ARGS(hif, tx_fill_level, is_recv));
#define _trace_hif_send(hif, tx_fill_level)
DEFINE_EVENT(hif_data, hif_recv,
	TP_PROTO(const struct wfx_hif_msg *hif, int tx_fill_level, bool is_recv),
	TP_ARGS(hif, tx_fill_level, is_recv));
#define _trace_hif_recv(hif, tx_fill_level)

#define wfx_reg_list_enum

#undef wfx_reg_name
#define wfx_reg_name(sym, name)
wfx_reg_list_enum
#undef wfx_reg_name
#define wfx_reg_name(sym, name)
#define wfx_reg_list

DECLARE_EVENT_CLASS(io_data,
	TP_PROTO(int reg, int addr, const void *io_buf, size_t len),
	TP_ARGS(reg, addr, io_buf, len),
	TP_STRUCT__entry(
		__field(int, reg)
		__field(int, addr)
		__field(int, msg_len)
		__field(int, buf_len)
		__array(u8, buf, 32)
		__array(u8, addr_str, 10)
	),
	TP_fast_assign(
		__entry->reg = reg;
		__entry->addr = addr;
		__entry->msg_len = len;
		__entry->buf_len = min_t(int, sizeof(__entry->buf), __entry->msg_len);
		memcpy(__entry->buf, io_buf, __entry->buf_len);
		if (addr >= 0)
			snprintf(__entry->addr_str, 10, "/%08x", addr);
		else
			__entry->addr_str[0] = 0;
	),
	TP_printk("%s%s: %s%s (%d bytes)",
		__print_symbolic(__entry->reg, wfx_reg_list),
		__entry->addr_str,
		__print_hex(__entry->buf, __entry->buf_len),
		__entry->msg_len > sizeof(__entry->buf) ? " ..." : "",
		__entry->msg_len
	)
);
DEFINE_EVENT(io_data, io_write,
	TP_PROTO(int reg, int addr, const void *io_buf, size_t len),
	TP_ARGS(reg, addr, io_buf, len));
#define _trace_io_ind_write(reg, addr, io_buf, len)
#define _trace_io_write(reg, io_buf, len)
DEFINE_EVENT(io_data, io_read,
	TP_PROTO(int reg, int addr, const void *io_buf, size_t len),
	TP_ARGS(reg, addr, io_buf, len));
#define _trace_io_ind_read(reg, addr, io_buf, len)
#define _trace_io_read(reg, io_buf, len)

DECLARE_EVENT_CLASS(io_data32,
	TP_PROTO(int reg, int addr, u32 val),
	TP_ARGS(reg, addr, val),
	TP_STRUCT__entry(
		__field(int, reg)
		__field(int, addr)
		__field(int, val)
		__array(u8, addr_str, 10)
	),
	TP_fast_assign(
		__entry->reg = reg;
		__entry->addr = addr;
		__entry->val = val;
		if (addr >= 0)
			snprintf(__entry->addr_str, 10, "/%08x", addr);
		else
			__entry->addr_str[0] = 0;
	),
	TP_printk("%s%s: %08x",
		__print_symbolic(__entry->reg, wfx_reg_list),
		__entry->addr_str,
		__entry->val
	)
);
DEFINE_EVENT(io_data32, io_write32,
	TP_PROTO(int reg, int addr, u32 val),
	TP_ARGS(reg, addr, val));
#define _trace_io_ind_write32(reg, addr, val)
#define _trace_io_write32(reg, val)
DEFINE_EVENT(io_data32, io_read32,
	TP_PROTO(int reg, int addr, u32 val),
	TP_ARGS(reg, addr, val));
#define _trace_io_ind_read32(reg, addr, val)
#define _trace_io_read32(reg, val)

DECLARE_EVENT_CLASS(piggyback,
	TP_PROTO(u32 val, bool ignored),
	TP_ARGS(val, ignored),
	TP_STRUCT__entry(
		__field(int, val)
		__field(bool, ignored)
	),
	TP_fast_assign(
		__entry->val = val;
		__entry->ignored = ignored;
	),
	TP_printk("CONTROL: %08x%s",
		__entry->val,
		__entry->ignored ? " (ignored)" : ""
	)
);
DEFINE_EVENT(piggyback, piggyback,
	TP_PROTO(u32 val, bool ignored),
	TP_ARGS(val, ignored));
#define _trace_piggyback(val, ignored)

TRACE_EVENT(bh_stats,
	TP_PROTO(int ind, int req, int cnf, int busy, bool release),
	TP_ARGS(ind, req, cnf, busy, release),
	TP_STRUCT__entry(
		__field(int, ind)
		__field(int, req)
		__field(int, cnf)
		__field(int, busy)
		__field(bool, release)
	),
	TP_fast_assign(
		__entry->ind = ind;
		__entry->req = req;
		__entry->cnf = cnf;
		__entry->busy = busy;
		__entry->release = release;
	),
	TP_printk("IND/REQ/CNF:%3d/%3d/%3d, REQ in progress:%3d, WUP: %s",
		__entry->ind,
		__entry->req,
		__entry->cnf,
		__entry->busy,
		__entry->release ? "release" : "keep"
	)
);
#define _trace_bh_stats(ind, req, cnf, busy, release)

TRACE_EVENT(tx_stats,
	TP_PROTO(const struct wfx_hif_cnf_tx *tx_cnf, const struct sk_buff *skb,
		 int delay),
	TP_ARGS(tx_cnf, skb, delay),
	TP_STRUCT__entry(
		__field(int, pkt_id)
		__field(int, delay_media)
		__field(int, delay_queue)
		__field(int, delay_fw)
		__field(int, ack_failures)
		__field(int, flags)
		__array(int, rate, 4)
		__array(int, tx_count, 4)
	),
	TP_fast_assign(
		/* Keep sync with wfx_rates definition in main.c */
		static const int hw_rate[] = { 0, 1, 2, 3, 6, 7, 8, 9, 10, 11, 12, 13 };
		const struct ieee80211_tx_info *tx_info =
			(const struct ieee80211_tx_info *)skb->cb;
		const struct ieee80211_tx_rate *rates = tx_info->driver_rates;
		int i;

		__entry->pkt_id = tx_cnf->packet_id;
		__entry->delay_media = le32_to_cpu(tx_cnf->media_delay);
		__entry->delay_queue = le32_to_cpu(tx_cnf->tx_queue_delay);
		__entry->delay_fw = delay;
		__entry->ack_failures = tx_cnf->ack_failures;
		if (!tx_cnf->status || __entry->ack_failures)
			__entry->ack_failures += 1;

		for (i = 0; i < IEEE80211_NUM_ACS; i++) {
			if (rates[0].flags & IEEE80211_TX_RC_MCS)
				__entry->rate[i] = rates[i].idx;
			else
				__entry->rate[i] = hw_rate[rates[i].idx];
			__entry->tx_count[i] = rates[i].count;
		}
		__entry->flags = 0;
		if (rates[0].flags & IEEE80211_TX_RC_MCS)
			__entry->flags |= 0x01;
		if (rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
			__entry->flags |= 0x02;
		if (rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD)
			__entry->flags |= 0x04;
		if (rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
			__entry->flags |= 0x08;
		if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM)
			__entry->flags |= 0x10;
		if (tx_cnf->status)
			__entry->flags |= 0x20;
		if (tx_cnf->status == HIF_STATUS_TX_FAIL_REQUEUE)
			__entry->flags |= 0x40;
	),
	TP_printk("packet ID: %08x, rate policy: %s %d|%d %d|%d %d|%d %d|%d -> %d attempt, Delays media/queue/total: %4dus/%4dus/%4dus",
		__entry->pkt_id,
		__print_flags(__entry->flags, NULL,
			{ 0x01, "M" }, { 0x02, "S" }, { 0x04, "G" }, { 0x08, "R" },
			{ 0x10, "D" }, { 0x20, "F" }, { 0x40, "Q" }),
		__entry->rate[0],
		__entry->tx_count[0],
		__entry->rate[1],
		__entry->tx_count[1],
		__entry->rate[2],
		__entry->tx_count[2],
		__entry->rate[3],
		__entry->tx_count[3],
		__entry->ack_failures,
		__entry->delay_media,
		__entry->delay_queue,
		__entry->delay_fw
	)
);
#define _trace_tx_stats(tx_cnf, skb, delay)

TRACE_EVENT(queues_stats,
	TP_PROTO(struct wfx_dev *wdev, const struct wfx_queue *elected_queue),
	TP_ARGS(wdev, elected_queue),
	TP_STRUCT__entry(
		__field(int, vif_id)
		__field(int, queue_id)
		__array(int, hw, IEEE80211_NUM_ACS * 2)
		__array(int, drv, IEEE80211_NUM_ACS * 2)
		__array(int, cab, IEEE80211_NUM_ACS * 2)
	),
	TP_fast_assign(
		const struct wfx_queue *queue;
		struct wfx_vif *wvif;
		int i, j;

		for (j = 0; j < IEEE80211_NUM_ACS * 2; j++) {
			__entry->hw[j] = -1;
			__entry->drv[j] = -1;
			__entry->cab[j] = -1;
		}
		__entry->vif_id = -1;
		__entry->queue_id = -1;
		wvif = NULL;
		while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
			for (i = 0; i < IEEE80211_NUM_ACS; i++) {
				j = wvif->id * IEEE80211_NUM_ACS + i;
				WARN_ON(j >= IEEE80211_NUM_ACS * 2);
				queue = &wvif->tx_queue[i];
				__entry->hw[j] = atomic_read(&queue->pending_frames);
				__entry->drv[j] = skb_queue_len(&queue->normal);
				__entry->cab[j] = skb_queue_len(&queue->cab);
				if (queue == elected_queue) {
					__entry->vif_id = wvif->id;
					__entry->queue_id = i;
				}
			}
		}
	),
	TP_printk("got skb from %d/%d, pend. hw/norm/cab: [ %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d ] [ %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d ]",
		__entry->vif_id, __entry->queue_id,
		__entry->hw[0], __entry->drv[0], __entry->cab[0],
		__entry->hw[1], __entry->drv[1], __entry->cab[1],
		__entry->hw[2], __entry->drv[2], __entry->cab[2],
		__entry->hw[3], __entry->drv[3], __entry->cab[3],
		__entry->hw[4], __entry->drv[4], __entry->cab[4],
		__entry->hw[5], __entry->drv[5], __entry->cab[5],
		__entry->hw[6], __entry->drv[6], __entry->cab[6],
		__entry->hw[7], __entry->drv[7], __entry->cab[7]
	)
);

#endif

/* This part must be outside protection */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE

#include <trace/define_trace.h>