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
32 /**
33 * @file iavf_sysctls_common.h
34 * @brief Sysctls common to the legacy and iflib drivers
35 *
36 * Contains global sysctl definitions which are shared between the legacy and
37 * iflib driver implementations.
38 */
39 #ifndef _IAVF_SYSCTLS_COMMON_H_
40 #define _IAVF_SYSCTLS_COMMON_H_
41
42 #include <sys/sysctl.h>
43
44 /* Root node for tunables */
45 static SYSCTL_NODE(_hw, OID_AUTO, iavf, CTLFLAG_RD, 0,
46 "IAVF driver parameters");
47
48 /**
49 * @var iavf_enable_head_writeback
50 * @brief Sysctl to control Tx descriptor completion method
51 *
52 * Global sysctl value indicating whether to enable the head writeback method
53 * of Tx descriptor completion notification.
54 *
55 * @remark Head writeback has been deprecated and will only work on 700-series
56 * virtual functions only.
57 */
58 static int iavf_enable_head_writeback = 0;
59 SYSCTL_INT(_hw_iavf, OID_AUTO, enable_head_writeback, CTLFLAG_RDTUN,
60 &iavf_enable_head_writeback, 0,
61 "For detecting last completed TX descriptor by hardware, use value written by HW instead of checking descriptors. For 700 series VFs only.");
62
63 /**
64 * @var iavf_core_debug_mask
65 * @brief Debug mask for driver messages
66 *
67 * Global sysctl value used to control what set of debug messages are printed.
68 * Used by messages in core driver code.
69 */
70 static int iavf_core_debug_mask = 0;
71 SYSCTL_INT(_hw_iavf, OID_AUTO, core_debug_mask, CTLFLAG_RDTUN,
72 &iavf_core_debug_mask, 0,
73 "Display debug statements that are printed in non-shared code");
74
75 /**
76 * @var iavf_shared_debug_mask
77 * @brief Debug mask for shared code messages
78 *
79 * Global sysctl value used to control what set of debug messages are printed.
80 * Used by messages in shared device logic code.
81 */
82 static int iavf_shared_debug_mask = 0;
83 SYSCTL_INT(_hw_iavf, OID_AUTO, shared_debug_mask, CTLFLAG_RDTUN,
84 &iavf_shared_debug_mask, 0,
85 "Display debug statements that are printed in shared code");
86
87 /**
88 * @var iavf_rx_itr
89 * @brief Rx interrupt throttling rate
90 *
91 * Controls the default interrupt throttling rate for receive interrupts.
92 */
93 int iavf_rx_itr = IAVF_ITR_8K;
94 SYSCTL_INT(_hw_iavf, OID_AUTO, rx_itr, CTLFLAG_RDTUN,
95 &iavf_rx_itr, 0, "RX Interrupt Rate");
96
97 /**
98 * @var iavf_tx_itr
99 * @brief Tx interrupt throttling rate
100 *
101 * Controls the default interrupt throttling rate for transmit interrupts.
102 */
103 int iavf_tx_itr = IAVF_ITR_4K;
104 SYSCTL_INT(_hw_iavf, OID_AUTO, tx_itr, CTLFLAG_RDTUN,
105 &iavf_tx_itr, 0, "TX Interrupt Rate");
106
107 /**
108 * iavf_save_tunables - Sanity check and save off tunable values
109 * @sc: device softc
110 *
111 * @pre "iavf_drv_info.h" is included before this file
112 * @pre dev pointer in sc is valid
113 */
114 static void
iavf_save_tunables(struct iavf_sc * sc)115 iavf_save_tunables(struct iavf_sc *sc)
116 {
117 device_t dev = sc->dev;
118 u16 pci_device_id = pci_get_device(dev);
119
120 /* Save tunable information */
121 sc->dbg_mask = (enum iavf_dbg_mask)iavf_core_debug_mask;
122 sc->hw.debug_mask = iavf_shared_debug_mask;
123
124 if (pci_device_id == IAVF_DEV_ID_VF ||
125 pci_device_id == IAVF_DEV_ID_X722_VF)
126 sc->vsi.enable_head_writeback = !!(iavf_enable_head_writeback);
127 else if (iavf_enable_head_writeback) {
128 device_printf(dev, "Head writeback can only be enabled on 700 series Virtual Functions\n");
129 device_printf(dev, "Using descriptor writeback instead...\n");
130 sc->vsi.enable_head_writeback = 0;
131 }
132
133 if (iavf_tx_itr < 0 || iavf_tx_itr > IAVF_MAX_ITR) {
134 device_printf(dev, "Invalid tx_itr value of %d set!\n",
135 iavf_tx_itr);
136 device_printf(dev, "tx_itr must be between %d and %d, "
137 "inclusive\n",
138 0, IAVF_MAX_ITR);
139 device_printf(dev, "Using default value of %d instead\n",
140 IAVF_ITR_4K);
141 sc->tx_itr = IAVF_ITR_4K;
142 } else
143 sc->tx_itr = iavf_tx_itr;
144
145 if (iavf_rx_itr < 0 || iavf_rx_itr > IAVF_MAX_ITR) {
146 device_printf(dev, "Invalid rx_itr value of %d set!\n",
147 iavf_rx_itr);
148 device_printf(dev, "rx_itr must be between %d and %d, "
149 "inclusive\n",
150 0, IAVF_MAX_ITR);
151 device_printf(dev, "Using default value of %d instead\n",
152 IAVF_ITR_8K);
153 sc->rx_itr = IAVF_ITR_8K;
154 } else
155 sc->rx_itr = iavf_rx_itr;
156 }
157 #endif /* _IAVF_SYSCTLS_COMMON_H_ */
158