162306a36Sopenharmony_ci// SPDX-License-Identifier: ISC
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2010 Broadcom Corporation
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef BRCMFMAC_DEBUG_H
762306a36Sopenharmony_ci#define BRCMFMAC_DEBUG_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/net.h>	/* net_ratelimit() */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/* message levels */
1262306a36Sopenharmony_ci#define BRCMF_TRACE_VAL		0x00000002
1362306a36Sopenharmony_ci#define BRCMF_INFO_VAL		0x00000004
1462306a36Sopenharmony_ci#define BRCMF_DATA_VAL		0x00000008
1562306a36Sopenharmony_ci#define BRCMF_CTL_VAL		0x00000010
1662306a36Sopenharmony_ci#define BRCMF_TIMER_VAL		0x00000020
1762306a36Sopenharmony_ci#define BRCMF_HDRS_VAL		0x00000040
1862306a36Sopenharmony_ci#define BRCMF_BYTES_VAL		0x00000080
1962306a36Sopenharmony_ci#define BRCMF_INTR_VAL		0x00000100
2062306a36Sopenharmony_ci#define BRCMF_GLOM_VAL		0x00000200
2162306a36Sopenharmony_ci#define BRCMF_EVENT_VAL		0x00000400
2262306a36Sopenharmony_ci#define BRCMF_BTA_VAL		0x00000800
2362306a36Sopenharmony_ci#define BRCMF_FIL_VAL		0x00001000
2462306a36Sopenharmony_ci#define BRCMF_USB_VAL		0x00002000
2562306a36Sopenharmony_ci#define BRCMF_SCAN_VAL		0x00004000
2662306a36Sopenharmony_ci#define BRCMF_CONN_VAL		0x00008000
2762306a36Sopenharmony_ci#define BRCMF_BCDC_VAL		0x00010000
2862306a36Sopenharmony_ci#define BRCMF_SDIO_VAL		0x00020000
2962306a36Sopenharmony_ci#define BRCMF_MSGBUF_VAL	0x00040000
3062306a36Sopenharmony_ci#define BRCMF_PCIE_VAL		0x00080000
3162306a36Sopenharmony_ci#define BRCMF_FWCON_VAL		0x00100000
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci/* set default print format */
3462306a36Sopenharmony_ci#undef pr_fmt
3562306a36Sopenharmony_ci#define pr_fmt(fmt)		KBUILD_MODNAME ": " fmt
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistruct brcmf_bus;
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci__printf(3, 4)
4062306a36Sopenharmony_civoid __brcmf_err(struct brcmf_bus *bus, const char *func, const char *fmt, ...);
4162306a36Sopenharmony_ci/* Macro for error messages. When debugging / tracing the driver all error
4262306a36Sopenharmony_ci * messages are important to us.
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_ci#ifndef brcmf_err
4562306a36Sopenharmony_ci#define brcmf_err(fmt, ...)						\
4662306a36Sopenharmony_ci	do {								\
4762306a36Sopenharmony_ci		if (IS_ENABLED(CONFIG_BRCMDBG) ||			\
4862306a36Sopenharmony_ci		    IS_ENABLED(CONFIG_BRCM_TRACING) ||			\
4962306a36Sopenharmony_ci		    net_ratelimit())					\
5062306a36Sopenharmony_ci			__brcmf_err(NULL, __func__, fmt, ##__VA_ARGS__);\
5162306a36Sopenharmony_ci	} while (0)
5262306a36Sopenharmony_ci#endif
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define bphy_err(drvr, fmt, ...)					\
5562306a36Sopenharmony_ci	do {								\
5662306a36Sopenharmony_ci		if (IS_ENABLED(CONFIG_BRCMDBG) ||			\
5762306a36Sopenharmony_ci		    IS_ENABLED(CONFIG_BRCM_TRACING) ||			\
5862306a36Sopenharmony_ci		    net_ratelimit())					\
5962306a36Sopenharmony_ci			wiphy_err((drvr)->wiphy, "%s: " fmt, __func__,	\
6062306a36Sopenharmony_ci				  ##__VA_ARGS__);			\
6162306a36Sopenharmony_ci	} while (0)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define bphy_info_once(drvr, fmt, ...)					\
6462306a36Sopenharmony_ci	wiphy_info_once((drvr)->wiphy, "%s: " fmt, __func__,		\
6562306a36Sopenharmony_ci			##__VA_ARGS__)
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#if defined(DEBUG) || defined(CONFIG_BRCM_TRACING)
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/* For debug/tracing purposes treat info messages as errors */
7062306a36Sopenharmony_ci#define brcmf_info brcmf_err
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci__printf(3, 4)
7362306a36Sopenharmony_civoid __brcmf_dbg(u32 level, const char *func, const char *fmt, ...);
7462306a36Sopenharmony_ci#define brcmf_dbg(level, fmt, ...)				\
7562306a36Sopenharmony_cido {								\
7662306a36Sopenharmony_ci	__brcmf_dbg(BRCMF_##level##_VAL, __func__,		\
7762306a36Sopenharmony_ci		    fmt, ##__VA_ARGS__);			\
7862306a36Sopenharmony_ci} while (0)
7962306a36Sopenharmony_ci#define BRCMF_DATA_ON()		(brcmf_msg_level & BRCMF_DATA_VAL)
8062306a36Sopenharmony_ci#define BRCMF_CTL_ON()		(brcmf_msg_level & BRCMF_CTL_VAL)
8162306a36Sopenharmony_ci#define BRCMF_HDRS_ON()		(brcmf_msg_level & BRCMF_HDRS_VAL)
8262306a36Sopenharmony_ci#define BRCMF_BYTES_ON()	(brcmf_msg_level & BRCMF_BYTES_VAL)
8362306a36Sopenharmony_ci#define BRCMF_GLOM_ON()		(brcmf_msg_level & BRCMF_GLOM_VAL)
8462306a36Sopenharmony_ci#define BRCMF_EVENT_ON()	(brcmf_msg_level & BRCMF_EVENT_VAL)
8562306a36Sopenharmony_ci#define BRCMF_FIL_ON()		(brcmf_msg_level & BRCMF_FIL_VAL)
8662306a36Sopenharmony_ci#define BRCMF_FWCON_ON()	(brcmf_msg_level & BRCMF_FWCON_VAL)
8762306a36Sopenharmony_ci#define BRCMF_SCAN_ON()		(brcmf_msg_level & BRCMF_SCAN_VAL)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#else /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#define brcmf_info(fmt, ...)						\
9262306a36Sopenharmony_ci	do {								\
9362306a36Sopenharmony_ci		pr_info("%s: " fmt, __func__, ##__VA_ARGS__);		\
9462306a36Sopenharmony_ci	} while (0)
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define brcmf_dbg(level, fmt, ...) no_printk(fmt, ##__VA_ARGS__)
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci#define BRCMF_DATA_ON()		0
9962306a36Sopenharmony_ci#define BRCMF_CTL_ON()		0
10062306a36Sopenharmony_ci#define BRCMF_HDRS_ON()		0
10162306a36Sopenharmony_ci#define BRCMF_BYTES_ON()	0
10262306a36Sopenharmony_ci#define BRCMF_GLOM_ON()		0
10362306a36Sopenharmony_ci#define BRCMF_EVENT_ON()	0
10462306a36Sopenharmony_ci#define BRCMF_FIL_ON()		0
10562306a36Sopenharmony_ci#define BRCMF_FWCON_ON()	0
10662306a36Sopenharmony_ci#define BRCMF_SCAN_ON()		0
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci#endif /* defined(DEBUG) || defined(CONFIG_BRCM_TRACING) */
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci#define brcmf_dbg_hex_dump(test, data, len, fmt, ...)			\
11162306a36Sopenharmony_cido {									\
11262306a36Sopenharmony_ci	trace_brcmf_hexdump((void *)data, len);				\
11362306a36Sopenharmony_ci	if (test)							\
11462306a36Sopenharmony_ci		brcmu_dbg_hex_dump(data, len, fmt, ##__VA_ARGS__);	\
11562306a36Sopenharmony_ci} while (0)
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciextern int brcmf_msg_level;
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistruct brcmf_pub;
12062306a36Sopenharmony_ci#ifdef DEBUG
12162306a36Sopenharmony_cistruct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr);
12262306a36Sopenharmony_civoid brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
12362306a36Sopenharmony_ci			     int (*read_fn)(struct seq_file *seq, void *data));
12462306a36Sopenharmony_ciint brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,
12562306a36Sopenharmony_ci			       size_t len);
12662306a36Sopenharmony_ci#else
12762306a36Sopenharmony_cistatic inline struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr)
12862306a36Sopenharmony_ci{
12962306a36Sopenharmony_ci	return ERR_PTR(-ENOENT);
13062306a36Sopenharmony_ci}
13162306a36Sopenharmony_cistatic inline
13262306a36Sopenharmony_civoid brcmf_debugfs_add_entry(struct brcmf_pub *drvr, const char *fn,
13362306a36Sopenharmony_ci			     int (*read_fn)(struct seq_file *seq, void *data))
13462306a36Sopenharmony_ci{ }
13562306a36Sopenharmony_cistatic inline
13662306a36Sopenharmony_ciint brcmf_debug_create_memdump(struct brcmf_bus *bus, const void *data,
13762306a36Sopenharmony_ci			       size_t len)
13862306a36Sopenharmony_ci{
13962306a36Sopenharmony_ci	return 0;
14062306a36Sopenharmony_ci}
14162306a36Sopenharmony_ci#endif
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci#endif /* BRCMFMAC_DEBUG_H */
144