Path: blob/main/sys/contrib/dev/athk/ath12k/debug.c
48375 views
// SPDX-License-Identifier: BSD-3-Clause-Clear1/*2* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.3* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.4*/56#include <linux/vmalloc.h>7#include "core.h"8#include "debug.h"910void ath12k_info(struct ath12k_base *ab, const char *fmt, ...)11{12struct va_format vaf = {13.fmt = fmt,14};15va_list args;1617va_start(args, fmt);18vaf.va = &args;19#if defined(__linux__)20dev_info(ab->dev, "%pV", &vaf);21#elif defined(__FreeBSD__)22{23char *str;24vasprintf(&str, M_KMALLOC, fmt, args);25dev_printk(KERN_INFO, ab->dev, "%s", str);26free(str, M_KMALLOC);27}28#endif29/* TODO: Trace the log */30va_end(args);31}3233void ath12k_err(struct ath12k_base *ab, const char *fmt, ...)34{35struct va_format vaf = {36.fmt = fmt,37};38va_list args;3940va_start(args, fmt);41vaf.va = &args;42#if defined(__linux__)43dev_err(ab->dev, "%pV", &vaf);44#elif defined(__FreeBSD__)45{46char *str;47vasprintf(&str, M_KMALLOC, fmt, args);48dev_printk(KERN_ERR, ab->dev, "%s", str);49free(str, M_KMALLOC);50}51#endif52/* TODO: Trace the log */53va_end(args);54}5556void ath12k_warn(struct ath12k_base *ab, const char *fmt, ...)57{58struct va_format vaf = {59.fmt = fmt,60};61va_list args;6263va_start(args, fmt);64vaf.va = &args;65#if defined(__linux__)66dev_warn_ratelimited(ab->dev, "%pV", &vaf);67#elif defined(__FreeBSD__)68{69static linux_ratelimit_t __ratelimited;7071if (linux_ratelimited(&__ratelimited)) {72char *str;73vasprintf(&str, M_KMALLOC, fmt, args);74dev_printk(KERN_WARN, ab->dev, "%s", str);75free(str, M_KMALLOC);76}77}78#endif79/* TODO: Trace the log */80va_end(args);81}8283#ifdef CONFIG_ATH12K_DEBUG8485void __ath12k_dbg(struct ath12k_base *ab, enum ath12k_debug_mask mask,86const char *fmt, ...)87{88struct va_format vaf;89va_list args;9091va_start(args, fmt);9293vaf.fmt = fmt;94vaf.va = &args;9596if (ath12k_debug_mask & mask)97#if defined(__linux__)98dev_dbg(ab->dev, "%pV", &vaf);99#elif defined(__FreeBSD__)100{101char *str;102vasprintf(&str, M_KMALLOC, fmt, args);103dev_printk(KERN_DEBUG, ab->dev, "%s", str);104free(str, M_KMALLOC);105}106#endif107108/* TODO: trace log */109110va_end(args);111}112113void ath12k_dbg_dump(struct ath12k_base *ab,114enum ath12k_debug_mask mask,115const char *msg, const char *prefix,116const void *buf, size_t len)117{118#if defined(__linux__)119char linebuf[256];120size_t linebuflen;121const void *ptr;122#elif defined(__FreeBSD__)123struct sbuf *sb;124int rc;125#endif126127if (ath12k_debug_mask & mask) {128if (msg)129__ath12k_dbg(ab, mask, "%s\n", msg);130131#if defined(__linux__)132for (ptr = buf; (ptr - buf) < len; ptr += 16) {133linebuflen = 0;134linebuflen += scnprintf(linebuf + linebuflen,135sizeof(linebuf) - linebuflen,136"%s%08x: ",137(prefix ? prefix : ""),138(unsigned int)(ptr - buf));139hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,140linebuf + linebuflen,141sizeof(linebuf) - linebuflen, true);142dev_dbg(ab->dev, "%s\n", linebuf);143}144#elif defined(__FreeBSD__)145sb = sbuf_new_auto();146if (sb == NULL)147goto trace;148149sbuf_hexdump(sb, buf, len, prefix, 0);150sbuf_trim(sb);151rc = sbuf_finish(sb);152if (rc == 0)153dev_printk(KERN_DEBUG, ab->dev, "%s\n", sbuf_data(sb));154sbuf_delete(sb);155trace: ;156#endif157}158}159160#endif /* CONFIG_ATH12K_DEBUG */161162163