1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2016 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
27 /* ethtool support for i40e */
30 #include "i40e_diag.h"
33 char stat_string
[ETH_GSTRING_LEN
];
38 #define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
44 #define I40E_NETDEV_STAT(_net_stat) \
45 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
46 #define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48 #define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
50 #define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
53 static const struct i40e_stats i40e_gstrings_net_stats
[] = {
54 I40E_NETDEV_STAT(rx_packets
),
55 I40E_NETDEV_STAT(tx_packets
),
56 I40E_NETDEV_STAT(rx_bytes
),
57 I40E_NETDEV_STAT(tx_bytes
),
58 I40E_NETDEV_STAT(rx_errors
),
59 I40E_NETDEV_STAT(tx_errors
),
60 I40E_NETDEV_STAT(rx_dropped
),
61 I40E_NETDEV_STAT(tx_dropped
),
62 I40E_NETDEV_STAT(collisions
),
63 I40E_NETDEV_STAT(rx_length_errors
),
64 I40E_NETDEV_STAT(rx_crc_errors
),
67 static const struct i40e_stats i40e_gstrings_veb_stats
[] = {
68 I40E_VEB_STAT("rx_bytes", stats
.rx_bytes
),
69 I40E_VEB_STAT("tx_bytes", stats
.tx_bytes
),
70 I40E_VEB_STAT("rx_unicast", stats
.rx_unicast
),
71 I40E_VEB_STAT("tx_unicast", stats
.tx_unicast
),
72 I40E_VEB_STAT("rx_multicast", stats
.rx_multicast
),
73 I40E_VEB_STAT("tx_multicast", stats
.tx_multicast
),
74 I40E_VEB_STAT("rx_broadcast", stats
.rx_broadcast
),
75 I40E_VEB_STAT("tx_broadcast", stats
.tx_broadcast
),
76 I40E_VEB_STAT("rx_discards", stats
.rx_discards
),
77 I40E_VEB_STAT("tx_discards", stats
.tx_discards
),
78 I40E_VEB_STAT("tx_errors", stats
.tx_errors
),
79 I40E_VEB_STAT("rx_unknown_protocol", stats
.rx_unknown_protocol
),
82 static const struct i40e_stats i40e_gstrings_misc_stats
[] = {
83 I40E_VSI_STAT("rx_unicast", eth_stats
.rx_unicast
),
84 I40E_VSI_STAT("tx_unicast", eth_stats
.tx_unicast
),
85 I40E_VSI_STAT("rx_multicast", eth_stats
.rx_multicast
),
86 I40E_VSI_STAT("tx_multicast", eth_stats
.tx_multicast
),
87 I40E_VSI_STAT("rx_broadcast", eth_stats
.rx_broadcast
),
88 I40E_VSI_STAT("tx_broadcast", eth_stats
.tx_broadcast
),
89 I40E_VSI_STAT("rx_unknown_protocol", eth_stats
.rx_unknown_protocol
),
90 I40E_VSI_STAT("tx_linearize", tx_linearize
),
91 I40E_VSI_STAT("tx_force_wb", tx_force_wb
),
92 I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt
),
93 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed
),
94 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed
),
97 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
98 * but they are separate. This device supports Virtualization, and
99 * as such might have several netdevs supporting VMDq and FCoE going
100 * through a single port. The NETDEV_STATs are for individual netdevs
101 * seen at the top of the stack, and the PF_STATs are for the physical
102 * function at the bottom of the stack hosting those netdevs.
104 * The PF_STATs are appended to the netdev stats only when ethtool -S
105 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
107 static const struct i40e_stats i40e_gstrings_stats
[] = {
108 I40E_PF_STAT("rx_bytes", stats
.eth
.rx_bytes
),
109 I40E_PF_STAT("tx_bytes", stats
.eth
.tx_bytes
),
110 I40E_PF_STAT("rx_unicast", stats
.eth
.rx_unicast
),
111 I40E_PF_STAT("tx_unicast", stats
.eth
.tx_unicast
),
112 I40E_PF_STAT("rx_multicast", stats
.eth
.rx_multicast
),
113 I40E_PF_STAT("tx_multicast", stats
.eth
.tx_multicast
),
114 I40E_PF_STAT("rx_broadcast", stats
.eth
.rx_broadcast
),
115 I40E_PF_STAT("tx_broadcast", stats
.eth
.tx_broadcast
),
116 I40E_PF_STAT("tx_errors", stats
.eth
.tx_errors
),
117 I40E_PF_STAT("rx_dropped", stats
.eth
.rx_discards
),
118 I40E_PF_STAT("tx_dropped_link_down", stats
.tx_dropped_link_down
),
119 I40E_PF_STAT("rx_crc_errors", stats
.crc_errors
),
120 I40E_PF_STAT("illegal_bytes", stats
.illegal_bytes
),
121 I40E_PF_STAT("mac_local_faults", stats
.mac_local_faults
),
122 I40E_PF_STAT("mac_remote_faults", stats
.mac_remote_faults
),
123 I40E_PF_STAT("tx_timeout", tx_timeout_count
),
124 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error
),
125 I40E_PF_STAT("rx_length_errors", stats
.rx_length_errors
),
126 I40E_PF_STAT("link_xon_rx", stats
.link_xon_rx
),
127 I40E_PF_STAT("link_xoff_rx", stats
.link_xoff_rx
),
128 I40E_PF_STAT("link_xon_tx", stats
.link_xon_tx
),
129 I40E_PF_STAT("link_xoff_tx", stats
.link_xoff_tx
),
130 I40E_PF_STAT("rx_size_64", stats
.rx_size_64
),
131 I40E_PF_STAT("rx_size_127", stats
.rx_size_127
),
132 I40E_PF_STAT("rx_size_255", stats
.rx_size_255
),
133 I40E_PF_STAT("rx_size_511", stats
.rx_size_511
),
134 I40E_PF_STAT("rx_size_1023", stats
.rx_size_1023
),
135 I40E_PF_STAT("rx_size_1522", stats
.rx_size_1522
),
136 I40E_PF_STAT("rx_size_big", stats
.rx_size_big
),
137 I40E_PF_STAT("tx_size_64", stats
.tx_size_64
),
138 I40E_PF_STAT("tx_size_127", stats
.tx_size_127
),
139 I40E_PF_STAT("tx_size_255", stats
.tx_size_255
),
140 I40E_PF_STAT("tx_size_511", stats
.tx_size_511
),
141 I40E_PF_STAT("tx_size_1023", stats
.tx_size_1023
),
142 I40E_PF_STAT("tx_size_1522", stats
.tx_size_1522
),
143 I40E_PF_STAT("tx_size_big", stats
.tx_size_big
),
144 I40E_PF_STAT("rx_undersize", stats
.rx_undersize
),
145 I40E_PF_STAT("rx_fragments", stats
.rx_fragments
),
146 I40E_PF_STAT("rx_oversize", stats
.rx_oversize
),
147 I40E_PF_STAT("rx_jabber", stats
.rx_jabber
),
148 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests
),
149 I40E_PF_STAT("arq_overflows", arq_overflows
),
150 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared
),
151 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt
),
152 I40E_PF_STAT("fdir_atr_match", stats
.fd_atr_match
),
153 I40E_PF_STAT("fdir_atr_tunnel_match", stats
.fd_atr_tunnel_match
),
154 I40E_PF_STAT("fdir_atr_status", stats
.fd_atr_status
),
155 I40E_PF_STAT("fdir_sb_match", stats
.fd_sb_match
),
156 I40E_PF_STAT("fdir_sb_status", stats
.fd_sb_status
),
159 I40E_PF_STAT("tx_lpi_status", stats
.tx_lpi_status
),
160 I40E_PF_STAT("rx_lpi_status", stats
.rx_lpi_status
),
161 I40E_PF_STAT("tx_lpi_count", stats
.tx_lpi_count
),
162 I40E_PF_STAT("rx_lpi_count", stats
.rx_lpi_count
),
166 static const struct i40e_stats i40e_gstrings_fcoe_stats
[] = {
167 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats
.fcoe_bad_fccrc
),
168 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats
.rx_fcoe_dropped
),
169 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats
.rx_fcoe_packets
),
170 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats
.rx_fcoe_dwords
),
171 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats
.fcoe_ddp_count
),
172 I40E_VSI_STAT("fcoe_last_error", fcoe_stats
.fcoe_last_error
),
173 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats
.tx_fcoe_packets
),
174 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats
.tx_fcoe_dwords
),
177 #endif /* I40E_FCOE */
178 #define I40E_QUEUE_STATS_LEN(n) \
179 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
180 * 2 /* Tx and Rx together */ \
181 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
182 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
183 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
184 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
186 #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
187 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
188 I40E_FCOE_STATS_LEN + \
189 I40E_MISC_STATS_LEN + \
190 I40E_QUEUE_STATS_LEN((n)))
192 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
193 I40E_MISC_STATS_LEN + \
194 I40E_QUEUE_STATS_LEN((n)))
195 #endif /* I40E_FCOE */
196 #define I40E_PFC_STATS_LEN ( \
197 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
200 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
201 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
203 #define I40E_VEB_TC_STATS_LEN ( \
204 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
206 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
207 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
209 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
210 #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
211 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
212 I40E_PFC_STATS_LEN + \
213 I40E_VSI_STATS_LEN((n)))
215 enum i40e_ethtool_test_id
{
216 I40E_ETH_TEST_REG
= 0,
217 I40E_ETH_TEST_EEPROM
,
222 static const char i40e_gstrings_test
[][ETH_GSTRING_LEN
] = {
223 "Register test (offline)",
224 "Eeprom test (offline)",
225 "Interrupt test (offline)",
226 "Link test (on/offline)"
229 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
231 static const char i40e_priv_flags_strings
[][ETH_GSTRING_LEN
] = {
239 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
241 /* Private flags with a global effect, restricted to PF 0 */
242 static const char i40e_gl_priv_flags_strings
[][ETH_GSTRING_LEN
] = {
243 "vf-true-promisc-support",
246 #define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_priv_flags_strings)
249 * i40e_partition_setting_complaint - generic complaint for MFP restriction
252 static void i40e_partition_setting_complaint(struct i40e_pf
*pf
)
254 dev_info(&pf
->pdev
->dev
,
255 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
259 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
260 * @phy_types: PHY types to convert
261 * @supported: pointer to the ethtool supported variable to fill in
262 * @advertising: pointer to the ethtool advertising variable to fill in
265 static void i40e_phy_type_to_ethtool(struct i40e_pf
*pf
, u32
*supported
,
268 struct i40e_link_status
*hw_link_info
= &pf
->hw
.phy
.link_info
;
269 u64 phy_types
= pf
->hw
.phy
.phy_types
;
274 if (phy_types
& I40E_CAP_PHY_TYPE_SGMII
) {
275 *supported
|= SUPPORTED_Autoneg
|
276 SUPPORTED_1000baseT_Full
;
277 *advertising
|= ADVERTISED_Autoneg
;
278 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
279 *advertising
|= ADVERTISED_1000baseT_Full
;
280 if (pf
->flags
& I40E_FLAG_100M_SGMII_CAPABLE
) {
281 *supported
|= SUPPORTED_100baseT_Full
;
282 *advertising
|= ADVERTISED_100baseT_Full
;
285 if (phy_types
& I40E_CAP_PHY_TYPE_XAUI
||
286 phy_types
& I40E_CAP_PHY_TYPE_XFI
||
287 phy_types
& I40E_CAP_PHY_TYPE_SFI
||
288 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU
||
289 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_AOC
)
290 *supported
|= SUPPORTED_10000baseT_Full
;
291 if (phy_types
& I40E_CAP_PHY_TYPE_10GBASE_CR1_CU
||
292 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_CR1
||
293 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_T
||
294 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_SR
||
295 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_LR
) {
296 *supported
|= SUPPORTED_Autoneg
|
297 SUPPORTED_10000baseT_Full
;
298 *advertising
|= ADVERTISED_Autoneg
;
299 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
300 *advertising
|= ADVERTISED_10000baseT_Full
;
302 if (phy_types
& I40E_CAP_PHY_TYPE_XLAUI
||
303 phy_types
& I40E_CAP_PHY_TYPE_XLPPI
||
304 phy_types
& I40E_CAP_PHY_TYPE_40GBASE_AOC
)
305 *supported
|= SUPPORTED_40000baseCR4_Full
;
306 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_CR4_CU
||
307 phy_types
& I40E_CAP_PHY_TYPE_40GBASE_CR4
) {
308 *supported
|= SUPPORTED_Autoneg
|
309 SUPPORTED_40000baseCR4_Full
;
310 *advertising
|= ADVERTISED_Autoneg
;
311 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_40GB
)
312 *advertising
|= ADVERTISED_40000baseCR4_Full
;
314 if (phy_types
& I40E_CAP_PHY_TYPE_100BASE_TX
) {
315 *supported
|= SUPPORTED_Autoneg
|
316 SUPPORTED_100baseT_Full
;
317 *advertising
|= ADVERTISED_Autoneg
;
318 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_100MB
)
319 *advertising
|= ADVERTISED_100baseT_Full
;
321 if (phy_types
& I40E_CAP_PHY_TYPE_1000BASE_T
||
322 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_SX
||
323 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_LX
||
324 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL
) {
325 *supported
|= SUPPORTED_Autoneg
|
326 SUPPORTED_1000baseT_Full
;
327 *advertising
|= ADVERTISED_Autoneg
;
328 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
329 *advertising
|= ADVERTISED_1000baseT_Full
;
331 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_SR4
)
332 *supported
|= SUPPORTED_40000baseSR4_Full
;
333 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_LR4
)
334 *supported
|= SUPPORTED_40000baseLR4_Full
;
335 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_KR4
) {
336 *supported
|= SUPPORTED_40000baseKR4_Full
|
338 *advertising
|= ADVERTISED_40000baseKR4_Full
|
341 if (phy_types
& I40E_CAP_PHY_TYPE_20GBASE_KR2
) {
342 *supported
|= SUPPORTED_20000baseKR2_Full
|
344 *advertising
|= ADVERTISED_Autoneg
;
345 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_20GB
)
346 *advertising
|= ADVERTISED_20000baseKR2_Full
;
348 if (phy_types
& I40E_CAP_PHY_TYPE_10GBASE_KR
) {
349 if (!(pf
->flags
& I40E_FLAG_HAVE_CRT_RETIMER
))
350 *supported
|= SUPPORTED_10000baseKR_Full
|
352 *advertising
|= ADVERTISED_Autoneg
;
353 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
354 if (!(pf
->flags
& I40E_FLAG_HAVE_CRT_RETIMER
))
355 *advertising
|= ADVERTISED_10000baseKR_Full
;
357 if (phy_types
& I40E_CAP_PHY_TYPE_10GBASE_KX4
) {
358 *supported
|= SUPPORTED_10000baseKX4_Full
|
360 *advertising
|= ADVERTISED_Autoneg
;
361 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
362 *advertising
|= ADVERTISED_10000baseKX4_Full
;
364 if (phy_types
& I40E_CAP_PHY_TYPE_1000BASE_KX
) {
365 if (!(pf
->flags
& I40E_FLAG_HAVE_CRT_RETIMER
))
366 *supported
|= SUPPORTED_1000baseKX_Full
|
368 *advertising
|= ADVERTISED_Autoneg
;
369 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
370 if (!(pf
->flags
& I40E_FLAG_HAVE_CRT_RETIMER
))
371 *advertising
|= ADVERTISED_1000baseKX_Full
;
373 if (phy_types
& I40E_CAP_PHY_TYPE_25GBASE_KR
||
374 phy_types
& I40E_CAP_PHY_TYPE_25GBASE_CR
||
375 phy_types
& I40E_CAP_PHY_TYPE_25GBASE_SR
||
376 phy_types
& I40E_CAP_PHY_TYPE_25GBASE_LR
) {
377 *supported
|= SUPPORTED_Autoneg
;
378 *advertising
|= ADVERTISED_Autoneg
;
383 * i40e_get_settings_link_up - Get the Link settings for when link is up
385 * @ecmd: ethtool command to fill in
386 * @netdev: network interface device structure
389 static void i40e_get_settings_link_up(struct i40e_hw
*hw
,
390 struct ethtool_link_ksettings
*cmd
,
391 struct net_device
*netdev
,
394 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
395 u32 link_speed
= hw_link_info
->link_speed
;
396 u32 e_advertising
= 0x0;
397 u32 e_supported
= 0x0;
398 u32 supported
, advertising
;
400 ethtool_convert_link_mode_to_legacy_u32(&supported
,
401 cmd
->link_modes
.supported
);
402 ethtool_convert_link_mode_to_legacy_u32(&advertising
,
403 cmd
->link_modes
.advertising
);
405 /* Initialize supported and advertised settings based on phy settings */
406 switch (hw_link_info
->phy_type
) {
407 case I40E_PHY_TYPE_40GBASE_CR4
:
408 case I40E_PHY_TYPE_40GBASE_CR4_CU
:
409 supported
= SUPPORTED_Autoneg
|
410 SUPPORTED_40000baseCR4_Full
;
411 advertising
= ADVERTISED_Autoneg
|
412 ADVERTISED_40000baseCR4_Full
;
414 case I40E_PHY_TYPE_XLAUI
:
415 case I40E_PHY_TYPE_XLPPI
:
416 case I40E_PHY_TYPE_40GBASE_AOC
:
417 supported
= SUPPORTED_40000baseCR4_Full
;
419 case I40E_PHY_TYPE_40GBASE_SR4
:
420 supported
= SUPPORTED_40000baseSR4_Full
;
422 case I40E_PHY_TYPE_40GBASE_LR4
:
423 supported
= SUPPORTED_40000baseLR4_Full
;
425 case I40E_PHY_TYPE_10GBASE_SR
:
426 case I40E_PHY_TYPE_10GBASE_LR
:
427 case I40E_PHY_TYPE_1000BASE_SX
:
428 case I40E_PHY_TYPE_1000BASE_LX
:
429 supported
= SUPPORTED_10000baseT_Full
;
430 if (hw_link_info
->module_type
[2] &
431 I40E_MODULE_TYPE_1000BASE_SX
||
432 hw_link_info
->module_type
[2] &
433 I40E_MODULE_TYPE_1000BASE_LX
) {
434 supported
|= SUPPORTED_1000baseT_Full
;
435 if (hw_link_info
->requested_speeds
&
437 advertising
|= ADVERTISED_1000baseT_Full
;
439 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
440 advertising
|= ADVERTISED_10000baseT_Full
;
442 case I40E_PHY_TYPE_10GBASE_T
:
443 case I40E_PHY_TYPE_1000BASE_T
:
444 case I40E_PHY_TYPE_100BASE_TX
:
445 supported
= SUPPORTED_Autoneg
|
446 SUPPORTED_10000baseT_Full
|
447 SUPPORTED_1000baseT_Full
|
448 SUPPORTED_100baseT_Full
;
449 advertising
= ADVERTISED_Autoneg
;
450 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
451 advertising
|= ADVERTISED_10000baseT_Full
;
452 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
453 advertising
|= ADVERTISED_1000baseT_Full
;
454 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_100MB
)
455 advertising
|= ADVERTISED_100baseT_Full
;
457 case I40E_PHY_TYPE_1000BASE_T_OPTICAL
:
458 supported
= SUPPORTED_Autoneg
|
459 SUPPORTED_1000baseT_Full
;
460 advertising
= ADVERTISED_Autoneg
|
461 ADVERTISED_1000baseT_Full
;
463 case I40E_PHY_TYPE_10GBASE_CR1_CU
:
464 case I40E_PHY_TYPE_10GBASE_CR1
:
465 supported
= SUPPORTED_Autoneg
|
466 SUPPORTED_10000baseT_Full
;
467 advertising
= ADVERTISED_Autoneg
|
468 ADVERTISED_10000baseT_Full
;
470 case I40E_PHY_TYPE_XAUI
:
471 case I40E_PHY_TYPE_XFI
:
472 case I40E_PHY_TYPE_SFI
:
473 case I40E_PHY_TYPE_10GBASE_SFPP_CU
:
474 case I40E_PHY_TYPE_10GBASE_AOC
:
475 supported
= SUPPORTED_10000baseT_Full
;
476 advertising
= SUPPORTED_10000baseT_Full
;
478 case I40E_PHY_TYPE_SGMII
:
479 supported
= SUPPORTED_Autoneg
|
480 SUPPORTED_1000baseT_Full
;
481 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
482 advertising
|= ADVERTISED_1000baseT_Full
;
483 if (pf
->flags
& I40E_FLAG_100M_SGMII_CAPABLE
) {
484 supported
|= SUPPORTED_100baseT_Full
;
485 if (hw_link_info
->requested_speeds
&
486 I40E_LINK_SPEED_100MB
)
487 advertising
|= ADVERTISED_100baseT_Full
;
490 case I40E_PHY_TYPE_40GBASE_KR4
:
491 case I40E_PHY_TYPE_20GBASE_KR2
:
492 case I40E_PHY_TYPE_10GBASE_KR
:
493 case I40E_PHY_TYPE_10GBASE_KX4
:
494 case I40E_PHY_TYPE_1000BASE_KX
:
495 supported
|= SUPPORTED_40000baseKR4_Full
|
496 SUPPORTED_20000baseKR2_Full
|
497 SUPPORTED_10000baseKR_Full
|
498 SUPPORTED_10000baseKX4_Full
|
499 SUPPORTED_1000baseKX_Full
|
501 advertising
|= ADVERTISED_40000baseKR4_Full
|
502 ADVERTISED_20000baseKR2_Full
|
503 ADVERTISED_10000baseKR_Full
|
504 ADVERTISED_10000baseKX4_Full
|
505 ADVERTISED_1000baseKX_Full
|
508 case I40E_PHY_TYPE_25GBASE_KR
:
509 case I40E_PHY_TYPE_25GBASE_CR
:
510 case I40E_PHY_TYPE_25GBASE_SR
:
511 case I40E_PHY_TYPE_25GBASE_LR
:
512 supported
= SUPPORTED_Autoneg
;
513 advertising
= ADVERTISED_Autoneg
;
514 /* TODO: add speeds when ethtool is ready to support*/
517 /* if we got here and link is up something bad is afoot */
518 netdev_info(netdev
, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
519 hw_link_info
->phy_type
);
522 /* Now that we've worked out everything that could be supported by the
523 * current PHY type, get what is supported by the NVM and them to
524 * get what is truly supported
526 i40e_phy_type_to_ethtool(pf
, &e_supported
,
529 supported
= supported
& e_supported
;
530 advertising
= advertising
& e_advertising
;
532 /* Set speed and duplex */
533 switch (link_speed
) {
534 case I40E_LINK_SPEED_40GB
:
535 cmd
->base
.speed
= SPEED_40000
;
537 case I40E_LINK_SPEED_25GB
:
539 cmd
->base
.speed
= SPEED_25000
;
542 "Speed is 25G, display not supported by this version of ethtool.\n");
545 case I40E_LINK_SPEED_20GB
:
546 cmd
->base
.speed
= SPEED_20000
;
548 case I40E_LINK_SPEED_10GB
:
549 cmd
->base
.speed
= SPEED_10000
;
551 case I40E_LINK_SPEED_1GB
:
552 cmd
->base
.speed
= SPEED_1000
;
554 case I40E_LINK_SPEED_100MB
:
555 cmd
->base
.speed
= SPEED_100
;
560 cmd
->base
.duplex
= DUPLEX_FULL
;
562 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
564 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
569 * i40e_get_settings_link_down - Get the Link settings for when link is down
571 * @ecmd: ethtool command to fill in
573 * Reports link settings that can be determined when link is down
575 static void i40e_get_settings_link_down(struct i40e_hw
*hw
,
576 struct ethtool_link_ksettings
*cmd
,
579 u32 supported
, advertising
;
581 /* link is down and the driver needs to fall back on
582 * supported phy types to figure out what info to display
584 i40e_phy_type_to_ethtool(pf
, &supported
, &advertising
);
586 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
588 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
591 /* With no link speed and duplex are unknown */
592 cmd
->base
.speed
= SPEED_UNKNOWN
;
593 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
597 * i40e_get_settings - Get Link Speed and Duplex settings
598 * @netdev: network interface device structure
599 * @ecmd: ethtool command
601 * Reports speed/duplex settings based on media_type
603 static int i40e_get_link_ksettings(struct net_device
*netdev
,
604 struct ethtool_link_ksettings
*cmd
)
606 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
607 struct i40e_pf
*pf
= np
->vsi
->back
;
608 struct i40e_hw
*hw
= &pf
->hw
;
609 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
610 bool link_up
= hw_link_info
->link_info
& I40E_AQ_LINK_UP
;
614 i40e_get_settings_link_up(hw
, cmd
, netdev
, pf
);
616 i40e_get_settings_link_down(hw
, cmd
, pf
);
618 /* Now set the settings that don't rely on link being up/down */
619 /* Set autoneg settings */
620 cmd
->base
.autoneg
= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
621 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
623 switch (hw
->phy
.media_type
) {
624 case I40E_MEDIA_TYPE_BACKPLANE
:
625 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
627 ethtool_link_ksettings_add_link_mode(cmd
, supported
,
629 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
631 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
633 cmd
->base
.port
= PORT_NONE
;
635 case I40E_MEDIA_TYPE_BASET
:
636 ethtool_link_ksettings_add_link_mode(cmd
, supported
, TP
);
637 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, TP
);
638 cmd
->base
.port
= PORT_TP
;
640 case I40E_MEDIA_TYPE_DA
:
641 case I40E_MEDIA_TYPE_CX4
:
642 ethtool_link_ksettings_add_link_mode(cmd
, supported
, FIBRE
);
643 ethtool_link_ksettings_add_link_mode(cmd
, advertising
, FIBRE
);
644 cmd
->base
.port
= PORT_DA
;
646 case I40E_MEDIA_TYPE_FIBER
:
647 ethtool_link_ksettings_add_link_mode(cmd
, supported
, FIBRE
);
648 cmd
->base
.port
= PORT_FIBRE
;
650 case I40E_MEDIA_TYPE_UNKNOWN
:
652 cmd
->base
.port
= PORT_OTHER
;
656 /* Set flow control settings */
657 ethtool_link_ksettings_add_link_mode(cmd
, supported
, Pause
);
659 switch (hw
->fc
.requested_mode
) {
661 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
664 case I40E_FC_TX_PAUSE
:
665 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
668 case I40E_FC_RX_PAUSE
:
669 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
671 ethtool_link_ksettings_add_link_mode(cmd
, advertising
,
675 ethtool_convert_link_mode_to_legacy_u32(
676 &advertising
, cmd
->link_modes
.advertising
);
678 advertising
&= ~(ADVERTISED_Pause
| ADVERTISED_Asym_Pause
);
680 ethtool_convert_legacy_u32_to_link_mode(
681 cmd
->link_modes
.advertising
, advertising
);
689 * i40e_set_settings - Set Speed and Duplex
690 * @netdev: network interface device structure
691 * @ecmd: ethtool command
693 * Set speed/duplex per media_types advertised/forced
695 static int i40e_set_link_ksettings(struct net_device
*netdev
,
696 const struct ethtool_link_ksettings
*cmd
)
698 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
699 struct i40e_aq_get_phy_abilities_resp abilities
;
700 struct i40e_aq_set_phy_config config
;
701 struct i40e_pf
*pf
= np
->vsi
->back
;
702 struct i40e_vsi
*vsi
= np
->vsi
;
703 struct i40e_hw
*hw
= &pf
->hw
;
704 struct ethtool_link_ksettings safe_cmd
;
705 struct ethtool_link_ksettings copy_cmd
;
706 i40e_status status
= 0;
713 /* Changing port settings is not supported if this isn't the
714 * port's controlling PF
716 if (hw
->partition_id
!= 1) {
717 i40e_partition_setting_complaint(pf
);
721 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
724 if (hw
->phy
.media_type
!= I40E_MEDIA_TYPE_BASET
&&
725 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_FIBER
&&
726 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_BACKPLANE
&&
727 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_DA
&&
728 hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
)
731 if (hw
->device_id
== I40E_DEV_ID_KX_B
||
732 hw
->device_id
== I40E_DEV_ID_KX_C
||
733 hw
->device_id
== I40E_DEV_ID_20G_KR2
||
734 hw
->device_id
== I40E_DEV_ID_20G_KR2_A
) {
735 netdev_info(netdev
, "Changing settings is not supported on backplane.\n");
739 /* copy the cmd to copy_cmd to avoid modifying the origin */
740 memcpy(©_cmd
, cmd
, sizeof(struct ethtool_link_ksettings
));
742 /* get our own copy of the bits to check against */
743 memset(&safe_cmd
, 0, sizeof(struct ethtool_link_ksettings
));
744 i40e_get_link_ksettings(netdev
, &safe_cmd
);
746 /* save autoneg and speed out of cmd */
747 autoneg
= cmd
->base
.autoneg
;
748 ethtool_convert_link_mode_to_legacy_u32(&advertise
,
749 cmd
->link_modes
.advertising
);
751 /* set autoneg and speed back to what they currently are */
752 copy_cmd
.base
.autoneg
= safe_cmd
.base
.autoneg
;
753 ethtool_convert_link_mode_to_legacy_u32(
754 &tmp
, safe_cmd
.link_modes
.advertising
);
755 ethtool_convert_legacy_u32_to_link_mode(
756 copy_cmd
.link_modes
.advertising
, tmp
);
758 copy_cmd
.base
.cmd
= safe_cmd
.base
.cmd
;
760 /* If copy_cmd and safe_cmd are not the same now, then they are
761 * trying to set something that we do not support
763 if (memcmp(©_cmd
, &safe_cmd
, sizeof(struct ethtool_link_ksettings
)))
766 while (test_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
767 usleep_range(1000, 2000);
769 /* Get the current phy config */
770 status
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
,
775 /* Copy abilities to config in case autoneg is not
778 memset(&config
, 0, sizeof(struct i40e_aq_set_phy_config
));
779 config
.abilities
= abilities
.abilities
;
782 if (autoneg
== AUTONEG_ENABLE
) {
783 /* If autoneg was not already enabled */
784 if (!(hw
->phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
)) {
785 /* If autoneg is not supported, return error */
786 if (!ethtool_link_ksettings_test_link_mode(
787 &safe_cmd
, supported
, Autoneg
)) {
788 netdev_info(netdev
, "Autoneg not supported on this phy\n");
791 /* Autoneg is allowed to change */
792 config
.abilities
= abilities
.abilities
|
793 I40E_AQ_PHY_ENABLE_AN
;
797 /* If autoneg is currently enabled */
798 if (hw
->phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
) {
799 /* If autoneg is supported 10GBASE_T is the only PHY
800 * that can disable it, so otherwise return error
802 if (ethtool_link_ksettings_test_link_mode(
803 &safe_cmd
, supported
, Autoneg
) &&
804 hw
->phy
.link_info
.phy_type
!=
805 I40E_PHY_TYPE_10GBASE_T
) {
806 netdev_info(netdev
, "Autoneg cannot be disabled on this phy\n");
809 /* Autoneg is allowed to change */
810 config
.abilities
= abilities
.abilities
&
811 ~I40E_AQ_PHY_ENABLE_AN
;
816 ethtool_convert_link_mode_to_legacy_u32(&tmp
,
817 safe_cmd
.link_modes
.supported
);
818 if (advertise
& ~tmp
)
821 if (advertise
& ADVERTISED_100baseT_Full
)
822 config
.link_speed
|= I40E_LINK_SPEED_100MB
;
823 if (advertise
& ADVERTISED_1000baseT_Full
||
824 advertise
& ADVERTISED_1000baseKX_Full
)
825 config
.link_speed
|= I40E_LINK_SPEED_1GB
;
826 if (advertise
& ADVERTISED_10000baseT_Full
||
827 advertise
& ADVERTISED_10000baseKX4_Full
||
828 advertise
& ADVERTISED_10000baseKR_Full
)
829 config
.link_speed
|= I40E_LINK_SPEED_10GB
;
830 if (advertise
& ADVERTISED_20000baseKR2_Full
)
831 config
.link_speed
|= I40E_LINK_SPEED_20GB
;
832 if (advertise
& ADVERTISED_40000baseKR4_Full
||
833 advertise
& ADVERTISED_40000baseCR4_Full
||
834 advertise
& ADVERTISED_40000baseSR4_Full
||
835 advertise
& ADVERTISED_40000baseLR4_Full
)
836 config
.link_speed
|= I40E_LINK_SPEED_40GB
;
838 /* If speed didn't get set, set it to what it currently is.
839 * This is needed because if advertise is 0 (as it is when autoneg
840 * is disabled) then speed won't get set.
842 if (!config
.link_speed
)
843 config
.link_speed
= abilities
.link_speed
;
845 if (change
|| (abilities
.link_speed
!= config
.link_speed
)) {
846 /* copy over the rest of the abilities */
847 config
.phy_type
= abilities
.phy_type
;
848 config
.phy_type_ext
= abilities
.phy_type_ext
;
849 config
.eee_capability
= abilities
.eee_capability
;
850 config
.eeer
= abilities
.eeer_val
;
851 config
.low_power_ctrl
= abilities
.d3_lpan
;
852 config
.fec_config
= abilities
.fec_cfg_curr_mod_ext_info
&
853 I40E_AQ_PHY_FEC_CONFIG_MASK
;
855 /* save the requested speeds */
856 hw
->phy
.link_info
.requested_speeds
= config
.link_speed
;
857 /* set link and auto negotiation so changes take effect */
858 config
.abilities
|= I40E_AQ_PHY_ENABLE_ATOMIC_LINK
;
859 /* If link is up put link down */
860 if (hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) {
861 /* Tell the OS link is going down, the link will go
862 * back up when fw says it is ready asynchronously
864 i40e_print_link_message(vsi
, false);
865 netif_carrier_off(netdev
);
866 netif_tx_stop_all_queues(netdev
);
869 /* make the aq call */
870 status
= i40e_aq_set_phy_config(hw
, &config
, NULL
);
872 netdev_info(netdev
, "Set phy config failed, err %s aq_err %s\n",
873 i40e_stat_str(hw
, status
),
874 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
878 status
= i40e_update_link_info(hw
);
880 netdev_dbg(netdev
, "Updating link info failed with err %s aq_err %s\n",
881 i40e_stat_str(hw
, status
),
882 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
885 netdev_info(netdev
, "Nothing changed, exiting without setting anything.\n");
891 static int i40e_nway_reset(struct net_device
*netdev
)
893 /* restart autonegotiation */
894 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
895 struct i40e_pf
*pf
= np
->vsi
->back
;
896 struct i40e_hw
*hw
= &pf
->hw
;
897 bool link_up
= hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
900 ret
= i40e_aq_set_link_restart_an(hw
, link_up
, NULL
);
902 netdev_info(netdev
, "link restart failed, err %s aq_err %s\n",
903 i40e_stat_str(hw
, ret
),
904 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
912 * i40e_get_pauseparam - Get Flow Control status
913 * Return tx/rx-pause status
915 static void i40e_get_pauseparam(struct net_device
*netdev
,
916 struct ethtool_pauseparam
*pause
)
918 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
919 struct i40e_pf
*pf
= np
->vsi
->back
;
920 struct i40e_hw
*hw
= &pf
->hw
;
921 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
922 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
925 ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
926 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
928 /* PFC enabled so report LFC as off */
929 if (dcbx_cfg
->pfc
.pfcenable
) {
935 if (hw
->fc
.current_mode
== I40E_FC_RX_PAUSE
) {
937 } else if (hw
->fc
.current_mode
== I40E_FC_TX_PAUSE
) {
939 } else if (hw
->fc
.current_mode
== I40E_FC_FULL
) {
946 * i40e_set_pauseparam - Set Flow Control parameter
947 * @netdev: network interface device structure
948 * @pause: return tx/rx flow control status
950 static int i40e_set_pauseparam(struct net_device
*netdev
,
951 struct ethtool_pauseparam
*pause
)
953 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
954 struct i40e_pf
*pf
= np
->vsi
->back
;
955 struct i40e_vsi
*vsi
= np
->vsi
;
956 struct i40e_hw
*hw
= &pf
->hw
;
957 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
958 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
959 bool link_up
= hw_link_info
->link_info
& I40E_AQ_LINK_UP
;
964 /* Changing the port's flow control is not supported if this isn't the
965 * port's controlling PF
967 if (hw
->partition_id
!= 1) {
968 i40e_partition_setting_complaint(pf
);
972 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
975 if (pause
->autoneg
!= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
976 AUTONEG_ENABLE
: AUTONEG_DISABLE
)) {
977 netdev_info(netdev
, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
981 /* If we have link and don't have autoneg */
982 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
983 !(hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
)) {
984 /* Send message that it might not necessarily work*/
985 netdev_info(netdev
, "Autoneg did not complete so changing settings may not result in an actual change.\n");
988 if (dcbx_cfg
->pfc
.pfcenable
) {
990 "Priority flow control enabled. Cannot set link flow control.\n");
994 if (pause
->rx_pause
&& pause
->tx_pause
)
995 hw
->fc
.requested_mode
= I40E_FC_FULL
;
996 else if (pause
->rx_pause
&& !pause
->tx_pause
)
997 hw
->fc
.requested_mode
= I40E_FC_RX_PAUSE
;
998 else if (!pause
->rx_pause
&& pause
->tx_pause
)
999 hw
->fc
.requested_mode
= I40E_FC_TX_PAUSE
;
1000 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
1001 hw
->fc
.requested_mode
= I40E_FC_NONE
;
1005 /* Tell the OS link is going down, the link will go back up when fw
1006 * says it is ready asynchronously
1008 i40e_print_link_message(vsi
, false);
1009 netif_carrier_off(netdev
);
1010 netif_tx_stop_all_queues(netdev
);
1012 /* Set the fc mode and only restart an if link is up*/
1013 status
= i40e_set_fc(hw
, &aq_failures
, link_up
);
1015 if (aq_failures
& I40E_SET_FC_AQ_FAIL_GET
) {
1016 netdev_info(netdev
, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1017 i40e_stat_str(hw
, status
),
1018 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1021 if (aq_failures
& I40E_SET_FC_AQ_FAIL_SET
) {
1022 netdev_info(netdev
, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1023 i40e_stat_str(hw
, status
),
1024 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1027 if (aq_failures
& I40E_SET_FC_AQ_FAIL_UPDATE
) {
1028 netdev_info(netdev
, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1029 i40e_stat_str(hw
, status
),
1030 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
1034 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
1035 /* Give it a little more time to try to come back */
1037 if (!test_bit(__I40E_DOWN
, &pf
->state
))
1038 return i40e_nway_reset(netdev
);
1044 static u32
i40e_get_msglevel(struct net_device
*netdev
)
1046 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1047 struct i40e_pf
*pf
= np
->vsi
->back
;
1048 u32 debug_mask
= pf
->hw
.debug_mask
;
1051 netdev_info(netdev
, "i40e debug_mask: 0x%08X\n", debug_mask
);
1053 return pf
->msg_enable
;
1056 static void i40e_set_msglevel(struct net_device
*netdev
, u32 data
)
1058 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1059 struct i40e_pf
*pf
= np
->vsi
->back
;
1061 if (I40E_DEBUG_USER
& data
)
1062 pf
->hw
.debug_mask
= data
;
1064 pf
->msg_enable
= data
;
1067 static int i40e_get_regs_len(struct net_device
*netdev
)
1072 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++)
1073 reg_count
+= i40e_reg_list
[i
].elements
;
1075 return reg_count
* sizeof(u32
);
1078 static void i40e_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
,
1081 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1082 struct i40e_pf
*pf
= np
->vsi
->back
;
1083 struct i40e_hw
*hw
= &pf
->hw
;
1088 /* Tell ethtool which driver-version-specific regs output we have.
1090 * At some point, if we have ethtool doing special formatting of
1091 * this data, it will rely on this version number to know how to
1092 * interpret things. Hence, this needs to be updated if/when the
1093 * diags register table is changed.
1097 /* loop through the diags reg table for what to print */
1099 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++) {
1100 for (j
= 0; j
< i40e_reg_list
[i
].elements
; j
++) {
1101 reg
= i40e_reg_list
[i
].offset
1102 + (j
* i40e_reg_list
[i
].stride
);
1103 reg_buf
[ri
++] = rd32(hw
, reg
);
1109 static int i40e_get_eeprom(struct net_device
*netdev
,
1110 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
1112 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1113 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1114 struct i40e_pf
*pf
= np
->vsi
->back
;
1115 int ret_val
= 0, len
, offset
;
1121 #define I40E_NVM_SECTOR_SIZE 4096
1122 if (eeprom
->len
== 0)
1125 /* check for NVMUpdate access method */
1126 magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
1127 if (eeprom
->magic
&& eeprom
->magic
!= magic
) {
1128 struct i40e_nvm_access
*cmd
= (struct i40e_nvm_access
*)eeprom
;
1131 /* make sure it is the right magic for NVMUpdate */
1132 if ((eeprom
->magic
>> 16) != hw
->device_id
)
1134 else if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
1135 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
1138 ret_val
= i40e_nvmupd_command(hw
, cmd
, bytes
, &errno
);
1140 if ((errno
|| ret_val
) && (hw
->debug_mask
& I40E_DEBUG_NVM
))
1141 dev_info(&pf
->pdev
->dev
,
1142 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1143 ret_val
, hw
->aq
.asq_last_status
, errno
,
1144 (u8
)(cmd
->config
& I40E_NVM_MOD_PNT_MASK
),
1145 cmd
->offset
, cmd
->data_size
);
1150 /* normal ethtool get_eeprom support */
1151 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
1153 eeprom_buff
= kzalloc(eeprom
->len
, GFP_KERNEL
);
1157 ret_val
= i40e_acquire_nvm(hw
, I40E_RESOURCE_READ
);
1159 dev_info(&pf
->pdev
->dev
,
1160 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1161 ret_val
, hw
->aq
.asq_last_status
);
1165 sectors
= eeprom
->len
/ I40E_NVM_SECTOR_SIZE
;
1166 sectors
+= (eeprom
->len
% I40E_NVM_SECTOR_SIZE
) ? 1 : 0;
1167 len
= I40E_NVM_SECTOR_SIZE
;
1169 for (i
= 0; i
< sectors
; i
++) {
1170 if (i
== (sectors
- 1)) {
1171 len
= eeprom
->len
- (I40E_NVM_SECTOR_SIZE
* i
);
1174 offset
= eeprom
->offset
+ (I40E_NVM_SECTOR_SIZE
* i
),
1175 ret_val
= i40e_aq_read_nvm(hw
, 0x0, offset
, len
,
1176 (u8
*)eeprom_buff
+ (I40E_NVM_SECTOR_SIZE
* i
),
1178 if (ret_val
&& hw
->aq
.asq_last_status
== I40E_AQ_RC_EPERM
) {
1179 dev_info(&pf
->pdev
->dev
,
1180 "read NVM failed, invalid offset 0x%x\n",
1183 } else if (ret_val
&&
1184 hw
->aq
.asq_last_status
== I40E_AQ_RC_EACCES
) {
1185 dev_info(&pf
->pdev
->dev
,
1186 "read NVM failed, access, offset 0x%x\n",
1189 } else if (ret_val
) {
1190 dev_info(&pf
->pdev
->dev
,
1191 "read NVM failed offset %d err=%d status=0x%x\n",
1192 offset
, ret_val
, hw
->aq
.asq_last_status
);
1197 i40e_release_nvm(hw
);
1198 memcpy(bytes
, (u8
*)eeprom_buff
, eeprom
->len
);
1204 static int i40e_get_eeprom_len(struct net_device
*netdev
)
1206 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1207 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1210 #define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1211 if (hw
->mac
.type
== I40E_MAC_X722
) {
1212 val
= X722_EEPROM_SCOPE_LIMIT
+ 1;
1215 val
= (rd32(hw
, I40E_GLPCI_LBARCTRL
)
1216 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK
)
1217 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT
;
1218 /* register returns value in power of 2, 64Kbyte chunks. */
1219 val
= (64 * 1024) * BIT(val
);
1223 static int i40e_set_eeprom(struct net_device
*netdev
,
1224 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
1226 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1227 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1228 struct i40e_pf
*pf
= np
->vsi
->back
;
1229 struct i40e_nvm_access
*cmd
= (struct i40e_nvm_access
*)eeprom
;
1234 /* normal ethtool set_eeprom is not supported */
1235 magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
1236 if (eeprom
->magic
== magic
)
1237 errno
= -EOPNOTSUPP
;
1238 /* check for NVMUpdate access method */
1239 else if (!eeprom
->magic
|| (eeprom
->magic
>> 16) != hw
->device_id
)
1241 else if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
1242 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
1245 ret_val
= i40e_nvmupd_command(hw
, cmd
, bytes
, &errno
);
1247 if ((errno
|| ret_val
) && (hw
->debug_mask
& I40E_DEBUG_NVM
))
1248 dev_info(&pf
->pdev
->dev
,
1249 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1250 ret_val
, hw
->aq
.asq_last_status
, errno
,
1251 (u8
)(cmd
->config
& I40E_NVM_MOD_PNT_MASK
),
1252 cmd
->offset
, cmd
->data_size
);
1257 static void i40e_get_drvinfo(struct net_device
*netdev
,
1258 struct ethtool_drvinfo
*drvinfo
)
1260 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1261 struct i40e_vsi
*vsi
= np
->vsi
;
1262 struct i40e_pf
*pf
= vsi
->back
;
1264 strlcpy(drvinfo
->driver
, i40e_driver_name
, sizeof(drvinfo
->driver
));
1265 strlcpy(drvinfo
->version
, i40e_driver_version_str
,
1266 sizeof(drvinfo
->version
));
1267 strlcpy(drvinfo
->fw_version
, i40e_nvm_version_str(&pf
->hw
),
1268 sizeof(drvinfo
->fw_version
));
1269 strlcpy(drvinfo
->bus_info
, pci_name(pf
->pdev
),
1270 sizeof(drvinfo
->bus_info
));
1271 drvinfo
->n_priv_flags
= I40E_PRIV_FLAGS_STR_LEN
;
1272 if (pf
->hw
.pf_id
== 0)
1273 drvinfo
->n_priv_flags
+= I40E_GL_PRIV_FLAGS_STR_LEN
;
1276 static void i40e_get_ringparam(struct net_device
*netdev
,
1277 struct ethtool_ringparam
*ring
)
1279 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1280 struct i40e_pf
*pf
= np
->vsi
->back
;
1281 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
1283 ring
->rx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
1284 ring
->tx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
1285 ring
->rx_mini_max_pending
= 0;
1286 ring
->rx_jumbo_max_pending
= 0;
1287 ring
->rx_pending
= vsi
->rx_rings
[0]->count
;
1288 ring
->tx_pending
= vsi
->tx_rings
[0]->count
;
1289 ring
->rx_mini_pending
= 0;
1290 ring
->rx_jumbo_pending
= 0;
1293 static int i40e_set_ringparam(struct net_device
*netdev
,
1294 struct ethtool_ringparam
*ring
)
1296 struct i40e_ring
*tx_rings
= NULL
, *rx_rings
= NULL
;
1297 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1298 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1299 struct i40e_vsi
*vsi
= np
->vsi
;
1300 struct i40e_pf
*pf
= vsi
->back
;
1301 u32 new_rx_count
, new_tx_count
;
1304 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
1307 if (ring
->tx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
1308 ring
->tx_pending
< I40E_MIN_NUM_DESCRIPTORS
||
1309 ring
->rx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
1310 ring
->rx_pending
< I40E_MIN_NUM_DESCRIPTORS
) {
1312 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1313 ring
->tx_pending
, ring
->rx_pending
,
1314 I40E_MIN_NUM_DESCRIPTORS
, I40E_MAX_NUM_DESCRIPTORS
);
1318 new_tx_count
= ALIGN(ring
->tx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
1319 new_rx_count
= ALIGN(ring
->rx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
1321 /* if nothing to do return success */
1322 if ((new_tx_count
== vsi
->tx_rings
[0]->count
) &&
1323 (new_rx_count
== vsi
->rx_rings
[0]->count
))
1326 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
1327 usleep_range(1000, 2000);
1329 if (!netif_running(vsi
->netdev
)) {
1330 /* simple case - set for the next time the netdev is started */
1331 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1332 vsi
->tx_rings
[i
]->count
= new_tx_count
;
1333 vsi
->rx_rings
[i
]->count
= new_rx_count
;
1338 /* We can't just free everything and then setup again,
1339 * because the ISRs in MSI-X mode get passed pointers
1340 * to the Tx and Rx ring structs.
1343 /* alloc updated Tx resources */
1344 if (new_tx_count
!= vsi
->tx_rings
[0]->count
) {
1346 "Changing Tx descriptor count from %d to %d.\n",
1347 vsi
->tx_rings
[0]->count
, new_tx_count
);
1348 tx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
1349 sizeof(struct i40e_ring
), GFP_KERNEL
);
1355 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1356 /* clone ring and setup updated count */
1357 tx_rings
[i
] = *vsi
->tx_rings
[i
];
1358 tx_rings
[i
].count
= new_tx_count
;
1359 /* the desc and bi pointers will be reallocated in the
1362 tx_rings
[i
].desc
= NULL
;
1363 tx_rings
[i
].rx_bi
= NULL
;
1364 err
= i40e_setup_tx_descriptors(&tx_rings
[i
]);
1368 i40e_free_tx_resources(&tx_rings
[i
]);
1378 /* alloc updated Rx resources */
1379 if (new_rx_count
!= vsi
->rx_rings
[0]->count
) {
1381 "Changing Rx descriptor count from %d to %d\n",
1382 vsi
->rx_rings
[0]->count
, new_rx_count
);
1383 rx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
1384 sizeof(struct i40e_ring
), GFP_KERNEL
);
1390 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1391 struct i40e_ring
*ring
;
1394 /* clone ring and setup updated count */
1395 rx_rings
[i
] = *vsi
->rx_rings
[i
];
1396 rx_rings
[i
].count
= new_rx_count
;
1397 /* the desc and bi pointers will be reallocated in the
1400 rx_rings
[i
].desc
= NULL
;
1401 rx_rings
[i
].rx_bi
= NULL
;
1402 /* this is to allow wr32 to have something to write to
1403 * during early allocation of Rx buffers
1405 rx_rings
[i
].tail
= hw
->hw_addr
+ I40E_PRTGEN_STATUS
;
1406 err
= i40e_setup_rx_descriptors(&rx_rings
[i
]);
1410 /* now allocate the Rx buffers to make sure the OS
1411 * has enough memory, any failure here means abort
1413 ring
= &rx_rings
[i
];
1414 unused
= I40E_DESC_UNUSED(ring
);
1415 err
= i40e_alloc_rx_buffers(ring
, unused
);
1419 i40e_free_rx_resources(&rx_rings
[i
]);
1429 /* Bring interface down, copy in the new ring info,
1430 * then restore the interface
1435 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1436 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
1437 *vsi
->tx_rings
[i
] = tx_rings
[i
];
1444 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1445 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
1446 /* get the real tail offset */
1447 rx_rings
[i
].tail
= vsi
->rx_rings
[i
]->tail
;
1448 /* this is to fake out the allocation routine
1449 * into thinking it has to realloc everything
1450 * but the recycling logic will let us re-use
1451 * the buffers allocated above
1453 rx_rings
[i
].next_to_use
= 0;
1454 rx_rings
[i
].next_to_clean
= 0;
1455 rx_rings
[i
].next_to_alloc
= 0;
1456 /* do a struct copy */
1457 *vsi
->rx_rings
[i
] = rx_rings
[i
];
1466 /* error cleanup if the Rx allocations failed after getting Tx */
1468 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1469 i40e_free_tx_resources(&tx_rings
[i
]);
1475 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
1480 static int i40e_get_sset_count(struct net_device
*netdev
, int sset
)
1482 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1483 struct i40e_vsi
*vsi
= np
->vsi
;
1484 struct i40e_pf
*pf
= vsi
->back
;
1488 return I40E_TEST_LEN
;
1490 if (vsi
== pf
->vsi
[pf
->lan_vsi
] && pf
->hw
.partition_id
== 1) {
1491 int len
= I40E_PF_STATS_LEN(netdev
);
1493 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1494 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
))
1495 len
+= I40E_VEB_STATS_TOTAL
;
1498 return I40E_VSI_STATS_LEN(netdev
);
1500 case ETH_SS_PRIV_FLAGS
:
1501 return I40E_PRIV_FLAGS_STR_LEN
+
1502 (pf
->hw
.pf_id
== 0 ? I40E_GL_PRIV_FLAGS_STR_LEN
: 0);
1508 static void i40e_get_ethtool_stats(struct net_device
*netdev
,
1509 struct ethtool_stats
*stats
, u64
*data
)
1511 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1512 struct i40e_ring
*tx_ring
, *rx_ring
;
1513 struct i40e_vsi
*vsi
= np
->vsi
;
1514 struct i40e_pf
*pf
= vsi
->back
;
1518 struct rtnl_link_stats64
*net_stats
= i40e_get_vsi_stats_struct(vsi
);
1521 i40e_update_stats(vsi
);
1523 for (j
= 0; j
< I40E_NETDEV_STATS_LEN
; j
++) {
1524 p
= (char *)net_stats
+ i40e_gstrings_net_stats
[j
].stat_offset
;
1525 data
[i
++] = (i40e_gstrings_net_stats
[j
].sizeof_stat
==
1526 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1528 for (j
= 0; j
< I40E_MISC_STATS_LEN
; j
++) {
1529 p
= (char *)vsi
+ i40e_gstrings_misc_stats
[j
].stat_offset
;
1530 data
[i
++] = (i40e_gstrings_misc_stats
[j
].sizeof_stat
==
1531 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1534 for (j
= 0; j
< I40E_FCOE_STATS_LEN
; j
++) {
1535 p
= (char *)vsi
+ i40e_gstrings_fcoe_stats
[j
].stat_offset
;
1536 data
[i
++] = (i40e_gstrings_fcoe_stats
[j
].sizeof_stat
==
1537 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1541 for (j
= 0; j
< vsi
->num_queue_pairs
; j
++) {
1542 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[j
]);
1547 /* process Tx ring statistics */
1549 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
1550 data
[i
] = tx_ring
->stats
.packets
;
1551 data
[i
+ 1] = tx_ring
->stats
.bytes
;
1552 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
1555 /* Rx ring is the 2nd half of the queue pair */
1556 rx_ring
= &tx_ring
[1];
1558 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
1559 data
[i
] = rx_ring
->stats
.packets
;
1560 data
[i
+ 1] = rx_ring
->stats
.bytes
;
1561 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
1565 if (vsi
!= pf
->vsi
[pf
->lan_vsi
] || pf
->hw
.partition_id
!= 1)
1568 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1569 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
1570 struct i40e_veb
*veb
= pf
->veb
[pf
->lan_veb
];
1572 for (j
= 0; j
< I40E_VEB_STATS_LEN
; j
++) {
1574 p
+= i40e_gstrings_veb_stats
[j
].stat_offset
;
1575 data
[i
++] = (i40e_gstrings_veb_stats
[j
].sizeof_stat
==
1576 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1578 for (j
= 0; j
< I40E_MAX_TRAFFIC_CLASS
; j
++) {
1579 data
[i
++] = veb
->tc_stats
.tc_tx_packets
[j
];
1580 data
[i
++] = veb
->tc_stats
.tc_tx_bytes
[j
];
1581 data
[i
++] = veb
->tc_stats
.tc_rx_packets
[j
];
1582 data
[i
++] = veb
->tc_stats
.tc_rx_bytes
[j
];
1585 for (j
= 0; j
< I40E_GLOBAL_STATS_LEN
; j
++) {
1586 p
= (char *)pf
+ i40e_gstrings_stats
[j
].stat_offset
;
1587 data
[i
++] = (i40e_gstrings_stats
[j
].sizeof_stat
==
1588 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1590 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
1591 data
[i
++] = pf
->stats
.priority_xon_tx
[j
];
1592 data
[i
++] = pf
->stats
.priority_xoff_tx
[j
];
1594 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
1595 data
[i
++] = pf
->stats
.priority_xon_rx
[j
];
1596 data
[i
++] = pf
->stats
.priority_xoff_rx
[j
];
1598 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++)
1599 data
[i
++] = pf
->stats
.priority_xon_2_xoff
[j
];
1602 static void i40e_get_strings(struct net_device
*netdev
, u32 stringset
,
1605 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1606 struct i40e_vsi
*vsi
= np
->vsi
;
1607 struct i40e_pf
*pf
= vsi
->back
;
1608 char *p
= (char *)data
;
1611 switch (stringset
) {
1613 memcpy(data
, i40e_gstrings_test
,
1614 I40E_TEST_LEN
* ETH_GSTRING_LEN
);
1617 for (i
= 0; i
< I40E_NETDEV_STATS_LEN
; i
++) {
1618 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1619 i40e_gstrings_net_stats
[i
].stat_string
);
1620 p
+= ETH_GSTRING_LEN
;
1622 for (i
= 0; i
< I40E_MISC_STATS_LEN
; i
++) {
1623 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1624 i40e_gstrings_misc_stats
[i
].stat_string
);
1625 p
+= ETH_GSTRING_LEN
;
1628 for (i
= 0; i
< I40E_FCOE_STATS_LEN
; i
++) {
1629 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1630 i40e_gstrings_fcoe_stats
[i
].stat_string
);
1631 p
+= ETH_GSTRING_LEN
;
1634 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1635 snprintf(p
, ETH_GSTRING_LEN
, "tx-%d.tx_packets", i
);
1636 p
+= ETH_GSTRING_LEN
;
1637 snprintf(p
, ETH_GSTRING_LEN
, "tx-%d.tx_bytes", i
);
1638 p
+= ETH_GSTRING_LEN
;
1639 snprintf(p
, ETH_GSTRING_LEN
, "rx-%d.rx_packets", i
);
1640 p
+= ETH_GSTRING_LEN
;
1641 snprintf(p
, ETH_GSTRING_LEN
, "rx-%d.rx_bytes", i
);
1642 p
+= ETH_GSTRING_LEN
;
1644 if (vsi
!= pf
->vsi
[pf
->lan_vsi
] || pf
->hw
.partition_id
!= 1)
1647 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1648 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
1649 for (i
= 0; i
< I40E_VEB_STATS_LEN
; i
++) {
1650 snprintf(p
, ETH_GSTRING_LEN
, "veb.%s",
1651 i40e_gstrings_veb_stats
[i
].stat_string
);
1652 p
+= ETH_GSTRING_LEN
;
1654 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1655 snprintf(p
, ETH_GSTRING_LEN
,
1656 "veb.tc_%d_tx_packets", i
);
1657 p
+= ETH_GSTRING_LEN
;
1658 snprintf(p
, ETH_GSTRING_LEN
,
1659 "veb.tc_%d_tx_bytes", i
);
1660 p
+= ETH_GSTRING_LEN
;
1661 snprintf(p
, ETH_GSTRING_LEN
,
1662 "veb.tc_%d_rx_packets", i
);
1663 p
+= ETH_GSTRING_LEN
;
1664 snprintf(p
, ETH_GSTRING_LEN
,
1665 "veb.tc_%d_rx_bytes", i
);
1666 p
+= ETH_GSTRING_LEN
;
1669 for (i
= 0; i
< I40E_GLOBAL_STATS_LEN
; i
++) {
1670 snprintf(p
, ETH_GSTRING_LEN
, "port.%s",
1671 i40e_gstrings_stats
[i
].stat_string
);
1672 p
+= ETH_GSTRING_LEN
;
1674 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1675 snprintf(p
, ETH_GSTRING_LEN
,
1676 "port.tx_priority_%d_xon", i
);
1677 p
+= ETH_GSTRING_LEN
;
1678 snprintf(p
, ETH_GSTRING_LEN
,
1679 "port.tx_priority_%d_xoff", i
);
1680 p
+= ETH_GSTRING_LEN
;
1682 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1683 snprintf(p
, ETH_GSTRING_LEN
,
1684 "port.rx_priority_%d_xon", i
);
1685 p
+= ETH_GSTRING_LEN
;
1686 snprintf(p
, ETH_GSTRING_LEN
,
1687 "port.rx_priority_%d_xoff", i
);
1688 p
+= ETH_GSTRING_LEN
;
1690 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1691 snprintf(p
, ETH_GSTRING_LEN
,
1692 "port.rx_priority_%d_xon_2_xoff", i
);
1693 p
+= ETH_GSTRING_LEN
;
1695 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1697 case ETH_SS_PRIV_FLAGS
:
1698 memcpy(data
, i40e_priv_flags_strings
,
1699 I40E_PRIV_FLAGS_STR_LEN
* ETH_GSTRING_LEN
);
1700 data
+= I40E_PRIV_FLAGS_STR_LEN
* ETH_GSTRING_LEN
;
1701 if (pf
->hw
.pf_id
== 0)
1702 memcpy(data
, i40e_gl_priv_flags_strings
,
1703 I40E_GL_PRIV_FLAGS_STR_LEN
* ETH_GSTRING_LEN
);
1710 static int i40e_get_ts_info(struct net_device
*dev
,
1711 struct ethtool_ts_info
*info
)
1713 struct i40e_pf
*pf
= i40e_netdev_to_pf(dev
);
1715 /* only report HW timestamping if PTP is enabled */
1716 if (!(pf
->flags
& I40E_FLAG_PTP
))
1717 return ethtool_op_get_ts_info(dev
, info
);
1719 info
->so_timestamping
= SOF_TIMESTAMPING_TX_SOFTWARE
|
1720 SOF_TIMESTAMPING_RX_SOFTWARE
|
1721 SOF_TIMESTAMPING_SOFTWARE
|
1722 SOF_TIMESTAMPING_TX_HARDWARE
|
1723 SOF_TIMESTAMPING_RX_HARDWARE
|
1724 SOF_TIMESTAMPING_RAW_HARDWARE
;
1727 info
->phc_index
= ptp_clock_index(pf
->ptp_clock
);
1729 info
->phc_index
= -1;
1731 info
->tx_types
= BIT(HWTSTAMP_TX_OFF
) | BIT(HWTSTAMP_TX_ON
);
1733 info
->rx_filters
= BIT(HWTSTAMP_FILTER_NONE
) |
1734 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT
) |
1735 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC
) |
1736 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
);
1738 if (pf
->flags
& I40E_FLAG_PTP_L4_CAPABLE
)
1739 info
->rx_filters
|= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC
) |
1740 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
) |
1741 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT
) |
1742 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT
) |
1743 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC
) |
1744 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC
) |
1745 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
) |
1746 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
);
1751 static int i40e_link_test(struct net_device
*netdev
, u64
*data
)
1753 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1754 struct i40e_pf
*pf
= np
->vsi
->back
;
1756 bool link_up
= false;
1758 netif_info(pf
, hw
, netdev
, "link test\n");
1759 status
= i40e_get_link_status(&pf
->hw
, &link_up
);
1761 netif_err(pf
, drv
, netdev
, "link query timed out, please retry test\n");
1774 static int i40e_reg_test(struct net_device
*netdev
, u64
*data
)
1776 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1777 struct i40e_pf
*pf
= np
->vsi
->back
;
1779 netif_info(pf
, hw
, netdev
, "register test\n");
1780 *data
= i40e_diag_reg_test(&pf
->hw
);
1785 static int i40e_eeprom_test(struct net_device
*netdev
, u64
*data
)
1787 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1788 struct i40e_pf
*pf
= np
->vsi
->back
;
1790 netif_info(pf
, hw
, netdev
, "eeprom test\n");
1791 *data
= i40e_diag_eeprom_test(&pf
->hw
);
1793 /* forcebly clear the NVM Update state machine */
1794 pf
->hw
.nvmupd_state
= I40E_NVMUPD_STATE_INIT
;
1799 static int i40e_intr_test(struct net_device
*netdev
, u64
*data
)
1801 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1802 struct i40e_pf
*pf
= np
->vsi
->back
;
1803 u16 swc_old
= pf
->sw_int_count
;
1805 netif_info(pf
, hw
, netdev
, "interrupt test\n");
1806 wr32(&pf
->hw
, I40E_PFINT_DYN_CTL0
,
1807 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
1808 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
|
1809 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK
|
1810 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK
|
1811 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
));
1812 usleep_range(1000, 2000);
1813 *data
= (swc_old
== pf
->sw_int_count
);
1818 static inline bool i40e_active_vfs(struct i40e_pf
*pf
)
1820 struct i40e_vf
*vfs
= pf
->vf
;
1823 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
1824 if (test_bit(I40E_VF_STAT_ACTIVE
, &vfs
[i
].vf_states
))
1829 static inline bool i40e_active_vmdqs(struct i40e_pf
*pf
)
1831 return !!i40e_find_vsi_by_type(pf
, I40E_VSI_VMDQ2
);
1834 static void i40e_diag_test(struct net_device
*netdev
,
1835 struct ethtool_test
*eth_test
, u64
*data
)
1837 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1838 bool if_running
= netif_running(netdev
);
1839 struct i40e_pf
*pf
= np
->vsi
->back
;
1841 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1843 netif_info(pf
, drv
, netdev
, "offline testing starting\n");
1845 set_bit(__I40E_TESTING
, &pf
->state
);
1847 if (i40e_active_vfs(pf
) || i40e_active_vmdqs(pf
)) {
1848 dev_warn(&pf
->pdev
->dev
,
1849 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1850 data
[I40E_ETH_TEST_REG
] = 1;
1851 data
[I40E_ETH_TEST_EEPROM
] = 1;
1852 data
[I40E_ETH_TEST_INTR
] = 1;
1853 data
[I40E_ETH_TEST_LINK
] = 1;
1854 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1855 clear_bit(__I40E_TESTING
, &pf
->state
);
1859 /* If the device is online then take it offline */
1861 /* indicate we're in test mode */
1864 /* This reset does not affect link - if it is
1865 * changed to a type of reset that does affect
1866 * link then the following link test would have
1867 * to be moved to before the reset
1869 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
1871 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
1872 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1874 if (i40e_eeprom_test(netdev
, &data
[I40E_ETH_TEST_EEPROM
]))
1875 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1877 if (i40e_intr_test(netdev
, &data
[I40E_ETH_TEST_INTR
]))
1878 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1880 /* run reg test last, a reset is required after it */
1881 if (i40e_reg_test(netdev
, &data
[I40E_ETH_TEST_REG
]))
1882 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1884 clear_bit(__I40E_TESTING
, &pf
->state
);
1885 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
1891 netif_info(pf
, drv
, netdev
, "online testing starting\n");
1893 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
1894 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1896 /* Offline only tests, not run in online; pass by default */
1897 data
[I40E_ETH_TEST_REG
] = 0;
1898 data
[I40E_ETH_TEST_EEPROM
] = 0;
1899 data
[I40E_ETH_TEST_INTR
] = 0;
1904 netif_info(pf
, drv
, netdev
, "testing finished\n");
1907 static void i40e_get_wol(struct net_device
*netdev
,
1908 struct ethtool_wolinfo
*wol
)
1910 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1911 struct i40e_pf
*pf
= np
->vsi
->back
;
1912 struct i40e_hw
*hw
= &pf
->hw
;
1915 /* NVM bit on means WoL disabled for the port */
1916 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
1917 if ((BIT(hw
->port
) & wol_nvm_bits
) || (hw
->partition_id
!= 1)) {
1921 wol
->supported
= WAKE_MAGIC
;
1922 wol
->wolopts
= (pf
->wol_en
? WAKE_MAGIC
: 0);
1927 * i40e_set_wol - set the WakeOnLAN configuration
1928 * @netdev: the netdev in question
1929 * @wol: the ethtool WoL setting data
1931 static int i40e_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1933 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1934 struct i40e_pf
*pf
= np
->vsi
->back
;
1935 struct i40e_vsi
*vsi
= np
->vsi
;
1936 struct i40e_hw
*hw
= &pf
->hw
;
1939 /* WoL not supported if this isn't the controlling PF on the port */
1940 if (hw
->partition_id
!= 1) {
1941 i40e_partition_setting_complaint(pf
);
1945 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
1948 /* NVM bit on means WoL disabled for the port */
1949 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
1950 if (BIT(hw
->port
) & wol_nvm_bits
)
1953 /* only magic packet is supported */
1954 if (wol
->wolopts
&& (wol
->wolopts
!= WAKE_MAGIC
))
1957 /* is this a new value? */
1958 if (pf
->wol_en
!= !!wol
->wolopts
) {
1959 pf
->wol_en
= !!wol
->wolopts
;
1960 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
1966 static int i40e_set_phys_id(struct net_device
*netdev
,
1967 enum ethtool_phys_id_state state
)
1969 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1970 i40e_status ret
= 0;
1971 struct i40e_pf
*pf
= np
->vsi
->back
;
1972 struct i40e_hw
*hw
= &pf
->hw
;
1977 case ETHTOOL_ID_ACTIVE
:
1978 if (!(pf
->flags
& I40E_FLAG_PHY_CONTROLS_LEDS
)) {
1979 pf
->led_status
= i40e_led_get(hw
);
1981 i40e_aq_set_phy_debug(hw
, I40E_PHY_DEBUG_ALL
, NULL
);
1982 ret
= i40e_led_get_phy(hw
, &temp_status
,
1984 pf
->led_status
= temp_status
;
1988 if (!(pf
->flags
& I40E_FLAG_PHY_CONTROLS_LEDS
))
1989 i40e_led_set(hw
, 0xf, false);
1991 ret
= i40e_led_set_phy(hw
, true, pf
->led_status
, 0);
1993 case ETHTOOL_ID_OFF
:
1994 if (!(pf
->flags
& I40E_FLAG_PHY_CONTROLS_LEDS
))
1995 i40e_led_set(hw
, 0x0, false);
1997 ret
= i40e_led_set_phy(hw
, false, pf
->led_status
, 0);
1999 case ETHTOOL_ID_INACTIVE
:
2000 if (!(pf
->flags
& I40E_FLAG_PHY_CONTROLS_LEDS
)) {
2001 i40e_led_set(hw
, pf
->led_status
, false);
2003 ret
= i40e_led_set_phy(hw
, false, pf
->led_status
,
2005 I40E_PHY_LED_MODE_ORIG
));
2006 i40e_aq_set_phy_debug(hw
, 0, NULL
);
2018 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2019 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2020 * 125us (8000 interrupts per second) == ITR(62)
2024 * __i40e_get_coalesce - get per-queue coalesce settings
2025 * @netdev: the netdev to check
2026 * @ec: ethtool coalesce data structure
2027 * @queue: which queue to pick
2029 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2030 * are per queue. If queue is <0 then we default to queue 0 as the
2031 * representative value.
2033 static int __i40e_get_coalesce(struct net_device
*netdev
,
2034 struct ethtool_coalesce
*ec
,
2037 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2038 struct i40e_ring
*rx_ring
, *tx_ring
;
2039 struct i40e_vsi
*vsi
= np
->vsi
;
2041 ec
->tx_max_coalesced_frames_irq
= vsi
->work_limit
;
2042 ec
->rx_max_coalesced_frames_irq
= vsi
->work_limit
;
2044 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2045 * return queue 0's value to represent.
2049 } else if (queue
>= vsi
->num_queue_pairs
) {
2053 rx_ring
= vsi
->rx_rings
[queue
];
2054 tx_ring
= vsi
->tx_rings
[queue
];
2056 if (ITR_IS_DYNAMIC(rx_ring
->rx_itr_setting
))
2057 ec
->use_adaptive_rx_coalesce
= 1;
2059 if (ITR_IS_DYNAMIC(tx_ring
->tx_itr_setting
))
2060 ec
->use_adaptive_tx_coalesce
= 1;
2062 ec
->rx_coalesce_usecs
= rx_ring
->rx_itr_setting
& ~I40E_ITR_DYNAMIC
;
2063 ec
->tx_coalesce_usecs
= tx_ring
->tx_itr_setting
& ~I40E_ITR_DYNAMIC
;
2066 /* we use the _usecs_high to store/set the interrupt rate limit
2067 * that the hardware supports, that almost but not quite
2068 * fits the original intent of the ethtool variable,
2069 * the rx_coalesce_usecs_high limits total interrupts
2070 * per second from both tx/rx sources.
2072 ec
->rx_coalesce_usecs_high
= vsi
->int_rate_limit
;
2073 ec
->tx_coalesce_usecs_high
= vsi
->int_rate_limit
;
2079 * i40e_get_coalesce - get a netdev's coalesce settings
2080 * @netdev: the netdev to check
2081 * @ec: ethtool coalesce data structure
2083 * Gets the coalesce settings for a particular netdev. Note that if user has
2084 * modified per-queue settings, this only guarantees to represent queue 0. See
2085 * __i40e_get_coalesce for more details.
2087 static int i40e_get_coalesce(struct net_device
*netdev
,
2088 struct ethtool_coalesce
*ec
)
2090 return __i40e_get_coalesce(netdev
, ec
, -1);
2094 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2095 * @netdev: netdev structure
2096 * @ec: ethtool's coalesce settings
2097 * @queue: the particular queue to read
2099 * Will read a specific queue's coalesce settings
2101 static int i40e_get_per_queue_coalesce(struct net_device
*netdev
, u32 queue
,
2102 struct ethtool_coalesce
*ec
)
2104 return __i40e_get_coalesce(netdev
, ec
, queue
);
2108 * i40e_set_itr_per_queue - set ITR values for specific queue
2109 * @vsi: the VSI to set values for
2110 * @ec: coalesce settings from ethtool
2111 * @queue: the queue to modify
2113 * Change the ITR settings for a specific queue.
2116 static void i40e_set_itr_per_queue(struct i40e_vsi
*vsi
,
2117 struct ethtool_coalesce
*ec
,
2120 struct i40e_pf
*pf
= vsi
->back
;
2121 struct i40e_hw
*hw
= &pf
->hw
;
2122 struct i40e_q_vector
*q_vector
;
2125 intrl
= i40e_intrl_usec_to_reg(vsi
->int_rate_limit
);
2127 vsi
->rx_rings
[queue
]->rx_itr_setting
= ec
->rx_coalesce_usecs
;
2128 vsi
->tx_rings
[queue
]->tx_itr_setting
= ec
->tx_coalesce_usecs
;
2130 if (ec
->use_adaptive_rx_coalesce
)
2131 vsi
->rx_rings
[queue
]->rx_itr_setting
|= I40E_ITR_DYNAMIC
;
2133 vsi
->rx_rings
[queue
]->rx_itr_setting
&= ~I40E_ITR_DYNAMIC
;
2135 if (ec
->use_adaptive_tx_coalesce
)
2136 vsi
->tx_rings
[queue
]->tx_itr_setting
|= I40E_ITR_DYNAMIC
;
2138 vsi
->tx_rings
[queue
]->tx_itr_setting
&= ~I40E_ITR_DYNAMIC
;
2140 q_vector
= vsi
->rx_rings
[queue
]->q_vector
;
2141 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_rings
[queue
]->rx_itr_setting
);
2142 vector
= vsi
->base_vector
+ q_vector
->v_idx
;
2143 wr32(hw
, I40E_PFINT_ITRN(I40E_RX_ITR
, vector
- 1), q_vector
->rx
.itr
);
2145 q_vector
= vsi
->tx_rings
[queue
]->q_vector
;
2146 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_rings
[queue
]->tx_itr_setting
);
2147 vector
= vsi
->base_vector
+ q_vector
->v_idx
;
2148 wr32(hw
, I40E_PFINT_ITRN(I40E_TX_ITR
, vector
- 1), q_vector
->tx
.itr
);
2150 wr32(hw
, I40E_PFINT_RATEN(vector
- 1), intrl
);
2155 * __i40e_set_coalesce - set coalesce settings for particular queue
2156 * @netdev: the netdev to change
2157 * @ec: ethtool coalesce settings
2158 * @queue: the queue to change
2160 * Sets the coalesce settings for a particular queue.
2162 static int __i40e_set_coalesce(struct net_device
*netdev
,
2163 struct ethtool_coalesce
*ec
,
2166 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2167 struct i40e_vsi
*vsi
= np
->vsi
;
2168 struct i40e_pf
*pf
= vsi
->back
;
2172 if (ec
->tx_max_coalesced_frames_irq
|| ec
->rx_max_coalesced_frames_irq
)
2173 vsi
->work_limit
= ec
->tx_max_coalesced_frames_irq
;
2175 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2176 if (ec
->tx_coalesce_usecs_high
!= vsi
->int_rate_limit
) {
2177 netif_info(pf
, drv
, netdev
, "tx-usecs-high is not used, please program rx-usecs-high\n");
2181 if (ec
->rx_coalesce_usecs_high
> INTRL_REG_TO_USEC(I40E_MAX_INTRL
)) {
2182 netif_info(pf
, drv
, netdev
, "Invalid value, rx-usecs-high range is 0-%lu\n",
2183 INTRL_REG_TO_USEC(I40E_MAX_INTRL
));
2187 if (ec
->rx_coalesce_usecs
== 0) {
2188 if (ec
->use_adaptive_rx_coalesce
)
2189 netif_info(pf
, drv
, netdev
, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
2190 } else if ((ec
->rx_coalesce_usecs
< (I40E_MIN_ITR
<< 1)) ||
2191 (ec
->rx_coalesce_usecs
> (I40E_MAX_ITR
<< 1))) {
2192 netif_info(pf
, drv
, netdev
, "Invalid value, rx-usecs range is 0-8160\n");
2196 intrl_reg
= i40e_intrl_usec_to_reg(ec
->rx_coalesce_usecs_high
);
2197 vsi
->int_rate_limit
= INTRL_REG_TO_USEC(intrl_reg
);
2198 if (vsi
->int_rate_limit
!= ec
->rx_coalesce_usecs_high
) {
2199 netif_info(pf
, drv
, netdev
, "Interrupt rate limit rounded down to %d\n",
2200 vsi
->int_rate_limit
);
2203 if (ec
->tx_coalesce_usecs
== 0) {
2204 if (ec
->use_adaptive_tx_coalesce
)
2205 netif_info(pf
, drv
, netdev
, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
2206 } else if ((ec
->tx_coalesce_usecs
< (I40E_MIN_ITR
<< 1)) ||
2207 (ec
->tx_coalesce_usecs
> (I40E_MAX_ITR
<< 1))) {
2208 netif_info(pf
, drv
, netdev
, "Invalid value, tx-usecs range is 0-8160\n");
2212 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2213 * apply to all queues.
2216 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
2217 i40e_set_itr_per_queue(vsi
, ec
, i
);
2218 } else if (queue
< vsi
->num_queue_pairs
) {
2219 i40e_set_itr_per_queue(vsi
, ec
, queue
);
2221 netif_info(pf
, drv
, netdev
, "Invalid queue value, queue range is 0 - %d\n",
2222 vsi
->num_queue_pairs
- 1);
2230 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2231 * @netdev: the netdev to change
2232 * @ec: ethtool coalesce settings
2234 * This will set each queue to the same coalesce settings.
2236 static int i40e_set_coalesce(struct net_device
*netdev
,
2237 struct ethtool_coalesce
*ec
)
2239 return __i40e_set_coalesce(netdev
, ec
, -1);
2243 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2244 * @netdev: the netdev to change
2245 * @ec: ethtool's coalesce settings
2246 * @queue: the queue to change
2248 * Sets the specified queue's coalesce settings.
2250 static int i40e_set_per_queue_coalesce(struct net_device
*netdev
, u32 queue
,
2251 struct ethtool_coalesce
*ec
)
2253 return __i40e_set_coalesce(netdev
, ec
, queue
);
2257 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2258 * @pf: pointer to the physical function struct
2259 * @cmd: ethtool rxnfc command
2261 * Returns Success if the flow is supported, else Invalid Input.
2263 static int i40e_get_rss_hash_opts(struct i40e_pf
*pf
, struct ethtool_rxnfc
*cmd
)
2265 struct i40e_hw
*hw
= &pf
->hw
;
2271 switch (cmd
->flow_type
) {
2273 flow_pctype
= I40E_FILTER_PCTYPE_NONF_IPV4_TCP
;
2276 flow_pctype
= I40E_FILTER_PCTYPE_NONF_IPV4_UDP
;
2279 flow_pctype
= I40E_FILTER_PCTYPE_NONF_IPV6_TCP
;
2282 flow_pctype
= I40E_FILTER_PCTYPE_NONF_IPV6_UDP
;
2285 case AH_ESP_V4_FLOW
:
2290 case AH_ESP_V6_FLOW
:
2294 /* Default is src/dest for IP, no matter the L4 hashing */
2295 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
2301 /* Read flow based hash input set register */
2303 i_set
= (u64
)i40e_read_rx_ctl(hw
, I40E_GLQF_HASH_INSET(0,
2305 ((u64
)i40e_read_rx_ctl(hw
, I40E_GLQF_HASH_INSET(1,
2306 flow_pctype
)) << 32);
2309 /* Process bits of hash input set */
2311 if (i_set
& I40E_L4_SRC_MASK
)
2312 cmd
->data
|= RXH_L4_B_0_1
;
2313 if (i_set
& I40E_L4_DST_MASK
)
2314 cmd
->data
|= RXH_L4_B_2_3
;
2316 if (cmd
->flow_type
== TCP_V4_FLOW
||
2317 cmd
->flow_type
== UDP_V4_FLOW
) {
2318 if (i_set
& I40E_L3_SRC_MASK
)
2319 cmd
->data
|= RXH_IP_SRC
;
2320 if (i_set
& I40E_L3_DST_MASK
)
2321 cmd
->data
|= RXH_IP_DST
;
2322 } else if (cmd
->flow_type
== TCP_V6_FLOW
||
2323 cmd
->flow_type
== UDP_V6_FLOW
) {
2324 if (i_set
& I40E_L3_V6_SRC_MASK
)
2325 cmd
->data
|= RXH_IP_SRC
;
2326 if (i_set
& I40E_L3_V6_DST_MASK
)
2327 cmd
->data
|= RXH_IP_DST
;
2335 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2336 * @pf: Pointer to the physical function struct
2337 * @cmd: The command to get or set Rx flow classification rules
2338 * @rule_locs: Array of used rule locations
2340 * This function populates both the total and actual rule count of
2341 * the ethtool flow classification command
2343 * Returns 0 on success or -EMSGSIZE if entry not found
2345 static int i40e_get_ethtool_fdir_all(struct i40e_pf
*pf
,
2346 struct ethtool_rxnfc
*cmd
,
2349 struct i40e_fdir_filter
*rule
;
2350 struct hlist_node
*node2
;
2353 /* report total rule count */
2354 cmd
->data
= i40e_get_fd_cnt_all(pf
);
2356 hlist_for_each_entry_safe(rule
, node2
,
2357 &pf
->fdir_filter_list
, fdir_node
) {
2358 if (cnt
== cmd
->rule_cnt
)
2361 rule_locs
[cnt
] = rule
->fd_id
;
2365 cmd
->rule_cnt
= cnt
;
2371 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2372 * @pf: Pointer to the physical function struct
2373 * @cmd: The command to get or set Rx flow classification rules
2375 * This function looks up a filter based on the Rx flow classification
2376 * command and fills the flow spec info for it if found
2378 * Returns 0 on success or -EINVAL if filter not found
2380 static int i40e_get_ethtool_fdir_entry(struct i40e_pf
*pf
,
2381 struct ethtool_rxnfc
*cmd
)
2383 struct ethtool_rx_flow_spec
*fsp
=
2384 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2385 struct i40e_fdir_filter
*rule
= NULL
;
2386 struct hlist_node
*node2
;
2390 hlist_for_each_entry_safe(rule
, node2
,
2391 &pf
->fdir_filter_list
, fdir_node
) {
2392 if (fsp
->location
<= rule
->fd_id
)
2396 if (!rule
|| fsp
->location
!= rule
->fd_id
)
2399 fsp
->flow_type
= rule
->flow_type
;
2400 if (fsp
->flow_type
== IP_USER_FLOW
) {
2401 fsp
->h_u
.usr_ip4_spec
.ip_ver
= ETH_RX_NFC_IP4
;
2402 fsp
->h_u
.usr_ip4_spec
.proto
= 0;
2403 fsp
->m_u
.usr_ip4_spec
.proto
= 0;
2406 /* Reverse the src and dest notion, since the HW views them from
2407 * Tx perspective where as the user expects it from Rx filter view.
2409 fsp
->h_u
.tcp_ip4_spec
.psrc
= rule
->dst_port
;
2410 fsp
->h_u
.tcp_ip4_spec
.pdst
= rule
->src_port
;
2411 fsp
->h_u
.tcp_ip4_spec
.ip4src
= rule
->dst_ip
;
2412 fsp
->h_u
.tcp_ip4_spec
.ip4dst
= rule
->src_ip
;
2414 switch (rule
->flow_type
) {
2416 index
= I40E_FILTER_PCTYPE_NONF_IPV4_TCP
;
2419 index
= I40E_FILTER_PCTYPE_NONF_IPV4_UDP
;
2422 index
= I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
;
2425 /* If we have stored a filter with a flow type not listed here
2426 * it is almost certainly a driver bug. WARN(), and then
2427 * assign the input_set as if all fields are enabled to avoid
2428 * reading unassigned memory.
2430 WARN(1, "Missing input set index for flow_type %d\n",
2432 input_set
= 0xFFFFFFFFFFFFFFFFULL
;
2436 input_set
= i40e_read_fd_input_set(pf
, index
);
2439 if (input_set
& I40E_L3_SRC_MASK
)
2440 fsp
->m_u
.tcp_ip4_spec
.ip4src
= htonl(0xFFFF);
2442 if (input_set
& I40E_L3_DST_MASK
)
2443 fsp
->m_u
.tcp_ip4_spec
.ip4dst
= htonl(0xFFFF);
2445 if (input_set
& I40E_L4_SRC_MASK
)
2446 fsp
->m_u
.tcp_ip4_spec
.psrc
= htons(0xFFFFFFFF);
2448 if (input_set
& I40E_L4_DST_MASK
)
2449 fsp
->m_u
.tcp_ip4_spec
.pdst
= htons(0xFFFFFFFF);
2451 if (rule
->dest_ctl
== I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
)
2452 fsp
->ring_cookie
= RX_CLS_FLOW_DISC
;
2454 fsp
->ring_cookie
= rule
->q_index
;
2456 if (rule
->dest_vsi
!= pf
->vsi
[pf
->lan_vsi
]->id
) {
2457 struct i40e_vsi
*vsi
;
2459 vsi
= i40e_find_vsi_from_id(pf
, rule
->dest_vsi
);
2460 if (vsi
&& vsi
->type
== I40E_VSI_SRIOV
) {
2461 fsp
->h_ext
.data
[1] = htonl(vsi
->vf_id
);
2462 fsp
->m_ext
.data
[1] = htonl(0x1);
2470 * i40e_get_rxnfc - command to get RX flow classification rules
2471 * @netdev: network interface device structure
2472 * @cmd: ethtool rxnfc command
2474 * Returns Success if the command is supported.
2476 static int i40e_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
,
2479 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2480 struct i40e_vsi
*vsi
= np
->vsi
;
2481 struct i40e_pf
*pf
= vsi
->back
;
2482 int ret
= -EOPNOTSUPP
;
2485 case ETHTOOL_GRXRINGS
:
2486 cmd
->data
= vsi
->num_queue_pairs
;
2490 ret
= i40e_get_rss_hash_opts(pf
, cmd
);
2492 case ETHTOOL_GRXCLSRLCNT
:
2493 cmd
->rule_cnt
= pf
->fdir_pf_active_filters
;
2494 /* report total rule count */
2495 cmd
->data
= i40e_get_fd_cnt_all(pf
);
2498 case ETHTOOL_GRXCLSRULE
:
2499 ret
= i40e_get_ethtool_fdir_entry(pf
, cmd
);
2501 case ETHTOOL_GRXCLSRLALL
:
2502 ret
= i40e_get_ethtool_fdir_all(pf
, cmd
, rule_locs
);
2512 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2513 * @nfc: pointer to user request
2514 * @i_setc bits currently set
2516 * Returns value of bits to be set per user request
2518 static u64
i40e_get_rss_hash_bits(struct ethtool_rxnfc
*nfc
, u64 i_setc
)
2521 u64 src_l3
= 0, dst_l3
= 0;
2523 if (nfc
->data
& RXH_L4_B_0_1
)
2524 i_set
|= I40E_L4_SRC_MASK
;
2526 i_set
&= ~I40E_L4_SRC_MASK
;
2527 if (nfc
->data
& RXH_L4_B_2_3
)
2528 i_set
|= I40E_L4_DST_MASK
;
2530 i_set
&= ~I40E_L4_DST_MASK
;
2532 if (nfc
->flow_type
== TCP_V6_FLOW
|| nfc
->flow_type
== UDP_V6_FLOW
) {
2533 src_l3
= I40E_L3_V6_SRC_MASK
;
2534 dst_l3
= I40E_L3_V6_DST_MASK
;
2535 } else if (nfc
->flow_type
== TCP_V4_FLOW
||
2536 nfc
->flow_type
== UDP_V4_FLOW
) {
2537 src_l3
= I40E_L3_SRC_MASK
;
2538 dst_l3
= I40E_L3_DST_MASK
;
2540 /* Any other flow type are not supported here */
2544 if (nfc
->data
& RXH_IP_SRC
)
2548 if (nfc
->data
& RXH_IP_DST
)
2557 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2558 * @pf: pointer to the physical function struct
2559 * @cmd: ethtool rxnfc command
2561 * Returns Success if the flow input set is supported.
2563 static int i40e_set_rss_hash_opt(struct i40e_pf
*pf
, struct ethtool_rxnfc
*nfc
)
2565 struct i40e_hw
*hw
= &pf
->hw
;
2566 u64 hena
= (u64
)i40e_read_rx_ctl(hw
, I40E_PFQF_HENA(0)) |
2567 ((u64
)i40e_read_rx_ctl(hw
, I40E_PFQF_HENA(1)) << 32);
2571 /* RSS does not support anything other than hashing
2572 * to queues on src and dst IPs and ports
2574 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
2575 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
2578 switch (nfc
->flow_type
) {
2580 flow_pctype
= I40E_FILTER_PCTYPE_NONF_IPV4_TCP
;
2581 if (pf
->flags
& I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
)
2583 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK
);
2586 flow_pctype
= I40E_FILTER_PCTYPE_NONF_IPV6_TCP
;
2587 if (pf
->flags
& I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
)
2589 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK
);
2590 if (pf
->flags
& I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
)
2592 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK
);
2595 flow_pctype
= I40E_FILTER_PCTYPE_NONF_IPV4_UDP
;
2596 if (pf
->flags
& I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
)
2598 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP
) |
2599 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP
);
2601 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
);
2604 flow_pctype
= I40E_FILTER_PCTYPE_NONF_IPV6_UDP
;
2605 if (pf
->flags
& I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
)
2607 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP
) |
2608 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP
);
2610 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
);
2612 case AH_ESP_V4_FLOW
:
2616 if ((nfc
->data
& RXH_L4_B_0_1
) ||
2617 (nfc
->data
& RXH_L4_B_2_3
))
2619 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
);
2621 case AH_ESP_V6_FLOW
:
2625 if ((nfc
->data
& RXH_L4_B_0_1
) ||
2626 (nfc
->data
& RXH_L4_B_2_3
))
2628 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
);
2631 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
) |
2632 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
);
2635 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
) |
2636 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
);
2643 i_setc
= (u64
)i40e_read_rx_ctl(hw
, I40E_GLQF_HASH_INSET(0,
2645 ((u64
)i40e_read_rx_ctl(hw
, I40E_GLQF_HASH_INSET(1,
2646 flow_pctype
)) << 32);
2647 i_set
= i40e_get_rss_hash_bits(nfc
, i_setc
);
2648 i40e_write_rx_ctl(hw
, I40E_GLQF_HASH_INSET(0, flow_pctype
),
2650 i40e_write_rx_ctl(hw
, I40E_GLQF_HASH_INSET(1, flow_pctype
),
2651 (u32
)(i_set
>> 32));
2652 hena
|= BIT_ULL(flow_pctype
);
2655 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
2656 i40e_write_rx_ctl(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
2663 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2664 * @vsi: Pointer to the targeted VSI
2665 * @input: The filter to update or NULL to indicate deletion
2666 * @sw_idx: Software index to the filter
2667 * @cmd: The command to get or set Rx flow classification rules
2669 * This function updates (or deletes) a Flow Director entry from
2670 * the hlist of the corresponding PF
2672 * Returns 0 on success
2674 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi
*vsi
,
2675 struct i40e_fdir_filter
*input
,
2677 struct ethtool_rxnfc
*cmd
)
2679 struct i40e_fdir_filter
*rule
, *parent
;
2680 struct i40e_pf
*pf
= vsi
->back
;
2681 struct hlist_node
*node2
;
2687 hlist_for_each_entry_safe(rule
, node2
,
2688 &pf
->fdir_filter_list
, fdir_node
) {
2689 /* hash found, or no matching entry */
2690 if (rule
->fd_id
>= sw_idx
)
2695 /* if there is an old rule occupying our place remove it */
2696 if (rule
&& (rule
->fd_id
== sw_idx
)) {
2697 /* Remove this rule, since we're either deleting it, or
2700 err
= i40e_add_del_fdir(vsi
, rule
, false);
2701 hlist_del(&rule
->fdir_node
);
2703 pf
->fdir_pf_active_filters
--;
2706 /* If we weren't given an input, this is a delete, so just return the
2707 * error code indicating if there was an entry at the requested slot
2712 /* Otherwise, install the new rule as requested */
2713 INIT_HLIST_NODE(&input
->fdir_node
);
2715 /* add filter to the list */
2717 hlist_add_behind(&input
->fdir_node
, &parent
->fdir_node
);
2719 hlist_add_head(&input
->fdir_node
,
2720 &pf
->fdir_filter_list
);
2723 pf
->fdir_pf_active_filters
++;
2729 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2730 * @vsi: Pointer to the targeted VSI
2731 * @cmd: The command to get or set Rx flow classification rules
2733 * The function removes a Flow Director filter entry from the
2734 * hlist of the corresponding PF
2736 * Returns 0 on success
2738 static int i40e_del_fdir_entry(struct i40e_vsi
*vsi
,
2739 struct ethtool_rxnfc
*cmd
)
2741 struct ethtool_rx_flow_spec
*fsp
=
2742 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2743 struct i40e_pf
*pf
= vsi
->back
;
2746 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
2747 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
2750 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
2753 ret
= i40e_update_ethtool_fdir_entry(vsi
, NULL
, fsp
->location
, cmd
);
2755 i40e_fdir_check_and_reenable(pf
);
2760 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
2761 * @vsi: pointer to the targeted VSI
2762 * @fsp: pointer to Rx flow specification
2764 * Ensures that a given ethtool_rx_flow_spec has a valid mask.
2766 static int i40e_check_fdir_input_set(struct i40e_vsi
*vsi
,
2767 struct ethtool_rx_flow_spec
*fsp
)
2769 struct i40e_pf
*pf
= vsi
->back
;
2770 struct ethtool_tcpip4_spec
*tcp_ip4_spec
;
2771 struct ethtool_usrip4_spec
*usr_ip4_spec
;
2772 u64 current_mask
, new_mask
;
2775 switch (fsp
->flow_type
& ~FLOW_EXT
) {
2777 index
= I40E_FILTER_PCTYPE_NONF_IPV4_TCP
;
2780 index
= I40E_FILTER_PCTYPE_NONF_IPV4_UDP
;
2783 index
= I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
;
2789 /* Read the current input set from register memory. */
2790 current_mask
= i40e_read_fd_input_set(pf
, index
);
2791 new_mask
= current_mask
;
2793 /* Verify the provided mask is valid. */
2794 switch (fsp
->flow_type
& ~FLOW_EXT
) {
2797 tcp_ip4_spec
= &fsp
->m_u
.tcp_ip4_spec
;
2799 /* IPv4 source address */
2800 if (tcp_ip4_spec
->ip4src
== htonl(0xFFFFFFFF))
2801 new_mask
|= I40E_L3_SRC_MASK
;
2802 else if (!tcp_ip4_spec
->ip4src
)
2803 new_mask
&= ~I40E_L3_SRC_MASK
;
2807 /* IPv4 destination address */
2808 if (tcp_ip4_spec
->ip4dst
== htonl(0xFFFFFFFF))
2809 new_mask
|= I40E_L3_DST_MASK
;
2810 else if (!tcp_ip4_spec
->ip4dst
)
2811 new_mask
&= ~I40E_L3_DST_MASK
;
2815 /* L4 source port */
2816 if (tcp_ip4_spec
->psrc
== htons(0xFFFF))
2817 new_mask
|= I40E_L4_SRC_MASK
;
2818 else if (!tcp_ip4_spec
->psrc
)
2819 new_mask
&= ~I40E_L4_SRC_MASK
;
2823 /* L4 destination port */
2824 if (tcp_ip4_spec
->pdst
== htons(0xFFFF))
2825 new_mask
|= I40E_L4_DST_MASK
;
2826 else if (!tcp_ip4_spec
->pdst
)
2827 new_mask
&= ~I40E_L4_DST_MASK
;
2831 /* Filtering on Type of Service is not supported. */
2832 if (tcp_ip4_spec
->tos
)
2837 usr_ip4_spec
= &fsp
->m_u
.usr_ip4_spec
;
2839 /* IPv4 source address */
2840 if (usr_ip4_spec
->ip4src
== htonl(0xFFFFFFFF))
2841 new_mask
|= I40E_L3_SRC_MASK
;
2842 else if (!usr_ip4_spec
->ip4src
)
2843 new_mask
&= ~I40E_L3_SRC_MASK
;
2847 /* IPv4 destination address */
2848 if (usr_ip4_spec
->ip4dst
== htonl(0xFFFFFFFF))
2849 new_mask
|= I40E_L3_DST_MASK
;
2850 else if (!usr_ip4_spec
->ip4dst
)
2851 new_mask
&= ~I40E_L3_DST_MASK
;
2855 /* First 4 bytes of L4 header */
2856 if (usr_ip4_spec
->l4_4_bytes
== htonl(0xFFFFFFFF))
2857 new_mask
|= I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
;
2858 else if (!usr_ip4_spec
->l4_4_bytes
)
2859 new_mask
&= ~(I40E_L4_SRC_MASK
| I40E_L4_DST_MASK
);
2863 /* Filtering on Type of Service is not supported. */
2864 if (usr_ip4_spec
->tos
)
2867 /* IP version does not have a mask field. */
2868 if (usr_ip4_spec
->ip_ver
)
2871 /* L4 protocol doesn't have a mask field. */
2872 if (usr_ip4_spec
->proto
)
2880 if (new_mask
!= current_mask
)
2887 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2888 * @vsi: pointer to the targeted VSI
2889 * @cmd: command to get or set RX flow classification rules
2891 * Add Flow Director filters for a specific flow spec based on their
2892 * protocol. Returns 0 if the filters were successfully added.
2894 static int i40e_add_fdir_ethtool(struct i40e_vsi
*vsi
,
2895 struct ethtool_rxnfc
*cmd
)
2897 struct ethtool_rx_flow_spec
*fsp
;
2898 struct i40e_fdir_filter
*input
;
2907 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
2910 if (pf
->hw_disabled_flags
& I40E_FLAG_FD_SB_ENABLED
)
2913 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
2914 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
2917 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
2920 fsp
= (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2922 /* Extended MAC field is not supported */
2923 if (fsp
->flow_type
& FLOW_MAC_EXT
)
2926 ret
= i40e_check_fdir_input_set(vsi
, fsp
);
2930 if (fsp
->location
>= (pf
->hw
.func_caps
.fd_filters_best_effort
+
2931 pf
->hw
.func_caps
.fd_filters_guaranteed
)) {
2935 if ((fsp
->ring_cookie
!= RX_CLS_FLOW_DISC
) &&
2936 (fsp
->ring_cookie
>= vsi
->num_queue_pairs
))
2939 input
= kzalloc(sizeof(*input
), GFP_KERNEL
);
2944 input
->fd_id
= fsp
->location
;
2946 if (fsp
->ring_cookie
== RX_CLS_FLOW_DISC
)
2947 input
->dest_ctl
= I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
;
2950 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX
;
2952 input
->q_index
= fsp
->ring_cookie
;
2953 input
->flex_off
= 0;
2955 input
->dest_vsi
= vsi
->id
;
2956 input
->fd_status
= I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID
;
2957 input
->cnt_index
= I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
);
2958 input
->flow_type
= fsp
->flow_type
;
2959 input
->ip4_proto
= fsp
->h_u
.usr_ip4_spec
.proto
;
2961 /* Reverse the src and dest notion, since the HW expects them to be from
2962 * Tx perspective where as the input from user is from Rx filter view.
2964 input
->dst_port
= fsp
->h_u
.tcp_ip4_spec
.psrc
;
2965 input
->src_port
= fsp
->h_u
.tcp_ip4_spec
.pdst
;
2966 input
->dst_ip
= fsp
->h_u
.tcp_ip4_spec
.ip4src
;
2967 input
->src_ip
= fsp
->h_u
.tcp_ip4_spec
.ip4dst
;
2969 if (ntohl(fsp
->m_ext
.data
[1])) {
2970 vf_id
= ntohl(fsp
->h_ext
.data
[1]);
2971 if (vf_id
>= pf
->num_alloc_vfs
) {
2972 netif_info(pf
, drv
, vsi
->netdev
,
2973 "Invalid VF id %d\n", vf_id
);
2976 /* Find vsi id from vf id and override dest vsi */
2977 input
->dest_vsi
= pf
->vf
[vf_id
].lan_vsi_id
;
2978 if (input
->q_index
>= pf
->vf
[vf_id
].num_queue_pairs
) {
2979 netif_info(pf
, drv
, vsi
->netdev
,
2980 "Invalid queue id %d for VF %d\n",
2981 input
->q_index
, vf_id
);
2986 ret
= i40e_add_del_fdir(vsi
, input
, true);
2990 /* Add the input filter to the fdir_input_list, possibly replacing
2991 * a previous filter. Do not free the input structure after adding it
2992 * to the list as this would cause a use-after-free bug.
2994 i40e_update_ethtool_fdir_entry(vsi
, input
, fsp
->location
, NULL
);
3004 * i40e_set_rxnfc - command to set RX flow classification rules
3005 * @netdev: network interface device structure
3006 * @cmd: ethtool rxnfc command
3008 * Returns Success if the command is supported.
3010 static int i40e_set_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
)
3012 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3013 struct i40e_vsi
*vsi
= np
->vsi
;
3014 struct i40e_pf
*pf
= vsi
->back
;
3015 int ret
= -EOPNOTSUPP
;
3019 ret
= i40e_set_rss_hash_opt(pf
, cmd
);
3021 case ETHTOOL_SRXCLSRLINS
:
3022 ret
= i40e_add_fdir_ethtool(vsi
, cmd
);
3024 case ETHTOOL_SRXCLSRLDEL
:
3025 ret
= i40e_del_fdir_entry(vsi
, cmd
);
3035 * i40e_max_channels - get Max number of combined channels supported
3038 static unsigned int i40e_max_channels(struct i40e_vsi
*vsi
)
3040 /* TODO: This code assumes DCB and FD is disabled for now. */
3041 return vsi
->alloc_queue_pairs
;
3045 * i40e_get_channels - Get the current channels enabled and max supported etc.
3046 * @netdev: network interface device structure
3047 * @ch: ethtool channels structure
3049 * We don't support separate tx and rx queues as channels. The other count
3050 * represents how many queues are being used for control. max_combined counts
3051 * how many queue pairs we can support. They may not be mapped 1 to 1 with
3052 * q_vectors since we support a lot more queue pairs than q_vectors.
3054 static void i40e_get_channels(struct net_device
*dev
,
3055 struct ethtool_channels
*ch
)
3057 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
3058 struct i40e_vsi
*vsi
= np
->vsi
;
3059 struct i40e_pf
*pf
= vsi
->back
;
3061 /* report maximum channels */
3062 ch
->max_combined
= i40e_max_channels(vsi
);
3064 /* report info for other vector */
3065 ch
->other_count
= (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) ? 1 : 0;
3066 ch
->max_other
= ch
->other_count
;
3068 /* Note: This code assumes DCB is disabled for now. */
3069 ch
->combined_count
= vsi
->num_queue_pairs
;
3073 * i40e_set_channels - Set the new channels count.
3074 * @netdev: network interface device structure
3075 * @ch: ethtool channels structure
3077 * The new channels count may not be the same as requested by the user
3078 * since it gets rounded down to a power of 2 value.
3080 static int i40e_set_channels(struct net_device
*dev
,
3081 struct ethtool_channels
*ch
)
3083 const u8 drop
= I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
;
3084 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
3085 unsigned int count
= ch
->combined_count
;
3086 struct i40e_vsi
*vsi
= np
->vsi
;
3087 struct i40e_pf
*pf
= vsi
->back
;
3088 struct i40e_fdir_filter
*rule
;
3089 struct hlist_node
*node2
;
3093 /* We do not support setting channels for any other VSI at present */
3094 if (vsi
->type
!= I40E_VSI_MAIN
)
3097 /* verify they are not requesting separate vectors */
3098 if (!count
|| ch
->rx_count
|| ch
->tx_count
)
3101 /* verify other_count has not changed */
3102 if (ch
->other_count
!= ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) ? 1 : 0))
3105 /* verify the number of channels does not exceed hardware limits */
3106 if (count
> i40e_max_channels(vsi
))
3109 /* verify that the number of channels does not invalidate any current
3110 * flow director rules
3112 hlist_for_each_entry_safe(rule
, node2
,
3113 &pf
->fdir_filter_list
, fdir_node
) {
3114 if (rule
->dest_ctl
!= drop
&& count
<= rule
->q_index
) {
3115 dev_warn(&pf
->pdev
->dev
,
3116 "Existing user defined filter %d assigns flow to queue %d\n",
3117 rule
->fd_id
, rule
->q_index
);
3123 dev_err(&pf
->pdev
->dev
,
3124 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
3129 /* update feature limits from largest to smallest supported values */
3130 /* TODO: Flow director limit, DCB etc */
3132 /* use rss_reconfig to rebuild with new queue count and update traffic
3133 * class queue mapping
3135 new_count
= i40e_reconfig_rss_queues(pf
, count
);
3143 * i40e_get_rxfh_key_size - get the RSS hash key size
3144 * @netdev: network interface device structure
3146 * Returns the table size.
3148 static u32
i40e_get_rxfh_key_size(struct net_device
*netdev
)
3150 return I40E_HKEY_ARRAY_SIZE
;
3154 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
3155 * @netdev: network interface device structure
3157 * Returns the table size.
3159 static u32
i40e_get_rxfh_indir_size(struct net_device
*netdev
)
3161 return I40E_HLUT_ARRAY_SIZE
;
3164 static int i40e_get_rxfh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
3167 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3168 struct i40e_vsi
*vsi
= np
->vsi
;
3169 u8
*lut
, *seed
= NULL
;
3174 *hfunc
= ETH_RSS_HASH_TOP
;
3180 lut
= kzalloc(I40E_HLUT_ARRAY_SIZE
, GFP_KERNEL
);
3183 ret
= i40e_get_rss(vsi
, seed
, lut
, I40E_HLUT_ARRAY_SIZE
);
3186 for (i
= 0; i
< I40E_HLUT_ARRAY_SIZE
; i
++)
3187 indir
[i
] = (u32
)(lut
[i
]);
3196 * i40e_set_rxfh - set the rx flow hash indirection table
3197 * @netdev: network interface device structure
3198 * @indir: indirection table
3201 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
3202 * returns 0 after programming the table.
3204 static int i40e_set_rxfh(struct net_device
*netdev
, const u32
*indir
,
3205 const u8
*key
, const u8 hfunc
)
3207 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
3208 struct i40e_vsi
*vsi
= np
->vsi
;
3209 struct i40e_pf
*pf
= vsi
->back
;
3213 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
3217 if (!vsi
->rss_hkey_user
) {
3218 vsi
->rss_hkey_user
= kzalloc(I40E_HKEY_ARRAY_SIZE
,
3220 if (!vsi
->rss_hkey_user
)
3223 memcpy(vsi
->rss_hkey_user
, key
, I40E_HKEY_ARRAY_SIZE
);
3224 seed
= vsi
->rss_hkey_user
;
3226 if (!vsi
->rss_lut_user
) {
3227 vsi
->rss_lut_user
= kzalloc(I40E_HLUT_ARRAY_SIZE
, GFP_KERNEL
);
3228 if (!vsi
->rss_lut_user
)
3232 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3234 for (i
= 0; i
< I40E_HLUT_ARRAY_SIZE
; i
++)
3235 vsi
->rss_lut_user
[i
] = (u8
)(indir
[i
]);
3237 i40e_fill_rss_lut(pf
, vsi
->rss_lut_user
, I40E_HLUT_ARRAY_SIZE
,
3240 return i40e_config_rss(vsi
, seed
, vsi
->rss_lut_user
,
3241 I40E_HLUT_ARRAY_SIZE
);
3245 * i40e_get_priv_flags - report device private flags
3246 * @dev: network interface device structure
3248 * The get string set count and the string set should be matched for each
3249 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
3252 * Returns a u32 bitmap of flags.
3254 static u32
i40e_get_priv_flags(struct net_device
*dev
)
3256 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
3257 struct i40e_vsi
*vsi
= np
->vsi
;
3258 struct i40e_pf
*pf
= vsi
->back
;
3261 ret_flags
|= pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
?
3262 I40E_PRIV_FLAGS_LINKPOLL_FLAG
: 0;
3263 ret_flags
|= pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
?
3264 I40E_PRIV_FLAGS_FD_ATR
: 0;
3265 ret_flags
|= pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
?
3266 I40E_PRIV_FLAGS_VEB_STATS
: 0;
3267 ret_flags
|= pf
->hw_disabled_flags
& I40E_FLAG_HW_ATR_EVICT_CAPABLE
?
3268 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT
;
3269 if (pf
->hw
.pf_id
== 0) {
3270 ret_flags
|= pf
->flags
& I40E_FLAG_TRUE_PROMISC_SUPPORT
?
3271 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT
: 0;
3278 * i40e_set_priv_flags - set private flags
3279 * @dev: network interface device structure
3280 * @flags: bit flags to be set
3282 static int i40e_set_priv_flags(struct net_device
*dev
, u32 flags
)
3284 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
3285 struct i40e_vsi
*vsi
= np
->vsi
;
3286 struct i40e_pf
*pf
= vsi
->back
;
3287 u16 sw_flags
= 0, valid_flags
= 0;
3288 bool reset_required
= false;
3289 bool promisc_change
= false;
3292 /* NOTE: MFP is not settable */
3294 if (flags
& I40E_PRIV_FLAGS_LINKPOLL_FLAG
)
3295 pf
->flags
|= I40E_FLAG_LINK_POLLING_ENABLED
;
3297 pf
->flags
&= ~I40E_FLAG_LINK_POLLING_ENABLED
;
3299 /* allow the user to control the state of the Flow
3300 * Director ATR (Application Targeted Routing) feature
3303 if (flags
& I40E_PRIV_FLAGS_FD_ATR
) {
3304 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
3306 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
3307 pf
->hw_disabled_flags
|= I40E_FLAG_FD_ATR_ENABLED
;
3309 /* flush current ATR settings */
3310 set_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
);
3313 if ((flags
& I40E_PRIV_FLAGS_VEB_STATS
) &&
3314 !(pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
3315 pf
->flags
|= I40E_FLAG_VEB_STATS_ENABLED
;
3316 reset_required
= true;
3317 } else if (!(flags
& I40E_PRIV_FLAGS_VEB_STATS
) &&
3318 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
3319 pf
->flags
&= ~I40E_FLAG_VEB_STATS_ENABLED
;
3320 reset_required
= true;
3323 if (pf
->hw
.pf_id
== 0) {
3324 if ((flags
& I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT
) &&
3325 !(pf
->flags
& I40E_FLAG_TRUE_PROMISC_SUPPORT
)) {
3326 pf
->flags
|= I40E_FLAG_TRUE_PROMISC_SUPPORT
;
3327 promisc_change
= true;
3328 } else if (!(flags
& I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT
) &&
3329 (pf
->flags
& I40E_FLAG_TRUE_PROMISC_SUPPORT
)) {
3330 pf
->flags
&= ~I40E_FLAG_TRUE_PROMISC_SUPPORT
;
3331 promisc_change
= true;
3334 if (promisc_change
) {
3335 if (!(pf
->flags
& I40E_FLAG_TRUE_PROMISC_SUPPORT
))
3336 sw_flags
= I40E_AQ_SET_SWITCH_CFG_PROMISC
;
3337 valid_flags
= I40E_AQ_SET_SWITCH_CFG_PROMISC
;
3338 ret
= i40e_aq_set_switch_config(&pf
->hw
, sw_flags
, valid_flags
,
3340 if (ret
&& pf
->hw
.aq
.asq_last_status
!= I40E_AQ_RC_ESRCH
) {
3341 dev_info(&pf
->pdev
->dev
,
3342 "couldn't set switch config bits, err %s aq_err %s\n",
3343 i40e_stat_str(&pf
->hw
, ret
),
3344 i40e_aq_str(&pf
->hw
,
3345 pf
->hw
.aq
.asq_last_status
));
3346 /* not a fatal problem, just keep going */
3350 if ((flags
& I40E_PRIV_FLAGS_HW_ATR_EVICT
) &&
3351 (pf
->flags
& I40E_FLAG_HW_ATR_EVICT_CAPABLE
))
3352 pf
->hw_disabled_flags
&= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE
;
3354 pf
->hw_disabled_flags
|= I40E_FLAG_HW_ATR_EVICT_CAPABLE
;
3356 /* if needed, issue reset to cause things to take effect */
3358 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
3363 static const struct ethtool_ops i40e_ethtool_ops
= {
3364 .get_drvinfo
= i40e_get_drvinfo
,
3365 .get_regs_len
= i40e_get_regs_len
,
3366 .get_regs
= i40e_get_regs
,
3367 .nway_reset
= i40e_nway_reset
,
3368 .get_link
= ethtool_op_get_link
,
3369 .get_wol
= i40e_get_wol
,
3370 .set_wol
= i40e_set_wol
,
3371 .set_eeprom
= i40e_set_eeprom
,
3372 .get_eeprom_len
= i40e_get_eeprom_len
,
3373 .get_eeprom
= i40e_get_eeprom
,
3374 .get_ringparam
= i40e_get_ringparam
,
3375 .set_ringparam
= i40e_set_ringparam
,
3376 .get_pauseparam
= i40e_get_pauseparam
,
3377 .set_pauseparam
= i40e_set_pauseparam
,
3378 .get_msglevel
= i40e_get_msglevel
,
3379 .set_msglevel
= i40e_set_msglevel
,
3380 .get_rxnfc
= i40e_get_rxnfc
,
3381 .set_rxnfc
= i40e_set_rxnfc
,
3382 .self_test
= i40e_diag_test
,
3383 .get_strings
= i40e_get_strings
,
3384 .set_phys_id
= i40e_set_phys_id
,
3385 .get_sset_count
= i40e_get_sset_count
,
3386 .get_ethtool_stats
= i40e_get_ethtool_stats
,
3387 .get_coalesce
= i40e_get_coalesce
,
3388 .set_coalesce
= i40e_set_coalesce
,
3389 .get_rxfh_key_size
= i40e_get_rxfh_key_size
,
3390 .get_rxfh_indir_size
= i40e_get_rxfh_indir_size
,
3391 .get_rxfh
= i40e_get_rxfh
,
3392 .set_rxfh
= i40e_set_rxfh
,
3393 .get_channels
= i40e_get_channels
,
3394 .set_channels
= i40e_set_channels
,
3395 .get_ts_info
= i40e_get_ts_info
,
3396 .get_priv_flags
= i40e_get_priv_flags
,
3397 .set_priv_flags
= i40e_set_priv_flags
,
3398 .get_per_queue_coalesce
= i40e_get_per_queue_coalesce
,
3399 .set_per_queue_coalesce
= i40e_set_per_queue_coalesce
,
3400 .get_link_ksettings
= i40e_get_link_ksettings
,
3401 .set_link_ksettings
= i40e_set_link_ksettings
,
3404 void i40e_set_ethtool_ops(struct net_device
*netdev
)
3406 netdev
->ethtool_ops
= &i40e_ethtool_ops
;