1 // SPDX-License-Identifier: BSD-3-Clause-Clear
2 /*
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4 */
5
6 #include <linux/vmalloc.h>
7 #include "core.h"
8 #include "debug.h"
9
ath11k_info(struct ath11k_base * ab,const char * fmt,...)10 void ath11k_info(struct ath11k_base *ab, const char *fmt, ...)
11 {
12 struct va_format vaf = {
13 .fmt = fmt,
14 };
15 va_list args;
16
17 va_start(args, fmt);
18 vaf.va = &args;
19 #if defined(__linux__)
20 dev_info(ab->dev, "%pV", &vaf);
21 #elif defined(__FreeBSD__)
22 {
23 char *str;
24 vasprintf(&str, M_KMALLOC, fmt, args);
25 dev_printk(KERN_INFO, ab->dev, "%s", str);
26 free(str, M_KMALLOC);
27 }
28 #endif
29 trace_ath11k_log_info(ab, &vaf);
30 va_end(args);
31 }
32 EXPORT_SYMBOL(ath11k_info);
33
ath11k_err(struct ath11k_base * ab,const char * fmt,...)34 void ath11k_err(struct ath11k_base *ab, const char *fmt, ...)
35 {
36 struct va_format vaf = {
37 .fmt = fmt,
38 };
39 va_list args;
40
41 va_start(args, fmt);
42 vaf.va = &args;
43 #if defined(__linux__)
44 dev_err(ab->dev, "%pV", &vaf);
45 #elif defined(__FreeBSD__)
46 {
47 char *str;
48 vasprintf(&str, M_KMALLOC, fmt, args);
49 dev_printk(KERN_ERR, ab->dev, "%s", str);
50 free(str, M_KMALLOC);
51 }
52 #endif
53 trace_ath11k_log_err(ab, &vaf);
54 va_end(args);
55 }
56 EXPORT_SYMBOL(ath11k_err);
57
ath11k_warn(struct ath11k_base * ab,const char * fmt,...)58 void ath11k_warn(struct ath11k_base *ab, const char *fmt, ...)
59 {
60 struct va_format vaf = {
61 .fmt = fmt,
62 };
63 va_list args;
64
65 va_start(args, fmt);
66 vaf.va = &args;
67 #if defined(__linux__)
68 dev_warn_ratelimited(ab->dev, "%pV", &vaf);
69 #elif defined(__FreeBSD__)
70 {
71 static linux_ratelimit_t __ratelimited;
72
73 if (linux_ratelimited(&__ratelimited)) {
74 char *str;
75 vasprintf(&str, M_KMALLOC, fmt, args);
76 dev_printk(KERN_WARN, ab->dev, "%s", str);
77 free(str, M_KMALLOC);
78 }
79 }
80 #endif
81 trace_ath11k_log_warn(ab, &vaf);
82 va_end(args);
83 }
84 EXPORT_SYMBOL(ath11k_warn);
85
86 #ifdef CONFIG_ATH11K_DEBUG
87
__ath11k_dbg(struct ath11k_base * ab,enum ath11k_debug_mask mask,const char * fmt,...)88 void __ath11k_dbg(struct ath11k_base *ab, enum ath11k_debug_mask mask,
89 const char *fmt, ...)
90 {
91 struct va_format vaf;
92 va_list args;
93
94 va_start(args, fmt);
95
96 vaf.fmt = fmt;
97 vaf.va = &args;
98
99 if (ath11k_debug_mask & mask)
100 #if defined(__linux__)
101 dev_printk(KERN_DEBUG, ab->dev, "%s %pV", ath11k_dbg_str(mask), &vaf);
102 #elif defined(__FreeBSD__)
103 {
104 char *str;
105 vasprintf(&str, M_KMALLOC, fmt, args);
106 dev_printk(KERN_DEBUG, ab->dev, "%s %s", ath11k_dbg_str(mask), str);
107 free(str, M_KMALLOC);
108 }
109 #endif
110
111 trace_ath11k_log_dbg(ab, mask, &vaf);
112
113 va_end(args);
114 }
115 EXPORT_SYMBOL(__ath11k_dbg);
116
ath11k_dbg_dump(struct ath11k_base * ab,enum ath11k_debug_mask mask,const char * msg,const char * prefix,const void * buf,size_t len)117 void ath11k_dbg_dump(struct ath11k_base *ab,
118 enum ath11k_debug_mask mask,
119 const char *msg, const char *prefix,
120 const void *buf, size_t len)
121 {
122 #if defined(__linux__)
123 char linebuf[256];
124 size_t linebuflen;
125 const void *ptr;
126 #elif defined(__FreeBSD__)
127 struct sbuf *sb;
128 int rc;
129 #endif
130
131 if (ath11k_debug_mask & mask) {
132 if (msg)
133 __ath11k_dbg(ab, mask, "%s\n", msg);
134
135 #if defined(__linux__)
136 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
137 linebuflen = 0;
138 linebuflen += scnprintf(linebuf + linebuflen,
139 sizeof(linebuf) - linebuflen,
140 "%s%08x: ",
141 (prefix ? prefix : ""),
142 (unsigned int)(ptr - buf));
143 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
144 linebuf + linebuflen,
145 sizeof(linebuf) - linebuflen, true);
146 dev_printk(KERN_DEBUG, ab->dev, "%s\n", linebuf);
147 }
148 #elif defined(__FreeBSD__)
149 sb = sbuf_new_auto();
150 if (sb == NULL)
151 goto trace;
152
153 sbuf_hexdump(sb, buf, len, prefix, 0);
154 sbuf_trim(sb);
155 rc = sbuf_finish(sb);
156 if (rc == 0)
157 dev_printk(KERN_DEBUG, ab->dev, "%s\n", sbuf_data(sb));
158 sbuf_delete(sb);
159 trace: ;
160 #endif
161 }
162
163 /* tracing code doesn't like null strings */
164 trace_ath11k_log_dbg_dump(ab, msg ? msg : "", prefix ? prefix : "",
165 buf, len);
166 }
167 EXPORT_SYMBOL(ath11k_dbg_dump);
168
169 #endif /* CONFIG_ATH11K_DEBUG */
170