Path: blob/main/sys/contrib/dev/iwlwifi/iwl-debug.c
105417 views
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause1/*2* Copyright (C) 2005-2011, 2021-2022 Intel Corporation3*/4#include <linux/device.h>5#include <linux/interrupt.h>6#include <linux/export.h>7#if defined(CONFIG_IWLWIFI_DEBUG)8#include <linux/net.h>9#endif10#include "iwl-drv.h"11#include "iwl-debug.h"12#if defined(__FreeBSD__)13#include "iwl-modparams.h"14#endif15#include "iwl-devtrace.h"1617#if defined(__FreeBSD__)18#if defined(CONFIG_IWLWIFI_DEBUG)19#include <sys/systm.h> /* hexdump(9) */20#include <linux/preempt.h>21#endif22#endif2324#if defined(__linux__)25#define __iwl_fn(fn) \26void __iwl_ ##fn(struct device *dev, const char *fmt, ...) \27{ \28struct va_format vaf = { \29.fmt = fmt, \30}; \31va_list args; \32\33va_start(args, fmt); \34vaf.va = &args; \35dev_ ##fn(dev, "%pV", &vaf); \36trace_iwlwifi_ ##fn(&vaf); \37va_end(args); \38}39#elif defined(__FreeBSD__)40#define __iwl_fn(fn) \41void __iwl_ ##fn(struct device *dev, const char *fmt, ...) \42{ \43struct va_format vaf = { \44.fmt = fmt, \45}; \46va_list args; \47char *str; \48\49va_start(args, fmt); \50vaf.va = &args; \51vasprintf(&str, M_KMALLOC, vaf.fmt, args); \52dev_ ##fn(dev, "%s", str); \53trace_iwlwifi_ ##fn(&vaf); \54free(str, M_KMALLOC); \55va_end(args); \56}57#endif5859__iwl_fn(warn)60IWL_EXPORT_SYMBOL(__iwl_warn);61__iwl_fn(info)62IWL_EXPORT_SYMBOL(__iwl_info);63__iwl_fn(crit)64IWL_EXPORT_SYMBOL(__iwl_crit);6566void __iwl_err(struct device *dev, enum iwl_err_mode mode, const char *fmt, ...)67{68struct va_format vaf = {69.fmt = fmt,70};71va_list args, args2;7273va_start(args, fmt);74switch (mode) {75case IWL_ERR_MODE_RATELIMIT:76if (net_ratelimit())77break;78fallthrough;79case IWL_ERR_MODE_REGULAR:80case IWL_ERR_MODE_RFKILL:81va_copy(args2, args);82vaf.va = &args2;83#if defined(__linux_)84if (mode == IWL_ERR_MODE_RFKILL)85dev_err(dev, "(RFKILL) %pV", &vaf);86else87dev_err(dev, "%pV", &vaf);88#elif defined(__FreeBSD__)89char *str;90vasprintf(&str, M_KMALLOC, vaf.fmt, args2);91dev_err(dev, "%s%s", (mode == IWL_ERR_MODE_RFKILL) ? "(RFKILL)" : "", str);92free(str, M_KMALLOC);93#endif94va_end(args2);95break;96default:97break;98}99vaf.va = &args;100trace_iwlwifi_err(&vaf);101va_end(args);102}103IWL_EXPORT_SYMBOL(__iwl_err);104105#if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWLWIFI_DEVICE_TRACING)106107#ifdef CONFIG_IWLWIFI_DEBUG108bool109iwl_have_debug_level(enum iwl_dl level)110{111112return (iwlwifi_mod_params.debug_level & level || level == IWL_DL_ANY);113}114115/* Passing the iwl_drv * in seems pointless. */116void117iwl_print_hex_dump(void *drv __unused, enum iwl_dl level,118#if defined(__linux__)119const char *prefix, uint8_t *data, size_t len)120#elif defined(__FreeBSD__)121const char *prefix, const uint8_t *data, size_t len)122#endif123{124125/* Given we have a level, check for it. */126if (!iwl_have_debug_level(level))127return;128129#if defined(__linux_)130/* XXX I am cluseless in my editor. pcie/trans.c to the rescue. */131print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET,13232, 4, data, len, 0);133#elif defined(__FreeBSD__)134hexdump(data, len, prefix, 0);135#endif136}137#endif138139void __iwl_dbg(struct device *dev,140u32 level, bool limit, const char *function,141const char *fmt, ...)142{143struct va_format vaf = {144.fmt = fmt,145};146va_list args;147148va_start(args, fmt);149vaf.va = &args;150#ifdef CONFIG_IWLWIFI_DEBUG151if (iwl_have_debug_level(level) &&152(!limit || net_ratelimit()))153#if defined(__linux_)154dev_printk(KERN_DEBUG, dev, "%s %pV", function, &vaf);155#elif defined(__FreeBSD__)156{157char *str;158vasprintf(&str, M_KMALLOC, vaf.fmt, args);159dev_printk(KERN_DEBUG, dev, "%d %u %s %s",160curthread->td_tid, (unsigned int)ticks, function, str);161free(str, M_KMALLOC);162}163#endif164165#endif166trace_iwlwifi_dbg(level, function, &vaf);167va_end(args);168}169IWL_EXPORT_SYMBOL(__iwl_dbg);170#endif171172173