/* 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_MCAST: multicast related messages */54BATADV_DBG_MCAST = BIT(6),5556/** @BATADV_DBG_TP_METER: throughput meter messages */57BATADV_DBG_TP_METER = BIT(7),5859/** @BATADV_DBG_ALL: the union of all the above log levels */60BATADV_DBG_ALL = 255,61};6263#ifdef CONFIG_BATMAN_ADV_DEBUG64int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)65__printf(2, 3);6667/**68* _batadv_dbg() - Store debug output with(out) rate limiting69* @type: type of debug message70* @bat_priv: the bat priv with all the mesh interface information71* @ratelimited: whether output should be rate limited72* @fmt: format string73* @arg: variable arguments74*/75#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \76do { \77struct batadv_priv *__batpriv = (bat_priv); \78if (atomic_read(&__batpriv->log_level) & (type) && \79(!(ratelimited) || net_ratelimit())) \80batadv_debug_log(__batpriv, fmt, ## arg); \81} \82while (0)83#else /* !CONFIG_BATMAN_ADV_DEBUG */84__printf(4, 5)85static inline void _batadv_dbg(int type __always_unused,86struct batadv_priv *bat_priv __always_unused,87int ratelimited __always_unused,88const char *fmt __always_unused, ...)89{90}91#endif9293/**94* batadv_dbg() - Store debug output without rate limiting95* @type: type of debug message96* @bat_priv: the bat priv with all the mesh interface information97* @arg: format string and variable arguments98*/99#define batadv_dbg(type, bat_priv, arg...) \100_batadv_dbg(type, bat_priv, 0, ## arg)101102/**103* batadv_dbg_ratelimited() - Store debug output with rate limiting104* @type: type of debug message105* @bat_priv: the bat priv with all the mesh interface information106* @arg: format string and variable arguments107*/108#define batadv_dbg_ratelimited(type, bat_priv, arg...) \109_batadv_dbg(type, bat_priv, 1, ## arg)110111/**112* batadv_info() - Store message in debug buffer and print it to kmsg buffer113* @net_dev: the mesh interface net device114* @fmt: format string115* @arg: variable arguments116*/117#define batadv_info(net_dev, fmt, arg...) \118do { \119struct net_device *_netdev = (net_dev); \120struct batadv_priv *_batpriv = netdev_priv(_netdev); \121batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \122pr_info("%s: " fmt, _netdev->name, ## arg); \123} while (0)124125/**126* batadv_err() - Store error in debug buffer and print it to kmsg buffer127* @net_dev: the mesh interface net device128* @fmt: format string129* @arg: variable arguments130*/131#define batadv_err(net_dev, fmt, arg...) \132do { \133struct net_device *_netdev = (net_dev); \134struct batadv_priv *_batpriv = netdev_priv(_netdev); \135batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \136pr_err("%s: " fmt, _netdev->name, ## arg); \137} while (0)138139#endif /* _NET_BATMAN_ADV_LOG_H_ */140141142