18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright (C) 2007-2020 B.A.T.M.A.N. contributors: 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Marek Lindner, Simon Wunderlich 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef _NET_BATMAN_ADV_LOG_H_ 88c2ecf20Sopenharmony_ci#define _NET_BATMAN_ADV_LOG_H_ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include "main.h" 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/atomic.h> 138c2ecf20Sopenharmony_ci#include <linux/bitops.h> 148c2ecf20Sopenharmony_ci#include <linux/compiler.h> 158c2ecf20Sopenharmony_ci#include <linux/printk.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#ifdef CONFIG_BATMAN_ADV_DEBUG 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciint batadv_debug_log_setup(struct batadv_priv *bat_priv); 208c2ecf20Sopenharmony_civoid batadv_debug_log_cleanup(struct batadv_priv *bat_priv); 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#else 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic inline int batadv_debug_log_setup(struct batadv_priv *bat_priv) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci return 0; 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#endif 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/** 368c2ecf20Sopenharmony_ci * enum batadv_dbg_level - available log levels 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_cienum batadv_dbg_level { 398c2ecf20Sopenharmony_ci /** @BATADV_DBG_BATMAN: OGM and TQ computations related messages */ 408c2ecf20Sopenharmony_ci BATADV_DBG_BATMAN = BIT(0), 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci /** @BATADV_DBG_ROUTES: route added / changed / deleted */ 438c2ecf20Sopenharmony_ci BATADV_DBG_ROUTES = BIT(1), 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci /** @BATADV_DBG_TT: translation table messages */ 468c2ecf20Sopenharmony_ci BATADV_DBG_TT = BIT(2), 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci /** @BATADV_DBG_BLA: bridge loop avoidance messages */ 498c2ecf20Sopenharmony_ci BATADV_DBG_BLA = BIT(3), 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci /** @BATADV_DBG_DAT: ARP snooping and DAT related messages */ 528c2ecf20Sopenharmony_ci BATADV_DBG_DAT = BIT(4), 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci /** @BATADV_DBG_NC: network coding related messages */ 558c2ecf20Sopenharmony_ci BATADV_DBG_NC = BIT(5), 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci /** @BATADV_DBG_MCAST: multicast related messages */ 588c2ecf20Sopenharmony_ci BATADV_DBG_MCAST = BIT(6), 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci /** @BATADV_DBG_TP_METER: throughput meter messages */ 618c2ecf20Sopenharmony_ci BATADV_DBG_TP_METER = BIT(7), 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci /** @BATADV_DBG_ALL: the union of all the above log levels */ 648c2ecf20Sopenharmony_ci BATADV_DBG_ALL = 255, 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#ifdef CONFIG_BATMAN_ADV_DEBUG 688c2ecf20Sopenharmony_ciint batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...) 698c2ecf20Sopenharmony_ci__printf(2, 3); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/** 728c2ecf20Sopenharmony_ci * _batadv_dbg() - Store debug output with(out) rate limiting 738c2ecf20Sopenharmony_ci * @type: type of debug message 748c2ecf20Sopenharmony_ci * @bat_priv: the bat priv with all the soft interface information 758c2ecf20Sopenharmony_ci * @ratelimited: whether output should be rate limited 768c2ecf20Sopenharmony_ci * @fmt: format string 778c2ecf20Sopenharmony_ci * @arg: variable arguments 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_ci#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \ 808c2ecf20Sopenharmony_ci do { \ 818c2ecf20Sopenharmony_ci struct batadv_priv *__batpriv = (bat_priv); \ 828c2ecf20Sopenharmony_ci if (atomic_read(&__batpriv->log_level) & (type) && \ 838c2ecf20Sopenharmony_ci (!(ratelimited) || net_ratelimit())) \ 848c2ecf20Sopenharmony_ci batadv_debug_log(__batpriv, fmt, ## arg); \ 858c2ecf20Sopenharmony_ci } \ 868c2ecf20Sopenharmony_ci while (0) 878c2ecf20Sopenharmony_ci#else /* !CONFIG_BATMAN_ADV_DEBUG */ 888c2ecf20Sopenharmony_ci__printf(4, 5) 898c2ecf20Sopenharmony_cistatic inline void _batadv_dbg(int type __always_unused, 908c2ecf20Sopenharmony_ci struct batadv_priv *bat_priv __always_unused, 918c2ecf20Sopenharmony_ci int ratelimited __always_unused, 928c2ecf20Sopenharmony_ci const char *fmt __always_unused, ...) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci#endif 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/** 988c2ecf20Sopenharmony_ci * batadv_dbg() - Store debug output without rate limiting 998c2ecf20Sopenharmony_ci * @type: type of debug message 1008c2ecf20Sopenharmony_ci * @bat_priv: the bat priv with all the soft interface information 1018c2ecf20Sopenharmony_ci * @arg: format string and variable arguments 1028c2ecf20Sopenharmony_ci */ 1038c2ecf20Sopenharmony_ci#define batadv_dbg(type, bat_priv, arg...) \ 1048c2ecf20Sopenharmony_ci _batadv_dbg(type, bat_priv, 0, ## arg) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/** 1078c2ecf20Sopenharmony_ci * batadv_dbg_ratelimited() - Store debug output with rate limiting 1088c2ecf20Sopenharmony_ci * @type: type of debug message 1098c2ecf20Sopenharmony_ci * @bat_priv: the bat priv with all the soft interface information 1108c2ecf20Sopenharmony_ci * @arg: format string and variable arguments 1118c2ecf20Sopenharmony_ci */ 1128c2ecf20Sopenharmony_ci#define batadv_dbg_ratelimited(type, bat_priv, arg...) \ 1138c2ecf20Sopenharmony_ci _batadv_dbg(type, bat_priv, 1, ## arg) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/** 1168c2ecf20Sopenharmony_ci * batadv_info() - Store message in debug buffer and print it to kmsg buffer 1178c2ecf20Sopenharmony_ci * @net_dev: the soft interface net device 1188c2ecf20Sopenharmony_ci * @fmt: format string 1198c2ecf20Sopenharmony_ci * @arg: variable arguments 1208c2ecf20Sopenharmony_ci */ 1218c2ecf20Sopenharmony_ci#define batadv_info(net_dev, fmt, arg...) \ 1228c2ecf20Sopenharmony_ci do { \ 1238c2ecf20Sopenharmony_ci struct net_device *_netdev = (net_dev); \ 1248c2ecf20Sopenharmony_ci struct batadv_priv *_batpriv = netdev_priv(_netdev); \ 1258c2ecf20Sopenharmony_ci batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ 1268c2ecf20Sopenharmony_ci pr_info("%s: " fmt, _netdev->name, ## arg); \ 1278c2ecf20Sopenharmony_ci } while (0) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/** 1308c2ecf20Sopenharmony_ci * batadv_err() - Store error in debug buffer and print it to kmsg buffer 1318c2ecf20Sopenharmony_ci * @net_dev: the soft interface net device 1328c2ecf20Sopenharmony_ci * @fmt: format string 1338c2ecf20Sopenharmony_ci * @arg: variable arguments 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_ci#define batadv_err(net_dev, fmt, arg...) \ 1368c2ecf20Sopenharmony_ci do { \ 1378c2ecf20Sopenharmony_ci struct net_device *_netdev = (net_dev); \ 1388c2ecf20Sopenharmony_ci struct batadv_priv *_batpriv = netdev_priv(_netdev); \ 1398c2ecf20Sopenharmony_ci batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ 1408c2ecf20Sopenharmony_ci pr_err("%s: " fmt, _netdev->name, ## arg); \ 1418c2ecf20Sopenharmony_ci } while (0) 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci#endif /* _NET_BATMAN_ADV_LOG_H_ */ 144