xref: /freebsd/sys/dev/iavf/iavf_sysctls_common.h (revision 2b8331622f0b212cf3bb4fc4914a501e5321d506)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2021, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*$FreeBSD$*/
32 
33 /**
34  * @file iavf_sysctls_common.h
35  * @brief Sysctls common to the legacy and iflib drivers
36  *
37  * Contains global sysctl definitions which are shared between the legacy and
38  * iflib driver implementations.
39  */
40 #ifndef _IAVF_SYSCTLS_COMMON_H_
41 #define _IAVF_SYSCTLS_COMMON_H_
42 
43 #include <sys/sysctl.h>
44 
45 /* Root node for tunables */
46 static SYSCTL_NODE(_hw, OID_AUTO, iavf, CTLFLAG_RD, 0,
47     "IAVF driver parameters");
48 
49 /**
50  * @var iavf_enable_head_writeback
51  * @brief Sysctl to control Tx descriptor completion method
52  *
53  * Global sysctl value indicating whether to enable the head writeback method
54  * of Tx descriptor completion notification.
55  *
56  * @remark Head writeback has been deprecated and will only work on 700-series
57  * virtual functions only.
58  */
59 static int iavf_enable_head_writeback = 0;
60 SYSCTL_INT(_hw_iavf, OID_AUTO, enable_head_writeback, CTLFLAG_RDTUN,
61     &iavf_enable_head_writeback, 0,
62     "For detecting last completed TX descriptor by hardware, use value written by HW instead of checking descriptors. For 700 series VFs only.");
63 
64 /**
65  * @var iavf_core_debug_mask
66  * @brief Debug mask for driver messages
67  *
68  * Global sysctl value used to control what set of debug messages are printed.
69  * Used by messages in core driver code.
70  */
71 static int iavf_core_debug_mask = 0;
72 SYSCTL_INT(_hw_iavf, OID_AUTO, core_debug_mask, CTLFLAG_RDTUN,
73     &iavf_core_debug_mask, 0,
74     "Display debug statements that are printed in non-shared code");
75 
76 /**
77  * @var iavf_shared_debug_mask
78  * @brief Debug mask for shared code messages
79  *
80  * Global sysctl value used to control what set of debug messages are printed.
81  * Used by messages in shared device logic code.
82  */
83 static int iavf_shared_debug_mask = 0;
84 SYSCTL_INT(_hw_iavf, OID_AUTO, shared_debug_mask, CTLFLAG_RDTUN,
85     &iavf_shared_debug_mask, 0,
86     "Display debug statements that are printed in shared code");
87 
88 /**
89  * @var iavf_rx_itr
90  * @brief Rx interrupt throttling rate
91  *
92  * Controls the default interrupt throttling rate for receive interrupts.
93  */
94 int iavf_rx_itr = IAVF_ITR_8K;
95 SYSCTL_INT(_hw_iavf, OID_AUTO, rx_itr, CTLFLAG_RDTUN,
96     &iavf_rx_itr, 0, "RX Interrupt Rate");
97 
98 /**
99  * @var iavf_tx_itr
100  * @brief Tx interrupt throttling rate
101  *
102  * Controls the default interrupt throttling rate for transmit interrupts.
103  */
104 int iavf_tx_itr = IAVF_ITR_4K;
105 SYSCTL_INT(_hw_iavf, OID_AUTO, tx_itr, CTLFLAG_RDTUN,
106     &iavf_tx_itr, 0, "TX Interrupt Rate");
107 
108 /**
109  * iavf_save_tunables - Sanity check and save off tunable values
110  * @sc: device softc
111  *
112  * @pre "iavf_drv_info.h" is included before this file
113  * @pre dev pointer in sc is valid
114  */
115 static void
116 iavf_save_tunables(struct iavf_sc *sc)
117 {
118 	device_t dev = sc->dev;
119 	u16 pci_device_id = pci_get_device(dev);
120 
121 	/* Save tunable information */
122 	sc->dbg_mask = (enum iavf_dbg_mask)iavf_core_debug_mask;
123 	sc->hw.debug_mask = iavf_shared_debug_mask;
124 
125 	if (pci_device_id == IAVF_DEV_ID_VF ||
126 	    pci_device_id == IAVF_DEV_ID_X722_VF)
127 		sc->vsi.enable_head_writeback = !!(iavf_enable_head_writeback);
128 	else if (iavf_enable_head_writeback) {
129 		device_printf(dev, "Head writeback can only be enabled on 700 series Virtual Functions\n");
130 		device_printf(dev, "Using descriptor writeback instead...\n");
131 		sc->vsi.enable_head_writeback = 0;
132 	}
133 
134 	if (iavf_tx_itr < 0 || iavf_tx_itr > IAVF_MAX_ITR) {
135 		device_printf(dev, "Invalid tx_itr value of %d set!\n",
136 		    iavf_tx_itr);
137 		device_printf(dev, "tx_itr must be between %d and %d, "
138 		    "inclusive\n",
139 		    0, IAVF_MAX_ITR);
140 		device_printf(dev, "Using default value of %d instead\n",
141 		    IAVF_ITR_4K);
142 		sc->tx_itr = IAVF_ITR_4K;
143 	} else
144 		sc->tx_itr = iavf_tx_itr;
145 
146 	if (iavf_rx_itr < 0 || iavf_rx_itr > IAVF_MAX_ITR) {
147 		device_printf(dev, "Invalid rx_itr value of %d set!\n",
148 		    iavf_rx_itr);
149 		device_printf(dev, "rx_itr must be between %d and %d, "
150 		    "inclusive\n",
151 		    0, IAVF_MAX_ITR);
152 		device_printf(dev, "Using default value of %d instead\n",
153 		    IAVF_ITR_8K);
154 		sc->rx_itr = IAVF_ITR_8K;
155 	} else
156 		sc->rx_itr = iavf_rx_itr;
157 }
158 #endif /* _IAVF_SYSCTLS_COMMON_H_ */
159