1// SPDX-License-Identifier: BSD-3-Clause-Clear
2/*
3 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
5 */
6
7#include <linux/vmalloc.h>
8#include "core.h"
9#include "debug.h"
10
11void ath12k_info(struct ath12k_base *ab, const char *fmt, ...)
12{
13	struct va_format vaf = {
14		.fmt = fmt,
15	};
16	va_list args;
17
18	va_start(args, fmt);
19	vaf.va = &args;
20	dev_info(ab->dev, "%pV", &vaf);
21	/* TODO: Trace the log */
22	va_end(args);
23}
24
25void ath12k_err(struct ath12k_base *ab, const char *fmt, ...)
26{
27	struct va_format vaf = {
28		.fmt = fmt,
29	};
30	va_list args;
31
32	va_start(args, fmt);
33	vaf.va = &args;
34	dev_err(ab->dev, "%pV", &vaf);
35	/* TODO: Trace the log */
36	va_end(args);
37}
38
39void ath12k_warn(struct ath12k_base *ab, const char *fmt, ...)
40{
41	struct va_format vaf = {
42		.fmt = fmt,
43	};
44	va_list args;
45
46	va_start(args, fmt);
47	vaf.va = &args;
48	dev_warn_ratelimited(ab->dev, "%pV", &vaf);
49	/* TODO: Trace the log */
50	va_end(args);
51}
52
53#ifdef CONFIG_ATH12K_DEBUG
54
55void __ath12k_dbg(struct ath12k_base *ab, enum ath12k_debug_mask mask,
56		  const char *fmt, ...)
57{
58	struct va_format vaf;
59	va_list args;
60
61	va_start(args, fmt);
62
63	vaf.fmt = fmt;
64	vaf.va = &args;
65
66	if (ath12k_debug_mask & mask)
67		dev_printk(KERN_DEBUG, ab->dev, "%pV", &vaf);
68
69	/* TODO: trace log */
70
71	va_end(args);
72}
73
74void ath12k_dbg_dump(struct ath12k_base *ab,
75		     enum ath12k_debug_mask mask,
76		     const char *msg, const char *prefix,
77		     const void *buf, size_t len)
78{
79	char linebuf[256];
80	size_t linebuflen;
81	const void *ptr;
82
83	if (ath12k_debug_mask & mask) {
84		if (msg)
85			__ath12k_dbg(ab, mask, "%s\n", msg);
86
87		for (ptr = buf; (ptr - buf) < len; ptr += 16) {
88			linebuflen = 0;
89			linebuflen += scnprintf(linebuf + linebuflen,
90						sizeof(linebuf) - linebuflen,
91						"%s%08x: ",
92						(prefix ? prefix : ""),
93						(unsigned int)(ptr - buf));
94			hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
95					   linebuf + linebuflen,
96					   sizeof(linebuf) - linebuflen, true);
97			dev_dbg(ab->dev, "%s\n", linebuf);
98		}
99	}
100}
101
102#endif /* CONFIG_ATH12K_DEBUG */
103