1*c4d5dff6SMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0 2*c4d5dff6SMauro Carvalho Chehab 3*c4d5dff6SMauro Carvalho Chehab=============== 4*c4d5dff6SMauro Carvalho ChehabNETIF Msg Level 5*c4d5dff6SMauro Carvalho Chehab=============== 6*c4d5dff6SMauro Carvalho Chehab 7*c4d5dff6SMauro Carvalho ChehabThe design of the network interface message level setting. 8*c4d5dff6SMauro Carvalho Chehab 9*c4d5dff6SMauro Carvalho ChehabHistory 10*c4d5dff6SMauro Carvalho Chehab------- 11*c4d5dff6SMauro Carvalho Chehab 12*c4d5dff6SMauro Carvalho Chehab The design of the debugging message interface was guided and 13*c4d5dff6SMauro Carvalho Chehab constrained by backwards compatibility previous practice. It is useful 14*c4d5dff6SMauro Carvalho Chehab to understand the history and evolution in order to understand current 15*c4d5dff6SMauro Carvalho Chehab practice and relate it to older driver source code. 16*c4d5dff6SMauro Carvalho Chehab 17*c4d5dff6SMauro Carvalho Chehab From the beginning of Linux, each network device driver has had a local 18*c4d5dff6SMauro Carvalho Chehab integer variable that controls the debug message level. The message 19*c4d5dff6SMauro Carvalho Chehab level ranged from 0 to 7, and monotonically increased in verbosity. 20*c4d5dff6SMauro Carvalho Chehab 21*c4d5dff6SMauro Carvalho Chehab The message level was not precisely defined past level 3, but were 22*c4d5dff6SMauro Carvalho Chehab always implemented within +-1 of the specified level. Drivers tended 23*c4d5dff6SMauro Carvalho Chehab to shed the more verbose level messages as they matured. 24*c4d5dff6SMauro Carvalho Chehab 25*c4d5dff6SMauro Carvalho Chehab - 0 Minimal messages, only essential information on fatal errors. 26*c4d5dff6SMauro Carvalho Chehab - 1 Standard messages, initialization status. No run-time messages 27*c4d5dff6SMauro Carvalho Chehab - 2 Special media selection messages, generally timer-driver. 28*c4d5dff6SMauro Carvalho Chehab - 3 Interface starts and stops, including normal status messages 29*c4d5dff6SMauro Carvalho Chehab - 4 Tx and Rx frame error messages, and abnormal driver operation 30*c4d5dff6SMauro Carvalho Chehab - 5 Tx packet queue information, interrupt events. 31*c4d5dff6SMauro Carvalho Chehab - 6 Status on each completed Tx packet and received Rx packets 32*c4d5dff6SMauro Carvalho Chehab - 7 Initial contents of Tx and Rx packets 33*c4d5dff6SMauro Carvalho Chehab 34*c4d5dff6SMauro Carvalho Chehab Initially this message level variable was uniquely named in each driver 35*c4d5dff6SMauro Carvalho Chehab e.g. "lance_debug", so that a kernel symbolic debugger could locate and 36*c4d5dff6SMauro Carvalho Chehab modify the setting. When kernel modules became common, the variables 37*c4d5dff6SMauro Carvalho Chehab were consistently renamed to "debug" and allowed to be set as a module 38*c4d5dff6SMauro Carvalho Chehab parameter. 39*c4d5dff6SMauro Carvalho Chehab 40*c4d5dff6SMauro Carvalho Chehab This approach worked well. However there is always a demand for 41*c4d5dff6SMauro Carvalho Chehab additional features. Over the years the following emerged as 42*c4d5dff6SMauro Carvalho Chehab reasonable and easily implemented enhancements 43*c4d5dff6SMauro Carvalho Chehab 44*c4d5dff6SMauro Carvalho Chehab - Using an ioctl() call to modify the level. 45*c4d5dff6SMauro Carvalho Chehab - Per-interface rather than per-driver message level setting. 46*c4d5dff6SMauro Carvalho Chehab - More selective control over the type of messages emitted. 47*c4d5dff6SMauro Carvalho Chehab 48*c4d5dff6SMauro Carvalho Chehab The netif_msg recommendation adds these features with only a minor 49*c4d5dff6SMauro Carvalho Chehab complexity and code size increase. 50*c4d5dff6SMauro Carvalho Chehab 51*c4d5dff6SMauro Carvalho Chehab The recommendation is the following points 52*c4d5dff6SMauro Carvalho Chehab 53*c4d5dff6SMauro Carvalho Chehab - Retaining the per-driver integer variable "debug" as a module 54*c4d5dff6SMauro Carvalho Chehab parameter with a default level of '1'. 55*c4d5dff6SMauro Carvalho Chehab 56*c4d5dff6SMauro Carvalho Chehab - Adding a per-interface private variable named "msg_enable". The 57*c4d5dff6SMauro Carvalho Chehab variable is a bit map rather than a level, and is initialized as:: 58*c4d5dff6SMauro Carvalho Chehab 59*c4d5dff6SMauro Carvalho Chehab 1 << debug 60*c4d5dff6SMauro Carvalho Chehab 61*c4d5dff6SMauro Carvalho Chehab Or more precisely:: 62*c4d5dff6SMauro Carvalho Chehab 63*c4d5dff6SMauro Carvalho Chehab debug < 0 ? 0 : 1 << min(sizeof(int)-1, debug) 64*c4d5dff6SMauro Carvalho Chehab 65*c4d5dff6SMauro Carvalho Chehab Messages should changes from:: 66*c4d5dff6SMauro Carvalho Chehab 67*c4d5dff6SMauro Carvalho Chehab if (debug > 1) 68*c4d5dff6SMauro Carvalho Chehab printk(MSG_DEBUG "%s: ... 69*c4d5dff6SMauro Carvalho Chehab 70*c4d5dff6SMauro Carvalho Chehab to:: 71*c4d5dff6SMauro Carvalho Chehab 72*c4d5dff6SMauro Carvalho Chehab if (np->msg_enable & NETIF_MSG_LINK) 73*c4d5dff6SMauro Carvalho Chehab printk(MSG_DEBUG "%s: ... 74*c4d5dff6SMauro Carvalho Chehab 75*c4d5dff6SMauro Carvalho Chehab 76*c4d5dff6SMauro Carvalho ChehabThe set of message levels is named 77*c4d5dff6SMauro Carvalho Chehab 78*c4d5dff6SMauro Carvalho Chehab 79*c4d5dff6SMauro Carvalho Chehab ========= =================== ============ 80*c4d5dff6SMauro Carvalho Chehab Old level Name Bit position 81*c4d5dff6SMauro Carvalho Chehab ========= =================== ============ 82*c4d5dff6SMauro Carvalho Chehab 0 NETIF_MSG_DRV 0x0001 83*c4d5dff6SMauro Carvalho Chehab 1 NETIF_MSG_PROBE 0x0002 84*c4d5dff6SMauro Carvalho Chehab 2 NETIF_MSG_LINK 0x0004 85*c4d5dff6SMauro Carvalho Chehab 2 NETIF_MSG_TIMER 0x0004 86*c4d5dff6SMauro Carvalho Chehab 3 NETIF_MSG_IFDOWN 0x0008 87*c4d5dff6SMauro Carvalho Chehab 3 NETIF_MSG_IFUP 0x0008 88*c4d5dff6SMauro Carvalho Chehab 4 NETIF_MSG_RX_ERR 0x0010 89*c4d5dff6SMauro Carvalho Chehab 4 NETIF_MSG_TX_ERR 0x0010 90*c4d5dff6SMauro Carvalho Chehab 5 NETIF_MSG_TX_QUEUED 0x0020 91*c4d5dff6SMauro Carvalho Chehab 5 NETIF_MSG_INTR 0x0020 92*c4d5dff6SMauro Carvalho Chehab 6 NETIF_MSG_TX_DONE 0x0040 93*c4d5dff6SMauro Carvalho Chehab 6 NETIF_MSG_RX_STATUS 0x0040 94*c4d5dff6SMauro Carvalho Chehab 7 NETIF_MSG_PKTDATA 0x0080 95*c4d5dff6SMauro Carvalho Chehab ========= =================== ============ 96