xref: /linux/drivers/net/wireless/intel/iwlwifi/iwl-debug.c (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2005-2011, 2021-2022 Intel Corporation
4  */
5 #include <linux/device.h>
6 #include <linux/interrupt.h>
7 #include <linux/export.h>
8 #include "iwl-drv.h"
9 #include "iwl-debug.h"
10 #include "iwl-devtrace.h"
11 
12 #define __iwl_fn(fn)						\
13 void __iwl_ ##fn(struct device *dev, const char *fmt, ...)	\
14 {								\
15 	struct va_format vaf = {				\
16 		.fmt = fmt,					\
17 	};							\
18 	va_list args;						\
19 								\
20 	va_start(args, fmt);					\
21 	vaf.va = &args;						\
22 	dev_ ##fn(dev, "%pV", &vaf);				\
23 	trace_iwlwifi_ ##fn(&vaf);				\
24 	va_end(args);						\
25 }
26 
27 __iwl_fn(warn)
28 IWL_EXPORT_SYMBOL(__iwl_warn);
29 __iwl_fn(info)
30 IWL_EXPORT_SYMBOL(__iwl_info);
31 __iwl_fn(crit)
32 IWL_EXPORT_SYMBOL(__iwl_crit);
33 
34 void __iwl_err(struct device *dev, enum iwl_err_mode mode, const char *fmt, ...)
35 {
36 	struct va_format vaf = {
37 		.fmt = fmt,
38 	};
39 	va_list args, args2;
40 
41 	va_start(args, fmt);
42 	switch (mode) {
43 	case IWL_ERR_MODE_RATELIMIT:
44 		if (net_ratelimit())
45 			break;
46 		fallthrough;
47 	case IWL_ERR_MODE_REGULAR:
48 	case IWL_ERR_MODE_RFKILL:
49 		va_copy(args2, args);
50 		vaf.va = &args2;
51 		if (mode == IWL_ERR_MODE_RFKILL)
52 			dev_err(dev, "(RFKILL) %pV", &vaf);
53 		else
54 			dev_err(dev, "%pV", &vaf);
55 		va_end(args2);
56 		break;
57 	default:
58 		break;
59 	}
60 	vaf.va = &args;
61 	trace_iwlwifi_err(&vaf);
62 	va_end(args);
63 }
64 IWL_EXPORT_SYMBOL(__iwl_err);
65 
66 #if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWLWIFI_DEVICE_TRACING)
67 void __iwl_dbg(struct device *dev,
68 	       u32 level, bool limit, const char *function,
69 	       const char *fmt, ...)
70 {
71 	struct va_format vaf = {
72 		.fmt = fmt,
73 	};
74 	va_list args;
75 
76 	va_start(args, fmt);
77 	vaf.va = &args;
78 #ifdef CONFIG_IWLWIFI_DEBUG
79 	if (iwl_have_debug_level(level) &&
80 	    (!limit || net_ratelimit()))
81 		dev_printk(KERN_DEBUG, dev, "%s %pV", function, &vaf);
82 #endif
83 	trace_iwlwifi_dbg(level, function, &vaf);
84 	va_end(args);
85 }
86 IWL_EXPORT_SYMBOL(__iwl_dbg);
87 #endif
88