162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/******************************************************************************
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
562306a36Sopenharmony_ci * Copyright(c) 2018 - 2021 Intel Corporation
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Portions of this file are derived from the ipw3945 project.
862306a36Sopenharmony_ci *****************************************************************************/
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef __iwl_debug_h__
1162306a36Sopenharmony_ci#define __iwl_debug_h__
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include "iwl-modparams.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_cistatic inline bool iwl_have_debug_level(u32 level)
1762306a36Sopenharmony_ci{
1862306a36Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG
1962306a36Sopenharmony_ci	return iwlwifi_mod_params.debug_level & level;
2062306a36Sopenharmony_ci#else
2162306a36Sopenharmony_ci	return false;
2262306a36Sopenharmony_ci#endif
2362306a36Sopenharmony_ci}
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cienum iwl_err_mode {
2662306a36Sopenharmony_ci	IWL_ERR_MODE_REGULAR,
2762306a36Sopenharmony_ci	IWL_ERR_MODE_RFKILL,
2862306a36Sopenharmony_ci	IWL_ERR_MODE_TRACE_ONLY,
2962306a36Sopenharmony_ci	IWL_ERR_MODE_RATELIMIT,
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistruct device;
3362306a36Sopenharmony_civoid __iwl_err(struct device *dev, enum iwl_err_mode mode, const char *fmt, ...)
3462306a36Sopenharmony_ci	__printf(3, 4);
3562306a36Sopenharmony_civoid __iwl_warn(struct device *dev, const char *fmt, ...) __printf(2, 3);
3662306a36Sopenharmony_civoid __iwl_info(struct device *dev, const char *fmt, ...) __printf(2, 3);
3762306a36Sopenharmony_civoid __iwl_crit(struct device *dev, const char *fmt, ...) __printf(2, 3);
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* not all compilers can evaluate strlen() at compile time, so use sizeof() */
4062306a36Sopenharmony_ci#define CHECK_FOR_NEWLINE(f) BUILD_BUG_ON(f[sizeof(f) - 2] != '\n')
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* No matter what is m (priv, bus, trans), this will work */
4362306a36Sopenharmony_ci#define __IWL_ERR_DEV(d, mode, f, a...)					\
4462306a36Sopenharmony_ci	do {								\
4562306a36Sopenharmony_ci		CHECK_FOR_NEWLINE(f);					\
4662306a36Sopenharmony_ci		__iwl_err((d), mode, f, ## a);				\
4762306a36Sopenharmony_ci	} while (0)
4862306a36Sopenharmony_ci#define IWL_ERR_DEV(d, f, a...)						\
4962306a36Sopenharmony_ci	__IWL_ERR_DEV(d, IWL_ERR_MODE_REGULAR, f, ## a)
5062306a36Sopenharmony_ci#define IWL_ERR(m, f, a...)						\
5162306a36Sopenharmony_ci	IWL_ERR_DEV((m)->dev, f, ## a)
5262306a36Sopenharmony_ci#define IWL_ERR_LIMIT(m, f, a...)					\
5362306a36Sopenharmony_ci	__IWL_ERR_DEV((m)->dev, IWL_ERR_MODE_RATELIMIT, f, ## a)
5462306a36Sopenharmony_ci#define IWL_WARN(m, f, a...)						\
5562306a36Sopenharmony_ci	do {								\
5662306a36Sopenharmony_ci		CHECK_FOR_NEWLINE(f);					\
5762306a36Sopenharmony_ci		__iwl_warn((m)->dev, f, ## a);				\
5862306a36Sopenharmony_ci	} while (0)
5962306a36Sopenharmony_ci#define IWL_INFO(m, f, a...)						\
6062306a36Sopenharmony_ci	do {								\
6162306a36Sopenharmony_ci		CHECK_FOR_NEWLINE(f);					\
6262306a36Sopenharmony_ci		__iwl_info((m)->dev, f, ## a);				\
6362306a36Sopenharmony_ci	} while (0)
6462306a36Sopenharmony_ci#define IWL_CRIT(m, f, a...)						\
6562306a36Sopenharmony_ci	do {								\
6662306a36Sopenharmony_ci		CHECK_FOR_NEWLINE(f);					\
6762306a36Sopenharmony_ci		__iwl_crit((m)->dev, f, ## a);				\
6862306a36Sopenharmony_ci	} while (0)
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWLWIFI_DEVICE_TRACING)
7162306a36Sopenharmony_civoid __iwl_dbg(struct device *dev,
7262306a36Sopenharmony_ci	       u32 level, bool limit, const char *function,
7362306a36Sopenharmony_ci	       const char *fmt, ...) __printf(5, 6);
7462306a36Sopenharmony_ci#else
7562306a36Sopenharmony_ci__printf(5, 6) static inline void
7662306a36Sopenharmony_ci__iwl_dbg(struct device *dev,
7762306a36Sopenharmony_ci	  u32 level, bool limit, const char *function,
7862306a36Sopenharmony_ci	  const char *fmt, ...)
7962306a36Sopenharmony_ci{}
8062306a36Sopenharmony_ci#endif
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#define iwl_print_hex_error(m, p, len)					\
8362306a36Sopenharmony_cido {									\
8462306a36Sopenharmony_ci	print_hex_dump(KERN_ERR, "iwl data: ",				\
8562306a36Sopenharmony_ci		       DUMP_PREFIX_OFFSET, 16, 1, p, len, 1);		\
8662306a36Sopenharmony_ci} while (0)
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define __IWL_DEBUG_DEV(dev, level, limit, fmt, args...)		\
8962306a36Sopenharmony_ci	do {								\
9062306a36Sopenharmony_ci		CHECK_FOR_NEWLINE(fmt);					\
9162306a36Sopenharmony_ci		__iwl_dbg(dev, level, limit, __func__, fmt, ##args);	\
9262306a36Sopenharmony_ci	} while (0)
9362306a36Sopenharmony_ci#define IWL_DEBUG(m, level, fmt, args...)				\
9462306a36Sopenharmony_ci	__IWL_DEBUG_DEV((m)->dev, level, false, fmt, ##args)
9562306a36Sopenharmony_ci#define IWL_DEBUG_DEV(dev, level, fmt, args...)				\
9662306a36Sopenharmony_ci	__IWL_DEBUG_DEV(dev, level, false, fmt, ##args)
9762306a36Sopenharmony_ci#define IWL_DEBUG_LIMIT(m, level, fmt, args...)				\
9862306a36Sopenharmony_ci	__IWL_DEBUG_DEV((m)->dev, level, true, fmt, ##args)
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG
10162306a36Sopenharmony_ci#define iwl_print_hex_dump(m, level, p, len)				\
10262306a36Sopenharmony_cido {                                            			\
10362306a36Sopenharmony_ci	if (iwl_have_debug_level(level))				\
10462306a36Sopenharmony_ci		print_hex_dump(KERN_DEBUG, "iwl data: ",		\
10562306a36Sopenharmony_ci			       DUMP_PREFIX_OFFSET, 16, 1, p, len, 1);	\
10662306a36Sopenharmony_ci} while (0)
10762306a36Sopenharmony_ci#else
10862306a36Sopenharmony_ci#define iwl_print_hex_dump(m, level, p, len)
10962306a36Sopenharmony_ci#endif				/* CONFIG_IWLWIFI_DEBUG */
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci/*
11262306a36Sopenharmony_ci * To use the debug system:
11362306a36Sopenharmony_ci *
11462306a36Sopenharmony_ci * If you are defining a new debug classification, simply add it to the #define
11562306a36Sopenharmony_ci * list here in the form of
11662306a36Sopenharmony_ci *
11762306a36Sopenharmony_ci * #define IWL_DL_xxxx VALUE
11862306a36Sopenharmony_ci *
11962306a36Sopenharmony_ci * where xxxx should be the name of the classification (for example, WEP).
12062306a36Sopenharmony_ci *
12162306a36Sopenharmony_ci * You then need to either add a IWL_xxxx_DEBUG() macro definition for your
12262306a36Sopenharmony_ci * classification, or use IWL_DEBUG(IWL_DL_xxxx, ...) whenever you want
12362306a36Sopenharmony_ci * to send output to that classification.
12462306a36Sopenharmony_ci *
12562306a36Sopenharmony_ci * The active debug levels can be accessed via files
12662306a36Sopenharmony_ci *
12762306a36Sopenharmony_ci *	/sys/module/iwlwifi/parameters/debug
12862306a36Sopenharmony_ci * when CONFIG_IWLWIFI_DEBUG=y.
12962306a36Sopenharmony_ci *
13062306a36Sopenharmony_ci *	/sys/kernel/debug/phy0/iwlwifi/debug/debug_level
13162306a36Sopenharmony_ci * when CONFIG_IWLWIFI_DEBUGFS=y.
13262306a36Sopenharmony_ci *
13362306a36Sopenharmony_ci */
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/* 0x0000000F - 0x00000001 */
13662306a36Sopenharmony_ci#define IWL_DL_INFO		0x00000001
13762306a36Sopenharmony_ci#define IWL_DL_MAC80211		0x00000002
13862306a36Sopenharmony_ci#define IWL_DL_HCMD		0x00000004
13962306a36Sopenharmony_ci#define IWL_DL_TDLS		0x00000008
14062306a36Sopenharmony_ci/* 0x000000F0 - 0x00000010 */
14162306a36Sopenharmony_ci#define IWL_DL_QUOTA		0x00000010
14262306a36Sopenharmony_ci#define IWL_DL_TE		0x00000020
14362306a36Sopenharmony_ci#define IWL_DL_EEPROM		0x00000040
14462306a36Sopenharmony_ci#define IWL_DL_RADIO		0x00000080
14562306a36Sopenharmony_ci/* 0x00000F00 - 0x00000100 */
14662306a36Sopenharmony_ci#define IWL_DL_POWER		0x00000100
14762306a36Sopenharmony_ci#define IWL_DL_TEMP		0x00000200
14862306a36Sopenharmony_ci#define IWL_DL_WOWLAN		0x00000400
14962306a36Sopenharmony_ci#define IWL_DL_SCAN		0x00000800
15062306a36Sopenharmony_ci/* 0x0000F000 - 0x00001000 */
15162306a36Sopenharmony_ci#define IWL_DL_ASSOC		0x00001000
15262306a36Sopenharmony_ci#define IWL_DL_DROP		0x00002000
15362306a36Sopenharmony_ci#define IWL_DL_LAR		0x00004000
15462306a36Sopenharmony_ci#define IWL_DL_COEX		0x00008000
15562306a36Sopenharmony_ci/* 0x000F0000 - 0x00010000 */
15662306a36Sopenharmony_ci#define IWL_DL_FW		0x00010000
15762306a36Sopenharmony_ci#define IWL_DL_RF_KILL		0x00020000
15862306a36Sopenharmony_ci#define IWL_DL_TPT		0x00040000
15962306a36Sopenharmony_ci/* 0x00F00000 - 0x00100000 */
16062306a36Sopenharmony_ci#define IWL_DL_RATE		0x00100000
16162306a36Sopenharmony_ci#define IWL_DL_CALIB		0x00200000
16262306a36Sopenharmony_ci#define IWL_DL_WEP		0x00400000
16362306a36Sopenharmony_ci#define IWL_DL_TX		0x00800000
16462306a36Sopenharmony_ci/* 0x0F000000 - 0x01000000 */
16562306a36Sopenharmony_ci#define IWL_DL_RX		0x01000000
16662306a36Sopenharmony_ci#define IWL_DL_ISR		0x02000000
16762306a36Sopenharmony_ci#define IWL_DL_HT		0x04000000
16862306a36Sopenharmony_ci#define IWL_DL_EXTERNAL		0x08000000
16962306a36Sopenharmony_ci/* 0xF0000000 - 0x10000000 */
17062306a36Sopenharmony_ci#define IWL_DL_11H		0x10000000
17162306a36Sopenharmony_ci#define IWL_DL_STATS		0x20000000
17262306a36Sopenharmony_ci#define IWL_DL_TX_REPLY		0x40000000
17362306a36Sopenharmony_ci#define IWL_DL_TX_QUEUES	0x80000000
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci#define IWL_DEBUG_INFO(p, f, a...)	IWL_DEBUG(p, IWL_DL_INFO, f, ## a)
17662306a36Sopenharmony_ci#define IWL_DEBUG_TDLS(p, f, a...)	IWL_DEBUG(p, IWL_DL_TDLS, f, ## a)
17762306a36Sopenharmony_ci#define IWL_DEBUG_MAC80211(p, f, a...)	IWL_DEBUG(p, IWL_DL_MAC80211, f, ## a)
17862306a36Sopenharmony_ci#define IWL_DEBUG_EXTERNAL(p, f, a...)	IWL_DEBUG(p, IWL_DL_EXTERNAL, f, ## a)
17962306a36Sopenharmony_ci#define IWL_DEBUG_TEMP(p, f, a...)	IWL_DEBUG(p, IWL_DL_TEMP, f, ## a)
18062306a36Sopenharmony_ci#define IWL_DEBUG_SCAN(p, f, a...)	IWL_DEBUG(p, IWL_DL_SCAN, f, ## a)
18162306a36Sopenharmony_ci#define IWL_DEBUG_RX(p, f, a...)	IWL_DEBUG(p, IWL_DL_RX, f, ## a)
18262306a36Sopenharmony_ci#define IWL_DEBUG_TX(p, f, a...)	IWL_DEBUG(p, IWL_DL_TX, f, ## a)
18362306a36Sopenharmony_ci#define IWL_DEBUG_ISR(p, f, a...)	IWL_DEBUG(p, IWL_DL_ISR, f, ## a)
18462306a36Sopenharmony_ci#define IWL_DEBUG_WEP(p, f, a...)	IWL_DEBUG(p, IWL_DL_WEP, f, ## a)
18562306a36Sopenharmony_ci#define IWL_DEBUG_HC(p, f, a...)	IWL_DEBUG(p, IWL_DL_HCMD, f, ## a)
18662306a36Sopenharmony_ci#define IWL_DEBUG_QUOTA(p, f, a...)	IWL_DEBUG(p, IWL_DL_QUOTA, f, ## a)
18762306a36Sopenharmony_ci#define IWL_DEBUG_TE(p, f, a...)	IWL_DEBUG(p, IWL_DL_TE, f, ## a)
18862306a36Sopenharmony_ci#define IWL_DEBUG_EEPROM(d, f, a...)	IWL_DEBUG_DEV(d, IWL_DL_EEPROM, f, ## a)
18962306a36Sopenharmony_ci#define IWL_DEBUG_CALIB(p, f, a...)	IWL_DEBUG(p, IWL_DL_CALIB, f, ## a)
19062306a36Sopenharmony_ci#define IWL_DEBUG_FW(p, f, a...)	IWL_DEBUG(p, IWL_DL_FW, f, ## a)
19162306a36Sopenharmony_ci#define IWL_DEBUG_RF_KILL(p, f, a...)	IWL_DEBUG(p, IWL_DL_RF_KILL, f, ## a)
19262306a36Sopenharmony_ci#define IWL_DEBUG_DROP(p, f, a...)	IWL_DEBUG(p, IWL_DL_DROP, f, ## a)
19362306a36Sopenharmony_ci#define IWL_DEBUG_DROP_LIMIT(p, f, a...)	\
19462306a36Sopenharmony_ci		IWL_DEBUG_LIMIT(p, IWL_DL_DROP, f, ## a)
19562306a36Sopenharmony_ci#define IWL_DEBUG_COEX(p, f, a...)	IWL_DEBUG(p, IWL_DL_COEX, f, ## a)
19662306a36Sopenharmony_ci#define IWL_DEBUG_RATE(p, f, a...)	IWL_DEBUG(p, IWL_DL_RATE, f, ## a)
19762306a36Sopenharmony_ci#define IWL_DEBUG_RATE_LIMIT(p, f, a...)	\
19862306a36Sopenharmony_ci		IWL_DEBUG_LIMIT(p, IWL_DL_RATE, f, ## a)
19962306a36Sopenharmony_ci#define IWL_DEBUG_ASSOC(p, f, a...)	\
20062306a36Sopenharmony_ci		IWL_DEBUG(p, IWL_DL_ASSOC | IWL_DL_INFO, f, ## a)
20162306a36Sopenharmony_ci#define IWL_DEBUG_ASSOC_LIMIT(p, f, a...)	\
20262306a36Sopenharmony_ci		IWL_DEBUG_LIMIT(p, IWL_DL_ASSOC | IWL_DL_INFO, f, ## a)
20362306a36Sopenharmony_ci#define IWL_DEBUG_HT(p, f, a...)	IWL_DEBUG(p, IWL_DL_HT, f, ## a)
20462306a36Sopenharmony_ci#define IWL_DEBUG_STATS(p, f, a...)	IWL_DEBUG(p, IWL_DL_STATS, f, ## a)
20562306a36Sopenharmony_ci#define IWL_DEBUG_STATS_LIMIT(p, f, a...)	\
20662306a36Sopenharmony_ci		IWL_DEBUG_LIMIT(p, IWL_DL_STATS, f, ## a)
20762306a36Sopenharmony_ci#define IWL_DEBUG_TX_REPLY(p, f, a...)	IWL_DEBUG(p, IWL_DL_TX_REPLY, f, ## a)
20862306a36Sopenharmony_ci#define IWL_DEBUG_TX_QUEUES(p, f, a...)	IWL_DEBUG(p, IWL_DL_TX_QUEUES, f, ## a)
20962306a36Sopenharmony_ci#define IWL_DEBUG_RADIO(p, f, a...)	IWL_DEBUG(p, IWL_DL_RADIO, f, ## a)
21062306a36Sopenharmony_ci#define IWL_DEBUG_DEV_RADIO(p, f, a...)	IWL_DEBUG_DEV(p, IWL_DL_RADIO, f, ## a)
21162306a36Sopenharmony_ci#define IWL_DEBUG_POWER(p, f, a...)	IWL_DEBUG(p, IWL_DL_POWER, f, ## a)
21262306a36Sopenharmony_ci#define IWL_DEBUG_11H(p, f, a...)	IWL_DEBUG(p, IWL_DL_11H, f, ## a)
21362306a36Sopenharmony_ci#define IWL_DEBUG_TPT(p, f, a...)	IWL_DEBUG(p, IWL_DL_TPT, f, ## a)
21462306a36Sopenharmony_ci#define IWL_DEBUG_WOWLAN(p, f, a...)	IWL_DEBUG(p, IWL_DL_WOWLAN, f, ## a)
21562306a36Sopenharmony_ci#define IWL_DEBUG_LAR(p, f, a...)	IWL_DEBUG(p, IWL_DL_LAR, f, ## a)
21662306a36Sopenharmony_ci#define IWL_DEBUG_FW_INFO(p, f, a...)		\
21762306a36Sopenharmony_ci		IWL_DEBUG(p, IWL_DL_INFO | IWL_DL_FW, f, ## a)
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci#endif
220