18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: ISC */
28c2ecf20Sopenharmony_ci#if !defined(_ATH6KL_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include <net/cfg80211.h>
58c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
68c2ecf20Sopenharmony_ci#include <linux/tracepoint.h>
78c2ecf20Sopenharmony_ci#include "wmi.h"
88c2ecf20Sopenharmony_ci#include "hif.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#if !defined(_ATH6KL_TRACE_H)
118c2ecf20Sopenharmony_cistatic inline unsigned int ath6kl_get_wmi_id(void *buf, size_t buf_len)
128c2ecf20Sopenharmony_ci{
138c2ecf20Sopenharmony_ci	struct wmi_cmd_hdr *hdr = buf;
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci	if (buf_len < sizeof(*hdr))
168c2ecf20Sopenharmony_ci		return 0;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	return le16_to_cpu(hdr->cmd_id);
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci#endif /* __ATH6KL_TRACE_H */
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define _ATH6KL_TRACE_H
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* create empty functions when tracing is disabled */
258c2ecf20Sopenharmony_ci#if !defined(CONFIG_ATH6KL_TRACING)
268c2ecf20Sopenharmony_ci#undef TRACE_EVENT
278c2ecf20Sopenharmony_ci#define TRACE_EVENT(name, proto, ...) \
288c2ecf20Sopenharmony_cistatic inline void trace_ ## name(proto) {}
298c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS
308c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(...)
318c2ecf20Sopenharmony_ci#undef DEFINE_EVENT
328c2ecf20Sopenharmony_ci#define DEFINE_EVENT(evt_class, name, proto, ...) \
338c2ecf20Sopenharmony_cistatic inline void trace_ ## name(proto) {}
348c2ecf20Sopenharmony_ci#endif /* !CONFIG_ATH6KL_TRACING || __CHECKER__ */
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#undef TRACE_SYSTEM
378c2ecf20Sopenharmony_ci#define TRACE_SYSTEM ath6kl
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_wmi_cmd,
408c2ecf20Sopenharmony_ci	TP_PROTO(void *buf, size_t buf_len),
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	TP_ARGS(buf, buf_len),
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
458c2ecf20Sopenharmony_ci		__field(unsigned int, id)
468c2ecf20Sopenharmony_ci		__field(size_t, buf_len)
478c2ecf20Sopenharmony_ci		__dynamic_array(u8, buf, buf_len)
488c2ecf20Sopenharmony_ci	),
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	TP_fast_assign(
518c2ecf20Sopenharmony_ci		__entry->id = ath6kl_get_wmi_id(buf, buf_len);
528c2ecf20Sopenharmony_ci		__entry->buf_len = buf_len;
538c2ecf20Sopenharmony_ci		memcpy(__get_dynamic_array(buf), buf, buf_len);
548c2ecf20Sopenharmony_ci	),
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	TP_printk(
578c2ecf20Sopenharmony_ci		"id %d len %zd",
588c2ecf20Sopenharmony_ci		__entry->id, __entry->buf_len
598c2ecf20Sopenharmony_ci	)
608c2ecf20Sopenharmony_ci);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_wmi_event,
638c2ecf20Sopenharmony_ci	TP_PROTO(void *buf, size_t buf_len),
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	TP_ARGS(buf, buf_len),
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
688c2ecf20Sopenharmony_ci		__field(unsigned int, id)
698c2ecf20Sopenharmony_ci		__field(size_t, buf_len)
708c2ecf20Sopenharmony_ci		__dynamic_array(u8, buf, buf_len)
718c2ecf20Sopenharmony_ci	),
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	TP_fast_assign(
748c2ecf20Sopenharmony_ci		__entry->id = ath6kl_get_wmi_id(buf, buf_len);
758c2ecf20Sopenharmony_ci		__entry->buf_len = buf_len;
768c2ecf20Sopenharmony_ci		memcpy(__get_dynamic_array(buf), buf, buf_len);
778c2ecf20Sopenharmony_ci	),
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	TP_printk(
808c2ecf20Sopenharmony_ci		"id %d len %zd",
818c2ecf20Sopenharmony_ci		__entry->id, __entry->buf_len
828c2ecf20Sopenharmony_ci	)
838c2ecf20Sopenharmony_ci);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_sdio,
868c2ecf20Sopenharmony_ci	TP_PROTO(unsigned int addr, int flags,
878c2ecf20Sopenharmony_ci		 void *buf, size_t buf_len),
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	TP_ARGS(addr, flags, buf, buf_len),
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
928c2ecf20Sopenharmony_ci		__field(unsigned int, tx)
938c2ecf20Sopenharmony_ci		__field(unsigned int, addr)
948c2ecf20Sopenharmony_ci		__field(int, flags)
958c2ecf20Sopenharmony_ci		__field(size_t, buf_len)
968c2ecf20Sopenharmony_ci		__dynamic_array(u8, buf, buf_len)
978c2ecf20Sopenharmony_ci	),
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	TP_fast_assign(
1008c2ecf20Sopenharmony_ci		__entry->addr = addr;
1018c2ecf20Sopenharmony_ci		__entry->flags = flags;
1028c2ecf20Sopenharmony_ci		__entry->buf_len = buf_len;
1038c2ecf20Sopenharmony_ci		memcpy(__get_dynamic_array(buf), buf, buf_len);
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci		if (flags & HIF_WRITE)
1068c2ecf20Sopenharmony_ci			__entry->tx = 1;
1078c2ecf20Sopenharmony_ci		else
1088c2ecf20Sopenharmony_ci			__entry->tx = 0;
1098c2ecf20Sopenharmony_ci	),
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	TP_printk(
1128c2ecf20Sopenharmony_ci		"%s addr 0x%x flags 0x%x len %zd\n",
1138c2ecf20Sopenharmony_ci		__entry->tx ? "tx" : "rx",
1148c2ecf20Sopenharmony_ci		__entry->addr,
1158c2ecf20Sopenharmony_ci		__entry->flags,
1168c2ecf20Sopenharmony_ci		__entry->buf_len
1178c2ecf20Sopenharmony_ci	)
1188c2ecf20Sopenharmony_ci);
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_sdio_scat,
1218c2ecf20Sopenharmony_ci	TP_PROTO(unsigned int addr, int flags, unsigned int total_len,
1228c2ecf20Sopenharmony_ci		 unsigned int entries, struct hif_scatter_item *list),
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	TP_ARGS(addr, flags, total_len, entries, list),
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
1278c2ecf20Sopenharmony_ci		__field(unsigned int, tx)
1288c2ecf20Sopenharmony_ci		__field(unsigned int, addr)
1298c2ecf20Sopenharmony_ci		__field(int, flags)
1308c2ecf20Sopenharmony_ci		__field(unsigned int, entries)
1318c2ecf20Sopenharmony_ci		__field(size_t, total_len)
1328c2ecf20Sopenharmony_ci		__dynamic_array(unsigned int, len_array, entries)
1338c2ecf20Sopenharmony_ci		__dynamic_array(u8, data, total_len)
1348c2ecf20Sopenharmony_ci	),
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	TP_fast_assign(
1378c2ecf20Sopenharmony_ci		unsigned int *len_array;
1388c2ecf20Sopenharmony_ci		int i, offset = 0;
1398c2ecf20Sopenharmony_ci		size_t len;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci		__entry->addr = addr;
1428c2ecf20Sopenharmony_ci		__entry->flags = flags;
1438c2ecf20Sopenharmony_ci		__entry->entries = entries;
1448c2ecf20Sopenharmony_ci		__entry->total_len = total_len;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci		if (flags & HIF_WRITE)
1478c2ecf20Sopenharmony_ci			__entry->tx = 1;
1488c2ecf20Sopenharmony_ci		else
1498c2ecf20Sopenharmony_ci			__entry->tx = 0;
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci		len_array = __get_dynamic_array(len_array);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci		for (i = 0; i < entries; i++) {
1548c2ecf20Sopenharmony_ci			len = list[i].len;
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci			memcpy((u8 *) __get_dynamic_array(data) + offset,
1578c2ecf20Sopenharmony_ci			       list[i].buf, len);
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci			len_array[i] = len;
1608c2ecf20Sopenharmony_ci			offset += len;
1618c2ecf20Sopenharmony_ci		}
1628c2ecf20Sopenharmony_ci	),
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	TP_printk(
1658c2ecf20Sopenharmony_ci		"%s addr 0x%x flags 0x%x entries %d total_len %zd\n",
1668c2ecf20Sopenharmony_ci		__entry->tx ? "tx" : "rx",
1678c2ecf20Sopenharmony_ci		__entry->addr,
1688c2ecf20Sopenharmony_ci		__entry->flags,
1698c2ecf20Sopenharmony_ci		__entry->entries,
1708c2ecf20Sopenharmony_ci		__entry->total_len
1718c2ecf20Sopenharmony_ci	)
1728c2ecf20Sopenharmony_ci);
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_sdio_irq,
1758c2ecf20Sopenharmony_ci	TP_PROTO(void *buf, size_t buf_len),
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	TP_ARGS(buf, buf_len),
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
1808c2ecf20Sopenharmony_ci		__field(size_t, buf_len)
1818c2ecf20Sopenharmony_ci		__dynamic_array(u8, buf, buf_len)
1828c2ecf20Sopenharmony_ci	),
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	TP_fast_assign(
1858c2ecf20Sopenharmony_ci		__entry->buf_len = buf_len;
1868c2ecf20Sopenharmony_ci		memcpy(__get_dynamic_array(buf), buf, buf_len);
1878c2ecf20Sopenharmony_ci	),
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	TP_printk(
1908c2ecf20Sopenharmony_ci		"irq len %zd\n", __entry->buf_len
1918c2ecf20Sopenharmony_ci	)
1928c2ecf20Sopenharmony_ci);
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_htc_rx,
1958c2ecf20Sopenharmony_ci	TP_PROTO(int status, int endpoint, void *buf,
1968c2ecf20Sopenharmony_ci		 size_t buf_len),
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci	TP_ARGS(status, endpoint, buf, buf_len),
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
2018c2ecf20Sopenharmony_ci		__field(int, status)
2028c2ecf20Sopenharmony_ci		__field(int, endpoint)
2038c2ecf20Sopenharmony_ci		__field(size_t, buf_len)
2048c2ecf20Sopenharmony_ci		__dynamic_array(u8, buf, buf_len)
2058c2ecf20Sopenharmony_ci	),
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	TP_fast_assign(
2088c2ecf20Sopenharmony_ci		__entry->status = status;
2098c2ecf20Sopenharmony_ci		__entry->endpoint = endpoint;
2108c2ecf20Sopenharmony_ci		__entry->buf_len = buf_len;
2118c2ecf20Sopenharmony_ci		memcpy(__get_dynamic_array(buf), buf, buf_len);
2128c2ecf20Sopenharmony_ci	),
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	TP_printk(
2158c2ecf20Sopenharmony_ci		"status %d endpoint %d len %zd\n",
2168c2ecf20Sopenharmony_ci		__entry->status,
2178c2ecf20Sopenharmony_ci		__entry->endpoint,
2188c2ecf20Sopenharmony_ci		__entry->buf_len
2198c2ecf20Sopenharmony_ci	)
2208c2ecf20Sopenharmony_ci);
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_htc_tx,
2238c2ecf20Sopenharmony_ci	TP_PROTO(int status, int endpoint, void *buf,
2248c2ecf20Sopenharmony_ci		 size_t buf_len),
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	TP_ARGS(status, endpoint, buf, buf_len),
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
2298c2ecf20Sopenharmony_ci		__field(int, status)
2308c2ecf20Sopenharmony_ci		__field(int, endpoint)
2318c2ecf20Sopenharmony_ci		__field(size_t, buf_len)
2328c2ecf20Sopenharmony_ci		__dynamic_array(u8, buf, buf_len)
2338c2ecf20Sopenharmony_ci	),
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	TP_fast_assign(
2368c2ecf20Sopenharmony_ci		__entry->status = status;
2378c2ecf20Sopenharmony_ci		__entry->endpoint = endpoint;
2388c2ecf20Sopenharmony_ci		__entry->buf_len = buf_len;
2398c2ecf20Sopenharmony_ci		memcpy(__get_dynamic_array(buf), buf, buf_len);
2408c2ecf20Sopenharmony_ci	),
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	TP_printk(
2438c2ecf20Sopenharmony_ci		"status %d endpoint %d len %zd\n",
2448c2ecf20Sopenharmony_ci		__entry->status,
2458c2ecf20Sopenharmony_ci		__entry->endpoint,
2468c2ecf20Sopenharmony_ci		__entry->buf_len
2478c2ecf20Sopenharmony_ci	)
2488c2ecf20Sopenharmony_ci);
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci#define ATH6KL_MSG_MAX 200
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ciDECLARE_EVENT_CLASS(ath6kl_log_event,
2538c2ecf20Sopenharmony_ci	TP_PROTO(struct va_format *vaf),
2548c2ecf20Sopenharmony_ci	TP_ARGS(vaf),
2558c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
2568c2ecf20Sopenharmony_ci		__dynamic_array(char, msg, ATH6KL_MSG_MAX)
2578c2ecf20Sopenharmony_ci	),
2588c2ecf20Sopenharmony_ci	TP_fast_assign(
2598c2ecf20Sopenharmony_ci		WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg),
2608c2ecf20Sopenharmony_ci				       ATH6KL_MSG_MAX,
2618c2ecf20Sopenharmony_ci				       vaf->fmt,
2628c2ecf20Sopenharmony_ci				       *vaf->va) >= ATH6KL_MSG_MAX);
2638c2ecf20Sopenharmony_ci	),
2648c2ecf20Sopenharmony_ci	TP_printk("%s", __get_str(msg))
2658c2ecf20Sopenharmony_ci);
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ciDEFINE_EVENT(ath6kl_log_event, ath6kl_log_err,
2688c2ecf20Sopenharmony_ci	     TP_PROTO(struct va_format *vaf),
2698c2ecf20Sopenharmony_ci	     TP_ARGS(vaf)
2708c2ecf20Sopenharmony_ci);
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ciDEFINE_EVENT(ath6kl_log_event, ath6kl_log_warn,
2738c2ecf20Sopenharmony_ci	     TP_PROTO(struct va_format *vaf),
2748c2ecf20Sopenharmony_ci	     TP_ARGS(vaf)
2758c2ecf20Sopenharmony_ci);
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ciDEFINE_EVENT(ath6kl_log_event, ath6kl_log_info,
2788c2ecf20Sopenharmony_ci	     TP_PROTO(struct va_format *vaf),
2798c2ecf20Sopenharmony_ci	     TP_ARGS(vaf)
2808c2ecf20Sopenharmony_ci);
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_log_dbg,
2838c2ecf20Sopenharmony_ci	TP_PROTO(unsigned int level, struct va_format *vaf),
2848c2ecf20Sopenharmony_ci	TP_ARGS(level, vaf),
2858c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
2868c2ecf20Sopenharmony_ci		__field(unsigned int, level)
2878c2ecf20Sopenharmony_ci		__dynamic_array(char, msg, ATH6KL_MSG_MAX)
2888c2ecf20Sopenharmony_ci	),
2898c2ecf20Sopenharmony_ci	TP_fast_assign(
2908c2ecf20Sopenharmony_ci		__entry->level = level;
2918c2ecf20Sopenharmony_ci		WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg),
2928c2ecf20Sopenharmony_ci				       ATH6KL_MSG_MAX,
2938c2ecf20Sopenharmony_ci				       vaf->fmt,
2948c2ecf20Sopenharmony_ci				       *vaf->va) >= ATH6KL_MSG_MAX);
2958c2ecf20Sopenharmony_ci	),
2968c2ecf20Sopenharmony_ci	TP_printk("%s", __get_str(msg))
2978c2ecf20Sopenharmony_ci);
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ciTRACE_EVENT(ath6kl_log_dbg_dump,
3008c2ecf20Sopenharmony_ci	TP_PROTO(const char *msg, const char *prefix,
3018c2ecf20Sopenharmony_ci		 const void *buf, size_t buf_len),
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	TP_ARGS(msg, prefix, buf, buf_len),
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
3068c2ecf20Sopenharmony_ci		__string(msg, msg)
3078c2ecf20Sopenharmony_ci		__string(prefix, prefix)
3088c2ecf20Sopenharmony_ci		__field(size_t, buf_len)
3098c2ecf20Sopenharmony_ci		__dynamic_array(u8, buf, buf_len)
3108c2ecf20Sopenharmony_ci	),
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	TP_fast_assign(
3138c2ecf20Sopenharmony_ci		__assign_str(msg, msg);
3148c2ecf20Sopenharmony_ci		__assign_str(prefix, prefix);
3158c2ecf20Sopenharmony_ci		__entry->buf_len = buf_len;
3168c2ecf20Sopenharmony_ci		memcpy(__get_dynamic_array(buf), buf, buf_len);
3178c2ecf20Sopenharmony_ci	),
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	TP_printk(
3208c2ecf20Sopenharmony_ci		"%s/%s\n", __get_str(prefix), __get_str(msg)
3218c2ecf20Sopenharmony_ci	)
3228c2ecf20Sopenharmony_ci);
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci#endif /* _ ATH6KL_TRACE_H || TRACE_HEADER_MULTI_READ*/
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci/* we don't want to use include/trace/events */
3278c2ecf20Sopenharmony_ci#undef TRACE_INCLUDE_PATH
3288c2ecf20Sopenharmony_ci#define TRACE_INCLUDE_PATH .
3298c2ecf20Sopenharmony_ci#undef TRACE_INCLUDE_FILE
3308c2ecf20Sopenharmony_ci#define TRACE_INCLUDE_FILE trace
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci/* This part must be outside protection */
3338c2ecf20Sopenharmony_ci#include <trace/define_trace.h>
334