/* SPDX-License-Identifier: GPL-2.0 */1/* Copyright (C) B.A.T.M.A.N. contributors:2*3* Marek Lindner, Simon Wunderlich4*/56#ifndef _NET_BATMAN_ADV_LOG_H_7#define _NET_BATMAN_ADV_LOG_H_89#include "main.h"1011#include <linux/atomic.h>12#include <linux/bitops.h>13#include <linux/compiler.h>14#include <linux/printk.h>1516#ifdef CONFIG_BATMAN_ADV_DEBUG1718int batadv_debug_log_setup(struct batadv_priv *bat_priv);19void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);2021#else2223static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)24{25return 0;26}2728static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)29{30}3132#endif3334/**35* enum batadv_dbg_level - available log levels36*/37enum batadv_dbg_level {38/** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */39BATADV_DBG_BATMAN = BIT(0),4041/** @BATADV_DBG_ROUTES: route added / changed / deleted */42BATADV_DBG_ROUTES = BIT(1),4344/** @BATADV_DBG_TT: translation table messages */45BATADV_DBG_TT = BIT(2),4647/** @BATADV_DBG_BLA: bridge loop avoidance messages */48BATADV_DBG_BLA = BIT(3),4950/** @BATADV_DBG_DAT: ARP snooping and DAT related messages */51BATADV_DBG_DAT = BIT(4),5253/** @BATADV_DBG_NC: network coding related messages */54BATADV_DBG_NC = BIT(5),5556/** @BATADV_DBG_MCAST: multicast related messages */57BATADV_DBG_MCAST = BIT(6),5859/** @BATADV_DBG_TP_METER: throughput meter messages */60BATADV_DBG_TP_METER = BIT(7),6162/** @BATADV_DBG_ALL: the union of all the above log levels */63BATADV_DBG_ALL = 255,64};6566#ifdef CONFIG_BATMAN_ADV_DEBUG67int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)68__printf(2, 3);6970/**71* _batadv_dbg() - Store debug output with(out) rate limiting72* @type: type of debug message73* @bat_priv: the bat priv with all the mesh interface information74* @ratelimited: whether output should be rate limited75* @fmt: format string76* @arg: variable arguments77*/78#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \79do { \80struct batadv_priv *__batpriv = (bat_priv); \81if (atomic_read(&__batpriv->log_level) & (type) && \82(!(ratelimited) || net_ratelimit())) \83batadv_debug_log(__batpriv, fmt, ## arg); \84} \85while (0)86#else /* !CONFIG_BATMAN_ADV_DEBUG */87__printf(4, 5)88static inline void _batadv_dbg(int type __always_unused,89struct batadv_priv *bat_priv __always_unused,90int ratelimited __always_unused,91const char *fmt __always_unused, ...)92{93}94#endif9596/**97* batadv_dbg() - Store debug output without rate limiting98* @type: type of debug message99* @bat_priv: the bat priv with all the mesh interface information100* @arg: format string and variable arguments101*/102#define batadv_dbg(type, bat_priv, arg...) \103_batadv_dbg(type, bat_priv, 0, ## arg)104105/**106* batadv_dbg_ratelimited() - Store debug output with rate limiting107* @type: type of debug message108* @bat_priv: the bat priv with all the mesh interface information109* @arg: format string and variable arguments110*/111#define batadv_dbg_ratelimited(type, bat_priv, arg...) \112_batadv_dbg(type, bat_priv, 1, ## arg)113114/**115* batadv_info() - Store message in debug buffer and print it to kmsg buffer116* @net_dev: the mesh interface net device117* @fmt: format string118* @arg: variable arguments119*/120#define batadv_info(net_dev, fmt, arg...) \121do { \122struct net_device *_netdev = (net_dev); \123struct batadv_priv *_batpriv = netdev_priv(_netdev); \124batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \125pr_info("%s: " fmt, _netdev->name, ## arg); \126} while (0)127128/**129* batadv_err() - Store error in debug buffer and print it to kmsg buffer130* @net_dev: the mesh interface net device131* @fmt: format string132* @arg: variable arguments133*/134#define batadv_err(net_dev, fmt, arg...) \135do { \136struct net_device *_netdev = (net_dev); \137struct batadv_priv *_batpriv = netdev_priv(_netdev); \138batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \139pr_err("%s: " fmt, _netdev->name, ## arg); \140} while (0)141142#endif /* _NET_BATMAN_ADV_LOG_H_ */143144145