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
),
93 static int i40e_add_fdir_ethtool(struct i40e_vsi
*vsi
,
94 struct ethtool_rxnfc
*cmd
);
96 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
106 static struct i40e_stats i40e_gstrings_stats
[] = {
107 I40E_PF_STAT("rx_bytes", stats
.eth
.rx_bytes
),
108 I40E_PF_STAT("tx_bytes", stats
.eth
.tx_bytes
),
109 I40E_PF_STAT("rx_unicast", stats
.eth
.rx_unicast
),
110 I40E_PF_STAT("tx_unicast", stats
.eth
.tx_unicast
),
111 I40E_PF_STAT("rx_multicast", stats
.eth
.rx_multicast
),
112 I40E_PF_STAT("tx_multicast", stats
.eth
.tx_multicast
),
113 I40E_PF_STAT("rx_broadcast", stats
.eth
.rx_broadcast
),
114 I40E_PF_STAT("tx_broadcast", stats
.eth
.tx_broadcast
),
115 I40E_PF_STAT("tx_errors", stats
.eth
.tx_errors
),
116 I40E_PF_STAT("rx_dropped", stats
.eth
.rx_discards
),
117 I40E_PF_STAT("tx_dropped_link_down", stats
.tx_dropped_link_down
),
118 I40E_PF_STAT("rx_crc_errors", stats
.crc_errors
),
119 I40E_PF_STAT("illegal_bytes", stats
.illegal_bytes
),
120 I40E_PF_STAT("mac_local_faults", stats
.mac_local_faults
),
121 I40E_PF_STAT("mac_remote_faults", stats
.mac_remote_faults
),
122 I40E_PF_STAT("tx_timeout", tx_timeout_count
),
123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error
),
124 I40E_PF_STAT("rx_length_errors", stats
.rx_length_errors
),
125 I40E_PF_STAT("link_xon_rx", stats
.link_xon_rx
),
126 I40E_PF_STAT("link_xoff_rx", stats
.link_xoff_rx
),
127 I40E_PF_STAT("link_xon_tx", stats
.link_xon_tx
),
128 I40E_PF_STAT("link_xoff_tx", stats
.link_xoff_tx
),
129 I40E_PF_STAT("rx_size_64", stats
.rx_size_64
),
130 I40E_PF_STAT("rx_size_127", stats
.rx_size_127
),
131 I40E_PF_STAT("rx_size_255", stats
.rx_size_255
),
132 I40E_PF_STAT("rx_size_511", stats
.rx_size_511
),
133 I40E_PF_STAT("rx_size_1023", stats
.rx_size_1023
),
134 I40E_PF_STAT("rx_size_1522", stats
.rx_size_1522
),
135 I40E_PF_STAT("rx_size_big", stats
.rx_size_big
),
136 I40E_PF_STAT("tx_size_64", stats
.tx_size_64
),
137 I40E_PF_STAT("tx_size_127", stats
.tx_size_127
),
138 I40E_PF_STAT("tx_size_255", stats
.tx_size_255
),
139 I40E_PF_STAT("tx_size_511", stats
.tx_size_511
),
140 I40E_PF_STAT("tx_size_1023", stats
.tx_size_1023
),
141 I40E_PF_STAT("tx_size_1522", stats
.tx_size_1522
),
142 I40E_PF_STAT("tx_size_big", stats
.tx_size_big
),
143 I40E_PF_STAT("rx_undersize", stats
.rx_undersize
),
144 I40E_PF_STAT("rx_fragments", stats
.rx_fragments
),
145 I40E_PF_STAT("rx_oversize", stats
.rx_oversize
),
146 I40E_PF_STAT("rx_jabber", stats
.rx_jabber
),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests
),
148 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared
),
149 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt
),
150 I40E_PF_STAT("fdir_atr_match", stats
.fd_atr_match
),
151 I40E_PF_STAT("fdir_atr_tunnel_match", stats
.fd_atr_tunnel_match
),
152 I40E_PF_STAT("fdir_atr_status", stats
.fd_atr_status
),
153 I40E_PF_STAT("fdir_sb_match", stats
.fd_sb_match
),
154 I40E_PF_STAT("fdir_sb_status", stats
.fd_sb_status
),
157 I40E_PF_STAT("tx_lpi_status", stats
.tx_lpi_status
),
158 I40E_PF_STAT("rx_lpi_status", stats
.rx_lpi_status
),
159 I40E_PF_STAT("tx_lpi_count", stats
.tx_lpi_count
),
160 I40E_PF_STAT("rx_lpi_count", stats
.rx_lpi_count
),
164 static const struct i40e_stats i40e_gstrings_fcoe_stats
[] = {
165 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats
.fcoe_bad_fccrc
),
166 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats
.rx_fcoe_dropped
),
167 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats
.rx_fcoe_packets
),
168 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats
.rx_fcoe_dwords
),
169 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats
.fcoe_ddp_count
),
170 I40E_VSI_STAT("fcoe_last_error", fcoe_stats
.fcoe_last_error
),
171 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats
.tx_fcoe_packets
),
172 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats
.tx_fcoe_dwords
),
175 #endif /* I40E_FCOE */
176 #define I40E_QUEUE_STATS_LEN(n) \
177 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
178 * 2 /* Tx and Rx together */ \
179 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
180 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
181 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
182 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
184 #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
185 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
186 I40E_FCOE_STATS_LEN + \
187 I40E_MISC_STATS_LEN + \
188 I40E_QUEUE_STATS_LEN((n)))
190 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
191 I40E_MISC_STATS_LEN + \
192 I40E_QUEUE_STATS_LEN((n)))
193 #endif /* I40E_FCOE */
194 #define I40E_PFC_STATS_LEN ( \
195 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
201 #define I40E_VEB_TC_STATS_LEN ( \
202 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
207 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
208 #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
209 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
210 I40E_PFC_STATS_LEN + \
211 I40E_VSI_STATS_LEN((n)))
213 enum i40e_ethtool_test_id
{
214 I40E_ETH_TEST_REG
= 0,
215 I40E_ETH_TEST_EEPROM
,
217 I40E_ETH_TEST_LOOPBACK
,
221 static const char i40e_gstrings_test
[][ETH_GSTRING_LEN
] = {
222 "Register test (offline)",
223 "Eeprom test (offline)",
224 "Interrupt test (offline)",
225 "Loopback 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
] = {
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
)
260 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
261 u32 link_speed
= hw_link_info
->link_speed
;
263 /* Initialize supported and advertised settings based on phy settings */
264 switch (hw_link_info
->phy_type
) {
265 case I40E_PHY_TYPE_40GBASE_CR4
:
266 case I40E_PHY_TYPE_40GBASE_CR4_CU
:
267 ecmd
->supported
= SUPPORTED_Autoneg
|
268 SUPPORTED_40000baseCR4_Full
;
269 ecmd
->advertising
= ADVERTISED_Autoneg
|
270 ADVERTISED_40000baseCR4_Full
;
272 case I40E_PHY_TYPE_XLAUI
:
273 case I40E_PHY_TYPE_XLPPI
:
274 case I40E_PHY_TYPE_40GBASE_AOC
:
275 ecmd
->supported
= SUPPORTED_40000baseCR4_Full
;
277 case I40E_PHY_TYPE_40GBASE_SR4
:
278 ecmd
->supported
= SUPPORTED_40000baseSR4_Full
;
280 case I40E_PHY_TYPE_40GBASE_LR4
:
281 ecmd
->supported
= SUPPORTED_40000baseLR4_Full
;
283 case I40E_PHY_TYPE_10GBASE_SR
:
284 case I40E_PHY_TYPE_10GBASE_LR
:
285 case I40E_PHY_TYPE_1000BASE_SX
:
286 case I40E_PHY_TYPE_1000BASE_LX
:
287 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
288 if (hw_link_info
->module_type
[2] &
289 I40E_MODULE_TYPE_1000BASE_SX
||
290 hw_link_info
->module_type
[2] &
291 I40E_MODULE_TYPE_1000BASE_LX
) {
292 ecmd
->supported
|= SUPPORTED_1000baseT_Full
;
293 if (hw_link_info
->requested_speeds
&
295 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
297 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
298 ecmd
->advertising
|= ADVERTISED_10000baseT_Full
;
300 case I40E_PHY_TYPE_10GBASE_T
:
301 case I40E_PHY_TYPE_1000BASE_T
:
302 case I40E_PHY_TYPE_100BASE_TX
:
303 ecmd
->supported
= SUPPORTED_Autoneg
|
304 SUPPORTED_10000baseT_Full
|
305 SUPPORTED_1000baseT_Full
|
306 SUPPORTED_100baseT_Full
;
307 ecmd
->advertising
= ADVERTISED_Autoneg
;
308 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
309 ecmd
->advertising
|= ADVERTISED_10000baseT_Full
;
310 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
311 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
312 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_100MB
)
313 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
315 case I40E_PHY_TYPE_10GBASE_CR1_CU
:
316 case I40E_PHY_TYPE_10GBASE_CR1
:
317 ecmd
->supported
= SUPPORTED_Autoneg
|
318 SUPPORTED_10000baseT_Full
;
319 ecmd
->advertising
= ADVERTISED_Autoneg
|
320 ADVERTISED_10000baseT_Full
;
322 case I40E_PHY_TYPE_XAUI
:
323 case I40E_PHY_TYPE_XFI
:
324 case I40E_PHY_TYPE_SFI
:
325 case I40E_PHY_TYPE_10GBASE_SFPP_CU
:
326 case I40E_PHY_TYPE_10GBASE_AOC
:
327 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
329 case I40E_PHY_TYPE_SGMII
:
330 ecmd
->supported
= SUPPORTED_Autoneg
|
331 SUPPORTED_1000baseT_Full
|
332 SUPPORTED_100baseT_Full
;
333 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
334 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
335 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_100MB
)
336 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
338 /* Backplane is set based on supported phy types in get_settings
339 * so don't set anything here but don't warn either
341 case I40E_PHY_TYPE_40GBASE_KR4
:
342 case I40E_PHY_TYPE_20GBASE_KR2
:
343 case I40E_PHY_TYPE_10GBASE_KR
:
344 case I40E_PHY_TYPE_10GBASE_KX4
:
345 case I40E_PHY_TYPE_1000BASE_KX
:
348 /* if we got here and link is up something bad is afoot */
349 netdev_info(netdev
, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
350 hw_link_info
->phy_type
);
353 /* Set speed and duplex */
354 switch (link_speed
) {
355 case I40E_LINK_SPEED_40GB
:
356 ethtool_cmd_speed_set(ecmd
, SPEED_40000
);
358 case I40E_LINK_SPEED_20GB
:
359 ethtool_cmd_speed_set(ecmd
, SPEED_20000
);
361 case I40E_LINK_SPEED_10GB
:
362 ethtool_cmd_speed_set(ecmd
, SPEED_10000
);
364 case I40E_LINK_SPEED_1GB
:
365 ethtool_cmd_speed_set(ecmd
, SPEED_1000
);
367 case I40E_LINK_SPEED_100MB
:
368 ethtool_cmd_speed_set(ecmd
, SPEED_100
);
373 ecmd
->duplex
= DUPLEX_FULL
;
377 * i40e_get_settings_link_down - Get the Link settings for when link is down
379 * @ecmd: ethtool command to fill in
381 * Reports link settings that can be determined when link is down
383 static void i40e_get_settings_link_down(struct i40e_hw
*hw
,
384 struct ethtool_cmd
*ecmd
)
386 enum i40e_aq_capabilities_phy_type phy_types
= hw
->phy
.phy_types
;
388 /* link is down and the driver needs to fall back on
389 * supported phy types to figure out what info to display
391 ecmd
->supported
= 0x0;
392 ecmd
->advertising
= 0x0;
393 if (phy_types
& I40E_CAP_PHY_TYPE_SGMII
) {
394 ecmd
->supported
|= SUPPORTED_Autoneg
|
395 SUPPORTED_1000baseT_Full
|
396 SUPPORTED_100baseT_Full
;
397 ecmd
->advertising
|= ADVERTISED_Autoneg
|
398 ADVERTISED_1000baseT_Full
|
399 ADVERTISED_100baseT_Full
;
401 if (phy_types
& I40E_CAP_PHY_TYPE_XAUI
||
402 phy_types
& I40E_CAP_PHY_TYPE_XFI
||
403 phy_types
& I40E_CAP_PHY_TYPE_SFI
||
404 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU
||
405 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_AOC
)
406 ecmd
->supported
|= SUPPORTED_10000baseT_Full
;
407 if (phy_types
& I40E_CAP_PHY_TYPE_10GBASE_CR1_CU
||
408 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_CR1
||
409 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_T
||
410 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_SR
||
411 phy_types
& I40E_CAP_PHY_TYPE_10GBASE_LR
) {
412 ecmd
->supported
|= SUPPORTED_Autoneg
|
413 SUPPORTED_10000baseT_Full
;
414 ecmd
->advertising
|= ADVERTISED_Autoneg
|
415 ADVERTISED_10000baseT_Full
;
417 if (phy_types
& I40E_CAP_PHY_TYPE_XLAUI
||
418 phy_types
& I40E_CAP_PHY_TYPE_XLPPI
||
419 phy_types
& I40E_CAP_PHY_TYPE_40GBASE_AOC
)
420 ecmd
->supported
|= SUPPORTED_40000baseCR4_Full
;
421 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_CR4_CU
||
422 phy_types
& I40E_CAP_PHY_TYPE_40GBASE_CR4
) {
423 ecmd
->supported
|= SUPPORTED_Autoneg
|
424 SUPPORTED_40000baseCR4_Full
;
425 ecmd
->advertising
|= ADVERTISED_Autoneg
|
426 ADVERTISED_40000baseCR4_Full
;
428 if (phy_types
& I40E_CAP_PHY_TYPE_100BASE_TX
) {
429 ecmd
->supported
|= SUPPORTED_Autoneg
|
430 SUPPORTED_100baseT_Full
;
431 ecmd
->advertising
|= ADVERTISED_Autoneg
|
432 ADVERTISED_100baseT_Full
;
434 if (phy_types
& I40E_CAP_PHY_TYPE_1000BASE_T
||
435 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_SX
||
436 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_LX
||
437 phy_types
& I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL
) {
438 ecmd
->supported
|= SUPPORTED_Autoneg
|
439 SUPPORTED_1000baseT_Full
;
440 ecmd
->advertising
|= ADVERTISED_Autoneg
|
441 ADVERTISED_1000baseT_Full
;
443 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_SR4
)
444 ecmd
->supported
|= SUPPORTED_40000baseSR4_Full
;
445 if (phy_types
& I40E_CAP_PHY_TYPE_40GBASE_LR4
)
446 ecmd
->supported
|= SUPPORTED_40000baseLR4_Full
;
448 /* With no link speed and duplex are unknown */
449 ethtool_cmd_speed_set(ecmd
, SPEED_UNKNOWN
);
450 ecmd
->duplex
= DUPLEX_UNKNOWN
;
454 * i40e_get_settings - Get Link Speed and Duplex settings
455 * @netdev: network interface device structure
456 * @ecmd: ethtool command
458 * Reports speed/duplex settings based on media_type
460 static int i40e_get_settings(struct net_device
*netdev
,
461 struct ethtool_cmd
*ecmd
)
463 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
464 struct i40e_pf
*pf
= np
->vsi
->back
;
465 struct i40e_hw
*hw
= &pf
->hw
;
466 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
467 bool link_up
= hw_link_info
->link_info
& I40E_AQ_LINK_UP
;
470 i40e_get_settings_link_up(hw
, ecmd
, netdev
);
472 i40e_get_settings_link_down(hw
, ecmd
);
474 /* Now set the settings that don't rely on link being up/down */
476 /* For backplane, supported and advertised are only reliant on the
477 * phy types the NVM specifies are supported.
479 if (hw
->device_id
== I40E_DEV_ID_KX_B
||
480 hw
->device_id
== I40E_DEV_ID_KX_C
||
481 hw
->device_id
== I40E_DEV_ID_20G_KR2
||
482 hw
->device_id
== I40E_DEV_ID_20G_KR2_A
) {
483 ecmd
->supported
= SUPPORTED_Autoneg
;
484 ecmd
->advertising
= ADVERTISED_Autoneg
;
485 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_40GBASE_KR4
) {
486 ecmd
->supported
|= SUPPORTED_40000baseKR4_Full
;
487 ecmd
->advertising
|= ADVERTISED_40000baseKR4_Full
;
489 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_20GBASE_KR2
) {
490 ecmd
->supported
|= SUPPORTED_20000baseKR2_Full
;
491 ecmd
->advertising
|= ADVERTISED_20000baseKR2_Full
;
493 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_10GBASE_KR
) {
494 ecmd
->supported
|= SUPPORTED_10000baseKR_Full
;
495 ecmd
->advertising
|= ADVERTISED_10000baseKR_Full
;
497 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_10GBASE_KX4
) {
498 ecmd
->supported
|= SUPPORTED_10000baseKX4_Full
;
499 ecmd
->advertising
|= ADVERTISED_10000baseKX4_Full
;
501 if (hw
->phy
.phy_types
& I40E_CAP_PHY_TYPE_1000BASE_KX
) {
502 ecmd
->supported
|= SUPPORTED_1000baseKX_Full
;
503 ecmd
->advertising
|= ADVERTISED_1000baseKX_Full
;
507 /* Set autoneg settings */
508 ecmd
->autoneg
= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
509 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
511 switch (hw
->phy
.media_type
) {
512 case I40E_MEDIA_TYPE_BACKPLANE
:
513 ecmd
->supported
|= SUPPORTED_Autoneg
|
515 ecmd
->advertising
|= ADVERTISED_Autoneg
|
516 ADVERTISED_Backplane
;
517 ecmd
->port
= PORT_NONE
;
519 case I40E_MEDIA_TYPE_BASET
:
520 ecmd
->supported
|= SUPPORTED_TP
;
521 ecmd
->advertising
|= ADVERTISED_TP
;
522 ecmd
->port
= PORT_TP
;
524 case I40E_MEDIA_TYPE_DA
:
525 case I40E_MEDIA_TYPE_CX4
:
526 ecmd
->supported
|= SUPPORTED_FIBRE
;
527 ecmd
->advertising
|= ADVERTISED_FIBRE
;
528 ecmd
->port
= PORT_DA
;
530 case I40E_MEDIA_TYPE_FIBER
:
531 ecmd
->supported
|= SUPPORTED_FIBRE
;
532 ecmd
->port
= PORT_FIBRE
;
534 case I40E_MEDIA_TYPE_UNKNOWN
:
536 ecmd
->port
= PORT_OTHER
;
540 /* Set transceiver */
541 ecmd
->transceiver
= XCVR_EXTERNAL
;
543 /* Set flow control settings */
544 ecmd
->supported
|= SUPPORTED_Pause
;
546 switch (hw
->fc
.requested_mode
) {
548 ecmd
->advertising
|= ADVERTISED_Pause
;
550 case I40E_FC_TX_PAUSE
:
551 ecmd
->advertising
|= ADVERTISED_Asym_Pause
;
553 case I40E_FC_RX_PAUSE
:
554 ecmd
->advertising
|= (ADVERTISED_Pause
|
555 ADVERTISED_Asym_Pause
);
558 ecmd
->advertising
&= ~(ADVERTISED_Pause
|
559 ADVERTISED_Asym_Pause
);
567 * i40e_set_settings - Set Speed and Duplex
568 * @netdev: network interface device structure
569 * @ecmd: ethtool command
571 * Set speed/duplex per media_types advertised/forced
573 static int i40e_set_settings(struct net_device
*netdev
,
574 struct ethtool_cmd
*ecmd
)
576 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
577 struct i40e_aq_get_phy_abilities_resp abilities
;
578 struct i40e_aq_set_phy_config config
;
579 struct i40e_pf
*pf
= np
->vsi
->back
;
580 struct i40e_vsi
*vsi
= np
->vsi
;
581 struct i40e_hw
*hw
= &pf
->hw
;
582 struct ethtool_cmd safe_ecmd
;
583 i40e_status status
= 0;
589 /* Changing port settings is not supported if this isn't the
590 * port's controlling PF
592 if (hw
->partition_id
!= 1) {
593 i40e_partition_setting_complaint(pf
);
597 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
600 if (hw
->phy
.media_type
!= I40E_MEDIA_TYPE_BASET
&&
601 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_FIBER
&&
602 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_BACKPLANE
&&
603 hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
)
606 if (hw
->device_id
== I40E_DEV_ID_KX_B
||
607 hw
->device_id
== I40E_DEV_ID_KX_C
||
608 hw
->device_id
== I40E_DEV_ID_20G_KR2
||
609 hw
->device_id
== I40E_DEV_ID_20G_KR2_A
) {
610 netdev_info(netdev
, "Changing settings is not supported on backplane.\n");
614 /* get our own copy of the bits to check against */
615 memset(&safe_ecmd
, 0, sizeof(struct ethtool_cmd
));
616 i40e_get_settings(netdev
, &safe_ecmd
);
618 /* save autoneg and speed out of ecmd */
619 autoneg
= ecmd
->autoneg
;
620 advertise
= ecmd
->advertising
;
622 /* set autoneg and speed back to what they currently are */
623 ecmd
->autoneg
= safe_ecmd
.autoneg
;
624 ecmd
->advertising
= safe_ecmd
.advertising
;
626 ecmd
->cmd
= safe_ecmd
.cmd
;
627 /* If ecmd and safe_ecmd are not the same now, then they are
628 * trying to set something that we do not support
630 if (memcmp(ecmd
, &safe_ecmd
, sizeof(struct ethtool_cmd
)))
633 while (test_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
634 usleep_range(1000, 2000);
636 /* Get the current phy config */
637 status
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
,
642 /* Copy abilities to config in case autoneg is not
645 memset(&config
, 0, sizeof(struct i40e_aq_set_phy_config
));
646 config
.abilities
= abilities
.abilities
;
649 if (autoneg
== AUTONEG_ENABLE
) {
650 /* If autoneg is not supported, return error */
651 if (!(safe_ecmd
.supported
& SUPPORTED_Autoneg
)) {
652 netdev_info(netdev
, "Autoneg not supported on this phy\n");
655 /* If autoneg was not already enabled */
656 if (!(hw
->phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
)) {
657 config
.abilities
= abilities
.abilities
|
658 I40E_AQ_PHY_ENABLE_AN
;
662 /* If autoneg is supported 10GBASE_T is the only phy that
663 * can disable it, so otherwise return error
665 if (safe_ecmd
.supported
& SUPPORTED_Autoneg
&&
666 hw
->phy
.link_info
.phy_type
!= I40E_PHY_TYPE_10GBASE_T
) {
667 netdev_info(netdev
, "Autoneg cannot be disabled on this phy\n");
670 /* If autoneg is currently enabled */
671 if (hw
->phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
) {
672 config
.abilities
= abilities
.abilities
&
673 ~I40E_AQ_PHY_ENABLE_AN
;
678 if (advertise
& ~safe_ecmd
.supported
)
681 if (advertise
& ADVERTISED_100baseT_Full
)
682 config
.link_speed
|= I40E_LINK_SPEED_100MB
;
683 if (advertise
& ADVERTISED_1000baseT_Full
||
684 advertise
& ADVERTISED_1000baseKX_Full
)
685 config
.link_speed
|= I40E_LINK_SPEED_1GB
;
686 if (advertise
& ADVERTISED_10000baseT_Full
||
687 advertise
& ADVERTISED_10000baseKX4_Full
||
688 advertise
& ADVERTISED_10000baseKR_Full
)
689 config
.link_speed
|= I40E_LINK_SPEED_10GB
;
690 if (advertise
& ADVERTISED_20000baseKR2_Full
)
691 config
.link_speed
|= I40E_LINK_SPEED_20GB
;
692 if (advertise
& ADVERTISED_40000baseKR4_Full
||
693 advertise
& ADVERTISED_40000baseCR4_Full
||
694 advertise
& ADVERTISED_40000baseSR4_Full
||
695 advertise
& ADVERTISED_40000baseLR4_Full
)
696 config
.link_speed
|= I40E_LINK_SPEED_40GB
;
698 /* If speed didn't get set, set it to what it currently is.
699 * This is needed because if advertise is 0 (as it is when autoneg
700 * is disabled) then speed won't get set.
702 if (!config
.link_speed
)
703 config
.link_speed
= abilities
.link_speed
;
705 if (change
|| (abilities
.link_speed
!= config
.link_speed
)) {
706 /* copy over the rest of the abilities */
707 config
.phy_type
= abilities
.phy_type
;
708 config
.eee_capability
= abilities
.eee_capability
;
709 config
.eeer
= abilities
.eeer_val
;
710 config
.low_power_ctrl
= abilities
.d3_lpan
;
712 /* save the requested speeds */
713 hw
->phy
.link_info
.requested_speeds
= config
.link_speed
;
714 /* set link and auto negotiation so changes take effect */
715 config
.abilities
|= I40E_AQ_PHY_ENABLE_ATOMIC_LINK
;
716 /* If link is up put link down */
717 if (hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) {
718 /* Tell the OS link is going down, the link will go
719 * back up when fw says it is ready asynchronously
721 i40e_print_link_message(vsi
, false);
722 netif_carrier_off(netdev
);
723 netif_tx_stop_all_queues(netdev
);
726 /* make the aq call */
727 status
= i40e_aq_set_phy_config(hw
, &config
, NULL
);
729 netdev_info(netdev
, "Set phy config failed, err %s aq_err %s\n",
730 i40e_stat_str(hw
, status
),
731 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
735 status
= i40e_update_link_info(hw
);
737 netdev_info(netdev
, "Updating link info failed with err %s aq_err %s\n",
738 i40e_stat_str(hw
, status
),
739 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
742 netdev_info(netdev
, "Nothing changed, exiting without setting anything.\n");
748 static int i40e_nway_reset(struct net_device
*netdev
)
750 /* restart autonegotiation */
751 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
752 struct i40e_pf
*pf
= np
->vsi
->back
;
753 struct i40e_hw
*hw
= &pf
->hw
;
754 bool link_up
= hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
757 ret
= i40e_aq_set_link_restart_an(hw
, link_up
, NULL
);
759 netdev_info(netdev
, "link restart failed, err %s aq_err %s\n",
760 i40e_stat_str(hw
, ret
),
761 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
769 * i40e_get_pauseparam - Get Flow Control status
770 * Return tx/rx-pause status
772 static void i40e_get_pauseparam(struct net_device
*netdev
,
773 struct ethtool_pauseparam
*pause
)
775 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
776 struct i40e_pf
*pf
= np
->vsi
->back
;
777 struct i40e_hw
*hw
= &pf
->hw
;
778 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
779 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
782 ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
783 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
785 /* PFC enabled so report LFC as off */
786 if (dcbx_cfg
->pfc
.pfcenable
) {
792 if (hw
->fc
.current_mode
== I40E_FC_RX_PAUSE
) {
794 } else if (hw
->fc
.current_mode
== I40E_FC_TX_PAUSE
) {
796 } else if (hw
->fc
.current_mode
== I40E_FC_FULL
) {
803 * i40e_set_pauseparam - Set Flow Control parameter
804 * @netdev: network interface device structure
805 * @pause: return tx/rx flow control status
807 static int i40e_set_pauseparam(struct net_device
*netdev
,
808 struct ethtool_pauseparam
*pause
)
810 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
811 struct i40e_pf
*pf
= np
->vsi
->back
;
812 struct i40e_vsi
*vsi
= np
->vsi
;
813 struct i40e_hw
*hw
= &pf
->hw
;
814 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
815 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
816 bool link_up
= hw_link_info
->link_info
& I40E_AQ_LINK_UP
;
821 /* Changing the port's flow control is not supported if this isn't the
822 * port's controlling PF
824 if (hw
->partition_id
!= 1) {
825 i40e_partition_setting_complaint(pf
);
829 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
832 if (pause
->autoneg
!= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
833 AUTONEG_ENABLE
: AUTONEG_DISABLE
)) {
834 netdev_info(netdev
, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
838 /* If we have link and don't have autoneg */
839 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
840 !(hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
)) {
841 /* Send message that it might not necessarily work*/
842 netdev_info(netdev
, "Autoneg did not complete so changing settings may not result in an actual change.\n");
845 if (dcbx_cfg
->pfc
.pfcenable
) {
847 "Priority flow control enabled. Cannot set link flow control.\n");
851 if (pause
->rx_pause
&& pause
->tx_pause
)
852 hw
->fc
.requested_mode
= I40E_FC_FULL
;
853 else if (pause
->rx_pause
&& !pause
->tx_pause
)
854 hw
->fc
.requested_mode
= I40E_FC_RX_PAUSE
;
855 else if (!pause
->rx_pause
&& pause
->tx_pause
)
856 hw
->fc
.requested_mode
= I40E_FC_TX_PAUSE
;
857 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
858 hw
->fc
.requested_mode
= I40E_FC_NONE
;
862 /* Tell the OS link is going down, the link will go back up when fw
863 * says it is ready asynchronously
865 i40e_print_link_message(vsi
, false);
866 netif_carrier_off(netdev
);
867 netif_tx_stop_all_queues(netdev
);
869 /* Set the fc mode and only restart an if link is up*/
870 status
= i40e_set_fc(hw
, &aq_failures
, link_up
);
872 if (aq_failures
& I40E_SET_FC_AQ_FAIL_GET
) {
873 netdev_info(netdev
, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
874 i40e_stat_str(hw
, status
),
875 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
878 if (aq_failures
& I40E_SET_FC_AQ_FAIL_SET
) {
879 netdev_info(netdev
, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
880 i40e_stat_str(hw
, status
),
881 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
884 if (aq_failures
& I40E_SET_FC_AQ_FAIL_UPDATE
) {
885 netdev_info(netdev
, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
886 i40e_stat_str(hw
, status
),
887 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
891 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
892 /* Give it a little more time to try to come back */
894 if (!test_bit(__I40E_DOWN
, &pf
->state
))
895 return i40e_nway_reset(netdev
);
901 static u32
i40e_get_msglevel(struct net_device
*netdev
)
903 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
904 struct i40e_pf
*pf
= np
->vsi
->back
;
906 return pf
->msg_enable
;
909 static void i40e_set_msglevel(struct net_device
*netdev
, u32 data
)
911 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
912 struct i40e_pf
*pf
= np
->vsi
->back
;
914 if (I40E_DEBUG_USER
& data
)
915 pf
->hw
.debug_mask
= data
;
916 pf
->msg_enable
= data
;
919 static int i40e_get_regs_len(struct net_device
*netdev
)
924 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++)
925 reg_count
+= i40e_reg_list
[i
].elements
;
927 return reg_count
* sizeof(u32
);
930 static void i40e_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
,
933 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
934 struct i40e_pf
*pf
= np
->vsi
->back
;
935 struct i40e_hw
*hw
= &pf
->hw
;
940 /* Tell ethtool which driver-version-specific regs output we have.
942 * At some point, if we have ethtool doing special formatting of
943 * this data, it will rely on this version number to know how to
944 * interpret things. Hence, this needs to be updated if/when the
945 * diags register table is changed.
949 /* loop through the diags reg table for what to print */
951 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++) {
952 for (j
= 0; j
< i40e_reg_list
[i
].elements
; j
++) {
953 reg
= i40e_reg_list
[i
].offset
954 + (j
* i40e_reg_list
[i
].stride
);
955 reg_buf
[ri
++] = rd32(hw
, reg
);
961 static int i40e_get_eeprom(struct net_device
*netdev
,
962 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
964 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
965 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
966 struct i40e_pf
*pf
= np
->vsi
->back
;
967 int ret_val
= 0, len
, offset
;
973 #define I40E_NVM_SECTOR_SIZE 4096
974 if (eeprom
->len
== 0)
977 /* check for NVMUpdate access method */
978 magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
979 if (eeprom
->magic
&& eeprom
->magic
!= magic
) {
980 struct i40e_nvm_access
*cmd
;
983 /* make sure it is the right magic for NVMUpdate */
984 if ((eeprom
->magic
>> 16) != hw
->device_id
)
987 cmd
= (struct i40e_nvm_access
*)eeprom
;
988 ret_val
= i40e_nvmupd_command(hw
, cmd
, bytes
, &errno
);
990 ((hw
->aq
.asq_last_status
!= I40E_AQ_RC_EACCES
) ||
991 (hw
->debug_mask
& I40E_DEBUG_NVM
)))
992 dev_info(&pf
->pdev
->dev
,
993 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
994 ret_val
, hw
->aq
.asq_last_status
, errno
,
995 (u8
)(cmd
->config
& I40E_NVM_MOD_PNT_MASK
),
996 cmd
->offset
, cmd
->data_size
);
1001 /* normal ethtool get_eeprom support */
1002 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
1004 eeprom_buff
= kzalloc(eeprom
->len
, GFP_KERNEL
);
1008 ret_val
= i40e_acquire_nvm(hw
, I40E_RESOURCE_READ
);
1010 dev_info(&pf
->pdev
->dev
,
1011 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1012 ret_val
, hw
->aq
.asq_last_status
);
1016 sectors
= eeprom
->len
/ I40E_NVM_SECTOR_SIZE
;
1017 sectors
+= (eeprom
->len
% I40E_NVM_SECTOR_SIZE
) ? 1 : 0;
1018 len
= I40E_NVM_SECTOR_SIZE
;
1020 for (i
= 0; i
< sectors
; i
++) {
1021 if (i
== (sectors
- 1)) {
1022 len
= eeprom
->len
- (I40E_NVM_SECTOR_SIZE
* i
);
1025 offset
= eeprom
->offset
+ (I40E_NVM_SECTOR_SIZE
* i
),
1026 ret_val
= i40e_aq_read_nvm(hw
, 0x0, offset
, len
,
1027 (u8
*)eeprom_buff
+ (I40E_NVM_SECTOR_SIZE
* i
),
1029 if (ret_val
&& hw
->aq
.asq_last_status
== I40E_AQ_RC_EPERM
) {
1030 dev_info(&pf
->pdev
->dev
,
1031 "read NVM failed, invalid offset 0x%x\n",
1034 } else if (ret_val
&&
1035 hw
->aq
.asq_last_status
== I40E_AQ_RC_EACCES
) {
1036 dev_info(&pf
->pdev
->dev
,
1037 "read NVM failed, access, offset 0x%x\n",
1040 } else if (ret_val
) {
1041 dev_info(&pf
->pdev
->dev
,
1042 "read NVM failed offset %d err=%d status=0x%x\n",
1043 offset
, ret_val
, hw
->aq
.asq_last_status
);
1048 i40e_release_nvm(hw
);
1049 memcpy(bytes
, (u8
*)eeprom_buff
, eeprom
->len
);
1055 static int i40e_get_eeprom_len(struct net_device
*netdev
)
1057 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1058 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1061 val
= (rd32(hw
, I40E_GLPCI_LBARCTRL
)
1062 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK
)
1063 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT
;
1064 /* register returns value in power of 2, 64Kbyte chunks. */
1065 val
= (64 * 1024) * BIT(val
);
1069 static int i40e_set_eeprom(struct net_device
*netdev
,
1070 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
1072 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1073 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1074 struct i40e_pf
*pf
= np
->vsi
->back
;
1075 struct i40e_nvm_access
*cmd
;
1080 /* normal ethtool set_eeprom is not supported */
1081 magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
1082 if (eeprom
->magic
== magic
)
1085 /* check for NVMUpdate access method */
1086 if (!eeprom
->magic
|| (eeprom
->magic
>> 16) != hw
->device_id
)
1089 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
1090 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
1093 cmd
= (struct i40e_nvm_access
*)eeprom
;
1094 ret_val
= i40e_nvmupd_command(hw
, cmd
, bytes
, &errno
);
1096 ((hw
->aq
.asq_last_status
!= I40E_AQ_RC_EPERM
&&
1097 hw
->aq
.asq_last_status
!= I40E_AQ_RC_EBUSY
) ||
1098 (hw
->debug_mask
& I40E_DEBUG_NVM
)))
1099 dev_info(&pf
->pdev
->dev
,
1100 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1101 ret_val
, hw
->aq
.asq_last_status
, errno
,
1102 (u8
)(cmd
->config
& I40E_NVM_MOD_PNT_MASK
),
1103 cmd
->offset
, cmd
->data_size
);
1108 static void i40e_get_drvinfo(struct net_device
*netdev
,
1109 struct ethtool_drvinfo
*drvinfo
)
1111 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1112 struct i40e_vsi
*vsi
= np
->vsi
;
1113 struct i40e_pf
*pf
= vsi
->back
;
1115 strlcpy(drvinfo
->driver
, i40e_driver_name
, sizeof(drvinfo
->driver
));
1116 strlcpy(drvinfo
->version
, i40e_driver_version_str
,
1117 sizeof(drvinfo
->version
));
1118 strlcpy(drvinfo
->fw_version
, i40e_fw_version_str(&pf
->hw
),
1119 sizeof(drvinfo
->fw_version
));
1120 strlcpy(drvinfo
->bus_info
, pci_name(pf
->pdev
),
1121 sizeof(drvinfo
->bus_info
));
1122 drvinfo
->n_priv_flags
= I40E_PRIV_FLAGS_STR_LEN
;
1125 static void i40e_get_ringparam(struct net_device
*netdev
,
1126 struct ethtool_ringparam
*ring
)
1128 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1129 struct i40e_pf
*pf
= np
->vsi
->back
;
1130 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
1132 ring
->rx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
1133 ring
->tx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
1134 ring
->rx_mini_max_pending
= 0;
1135 ring
->rx_jumbo_max_pending
= 0;
1136 ring
->rx_pending
= vsi
->rx_rings
[0]->count
;
1137 ring
->tx_pending
= vsi
->tx_rings
[0]->count
;
1138 ring
->rx_mini_pending
= 0;
1139 ring
->rx_jumbo_pending
= 0;
1142 static int i40e_set_ringparam(struct net_device
*netdev
,
1143 struct ethtool_ringparam
*ring
)
1145 struct i40e_ring
*tx_rings
= NULL
, *rx_rings
= NULL
;
1146 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1147 struct i40e_vsi
*vsi
= np
->vsi
;
1148 struct i40e_pf
*pf
= vsi
->back
;
1149 u32 new_rx_count
, new_tx_count
;
1152 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
1155 if (ring
->tx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
1156 ring
->tx_pending
< I40E_MIN_NUM_DESCRIPTORS
||
1157 ring
->rx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
1158 ring
->rx_pending
< I40E_MIN_NUM_DESCRIPTORS
) {
1160 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1161 ring
->tx_pending
, ring
->rx_pending
,
1162 I40E_MIN_NUM_DESCRIPTORS
, I40E_MAX_NUM_DESCRIPTORS
);
1166 new_tx_count
= ALIGN(ring
->tx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
1167 new_rx_count
= ALIGN(ring
->rx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
1169 /* if nothing to do return success */
1170 if ((new_tx_count
== vsi
->tx_rings
[0]->count
) &&
1171 (new_rx_count
== vsi
->rx_rings
[0]->count
))
1174 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
1175 usleep_range(1000, 2000);
1177 if (!netif_running(vsi
->netdev
)) {
1178 /* simple case - set for the next time the netdev is started */
1179 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1180 vsi
->tx_rings
[i
]->count
= new_tx_count
;
1181 vsi
->rx_rings
[i
]->count
= new_rx_count
;
1186 /* We can't just free everything and then setup again,
1187 * because the ISRs in MSI-X mode get passed pointers
1188 * to the Tx and Rx ring structs.
1191 /* alloc updated Tx resources */
1192 if (new_tx_count
!= vsi
->tx_rings
[0]->count
) {
1194 "Changing Tx descriptor count from %d to %d.\n",
1195 vsi
->tx_rings
[0]->count
, new_tx_count
);
1196 tx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
1197 sizeof(struct i40e_ring
), GFP_KERNEL
);
1203 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1204 /* clone ring and setup updated count */
1205 tx_rings
[i
] = *vsi
->tx_rings
[i
];
1206 tx_rings
[i
].count
= new_tx_count
;
1207 /* the desc and bi pointers will be reallocated in the
1210 tx_rings
[i
].desc
= NULL
;
1211 tx_rings
[i
].rx_bi
= NULL
;
1212 err
= i40e_setup_tx_descriptors(&tx_rings
[i
]);
1216 i40e_free_tx_resources(&tx_rings
[i
]);
1226 /* alloc updated Rx resources */
1227 if (new_rx_count
!= vsi
->rx_rings
[0]->count
) {
1229 "Changing Rx descriptor count from %d to %d\n",
1230 vsi
->rx_rings
[0]->count
, new_rx_count
);
1231 rx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
1232 sizeof(struct i40e_ring
), GFP_KERNEL
);
1238 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1239 /* clone ring and setup updated count */
1240 rx_rings
[i
] = *vsi
->rx_rings
[i
];
1241 rx_rings
[i
].count
= new_rx_count
;
1242 /* the desc and bi pointers will be reallocated in the
1245 rx_rings
[i
].desc
= NULL
;
1246 rx_rings
[i
].rx_bi
= NULL
;
1247 err
= i40e_setup_rx_descriptors(&rx_rings
[i
]);
1251 i40e_free_rx_resources(&rx_rings
[i
]);
1261 /* Bring interface down, copy in the new ring info,
1262 * then restore the interface
1267 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1268 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
1269 *vsi
->tx_rings
[i
] = tx_rings
[i
];
1276 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1277 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
1278 *vsi
->rx_rings
[i
] = rx_rings
[i
];
1287 /* error cleanup if the Rx allocations failed after getting Tx */
1289 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1290 i40e_free_tx_resources(&tx_rings
[i
]);
1296 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
1301 static int i40e_get_sset_count(struct net_device
*netdev
, int sset
)
1303 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1304 struct i40e_vsi
*vsi
= np
->vsi
;
1305 struct i40e_pf
*pf
= vsi
->back
;
1309 return I40E_TEST_LEN
;
1311 if (vsi
== pf
->vsi
[pf
->lan_vsi
] && pf
->hw
.partition_id
== 1) {
1312 int len
= I40E_PF_STATS_LEN(netdev
);
1314 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1315 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
))
1316 len
+= I40E_VEB_STATS_TOTAL
;
1319 return I40E_VSI_STATS_LEN(netdev
);
1321 case ETH_SS_PRIV_FLAGS
:
1322 return I40E_PRIV_FLAGS_STR_LEN
;
1328 static void i40e_get_ethtool_stats(struct net_device
*netdev
,
1329 struct ethtool_stats
*stats
, u64
*data
)
1331 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1332 struct i40e_ring
*tx_ring
, *rx_ring
;
1333 struct i40e_vsi
*vsi
= np
->vsi
;
1334 struct i40e_pf
*pf
= vsi
->back
;
1338 struct rtnl_link_stats64
*net_stats
= i40e_get_vsi_stats_struct(vsi
);
1341 i40e_update_stats(vsi
);
1343 for (j
= 0; j
< I40E_NETDEV_STATS_LEN
; j
++) {
1344 p
= (char *)net_stats
+ i40e_gstrings_net_stats
[j
].stat_offset
;
1345 data
[i
++] = (i40e_gstrings_net_stats
[j
].sizeof_stat
==
1346 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1348 for (j
= 0; j
< I40E_MISC_STATS_LEN
; j
++) {
1349 p
= (char *)vsi
+ i40e_gstrings_misc_stats
[j
].stat_offset
;
1350 data
[i
++] = (i40e_gstrings_misc_stats
[j
].sizeof_stat
==
1351 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1354 for (j
= 0; j
< I40E_FCOE_STATS_LEN
; j
++) {
1355 p
= (char *)vsi
+ i40e_gstrings_fcoe_stats
[j
].stat_offset
;
1356 data
[i
++] = (i40e_gstrings_fcoe_stats
[j
].sizeof_stat
==
1357 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1361 for (j
= 0; j
< vsi
->num_queue_pairs
; j
++) {
1362 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[j
]);
1367 /* process Tx ring statistics */
1369 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
1370 data
[i
] = tx_ring
->stats
.packets
;
1371 data
[i
+ 1] = tx_ring
->stats
.bytes
;
1372 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
1375 /* Rx ring is the 2nd half of the queue pair */
1376 rx_ring
= &tx_ring
[1];
1378 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
1379 data
[i
] = rx_ring
->stats
.packets
;
1380 data
[i
+ 1] = rx_ring
->stats
.bytes
;
1381 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
1385 if (vsi
!= pf
->vsi
[pf
->lan_vsi
] || pf
->hw
.partition_id
!= 1)
1388 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1389 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
1390 struct i40e_veb
*veb
= pf
->veb
[pf
->lan_veb
];
1392 for (j
= 0; j
< I40E_VEB_STATS_LEN
; j
++) {
1394 p
+= i40e_gstrings_veb_stats
[j
].stat_offset
;
1395 data
[i
++] = (i40e_gstrings_veb_stats
[j
].sizeof_stat
==
1396 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1399 for (j
= 0; j
< I40E_GLOBAL_STATS_LEN
; j
++) {
1400 p
= (char *)pf
+ i40e_gstrings_stats
[j
].stat_offset
;
1401 data
[i
++] = (i40e_gstrings_stats
[j
].sizeof_stat
==
1402 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1404 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
1405 data
[i
++] = pf
->stats
.priority_xon_tx
[j
];
1406 data
[i
++] = pf
->stats
.priority_xoff_tx
[j
];
1408 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
1409 data
[i
++] = pf
->stats
.priority_xon_rx
[j
];
1410 data
[i
++] = pf
->stats
.priority_xoff_rx
[j
];
1412 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++)
1413 data
[i
++] = pf
->stats
.priority_xon_2_xoff
[j
];
1416 static void i40e_get_strings(struct net_device
*netdev
, u32 stringset
,
1419 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1420 struct i40e_vsi
*vsi
= np
->vsi
;
1421 struct i40e_pf
*pf
= vsi
->back
;
1422 char *p
= (char *)data
;
1425 switch (stringset
) {
1427 for (i
= 0; i
< I40E_TEST_LEN
; i
++) {
1428 memcpy(data
, i40e_gstrings_test
[i
], ETH_GSTRING_LEN
);
1429 data
+= ETH_GSTRING_LEN
;
1433 for (i
= 0; i
< I40E_NETDEV_STATS_LEN
; i
++) {
1434 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1435 i40e_gstrings_net_stats
[i
].stat_string
);
1436 p
+= ETH_GSTRING_LEN
;
1438 for (i
= 0; i
< I40E_MISC_STATS_LEN
; i
++) {
1439 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1440 i40e_gstrings_misc_stats
[i
].stat_string
);
1441 p
+= ETH_GSTRING_LEN
;
1444 for (i
= 0; i
< I40E_FCOE_STATS_LEN
; i
++) {
1445 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1446 i40e_gstrings_fcoe_stats
[i
].stat_string
);
1447 p
+= ETH_GSTRING_LEN
;
1450 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1451 snprintf(p
, ETH_GSTRING_LEN
, "tx-%u.tx_packets", i
);
1452 p
+= ETH_GSTRING_LEN
;
1453 snprintf(p
, ETH_GSTRING_LEN
, "tx-%u.tx_bytes", i
);
1454 p
+= ETH_GSTRING_LEN
;
1455 snprintf(p
, ETH_GSTRING_LEN
, "rx-%u.rx_packets", i
);
1456 p
+= ETH_GSTRING_LEN
;
1457 snprintf(p
, ETH_GSTRING_LEN
, "rx-%u.rx_bytes", i
);
1458 p
+= ETH_GSTRING_LEN
;
1460 if (vsi
!= pf
->vsi
[pf
->lan_vsi
] || pf
->hw
.partition_id
!= 1)
1463 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1464 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
1465 for (i
= 0; i
< I40E_VEB_STATS_LEN
; i
++) {
1466 snprintf(p
, ETH_GSTRING_LEN
, "veb.%s",
1467 i40e_gstrings_veb_stats
[i
].stat_string
);
1468 p
+= ETH_GSTRING_LEN
;
1470 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1471 snprintf(p
, ETH_GSTRING_LEN
,
1472 "veb.tc_%u_tx_packets", i
);
1473 p
+= ETH_GSTRING_LEN
;
1474 snprintf(p
, ETH_GSTRING_LEN
,
1475 "veb.tc_%u_tx_bytes", i
);
1476 p
+= ETH_GSTRING_LEN
;
1477 snprintf(p
, ETH_GSTRING_LEN
,
1478 "veb.tc_%u_rx_packets", i
);
1479 p
+= ETH_GSTRING_LEN
;
1480 snprintf(p
, ETH_GSTRING_LEN
,
1481 "veb.tc_%u_rx_bytes", i
);
1482 p
+= ETH_GSTRING_LEN
;
1485 for (i
= 0; i
< I40E_GLOBAL_STATS_LEN
; i
++) {
1486 snprintf(p
, ETH_GSTRING_LEN
, "port.%s",
1487 i40e_gstrings_stats
[i
].stat_string
);
1488 p
+= ETH_GSTRING_LEN
;
1490 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1491 snprintf(p
, ETH_GSTRING_LEN
,
1492 "port.tx_priority_%u_xon", i
);
1493 p
+= ETH_GSTRING_LEN
;
1494 snprintf(p
, ETH_GSTRING_LEN
,
1495 "port.tx_priority_%u_xoff", i
);
1496 p
+= ETH_GSTRING_LEN
;
1498 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1499 snprintf(p
, ETH_GSTRING_LEN
,
1500 "port.rx_priority_%u_xon", i
);
1501 p
+= ETH_GSTRING_LEN
;
1502 snprintf(p
, ETH_GSTRING_LEN
,
1503 "port.rx_priority_%u_xoff", i
);
1504 p
+= ETH_GSTRING_LEN
;
1506 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1507 snprintf(p
, ETH_GSTRING_LEN
,
1508 "port.rx_priority_%u_xon_2_xoff", i
);
1509 p
+= ETH_GSTRING_LEN
;
1511 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1513 case ETH_SS_PRIV_FLAGS
:
1514 for (i
= 0; i
< I40E_PRIV_FLAGS_STR_LEN
; i
++) {
1515 memcpy(data
, i40e_priv_flags_strings
[i
],
1517 data
+= ETH_GSTRING_LEN
;
1525 static int i40e_get_ts_info(struct net_device
*dev
,
1526 struct ethtool_ts_info
*info
)
1528 struct i40e_pf
*pf
= i40e_netdev_to_pf(dev
);
1530 /* only report HW timestamping if PTP is enabled */
1531 if (!(pf
->flags
& I40E_FLAG_PTP
))
1532 return ethtool_op_get_ts_info(dev
, info
);
1534 info
->so_timestamping
= SOF_TIMESTAMPING_TX_SOFTWARE
|
1535 SOF_TIMESTAMPING_RX_SOFTWARE
|
1536 SOF_TIMESTAMPING_SOFTWARE
|
1537 SOF_TIMESTAMPING_TX_HARDWARE
|
1538 SOF_TIMESTAMPING_RX_HARDWARE
|
1539 SOF_TIMESTAMPING_RAW_HARDWARE
;
1542 info
->phc_index
= ptp_clock_index(pf
->ptp_clock
);
1544 info
->phc_index
= -1;
1546 info
->tx_types
= BIT(HWTSTAMP_TX_OFF
) | BIT(HWTSTAMP_TX_ON
);
1548 info
->rx_filters
= BIT(HWTSTAMP_FILTER_NONE
) |
1549 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT
) |
1550 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT
);
1555 static int i40e_link_test(struct net_device
*netdev
, u64
*data
)
1557 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1558 struct i40e_pf
*pf
= np
->vsi
->back
;
1560 bool link_up
= false;
1562 netif_info(pf
, hw
, netdev
, "link test\n");
1563 status
= i40e_get_link_status(&pf
->hw
, &link_up
);
1565 netif_err(pf
, drv
, netdev
, "link query timed out, please retry test\n");
1578 static int i40e_reg_test(struct net_device
*netdev
, u64
*data
)
1580 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1581 struct i40e_pf
*pf
= np
->vsi
->back
;
1583 netif_info(pf
, hw
, netdev
, "register test\n");
1584 *data
= i40e_diag_reg_test(&pf
->hw
);
1589 static int i40e_eeprom_test(struct net_device
*netdev
, u64
*data
)
1591 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1592 struct i40e_pf
*pf
= np
->vsi
->back
;
1594 netif_info(pf
, hw
, netdev
, "eeprom test\n");
1595 *data
= i40e_diag_eeprom_test(&pf
->hw
);
1597 /* forcebly clear the NVM Update state machine */
1598 pf
->hw
.nvmupd_state
= I40E_NVMUPD_STATE_INIT
;
1603 static int i40e_intr_test(struct net_device
*netdev
, u64
*data
)
1605 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1606 struct i40e_pf
*pf
= np
->vsi
->back
;
1607 u16 swc_old
= pf
->sw_int_count
;
1609 netif_info(pf
, hw
, netdev
, "interrupt test\n");
1610 wr32(&pf
->hw
, I40E_PFINT_DYN_CTL0
,
1611 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
1612 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
|
1613 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK
|
1614 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK
|
1615 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
));
1616 usleep_range(1000, 2000);
1617 *data
= (swc_old
== pf
->sw_int_count
);
1622 static int i40e_loopback_test(struct net_device
*netdev
, u64
*data
)
1624 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1625 struct i40e_pf
*pf
= np
->vsi
->back
;
1627 netif_info(pf
, hw
, netdev
, "loopback test not implemented\n");
1633 static inline bool i40e_active_vfs(struct i40e_pf
*pf
)
1635 struct i40e_vf
*vfs
= pf
->vf
;
1638 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
1639 if (test_bit(I40E_VF_STAT_ACTIVE
, &vfs
[i
].vf_states
))
1644 static inline bool i40e_active_vmdqs(struct i40e_pf
*pf
)
1646 struct i40e_vsi
**vsi
= pf
->vsi
;
1649 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
1652 if (vsi
[i
]->type
== I40E_VSI_VMDQ2
)
1659 static void i40e_diag_test(struct net_device
*netdev
,
1660 struct ethtool_test
*eth_test
, u64
*data
)
1662 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1663 bool if_running
= netif_running(netdev
);
1664 struct i40e_pf
*pf
= np
->vsi
->back
;
1666 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1668 netif_info(pf
, drv
, netdev
, "offline testing starting\n");
1670 set_bit(__I40E_TESTING
, &pf
->state
);
1672 if (i40e_active_vfs(pf
) || i40e_active_vmdqs(pf
)) {
1673 dev_warn(&pf
->pdev
->dev
,
1674 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1675 data
[I40E_ETH_TEST_REG
] = 1;
1676 data
[I40E_ETH_TEST_EEPROM
] = 1;
1677 data
[I40E_ETH_TEST_INTR
] = 1;
1678 data
[I40E_ETH_TEST_LOOPBACK
] = 1;
1679 data
[I40E_ETH_TEST_LINK
] = 1;
1680 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1681 clear_bit(__I40E_TESTING
, &pf
->state
);
1685 /* If the device is online then take it offline */
1687 /* indicate we're in test mode */
1690 /* This reset does not affect link - if it is
1691 * changed to a type of reset that does affect
1692 * link then the following link test would have
1693 * to be moved to before the reset
1695 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
1697 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
1698 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1700 if (i40e_eeprom_test(netdev
, &data
[I40E_ETH_TEST_EEPROM
]))
1701 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1703 if (i40e_intr_test(netdev
, &data
[I40E_ETH_TEST_INTR
]))
1704 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1706 if (i40e_loopback_test(netdev
, &data
[I40E_ETH_TEST_LOOPBACK
]))
1707 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1709 /* run reg test last, a reset is required after it */
1710 if (i40e_reg_test(netdev
, &data
[I40E_ETH_TEST_REG
]))
1711 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1713 clear_bit(__I40E_TESTING
, &pf
->state
);
1714 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
1720 netif_info(pf
, drv
, netdev
, "online testing starting\n");
1722 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
1723 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1725 /* Offline only tests, not run in online; pass by default */
1726 data
[I40E_ETH_TEST_REG
] = 0;
1727 data
[I40E_ETH_TEST_EEPROM
] = 0;
1728 data
[I40E_ETH_TEST_INTR
] = 0;
1729 data
[I40E_ETH_TEST_LOOPBACK
] = 0;
1734 netif_info(pf
, drv
, netdev
, "testing finished\n");
1737 static void i40e_get_wol(struct net_device
*netdev
,
1738 struct ethtool_wolinfo
*wol
)
1740 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1741 struct i40e_pf
*pf
= np
->vsi
->back
;
1742 struct i40e_hw
*hw
= &pf
->hw
;
1745 /* NVM bit on means WoL disabled for the port */
1746 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
1747 if ((BIT(hw
->port
) & wol_nvm_bits
) || (hw
->partition_id
!= 1)) {
1751 wol
->supported
= WAKE_MAGIC
;
1752 wol
->wolopts
= (pf
->wol_en
? WAKE_MAGIC
: 0);
1757 * i40e_set_wol - set the WakeOnLAN configuration
1758 * @netdev: the netdev in question
1759 * @wol: the ethtool WoL setting data
1761 static int i40e_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1763 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1764 struct i40e_pf
*pf
= np
->vsi
->back
;
1765 struct i40e_vsi
*vsi
= np
->vsi
;
1766 struct i40e_hw
*hw
= &pf
->hw
;
1769 /* WoL not supported if this isn't the controlling PF on the port */
1770 if (hw
->partition_id
!= 1) {
1771 i40e_partition_setting_complaint(pf
);
1775 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
1778 /* NVM bit on means WoL disabled for the port */
1779 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
1780 if (BIT(hw
->port
) & wol_nvm_bits
)
1783 /* only magic packet is supported */
1784 if (wol
->wolopts
&& (wol
->wolopts
!= WAKE_MAGIC
))
1787 /* is this a new value? */
1788 if (pf
->wol_en
!= !!wol
->wolopts
) {
1789 pf
->wol_en
= !!wol
->wolopts
;
1790 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
1796 static int i40e_set_phys_id(struct net_device
*netdev
,
1797 enum ethtool_phys_id_state state
)
1799 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1800 struct i40e_pf
*pf
= np
->vsi
->back
;
1801 struct i40e_hw
*hw
= &pf
->hw
;
1805 case ETHTOOL_ID_ACTIVE
:
1806 pf
->led_status
= i40e_led_get(hw
);
1809 i40e_led_set(hw
, 0xF, false);
1811 case ETHTOOL_ID_OFF
:
1812 i40e_led_set(hw
, 0x0, false);
1814 case ETHTOOL_ID_INACTIVE
:
1815 i40e_led_set(hw
, pf
->led_status
, false);
1824 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1825 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1826 * 125us (8000 interrupts per second) == ITR(62)
1829 static int i40e_get_coalesce(struct net_device
*netdev
,
1830 struct ethtool_coalesce
*ec
)
1832 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1833 struct i40e_vsi
*vsi
= np
->vsi
;
1835 ec
->tx_max_coalesced_frames_irq
= vsi
->work_limit
;
1836 ec
->rx_max_coalesced_frames_irq
= vsi
->work_limit
;
1838 if (ITR_IS_DYNAMIC(vsi
->rx_itr_setting
))
1839 ec
->use_adaptive_rx_coalesce
= 1;
1841 if (ITR_IS_DYNAMIC(vsi
->tx_itr_setting
))
1842 ec
->use_adaptive_tx_coalesce
= 1;
1844 ec
->rx_coalesce_usecs
= vsi
->rx_itr_setting
& ~I40E_ITR_DYNAMIC
;
1845 ec
->tx_coalesce_usecs
= vsi
->tx_itr_setting
& ~I40E_ITR_DYNAMIC
;
1850 static int i40e_set_coalesce(struct net_device
*netdev
,
1851 struct ethtool_coalesce
*ec
)
1853 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1854 struct i40e_q_vector
*q_vector
;
1855 struct i40e_vsi
*vsi
= np
->vsi
;
1856 struct i40e_pf
*pf
= vsi
->back
;
1857 struct i40e_hw
*hw
= &pf
->hw
;
1861 if (ec
->tx_max_coalesced_frames_irq
|| ec
->rx_max_coalesced_frames_irq
)
1862 vsi
->work_limit
= ec
->tx_max_coalesced_frames_irq
;
1864 vector
= vsi
->base_vector
;
1865 if ((ec
->rx_coalesce_usecs
>= (I40E_MIN_ITR
<< 1)) &&
1866 (ec
->rx_coalesce_usecs
<= (I40E_MAX_ITR
<< 1))) {
1867 vsi
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
1868 } else if (ec
->rx_coalesce_usecs
== 0) {
1869 vsi
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
1870 if (ec
->use_adaptive_rx_coalesce
)
1871 netif_info(pf
, drv
, netdev
, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
1873 netif_info(pf
, drv
, netdev
, "Invalid value, rx-usecs range is 0-8160\n");
1877 if ((ec
->tx_coalesce_usecs
>= (I40E_MIN_ITR
<< 1)) &&
1878 (ec
->tx_coalesce_usecs
<= (I40E_MAX_ITR
<< 1))) {
1879 vsi
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
1880 } else if (ec
->tx_coalesce_usecs
== 0) {
1881 vsi
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
1882 if (ec
->use_adaptive_tx_coalesce
)
1883 netif_info(pf
, drv
, netdev
, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
1885 netif_info(pf
, drv
, netdev
,
1886 "Invalid value, tx-usecs range is 0-8160\n");
1890 if (ec
->use_adaptive_rx_coalesce
)
1891 vsi
->rx_itr_setting
|= I40E_ITR_DYNAMIC
;
1893 vsi
->rx_itr_setting
&= ~I40E_ITR_DYNAMIC
;
1895 if (ec
->use_adaptive_tx_coalesce
)
1896 vsi
->tx_itr_setting
|= I40E_ITR_DYNAMIC
;
1898 vsi
->tx_itr_setting
&= ~I40E_ITR_DYNAMIC
;
1900 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
1901 q_vector
= vsi
->q_vectors
[i
];
1902 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
1903 wr32(hw
, I40E_PFINT_ITRN(0, vector
- 1), q_vector
->rx
.itr
);
1904 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
1905 wr32(hw
, I40E_PFINT_ITRN(1, vector
- 1), q_vector
->tx
.itr
);
1913 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1914 * @pf: pointer to the physical function struct
1915 * @cmd: ethtool rxnfc command
1917 * Returns Success if the flow is supported, else Invalid Input.
1919 static int i40e_get_rss_hash_opts(struct i40e_pf
*pf
, struct ethtool_rxnfc
*cmd
)
1923 if (pf
->vsi
[pf
->lan_vsi
]->rxnfc
.data
!= 0) {
1924 cmd
->data
= pf
->vsi
[pf
->lan_vsi
]->rxnfc
.data
;
1925 cmd
->flow_type
= pf
->vsi
[pf
->lan_vsi
]->rxnfc
.flow_type
;
1928 /* Report default options for RSS on i40e */
1929 switch (cmd
->flow_type
) {
1932 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1933 /* fall through to add IP fields */
1935 case AH_ESP_V4_FLOW
:
1939 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
1943 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1944 /* fall through to add IP fields */
1946 case AH_ESP_V6_FLOW
:
1950 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
1960 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1961 * @pf: Pointer to the physical function struct
1962 * @cmd: The command to get or set Rx flow classification rules
1963 * @rule_locs: Array of used rule locations
1965 * This function populates both the total and actual rule count of
1966 * the ethtool flow classification command
1968 * Returns 0 on success or -EMSGSIZE if entry not found
1970 static int i40e_get_ethtool_fdir_all(struct i40e_pf
*pf
,
1971 struct ethtool_rxnfc
*cmd
,
1974 struct i40e_fdir_filter
*rule
;
1975 struct hlist_node
*node2
;
1978 /* report total rule count */
1979 cmd
->data
= i40e_get_fd_cnt_all(pf
);
1981 hlist_for_each_entry_safe(rule
, node2
,
1982 &pf
->fdir_filter_list
, fdir_node
) {
1983 if (cnt
== cmd
->rule_cnt
)
1986 rule_locs
[cnt
] = rule
->fd_id
;
1990 cmd
->rule_cnt
= cnt
;
1996 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1997 * @pf: Pointer to the physical function struct
1998 * @cmd: The command to get or set Rx flow classification rules
2000 * This function looks up a filter based on the Rx flow classification
2001 * command and fills the flow spec info for it if found
2003 * Returns 0 on success or -EINVAL if filter not found
2005 static int i40e_get_ethtool_fdir_entry(struct i40e_pf
*pf
,
2006 struct ethtool_rxnfc
*cmd
)
2008 struct ethtool_rx_flow_spec
*fsp
=
2009 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2010 struct i40e_fdir_filter
*rule
= NULL
;
2011 struct hlist_node
*node2
;
2013 hlist_for_each_entry_safe(rule
, node2
,
2014 &pf
->fdir_filter_list
, fdir_node
) {
2015 if (fsp
->location
<= rule
->fd_id
)
2019 if (!rule
|| fsp
->location
!= rule
->fd_id
)
2022 fsp
->flow_type
= rule
->flow_type
;
2023 if (fsp
->flow_type
== IP_USER_FLOW
) {
2024 fsp
->h_u
.usr_ip4_spec
.ip_ver
= ETH_RX_NFC_IP4
;
2025 fsp
->h_u
.usr_ip4_spec
.proto
= 0;
2026 fsp
->m_u
.usr_ip4_spec
.proto
= 0;
2029 /* Reverse the src and dest notion, since the HW views them from
2030 * Tx perspective where as the user expects it from Rx filter view.
2032 fsp
->h_u
.tcp_ip4_spec
.psrc
= rule
->dst_port
;
2033 fsp
->h_u
.tcp_ip4_spec
.pdst
= rule
->src_port
;
2034 fsp
->h_u
.tcp_ip4_spec
.ip4src
= rule
->dst_ip
[0];
2035 fsp
->h_u
.tcp_ip4_spec
.ip4dst
= rule
->src_ip
[0];
2037 if (rule
->dest_ctl
== I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
)
2038 fsp
->ring_cookie
= RX_CLS_FLOW_DISC
;
2040 fsp
->ring_cookie
= rule
->q_index
;
2042 if (rule
->dest_vsi
!= pf
->vsi
[pf
->lan_vsi
]->id
) {
2043 struct i40e_vsi
*vsi
;
2045 vsi
= i40e_find_vsi_from_id(pf
, rule
->dest_vsi
);
2046 if (vsi
&& vsi
->type
== I40E_VSI_SRIOV
) {
2047 fsp
->h_ext
.data
[1] = htonl(vsi
->vf_id
);
2048 fsp
->m_ext
.data
[1] = htonl(0x1);
2056 * i40e_get_rxnfc - command to get RX flow classification rules
2057 * @netdev: network interface device structure
2058 * @cmd: ethtool rxnfc command
2060 * Returns Success if the command is supported.
2062 static int i40e_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
,
2065 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2066 struct i40e_vsi
*vsi
= np
->vsi
;
2067 struct i40e_pf
*pf
= vsi
->back
;
2068 int ret
= -EOPNOTSUPP
;
2071 case ETHTOOL_GRXRINGS
:
2072 cmd
->data
= vsi
->alloc_queue_pairs
;
2076 ret
= i40e_get_rss_hash_opts(pf
, cmd
);
2078 case ETHTOOL_GRXCLSRLCNT
:
2079 cmd
->rule_cnt
= pf
->fdir_pf_active_filters
;
2080 /* report total rule count */
2081 cmd
->data
= i40e_get_fd_cnt_all(pf
);
2084 case ETHTOOL_GRXCLSRULE
:
2085 ret
= i40e_get_ethtool_fdir_entry(pf
, cmd
);
2087 case ETHTOOL_GRXCLSRLALL
:
2088 ret
= i40e_get_ethtool_fdir_all(pf
, cmd
, rule_locs
);
2098 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2099 * @pf: pointer to the physical function struct
2100 * @cmd: ethtool rxnfc command
2102 * Returns Success if the flow input set is supported.
2104 static int i40e_set_rss_hash_opt(struct i40e_pf
*pf
, struct ethtool_rxnfc
*nfc
)
2106 struct i40e_hw
*hw
= &pf
->hw
;
2107 u64 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
2108 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
2110 /* RSS does not support anything other than hashing
2111 * to queues on src and dst IPs and ports
2113 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
2114 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
2117 /* We need at least the IP SRC and DEST fields for hashing */
2118 if (!(nfc
->data
& RXH_IP_SRC
) ||
2119 !(nfc
->data
& RXH_IP_DST
))
2122 switch (nfc
->flow_type
) {
2124 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2126 hena
&= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP
);
2128 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2129 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP
);
2136 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2138 hena
&= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP
);
2140 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2141 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP
);
2148 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2150 hena
&= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP
) |
2151 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
));
2153 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2154 hena
|= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP
) |
2155 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
));
2162 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2164 hena
&= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP
) |
2165 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
));
2167 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2168 hena
|= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP
) |
2169 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
));
2175 case AH_ESP_V4_FLOW
:
2179 if ((nfc
->data
& RXH_L4_B_0_1
) ||
2180 (nfc
->data
& RXH_L4_B_2_3
))
2182 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
);
2184 case AH_ESP_V6_FLOW
:
2188 if ((nfc
->data
& RXH_L4_B_0_1
) ||
2189 (nfc
->data
& RXH_L4_B_2_3
))
2191 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
);
2194 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
) |
2195 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
);
2198 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
) |
2199 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
);
2205 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
2206 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
2209 /* Save setting for future output/update */
2210 pf
->vsi
[pf
->lan_vsi
]->rxnfc
= *nfc
;
2216 * i40e_match_fdir_input_set - Match a new filter against an existing one
2217 * @rule: The filter already added
2218 * @input: The new filter to comapre against
2220 * Returns true if the two input set match
2222 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter
*rule
,
2223 struct i40e_fdir_filter
*input
)
2225 if ((rule
->dst_ip
[0] != input
->dst_ip
[0]) ||
2226 (rule
->src_ip
[0] != input
->src_ip
[0]) ||
2227 (rule
->dst_port
!= input
->dst_port
) ||
2228 (rule
->src_port
!= input
->src_port
))
2234 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2235 * @vsi: Pointer to the targeted VSI
2236 * @input: The filter to update or NULL to indicate deletion
2237 * @sw_idx: Software index to the filter
2238 * @cmd: The command to get or set Rx flow classification rules
2240 * This function updates (or deletes) a Flow Director entry from
2241 * the hlist of the corresponding PF
2243 * Returns 0 on success
2245 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi
*vsi
,
2246 struct i40e_fdir_filter
*input
,
2248 struct ethtool_rxnfc
*cmd
)
2250 struct i40e_fdir_filter
*rule
, *parent
;
2251 struct i40e_pf
*pf
= vsi
->back
;
2252 struct hlist_node
*node2
;
2258 hlist_for_each_entry_safe(rule
, node2
,
2259 &pf
->fdir_filter_list
, fdir_node
) {
2260 /* hash found, or no matching entry */
2261 if (rule
->fd_id
>= sw_idx
)
2266 /* if there is an old rule occupying our place remove it */
2267 if (rule
&& (rule
->fd_id
== sw_idx
)) {
2268 if (input
&& !i40e_match_fdir_input_set(rule
, input
))
2269 err
= i40e_add_del_fdir(vsi
, rule
, false);
2271 err
= i40e_add_del_fdir(vsi
, rule
, false);
2272 hlist_del(&rule
->fdir_node
);
2274 pf
->fdir_pf_active_filters
--;
2277 /* If no input this was a delete, err should be 0 if a rule was
2278 * successfully found and removed from the list else -EINVAL
2283 /* initialize node and set software index */
2284 INIT_HLIST_NODE(&input
->fdir_node
);
2286 /* add filter to the list */
2288 hlist_add_behind(&input
->fdir_node
, &parent
->fdir_node
);
2290 hlist_add_head(&input
->fdir_node
,
2291 &pf
->fdir_filter_list
);
2294 pf
->fdir_pf_active_filters
++;
2300 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2301 * @vsi: Pointer to the targeted VSI
2302 * @cmd: The command to get or set Rx flow classification rules
2304 * The function removes a Flow Director filter entry from the
2305 * hlist of the corresponding PF
2307 * Returns 0 on success
2309 static int i40e_del_fdir_entry(struct i40e_vsi
*vsi
,
2310 struct ethtool_rxnfc
*cmd
)
2312 struct ethtool_rx_flow_spec
*fsp
=
2313 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2314 struct i40e_pf
*pf
= vsi
->back
;
2317 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
2318 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
2321 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
2324 ret
= i40e_update_ethtool_fdir_entry(vsi
, NULL
, fsp
->location
, cmd
);
2326 i40e_fdir_check_and_reenable(pf
);
2331 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2332 * @vsi: pointer to the targeted VSI
2333 * @cmd: command to get or set RX flow classification rules
2335 * Add Flow Director filters for a specific flow spec based on their
2336 * protocol. Returns 0 if the filters were successfully added.
2338 static int i40e_add_fdir_ethtool(struct i40e_vsi
*vsi
,
2339 struct ethtool_rxnfc
*cmd
)
2341 struct ethtool_rx_flow_spec
*fsp
;
2342 struct i40e_fdir_filter
*input
;
2352 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
2355 if (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)
2358 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
2359 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
2362 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
2365 fsp
= (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2367 if (fsp
->location
>= (pf
->hw
.func_caps
.fd_filters_best_effort
+
2368 pf
->hw
.func_caps
.fd_filters_guaranteed
)) {
2372 if ((fsp
->ring_cookie
!= RX_CLS_FLOW_DISC
) &&
2373 (fsp
->ring_cookie
>= vsi
->num_queue_pairs
))
2376 input
= kzalloc(sizeof(*input
), GFP_KERNEL
);
2381 input
->fd_id
= fsp
->location
;
2383 if (fsp
->ring_cookie
== RX_CLS_FLOW_DISC
)
2384 input
->dest_ctl
= I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
;
2387 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX
;
2389 input
->q_index
= fsp
->ring_cookie
;
2390 input
->flex_off
= 0;
2392 input
->dest_vsi
= vsi
->id
;
2393 input
->fd_status
= I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID
;
2394 input
->cnt_index
= I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
);
2395 input
->flow_type
= fsp
->flow_type
;
2396 input
->ip4_proto
= fsp
->h_u
.usr_ip4_spec
.proto
;
2398 /* Reverse the src and dest notion, since the HW expects them to be from
2399 * Tx perspective where as the input from user is from Rx filter view.
2401 input
->dst_port
= fsp
->h_u
.tcp_ip4_spec
.psrc
;
2402 input
->src_port
= fsp
->h_u
.tcp_ip4_spec
.pdst
;
2403 input
->dst_ip
[0] = fsp
->h_u
.tcp_ip4_spec
.ip4src
;
2404 input
->src_ip
[0] = fsp
->h_u
.tcp_ip4_spec
.ip4dst
;
2406 if (ntohl(fsp
->m_ext
.data
[1])) {
2407 if (ntohl(fsp
->h_ext
.data
[1]) >= pf
->num_alloc_vfs
) {
2408 netif_info(pf
, drv
, vsi
->netdev
, "Invalid VF id\n");
2411 vf_id
= ntohl(fsp
->h_ext
.data
[1]);
2412 /* Find vsi id from vf id and override dest vsi */
2413 input
->dest_vsi
= pf
->vf
[vf_id
].lan_vsi_id
;
2414 if (input
->q_index
>= pf
->vf
[vf_id
].num_queue_pairs
) {
2415 netif_info(pf
, drv
, vsi
->netdev
, "Invalid queue id\n");
2420 ret
= i40e_add_del_fdir(vsi
, input
, true);
2425 i40e_update_ethtool_fdir_entry(vsi
, input
, fsp
->location
, NULL
);
2431 * i40e_set_rxnfc - command to set RX flow classification rules
2432 * @netdev: network interface device structure
2433 * @cmd: ethtool rxnfc command
2435 * Returns Success if the command is supported.
2437 static int i40e_set_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
)
2439 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2440 struct i40e_vsi
*vsi
= np
->vsi
;
2441 struct i40e_pf
*pf
= vsi
->back
;
2442 int ret
= -EOPNOTSUPP
;
2446 ret
= i40e_set_rss_hash_opt(pf
, cmd
);
2448 case ETHTOOL_SRXCLSRLINS
:
2449 ret
= i40e_add_fdir_ethtool(vsi
, cmd
);
2451 case ETHTOOL_SRXCLSRLDEL
:
2452 ret
= i40e_del_fdir_entry(vsi
, cmd
);
2462 * i40e_max_channels - get Max number of combined channels supported
2465 static unsigned int i40e_max_channels(struct i40e_vsi
*vsi
)
2467 /* TODO: This code assumes DCB and FD is disabled for now. */
2468 return vsi
->alloc_queue_pairs
;
2472 * i40e_get_channels - Get the current channels enabled and max supported etc.
2473 * @netdev: network interface device structure
2474 * @ch: ethtool channels structure
2476 * We don't support separate tx and rx queues as channels. The other count
2477 * represents how many queues are being used for control. max_combined counts
2478 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2479 * q_vectors since we support a lot more queue pairs than q_vectors.
2481 static void i40e_get_channels(struct net_device
*dev
,
2482 struct ethtool_channels
*ch
)
2484 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2485 struct i40e_vsi
*vsi
= np
->vsi
;
2486 struct i40e_pf
*pf
= vsi
->back
;
2488 /* report maximum channels */
2489 ch
->max_combined
= i40e_max_channels(vsi
);
2491 /* report info for other vector */
2492 ch
->other_count
= (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) ? 1 : 0;
2493 ch
->max_other
= ch
->other_count
;
2495 /* Note: This code assumes DCB is disabled for now. */
2496 ch
->combined_count
= vsi
->num_queue_pairs
;
2500 * i40e_set_channels - Set the new channels count.
2501 * @netdev: network interface device structure
2502 * @ch: ethtool channels structure
2504 * The new channels count may not be the same as requested by the user
2505 * since it gets rounded down to a power of 2 value.
2507 static int i40e_set_channels(struct net_device
*dev
,
2508 struct ethtool_channels
*ch
)
2510 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2511 unsigned int count
= ch
->combined_count
;
2512 struct i40e_vsi
*vsi
= np
->vsi
;
2513 struct i40e_pf
*pf
= vsi
->back
;
2516 /* We do not support setting channels for any other VSI at present */
2517 if (vsi
->type
!= I40E_VSI_MAIN
)
2520 /* verify they are not requesting separate vectors */
2521 if (!count
|| ch
->rx_count
|| ch
->tx_count
)
2524 /* verify other_count has not changed */
2525 if (ch
->other_count
!= ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) ? 1 : 0))
2528 /* verify the number of channels does not exceed hardware limits */
2529 if (count
> i40e_max_channels(vsi
))
2532 /* update feature limits from largest to smallest supported values */
2533 /* TODO: Flow director limit, DCB etc */
2535 /* use rss_reconfig to rebuild with new queue count and update traffic
2536 * class queue mapping
2538 new_count
= i40e_reconfig_rss_queues(pf
, count
);
2545 #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2547 * i40e_get_rxfh_key_size - get the RSS hash key size
2548 * @netdev: network interface device structure
2550 * Returns the table size.
2552 static u32
i40e_get_rxfh_key_size(struct net_device
*netdev
)
2554 return I40E_HKEY_ARRAY_SIZE
;
2558 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2559 * @netdev: network interface device structure
2561 * Returns the table size.
2563 static u32
i40e_get_rxfh_indir_size(struct net_device
*netdev
)
2565 return I40E_HLUT_ARRAY_SIZE
;
2568 static int i40e_get_rxfh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
2571 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2572 struct i40e_vsi
*vsi
= np
->vsi
;
2573 struct i40e_pf
*pf
= vsi
->back
;
2574 struct i40e_hw
*hw
= &pf
->hw
;
2579 *hfunc
= ETH_RSS_HASH_TOP
;
2584 for (i
= 0, j
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++) {
2585 reg_val
= rd32(hw
, I40E_PFQF_HLUT(i
));
2586 indir
[j
++] = reg_val
& 0xff;
2587 indir
[j
++] = (reg_val
>> 8) & 0xff;
2588 indir
[j
++] = (reg_val
>> 16) & 0xff;
2589 indir
[j
++] = (reg_val
>> 24) & 0xff;
2593 for (i
= 0, j
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++) {
2594 reg_val
= rd32(hw
, I40E_PFQF_HKEY(i
));
2595 key
[j
++] = (u8
)(reg_val
& 0xff);
2596 key
[j
++] = (u8
)((reg_val
>> 8) & 0xff);
2597 key
[j
++] = (u8
)((reg_val
>> 16) & 0xff);
2598 key
[j
++] = (u8
)((reg_val
>> 24) & 0xff);
2605 * i40e_set_rxfh - set the rx flow hash indirection table
2606 * @netdev: network interface device structure
2607 * @indir: indirection table
2610 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
2611 * returns 0 after programming the table.
2613 static int i40e_set_rxfh(struct net_device
*netdev
, const u32
*indir
,
2614 const u8
*key
, const u8 hfunc
)
2616 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2617 struct i40e_vsi
*vsi
= np
->vsi
;
2618 struct i40e_pf
*pf
= vsi
->back
;
2619 struct i40e_hw
*hw
= &pf
->hw
;
2623 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
2629 for (i
= 0, j
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++) {
2630 reg_val
= indir
[j
++];
2631 reg_val
|= indir
[j
++] << 8;
2632 reg_val
|= indir
[j
++] << 16;
2633 reg_val
|= indir
[j
++] << 24;
2634 wr32(hw
, I40E_PFQF_HLUT(i
), reg_val
);
2638 for (i
= 0, j
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++) {
2640 reg_val
|= key
[j
++] << 8;
2641 reg_val
|= key
[j
++] << 16;
2642 reg_val
|= key
[j
++] << 24;
2643 wr32(hw
, I40E_PFQF_HKEY(i
), reg_val
);
2650 * i40e_get_priv_flags - report device private flags
2651 * @dev: network interface device structure
2653 * The get string set count and the string set should be matched for each
2654 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2657 * Returns a u32 bitmap of flags.
2659 static u32
i40e_get_priv_flags(struct net_device
*dev
)
2661 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2662 struct i40e_vsi
*vsi
= np
->vsi
;
2663 struct i40e_pf
*pf
= vsi
->back
;
2666 ret_flags
|= pf
->hw
.func_caps
.npar_enable
?
2667 I40E_PRIV_FLAGS_NPAR_FLAG
: 0;
2668 ret_flags
|= pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
?
2669 I40E_PRIV_FLAGS_LINKPOLL_FLAG
: 0;
2670 ret_flags
|= pf
->flags
& I40E_FLAG_FD_ATR_ENABLED
?
2671 I40E_PRIV_FLAGS_FD_ATR
: 0;
2677 * i40e_set_priv_flags - set private flags
2678 * @dev: network interface device structure
2679 * @flags: bit flags to be set
2681 static int i40e_set_priv_flags(struct net_device
*dev
, u32 flags
)
2683 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2684 struct i40e_vsi
*vsi
= np
->vsi
;
2685 struct i40e_pf
*pf
= vsi
->back
;
2687 if (flags
& I40E_PRIV_FLAGS_LINKPOLL_FLAG
)
2688 pf
->flags
|= I40E_FLAG_LINK_POLLING_ENABLED
;
2690 pf
->flags
&= ~I40E_FLAG_LINK_POLLING_ENABLED
;
2692 /* allow the user to control the state of the Flow
2693 * Director ATR (Application Targeted Routing) feature
2696 if (flags
& I40E_PRIV_FLAGS_FD_ATR
) {
2697 pf
->flags
|= I40E_FLAG_FD_ATR_ENABLED
;
2699 pf
->flags
&= ~I40E_FLAG_FD_ATR_ENABLED
;
2700 pf
->auto_disable_flags
|= I40E_FLAG_FD_ATR_ENABLED
;
2706 static const struct ethtool_ops i40e_ethtool_ops
= {
2707 .get_settings
= i40e_get_settings
,
2708 .set_settings
= i40e_set_settings
,
2709 .get_drvinfo
= i40e_get_drvinfo
,
2710 .get_regs_len
= i40e_get_regs_len
,
2711 .get_regs
= i40e_get_regs
,
2712 .nway_reset
= i40e_nway_reset
,
2713 .get_link
= ethtool_op_get_link
,
2714 .get_wol
= i40e_get_wol
,
2715 .set_wol
= i40e_set_wol
,
2716 .set_eeprom
= i40e_set_eeprom
,
2717 .get_eeprom_len
= i40e_get_eeprom_len
,
2718 .get_eeprom
= i40e_get_eeprom
,
2719 .get_ringparam
= i40e_get_ringparam
,
2720 .set_ringparam
= i40e_set_ringparam
,
2721 .get_pauseparam
= i40e_get_pauseparam
,
2722 .set_pauseparam
= i40e_set_pauseparam
,
2723 .get_msglevel
= i40e_get_msglevel
,
2724 .set_msglevel
= i40e_set_msglevel
,
2725 .get_rxnfc
= i40e_get_rxnfc
,
2726 .set_rxnfc
= i40e_set_rxnfc
,
2727 .self_test
= i40e_diag_test
,
2728 .get_strings
= i40e_get_strings
,
2729 .set_phys_id
= i40e_set_phys_id
,
2730 .get_sset_count
= i40e_get_sset_count
,
2731 .get_ethtool_stats
= i40e_get_ethtool_stats
,
2732 .get_coalesce
= i40e_get_coalesce
,
2733 .set_coalesce
= i40e_set_coalesce
,
2734 .get_rxfh_key_size
= i40e_get_rxfh_key_size
,
2735 .get_rxfh_indir_size
= i40e_get_rxfh_indir_size
,
2736 .get_rxfh
= i40e_get_rxfh
,
2737 .set_rxfh
= i40e_set_rxfh
,
2738 .get_channels
= i40e_get_channels
,
2739 .set_channels
= i40e_set_channels
,
2740 .get_ts_info
= i40e_get_ts_info
,
2741 .get_priv_flags
= i40e_get_priv_flags
,
2742 .set_priv_flags
= i40e_set_priv_flags
,
2745 void i40e_set_ethtool_ops(struct net_device
*netdev
)
2747 netdev
->ethtool_ops
= &i40e_ethtool_ops
;