18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci=============== 48c2ecf20Sopenharmony_ciNETIF Msg Level 58c2ecf20Sopenharmony_ci=============== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciThe design of the network interface message level setting. 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciHistory 108c2ecf20Sopenharmony_ci------- 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci The design of the debugging message interface was guided and 138c2ecf20Sopenharmony_ci constrained by backwards compatibility previous practice. It is useful 148c2ecf20Sopenharmony_ci to understand the history and evolution in order to understand current 158c2ecf20Sopenharmony_ci practice and relate it to older driver source code. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci From the beginning of Linux, each network device driver has had a local 188c2ecf20Sopenharmony_ci integer variable that controls the debug message level. The message 198c2ecf20Sopenharmony_ci level ranged from 0 to 7, and monotonically increased in verbosity. 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci The message level was not precisely defined past level 3, but were 228c2ecf20Sopenharmony_ci always implemented within +-1 of the specified level. Drivers tended 238c2ecf20Sopenharmony_ci to shed the more verbose level messages as they matured. 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci - 0 Minimal messages, only essential information on fatal errors. 268c2ecf20Sopenharmony_ci - 1 Standard messages, initialization status. No run-time messages 278c2ecf20Sopenharmony_ci - 2 Special media selection messages, generally timer-driver. 288c2ecf20Sopenharmony_ci - 3 Interface starts and stops, including normal status messages 298c2ecf20Sopenharmony_ci - 4 Tx and Rx frame error messages, and abnormal driver operation 308c2ecf20Sopenharmony_ci - 5 Tx packet queue information, interrupt events. 318c2ecf20Sopenharmony_ci - 6 Status on each completed Tx packet and received Rx packets 328c2ecf20Sopenharmony_ci - 7 Initial contents of Tx and Rx packets 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci Initially this message level variable was uniquely named in each driver 358c2ecf20Sopenharmony_ci e.g. "lance_debug", so that a kernel symbolic debugger could locate and 368c2ecf20Sopenharmony_ci modify the setting. When kernel modules became common, the variables 378c2ecf20Sopenharmony_ci were consistently renamed to "debug" and allowed to be set as a module 388c2ecf20Sopenharmony_ci parameter. 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci This approach worked well. However there is always a demand for 418c2ecf20Sopenharmony_ci additional features. Over the years the following emerged as 428c2ecf20Sopenharmony_ci reasonable and easily implemented enhancements 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci - Using an ioctl() call to modify the level. 458c2ecf20Sopenharmony_ci - Per-interface rather than per-driver message level setting. 468c2ecf20Sopenharmony_ci - More selective control over the type of messages emitted. 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci The netif_msg recommendation adds these features with only a minor 498c2ecf20Sopenharmony_ci complexity and code size increase. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci The recommendation is the following points 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci - Retaining the per-driver integer variable "debug" as a module 548c2ecf20Sopenharmony_ci parameter with a default level of '1'. 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci - Adding a per-interface private variable named "msg_enable". The 578c2ecf20Sopenharmony_ci variable is a bit map rather than a level, and is initialized as:: 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci 1 << debug 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci Or more precisely:: 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci debug < 0 ? 0 : 1 << min(sizeof(int)-1, debug) 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci Messages should changes from:: 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci if (debug > 1) 688c2ecf20Sopenharmony_ci printk(MSG_DEBUG "%s: ... 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci to:: 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci if (np->msg_enable & NETIF_MSG_LINK) 738c2ecf20Sopenharmony_ci printk(MSG_DEBUG "%s: ... 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ciThe set of message levels is named 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci ========= =================== ============ 808c2ecf20Sopenharmony_ci Old level Name Bit position 818c2ecf20Sopenharmony_ci ========= =================== ============ 828c2ecf20Sopenharmony_ci 0 NETIF_MSG_DRV 0x0001 838c2ecf20Sopenharmony_ci 1 NETIF_MSG_PROBE 0x0002 848c2ecf20Sopenharmony_ci 2 NETIF_MSG_LINK 0x0004 858c2ecf20Sopenharmony_ci 2 NETIF_MSG_TIMER 0x0004 868c2ecf20Sopenharmony_ci 3 NETIF_MSG_IFDOWN 0x0008 878c2ecf20Sopenharmony_ci 3 NETIF_MSG_IFUP 0x0008 888c2ecf20Sopenharmony_ci 4 NETIF_MSG_RX_ERR 0x0010 898c2ecf20Sopenharmony_ci 4 NETIF_MSG_TX_ERR 0x0010 908c2ecf20Sopenharmony_ci 5 NETIF_MSG_TX_QUEUED 0x0020 918c2ecf20Sopenharmony_ci 5 NETIF_MSG_INTR 0x0020 928c2ecf20Sopenharmony_ci 6 NETIF_MSG_TX_DONE 0x0040 938c2ecf20Sopenharmony_ci 6 NETIF_MSG_RX_STATUS 0x0040 948c2ecf20Sopenharmony_ci 7 NETIF_MSG_PKTDATA 0x0080 958c2ecf20Sopenharmony_ci ========= =================== ============ 96