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
] = {
236 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
239 * i40e_partition_setting_complaint - generic complaint for MFP restriction
242 static void i40e_partition_setting_complaint(struct i40e_pf
*pf
)
244 dev_info(&pf
->pdev
->dev
,
245 "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");
249 * i40e_get_settings_link_up - Get the Link settings for when link is up
251 * @ecmd: ethtool command to fill in
252 * @netdev: network interface device structure
255 static void i40e_get_settings_link_up(struct i40e_hw
*hw
,
256 struct ethtool_cmd
*ecmd
,
257 struct net_device
*netdev
)
259 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
260 u32 link_speed
= hw_link_info
->link_speed
;
262 /* Initialize supported and advertised settings based on phy settings */
263 switch (hw_link_info
->phy_type
) {
264 case I40E_PHY_TYPE_40GBASE_CR4
:
265 case I40E_PHY_TYPE_40GBASE_CR4_CU
:
266 ecmd
->supported
= SUPPORTED_Autoneg
|
267 SUPPORTED_40000baseCR4_Full
;
268 ecmd
->advertising
= ADVERTISED_Autoneg
|
269 ADVERTISED_40000baseCR4_Full
;
271 case I40E_PHY_TYPE_XLAUI
:
272 case I40E_PHY_TYPE_XLPPI
:
273 case I40E_PHY_TYPE_40GBASE_AOC
:
274 ecmd
->supported
= SUPPORTED_40000baseCR4_Full
;
276 case I40E_PHY_TYPE_40GBASE_KR4
:
277 ecmd
->supported
= SUPPORTED_Autoneg
|
278 SUPPORTED_40000baseKR4_Full
;
279 ecmd
->advertising
= ADVERTISED_Autoneg
|
280 ADVERTISED_40000baseKR4_Full
;
282 case I40E_PHY_TYPE_40GBASE_SR4
:
283 ecmd
->supported
= SUPPORTED_40000baseSR4_Full
;
285 case I40E_PHY_TYPE_40GBASE_LR4
:
286 ecmd
->supported
= SUPPORTED_40000baseLR4_Full
;
288 case I40E_PHY_TYPE_20GBASE_KR2
:
289 ecmd
->supported
= SUPPORTED_Autoneg
|
290 SUPPORTED_20000baseKR2_Full
;
291 ecmd
->advertising
= ADVERTISED_Autoneg
|
292 ADVERTISED_20000baseKR2_Full
;
294 case I40E_PHY_TYPE_10GBASE_KX4
:
295 ecmd
->supported
= SUPPORTED_Autoneg
|
296 SUPPORTED_10000baseKX4_Full
;
297 ecmd
->advertising
= ADVERTISED_Autoneg
|
298 ADVERTISED_10000baseKX4_Full
;
300 case I40E_PHY_TYPE_10GBASE_KR
:
301 ecmd
->supported
= SUPPORTED_Autoneg
|
302 SUPPORTED_10000baseKR_Full
;
303 ecmd
->advertising
= ADVERTISED_Autoneg
|
304 ADVERTISED_10000baseKR_Full
;
306 case I40E_PHY_TYPE_10GBASE_SR
:
307 case I40E_PHY_TYPE_10GBASE_LR
:
308 case I40E_PHY_TYPE_1000BASE_SX
:
309 case I40E_PHY_TYPE_1000BASE_LX
:
310 ecmd
->supported
= SUPPORTED_10000baseT_Full
|
311 SUPPORTED_1000baseT_Full
;
312 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
313 ecmd
->advertising
|= ADVERTISED_10000baseT_Full
;
314 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
315 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
317 case I40E_PHY_TYPE_1000BASE_KX
:
318 ecmd
->supported
= SUPPORTED_Autoneg
|
319 SUPPORTED_1000baseKX_Full
;
320 ecmd
->advertising
= ADVERTISED_Autoneg
|
321 ADVERTISED_1000baseKX_Full
;
323 case I40E_PHY_TYPE_10GBASE_T
:
324 case I40E_PHY_TYPE_1000BASE_T
:
325 case I40E_PHY_TYPE_100BASE_TX
:
326 ecmd
->supported
= SUPPORTED_Autoneg
|
327 SUPPORTED_10000baseT_Full
|
328 SUPPORTED_1000baseT_Full
|
329 SUPPORTED_100baseT_Full
;
330 ecmd
->advertising
= ADVERTISED_Autoneg
;
331 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
332 ecmd
->advertising
|= ADVERTISED_10000baseT_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 case I40E_PHY_TYPE_10GBASE_CR1_CU
:
339 case I40E_PHY_TYPE_10GBASE_CR1
:
340 ecmd
->supported
= SUPPORTED_Autoneg
|
341 SUPPORTED_10000baseT_Full
;
342 ecmd
->advertising
= ADVERTISED_Autoneg
|
343 ADVERTISED_10000baseT_Full
;
345 case I40E_PHY_TYPE_XAUI
:
346 case I40E_PHY_TYPE_XFI
:
347 case I40E_PHY_TYPE_SFI
:
348 case I40E_PHY_TYPE_10GBASE_SFPP_CU
:
349 case I40E_PHY_TYPE_10GBASE_AOC
:
350 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
352 case I40E_PHY_TYPE_SGMII
:
353 ecmd
->supported
= SUPPORTED_Autoneg
|
354 SUPPORTED_1000baseT_Full
|
355 SUPPORTED_100baseT_Full
;
356 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
357 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
358 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_100MB
)
359 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
362 /* if we got here and link is up something bad is afoot */
363 netdev_info(netdev
, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
364 hw_link_info
->phy_type
);
367 /* Set speed and duplex */
368 switch (link_speed
) {
369 case I40E_LINK_SPEED_40GB
:
370 ethtool_cmd_speed_set(ecmd
, SPEED_40000
);
372 case I40E_LINK_SPEED_20GB
:
373 ethtool_cmd_speed_set(ecmd
, SPEED_20000
);
375 case I40E_LINK_SPEED_10GB
:
376 ethtool_cmd_speed_set(ecmd
, SPEED_10000
);
378 case I40E_LINK_SPEED_1GB
:
379 ethtool_cmd_speed_set(ecmd
, SPEED_1000
);
381 case I40E_LINK_SPEED_100MB
:
382 ethtool_cmd_speed_set(ecmd
, SPEED_100
);
387 ecmd
->duplex
= DUPLEX_FULL
;
391 * i40e_get_settings_link_down - Get the Link settings for when link is down
393 * @ecmd: ethtool command to fill in
395 * Reports link settings that can be determined when link is down
397 static void i40e_get_settings_link_down(struct i40e_hw
*hw
,
398 struct ethtool_cmd
*ecmd
)
400 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
402 /* link is down and the driver needs to fall back on
403 * device ID to determine what kinds of info to display,
404 * it's mostly a guess that may change when link is up
406 switch (hw
->device_id
) {
407 case I40E_DEV_ID_QSFP_A
:
408 case I40E_DEV_ID_QSFP_B
:
409 case I40E_DEV_ID_QSFP_C
:
411 ecmd
->supported
= SUPPORTED_40000baseSR4_Full
|
412 SUPPORTED_40000baseCR4_Full
|
413 SUPPORTED_40000baseLR4_Full
;
414 ecmd
->advertising
= ADVERTISED_40000baseSR4_Full
|
415 ADVERTISED_40000baseCR4_Full
|
416 ADVERTISED_40000baseLR4_Full
;
418 case I40E_DEV_ID_KX_B
:
420 ecmd
->supported
= SUPPORTED_40000baseKR4_Full
;
421 ecmd
->advertising
= ADVERTISED_40000baseKR4_Full
;
423 case I40E_DEV_ID_KX_C
:
425 ecmd
->supported
= SUPPORTED_10000baseKR_Full
;
426 ecmd
->advertising
= ADVERTISED_10000baseKR_Full
;
428 case I40E_DEV_ID_10G_BASE_T
:
429 case I40E_DEV_ID_10G_BASE_T4
:
430 ecmd
->supported
= SUPPORTED_10000baseT_Full
|
431 SUPPORTED_1000baseT_Full
|
432 SUPPORTED_100baseT_Full
;
433 /* Figure out what has been requested */
434 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
435 ecmd
->advertising
|= ADVERTISED_10000baseT_Full
;
436 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
437 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
438 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_100MB
)
439 ecmd
->advertising
|= ADVERTISED_100baseT_Full
;
441 case I40E_DEV_ID_20G_KR2
:
442 case I40E_DEV_ID_20G_KR2_A
:
444 ecmd
->supported
= SUPPORTED_20000baseKR2_Full
;
445 ecmd
->advertising
= ADVERTISED_20000baseKR2_Full
;
448 /* all the rest are 10G/1G */
449 ecmd
->supported
= SUPPORTED_10000baseT_Full
|
450 SUPPORTED_1000baseT_Full
;
451 /* Figure out what has been requested */
452 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_10GB
)
453 ecmd
->advertising
|= ADVERTISED_10000baseT_Full
;
454 if (hw_link_info
->requested_speeds
& I40E_LINK_SPEED_1GB
)
455 ecmd
->advertising
|= ADVERTISED_1000baseT_Full
;
459 /* With no link speed and duplex are unknown */
460 ethtool_cmd_speed_set(ecmd
, SPEED_UNKNOWN
);
461 ecmd
->duplex
= DUPLEX_UNKNOWN
;
465 * i40e_get_settings - Get Link Speed and Duplex settings
466 * @netdev: network interface device structure
467 * @ecmd: ethtool command
469 * Reports speed/duplex settings based on media_type
471 static int i40e_get_settings(struct net_device
*netdev
,
472 struct ethtool_cmd
*ecmd
)
474 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
475 struct i40e_pf
*pf
= np
->vsi
->back
;
476 struct i40e_hw
*hw
= &pf
->hw
;
477 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
478 bool link_up
= hw_link_info
->link_info
& I40E_AQ_LINK_UP
;
481 i40e_get_settings_link_up(hw
, ecmd
, netdev
);
483 i40e_get_settings_link_down(hw
, ecmd
);
485 /* Now set the settings that don't rely on link being up/down */
487 /* Set autoneg settings */
488 ecmd
->autoneg
= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
489 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
491 switch (hw
->phy
.media_type
) {
492 case I40E_MEDIA_TYPE_BACKPLANE
:
493 ecmd
->supported
|= SUPPORTED_Autoneg
|
495 ecmd
->advertising
|= ADVERTISED_Autoneg
|
496 ADVERTISED_Backplane
;
497 ecmd
->port
= PORT_NONE
;
499 case I40E_MEDIA_TYPE_BASET
:
500 ecmd
->supported
|= SUPPORTED_TP
;
501 ecmd
->advertising
|= ADVERTISED_TP
;
502 ecmd
->port
= PORT_TP
;
504 case I40E_MEDIA_TYPE_DA
:
505 case I40E_MEDIA_TYPE_CX4
:
506 ecmd
->supported
|= SUPPORTED_FIBRE
;
507 ecmd
->advertising
|= ADVERTISED_FIBRE
;
508 ecmd
->port
= PORT_DA
;
510 case I40E_MEDIA_TYPE_FIBER
:
511 ecmd
->supported
|= SUPPORTED_FIBRE
;
512 ecmd
->port
= PORT_FIBRE
;
514 case I40E_MEDIA_TYPE_UNKNOWN
:
516 ecmd
->port
= PORT_OTHER
;
520 /* Set transceiver */
521 ecmd
->transceiver
= XCVR_EXTERNAL
;
523 /* Set flow control settings */
524 ecmd
->supported
|= SUPPORTED_Pause
;
526 switch (hw
->fc
.requested_mode
) {
528 ecmd
->advertising
|= ADVERTISED_Pause
;
530 case I40E_FC_TX_PAUSE
:
531 ecmd
->advertising
|= ADVERTISED_Asym_Pause
;
533 case I40E_FC_RX_PAUSE
:
534 ecmd
->advertising
|= (ADVERTISED_Pause
|
535 ADVERTISED_Asym_Pause
);
538 ecmd
->advertising
&= ~(ADVERTISED_Pause
|
539 ADVERTISED_Asym_Pause
);
547 * i40e_set_settings - Set Speed and Duplex
548 * @netdev: network interface device structure
549 * @ecmd: ethtool command
551 * Set speed/duplex per media_types advertised/forced
553 static int i40e_set_settings(struct net_device
*netdev
,
554 struct ethtool_cmd
*ecmd
)
556 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
557 struct i40e_aq_get_phy_abilities_resp abilities
;
558 struct i40e_aq_set_phy_config config
;
559 struct i40e_pf
*pf
= np
->vsi
->back
;
560 struct i40e_vsi
*vsi
= np
->vsi
;
561 struct i40e_hw
*hw
= &pf
->hw
;
562 struct ethtool_cmd safe_ecmd
;
563 i40e_status status
= 0;
569 /* Changing port settings is not supported if this isn't the
570 * port's controlling PF
572 if (hw
->partition_id
!= 1) {
573 i40e_partition_setting_complaint(pf
);
577 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
580 if (hw
->phy
.media_type
!= I40E_MEDIA_TYPE_BASET
&&
581 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_FIBER
&&
582 hw
->phy
.media_type
!= I40E_MEDIA_TYPE_BACKPLANE
&&
583 hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
)
586 /* get our own copy of the bits to check against */
587 memset(&safe_ecmd
, 0, sizeof(struct ethtool_cmd
));
588 i40e_get_settings(netdev
, &safe_ecmd
);
590 /* save autoneg and speed out of ecmd */
591 autoneg
= ecmd
->autoneg
;
592 advertise
= ecmd
->advertising
;
594 /* set autoneg and speed back to what they currently are */
595 ecmd
->autoneg
= safe_ecmd
.autoneg
;
596 ecmd
->advertising
= safe_ecmd
.advertising
;
598 ecmd
->cmd
= safe_ecmd
.cmd
;
599 /* If ecmd and safe_ecmd are not the same now, then they are
600 * trying to set something that we do not support
602 if (memcmp(ecmd
, &safe_ecmd
, sizeof(struct ethtool_cmd
)))
605 while (test_bit(__I40E_CONFIG_BUSY
, &vsi
->state
))
606 usleep_range(1000, 2000);
608 /* Get the current phy config */
609 status
= i40e_aq_get_phy_capabilities(hw
, false, false, &abilities
,
614 /* Copy abilities to config in case autoneg is not
617 memset(&config
, 0, sizeof(struct i40e_aq_set_phy_config
));
618 config
.abilities
= abilities
.abilities
;
621 if (autoneg
== AUTONEG_ENABLE
) {
622 /* If autoneg is not supported, return error */
623 if (!(safe_ecmd
.supported
& SUPPORTED_Autoneg
)) {
624 netdev_info(netdev
, "Autoneg not supported on this phy\n");
627 /* If autoneg was not already enabled */
628 if (!(hw
->phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
)) {
629 config
.abilities
= abilities
.abilities
|
630 I40E_AQ_PHY_ENABLE_AN
;
634 /* If autoneg is supported 10GBASE_T is the only phy that
635 * can disable it, so otherwise return error
637 if (safe_ecmd
.supported
& SUPPORTED_Autoneg
&&
638 hw
->phy
.link_info
.phy_type
!= I40E_PHY_TYPE_10GBASE_T
) {
639 netdev_info(netdev
, "Autoneg cannot be disabled on this phy\n");
642 /* If autoneg is currently enabled */
643 if (hw
->phy
.link_info
.an_info
& I40E_AQ_AN_COMPLETED
) {
644 config
.abilities
= abilities
.abilities
&
645 ~I40E_AQ_PHY_ENABLE_AN
;
650 if (advertise
& ~safe_ecmd
.supported
)
653 if (advertise
& ADVERTISED_100baseT_Full
)
654 config
.link_speed
|= I40E_LINK_SPEED_100MB
;
655 if (advertise
& ADVERTISED_1000baseT_Full
||
656 advertise
& ADVERTISED_1000baseKX_Full
)
657 config
.link_speed
|= I40E_LINK_SPEED_1GB
;
658 if (advertise
& ADVERTISED_10000baseT_Full
||
659 advertise
& ADVERTISED_10000baseKX4_Full
||
660 advertise
& ADVERTISED_10000baseKR_Full
)
661 config
.link_speed
|= I40E_LINK_SPEED_10GB
;
662 if (advertise
& ADVERTISED_20000baseKR2_Full
)
663 config
.link_speed
|= I40E_LINK_SPEED_20GB
;
664 if (advertise
& ADVERTISED_40000baseKR4_Full
||
665 advertise
& ADVERTISED_40000baseCR4_Full
||
666 advertise
& ADVERTISED_40000baseSR4_Full
||
667 advertise
& ADVERTISED_40000baseLR4_Full
)
668 config
.link_speed
|= I40E_LINK_SPEED_40GB
;
670 /* If speed didn't get set, set it to what it currently is.
671 * This is needed because if advertise is 0 (as it is when autoneg
672 * is disabled) then speed won't get set.
674 if (!config
.link_speed
)
675 config
.link_speed
= abilities
.link_speed
;
677 if (change
|| (abilities
.link_speed
!= config
.link_speed
)) {
678 /* copy over the rest of the abilities */
679 config
.phy_type
= abilities
.phy_type
;
680 config
.eee_capability
= abilities
.eee_capability
;
681 config
.eeer
= abilities
.eeer_val
;
682 config
.low_power_ctrl
= abilities
.d3_lpan
;
684 /* save the requested speeds */
685 hw
->phy
.link_info
.requested_speeds
= config
.link_speed
;
686 /* set link and auto negotiation so changes take effect */
687 config
.abilities
|= I40E_AQ_PHY_ENABLE_ATOMIC_LINK
;
688 /* If link is up put link down */
689 if (hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
) {
690 /* Tell the OS link is going down, the link will go
691 * back up when fw says it is ready asynchronously
693 i40e_print_link_message(vsi
, false);
694 netif_carrier_off(netdev
);
695 netif_tx_stop_all_queues(netdev
);
698 /* make the aq call */
699 status
= i40e_aq_set_phy_config(hw
, &config
, NULL
);
701 netdev_info(netdev
, "Set phy config failed, err %s aq_err %s\n",
702 i40e_stat_str(hw
, status
),
703 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
707 status
= i40e_aq_get_link_info(hw
, true, NULL
, NULL
);
709 netdev_info(netdev
, "Updating link info failed with err %s aq_err %s\n",
710 i40e_stat_str(hw
, status
),
711 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
714 netdev_info(netdev
, "Nothing changed, exiting without setting anything.\n");
720 static int i40e_nway_reset(struct net_device
*netdev
)
722 /* restart autonegotiation */
723 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
724 struct i40e_pf
*pf
= np
->vsi
->back
;
725 struct i40e_hw
*hw
= &pf
->hw
;
726 bool link_up
= hw
->phy
.link_info
.link_info
& I40E_AQ_LINK_UP
;
729 ret
= i40e_aq_set_link_restart_an(hw
, link_up
, NULL
);
731 netdev_info(netdev
, "link restart failed, err %s aq_err %s\n",
732 i40e_stat_str(hw
, ret
),
733 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
741 * i40e_get_pauseparam - Get Flow Control status
742 * Return tx/rx-pause status
744 static void i40e_get_pauseparam(struct net_device
*netdev
,
745 struct ethtool_pauseparam
*pause
)
747 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
748 struct i40e_pf
*pf
= np
->vsi
->back
;
749 struct i40e_hw
*hw
= &pf
->hw
;
750 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
751 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
754 ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
755 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
757 /* PFC enabled so report LFC as off */
758 if (dcbx_cfg
->pfc
.pfcenable
) {
764 if (hw
->fc
.current_mode
== I40E_FC_RX_PAUSE
) {
766 } else if (hw
->fc
.current_mode
== I40E_FC_TX_PAUSE
) {
768 } else if (hw
->fc
.current_mode
== I40E_FC_FULL
) {
775 * i40e_set_pauseparam - Set Flow Control parameter
776 * @netdev: network interface device structure
777 * @pause: return tx/rx flow control status
779 static int i40e_set_pauseparam(struct net_device
*netdev
,
780 struct ethtool_pauseparam
*pause
)
782 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
783 struct i40e_pf
*pf
= np
->vsi
->back
;
784 struct i40e_vsi
*vsi
= np
->vsi
;
785 struct i40e_hw
*hw
= &pf
->hw
;
786 struct i40e_link_status
*hw_link_info
= &hw
->phy
.link_info
;
787 struct i40e_dcbx_config
*dcbx_cfg
= &hw
->local_dcbx_config
;
788 bool link_up
= hw_link_info
->link_info
& I40E_AQ_LINK_UP
;
793 /* Changing the port's flow control is not supported if this isn't the
794 * port's controlling PF
796 if (hw
->partition_id
!= 1) {
797 i40e_partition_setting_complaint(pf
);
801 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
804 if (pause
->autoneg
!= ((hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
) ?
805 AUTONEG_ENABLE
: AUTONEG_DISABLE
)) {
806 netdev_info(netdev
, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
810 /* If we have link and don't have autoneg */
811 if (!test_bit(__I40E_DOWN
, &pf
->state
) &&
812 !(hw_link_info
->an_info
& I40E_AQ_AN_COMPLETED
)) {
813 /* Send message that it might not necessarily work*/
814 netdev_info(netdev
, "Autoneg did not complete so changing settings may not result in an actual change.\n");
817 if (dcbx_cfg
->pfc
.pfcenable
) {
819 "Priority flow control enabled. Cannot set link flow control.\n");
823 if (pause
->rx_pause
&& pause
->tx_pause
)
824 hw
->fc
.requested_mode
= I40E_FC_FULL
;
825 else if (pause
->rx_pause
&& !pause
->tx_pause
)
826 hw
->fc
.requested_mode
= I40E_FC_RX_PAUSE
;
827 else if (!pause
->rx_pause
&& pause
->tx_pause
)
828 hw
->fc
.requested_mode
= I40E_FC_TX_PAUSE
;
829 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
830 hw
->fc
.requested_mode
= I40E_FC_NONE
;
834 /* Tell the OS link is going down, the link will go back up when fw
835 * says it is ready asynchronously
837 i40e_print_link_message(vsi
, false);
838 netif_carrier_off(netdev
);
839 netif_tx_stop_all_queues(netdev
);
841 /* Set the fc mode and only restart an if link is up*/
842 status
= i40e_set_fc(hw
, &aq_failures
, link_up
);
844 if (aq_failures
& I40E_SET_FC_AQ_FAIL_GET
) {
845 netdev_info(netdev
, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
846 i40e_stat_str(hw
, status
),
847 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
850 if (aq_failures
& I40E_SET_FC_AQ_FAIL_SET
) {
851 netdev_info(netdev
, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
852 i40e_stat_str(hw
, status
),
853 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
856 if (aq_failures
& I40E_SET_FC_AQ_FAIL_UPDATE
) {
857 netdev_info(netdev
, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
858 i40e_stat_str(hw
, status
),
859 i40e_aq_str(hw
, hw
->aq
.asq_last_status
));
863 if (!test_bit(__I40E_DOWN
, &pf
->state
)) {
864 /* Give it a little more time to try to come back */
866 if (!test_bit(__I40E_DOWN
, &pf
->state
))
867 return i40e_nway_reset(netdev
);
873 static u32
i40e_get_msglevel(struct net_device
*netdev
)
875 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
876 struct i40e_pf
*pf
= np
->vsi
->back
;
878 return pf
->msg_enable
;
881 static void i40e_set_msglevel(struct net_device
*netdev
, u32 data
)
883 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
884 struct i40e_pf
*pf
= np
->vsi
->back
;
886 if (I40E_DEBUG_USER
& data
)
887 pf
->hw
.debug_mask
= data
;
888 pf
->msg_enable
= data
;
891 static int i40e_get_regs_len(struct net_device
*netdev
)
896 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++)
897 reg_count
+= i40e_reg_list
[i
].elements
;
899 return reg_count
* sizeof(u32
);
902 static void i40e_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
,
905 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
906 struct i40e_pf
*pf
= np
->vsi
->back
;
907 struct i40e_hw
*hw
= &pf
->hw
;
912 /* Tell ethtool which driver-version-specific regs output we have.
914 * At some point, if we have ethtool doing special formatting of
915 * this data, it will rely on this version number to know how to
916 * interpret things. Hence, this needs to be updated if/when the
917 * diags register table is changed.
921 /* loop through the diags reg table for what to print */
923 for (i
= 0; i40e_reg_list
[i
].offset
!= 0; i
++) {
924 for (j
= 0; j
< i40e_reg_list
[i
].elements
; j
++) {
925 reg
= i40e_reg_list
[i
].offset
926 + (j
* i40e_reg_list
[i
].stride
);
927 reg_buf
[ri
++] = rd32(hw
, reg
);
933 static int i40e_get_eeprom(struct net_device
*netdev
,
934 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
936 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
937 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
938 struct i40e_pf
*pf
= np
->vsi
->back
;
939 int ret_val
= 0, len
, offset
;
945 #define I40E_NVM_SECTOR_SIZE 4096
946 if (eeprom
->len
== 0)
949 /* check for NVMUpdate access method */
950 magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
951 if (eeprom
->magic
&& eeprom
->magic
!= magic
) {
952 struct i40e_nvm_access
*cmd
;
955 /* make sure it is the right magic for NVMUpdate */
956 if ((eeprom
->magic
>> 16) != hw
->device_id
)
959 cmd
= (struct i40e_nvm_access
*)eeprom
;
960 ret_val
= i40e_nvmupd_command(hw
, cmd
, bytes
, &errno
);
962 ((hw
->aq
.asq_last_status
!= I40E_AQ_RC_EACCES
) ||
963 (hw
->debug_mask
& I40E_DEBUG_NVM
)))
964 dev_info(&pf
->pdev
->dev
,
965 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
966 ret_val
, hw
->aq
.asq_last_status
, errno
,
967 (u8
)(cmd
->config
& I40E_NVM_MOD_PNT_MASK
),
968 cmd
->offset
, cmd
->data_size
);
973 /* normal ethtool get_eeprom support */
974 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
976 eeprom_buff
= kzalloc(eeprom
->len
, GFP_KERNEL
);
980 ret_val
= i40e_acquire_nvm(hw
, I40E_RESOURCE_READ
);
982 dev_info(&pf
->pdev
->dev
,
983 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
984 ret_val
, hw
->aq
.asq_last_status
);
988 sectors
= eeprom
->len
/ I40E_NVM_SECTOR_SIZE
;
989 sectors
+= (eeprom
->len
% I40E_NVM_SECTOR_SIZE
) ? 1 : 0;
990 len
= I40E_NVM_SECTOR_SIZE
;
992 for (i
= 0; i
< sectors
; i
++) {
993 if (i
== (sectors
- 1)) {
994 len
= eeprom
->len
- (I40E_NVM_SECTOR_SIZE
* i
);
997 offset
= eeprom
->offset
+ (I40E_NVM_SECTOR_SIZE
* i
),
998 ret_val
= i40e_aq_read_nvm(hw
, 0x0, offset
, len
,
999 (u8
*)eeprom_buff
+ (I40E_NVM_SECTOR_SIZE
* i
),
1001 if (ret_val
&& hw
->aq
.asq_last_status
== I40E_AQ_RC_EPERM
) {
1002 dev_info(&pf
->pdev
->dev
,
1003 "read NVM failed, invalid offset 0x%x\n",
1006 } else if (ret_val
&&
1007 hw
->aq
.asq_last_status
== I40E_AQ_RC_EACCES
) {
1008 dev_info(&pf
->pdev
->dev
,
1009 "read NVM failed, access, offset 0x%x\n",
1012 } else if (ret_val
) {
1013 dev_info(&pf
->pdev
->dev
,
1014 "read NVM failed offset %d err=%d status=0x%x\n",
1015 offset
, ret_val
, hw
->aq
.asq_last_status
);
1020 i40e_release_nvm(hw
);
1021 memcpy(bytes
, (u8
*)eeprom_buff
, eeprom
->len
);
1027 static int i40e_get_eeprom_len(struct net_device
*netdev
)
1029 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1030 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1033 val
= (rd32(hw
, I40E_GLPCI_LBARCTRL
)
1034 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK
)
1035 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT
;
1036 /* register returns value in power of 2, 64Kbyte chunks. */
1037 val
= (64 * 1024) * BIT(val
);
1041 static int i40e_set_eeprom(struct net_device
*netdev
,
1042 struct ethtool_eeprom
*eeprom
, u8
*bytes
)
1044 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1045 struct i40e_hw
*hw
= &np
->vsi
->back
->hw
;
1046 struct i40e_pf
*pf
= np
->vsi
->back
;
1047 struct i40e_nvm_access
*cmd
;
1052 /* normal ethtool set_eeprom is not supported */
1053 magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
1054 if (eeprom
->magic
== magic
)
1057 /* check for NVMUpdate access method */
1058 if (!eeprom
->magic
|| (eeprom
->magic
>> 16) != hw
->device_id
)
1061 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
1062 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
1065 cmd
= (struct i40e_nvm_access
*)eeprom
;
1066 ret_val
= i40e_nvmupd_command(hw
, cmd
, bytes
, &errno
);
1068 ((hw
->aq
.asq_last_status
!= I40E_AQ_RC_EPERM
&&
1069 hw
->aq
.asq_last_status
!= I40E_AQ_RC_EBUSY
) ||
1070 (hw
->debug_mask
& I40E_DEBUG_NVM
)))
1071 dev_info(&pf
->pdev
->dev
,
1072 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1073 ret_val
, hw
->aq
.asq_last_status
, errno
,
1074 (u8
)(cmd
->config
& I40E_NVM_MOD_PNT_MASK
),
1075 cmd
->offset
, cmd
->data_size
);
1080 static void i40e_get_drvinfo(struct net_device
*netdev
,
1081 struct ethtool_drvinfo
*drvinfo
)
1083 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1084 struct i40e_vsi
*vsi
= np
->vsi
;
1085 struct i40e_pf
*pf
= vsi
->back
;
1087 strlcpy(drvinfo
->driver
, i40e_driver_name
, sizeof(drvinfo
->driver
));
1088 strlcpy(drvinfo
->version
, i40e_driver_version_str
,
1089 sizeof(drvinfo
->version
));
1090 strlcpy(drvinfo
->fw_version
, i40e_fw_version_str(&pf
->hw
),
1091 sizeof(drvinfo
->fw_version
));
1092 strlcpy(drvinfo
->bus_info
, pci_name(pf
->pdev
),
1093 sizeof(drvinfo
->bus_info
));
1094 drvinfo
->n_priv_flags
= I40E_PRIV_FLAGS_STR_LEN
;
1097 static void i40e_get_ringparam(struct net_device
*netdev
,
1098 struct ethtool_ringparam
*ring
)
1100 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1101 struct i40e_pf
*pf
= np
->vsi
->back
;
1102 struct i40e_vsi
*vsi
= pf
->vsi
[pf
->lan_vsi
];
1104 ring
->rx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
1105 ring
->tx_max_pending
= I40E_MAX_NUM_DESCRIPTORS
;
1106 ring
->rx_mini_max_pending
= 0;
1107 ring
->rx_jumbo_max_pending
= 0;
1108 ring
->rx_pending
= vsi
->rx_rings
[0]->count
;
1109 ring
->tx_pending
= vsi
->tx_rings
[0]->count
;
1110 ring
->rx_mini_pending
= 0;
1111 ring
->rx_jumbo_pending
= 0;
1114 static int i40e_set_ringparam(struct net_device
*netdev
,
1115 struct ethtool_ringparam
*ring
)
1117 struct i40e_ring
*tx_rings
= NULL
, *rx_rings
= NULL
;
1118 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1119 struct i40e_vsi
*vsi
= np
->vsi
;
1120 struct i40e_pf
*pf
= vsi
->back
;
1121 u32 new_rx_count
, new_tx_count
;
1124 if ((ring
->rx_mini_pending
) || (ring
->rx_jumbo_pending
))
1127 if (ring
->tx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
1128 ring
->tx_pending
< I40E_MIN_NUM_DESCRIPTORS
||
1129 ring
->rx_pending
> I40E_MAX_NUM_DESCRIPTORS
||
1130 ring
->rx_pending
< I40E_MIN_NUM_DESCRIPTORS
) {
1132 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1133 ring
->tx_pending
, ring
->rx_pending
,
1134 I40E_MIN_NUM_DESCRIPTORS
, I40E_MAX_NUM_DESCRIPTORS
);
1138 new_tx_count
= ALIGN(ring
->tx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
1139 new_rx_count
= ALIGN(ring
->rx_pending
, I40E_REQ_DESCRIPTOR_MULTIPLE
);
1141 /* if nothing to do return success */
1142 if ((new_tx_count
== vsi
->tx_rings
[0]->count
) &&
1143 (new_rx_count
== vsi
->rx_rings
[0]->count
))
1146 while (test_and_set_bit(__I40E_CONFIG_BUSY
, &pf
->state
))
1147 usleep_range(1000, 2000);
1149 if (!netif_running(vsi
->netdev
)) {
1150 /* simple case - set for the next time the netdev is started */
1151 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1152 vsi
->tx_rings
[i
]->count
= new_tx_count
;
1153 vsi
->rx_rings
[i
]->count
= new_rx_count
;
1158 /* We can't just free everything and then setup again,
1159 * because the ISRs in MSI-X mode get passed pointers
1160 * to the Tx and Rx ring structs.
1163 /* alloc updated Tx resources */
1164 if (new_tx_count
!= vsi
->tx_rings
[0]->count
) {
1166 "Changing Tx descriptor count from %d to %d.\n",
1167 vsi
->tx_rings
[0]->count
, new_tx_count
);
1168 tx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
1169 sizeof(struct i40e_ring
), GFP_KERNEL
);
1175 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1176 /* clone ring and setup updated count */
1177 tx_rings
[i
] = *vsi
->tx_rings
[i
];
1178 tx_rings
[i
].count
= new_tx_count
;
1179 /* the desc and bi pointers will be reallocated in the
1182 tx_rings
[i
].desc
= NULL
;
1183 tx_rings
[i
].rx_bi
= NULL
;
1184 err
= i40e_setup_tx_descriptors(&tx_rings
[i
]);
1188 i40e_free_tx_resources(&tx_rings
[i
]);
1198 /* alloc updated Rx resources */
1199 if (new_rx_count
!= vsi
->rx_rings
[0]->count
) {
1201 "Changing Rx descriptor count from %d to %d\n",
1202 vsi
->rx_rings
[0]->count
, new_rx_count
);
1203 rx_rings
= kcalloc(vsi
->alloc_queue_pairs
,
1204 sizeof(struct i40e_ring
), GFP_KERNEL
);
1210 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1211 /* clone ring and setup updated count */
1212 rx_rings
[i
] = *vsi
->rx_rings
[i
];
1213 rx_rings
[i
].count
= new_rx_count
;
1214 /* the desc and bi pointers will be reallocated in the
1217 rx_rings
[i
].desc
= NULL
;
1218 rx_rings
[i
].rx_bi
= NULL
;
1219 err
= i40e_setup_rx_descriptors(&rx_rings
[i
]);
1223 i40e_free_rx_resources(&rx_rings
[i
]);
1233 /* Bring interface down, copy in the new ring info,
1234 * then restore the interface
1239 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1240 i40e_free_tx_resources(vsi
->tx_rings
[i
]);
1241 *vsi
->tx_rings
[i
] = tx_rings
[i
];
1248 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1249 i40e_free_rx_resources(vsi
->rx_rings
[i
]);
1250 *vsi
->rx_rings
[i
] = rx_rings
[i
];
1259 /* error cleanup if the Rx allocations failed after getting Tx */
1261 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++)
1262 i40e_free_tx_resources(&tx_rings
[i
]);
1268 clear_bit(__I40E_CONFIG_BUSY
, &pf
->state
);
1273 static int i40e_get_sset_count(struct net_device
*netdev
, int sset
)
1275 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1276 struct i40e_vsi
*vsi
= np
->vsi
;
1277 struct i40e_pf
*pf
= vsi
->back
;
1281 return I40E_TEST_LEN
;
1283 if (vsi
== pf
->vsi
[pf
->lan_vsi
] && pf
->hw
.partition_id
== 1) {
1284 int len
= I40E_PF_STATS_LEN(netdev
);
1286 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1287 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
))
1288 len
+= I40E_VEB_STATS_TOTAL
;
1291 return I40E_VSI_STATS_LEN(netdev
);
1293 case ETH_SS_PRIV_FLAGS
:
1294 return I40E_PRIV_FLAGS_STR_LEN
;
1300 static void i40e_get_ethtool_stats(struct net_device
*netdev
,
1301 struct ethtool_stats
*stats
, u64
*data
)
1303 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1304 struct i40e_ring
*tx_ring
, *rx_ring
;
1305 struct i40e_vsi
*vsi
= np
->vsi
;
1306 struct i40e_pf
*pf
= vsi
->back
;
1310 struct rtnl_link_stats64
*net_stats
= i40e_get_vsi_stats_struct(vsi
);
1313 i40e_update_stats(vsi
);
1315 for (j
= 0; j
< I40E_NETDEV_STATS_LEN
; j
++) {
1316 p
= (char *)net_stats
+ i40e_gstrings_net_stats
[j
].stat_offset
;
1317 data
[i
++] = (i40e_gstrings_net_stats
[j
].sizeof_stat
==
1318 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1320 for (j
= 0; j
< I40E_MISC_STATS_LEN
; j
++) {
1321 p
= (char *)vsi
+ i40e_gstrings_misc_stats
[j
].stat_offset
;
1322 data
[i
++] = (i40e_gstrings_misc_stats
[j
].sizeof_stat
==
1323 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1326 for (j
= 0; j
< I40E_FCOE_STATS_LEN
; j
++) {
1327 p
= (char *)vsi
+ i40e_gstrings_fcoe_stats
[j
].stat_offset
;
1328 data
[i
++] = (i40e_gstrings_fcoe_stats
[j
].sizeof_stat
==
1329 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1333 for (j
= 0; j
< vsi
->num_queue_pairs
; j
++) {
1334 tx_ring
= ACCESS_ONCE(vsi
->tx_rings
[j
]);
1339 /* process Tx ring statistics */
1341 start
= u64_stats_fetch_begin_irq(&tx_ring
->syncp
);
1342 data
[i
] = tx_ring
->stats
.packets
;
1343 data
[i
+ 1] = tx_ring
->stats
.bytes
;
1344 } while (u64_stats_fetch_retry_irq(&tx_ring
->syncp
, start
));
1347 /* Rx ring is the 2nd half of the queue pair */
1348 rx_ring
= &tx_ring
[1];
1350 start
= u64_stats_fetch_begin_irq(&rx_ring
->syncp
);
1351 data
[i
] = rx_ring
->stats
.packets
;
1352 data
[i
+ 1] = rx_ring
->stats
.bytes
;
1353 } while (u64_stats_fetch_retry_irq(&rx_ring
->syncp
, start
));
1357 if (vsi
!= pf
->vsi
[pf
->lan_vsi
] || pf
->hw
.partition_id
!= 1)
1360 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1361 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
1362 struct i40e_veb
*veb
= pf
->veb
[pf
->lan_veb
];
1364 for (j
= 0; j
< I40E_VEB_STATS_LEN
; j
++) {
1366 p
+= i40e_gstrings_veb_stats
[j
].stat_offset
;
1367 data
[i
++] = (i40e_gstrings_veb_stats
[j
].sizeof_stat
==
1368 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1371 for (j
= 0; j
< I40E_GLOBAL_STATS_LEN
; j
++) {
1372 p
= (char *)pf
+ i40e_gstrings_stats
[j
].stat_offset
;
1373 data
[i
++] = (i40e_gstrings_stats
[j
].sizeof_stat
==
1374 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1376 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
1377 data
[i
++] = pf
->stats
.priority_xon_tx
[j
];
1378 data
[i
++] = pf
->stats
.priority_xoff_tx
[j
];
1380 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++) {
1381 data
[i
++] = pf
->stats
.priority_xon_rx
[j
];
1382 data
[i
++] = pf
->stats
.priority_xoff_rx
[j
];
1384 for (j
= 0; j
< I40E_MAX_USER_PRIORITY
; j
++)
1385 data
[i
++] = pf
->stats
.priority_xon_2_xoff
[j
];
1388 static void i40e_get_strings(struct net_device
*netdev
, u32 stringset
,
1391 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1392 struct i40e_vsi
*vsi
= np
->vsi
;
1393 struct i40e_pf
*pf
= vsi
->back
;
1394 char *p
= (char *)data
;
1397 switch (stringset
) {
1399 for (i
= 0; i
< I40E_TEST_LEN
; i
++) {
1400 memcpy(data
, i40e_gstrings_test
[i
], ETH_GSTRING_LEN
);
1401 data
+= ETH_GSTRING_LEN
;
1405 for (i
= 0; i
< I40E_NETDEV_STATS_LEN
; i
++) {
1406 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1407 i40e_gstrings_net_stats
[i
].stat_string
);
1408 p
+= ETH_GSTRING_LEN
;
1410 for (i
= 0; i
< I40E_MISC_STATS_LEN
; i
++) {
1411 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1412 i40e_gstrings_misc_stats
[i
].stat_string
);
1413 p
+= ETH_GSTRING_LEN
;
1416 for (i
= 0; i
< I40E_FCOE_STATS_LEN
; i
++) {
1417 snprintf(p
, ETH_GSTRING_LEN
, "%s",
1418 i40e_gstrings_fcoe_stats
[i
].stat_string
);
1419 p
+= ETH_GSTRING_LEN
;
1422 for (i
= 0; i
< vsi
->num_queue_pairs
; i
++) {
1423 snprintf(p
, ETH_GSTRING_LEN
, "tx-%u.tx_packets", i
);
1424 p
+= ETH_GSTRING_LEN
;
1425 snprintf(p
, ETH_GSTRING_LEN
, "tx-%u.tx_bytes", i
);
1426 p
+= ETH_GSTRING_LEN
;
1427 snprintf(p
, ETH_GSTRING_LEN
, "rx-%u.rx_packets", i
);
1428 p
+= ETH_GSTRING_LEN
;
1429 snprintf(p
, ETH_GSTRING_LEN
, "rx-%u.rx_bytes", i
);
1430 p
+= ETH_GSTRING_LEN
;
1432 if (vsi
!= pf
->vsi
[pf
->lan_vsi
] || pf
->hw
.partition_id
!= 1)
1435 if ((pf
->lan_veb
!= I40E_NO_VEB
) &&
1436 (pf
->flags
& I40E_FLAG_VEB_STATS_ENABLED
)) {
1437 for (i
= 0; i
< I40E_VEB_STATS_LEN
; i
++) {
1438 snprintf(p
, ETH_GSTRING_LEN
, "veb.%s",
1439 i40e_gstrings_veb_stats
[i
].stat_string
);
1440 p
+= ETH_GSTRING_LEN
;
1442 for (i
= 0; i
< I40E_MAX_TRAFFIC_CLASS
; i
++) {
1443 snprintf(p
, ETH_GSTRING_LEN
,
1444 "veb.tc_%u_tx_packets", i
);
1445 p
+= ETH_GSTRING_LEN
;
1446 snprintf(p
, ETH_GSTRING_LEN
,
1447 "veb.tc_%u_tx_bytes", i
);
1448 p
+= ETH_GSTRING_LEN
;
1449 snprintf(p
, ETH_GSTRING_LEN
,
1450 "veb.tc_%u_rx_packets", i
);
1451 p
+= ETH_GSTRING_LEN
;
1452 snprintf(p
, ETH_GSTRING_LEN
,
1453 "veb.tc_%u_rx_bytes", i
);
1454 p
+= ETH_GSTRING_LEN
;
1457 for (i
= 0; i
< I40E_GLOBAL_STATS_LEN
; i
++) {
1458 snprintf(p
, ETH_GSTRING_LEN
, "port.%s",
1459 i40e_gstrings_stats
[i
].stat_string
);
1460 p
+= ETH_GSTRING_LEN
;
1462 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1463 snprintf(p
, ETH_GSTRING_LEN
,
1464 "port.tx_priority_%u_xon", i
);
1465 p
+= ETH_GSTRING_LEN
;
1466 snprintf(p
, ETH_GSTRING_LEN
,
1467 "port.tx_priority_%u_xoff", i
);
1468 p
+= ETH_GSTRING_LEN
;
1470 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1471 snprintf(p
, ETH_GSTRING_LEN
,
1472 "port.rx_priority_%u_xon", i
);
1473 p
+= ETH_GSTRING_LEN
;
1474 snprintf(p
, ETH_GSTRING_LEN
,
1475 "port.rx_priority_%u_xoff", i
);
1476 p
+= ETH_GSTRING_LEN
;
1478 for (i
= 0; i
< I40E_MAX_USER_PRIORITY
; i
++) {
1479 snprintf(p
, ETH_GSTRING_LEN
,
1480 "port.rx_priority_%u_xon_2_xoff", i
);
1481 p
+= ETH_GSTRING_LEN
;
1483 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1485 case ETH_SS_PRIV_FLAGS
:
1486 for (i
= 0; i
< I40E_PRIV_FLAGS_STR_LEN
; i
++) {
1487 memcpy(data
, i40e_priv_flags_strings
[i
],
1489 data
+= ETH_GSTRING_LEN
;
1497 static int i40e_get_ts_info(struct net_device
*dev
,
1498 struct ethtool_ts_info
*info
)
1500 struct i40e_pf
*pf
= i40e_netdev_to_pf(dev
);
1502 /* only report HW timestamping if PTP is enabled */
1503 if (!(pf
->flags
& I40E_FLAG_PTP
))
1504 return ethtool_op_get_ts_info(dev
, info
);
1506 info
->so_timestamping
= SOF_TIMESTAMPING_TX_SOFTWARE
|
1507 SOF_TIMESTAMPING_RX_SOFTWARE
|
1508 SOF_TIMESTAMPING_SOFTWARE
|
1509 SOF_TIMESTAMPING_TX_HARDWARE
|
1510 SOF_TIMESTAMPING_RX_HARDWARE
|
1511 SOF_TIMESTAMPING_RAW_HARDWARE
;
1514 info
->phc_index
= ptp_clock_index(pf
->ptp_clock
);
1516 info
->phc_index
= -1;
1518 info
->tx_types
= BIT(HWTSTAMP_TX_OFF
) | BIT(HWTSTAMP_TX_ON
);
1520 info
->rx_filters
= BIT(HWTSTAMP_FILTER_NONE
) |
1521 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT
) |
1522 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT
);
1527 static int i40e_link_test(struct net_device
*netdev
, u64
*data
)
1529 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1530 struct i40e_pf
*pf
= np
->vsi
->back
;
1532 bool link_up
= false;
1534 netif_info(pf
, hw
, netdev
, "link test\n");
1535 status
= i40e_get_link_status(&pf
->hw
, &link_up
);
1537 netif_err(pf
, drv
, netdev
, "link query timed out, please retry test\n");
1550 static int i40e_reg_test(struct net_device
*netdev
, u64
*data
)
1552 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1553 struct i40e_pf
*pf
= np
->vsi
->back
;
1555 netif_info(pf
, hw
, netdev
, "register test\n");
1556 *data
= i40e_diag_reg_test(&pf
->hw
);
1561 static int i40e_eeprom_test(struct net_device
*netdev
, u64
*data
)
1563 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1564 struct i40e_pf
*pf
= np
->vsi
->back
;
1566 netif_info(pf
, hw
, netdev
, "eeprom test\n");
1567 *data
= i40e_diag_eeprom_test(&pf
->hw
);
1569 /* forcebly clear the NVM Update state machine */
1570 pf
->hw
.nvmupd_state
= I40E_NVMUPD_STATE_INIT
;
1575 static int i40e_intr_test(struct net_device
*netdev
, u64
*data
)
1577 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1578 struct i40e_pf
*pf
= np
->vsi
->back
;
1579 u16 swc_old
= pf
->sw_int_count
;
1581 netif_info(pf
, hw
, netdev
, "interrupt test\n");
1582 wr32(&pf
->hw
, I40E_PFINT_DYN_CTL0
,
1583 (I40E_PFINT_DYN_CTL0_INTENA_MASK
|
1584 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK
|
1585 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK
|
1586 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK
|
1587 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK
));
1588 usleep_range(1000, 2000);
1589 *data
= (swc_old
== pf
->sw_int_count
);
1594 static int i40e_loopback_test(struct net_device
*netdev
, u64
*data
)
1596 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1597 struct i40e_pf
*pf
= np
->vsi
->back
;
1599 netif_info(pf
, hw
, netdev
, "loopback test not implemented\n");
1605 static inline bool i40e_active_vfs(struct i40e_pf
*pf
)
1607 struct i40e_vf
*vfs
= pf
->vf
;
1610 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++)
1611 if (test_bit(I40E_VF_STAT_ACTIVE
, &vfs
[i
].vf_states
))
1616 static inline bool i40e_active_vmdqs(struct i40e_pf
*pf
)
1618 struct i40e_vsi
**vsi
= pf
->vsi
;
1621 for (i
= 0; i
< pf
->num_alloc_vsi
; i
++) {
1624 if (vsi
[i
]->type
== I40E_VSI_VMDQ2
)
1631 static void i40e_diag_test(struct net_device
*netdev
,
1632 struct ethtool_test
*eth_test
, u64
*data
)
1634 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1635 bool if_running
= netif_running(netdev
);
1636 struct i40e_pf
*pf
= np
->vsi
->back
;
1638 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
1640 netif_info(pf
, drv
, netdev
, "offline testing starting\n");
1642 set_bit(__I40E_TESTING
, &pf
->state
);
1644 if (i40e_active_vfs(pf
) || i40e_active_vmdqs(pf
)) {
1645 dev_warn(&pf
->pdev
->dev
,
1646 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1647 data
[I40E_ETH_TEST_REG
] = 1;
1648 data
[I40E_ETH_TEST_EEPROM
] = 1;
1649 data
[I40E_ETH_TEST_INTR
] = 1;
1650 data
[I40E_ETH_TEST_LOOPBACK
] = 1;
1651 data
[I40E_ETH_TEST_LINK
] = 1;
1652 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1653 clear_bit(__I40E_TESTING
, &pf
->state
);
1657 /* If the device is online then take it offline */
1659 /* indicate we're in test mode */
1662 /* This reset does not affect link - if it is
1663 * changed to a type of reset that does affect
1664 * link then the following link test would have
1665 * to be moved to before the reset
1667 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
1669 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
1670 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1672 if (i40e_eeprom_test(netdev
, &data
[I40E_ETH_TEST_EEPROM
]))
1673 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1675 if (i40e_intr_test(netdev
, &data
[I40E_ETH_TEST_INTR
]))
1676 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1678 if (i40e_loopback_test(netdev
, &data
[I40E_ETH_TEST_LOOPBACK
]))
1679 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1681 /* run reg test last, a reset is required after it */
1682 if (i40e_reg_test(netdev
, &data
[I40E_ETH_TEST_REG
]))
1683 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1685 clear_bit(__I40E_TESTING
, &pf
->state
);
1686 i40e_do_reset(pf
, BIT(__I40E_PF_RESET_REQUESTED
));
1692 netif_info(pf
, drv
, netdev
, "online testing starting\n");
1694 if (i40e_link_test(netdev
, &data
[I40E_ETH_TEST_LINK
]))
1695 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
1697 /* Offline only tests, not run in online; pass by default */
1698 data
[I40E_ETH_TEST_REG
] = 0;
1699 data
[I40E_ETH_TEST_EEPROM
] = 0;
1700 data
[I40E_ETH_TEST_INTR
] = 0;
1701 data
[I40E_ETH_TEST_LOOPBACK
] = 0;
1706 netif_info(pf
, drv
, netdev
, "testing finished\n");
1709 static void i40e_get_wol(struct net_device
*netdev
,
1710 struct ethtool_wolinfo
*wol
)
1712 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1713 struct i40e_pf
*pf
= np
->vsi
->back
;
1714 struct i40e_hw
*hw
= &pf
->hw
;
1717 /* NVM bit on means WoL disabled for the port */
1718 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
1719 if ((BIT(hw
->port
) & wol_nvm_bits
) || (hw
->partition_id
!= 1)) {
1723 wol
->supported
= WAKE_MAGIC
;
1724 wol
->wolopts
= (pf
->wol_en
? WAKE_MAGIC
: 0);
1729 * i40e_set_wol - set the WakeOnLAN configuration
1730 * @netdev: the netdev in question
1731 * @wol: the ethtool WoL setting data
1733 static int i40e_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
1735 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1736 struct i40e_pf
*pf
= np
->vsi
->back
;
1737 struct i40e_vsi
*vsi
= np
->vsi
;
1738 struct i40e_hw
*hw
= &pf
->hw
;
1741 /* WoL not supported if this isn't the controlling PF on the port */
1742 if (hw
->partition_id
!= 1) {
1743 i40e_partition_setting_complaint(pf
);
1747 if (vsi
!= pf
->vsi
[pf
->lan_vsi
])
1750 /* NVM bit on means WoL disabled for the port */
1751 i40e_read_nvm_word(hw
, I40E_SR_NVM_WAKE_ON_LAN
, &wol_nvm_bits
);
1752 if (BIT(hw
->port
) & wol_nvm_bits
)
1755 /* only magic packet is supported */
1756 if (wol
->wolopts
&& (wol
->wolopts
!= WAKE_MAGIC
))
1759 /* is this a new value? */
1760 if (pf
->wol_en
!= !!wol
->wolopts
) {
1761 pf
->wol_en
= !!wol
->wolopts
;
1762 device_set_wakeup_enable(&pf
->pdev
->dev
, pf
->wol_en
);
1768 static int i40e_set_phys_id(struct net_device
*netdev
,
1769 enum ethtool_phys_id_state state
)
1771 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1772 struct i40e_pf
*pf
= np
->vsi
->back
;
1773 struct i40e_hw
*hw
= &pf
->hw
;
1777 case ETHTOOL_ID_ACTIVE
:
1778 pf
->led_status
= i40e_led_get(hw
);
1781 i40e_led_set(hw
, 0xF, false);
1783 case ETHTOOL_ID_OFF
:
1784 i40e_led_set(hw
, 0x0, false);
1786 case ETHTOOL_ID_INACTIVE
:
1787 i40e_led_set(hw
, pf
->led_status
, false);
1796 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1797 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1798 * 125us (8000 interrupts per second) == ITR(62)
1801 static int i40e_get_coalesce(struct net_device
*netdev
,
1802 struct ethtool_coalesce
*ec
)
1804 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1805 struct i40e_vsi
*vsi
= np
->vsi
;
1807 ec
->tx_max_coalesced_frames_irq
= vsi
->work_limit
;
1808 ec
->rx_max_coalesced_frames_irq
= vsi
->work_limit
;
1810 if (ITR_IS_DYNAMIC(vsi
->rx_itr_setting
))
1811 ec
->use_adaptive_rx_coalesce
= 1;
1813 if (ITR_IS_DYNAMIC(vsi
->tx_itr_setting
))
1814 ec
->use_adaptive_tx_coalesce
= 1;
1816 ec
->rx_coalesce_usecs
= vsi
->rx_itr_setting
& ~I40E_ITR_DYNAMIC
;
1817 ec
->tx_coalesce_usecs
= vsi
->tx_itr_setting
& ~I40E_ITR_DYNAMIC
;
1822 static int i40e_set_coalesce(struct net_device
*netdev
,
1823 struct ethtool_coalesce
*ec
)
1825 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
1826 struct i40e_q_vector
*q_vector
;
1827 struct i40e_vsi
*vsi
= np
->vsi
;
1828 struct i40e_pf
*pf
= vsi
->back
;
1829 struct i40e_hw
*hw
= &pf
->hw
;
1833 if (ec
->tx_max_coalesced_frames_irq
|| ec
->rx_max_coalesced_frames_irq
)
1834 vsi
->work_limit
= ec
->tx_max_coalesced_frames_irq
;
1836 vector
= vsi
->base_vector
;
1837 if ((ec
->rx_coalesce_usecs
>= (I40E_MIN_ITR
<< 1)) &&
1838 (ec
->rx_coalesce_usecs
<= (I40E_MAX_ITR
<< 1))) {
1839 vsi
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
1840 } else if (ec
->rx_coalesce_usecs
== 0) {
1841 vsi
->rx_itr_setting
= ec
->rx_coalesce_usecs
;
1842 if (ec
->use_adaptive_rx_coalesce
)
1843 netif_info(pf
, drv
, netdev
, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
1845 netif_info(pf
, drv
, netdev
, "Invalid value, rx-usecs range is 0-8160\n");
1849 if ((ec
->tx_coalesce_usecs
>= (I40E_MIN_ITR
<< 1)) &&
1850 (ec
->tx_coalesce_usecs
<= (I40E_MAX_ITR
<< 1))) {
1851 vsi
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
1852 } else if (ec
->tx_coalesce_usecs
== 0) {
1853 vsi
->tx_itr_setting
= ec
->tx_coalesce_usecs
;
1854 if (ec
->use_adaptive_tx_coalesce
)
1855 netif_info(pf
, drv
, netdev
, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
1857 netif_info(pf
, drv
, netdev
,
1858 "Invalid value, tx-usecs range is 0-8160\n");
1862 if (ec
->use_adaptive_rx_coalesce
)
1863 vsi
->rx_itr_setting
|= I40E_ITR_DYNAMIC
;
1865 vsi
->rx_itr_setting
&= ~I40E_ITR_DYNAMIC
;
1867 if (ec
->use_adaptive_tx_coalesce
)
1868 vsi
->tx_itr_setting
|= I40E_ITR_DYNAMIC
;
1870 vsi
->tx_itr_setting
&= ~I40E_ITR_DYNAMIC
;
1872 for (i
= 0; i
< vsi
->num_q_vectors
; i
++, vector
++) {
1873 q_vector
= vsi
->q_vectors
[i
];
1874 q_vector
->rx
.itr
= ITR_TO_REG(vsi
->rx_itr_setting
);
1875 wr32(hw
, I40E_PFINT_ITRN(0, vector
- 1), q_vector
->rx
.itr
);
1876 q_vector
->tx
.itr
= ITR_TO_REG(vsi
->tx_itr_setting
);
1877 wr32(hw
, I40E_PFINT_ITRN(1, vector
- 1), q_vector
->tx
.itr
);
1885 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1886 * @pf: pointer to the physical function struct
1887 * @cmd: ethtool rxnfc command
1889 * Returns Success if the flow is supported, else Invalid Input.
1891 static int i40e_get_rss_hash_opts(struct i40e_pf
*pf
, struct ethtool_rxnfc
*cmd
)
1895 if (pf
->vsi
[pf
->lan_vsi
]->rxnfc
.data
!= 0) {
1896 cmd
->data
= pf
->vsi
[pf
->lan_vsi
]->rxnfc
.data
;
1897 cmd
->flow_type
= pf
->vsi
[pf
->lan_vsi
]->rxnfc
.flow_type
;
1900 /* Report default options for RSS on i40e */
1901 switch (cmd
->flow_type
) {
1904 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1905 /* fall through to add IP fields */
1907 case AH_ESP_V4_FLOW
:
1911 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
1915 cmd
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1916 /* fall through to add IP fields */
1918 case AH_ESP_V6_FLOW
:
1922 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
1932 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1933 * @pf: Pointer to the physical function struct
1934 * @cmd: The command to get or set Rx flow classification rules
1935 * @rule_locs: Array of used rule locations
1937 * This function populates both the total and actual rule count of
1938 * the ethtool flow classification command
1940 * Returns 0 on success or -EMSGSIZE if entry not found
1942 static int i40e_get_ethtool_fdir_all(struct i40e_pf
*pf
,
1943 struct ethtool_rxnfc
*cmd
,
1946 struct i40e_fdir_filter
*rule
;
1947 struct hlist_node
*node2
;
1950 /* report total rule count */
1951 cmd
->data
= i40e_get_fd_cnt_all(pf
);
1953 hlist_for_each_entry_safe(rule
, node2
,
1954 &pf
->fdir_filter_list
, fdir_node
) {
1955 if (cnt
== cmd
->rule_cnt
)
1958 rule_locs
[cnt
] = rule
->fd_id
;
1962 cmd
->rule_cnt
= cnt
;
1968 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1969 * @pf: Pointer to the physical function struct
1970 * @cmd: The command to get or set Rx flow classification rules
1972 * This function looks up a filter based on the Rx flow classification
1973 * command and fills the flow spec info for it if found
1975 * Returns 0 on success or -EINVAL if filter not found
1977 static int i40e_get_ethtool_fdir_entry(struct i40e_pf
*pf
,
1978 struct ethtool_rxnfc
*cmd
)
1980 struct ethtool_rx_flow_spec
*fsp
=
1981 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
1982 struct i40e_fdir_filter
*rule
= NULL
;
1983 struct hlist_node
*node2
;
1985 hlist_for_each_entry_safe(rule
, node2
,
1986 &pf
->fdir_filter_list
, fdir_node
) {
1987 if (fsp
->location
<= rule
->fd_id
)
1991 if (!rule
|| fsp
->location
!= rule
->fd_id
)
1994 fsp
->flow_type
= rule
->flow_type
;
1995 if (fsp
->flow_type
== IP_USER_FLOW
) {
1996 fsp
->h_u
.usr_ip4_spec
.ip_ver
= ETH_RX_NFC_IP4
;
1997 fsp
->h_u
.usr_ip4_spec
.proto
= 0;
1998 fsp
->m_u
.usr_ip4_spec
.proto
= 0;
2001 /* Reverse the src and dest notion, since the HW views them from
2002 * Tx perspective where as the user expects it from Rx filter view.
2004 fsp
->h_u
.tcp_ip4_spec
.psrc
= rule
->dst_port
;
2005 fsp
->h_u
.tcp_ip4_spec
.pdst
= rule
->src_port
;
2006 fsp
->h_u
.tcp_ip4_spec
.ip4src
= rule
->dst_ip
[0];
2007 fsp
->h_u
.tcp_ip4_spec
.ip4dst
= rule
->src_ip
[0];
2009 if (rule
->dest_ctl
== I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
)
2010 fsp
->ring_cookie
= RX_CLS_FLOW_DISC
;
2012 fsp
->ring_cookie
= rule
->q_index
;
2014 if (rule
->dest_vsi
!= pf
->vsi
[pf
->lan_vsi
]->id
) {
2015 struct i40e_vsi
*vsi
;
2017 vsi
= i40e_find_vsi_from_id(pf
, rule
->dest_vsi
);
2018 if (vsi
&& vsi
->type
== I40E_VSI_SRIOV
) {
2019 fsp
->h_ext
.data
[1] = htonl(vsi
->vf_id
);
2020 fsp
->m_ext
.data
[1] = htonl(0x1);
2028 * i40e_get_rxnfc - command to get RX flow classification rules
2029 * @netdev: network interface device structure
2030 * @cmd: ethtool rxnfc command
2032 * Returns Success if the command is supported.
2034 static int i40e_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
,
2037 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2038 struct i40e_vsi
*vsi
= np
->vsi
;
2039 struct i40e_pf
*pf
= vsi
->back
;
2040 int ret
= -EOPNOTSUPP
;
2043 case ETHTOOL_GRXRINGS
:
2044 cmd
->data
= vsi
->alloc_queue_pairs
;
2048 ret
= i40e_get_rss_hash_opts(pf
, cmd
);
2050 case ETHTOOL_GRXCLSRLCNT
:
2051 cmd
->rule_cnt
= pf
->fdir_pf_active_filters
;
2052 /* report total rule count */
2053 cmd
->data
= i40e_get_fd_cnt_all(pf
);
2056 case ETHTOOL_GRXCLSRULE
:
2057 ret
= i40e_get_ethtool_fdir_entry(pf
, cmd
);
2059 case ETHTOOL_GRXCLSRLALL
:
2060 ret
= i40e_get_ethtool_fdir_all(pf
, cmd
, rule_locs
);
2070 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2071 * @pf: pointer to the physical function struct
2072 * @cmd: ethtool rxnfc command
2074 * Returns Success if the flow input set is supported.
2076 static int i40e_set_rss_hash_opt(struct i40e_pf
*pf
, struct ethtool_rxnfc
*nfc
)
2078 struct i40e_hw
*hw
= &pf
->hw
;
2079 u64 hena
= (u64
)rd32(hw
, I40E_PFQF_HENA(0)) |
2080 ((u64
)rd32(hw
, I40E_PFQF_HENA(1)) << 32);
2082 /* RSS does not support anything other than hashing
2083 * to queues on src and dst IPs and ports
2085 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
2086 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
2089 /* We need at least the IP SRC and DEST fields for hashing */
2090 if (!(nfc
->data
& RXH_IP_SRC
) ||
2091 !(nfc
->data
& RXH_IP_DST
))
2094 switch (nfc
->flow_type
) {
2096 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2098 hena
&= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP
);
2100 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2101 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP
);
2108 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2110 hena
&= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP
);
2112 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2113 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP
);
2120 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2122 hena
&= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP
) |
2123 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
));
2125 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2126 hena
|= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP
) |
2127 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
));
2134 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
2136 hena
&= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP
) |
2137 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
));
2139 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
2140 hena
|= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP
) |
2141 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
));
2147 case AH_ESP_V4_FLOW
:
2151 if ((nfc
->data
& RXH_L4_B_0_1
) ||
2152 (nfc
->data
& RXH_L4_B_2_3
))
2154 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
);
2156 case AH_ESP_V6_FLOW
:
2160 if ((nfc
->data
& RXH_L4_B_0_1
) ||
2161 (nfc
->data
& RXH_L4_B_2_3
))
2163 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
);
2166 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER
) |
2167 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4
);
2170 hena
|= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER
) |
2171 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6
);
2177 wr32(hw
, I40E_PFQF_HENA(0), (u32
)hena
);
2178 wr32(hw
, I40E_PFQF_HENA(1), (u32
)(hena
>> 32));
2181 /* Save setting for future output/update */
2182 pf
->vsi
[pf
->lan_vsi
]->rxnfc
= *nfc
;
2188 * i40e_match_fdir_input_set - Match a new filter against an existing one
2189 * @rule: The filter already added
2190 * @input: The new filter to comapre against
2192 * Returns true if the two input set match
2194 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter
*rule
,
2195 struct i40e_fdir_filter
*input
)
2197 if ((rule
->dst_ip
[0] != input
->dst_ip
[0]) ||
2198 (rule
->src_ip
[0] != input
->src_ip
[0]) ||
2199 (rule
->dst_port
!= input
->dst_port
) ||
2200 (rule
->src_port
!= input
->src_port
))
2206 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2207 * @vsi: Pointer to the targeted VSI
2208 * @input: The filter to update or NULL to indicate deletion
2209 * @sw_idx: Software index to the filter
2210 * @cmd: The command to get or set Rx flow classification rules
2212 * This function updates (or deletes) a Flow Director entry from
2213 * the hlist of the corresponding PF
2215 * Returns 0 on success
2217 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi
*vsi
,
2218 struct i40e_fdir_filter
*input
,
2220 struct ethtool_rxnfc
*cmd
)
2222 struct i40e_fdir_filter
*rule
, *parent
;
2223 struct i40e_pf
*pf
= vsi
->back
;
2224 struct hlist_node
*node2
;
2230 hlist_for_each_entry_safe(rule
, node2
,
2231 &pf
->fdir_filter_list
, fdir_node
) {
2232 /* hash found, or no matching entry */
2233 if (rule
->fd_id
>= sw_idx
)
2238 /* if there is an old rule occupying our place remove it */
2239 if (rule
&& (rule
->fd_id
== sw_idx
)) {
2240 if (input
&& !i40e_match_fdir_input_set(rule
, input
))
2241 err
= i40e_add_del_fdir(vsi
, rule
, false);
2243 err
= i40e_add_del_fdir(vsi
, rule
, false);
2244 hlist_del(&rule
->fdir_node
);
2246 pf
->fdir_pf_active_filters
--;
2249 /* If no input this was a delete, err should be 0 if a rule was
2250 * successfully found and removed from the list else -EINVAL
2255 /* initialize node and set software index */
2256 INIT_HLIST_NODE(&input
->fdir_node
);
2258 /* add filter to the list */
2260 hlist_add_behind(&input
->fdir_node
, &parent
->fdir_node
);
2262 hlist_add_head(&input
->fdir_node
,
2263 &pf
->fdir_filter_list
);
2266 pf
->fdir_pf_active_filters
++;
2272 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2273 * @vsi: Pointer to the targeted VSI
2274 * @cmd: The command to get or set Rx flow classification rules
2276 * The function removes a Flow Director filter entry from the
2277 * hlist of the corresponding PF
2279 * Returns 0 on success
2281 static int i40e_del_fdir_entry(struct i40e_vsi
*vsi
,
2282 struct ethtool_rxnfc
*cmd
)
2284 struct ethtool_rx_flow_spec
*fsp
=
2285 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2286 struct i40e_pf
*pf
= vsi
->back
;
2289 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
2290 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
2293 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
2296 ret
= i40e_update_ethtool_fdir_entry(vsi
, NULL
, fsp
->location
, cmd
);
2298 i40e_fdir_check_and_reenable(pf
);
2303 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2304 * @vsi: pointer to the targeted VSI
2305 * @cmd: command to get or set RX flow classification rules
2307 * Add Flow Director filters for a specific flow spec based on their
2308 * protocol. Returns 0 if the filters were successfully added.
2310 static int i40e_add_fdir_ethtool(struct i40e_vsi
*vsi
,
2311 struct ethtool_rxnfc
*cmd
)
2313 struct ethtool_rx_flow_spec
*fsp
;
2314 struct i40e_fdir_filter
*input
;
2324 if (!(pf
->flags
& I40E_FLAG_FD_SB_ENABLED
))
2327 if (pf
->auto_disable_flags
& I40E_FLAG_FD_SB_ENABLED
)
2330 if (test_bit(__I40E_RESET_RECOVERY_PENDING
, &pf
->state
) ||
2331 test_bit(__I40E_RESET_INTR_RECEIVED
, &pf
->state
))
2334 if (test_bit(__I40E_FD_FLUSH_REQUESTED
, &pf
->state
))
2337 fsp
= (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
2339 if (fsp
->location
>= (pf
->hw
.func_caps
.fd_filters_best_effort
+
2340 pf
->hw
.func_caps
.fd_filters_guaranteed
)) {
2344 if ((fsp
->ring_cookie
!= RX_CLS_FLOW_DISC
) &&
2345 (fsp
->ring_cookie
>= vsi
->num_queue_pairs
))
2348 input
= kzalloc(sizeof(*input
), GFP_KERNEL
);
2353 input
->fd_id
= fsp
->location
;
2355 if (fsp
->ring_cookie
== RX_CLS_FLOW_DISC
)
2356 input
->dest_ctl
= I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET
;
2359 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX
;
2361 input
->q_index
= fsp
->ring_cookie
;
2362 input
->flex_off
= 0;
2364 input
->dest_vsi
= vsi
->id
;
2365 input
->fd_status
= I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID
;
2366 input
->cnt_index
= I40E_FD_SB_STAT_IDX(pf
->hw
.pf_id
);
2367 input
->flow_type
= fsp
->flow_type
;
2368 input
->ip4_proto
= fsp
->h_u
.usr_ip4_spec
.proto
;
2370 /* Reverse the src and dest notion, since the HW expects them to be from
2371 * Tx perspective where as the input from user is from Rx filter view.
2373 input
->dst_port
= fsp
->h_u
.tcp_ip4_spec
.psrc
;
2374 input
->src_port
= fsp
->h_u
.tcp_ip4_spec
.pdst
;
2375 input
->dst_ip
[0] = fsp
->h_u
.tcp_ip4_spec
.ip4src
;
2376 input
->src_ip
[0] = fsp
->h_u
.tcp_ip4_spec
.ip4dst
;
2378 if (ntohl(fsp
->m_ext
.data
[1])) {
2379 if (ntohl(fsp
->h_ext
.data
[1]) >= pf
->num_alloc_vfs
) {
2380 netif_info(pf
, drv
, vsi
->netdev
, "Invalid VF id\n");
2383 vf_id
= ntohl(fsp
->h_ext
.data
[1]);
2384 /* Find vsi id from vf id and override dest vsi */
2385 input
->dest_vsi
= pf
->vf
[vf_id
].lan_vsi_id
;
2386 if (input
->q_index
>= pf
->vf
[vf_id
].num_queue_pairs
) {
2387 netif_info(pf
, drv
, vsi
->netdev
, "Invalid queue id\n");
2392 ret
= i40e_add_del_fdir(vsi
, input
, true);
2397 i40e_update_ethtool_fdir_entry(vsi
, input
, fsp
->location
, NULL
);
2403 * i40e_set_rxnfc - command to set RX flow classification rules
2404 * @netdev: network interface device structure
2405 * @cmd: ethtool rxnfc command
2407 * Returns Success if the command is supported.
2409 static int i40e_set_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
)
2411 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2412 struct i40e_vsi
*vsi
= np
->vsi
;
2413 struct i40e_pf
*pf
= vsi
->back
;
2414 int ret
= -EOPNOTSUPP
;
2418 ret
= i40e_set_rss_hash_opt(pf
, cmd
);
2420 case ETHTOOL_SRXCLSRLINS
:
2421 ret
= i40e_add_fdir_ethtool(vsi
, cmd
);
2423 case ETHTOOL_SRXCLSRLDEL
:
2424 ret
= i40e_del_fdir_entry(vsi
, cmd
);
2434 * i40e_max_channels - get Max number of combined channels supported
2437 static unsigned int i40e_max_channels(struct i40e_vsi
*vsi
)
2439 /* TODO: This code assumes DCB and FD is disabled for now. */
2440 return vsi
->alloc_queue_pairs
;
2444 * i40e_get_channels - Get the current channels enabled and max supported etc.
2445 * @netdev: network interface device structure
2446 * @ch: ethtool channels structure
2448 * We don't support separate tx and rx queues as channels. The other count
2449 * represents how many queues are being used for control. max_combined counts
2450 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2451 * q_vectors since we support a lot more queue pairs than q_vectors.
2453 static void i40e_get_channels(struct net_device
*dev
,
2454 struct ethtool_channels
*ch
)
2456 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2457 struct i40e_vsi
*vsi
= np
->vsi
;
2458 struct i40e_pf
*pf
= vsi
->back
;
2460 /* report maximum channels */
2461 ch
->max_combined
= i40e_max_channels(vsi
);
2463 /* report info for other vector */
2464 ch
->other_count
= (pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) ? 1 : 0;
2465 ch
->max_other
= ch
->other_count
;
2467 /* Note: This code assumes DCB is disabled for now. */
2468 ch
->combined_count
= vsi
->num_queue_pairs
;
2472 * i40e_set_channels - Set the new channels count.
2473 * @netdev: network interface device structure
2474 * @ch: ethtool channels structure
2476 * The new channels count may not be the same as requested by the user
2477 * since it gets rounded down to a power of 2 value.
2479 static int i40e_set_channels(struct net_device
*dev
,
2480 struct ethtool_channels
*ch
)
2482 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2483 unsigned int count
= ch
->combined_count
;
2484 struct i40e_vsi
*vsi
= np
->vsi
;
2485 struct i40e_pf
*pf
= vsi
->back
;
2488 /* We do not support setting channels for any other VSI at present */
2489 if (vsi
->type
!= I40E_VSI_MAIN
)
2492 /* verify they are not requesting separate vectors */
2493 if (!count
|| ch
->rx_count
|| ch
->tx_count
)
2496 /* verify other_count has not changed */
2497 if (ch
->other_count
!= ((pf
->flags
& I40E_FLAG_FD_SB_ENABLED
) ? 1 : 0))
2500 /* verify the number of channels does not exceed hardware limits */
2501 if (count
> i40e_max_channels(vsi
))
2504 /* update feature limits from largest to smallest supported values */
2505 /* TODO: Flow director limit, DCB etc */
2507 /* use rss_reconfig to rebuild with new queue count and update traffic
2508 * class queue mapping
2510 new_count
= i40e_reconfig_rss_queues(pf
, count
);
2517 #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2519 * i40e_get_rxfh_key_size - get the RSS hash key size
2520 * @netdev: network interface device structure
2522 * Returns the table size.
2524 static u32
i40e_get_rxfh_key_size(struct net_device
*netdev
)
2526 return I40E_HKEY_ARRAY_SIZE
;
2530 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2531 * @netdev: network interface device structure
2533 * Returns the table size.
2535 static u32
i40e_get_rxfh_indir_size(struct net_device
*netdev
)
2537 return I40E_HLUT_ARRAY_SIZE
;
2540 static int i40e_get_rxfh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
2543 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2544 struct i40e_vsi
*vsi
= np
->vsi
;
2545 struct i40e_pf
*pf
= vsi
->back
;
2546 struct i40e_hw
*hw
= &pf
->hw
;
2551 *hfunc
= ETH_RSS_HASH_TOP
;
2556 for (i
= 0, j
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++) {
2557 reg_val
= rd32(hw
, I40E_PFQF_HLUT(i
));
2558 indir
[j
++] = reg_val
& 0xff;
2559 indir
[j
++] = (reg_val
>> 8) & 0xff;
2560 indir
[j
++] = (reg_val
>> 16) & 0xff;
2561 indir
[j
++] = (reg_val
>> 24) & 0xff;
2565 for (i
= 0, j
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++) {
2566 reg_val
= rd32(hw
, I40E_PFQF_HKEY(i
));
2567 key
[j
++] = (u8
)(reg_val
& 0xff);
2568 key
[j
++] = (u8
)((reg_val
>> 8) & 0xff);
2569 key
[j
++] = (u8
)((reg_val
>> 16) & 0xff);
2570 key
[j
++] = (u8
)((reg_val
>> 24) & 0xff);
2577 * i40e_set_rxfh - set the rx flow hash indirection table
2578 * @netdev: network interface device structure
2579 * @indir: indirection table
2582 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
2583 * returns 0 after programming the table.
2585 static int i40e_set_rxfh(struct net_device
*netdev
, const u32
*indir
,
2586 const u8
*key
, const u8 hfunc
)
2588 struct i40e_netdev_priv
*np
= netdev_priv(netdev
);
2589 struct i40e_vsi
*vsi
= np
->vsi
;
2590 struct i40e_pf
*pf
= vsi
->back
;
2591 struct i40e_hw
*hw
= &pf
->hw
;
2595 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
2601 for (i
= 0, j
= 0; i
<= I40E_PFQF_HLUT_MAX_INDEX
; i
++) {
2602 reg_val
= indir
[j
++];
2603 reg_val
|= indir
[j
++] << 8;
2604 reg_val
|= indir
[j
++] << 16;
2605 reg_val
|= indir
[j
++] << 24;
2606 wr32(hw
, I40E_PFQF_HLUT(i
), reg_val
);
2610 for (i
= 0, j
= 0; i
<= I40E_PFQF_HKEY_MAX_INDEX
; i
++) {
2612 reg_val
|= key
[j
++] << 8;
2613 reg_val
|= key
[j
++] << 16;
2614 reg_val
|= key
[j
++] << 24;
2615 wr32(hw
, I40E_PFQF_HKEY(i
), reg_val
);
2622 * i40e_get_priv_flags - report device private flags
2623 * @dev: network interface device structure
2625 * The get string set count and the string set should be matched for each
2626 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2629 * Returns a u32 bitmap of flags.
2631 static u32
i40e_get_priv_flags(struct net_device
*dev
)
2633 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2634 struct i40e_vsi
*vsi
= np
->vsi
;
2635 struct i40e_pf
*pf
= vsi
->back
;
2638 ret_flags
|= pf
->hw
.func_caps
.npar_enable
?
2639 I40E_PRIV_FLAGS_NPAR_FLAG
: 0;
2640 ret_flags
|= pf
->flags
& I40E_FLAG_LINK_POLLING_ENABLED
?
2641 I40E_PRIV_FLAGS_LINKPOLL_FLAG
: 0;
2647 * i40e_set_priv_flags - set private flags
2648 * @dev: network interface device structure
2649 * @flags: bit flags to be set
2651 static int i40e_set_priv_flags(struct net_device
*dev
, u32 flags
)
2653 struct i40e_netdev_priv
*np
= netdev_priv(dev
);
2654 struct i40e_vsi
*vsi
= np
->vsi
;
2655 struct i40e_pf
*pf
= vsi
->back
;
2657 if (flags
& I40E_PRIV_FLAGS_LINKPOLL_FLAG
)
2658 pf
->flags
|= I40E_FLAG_LINK_POLLING_ENABLED
;
2660 pf
->flags
&= ~I40E_FLAG_LINK_POLLING_ENABLED
;
2665 static const struct ethtool_ops i40e_ethtool_ops
= {
2666 .get_settings
= i40e_get_settings
,
2667 .set_settings
= i40e_set_settings
,
2668 .get_drvinfo
= i40e_get_drvinfo
,
2669 .get_regs_len
= i40e_get_regs_len
,
2670 .get_regs
= i40e_get_regs
,
2671 .nway_reset
= i40e_nway_reset
,
2672 .get_link
= ethtool_op_get_link
,
2673 .get_wol
= i40e_get_wol
,
2674 .set_wol
= i40e_set_wol
,
2675 .set_eeprom
= i40e_set_eeprom
,
2676 .get_eeprom_len
= i40e_get_eeprom_len
,
2677 .get_eeprom
= i40e_get_eeprom
,
2678 .get_ringparam
= i40e_get_ringparam
,
2679 .set_ringparam
= i40e_set_ringparam
,
2680 .get_pauseparam
= i40e_get_pauseparam
,
2681 .set_pauseparam
= i40e_set_pauseparam
,
2682 .get_msglevel
= i40e_get_msglevel
,
2683 .set_msglevel
= i40e_set_msglevel
,
2684 .get_rxnfc
= i40e_get_rxnfc
,
2685 .set_rxnfc
= i40e_set_rxnfc
,
2686 .self_test
= i40e_diag_test
,
2687 .get_strings
= i40e_get_strings
,
2688 .set_phys_id
= i40e_set_phys_id
,
2689 .get_sset_count
= i40e_get_sset_count
,
2690 .get_ethtool_stats
= i40e_get_ethtool_stats
,
2691 .get_coalesce
= i40e_get_coalesce
,
2692 .set_coalesce
= i40e_set_coalesce
,
2693 .get_rxfh_key_size
= i40e_get_rxfh_key_size
,
2694 .get_rxfh_indir_size
= i40e_get_rxfh_indir_size
,
2695 .get_rxfh
= i40e_get_rxfh
,
2696 .set_rxfh
= i40e_set_rxfh
,
2697 .get_channels
= i40e_get_channels
,
2698 .set_channels
= i40e_set_channels
,
2699 .get_ts_info
= i40e_get_ts_info
,
2700 .get_priv_flags
= i40e_get_priv_flags
,
2701 .set_priv_flags
= i40e_set_priv_flags
,
2704 void i40e_set_ethtool_ops(struct net_device
*netdev
)
2706 netdev
->ethtool_ops
= &i40e_ethtool_ops
;