1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 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
),
94 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
104 static struct i40e_stats i40e_gstrings_stats
[] = {
105 I40E_PF_STAT("rx_bytes", stats
.eth
.rx_bytes
),
106 I40E_PF_STAT("tx_bytes", stats
.eth
.tx_bytes
),
107 I40E_PF_STAT("rx_unicast", stats
.eth
.rx_unicast
),
108 I40E_PF_STAT("tx_unicast", stats
.eth
.tx_unicast
),
109 I40E_PF_STAT("rx_multicast", stats
.eth
.rx_multicast
),
110 I40E_PF_STAT("tx_multicast", stats
.eth
.tx_multicast
),
111 I40E_PF_STAT("rx_broadcast", stats
.eth
.rx_broadcast
),
112 I40E_PF_STAT("tx_broadcast", stats
.eth
.tx_broadcast
),
113 I40E_PF_STAT("tx_errors", stats
.eth
.tx_errors
),
114 I40E_PF_STAT("rx_dropped", stats
.eth
.rx_discards
),
115 I40E_PF_STAT("tx_dropped_link_down", stats
.tx_dropped_link_down
),
116 I40E_PF_STAT("rx_crc_errors", stats
.crc_errors
),
117 I40E_PF_STAT("illegal_bytes", stats
.illegal_bytes
),
118 I40E_PF_STAT("mac_local_faults", stats
.mac_local_faults
),
119 I40E_PF_STAT("mac_remote_faults", stats
.mac_remote_faults
),
120 I40E_PF_STAT("tx_timeout", tx_timeout_count
),
121 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error
),
122 I40E_PF_STAT("rx_length_errors", stats
.rx_length_errors
),
123 I40E_PF_STAT("link_xon_rx", stats
.link_xon_rx
),
124 I40E_PF_STAT("link_xoff_rx", stats
.link_xoff_rx
),
125 I40E_PF_STAT("link_xon_tx", stats
.link_xon_tx
),
126 I40E_PF_STAT("link_xoff_tx", stats
.link_xoff_tx
),
127 I40E_PF_STAT("rx_size_64", stats
.rx_size_64
),
128 I40E_PF_STAT("rx_size_127", stats
.rx_size_127
),
129 I40E_PF_STAT("rx_size_255", stats
.rx_size_255
),
130 I40E_PF_STAT("rx_size_511", stats
.rx_size_511
),
131 I40E_PF_STAT("rx_size_1023", stats
.rx_size_1023
),
132 I40E_PF_STAT("rx_size_1522", stats
.rx_size_1522
),
133 I40E_PF_STAT("rx_size_big", stats
.rx_size_big
),
134 I40E_PF_STAT("tx_size_64", stats
.tx_size_64
),
135 I40E_PF_STAT("tx_size_127", stats
.tx_size_127
),
136 I40E_PF_STAT("tx_size_255", stats
.tx_size_255
),
137 I40E_PF_STAT("tx_size_511", stats
.tx_size_511
),
138 I40E_PF_STAT("tx_size_1023", stats
.tx_size_1023
),
139 I40E_PF_STAT("tx_size_1522", stats
.tx_size_1522
),
140 I40E_PF_STAT("tx_size_big", stats
.tx_size_big
),
141 I40E_PF_STAT("rx_undersize", stats
.rx_undersize
),
142 I40E_PF_STAT("rx_fragments", stats
.rx_fragments
),
143 I40E_PF_STAT("rx_oversize", stats
.rx_oversize
),
144 I40E_PF_STAT("rx_jabber", stats
.rx_jabber
),
145 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests
),
146 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared
),
147 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt
),
148 I40E_PF_STAT("fdir_atr_match", stats
.fd_atr_match
),
149 I40E_PF_STAT("fdir_atr_tunnel_match", stats
.fd_atr_tunnel_match
),
150 I40E_PF_STAT("fdir_atr_status", stats
.fd_atr_status
),
151 I40E_PF_STAT("fdir_sb_match", stats
.fd_sb_match
),
152 I40E_PF_STAT("fdir_sb_status", stats
.fd_sb_status
),
155 I40E_PF_STAT("tx_lpi_status", stats
.tx_lpi_status
),
156 I40E_PF_STAT("rx_lpi_status", stats
.rx_lpi_status
),
157 I40E_PF_STAT("tx_lpi_count", stats
.tx_lpi_count
),
158 I40E_PF_STAT("rx_lpi_count", stats
.rx_lpi_count
),
162 static const struct i40e_stats i40e_gstrings_fcoe_stats
[] = {
163 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats
.fcoe_bad_fccrc
),
164 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats
.rx_fcoe_dropped
),
165 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats
.rx_fcoe_packets
),
166 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats
.rx_fcoe_dwords
),
167 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats
.fcoe_ddp_count
),
168 I40E_VSI_STAT("fcoe_last_error", fcoe_stats
.fcoe_last_error
),
169 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats
.tx_fcoe_packets
),
170 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats
.tx_fcoe_dwords
),
173 #endif /* I40E_FCOE */
174 #define I40E_QUEUE_STATS_LEN(n) \
175 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
176 * 2 /* Tx and Rx together */ \
177 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
178 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
179 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
180 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
182 #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
183 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
184 I40E_FCOE_STATS_LEN + \
185 I40E_MISC_STATS_LEN + \
186 I40E_QUEUE_STATS_LEN((n)))
188 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
189 I40E_MISC_STATS_LEN + \
190 I40E_QUEUE_STATS_LEN((n)))
191 #endif /* I40E_FCOE */
192 #define I40E_PFC_STATS_LEN ( \
193 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
199 #define I40E_VEB_TC_STATS_LEN ( \
200 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
201 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
205 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
206 #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
207 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
208 I40E_PFC_STATS_LEN + \
209 I40E_VSI_STATS_LEN((n)))
211 enum i40e_ethtool_test_id
{
212 I40E_ETH_TEST_REG
= 0,
213 I40E_ETH_TEST_EEPROM
,
215 I40E_ETH_TEST_LOOPBACK
,
219 static const char i40e_gstrings_test
[][ETH_GSTRING_LEN
] = {
220 "Register test (offline)",
221 "Eeprom test (offline)",
222 "Interrupt test (offline)",
223 "Loopback test (offline)",
224 "Link test (on/offline)"
227 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
229 static const char i40e_priv_flags_strings
[][ETH_GSTRING_LEN
] = {
237 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
240 * i40e_partition_setting_complaint - generic complaint for MFP restriction
243 static void i40e_partition_setting_complaint(struct i40e_pf
*pf
)
245 dev_info(&pf
->pdev
->dev
,
246 "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");
250 * i40e_get_settings_link_up - Get the Link settings for when link is up
252 * @ecmd: ethtool command to fill in
253 * @netdev: network interface device structure
256 static void i40e_get_settings_link_up(struct i40e_hw
*hw
,
257 struct ethtool_cmd
*ecmd
,
258 struct net_device
*netdev
,
261 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
262 u32 link_speed
= hw_link_info
->link_speed
;
264 /* Initialize supported and advertised settings based on phy settings */
265 switch (hw_link_info
->phy_type
) {
266 case I40E_PHY_TYPE_40GBASE_CR4
:
267 case I40E_PHY_TYPE_40GBASE_CR4_CU
:
268 ecmd
->supported
= SUPPORTED_Autoneg
|
269 SUPPORTED_40000baseCR4_Full
;
270 ecmd
->advertising
= ADVERTISED_Autoneg
|
271 ADVERTISED_40000baseCR4_Full
;
273 case I40E_PHY_TYPE_XLAUI
:
274 case I40E_PHY_TYPE_XLPPI
:
275 case I40E_PHY_TYPE_40GBASE_AOC
:
276 ecmd
->supported
= SUPPORTED_40000baseCR4_Full
;
278 case I40E_PHY_TYPE_40GBASE_SR4
:
279 ecmd
->supported
= SUPPORTED_40000baseSR4_Full
;
281 case I40E_PHY_TYPE_40GBASE_LR4
:
282 ecmd
->supported
= SUPPORTED_40000baseLR4_Full
;
284 case I40E_PHY_TYPE_10GBASE_SR
:
285 case I40E_PHY_TYPE_10GBASE_LR
:
286 case I40E_PHY_TYPE_1000BASE_SX
:
287 case I40E_PHY_TYPE_1000BASE_LX
:
288 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
289 if (hw_link_info
->module_type
[2] &
290 I40E_MODULE_TYPE_1000BASE_SX
||
291 hw_link_info
->module_type
[2] &
292 I40E_MODULE_TYPE_1000BASE_LX
) {
293 ecmd
->supported
|= SUPPORTED_1000baseT_Full
;
294 if (hw_link_info
->requested_speeds
&
296 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
298 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
299 ecmd
->advertising
|= ADVERTISED_10000baseT_Full
;
301 case I40E_PHY_TYPE_10GBASE_T
:
302 case I40E_PHY_TYPE_1000BASE_T
:
303 ecmd
->supported
= SUPPORTED_Autoneg
|
304 SUPPORTED_10000baseT_Full
|
305 SUPPORTED_1000baseT_Full
;
306 ecmd
->advertising
= ADVERTISED_Autoneg
;
307 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
308 ecmd
->advertising
|= ADVERTISED_10000baseT_Full
;
309 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
310 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
312 case I40E_PHY_TYPE_1000BASE_T_OPTICAL
:
313 ecmd
->supported
= SUPPORTED_Autoneg
|
314 SUPPORTED_1000baseT_Full
;
315 ecmd
->advertising
= ADVERTISED_Autoneg
|
316 ADVERTISED_1000baseT_Full
;
318 case I40E_PHY_TYPE_100BASE_TX
:
319 ecmd
->supported
= SUPPORTED_Autoneg
|
320 SUPPORTED_100baseT_Full
;
321 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_100MB
)
322 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
324 case I40E_PHY_TYPE_10GBASE_CR1_CU
:
325 case I40E_PHY_TYPE_10GBASE_CR1
:
326 ecmd
->supported
= SUPPORTED_Autoneg
|
327 SUPPORTED_10000baseT_Full
;
328 ecmd
->advertising
= ADVERTISED_Autoneg
|
329 ADVERTISED_10000baseT_Full
;
331 case I40E_PHY_TYPE_XAUI
:
332 case I40E_PHY_TYPE_XFI
:
333 case I40E_PHY_TYPE_SFI
:
334 case I40E_PHY_TYPE_10GBASE_SFPP_CU
:
335 case I40E_PHY_TYPE_10GBASE_AOC
:
336 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
338 case I40E_PHY_TYPE_SGMII
:
339 ecmd
->supported
= SUPPORTED_Autoneg
|
340 SUPPORTED_1000baseT_Full
;
341 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
342 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
343 if (pf
->hw
.mac
.type
== I40E_MAC_X722
) {
344 ecmd
->supported
|= SUPPORTED_100baseT_Full
;
345 if (hw_link_info
->requested_speeds
&
346 I40E_LINK_SPEED_100MB
)
347 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
350 /* Backplane is set based on supported phy types in get_settings
351 * so don't set anything here but don't warn either
353 case I40E_PHY_TYPE_40GBASE_KR4
:
354 case I40E_PHY_TYPE_20GBASE_KR2
:
355 case I40E_PHY_TYPE_10GBASE_KR
:
356 case I40E_PHY_TYPE_10GBASE_KX4
:
357 case I40E_PHY_TYPE_1000BASE_KX
:
360 /* if we got here and link is up something bad is afoot */
361 netdev_info(netdev
, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
362 hw_link_info
->phy_type
);
365 /* Set speed and duplex */
366 switch (link_speed
) {
367 case I40E_LINK_SPEED_40GB
:
368 ethtool_cmd_speed_set(ecmd
, SPEED_40000
);
370 case I40E_LINK_SPEED_20GB
:
371 ethtool_cmd_speed_set(ecmd
, SPEED_20000
);
373 case I40E_LINK_SPEED_10GB
:
374 ethtool_cmd_speed_set(ecmd
, SPEED_10000
);
376 case I40E_LINK_SPEED_1GB
:
377 ethtool_cmd_speed_set(ecmd
, SPEED_1000
);
379 case I40E_LINK_SPEED_100MB
:
380 ethtool_cmd_speed_set(ecmd
, SPEED_100
);
385 ecmd
->duplex
= DUPLEX_FULL
;
389 * i40e_get_settings_link_down - Get the Link settings for when link is down
391 * @ecmd: ethtool command to fill in
393 * Reports link settings that can be determined when link is down
395 static void i40e_get_settings_link_down(struct i40e_hw
*hw
,
396 struct ethtool_cmd
*ecmd
,
399 enum i40e_aq_capabilities_phy_type phy_types
= hw
->phy
.phy_types
;
401 /* link is down and the driver needs to fall back on
402 * supported phy types to figure out what info to display
404 ecmd
->supported
= 0x0;
405 ecmd
->advertising
= 0x0;
406 if (phy_types
& I40E_CAP_PHY_TYPE_SGMII
) {
407 ecmd
->supported
|= SUPPORTED_Autoneg
|
408 SUPPORTED_1000baseT_Full
;
409 ecmd
->advertising
|= ADVERTISED_Autoneg
|
410 ADVERTISED_1000baseT_Full
;
411 if (pf
->hw
.mac
.type
== I40E_MAC_X722
) {
412 ecmd
->supported
|= SUPPORTED_100baseT_Full
;
413 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
416 if (phy_types
& I40E_CAP_PHY_TYPE_XAUI
||
417 phy_types
& I40E_CAP_PHY_TYPE_XFI
||
418 phy_types
& I40E_CAP_PHY_TYPE_SFI
||
419 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU
||
420 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_AOC
)
421 ecmd
->supported
|= SUPPORTED_10000baseT_Full
;
422 if (phy_types
& I40E_CAP_PHY_TYPE_10GBASE_CR1_CU
||
423 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_CR1
||
424 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_T
||
425 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_SR
||
426 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_LR
) {
427 ecmd
->supported
|= SUPPORTED_Autoneg
|
428 SUPPORTED_10000baseT_Full
;
429 ecmd
->advertising
|= ADVERTISED_Autoneg
|
430 ADVERTISED_10000baseT_Full
;
432 if (phy_types
& I40E_CAP_PHY_TYPE_XLAUI
||
433 phy_types
& I40E_CAP_PHY_TYPE_XLPPI
||
434 phy_types
& I40E_CAP_PHY_TYPE_40GBASE_AOC
)
435 ecmd
->supported
|= SUPPORTED_40000baseCR4_Full
;
436 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_CR4_CU
||
437 phy_types
& I40E_CAP_PHY_TYPE_40GBASE_CR4
) {
438 ecmd
->supported
|= SUPPORTED_Autoneg
|
439 SUPPORTED_40000baseCR4_Full
;
440 ecmd
->advertising
|= ADVERTISED_Autoneg
|
441 ADVERTISED_40000baseCR4_Full
;
443 if ((phy_types
& I40E_CAP_PHY_TYPE_100BASE_TX
) &&
444 !(phy_types
& I40E_CAP_PHY_TYPE_1000BASE_T
)) {
445 ecmd
->supported
|= SUPPORTED_Autoneg
|
446 SUPPORTED_100baseT_Full
;
447 ecmd
->advertising
|= ADVERTISED_Autoneg
|
448 ADVERTISED_100baseT_Full
;
450 if (phy_types
& I40E_CAP_PHY_TYPE_1000BASE_T
||
451 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_SX
||
452 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_LX
||
453 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL
) {
454 ecmd
->supported
|= SUPPORTED_Autoneg
|
455 SUPPORTED_1000baseT_Full
;
456 ecmd
->advertising
|= ADVERTISED_Autoneg
|
457 ADVERTISED_1000baseT_Full
;
459 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_SR4
)
460 ecmd
->supported
|= SUPPORTED_40000baseSR4_Full
;
461 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_LR4
)
462 ecmd
->supported
|= SUPPORTED_40000baseLR4_Full
;
464 /* With no link speed and duplex are unknown */
465 ethtool_cmd_speed_set(ecmd
, SPEED_UNKNOWN
);
466 ecmd
->duplex
= DUPLEX_UNKNOWN
;
470 * i40e_get_settings - Get Link Speed and Duplex settings
471 * @netdev: network interface device structure
472 * @ecmd: ethtool command
474 * Reports speed/duplex settings based on media_type
476 static int i40e_get_settings(struct net_device
*netdev
,
477 struct ethtool_cmd
*ecmd
)
479 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
480 struct i40e_pf
*pf
= np
->vsi
->back
;
481 struct i40e_hw
*hw
= &pf
->hw
;
482 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
483 bool link_up
= hw_link_info
->link_info
& I40E_AQ_LINK_UP
;
486 i40e_get_settings_link_up(hw
, ecmd
, netdev
, pf
);
488 i40e_get_settings_link_down(hw
, ecmd
, pf
);
490 /* Now set the settings that don't rely on link being up/down */
492 /* For backplane, supported and advertised are only reliant on the
493 * phy types the NVM specifies are supported.
495 if (hw
->device_id
== I40E_DEV_ID_KX_B
||
496 hw
->device_id
== I40E_DEV_ID_KX_C
||
497 hw
->device_id
== I40E_DEV_ID_20G_KR2
||
498 hw
->device_id
== I40E_DEV_ID_20G_KR2_A
) {
499 ecmd
->supported
= SUPPORTED_Autoneg
;
500 ecmd
->advertising
= ADVERTISED_Autoneg
;
501 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_40GBASE_KR4
) {
502 ecmd
->supported
|= SUPPORTED_40000baseKR4_Full
;
503 ecmd
->advertising
|= ADVERTISED_40000baseKR4_Full
;
505 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_20GBASE_KR2
) {
506 ecmd
->supported
|= SUPPORTED_20000baseKR2_Full
;
507 ecmd
->advertising
|= ADVERTISED_20000baseKR2_Full
;
509 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_10GBASE_KR
) {
510 ecmd
->supported
|= SUPPORTED_10000baseKR_Full
;
511 ecmd
->advertising
|= ADVERTISED_10000baseKR_Full
;
513 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_10GBASE_KX4
) {
514 ecmd
->supported
|= SUPPORTED_10000baseKX4_Full
;
515 ecmd
->advertising
|= ADVERTISED_10000baseKX4_Full
;
517 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_1000BASE_KX
) {
518 ecmd
->supported
|= SUPPORTED_1000baseKX_Full
;
519 ecmd
->advertising
|= ADVERTISED_1000baseKX_Full
;
523 /* Set autoneg settings */
524 ecmd
->autoneg
= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
525 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
527 switch (hw
->phy
.media_type
) {
528 case I40E_MEDIA_TYPE_BACKPLANE
:
529 ecmd
->supported
|= SUPPORTED_Autoneg
|
531 ecmd
->advertising
|= ADVERTISED_Autoneg
|
532 ADVERTISED_Backplane
;
533 ecmd
->port
= PORT_NONE
;
535 case I40E_MEDIA_TYPE_BASET
:
536 ecmd
->supported
|= SUPPORTED_TP
;
537 ecmd
->advertising
|= ADVERTISED_TP
;
538 ecmd
->port
= PORT_TP
;
540 case I40E_MEDIA_TYPE_DA
:
541 case I40E_MEDIA_TYPE_CX4
:
542 ecmd
->supported
|= SUPPORTED_FIBRE
;
543 ecmd
->advertising
|= ADVERTISED_FIBRE
;
544 ecmd
->port
= PORT_DA
;
546 case I40E_MEDIA_TYPE_FIBER
:
547 ecmd
->supported
|= SUPPORTED_FIBRE
;
548 ecmd
->port
= PORT_FIBRE
;
550 case I40E_MEDIA_TYPE_UNKNOWN
:
552 ecmd
->port
= PORT_OTHER
;
556 /* Set transceiver */
557 ecmd
->transceiver
= XCVR_EXTERNAL
;
559 /* Set flow control settings */
560 ecmd
->supported
|= SUPPORTED_Pause
;
562 switch (hw
->fc
.requested_mode
) {
564 ecmd
->advertising
|= ADVERTISED_Pause
;
566 case I40E_FC_TX_PAUSE
:
567 ecmd
->advertising
|= ADVERTISED_Asym_Pause
;
569 case I40E_FC_RX_PAUSE
:
570 ecmd
->advertising
|= (ADVERTISED_Pause
|
571 ADVERTISED_Asym_Pause
);
574 ecmd
->advertising
&= ~(ADVERTISED_Pause
|
575 ADVERTISED_Asym_Pause
);
583 * i40e_set_settings - Set Speed and Duplex
584 * @netdev: network interface device structure
585 * @ecmd: ethtool command
587 * Set speed/duplex per media_types advertised/forced
589 static int i40e_set_settings(struct net_device
*netdev
,
590 struct ethtool_cmd
*ecmd
)
592 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
593 struct i40e_aq_get_phy_abilities_resp abilities
;
594 struct i40e_aq_set_phy_config config
;
595 struct i40e_pf
*pf
= np
->vsi
->back
;
596 struct i40e_vsi
*vsi
= np
->vsi
;
597 struct i40e_hw
*hw
= &pf
->hw
;
598 struct ethtool_cmd safe_ecmd
;
599 i40e_status status
= 0;
605 /* Changing port settings is not supported if this isn't the
606 * port's controlling PF
608 if (hw
->partition_id
!= 1) {
609 i40e_partition_setting_complaint(pf
);
613 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
616 if (hw
->phy
.media_type
!= I40E_MEDIA_TYPE_BASET
&&
617 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_FIBER
&&
618 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_BACKPLANE
&&
619 hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
)
622 if (hw
->device_id
== I40E_DEV_ID_KX_B
||
623 hw
->device_id
== I40E_DEV_ID_KX_C
||
624 hw
->device_id
== I40E_DEV_ID_20G_KR2
||
625 hw
->device_id
== I40E_DEV_ID_20G_KR2_A
) {
626 netdev_info(netdev
, "Changing settings is not supported on backplane.\n");
630 /* get our own copy of the bits to check against */
631 memset(&safe_ecmd
, 0, sizeof(struct ethtool_cmd
));
632 i40e_get_settings(netdev
, &safe_ecmd
);
634 /* save autoneg and speed out of ecmd */
635 autoneg
= ecmd
->autoneg
;
636 advertise
= ecmd
->advertising
;
638 /* set autoneg and speed back to what they currently are */
639 ecmd
->autoneg
= safe_ecmd
.autoneg
;
640 ecmd
->advertising
= safe_ecmd
.advertising
;
642 ecmd
->cmd
= safe_ecmd
.cmd
;
643 /* If ecmd and safe_ecmd are not the same now, then they are
644 * trying to set something that we do not support
646 if (memcmp(ecmd
, &safe_ecmd
, sizeof(struct ethtool_cmd
)))
649 while (test_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
650 usleep_range(1000, 2000);
652 /* Get the current phy config */
653 status
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
,
658 /* Copy abilities to config in case autoneg is not
661 memset(&config
, 0, sizeof(struct i40e_aq_set_phy_config
));
662 config
.abilities
= abilities
.abilities
;
665 if (autoneg
== AUTONEG_ENABLE
) {
666 /* If autoneg was not already enabled */
667 if (!(hw
->phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
)) {
668 /* If autoneg is not supported, return error */
669 if (!(safe_ecmd
.supported
& SUPPORTED_Autoneg
)) {
670 netdev_info(netdev
, "Autoneg not supported on this phy\n");
673 /* Autoneg is allowed to change */
674 config
.abilities
= abilities
.abilities
|
675 I40E_AQ_PHY_ENABLE_AN
;
679 /* If autoneg is currently enabled */
680 if (hw
->phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
) {
681 /* If autoneg is supported 10GBASE_T is the only PHY
682 * that can disable it, so otherwise return error
684 if (safe_ecmd
.supported
& SUPPORTED_Autoneg
&&
685 hw
->phy
.link_info
.phy_type
!=
686 I40E_PHY_TYPE_10GBASE_T
) {
687 netdev_info(netdev
, "Autoneg cannot be disabled on this phy\n");
690 /* Autoneg is allowed to change */
691 config
.abilities
= abilities
.abilities
&
692 ~I40E_AQ_PHY_ENABLE_AN
;
697 if (advertise
& ~safe_ecmd
.supported
)
700 if (advertise
& ADVERTISED_100baseT_Full
)
701 config
.link_speed
|= I40E_LINK_SPEED_100MB
;
702 if (advertise
& ADVERTISED_1000baseT_Full
||
703 advertise
& ADVERTISED_1000baseKX_Full
)
704 config
.link_speed
|= I40E_LINK_SPEED_1GB
;
705 if (advertise
& ADVERTISED_10000baseT_Full
||
706 advertise
& ADVERTISED_10000baseKX4_Full
||
707 advertise
& ADVERTISED_10000baseKR_Full
)
708 config
.link_speed
|= I40E_LINK_SPEED_10GB
;
709 if (advertise
& ADVERTISED_20000baseKR2_Full
)
710 config
.link_speed
|= I40E_LINK_SPEED_20GB
;
711 if (advertise
& ADVERTISED_40000baseKR4_Full
||
712 advertise
& ADVERTISED_40000baseCR4_Full
||
713 advertise
& ADVERTISED_40000baseSR4_Full
||
714 advertise
& ADVERTISED_40000baseLR4_Full
)
715 config
.link_speed
|= I40E_LINK_SPEED_40GB
;
717 /* If speed didn't get set, set it to what it currently is.
718 * This is needed because if advertise is 0 (as it is when autoneg
719 * is disabled) then speed won't get set.
721 if (!config
.link_speed
)
722 config
.link_speed
= abilities
.link_speed
;
724 if (change
|| (abilities
.link_speed
!= config
.link_speed
)) {
725 /* copy over the rest of the abilities */
726 config
.phy_type
= abilities
.phy_type
;
727 config
.eee_capability
= abilities
.eee_capability
;
728 config
.eeer
= abilities
.eeer_val
;
729 config
.low_power_ctrl
= abilities
.d3_lpan
;
731 /* save the requested speeds */
732 hw
->phy
.link_info
.requested_speeds
= config
.link_speed
;
733 /* set link and auto negotiation so changes take effect */
734 config
.abilities
|= I40E_AQ_PHY_ENABLE_ATOMIC_LINK
;
735 /* If link is up put link down */
736 if (hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) {
737 /* Tell the OS link is going down, the link will go
738 * back up when fw says it is ready asynchronously
740 i40e_print_link_message(vsi
, false);
741 netif_carrier_off(netdev
);
742 netif_tx_stop_all_queues(netdev
);
745 /* make the aq call */
746 status
= i40e_aq_set_phy_config(hw
, &config
, NULL
);
748 netdev_info(netdev
, "Set phy config failed, err %s aq_err %s\n",
749 i40e_stat_str(hw
, status
),
750 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
754 status
= i40e_update_link_info(hw
);
756 netdev_dbg(netdev
, "Updating link info failed with err %s aq_err %s\n",
757 i40e_stat_str(hw
, status
),
758 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
761 netdev_info(netdev
, "Nothing changed, exiting without setting anything.\n");
767 static int i40e_nway_reset(struct net_device
*netdev
)
769 /* restart autonegotiation */
770 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
771 struct i40e_pf
*pf
= np
->vsi
->back
;
772 struct i40e_hw
*hw
= &pf
->hw
;
773 bool link_up
= hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
776 ret
= i40e_aq_set_link_restart_an(hw
, link_up
, NULL
);
778 netdev_info(netdev
, "link restart failed, err %s aq_err %s\n",
779 i40e_stat_str(hw
, ret
),
780 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
788 * i40e_get_pauseparam - Get Flow Control status
789 * Return tx/rx-pause status
791 static void i40e_get_pauseparam(struct net_device
*netdev
,
792 struct ethtool_pauseparam
*pause
)
794 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
795 struct i40e_pf
*pf
= np
->vsi
->back
;
796 struct i40e_hw
*hw
= &pf
->hw
;
797 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
798 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
801 ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
802 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
804 /* PFC enabled so report LFC as off */
805 if (dcbx_cfg
->pfc
.pfcenable
) {
811 if (hw
->fc
.current_mode
== I40E_FC_RX_PAUSE
) {
813 } else if (hw
->fc
.current_mode
== I40E_FC_TX_PAUSE
) {
815 } else if (hw
->fc
.current_mode
== I40E_FC_FULL
) {
822 * i40e_set_pauseparam - Set Flow Control parameter
823 * @netdev: network interface device structure
824 * @pause: return tx/rx flow control status
826 static int i40e_set_pauseparam(struct net_device
*netdev
,
827 struct ethtool_pauseparam
*pause
)
829 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
830 struct i40e_pf
*pf
= np
->vsi
->back
;
831 struct i40e_vsi
*vsi
= np
->vsi
;
832 struct i40e_hw
*hw
= &pf
->hw
;
833 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
834 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
835 bool link_up
= hw_link_info
->link_info
& I40E_AQ_LINK_UP
;
840 /* Changing the port's flow control is not supported if this isn't the
841 * port's controlling PF
843 if (hw
->partition_id
!= 1) {
844 i40e_partition_setting_complaint(pf
);
848 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
851 if (pause
->autoneg
!= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
852 AUTONEG_ENABLE
: AUTONEG_DISABLE
)) {
853 netdev_info(netdev
, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
857 /* If we have link and don't have autoneg */
858 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
859 !(hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
)) {
860 /* Send message that it might not necessarily work*/
861 netdev_info(netdev
, "Autoneg did not complete so changing settings may not result in an actual change.\n");
864 if (dcbx_cfg
->pfc
.pfcenable
) {
866 "Priority flow control enabled. Cannot set link flow control.\n");
870 if (pause
->rx_pause
&& pause
->tx_pause
)
871 hw
->fc
.requested_mode
= I40E_FC_FULL
;
872 else if (pause
->rx_pause
&& !pause
->tx_pause
)
873 hw
->fc
.requested_mode
= I40E_FC_RX_PAUSE
;
874 else if (!pause
->rx_pause
&& pause
->tx_pause
)
875 hw
->fc
.requested_mode
= I40E_FC_TX_PAUSE
;
876 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
877 hw
->fc
.requested_mode
= I40E_FC_NONE
;
881 /* Tell the OS link is going down, the link will go back up when fw
882 * says it is ready asynchronously
884 i40e_print_link_message(vsi
, false);
885 netif_carrier_off(netdev
);
886 netif_tx_stop_all_queues(netdev
);
888 /* Set the fc mode and only restart an if link is up*/
889 status
= i40e_set_fc(hw
, &aq_failures
, link_up
);
891 if (aq_failures
& I40E_SET_FC_AQ_FAIL_GET
) {
892 netdev_info(netdev
, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
893 i40e_stat_str(hw
, status
),
894 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
897 if (aq_failures
& I40E_SET_FC_AQ_FAIL_SET
) {
898 netdev_info(netdev
, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
899 i40e_stat_str(hw
, status
),
900 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
903 if (aq_failures
& I40E_SET_FC_AQ_FAIL_UPDATE
) {
904 netdev_info(netdev
, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
905 i40e_stat_str(hw
, status
),
906 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
910 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
911 /* Give it a little more time to try to come back */
913 if (!test_bit(__I40E_DOWN
, &pf
->state
))
914 return i40e_nway_reset(netdev
);
920 static u32
i40e_get_msglevel(struct net_device
*netdev
)
922 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
923 struct i40e_pf
*pf
= np
->vsi
->back
;
925 return pf
->msg_enable
;
928 static void i40e_set_msglevel(struct net_device
*netdev
, u32 data
)
930 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
931 struct i40e_pf
*pf
= np
->vsi
->back
;
933 if (I40E_DEBUG_USER
& data
)
934 pf
->hw
.debug_mask
= data
;
935 pf
->msg_enable
= data
;
938 static int i40e_get_regs_len(struct net_device
*netdev
)
943 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++)
944 reg_count
+= i40e_reg_list
[i
].elements
;
946 return reg_count
* sizeof(u32
);
949 static void i40e_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
,
952 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
953 struct i40e_pf
*pf
= np
->vsi
->back
;
954 struct i40e_hw
*hw
= &pf
->hw
;
959 /* Tell ethtool which driver-version-specific regs output we have.
961 * At some point, if we have ethtool doing special formatting of
962 * this data, it will rely on this version number to know how to
963 * interpret things. Hence, this needs to be updated if/when the
964 * diags register table is changed.
968 /* loop through the diags reg table for what to print */
970 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++) {
971 for (j
= 0; j
< i40e_reg_list
[i
].elements
; j
++) {
972 reg
= i40e_reg_list
[i
].offset
973 + (j
* i40e_reg_list
[i
].stride
);
974 reg_buf
[ri
++] = rd32(hw
, reg
);
980 static int i40e_get_eeprom(struct net_device
*netdev
,
981 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
983 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
984 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
985 struct i40e_pf
*pf
= np
->vsi
->back
;
986 int ret_val
= 0, len
, offset
;
992 #define I40E_NVM_SECTOR_SIZE 4096
993 if (eeprom
->len
== 0)
996 /* check for NVMUpdate access method */
997 magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
998 if (eeprom
->magic
&& eeprom
->magic
!= magic
) {
999 struct i40e_nvm_access
*cmd
;
1002 /* make sure it is the right magic for NVMUpdate */
1003 if ((eeprom
->magic
>> 16) != hw
->device_id
)
1006 cmd
= (struct i40e_nvm_access
*)eeprom
;
1007 ret_val
= i40e_nvmupd_command(hw
, cmd
, bytes
, &errno
);
1008 if (ret_val
&& (hw
->debug_mask
& I40E_DEBUG_NVM
))
1009 dev_info(&pf
->pdev
->dev
,
1010 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1011 ret_val
, hw
->aq
.asq_last_status
, errno
,
1012 (u8
)(cmd
->config
& I40E_NVM_MOD_PNT_MASK
),
1013 cmd
->offset
, cmd
->data_size
);
1018 /* normal ethtool get_eeprom support */
1019 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
1021 eeprom_buff
= kzalloc(eeprom
->len
, GFP_KERNEL
);
1025 ret_val
= i40e_acquire_nvm(hw
, I40E_RESOURCE_READ
);
1027 dev_info(&pf
->pdev
->dev
,
1028 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1029 ret_val
, hw
->aq
.asq_last_status
);
1033 sectors
= eeprom
->len
/ I40E_NVM_SECTOR_SIZE
;
1034 sectors
+= (eeprom
->len
% I40E_NVM_SECTOR_SIZE
) ? 1 : 0;
1035 len
= I40E_NVM_SECTOR_SIZE
;
1037 for (i
= 0; i
< sectors
; i
++) {
1038 if (i
== (sectors
- 1)) {
1039 len
= eeprom
->len
- (I40E_NVM_SECTOR_SIZE
* i
);
1042 offset
= eeprom
->offset
+ (I40E_NVM_SECTOR_SIZE
* i
),
1043 ret_val
= i40e_aq_read_nvm(hw
, 0x0, offset
, len
,
1044 (u8
*)eeprom_buff
+ (I40E_NVM_SECTOR_SIZE
* i
),
1046 if (ret_val
&& hw
->aq
.asq_last_status
== I40E_AQ_RC_EPERM
) {
1047 dev_info(&pf
->pdev
->dev
,
1048 "read NVM failed, invalid offset 0x%x\n",
1051 } else if (ret_val
&&
1052 hw
->aq
.asq_last_status
== I40E_AQ_RC_EACCES
) {
1053 dev_info(&pf
->pdev
->dev
,
1054 "read NVM failed, access, offset 0x%x\n",
1057 } else if (ret_val
) {
1058 dev_info(&pf
->pdev
->dev
,
1059 "read NVM failed offset %d err=%d status=0x%x\n",
1060 offset
, ret_val
, hw
->aq
.asq_last_status
);
1065 i40e_release_nvm(hw
);
1066 memcpy(bytes
, (u8
*)eeprom_buff
, eeprom
->len
);
1072 static int i40e_get_eeprom_len(struct net_device
*netdev
)
1074 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1075 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1078 val
= (rd32(hw
, I40E_GLPCI_LBARCTRL
)
1079 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK
)
1080 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT
;
1081 /* register returns value in power of 2, 64Kbyte chunks. */
1082 val
= (64 * 1024) * BIT(val
);
1086 static int i40e_set_eeprom(struct net_device
*netdev
,
1087 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
1089 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1090 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1091 struct i40e_pf
*pf
= np
->vsi
->back
;
1092 struct i40e_nvm_access
*cmd
;
1097 /* normal ethtool set_eeprom is not supported */
1098 magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
1099 if (eeprom
->magic
== magic
)
1102 /* check for NVMUpdate access method */
1103 if (!eeprom
->magic
|| (eeprom
->magic
>> 16) != hw
->device_id
)
1106 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
1107 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
1110 cmd
= (struct i40e_nvm_access
*)eeprom
;
1111 ret_val
= i40e_nvmupd_command(hw
, cmd
, bytes
, &errno
);
1112 if (ret_val
&& (hw
->debug_mask
& I40E_DEBUG_NVM
))
1113 dev_info(&pf
->pdev
->dev
,
1114 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1115 ret_val
, hw
->aq
.asq_last_status
, errno
,
1116 (u8
)(cmd
->config
& I40E_NVM_MOD_PNT_MASK
),
1117 cmd
->offset
, cmd
->data_size
);
1122 static void i40e_get_drvinfo(struct net_device
*netdev
,
1123 struct ethtool_drvinfo
*drvinfo
)
1125 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1126 struct i40e_vsi
*vsi
= np
->vsi
;
1127 struct i40e_pf
*pf
= vsi
->back
;
1129 strlcpy(drvinfo
->driver
, i40e_driver_name
, sizeof(drvinfo
->driver
));
1130 strlcpy(drvinfo
->version
, i40e_driver_version_str
,
1131 sizeof(drvinfo
->version
));
1132 strlcpy(drvinfo
->fw_version
, i40e_nvm_version_str(&pf
->hw
),
1133 sizeof(drvinfo
->fw_version
));
1134 strlcpy(drvinfo
->bus_info
, pci_name(pf
->pdev
),
1135 sizeof(drvinfo
->bus_info
));
1138 static void i40e_get_ringparam(struct net_device
*netdev
,
1139 struct ethtool_ringparam
*ring
)
1141 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1142 struct i40e_pf
*pf
= np
->vsi
->back
;
1143 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
1145 ring
->rx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
1146 ring
->tx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
1147 ring
->rx_mini_max_pending
= 0;
1148 ring
->rx_jumbo_max_pending
= 0;
1149 ring
->rx_pending
= vsi
->rx_rings
[0]->count
;
1150 ring
->tx_pending
= vsi
->tx_rings
[0]->count
;
1151 ring
->rx_mini_pending
= 0;
1152 ring
->rx_jumbo_pending
= 0;
1155 static int i40e_set_ringparam(struct net_device
*netdev
,
1156 struct ethtool_ringparam
*ring
)
1158 struct i40e_ring
*tx_rings
= NULL
, *rx_rings
= NULL
;
1159 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1160 struct i40e_vsi
*vsi
= np
->vsi
;
1161 struct i40e_pf
*pf
= vsi
->back
;
1162 u32 new_rx_count
, new_tx_count
;
1165 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
1168 if (ring
->tx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
1169 ring
->tx_pending
< I40E_MIN_NUM_DESCRIPTORS
||
1170 ring
->rx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
1171 ring
->rx_pending
< I40E_MIN_NUM_DESCRIPTORS
) {
1173 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1174 ring
->tx_pending
, ring
->rx_pending
,
1175 I40E_MIN_NUM_DESCRIPTORS
, I40E_MAX_NUM_DESCRIPTORS
);
1179 new_tx_count
= ALIGN(ring
->tx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
1180 new_rx_count
= ALIGN(ring
->rx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
1182 /* if nothing to do return success */
1183 if ((new_tx_count
== vsi
->tx_rings
[0]->count
) &&
1184 (new_rx_count
== vsi
->rx_rings
[0]->count
))
1187 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
1188 usleep_range(1000, 2000);
1190 if (!netif_running(vsi
->netdev
)) {
1191 /* simple case - set for the next time the netdev is started */
1192 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1193 vsi
->tx_rings
[i
]->count
= new_tx_count
;
1194 vsi
->rx_rings
[i
]->count
= new_rx_count
;
1199 /* We can't just free everything and then setup again,
1200 * because the ISRs in MSI-X mode get passed pointers
1201 * to the Tx and Rx ring structs.
1204 /* alloc updated Tx resources */
1205 if (new_tx_count
!= vsi
->tx_rings
[0]->count
) {
1207 "Changing Tx descriptor count from %d to %d.\n",
1208 vsi
->tx_rings
[0]->count
, new_tx_count
);
1209 tx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
1210 sizeof(struct i40e_ring
), GFP_KERNEL
);
1216 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1217 /* clone ring and setup updated count */
1218 tx_rings
[i
] = *vsi
->tx_rings
[i
];
1219 tx_rings
[i
].count
= new_tx_count
;
1220 /* the desc and bi pointers will be reallocated in the
1223 tx_rings
[i
].desc
= NULL
;
1224 tx_rings
[i
].rx_bi
= NULL
;
1225 err
= i40e_setup_tx_descriptors(&tx_rings
[i
]);
1229 i40e_free_tx_resources(&tx_rings
[i
]);
1239 /* alloc updated Rx resources */
1240 if (new_rx_count
!= vsi
->rx_rings
[0]->count
) {
1242 "Changing Rx descriptor count from %d to %d\n",
1243 vsi
->rx_rings
[0]->count
, new_rx_count
);
1244 rx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
1245 sizeof(struct i40e_ring
), GFP_KERNEL
);
1251 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1252 /* clone ring and setup updated count */
1253 rx_rings
[i
] = *vsi
->rx_rings
[i
];
1254 rx_rings
[i
].count
= new_rx_count
;
1255 /* the desc and bi pointers will be reallocated in the
1258 rx_rings
[i
].desc
= NULL
;
1259 rx_rings
[i
].rx_bi
= NULL
;
1260 err
= i40e_setup_rx_descriptors(&rx_rings
[i
]);
1264 i40e_free_rx_resources(&rx_rings
[i
]);
1274 /* Bring interface down, copy in the new ring info,
1275 * then restore the interface
1280 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1281 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
1282 *vsi
->tx_rings
[i
] = tx_rings
[i
];
1289 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1290 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
1291 *vsi
->rx_rings
[i
] = rx_rings
[i
];
1300 /* error cleanup if the Rx allocations failed after getting Tx */
1302 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1303 i40e_free_tx_resources(&tx_rings
[i
]);
1309 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
1314 static int i40e_get_sset_count(struct net_device
*netdev
, int sset
)
1316 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1317 struct i40e_vsi
*vsi
= np
->vsi
;
1318 struct i40e_pf
*pf
= vsi
->back
;
1322 return I40E_TEST_LEN
;
1324 if (vsi
== pf
->vsi
[pf
->lan_vsi
] && pf
->hw
.partition_id
== 1) {
1325 int len
= I40E_PF_STATS_LEN(netdev
);
1327 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1328 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
))
1329 len
+= I40E_VEB_STATS_TOTAL
;
1332 return I40E_VSI_STATS_LEN(netdev
);
1334 case ETH_SS_PRIV_FLAGS
:
1335 return I40E_PRIV_FLAGS_STR_LEN
;
1341 static void i40e_get_ethtool_stats(struct net_device
*netdev
,
1342 struct ethtool_stats
*stats
, u64
*data
)
1344 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1345 struct i40e_ring
*tx_ring
, *rx_ring
;
1346 struct i40e_vsi
*vsi
= np
->vsi
;
1347 struct i40e_pf
*pf
= vsi
->back
;
1351 struct rtnl_link_stats64
*net_stats
= i40e_get_vsi_stats_struct(vsi
);
1354 i40e_update_stats(vsi
);
1356 for (j
= 0; j
< I40E_NETDEV_STATS_LEN
; j
++) {
1357 p
= (char *)net_stats
+ i40e_gstrings_net_stats
[j
].stat_offset
;
1358 data
[i
++] = (i40e_gstrings_net_stats
[j
].sizeof_stat
==
1359 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1361 for (j
= 0; j
< I40E_MISC_STATS_LEN
; j
++) {
1362 p
= (char *)vsi
+ i40e_gstrings_misc_stats
[j
].stat_offset
;
1363 data
[i
++] = (i40e_gstrings_misc_stats
[j
].sizeof_stat
==
1364 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1367 for (j
= 0; j
< I40E_FCOE_STATS_LEN
; j
++) {
1368 p
= (char *)vsi
+ i40e_gstrings_fcoe_stats
[j
].stat_offset
;
1369 data
[i
++] = (i40e_gstrings_fcoe_stats
[j
].sizeof_stat
==
1370 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1374 for (j
= 0; j
< vsi
->num_queue_pairs
; j
++) {
1375 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[j
]);
1380 /* process Tx ring statistics */
1382 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
1383 data
[i
] = tx_ring
->stats
.packets
;
1384 data
[i
+ 1] = tx_ring
->stats
.bytes
;
1385 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
1388 /* Rx ring is the 2nd half of the queue pair */
1389 rx_ring
= &tx_ring
[1];
1391 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
1392 data
[i
] = rx_ring
->stats
.packets
;
1393 data
[i
+ 1] = rx_ring
->stats
.bytes
;
1394 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
1398 if (vsi
!= pf
->vsi
[pf
->lan_vsi
] || pf
->hw
.partition_id
!= 1)
1401 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1402 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
1403 struct i40e_veb
*veb
= pf
->veb
[pf
->lan_veb
];
1405 for (j
= 0; j
< I40E_VEB_STATS_LEN
; j
++) {
1407 p
+= i40e_gstrings_veb_stats
[j
].stat_offset
;
1408 data
[i
++] = (i40e_gstrings_veb_stats
[j
].sizeof_stat
==
1409 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1411 for (j
= 0; j
< I40E_MAX_TRAFFIC_CLASS
; j
++) {
1412 data
[i
++] = veb
->tc_stats
.tc_tx_packets
[j
];
1413 data
[i
++] = veb
->tc_stats
.tc_tx_bytes
[j
];
1414 data
[i
++] = veb
->tc_stats
.tc_rx_packets
[j
];
1415 data
[i
++] = veb
->tc_stats
.tc_rx_bytes
[j
];
1418 for (j
= 0; j
< I40E_GLOBAL_STATS_LEN
; j
++) {
1419 p
= (char *)pf
+ i40e_gstrings_stats
[j
].stat_offset
;
1420 data
[i
++] = (i40e_gstrings_stats
[j
].sizeof_stat
==
1421 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1423 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
1424 data
[i
++] = pf
->stats
.priority_xon_tx
[j
];
1425 data
[i
++] = pf
->stats
.priority_xoff_tx
[j
];
1427 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
1428 data
[i
++] = pf
->stats
.priority_xon_rx
[j
];
1429 data
[i
++] = pf
->stats
.priority_xoff_rx
[j
];
1431 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++)
1432 data
[i
++] = pf
->stats
.priority_xon_2_xoff
[j
];
1435 static void i40e_get_strings(struct net_device
*netdev
, u32 stringset
,
1438 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1439 struct i40e_vsi
*vsi
= np
->vsi
;
1440 struct i40e_pf
*pf
= vsi
->back
;
1441 char *p
= (char *)data
;
1444 switch (stringset
) {
1446 for (i
= 0; i
< I40E_TEST_LEN
; i
++) {
1447 memcpy(data
, i40e_gstrings_test
[i
], ETH_GSTRING_LEN
);
1448 data
+= ETH_GSTRING_LEN
;
1452 for (i
= 0; i
< I40E_NETDEV_STATS_LEN
; i
++) {
1453 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1454 i40e_gstrings_net_stats
[i
].stat_string
);
1455 p
+= ETH_GSTRING_LEN
;
1457 for (i
= 0; i
< I40E_MISC_STATS_LEN
; i
++) {
1458 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1459 i40e_gstrings_misc_stats
[i
].stat_string
);
1460 p
+= ETH_GSTRING_LEN
;
1463 for (i
= 0; i
< I40E_FCOE_STATS_LEN
; i
++) {
1464 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1465 i40e_gstrings_fcoe_stats
[i
].stat_string
);
1466 p
+= ETH_GSTRING_LEN
;
1469 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1470 snprintf(p
, ETH_GSTRING_LEN
, "tx-%u.tx_packets", i
);
1471 p
+= ETH_GSTRING_LEN
;
1472 snprintf(p
, ETH_GSTRING_LEN
, "tx-%u.tx_bytes", i
);
1473 p
+= ETH_GSTRING_LEN
;
1474 snprintf(p
, ETH_GSTRING_LEN
, "rx-%u.rx_packets", i
);
1475 p
+= ETH_GSTRING_LEN
;
1476 snprintf(p
, ETH_GSTRING_LEN
, "rx-%u.rx_bytes", i
);
1477 p
+= ETH_GSTRING_LEN
;
1479 if (vsi
!= pf
->vsi
[pf
->lan_vsi
] || pf
->hw
.partition_id
!= 1)
1482 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1483 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
1484 for (i
= 0; i
< I40E_VEB_STATS_LEN
; i
++) {
1485 snprintf(p
, ETH_GSTRING_LEN
, "veb.%s",
1486 i40e_gstrings_veb_stats
[i
].stat_string
);
1487 p
+= ETH_GSTRING_LEN
;
1489 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1490 snprintf(p
, ETH_GSTRING_LEN
,
1491 "veb.tc_%u_tx_packets", i
);
1492 p
+= ETH_GSTRING_LEN
;
1493 snprintf(p
, ETH_GSTRING_LEN
,
1494 "veb.tc_%u_tx_bytes", i
);
1495 p
+= ETH_GSTRING_LEN
;
1496 snprintf(p
, ETH_GSTRING_LEN
,
1497 "veb.tc_%u_rx_packets", i
);
1498 p
+= ETH_GSTRING_LEN
;
1499 snprintf(p
, ETH_GSTRING_LEN
,
1500 "veb.tc_%u_rx_bytes", i
);
1501 p
+= ETH_GSTRING_LEN
;
1504 for (i
= 0; i
< I40E_GLOBAL_STATS_LEN
; i
++) {
1505 snprintf(p
, ETH_GSTRING_LEN
, "port.%s",
1506 i40e_gstrings_stats
[i
].stat_string
);
1507 p
+= ETH_GSTRING_LEN
;
1509 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1510 snprintf(p
, ETH_GSTRING_LEN
,
1511 "port.tx_priority_%u_xon", i
);
1512 p
+= ETH_GSTRING_LEN
;
1513 snprintf(p
, ETH_GSTRING_LEN
,
1514 "port.tx_priority_%u_xoff", i
);
1515 p
+= ETH_GSTRING_LEN
;
1517 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1518 snprintf(p
, ETH_GSTRING_LEN
,
1519 "port.rx_priority_%u_xon", i
);
1520 p
+= ETH_GSTRING_LEN
;
1521 snprintf(p
, ETH_GSTRING_LEN
,
1522 "port.rx_priority_%u_xoff", i
);
1523 p
+= ETH_GSTRING_LEN
;
1525 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1526 snprintf(p
, ETH_GSTRING_LEN
,
1527 "port.rx_priority_%u_xon_2_xoff", i
);
1528 p
+= ETH_GSTRING_LEN
;
1530 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1532 case ETH_SS_PRIV_FLAGS
:
1533 for (i
= 0; i
< I40E_PRIV_FLAGS_STR_LEN
; i
++) {
1534 memcpy(data
, i40e_priv_flags_strings
[i
],
1536 data
+= ETH_GSTRING_LEN
;
1544 static int i40e_get_ts_info(struct net_device
*dev
,
1545 struct ethtool_ts_info
*info
)
1547 struct i40e_pf
*pf
= i40e_netdev_to_pf(dev
);
1549 /* only report HW timestamping if PTP is enabled */
1550 if (!(pf
->flags
& I40E_FLAG_PTP
))
1551 return ethtool_op_get_ts_info(dev
, info
);
1553 info
->so_timestamping
= SOF_TIMESTAMPING_TX_SOFTWARE
|
1554 SOF_TIMESTAMPING_RX_SOFTWARE
|
1555 SOF_TIMESTAMPING_SOFTWARE
|
1556 SOF_TIMESTAMPING_TX_HARDWARE
|
1557 SOF_TIMESTAMPING_RX_HARDWARE
|
1558 SOF_TIMESTAMPING_RAW_HARDWARE
;
1561 info
->phc_index
= ptp_clock_index(pf
->ptp_clock
);
1563 info
->phc_index
= -1;
1565 info
->tx_types
= BIT(HWTSTAMP_TX_OFF
) | BIT(HWTSTAMP_TX_ON
);
1567 info
->rx_filters
= BIT(HWTSTAMP_FILTER_NONE
) |
1568 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT
) |
1569 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT
);
1574 static int i40e_link_test(struct net_device
*netdev
, u64
*data
)
1576 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1577 struct i40e_pf
*pf
= np
->vsi
->back
;
1579 bool link_up
= false;
1581 netif_info(pf
, hw
, netdev
, "link test\n");
1582 status
= i40e_get_link_status(&pf
->hw
, &link_up
);
1584 netif_err(pf
, drv
, netdev
, "link query timed out, please retry test\n");
1597 static int i40e_reg_test(struct net_device
*netdev
, u64
*data
)
1599 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1600 struct i40e_pf
*pf
= np
->vsi
->back
;
1602 netif_info(pf
, hw
, netdev
, "register test\n");
1603 *data
= i40e_diag_reg_test(&pf
->hw
);
1608 static int i40e_eeprom_test(struct net_device
*netdev
, u64
*data
)
1610 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1611 struct i40e_pf
*pf
= np
->vsi
->back
;
1613 netif_info(pf
, hw
, netdev
, "eeprom test\n");
1614 *data
= i40e_diag_eeprom_test(&pf
->hw
);
1616 /* forcebly clear the NVM Update state machine */
1617 pf
->hw
.nvmupd_state
= I40E_NVMUPD_STATE_INIT
;
1622 static int i40e_intr_test(struct net_device
*netdev
, u64
*data
)
1624 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1625 struct i40e_pf
*pf
= np
->vsi
->back
;
1626 u16 swc_old
= pf
->sw_int_count
;
1628 netif_info(pf
, hw
, netdev
, "interrupt test\n");
1629 wr32(&pf
->hw
, I40E_PFINT_DYN_CTL0
,
1630 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
1631 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
|
1632 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK
|
1633 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK
|
1634 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
));
1635 usleep_range(1000, 2000);
1636 *data
= (swc_old
== pf
->sw_int_count
);
1641 static int i40e_loopback_test(struct net_device
*netdev
, u64
*data
)
1643 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1644 struct i40e_pf
*pf
= np
->vsi
->back
;
1646 netif_info(pf
, hw
, netdev
, "loopback test not implemented\n");
1652 static inline bool i40e_active_vfs(struct i40e_pf
*pf
)
1654 struct i40e_vf
*vfs
= pf
->vf
;
1657 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
1658 if (test_bit(I40E_VF_STAT_ACTIVE
, &vfs
[i
].vf_states
))
1663 static inline bool i40e_active_vmdqs(struct i40e_pf
*pf
)
1665 struct i40e_vsi
**vsi
= pf
->vsi
;
1668 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
1671 if (vsi
[i
]->type
== I40E_VSI_VMDQ2
)
1678 static void i40e_diag_test(struct net_device
*netdev
,
1679 struct ethtool_test
*eth_test
, u64
*data
)
1681 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1682 bool if_running
= netif_running(netdev
);
1683 struct i40e_pf
*pf
= np
->vsi
->back
;
1685 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1687 netif_info(pf
, drv
, netdev
, "offline testing starting\n");
1689 set_bit(__I40E_TESTING
, &pf
->state
);
1691 if (i40e_active_vfs(pf
) || i40e_active_vmdqs(pf
)) {
1692 dev_warn(&pf
->pdev
->dev
,
1693 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1694 data
[I40E_ETH_TEST_REG
] = 1;
1695 data
[I40E_ETH_TEST_EEPROM
] = 1;
1696 data
[I40E_ETH_TEST_INTR
] = 1;
1697 data
[I40E_ETH_TEST_LOOPBACK
] = 1;
1698 data
[I40E_ETH_TEST_LINK
] = 1;
1699 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1700 clear_bit(__I40E_TESTING
, &pf
->state
);
1704 /* If the device is online then take it offline */
1706 /* indicate we're in test mode */
1709 /* This reset does not affect link - if it is
1710 * changed to a type of reset that does affect
1711 * link then the following link test would have
1712 * to be moved to before the reset
1714 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
1716 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
1717 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1719 if (i40e_eeprom_test(netdev
, &data
[I40E_ETH_TEST_EEPROM
]))
1720 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1722 if (i40e_intr_test(netdev
, &data
[I40E_ETH_TEST_INTR
]))
1723 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1725 if (i40e_loopback_test(netdev
, &data
[I40E_ETH_TEST_LOOPBACK
]))
1726 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1728 /* run reg test last, a reset is required after it */
1729 if (i40e_reg_test(netdev
, &data
[I40E_ETH_TEST_REG
]))
1730 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1732 clear_bit(__I40E_TESTING
, &pf
->state
);
1733 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
1739 netif_info(pf
, drv
, netdev
, "online testing starting\n");
1741 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
1742 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1744 /* Offline only tests, not run in online; pass by default */
1745 data
[I40E_ETH_TEST_REG
] = 0;
1746 data
[I40E_ETH_TEST_EEPROM
] = 0;
1747 data
[I40E_ETH_TEST_INTR
] = 0;
1748 data
[I40E_ETH_TEST_LOOPBACK
] = 0;
1753 netif_info(pf
, drv
, netdev
, "testing finished\n");
1756 static void i40e_get_wol(struct net_device
*netdev
,
1757 struct ethtool_wolinfo
*wol
)
1759 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1760 struct i40e_pf
*pf
= np
->vsi
->back
;
1761 struct i40e_hw
*hw
= &pf
->hw
;
1764 /* NVM bit on means WoL disabled for the port */
1765 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
1766 if ((BIT(hw
->port
) & wol_nvm_bits
) || (hw
->partition_id
!= 1)) {
1770 wol
->supported
= WAKE_MAGIC
;
1771 wol
->wolopts
= (pf
->wol_en
? WAKE_MAGIC
: 0);
1776 * i40e_set_wol - set the WakeOnLAN configuration
1777 * @netdev: the netdev in question
1778 * @wol: the ethtool WoL setting data
1780 static int i40e_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1782 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1783 struct i40e_pf
*pf
= np
->vsi
->back
;
1784 struct i40e_vsi
*vsi
= np
->vsi
;
1785 struct i40e_hw
*hw
= &pf
->hw
;
1788 /* WoL not supported if this isn't the controlling PF on the port */
1789 if (hw
->partition_id
!= 1) {
1790 i40e_partition_setting_complaint(pf
);
1794 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
1797 /* NVM bit on means WoL disabled for the port */
1798 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
1799 if (BIT(hw
->port
) & wol_nvm_bits
)
1802 /* only magic packet is supported */
1803 if (wol
->wolopts
&& (wol
->wolopts
!= WAKE_MAGIC
))
1806 /* is this a new value? */
1807 if (pf
->wol_en
!= !!wol
->wolopts
) {
1808 pf
->wol_en
= !!wol
->wolopts
;
1809 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
1815 static int i40e_set_phys_id(struct net_device
*netdev
,
1816 enum ethtool_phys_id_state state
)
1818 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1819 struct i40e_pf
*pf
= np
->vsi
->back
;
1820 struct i40e_hw
*hw
= &pf
->hw
;
1824 case ETHTOOL_ID_ACTIVE
:
1825 pf
->led_status
= i40e_led_get(hw
);
1828 i40e_led_set(hw
, 0xF, false);
1830 case ETHTOOL_ID_OFF
:
1831 i40e_led_set(hw
, 0x0, false);
1833 case ETHTOOL_ID_INACTIVE
:
1834 i40e_led_set(hw
, pf
->led_status
, false);
1843 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1844 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1845 * 125us (8000 interrupts per second) == ITR(62)
1848 static int i40e_get_coalesce(struct net_device
*netdev
,
1849 struct ethtool_coalesce
*ec
)
1851 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1852 struct i40e_vsi
*vsi
= np
->vsi
;
1854 ec
->tx_max_coalesced_frames_irq
= vsi
->work_limit
;
1855 ec
->rx_max_coalesced_frames_irq
= vsi
->work_limit
;
1857 if (ITR_IS_DYNAMIC(vsi
->rx_itr_setting
))
1858 ec
->use_adaptive_rx_coalesce
= 1;
1860 if (ITR_IS_DYNAMIC(vsi
->tx_itr_setting
))
1861 ec
->use_adaptive_tx_coalesce
= 1;
1863 ec
->rx_coalesce_usecs
= vsi
->rx_itr_setting
& ~I40E_ITR_DYNAMIC
;
1864 ec
->tx_coalesce_usecs
= vsi
->tx_itr_setting
& ~I40E_ITR_DYNAMIC
;
1865 /* we use the _usecs_high to store/set the interrupt rate limit
1866 * that the hardware supports, that almost but not quite
1867 * fits the original intent of the ethtool variable,
1868 * the rx_coalesce_usecs_high limits total interrupts
1869 * per second from both tx/rx sources.
1871 ec
->rx_coalesce_usecs_high
= vsi
->int_rate_limit
;
1872 ec
->tx_coalesce_usecs_high
= vsi
->int_rate_limit
;
1877 static int i40e_set_coalesce(struct net_device
*netdev
,
1878 struct ethtool_coalesce
*ec
)
1880 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1881 struct i40e_q_vector
*q_vector
;
1882 struct i40e_vsi
*vsi
= np
->vsi
;
1883 struct i40e_pf
*pf
= vsi
->back
;
1884 struct i40e_hw
*hw
= &pf
->hw
;
1888 if (ec
->tx_max_coalesced_frames_irq
|| ec
->rx_max_coalesced_frames_irq
)
1889 vsi
->work_limit
= ec
->tx_max_coalesced_frames_irq
;
1891 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1892 if (ec
->tx_coalesce_usecs_high
!= vsi
->int_rate_limit
) {
1893 netif_info(pf
, drv
, netdev
, "tx-usecs-high is not used, please program rx-usecs-high\n");
1897 if (ec
->rx_coalesce_usecs_high
>= INTRL_REG_TO_USEC(I40E_MAX_INTRL
)) {
1898 netif_info(pf
, drv
, netdev
, "Invalid value, rx-usecs-high range is 0-235\n");
1902 vector
= vsi
->base_vector
;
1903 if ((ec
->rx_coalesce_usecs
>= (I40E_MIN_ITR
<< 1)) &&
1904 (ec
->rx_coalesce_usecs
<= (I40E_MAX_ITR
<< 1))) {
1905 vsi
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
1906 } else if (ec
->rx_coalesce_usecs
== 0) {
1907 vsi
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
1908 if (ec
->use_adaptive_rx_coalesce
)
1909 netif_info(pf
, drv
, netdev
, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
1911 netif_info(pf
, drv
, netdev
, "Invalid value, rx-usecs range is 0-8160\n");
1915 vsi
->int_rate_limit
= ec
->rx_coalesce_usecs_high
;
1917 if ((ec
->tx_coalesce_usecs
>= (I40E_MIN_ITR
<< 1)) &&
1918 (ec
->tx_coalesce_usecs
<= (I40E_MAX_ITR
<< 1))) {
1919 vsi
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
1920 } else if (ec
->tx_coalesce_usecs
== 0) {
1921 vsi
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
1922 if (ec
->use_adaptive_tx_coalesce
)
1923 netif_info(pf
, drv
, netdev
, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
1925 netif_info(pf
, drv
, netdev
,
1926 "Invalid value, tx-usecs range is 0-8160\n");
1930 if (ec
->use_adaptive_rx_coalesce
)
1931 vsi
->rx_itr_setting
|= I40E_ITR_DYNAMIC
;
1933 vsi
->rx_itr_setting
&= ~I40E_ITR_DYNAMIC
;
1935 if (ec
->use_adaptive_tx_coalesce
)
1936 vsi
->tx_itr_setting
|= I40E_ITR_DYNAMIC
;
1938 vsi
->tx_itr_setting
&= ~I40E_ITR_DYNAMIC
;
1940 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
1941 u16 intrl
= INTRL_USEC_TO_REG(vsi
->int_rate_limit
);
1943 q_vector
= vsi
->q_vectors
[i
];
1944 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
1945 wr32(hw
, I40E_PFINT_ITRN(0, vector
- 1), q_vector
->rx
.itr
);
1946 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
1947 wr32(hw
, I40E_PFINT_ITRN(1, vector
- 1), q_vector
->tx
.itr
);
1948 wr32(hw
, I40E_PFINT_RATEN(vector
- 1), intrl
);
1956 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1957 * @pf: pointer to the physical function struct
1958 * @cmd: ethtool rxnfc command
1960 * Returns Success if the flow is supported, else Invalid Input.
1962 static int i40e_get_rss_hash_opts(struct i40e_pf
*pf
, struct ethtool_rxnfc
*cmd
)
1966 if (pf
->vsi
[pf
->lan_vsi
]->rxnfc
.data
!= 0) {
1967 cmd
->data
= pf
->vsi
[pf
->lan_vsi
]->rxnfc
.data
;
1968 cmd
->flow_type
= pf
->vsi
[pf
->lan_vsi
]->rxnfc
.flow_type
;
1971 /* Report default options for RSS on i40e */
1972 switch (cmd
->flow_type
) {
1975 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1976 /* fall through to add IP fields */
1978 case AH_ESP_V4_FLOW
:
1982 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
1986 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1987 /* fall through to add IP fields */
1989 case AH_ESP_V6_FLOW
:
1993 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
2003 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2004 * @pf: Pointer to the physical function struct
2005 * @cmd: The command to get or set Rx flow classification rules
2006 * @rule_locs: Array of used rule locations
2008 * This function populates both the total and actual rule count of
2009 * the ethtool flow classification command
2011 * Returns 0 on success or -EMSGSIZE if entry not found
2013 static int i40e_get_ethtool_fdir_all(struct i40e_pf
*pf
,
2014 struct ethtool_rxnfc
*cmd
,
2017 struct i40e_fdir_filter
*rule
;
2018 struct hlist_node
*node2
;
2021 /* report total rule count */
2022 cmd
->data
= i40e_get_fd_cnt_all(pf
);
2024 hlist_for_each_entry_safe(rule
, node2
,
2025 &pf
->fdir_filter_list
, fdir_node
) {
2026 if (cnt
== cmd
->rule_cnt
)
2029 rule_locs
[cnt
] = rule
->fd_id
;
2033 cmd
->rule_cnt
= cnt
;
2039 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2040 * @pf: Pointer to the physical function struct
2041 * @cmd: The command to get or set Rx flow classification rules
2043 * This function looks up a filter based on the Rx flow classification
2044 * command and fills the flow spec info for it if found
2046 * Returns 0 on success or -EINVAL if filter not found
2048 static int i40e_get_ethtool_fdir_entry(struct i40e_pf
*pf
,
2049 struct ethtool_rxnfc
*cmd
)
2051 struct ethtool_rx_flow_spec
*fsp
=
2052 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2053 struct i40e_fdir_filter
*rule
= NULL
;
2054 struct hlist_node
*node2
;
2056 hlist_for_each_entry_safe(rule
, node2
,
2057 &pf
->fdir_filter_list
, fdir_node
) {
2058 if (fsp
->location
<= rule
->fd_id
)
2062 if (!rule
|| fsp
->location
!= rule
->fd_id
)
2065 fsp
->flow_type
= rule
->flow_type
;
2066 if (fsp
->flow_type
== IP_USER_FLOW
) {
2067 fsp
->h_u
.usr_ip4_spec
.ip_ver
= ETH_RX_NFC_IP4
;
2068 fsp
->h_u
.usr_ip4_spec
.proto
= 0;
2069 fsp
->m_u
.usr_ip4_spec
.proto
= 0;
2072 /* Reverse the src and dest notion, since the HW views them from
2073 * Tx perspective where as the user expects it from Rx filter view.
2075 fsp
->h_u
.tcp_ip4_spec
.psrc
= rule
->dst_port
;
2076 fsp
->h_u
.tcp_ip4_spec
.pdst
= rule
->src_port
;
2077 fsp
->h_u
.tcp_ip4_spec
.ip4src
= rule
->dst_ip
[0];
2078 fsp
->h_u
.tcp_ip4_spec
.ip4dst
= rule
->src_ip
[0];
2080 if (rule
->dest_ctl
== I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
)
2081 fsp
->ring_cookie
= RX_CLS_FLOW_DISC
;
2083 fsp
->ring_cookie
= rule
->q_index
;
2085 if (rule
->dest_vsi
!= pf
->vsi
[pf
->lan_vsi
]->id
) {
2086 struct i40e_vsi
*vsi
;
2088 vsi
= i40e_find_vsi_from_id(pf
, rule
->dest_vsi
);
2089 if (vsi
&& vsi
->type
== I40E_VSI_SRIOV
) {
2090 fsp
->h_ext
.data
[1] = htonl(vsi
->vf_id
);
2091 fsp
->m_ext
.data
[1] = htonl(0x1);
2099 * i40e_get_rxnfc - command to get RX flow classification rules
2100 * @netdev: network interface device structure
2101 * @cmd: ethtool rxnfc command
2103 * Returns Success if the command is supported.
2105 static int i40e_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
,
2108 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2109 struct i40e_vsi
*vsi
= np
->vsi
;
2110 struct i40e_pf
*pf
= vsi
->back
;
2111 int ret
= -EOPNOTSUPP
;
2114 case ETHTOOL_GRXRINGS
:
2115 cmd
->data
= vsi
->num_queue_pairs
;
2119 ret
= i40e_get_rss_hash_opts(pf
, cmd
);
2121 case ETHTOOL_GRXCLSRLCNT
:
2122 cmd
->rule_cnt
= pf
->fdir_pf_active_filters
;
2123 /* report total rule count */
2124 cmd
->data
= i40e_get_fd_cnt_all(pf
);
2127 case ETHTOOL_GRXCLSRULE
:
2128 ret
= i40e_get_ethtool_fdir_entry(pf
, cmd
);
2130 case ETHTOOL_GRXCLSRLALL
:
2131 ret
= i40e_get_ethtool_fdir_all(pf
, cmd
, rule_locs
);
2141 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2142 * @pf: pointer to the physical function struct
2143 * @cmd: ethtool rxnfc command
2145 * Returns Success if the flow input set is supported.
2147 static int i40e_set_rss_hash_opt(struct i40e_pf
*pf
, struct ethtool_rxnfc
*nfc
)
2149 struct i40e_hw
*hw
= &pf
->hw
;
2150 u64 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
2151 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
2153 /* RSS does not support anything other than hashing
2154 * to queues on src and dst IPs and ports
2156 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
2157 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
2160 /* We need at least the IP SRC and DEST fields for hashing */
2161 if (!(nfc
->data
& RXH_IP_SRC
) ||
2162 !(nfc
->data
& RXH_IP_DST
))
2165 switch (nfc
->flow_type
) {
2167 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2169 hena
&= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP
);
2171 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2172 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP
);
2179 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2181 hena
&= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP
);
2183 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2184 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP
);
2191 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2193 hena
&= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP
) |
2194 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
));
2196 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2197 hena
|= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP
) |
2198 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
));
2205 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2207 hena
&= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP
) |
2208 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
));
2210 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2211 hena
|= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP
) |
2212 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
));
2218 case AH_ESP_V4_FLOW
:
2222 if ((nfc
->data
& RXH_L4_B_0_1
) ||
2223 (nfc
->data
& RXH_L4_B_2_3
))
2225 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
);
2227 case AH_ESP_V6_FLOW
:
2231 if ((nfc
->data
& RXH_L4_B_0_1
) ||
2232 (nfc
->data
& RXH_L4_B_2_3
))
2234 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
);
2237 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
) |
2238 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
);
2241 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
) |
2242 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
);
2248 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
2249 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
2252 /* Save setting for future output/update */
2253 pf
->vsi
[pf
->lan_vsi
]->rxnfc
= *nfc
;
2259 * i40e_match_fdir_input_set - Match a new filter against an existing one
2260 * @rule: The filter already added
2261 * @input: The new filter to comapre against
2263 * Returns true if the two input set match
2265 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter
*rule
,
2266 struct i40e_fdir_filter
*input
)
2268 if ((rule
->dst_ip
[0] != input
->dst_ip
[0]) ||
2269 (rule
->src_ip
[0] != input
->src_ip
[0]) ||
2270 (rule
->dst_port
!= input
->dst_port
) ||
2271 (rule
->src_port
!= input
->src_port
))
2277 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2278 * @vsi: Pointer to the targeted VSI
2279 * @input: The filter to update or NULL to indicate deletion
2280 * @sw_idx: Software index to the filter
2281 * @cmd: The command to get or set Rx flow classification rules
2283 * This function updates (or deletes) a Flow Director entry from
2284 * the hlist of the corresponding PF
2286 * Returns 0 on success
2288 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi
*vsi
,
2289 struct i40e_fdir_filter
*input
,
2291 struct ethtool_rxnfc
*cmd
)
2293 struct i40e_fdir_filter
*rule
, *parent
;
2294 struct i40e_pf
*pf
= vsi
->back
;
2295 struct hlist_node
*node2
;
2301 hlist_for_each_entry_safe(rule
, node2
,
2302 &pf
->fdir_filter_list
, fdir_node
) {
2303 /* hash found, or no matching entry */
2304 if (rule
->fd_id
>= sw_idx
)
2309 /* if there is an old rule occupying our place remove it */
2310 if (rule
&& (rule
->fd_id
== sw_idx
)) {
2311 if (input
&& !i40e_match_fdir_input_set(rule
, input
))
2312 err
= i40e_add_del_fdir(vsi
, rule
, false);
2314 err
= i40e_add_del_fdir(vsi
, rule
, false);
2315 hlist_del(&rule
->fdir_node
);
2317 pf
->fdir_pf_active_filters
--;
2320 /* If no input this was a delete, err should be 0 if a rule was
2321 * successfully found and removed from the list else -EINVAL
2326 /* initialize node and set software index */
2327 INIT_HLIST_NODE(&input
->fdir_node
);
2329 /* add filter to the list */
2331 hlist_add_behind(&input
->fdir_node
, &parent
->fdir_node
);
2333 hlist_add_head(&input
->fdir_node
,
2334 &pf
->fdir_filter_list
);
2337 pf
->fdir_pf_active_filters
++;
2343 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2344 * @vsi: Pointer to the targeted VSI
2345 * @cmd: The command to get or set Rx flow classification rules
2347 * The function removes a Flow Director filter entry from the
2348 * hlist of the corresponding PF
2350 * Returns 0 on success
2352 static int i40e_del_fdir_entry(struct i40e_vsi
*vsi
,
2353 struct ethtool_rxnfc
*cmd
)
2355 struct ethtool_rx_flow_spec
*fsp
=
2356 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2357 struct i40e_pf
*pf
= vsi
->back
;
2360 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
2361 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
2364 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
2367 ret
= i40e_update_ethtool_fdir_entry(vsi
, NULL
, fsp
->location
, cmd
);
2369 i40e_fdir_check_and_reenable(pf
);
2374 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2375 * @vsi: pointer to the targeted VSI
2376 * @cmd: command to get or set RX flow classification rules
2378 * Add Flow Director filters for a specific flow spec based on their
2379 * protocol. Returns 0 if the filters were successfully added.
2381 static int i40e_add_fdir_ethtool(struct i40e_vsi
*vsi
,
2382 struct ethtool_rxnfc
*cmd
)
2384 struct ethtool_rx_flow_spec
*fsp
;
2385 struct i40e_fdir_filter
*input
;
2395 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
2398 if (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)
2401 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
2402 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
2405 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
2408 fsp
= (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2410 if (fsp
->location
>= (pf
->hw
.func_caps
.fd_filters_best_effort
+
2411 pf
->hw
.func_caps
.fd_filters_guaranteed
)) {
2415 if ((fsp
->ring_cookie
!= RX_CLS_FLOW_DISC
) &&
2416 (fsp
->ring_cookie
>= vsi
->num_queue_pairs
))
2419 input
= kzalloc(sizeof(*input
), GFP_KERNEL
);
2424 input
->fd_id
= fsp
->location
;
2426 if (fsp
->ring_cookie
== RX_CLS_FLOW_DISC
)
2427 input
->dest_ctl
= I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
;
2430 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX
;
2432 input
->q_index
= fsp
->ring_cookie
;
2433 input
->flex_off
= 0;
2435 input
->dest_vsi
= vsi
->id
;
2436 input
->fd_status
= I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID
;
2437 input
->cnt_index
= I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
);
2438 input
->flow_type
= fsp
->flow_type
;
2439 input
->ip4_proto
= fsp
->h_u
.usr_ip4_spec
.proto
;
2441 /* Reverse the src and dest notion, since the HW expects them to be from
2442 * Tx perspective where as the input from user is from Rx filter view.
2444 input
->dst_port
= fsp
->h_u
.tcp_ip4_spec
.psrc
;
2445 input
->src_port
= fsp
->h_u
.tcp_ip4_spec
.pdst
;
2446 input
->dst_ip
[0] = fsp
->h_u
.tcp_ip4_spec
.ip4src
;
2447 input
->src_ip
[0] = fsp
->h_u
.tcp_ip4_spec
.ip4dst
;
2449 if (ntohl(fsp
->m_ext
.data
[1])) {
2450 if (ntohl(fsp
->h_ext
.data
[1]) >= pf
->num_alloc_vfs
) {
2451 netif_info(pf
, drv
, vsi
->netdev
, "Invalid VF id\n");
2454 vf_id
= ntohl(fsp
->h_ext
.data
[1]);
2455 /* Find vsi id from vf id and override dest vsi */
2456 input
->dest_vsi
= pf
->vf
[vf_id
].lan_vsi_id
;
2457 if (input
->q_index
>= pf
->vf
[vf_id
].num_queue_pairs
) {
2458 netif_info(pf
, drv
, vsi
->netdev
, "Invalid queue id\n");
2463 ret
= i40e_add_del_fdir(vsi
, input
, true);
2468 i40e_update_ethtool_fdir_entry(vsi
, input
, fsp
->location
, NULL
);
2474 * i40e_set_rxnfc - command to set RX flow classification rules
2475 * @netdev: network interface device structure
2476 * @cmd: ethtool rxnfc command
2478 * Returns Success if the command is supported.
2480 static int i40e_set_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
)
2482 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2483 struct i40e_vsi
*vsi
= np
->vsi
;
2484 struct i40e_pf
*pf
= vsi
->back
;
2485 int ret
= -EOPNOTSUPP
;
2489 ret
= i40e_set_rss_hash_opt(pf
, cmd
);
2491 case ETHTOOL_SRXCLSRLINS
:
2492 ret
= i40e_add_fdir_ethtool(vsi
, cmd
);
2494 case ETHTOOL_SRXCLSRLDEL
:
2495 ret
= i40e_del_fdir_entry(vsi
, cmd
);
2505 * i40e_max_channels - get Max number of combined channels supported
2508 static unsigned int i40e_max_channels(struct i40e_vsi
*vsi
)
2510 /* TODO: This code assumes DCB and FD is disabled for now. */
2511 return vsi
->alloc_queue_pairs
;
2515 * i40e_get_channels - Get the current channels enabled and max supported etc.
2516 * @netdev: network interface device structure
2517 * @ch: ethtool channels structure
2519 * We don't support separate tx and rx queues as channels. The other count
2520 * represents how many queues are being used for control. max_combined counts
2521 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2522 * q_vectors since we support a lot more queue pairs than q_vectors.
2524 static void i40e_get_channels(struct net_device
*dev
,
2525 struct ethtool_channels
*ch
)
2527 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2528 struct i40e_vsi
*vsi
= np
->vsi
;
2529 struct i40e_pf
*pf
= vsi
->back
;
2531 /* report maximum channels */
2532 ch
->max_combined
= i40e_max_channels(vsi
);
2534 /* report info for other vector */
2535 ch
->other_count
= (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) ? 1 : 0;
2536 ch
->max_other
= ch
->other_count
;
2538 /* Note: This code assumes DCB is disabled for now. */
2539 ch
->combined_count
= vsi
->num_queue_pairs
;
2543 * i40e_set_channels - Set the new channels count.
2544 * @netdev: network interface device structure
2545 * @ch: ethtool channels structure
2547 * The new channels count may not be the same as requested by the user
2548 * since it gets rounded down to a power of 2 value.
2550 static int i40e_set_channels(struct net_device
*dev
,
2551 struct ethtool_channels
*ch
)
2553 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2554 unsigned int count
= ch
->combined_count
;
2555 struct i40e_vsi
*vsi
= np
->vsi
;
2556 struct i40e_pf
*pf
= vsi
->back
;
2559 /* We do not support setting channels for any other VSI at present */
2560 if (vsi
->type
!= I40E_VSI_MAIN
)
2563 /* verify they are not requesting separate vectors */
2564 if (!count
|| ch
->rx_count
|| ch
->tx_count
)
2567 /* verify other_count has not changed */
2568 if (ch
->other_count
!= ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) ? 1 : 0))
2571 /* verify the number of channels does not exceed hardware limits */
2572 if (count
> i40e_max_channels(vsi
))
2575 /* update feature limits from largest to smallest supported values */
2576 /* TODO: Flow director limit, DCB etc */
2578 /* use rss_reconfig to rebuild with new queue count and update traffic
2579 * class queue mapping
2581 new_count
= i40e_reconfig_rss_queues(pf
, count
);
2589 * i40e_get_rxfh_key_size - get the RSS hash key size
2590 * @netdev: network interface device structure
2592 * Returns the table size.
2594 static u32
i40e_get_rxfh_key_size(struct net_device
*netdev
)
2596 return I40E_HKEY_ARRAY_SIZE
;
2600 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2601 * @netdev: network interface device structure
2603 * Returns the table size.
2605 static u32
i40e_get_rxfh_indir_size(struct net_device
*netdev
)
2607 return I40E_HLUT_ARRAY_SIZE
;
2610 static int i40e_get_rxfh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
2613 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2614 struct i40e_vsi
*vsi
= np
->vsi
;
2615 u8
*lut
, *seed
= NULL
;
2620 *hfunc
= ETH_RSS_HASH_TOP
;
2626 lut
= kzalloc(I40E_HLUT_ARRAY_SIZE
, GFP_KERNEL
);
2629 ret
= i40e_get_rss(vsi
, seed
, lut
, I40E_HLUT_ARRAY_SIZE
);
2632 for (i
= 0; i
< I40E_HLUT_ARRAY_SIZE
; i
++)
2633 indir
[i
] = (u32
)(lut
[i
]);
2642 * i40e_set_rxfh - set the rx flow hash indirection table
2643 * @netdev: network interface device structure
2644 * @indir: indirection table
2647 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
2648 * returns 0 after programming the table.
2650 static int i40e_set_rxfh(struct net_device
*netdev
, const u32
*indir
,
2651 const u8
*key
, const u8 hfunc
)
2653 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2654 struct i40e_vsi
*vsi
= np
->vsi
;
2658 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
2665 if (!vsi
->rss_hkey_user
) {
2666 vsi
->rss_hkey_user
= kzalloc(I40E_HKEY_ARRAY_SIZE
,
2668 if (!vsi
->rss_hkey_user
)
2671 memcpy(vsi
->rss_hkey_user
, key
, I40E_HKEY_ARRAY_SIZE
);
2672 seed
= vsi
->rss_hkey_user
;
2674 if (!vsi
->rss_lut_user
) {
2675 vsi
->rss_lut_user
= kzalloc(I40E_HLUT_ARRAY_SIZE
, GFP_KERNEL
);
2676 if (!vsi
->rss_lut_user
)
2680 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2681 for (i
= 0; i
< I40E_HLUT_ARRAY_SIZE
; i
++)
2682 vsi
->rss_lut_user
[i
] = (u8
)(indir
[i
]);
2684 return i40e_config_rss(vsi
, seed
, vsi
->rss_lut_user
,
2685 I40E_HLUT_ARRAY_SIZE
);
2689 * i40e_get_priv_flags - report device private flags
2690 * @dev: network interface device structure
2692 * The get string set count and the string set should be matched for each
2693 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2696 * Returns a u32 bitmap of flags.
2698 static u32
i40e_get_priv_flags(struct net_device
*dev
)
2700 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2701 struct i40e_vsi
*vsi
= np
->vsi
;
2702 struct i40e_pf
*pf
= vsi
->back
;
2705 ret_flags
|= pf
->hw
.func_caps
.npar_enable
?
2706 I40E_PRIV_FLAGS_NPAR_FLAG
: 0;
2707 ret_flags
|= pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
?
2708 I40E_PRIV_FLAGS_LINKPOLL_FLAG
: 0;
2709 ret_flags
|= pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
?
2710 I40E_PRIV_FLAGS_FD_ATR
: 0;
2711 ret_flags
|= pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
?
2712 I40E_PRIV_FLAGS_VEB_STATS
: 0;
2713 ret_flags
|= pf
->flags
& I40E_FLAG_RX_PS_ENABLED
?
2714 I40E_PRIV_FLAGS_PS
: 0;
2720 * i40e_set_priv_flags - set private flags
2721 * @dev: network interface device structure
2722 * @flags: bit flags to be set
2724 static int i40e_set_priv_flags(struct net_device
*dev
, u32 flags
)
2726 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2727 struct i40e_vsi
*vsi
= np
->vsi
;
2728 struct i40e_pf
*pf
= vsi
->back
;
2729 bool reset_required
= false;
2731 /* NOTE: MFP is not settable */
2733 /* allow the user to control the method of receive
2734 * buffer DMA, whether the packet is split at header
2735 * boundaries into two separate buffers. In some cases
2736 * one routine or the other will perform better.
2738 if ((flags
& I40E_PRIV_FLAGS_PS
) &&
2739 !(pf
->flags
& I40E_FLAG_RX_PS_ENABLED
)) {
2740 pf
->flags
|= I40E_FLAG_RX_PS_ENABLED
;
2741 pf
->flags
&= ~I40E_FLAG_RX_1BUF_ENABLED
;
2742 reset_required
= true;
2743 } else if (!(flags
& I40E_PRIV_FLAGS_PS
) &&
2744 (pf
->flags
& I40E_FLAG_RX_PS_ENABLED
)) {
2745 pf
->flags
&= ~I40E_FLAG_RX_PS_ENABLED
;
2746 pf
->flags
|= I40E_FLAG_RX_1BUF_ENABLED
;
2747 reset_required
= true;
2750 if (flags
& I40E_PRIV_FLAGS_LINKPOLL_FLAG
)
2751 pf
->flags
|= I40E_FLAG_LINK_POLLING_ENABLED
;
2753 pf
->flags
&= ~I40E_FLAG_LINK_POLLING_ENABLED
;
2755 /* allow the user to control the state of the Flow
2756 * Director ATR (Application Targeted Routing) feature
2759 if (flags
& I40E_PRIV_FLAGS_FD_ATR
) {
2760 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
2762 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
2763 pf
->auto_disable_flags
|= I40E_FLAG_FD_ATR_ENABLED
;
2766 if (flags
& I40E_PRIV_FLAGS_VEB_STATS
)
2767 pf
->flags
|= I40E_FLAG_VEB_STATS_ENABLED
;
2769 pf
->flags
&= ~I40E_FLAG_VEB_STATS_ENABLED
;
2771 /* if needed, issue reset to cause things to take effect */
2773 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
2778 static const struct ethtool_ops i40e_ethtool_ops
= {
2779 .get_settings
= i40e_get_settings
,
2780 .set_settings
= i40e_set_settings
,
2781 .get_drvinfo
= i40e_get_drvinfo
,
2782 .get_regs_len
= i40e_get_regs_len
,
2783 .get_regs
= i40e_get_regs
,
2784 .nway_reset
= i40e_nway_reset
,
2785 .get_link
= ethtool_op_get_link
,
2786 .get_wol
= i40e_get_wol
,
2787 .set_wol
= i40e_set_wol
,
2788 .set_eeprom
= i40e_set_eeprom
,
2789 .get_eeprom_len
= i40e_get_eeprom_len
,
2790 .get_eeprom
= i40e_get_eeprom
,
2791 .get_ringparam
= i40e_get_ringparam
,
2792 .set_ringparam
= i40e_set_ringparam
,
2793 .get_pauseparam
= i40e_get_pauseparam
,
2794 .set_pauseparam
= i40e_set_pauseparam
,
2795 .get_msglevel
= i40e_get_msglevel
,
2796 .set_msglevel
= i40e_set_msglevel
,
2797 .get_rxnfc
= i40e_get_rxnfc
,
2798 .set_rxnfc
= i40e_set_rxnfc
,
2799 .self_test
= i40e_diag_test
,
2800 .get_strings
= i40e_get_strings
,
2801 .set_phys_id
= i40e_set_phys_id
,
2802 .get_sset_count
= i40e_get_sset_count
,
2803 .get_ethtool_stats
= i40e_get_ethtool_stats
,
2804 .get_coalesce
= i40e_get_coalesce
,
2805 .set_coalesce
= i40e_set_coalesce
,
2806 .get_rxfh_key_size
= i40e_get_rxfh_key_size
,
2807 .get_rxfh_indir_size
= i40e_get_rxfh_indir_size
,
2808 .get_rxfh
= i40e_get_rxfh
,
2809 .set_rxfh
= i40e_set_rxfh
,
2810 .get_channels
= i40e_get_channels
,
2811 .set_channels
= i40e_set_channels
,
2812 .get_ts_info
= i40e_get_ts_info
,
2813 .get_priv_flags
= i40e_get_priv_flags
,
2814 .set_priv_flags
= i40e_set_priv_flags
,
2817 void i40e_set_ethtool_ops(struct net_device
*netdev
)
2819 netdev
->ethtool_ops
= &i40e_ethtool_ops
;