mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 00:32:25 -04:00
Import BSD-3-Clause-Clear ath12k driver based on wireless-testing (wt-2023-05-11) 711dca0ca3d77414f8f346e564e9c8640147f40d (after v6.4-rc1) with further updates based on (wt-2023-06-09) 7bd20e011626ccc3ad53e57873452b1716fcfaaa (after v6.4-rc5), (wt-2023-07-24) 62e409149b62a285e89018e49b2e115757fb9022 (after v6.5-rc3), (wt-2023-08-06) 2a220a15be657a24868368892e3e2caba2115283 (after v6.5-rc4), (wt-2023-08-13) 81e147b1317ee7cde8b624ee8c0501b470d7e91c (after v6.5-rc5). Complement the driver to make compile on FreeBSD using LinuxKPI with changes covered by #ifdef (__FreeBSD__). Add the module build framework but keep disconnected from the build for now. The current driver (or rather LinuxKPI) lacks support for some "qcom" bits needed in order to get things working (as does ath11k). There was interest by various people to enhance support further for ath11k which will equally benefit ath12k. Given the lack of full license texts on the files this is imported under the draft policy for handling SPDX files (D29226) and with approval for BSD-3-Clause-Clear. [1] Approved by: core (jhb, 2023-05-11) [1] MFC after: 20 days
161 lines
3.2 KiB
C
161 lines
3.2 KiB
C
// SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
/*
|
|
* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
|
|
* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
|
|
*/
|
|
|
|
#include <linux/vmalloc.h>
|
|
#include "core.h"
|
|
#include "debug.h"
|
|
|
|
void ath12k_info(struct ath12k_base *ab, const char *fmt, ...)
|
|
{
|
|
struct va_format vaf = {
|
|
.fmt = fmt,
|
|
};
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
vaf.va = &args;
|
|
#if defined(__linux__)
|
|
dev_info(ab->dev, "%pV", &vaf);
|
|
#elif defined(__FreeBSD__)
|
|
{
|
|
char *str;
|
|
vasprintf(&str, M_KMALLOC, fmt, args);
|
|
dev_printk(KERN_INFO, ab->dev, "%s", str);
|
|
free(str, M_KMALLOC);
|
|
}
|
|
#endif
|
|
/* TODO: Trace the log */
|
|
va_end(args);
|
|
}
|
|
|
|
void ath12k_err(struct ath12k_base *ab, const char *fmt, ...)
|
|
{
|
|
struct va_format vaf = {
|
|
.fmt = fmt,
|
|
};
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
vaf.va = &args;
|
|
#if defined(__linux__)
|
|
dev_err(ab->dev, "%pV", &vaf);
|
|
#elif defined(__FreeBSD__)
|
|
{
|
|
char *str;
|
|
vasprintf(&str, M_KMALLOC, fmt, args);
|
|
dev_printk(KERN_ERR, ab->dev, "%s", str);
|
|
free(str, M_KMALLOC);
|
|
}
|
|
#endif
|
|
/* TODO: Trace the log */
|
|
va_end(args);
|
|
}
|
|
|
|
void ath12k_warn(struct ath12k_base *ab, const char *fmt, ...)
|
|
{
|
|
struct va_format vaf = {
|
|
.fmt = fmt,
|
|
};
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
vaf.va = &args;
|
|
#if defined(__linux__)
|
|
dev_warn_ratelimited(ab->dev, "%pV", &vaf);
|
|
#elif defined(__FreeBSD__)
|
|
{
|
|
static linux_ratelimit_t __ratelimited;
|
|
|
|
if (linux_ratelimited(&__ratelimited)) {
|
|
char *str;
|
|
vasprintf(&str, M_KMALLOC, fmt, args);
|
|
dev_printk(KERN_WARN, ab->dev, "%s", str);
|
|
free(str, M_KMALLOC);
|
|
}
|
|
}
|
|
#endif
|
|
/* TODO: Trace the log */
|
|
va_end(args);
|
|
}
|
|
|
|
#ifdef CONFIG_ATH12K_DEBUG
|
|
|
|
void __ath12k_dbg(struct ath12k_base *ab, enum ath12k_debug_mask mask,
|
|
const char *fmt, ...)
|
|
{
|
|
struct va_format vaf;
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
vaf.fmt = fmt;
|
|
vaf.va = &args;
|
|
|
|
if (ath12k_debug_mask & mask)
|
|
#if defined(__linux__)
|
|
dev_dbg(ab->dev, "%pV", &vaf);
|
|
#elif defined(__FreeBSD__)
|
|
{
|
|
char *str;
|
|
vasprintf(&str, M_KMALLOC, fmt, args);
|
|
dev_printk(KERN_DEBUG, ab->dev, "%s", str);
|
|
free(str, M_KMALLOC);
|
|
}
|
|
#endif
|
|
|
|
/* TODO: trace log */
|
|
|
|
va_end(args);
|
|
}
|
|
|
|
void ath12k_dbg_dump(struct ath12k_base *ab,
|
|
enum ath12k_debug_mask mask,
|
|
const char *msg, const char *prefix,
|
|
const void *buf, size_t len)
|
|
{
|
|
#if defined(__linux__)
|
|
char linebuf[256];
|
|
size_t linebuflen;
|
|
const void *ptr;
|
|
#elif defined(__FreeBSD__)
|
|
struct sbuf *sb;
|
|
int rc;
|
|
#endif
|
|
|
|
if (ath12k_debug_mask & mask) {
|
|
if (msg)
|
|
__ath12k_dbg(ab, mask, "%s\n", msg);
|
|
|
|
#if defined(__linux__)
|
|
for (ptr = buf; (ptr - buf) < len; ptr += 16) {
|
|
linebuflen = 0;
|
|
linebuflen += scnprintf(linebuf + linebuflen,
|
|
sizeof(linebuf) - linebuflen,
|
|
"%s%08x: ",
|
|
(prefix ? prefix : ""),
|
|
(unsigned int)(ptr - buf));
|
|
hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
|
|
linebuf + linebuflen,
|
|
sizeof(linebuf) - linebuflen, true);
|
|
dev_dbg(ab->dev, "%s\n", linebuf);
|
|
}
|
|
#elif defined(__FreeBSD__)
|
|
sb = sbuf_new_auto();
|
|
if (sb == NULL)
|
|
goto trace;
|
|
|
|
sbuf_hexdump(sb, buf, len, prefix, 0);
|
|
sbuf_trim(sb);
|
|
rc = sbuf_finish(sb);
|
|
if (rc == 0)
|
|
dev_printk(KERN_DEBUG, ab->dev, "%s\n", sbuf_data(sb));
|
|
sbuf_delete(sb);
|
|
trace: ;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
#endif /* CONFIG_ATH12K_DEBUG */
|