162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci=============== 462306a36Sopenharmony_ciNETIF Msg Level 562306a36Sopenharmony_ci=============== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciThe design of the network interface message level setting. 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciHistory 1062306a36Sopenharmony_ci------- 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci The design of the debugging message interface was guided and 1362306a36Sopenharmony_ci constrained by backwards compatibility previous practice. It is useful 1462306a36Sopenharmony_ci to understand the history and evolution in order to understand current 1562306a36Sopenharmony_ci practice and relate it to older driver source code. 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci From the beginning of Linux, each network device driver has had a local 1862306a36Sopenharmony_ci integer variable that controls the debug message level. The message 1962306a36Sopenharmony_ci level ranged from 0 to 7, and monotonically increased in verbosity. 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci The message level was not precisely defined past level 3, but were 2262306a36Sopenharmony_ci always implemented within +-1 of the specified level. Drivers tended 2362306a36Sopenharmony_ci to shed the more verbose level messages as they matured. 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci - 0 Minimal messages, only essential information on fatal errors. 2662306a36Sopenharmony_ci - 1 Standard messages, initialization status. No run-time messages 2762306a36Sopenharmony_ci - 2 Special media selection messages, generally timer-driver. 2862306a36Sopenharmony_ci - 3 Interface starts and stops, including normal status messages 2962306a36Sopenharmony_ci - 4 Tx and Rx frame error messages, and abnormal driver operation 3062306a36Sopenharmony_ci - 5 Tx packet queue information, interrupt events. 3162306a36Sopenharmony_ci - 6 Status on each completed Tx packet and received Rx packets 3262306a36Sopenharmony_ci - 7 Initial contents of Tx and Rx packets 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci Initially this message level variable was uniquely named in each driver 3562306a36Sopenharmony_ci e.g. "lance_debug", so that a kernel symbolic debugger could locate and 3662306a36Sopenharmony_ci modify the setting. When kernel modules became common, the variables 3762306a36Sopenharmony_ci were consistently renamed to "debug" and allowed to be set as a module 3862306a36Sopenharmony_ci parameter. 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci This approach worked well. However there is always a demand for 4162306a36Sopenharmony_ci additional features. Over the years the following emerged as 4262306a36Sopenharmony_ci reasonable and easily implemented enhancements 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci - Using an ioctl() call to modify the level. 4562306a36Sopenharmony_ci - Per-interface rather than per-driver message level setting. 4662306a36Sopenharmony_ci - More selective control over the type of messages emitted. 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci The netif_msg recommendation adds these features with only a minor 4962306a36Sopenharmony_ci complexity and code size increase. 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci The recommendation is the following points 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci - Retaining the per-driver integer variable "debug" as a module 5462306a36Sopenharmony_ci parameter with a default level of '1'. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci - Adding a per-interface private variable named "msg_enable". The 5762306a36Sopenharmony_ci variable is a bit map rather than a level, and is initialized as:: 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci 1 << debug 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci Or more precisely:: 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci debug < 0 ? 0 : 1 << min(sizeof(int)-1, debug) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci Messages should changes from:: 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci if (debug > 1) 6862306a36Sopenharmony_ci printk(MSG_DEBUG "%s: ... 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci to:: 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci if (np->msg_enable & NETIF_MSG_LINK) 7362306a36Sopenharmony_ci printk(MSG_DEBUG "%s: ... 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ciThe set of message levels is named 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci ========= =================== ============ 8062306a36Sopenharmony_ci Old level Name Bit position 8162306a36Sopenharmony_ci ========= =================== ============ 8262306a36Sopenharmony_ci 0 NETIF_MSG_DRV 0x0001 8362306a36Sopenharmony_ci 1 NETIF_MSG_PROBE 0x0002 8462306a36Sopenharmony_ci 2 NETIF_MSG_LINK 0x0004 8562306a36Sopenharmony_ci 2 NETIF_MSG_TIMER 0x0004 8662306a36Sopenharmony_ci 3 NETIF_MSG_IFDOWN 0x0008 8762306a36Sopenharmony_ci 3 NETIF_MSG_IFUP 0x0008 8862306a36Sopenharmony_ci 4 NETIF_MSG_RX_ERR 0x0010 8962306a36Sopenharmony_ci 4 NETIF_MSG_TX_ERR 0x0010 9062306a36Sopenharmony_ci 5 NETIF_MSG_TX_QUEUED 0x0020 9162306a36Sopenharmony_ci 5 NETIF_MSG_INTR 0x0020 9262306a36Sopenharmony_ci 6 NETIF_MSG_TX_DONE 0x0040 9362306a36Sopenharmony_ci 6 NETIF_MSG_RX_STATUS 0x0040 9462306a36Sopenharmony_ci 7 NETIF_MSG_PKTDATA 0x0080 9562306a36Sopenharmony_ci ========= =================== ============ 96