1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2005-2011, 2021 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 	trace_iwlwifi_err(&vaf);
61 	va_end(args);
62 }
63 IWL_EXPORT_SYMBOL(__iwl_err);
64 
65 #if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWLWIFI_DEVICE_TRACING)
66 void __iwl_dbg(struct device *dev,
67 	       u32 level, bool limit, const char *function,
68 	       const char *fmt, ...)
69 {
70 	struct va_format vaf = {
71 		.fmt = fmt,
72 	};
73 	va_list args;
74 
75 	va_start(args, fmt);
76 	vaf.va = &args;
77 #ifdef CONFIG_IWLWIFI_DEBUG
78 	if (iwl_have_debug_level(level) &&
79 	    (!limit || net_ratelimit()))
80 		dev_printk(KERN_DEBUG, dev, "%s %pV", function, &vaf);
81 #endif
82 	trace_iwlwifi_dbg(level, function, &vaf);
83 	va_end(args);
84 }
85 IWL_EXPORT_SYMBOL(__iwl_dbg);
86 #endif
87