Merge tag 'wireless-drivers-next-for-davem-2015-10-09' of git://git.kernel.org/pub...
[deliverable/linux.git] / drivers / net / ethernet / intel / i40e / i40e_ethtool.c
1 /*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2015 Intel Corporation.
5 *
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.
9 *
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
13 * more details.
14 *
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/>.
17 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
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
24 *
25 ******************************************************************************/
26
27 /* ethtool support for i40e */
28
29 #include "i40e.h"
30 #include "i40e_diag.h"
31
32 struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36 };
37
38 #define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42 }
43
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)
52
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),
65 };
66
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),
80 };
81
82 static const struct i40e_stats i40e_gstrings_misc_stats[] = {
83 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
87 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
89 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
90 I40E_VSI_STAT("tx_linearize", tx_linearize),
91 };
92
93 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
94 struct ethtool_rxnfc *cmd);
95
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.
102 *
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.
105 */
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),
155
156 /* LPI stats */
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),
161 };
162
163 #ifdef I40E_FCOE
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),
173 };
174
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)
183 #ifdef I40E_FCOE
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)))
189 #else
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)) \
200 / sizeof(u64))
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)) \
206 / sizeof(u64))
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)))
212
213 enum i40e_ethtool_test_id {
214 I40E_ETH_TEST_REG = 0,
215 I40E_ETH_TEST_EEPROM,
216 I40E_ETH_TEST_INTR,
217 I40E_ETH_TEST_LOOPBACK,
218 I40E_ETH_TEST_LINK,
219 };
220
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)"
227 };
228
229 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
230
231 static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
232 "NPAR",
233 "LinkPolling",
234 };
235
236 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
237
238 /**
239 * i40e_partition_setting_complaint - generic complaint for MFP restriction
240 * @pf: the PF struct
241 **/
242 static void i40e_partition_setting_complaint(struct i40e_pf *pf)
243 {
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");
246 }
247
248 /**
249 * i40e_get_settings_link_up - Get the Link settings for when link is up
250 * @hw: hw structure
251 * @ecmd: ethtool command to fill in
252 * @netdev: network interface device structure
253 *
254 **/
255 static void i40e_get_settings_link_up(struct i40e_hw *hw,
256 struct ethtool_cmd *ecmd,
257 struct net_device *netdev)
258 {
259 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
260 u32 link_speed = hw_link_info->link_speed;
261
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;
270 break;
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;
275 break;
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;
281 break;
282 case I40E_PHY_TYPE_40GBASE_SR4:
283 ecmd->supported = SUPPORTED_40000baseSR4_Full;
284 break;
285 case I40E_PHY_TYPE_40GBASE_LR4:
286 ecmd->supported = SUPPORTED_40000baseLR4_Full;
287 break;
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;
293 break;
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;
299 break;
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;
305 break;
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;
316 break;
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;
322 break;
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;
337 break;
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;
344 break;
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;
351 break;
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;
360 break;
361 default:
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);
365 }
366
367 /* Set speed and duplex */
368 switch (link_speed) {
369 case I40E_LINK_SPEED_40GB:
370 ethtool_cmd_speed_set(ecmd, SPEED_40000);
371 break;
372 case I40E_LINK_SPEED_20GB:
373 ethtool_cmd_speed_set(ecmd, SPEED_20000);
374 break;
375 case I40E_LINK_SPEED_10GB:
376 ethtool_cmd_speed_set(ecmd, SPEED_10000);
377 break;
378 case I40E_LINK_SPEED_1GB:
379 ethtool_cmd_speed_set(ecmd, SPEED_1000);
380 break;
381 case I40E_LINK_SPEED_100MB:
382 ethtool_cmd_speed_set(ecmd, SPEED_100);
383 break;
384 default:
385 break;
386 }
387 ecmd->duplex = DUPLEX_FULL;
388 }
389
390 /**
391 * i40e_get_settings_link_down - Get the Link settings for when link is down
392 * @hw: hw structure
393 * @ecmd: ethtool command to fill in
394 *
395 * Reports link settings that can be determined when link is down
396 **/
397 static void i40e_get_settings_link_down(struct i40e_hw *hw,
398 struct ethtool_cmd *ecmd)
399 {
400 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
401
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
405 */
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:
410 /* pluggable QSFP */
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;
417 break;
418 case I40E_DEV_ID_KX_B:
419 /* backplane 40G */
420 ecmd->supported = SUPPORTED_40000baseKR4_Full;
421 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
422 break;
423 case I40E_DEV_ID_KX_C:
424 /* backplane 10G */
425 ecmd->supported = SUPPORTED_10000baseKR_Full;
426 ecmd->advertising = ADVERTISED_10000baseKR_Full;
427 break;
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;
440 break;
441 case I40E_DEV_ID_20G_KR2:
442 case I40E_DEV_ID_20G_KR2_A:
443 /* backplane 20G */
444 ecmd->supported = SUPPORTED_20000baseKR2_Full;
445 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
446 break;
447 default:
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;
456 break;
457 }
458
459 /* With no link speed and duplex are unknown */
460 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
461 ecmd->duplex = DUPLEX_UNKNOWN;
462 }
463
464 /**
465 * i40e_get_settings - Get Link Speed and Duplex settings
466 * @netdev: network interface device structure
467 * @ecmd: ethtool command
468 *
469 * Reports speed/duplex settings based on media_type
470 **/
471 static int i40e_get_settings(struct net_device *netdev,
472 struct ethtool_cmd *ecmd)
473 {
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;
479
480 if (link_up)
481 i40e_get_settings_link_up(hw, ecmd, netdev);
482 else
483 i40e_get_settings_link_down(hw, ecmd);
484
485 /* Now set the settings that don't rely on link being up/down */
486
487 /* Set autoneg settings */
488 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
489 AUTONEG_ENABLE : AUTONEG_DISABLE);
490
491 switch (hw->phy.media_type) {
492 case I40E_MEDIA_TYPE_BACKPLANE:
493 ecmd->supported |= SUPPORTED_Autoneg |
494 SUPPORTED_Backplane;
495 ecmd->advertising |= ADVERTISED_Autoneg |
496 ADVERTISED_Backplane;
497 ecmd->port = PORT_NONE;
498 break;
499 case I40E_MEDIA_TYPE_BASET:
500 ecmd->supported |= SUPPORTED_TP;
501 ecmd->advertising |= ADVERTISED_TP;
502 ecmd->port = PORT_TP;
503 break;
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;
509 break;
510 case I40E_MEDIA_TYPE_FIBER:
511 ecmd->supported |= SUPPORTED_FIBRE;
512 ecmd->port = PORT_FIBRE;
513 break;
514 case I40E_MEDIA_TYPE_UNKNOWN:
515 default:
516 ecmd->port = PORT_OTHER;
517 break;
518 }
519
520 /* Set transceiver */
521 ecmd->transceiver = XCVR_EXTERNAL;
522
523 /* Set flow control settings */
524 ecmd->supported |= SUPPORTED_Pause;
525
526 switch (hw->fc.requested_mode) {
527 case I40E_FC_FULL:
528 ecmd->advertising |= ADVERTISED_Pause;
529 break;
530 case I40E_FC_TX_PAUSE:
531 ecmd->advertising |= ADVERTISED_Asym_Pause;
532 break;
533 case I40E_FC_RX_PAUSE:
534 ecmd->advertising |= (ADVERTISED_Pause |
535 ADVERTISED_Asym_Pause);
536 break;
537 default:
538 ecmd->advertising &= ~(ADVERTISED_Pause |
539 ADVERTISED_Asym_Pause);
540 break;
541 }
542
543 return 0;
544 }
545
546 /**
547 * i40e_set_settings - Set Speed and Duplex
548 * @netdev: network interface device structure
549 * @ecmd: ethtool command
550 *
551 * Set speed/duplex per media_types advertised/forced
552 **/
553 static int i40e_set_settings(struct net_device *netdev,
554 struct ethtool_cmd *ecmd)
555 {
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;
564 bool change = false;
565 int err = 0;
566 u8 autoneg;
567 u32 advertise;
568
569 /* Changing port settings is not supported if this isn't the
570 * port's controlling PF
571 */
572 if (hw->partition_id != 1) {
573 i40e_partition_setting_complaint(pf);
574 return -EOPNOTSUPP;
575 }
576
577 if (vsi != pf->vsi[pf->lan_vsi])
578 return -EOPNOTSUPP;
579
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)
584 return -EOPNOTSUPP;
585
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);
589
590 /* save autoneg and speed out of ecmd */
591 autoneg = ecmd->autoneg;
592 advertise = ecmd->advertising;
593
594 /* set autoneg and speed back to what they currently are */
595 ecmd->autoneg = safe_ecmd.autoneg;
596 ecmd->advertising = safe_ecmd.advertising;
597
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
601 */
602 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
603 return -EOPNOTSUPP;
604
605 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
606 usleep_range(1000, 2000);
607
608 /* Get the current phy config */
609 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
610 NULL);
611 if (status)
612 return -EAGAIN;
613
614 /* Copy abilities to config in case autoneg is not
615 * set below
616 */
617 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
618 config.abilities = abilities.abilities;
619
620 /* Check autoneg */
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");
625 return -EINVAL;
626 }
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;
631 change = true;
632 }
633 } else {
634 /* If autoneg is supported 10GBASE_T is the only phy that
635 * can disable it, so otherwise return error
636 */
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");
640 return -EINVAL;
641 }
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;
646 change = true;
647 }
648 }
649
650 if (advertise & ~safe_ecmd.supported)
651 return -EINVAL;
652
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;
669
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.
673 */
674 if (!config.link_speed)
675 config.link_speed = abilities.link_speed;
676
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;
683
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
692 */
693 i40e_print_link_message(vsi, false);
694 netif_carrier_off(netdev);
695 netif_tx_stop_all_queues(netdev);
696 }
697
698 /* make the aq call */
699 status = i40e_aq_set_phy_config(hw, &config, NULL);
700 if (status) {
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));
704 return -EAGAIN;
705 }
706
707 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
708 if (status)
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));
712
713 } else {
714 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
715 }
716
717 return err;
718 }
719
720 static int i40e_nway_reset(struct net_device *netdev)
721 {
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;
727 i40e_status ret = 0;
728
729 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
730 if (ret) {
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));
734 return -EIO;
735 }
736
737 return 0;
738 }
739
740 /**
741 * i40e_get_pauseparam - Get Flow Control status
742 * Return tx/rx-pause status
743 **/
744 static void i40e_get_pauseparam(struct net_device *netdev,
745 struct ethtool_pauseparam *pause)
746 {
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;
752
753 pause->autoneg =
754 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
755 AUTONEG_ENABLE : AUTONEG_DISABLE);
756
757 /* PFC enabled so report LFC as off */
758 if (dcbx_cfg->pfc.pfcenable) {
759 pause->rx_pause = 0;
760 pause->tx_pause = 0;
761 return;
762 }
763
764 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
765 pause->rx_pause = 1;
766 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
767 pause->tx_pause = 1;
768 } else if (hw->fc.current_mode == I40E_FC_FULL) {
769 pause->rx_pause = 1;
770 pause->tx_pause = 1;
771 }
772 }
773
774 /**
775 * i40e_set_pauseparam - Set Flow Control parameter
776 * @netdev: network interface device structure
777 * @pause: return tx/rx flow control status
778 **/
779 static int i40e_set_pauseparam(struct net_device *netdev,
780 struct ethtool_pauseparam *pause)
781 {
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;
789 i40e_status status;
790 u8 aq_failures;
791 int err = 0;
792
793 /* Changing the port's flow control is not supported if this isn't the
794 * port's controlling PF
795 */
796 if (hw->partition_id != 1) {
797 i40e_partition_setting_complaint(pf);
798 return -EOPNOTSUPP;
799 }
800
801 if (vsi != pf->vsi[pf->lan_vsi])
802 return -EOPNOTSUPP;
803
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");
807 return -EOPNOTSUPP;
808 }
809
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");
815 }
816
817 if (dcbx_cfg->pfc.pfcenable) {
818 netdev_info(netdev,
819 "Priority flow control enabled. Cannot set link flow control.\n");
820 return -EOPNOTSUPP;
821 }
822
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;
831 else
832 return -EINVAL;
833
834 /* Tell the OS link is going down, the link will go back up when fw
835 * says it is ready asynchronously
836 */
837 i40e_print_link_message(vsi, false);
838 netif_carrier_off(netdev);
839 netif_tx_stop_all_queues(netdev);
840
841 /* Set the fc mode and only restart an if link is up*/
842 status = i40e_set_fc(hw, &aq_failures, link_up);
843
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));
848 err = -EAGAIN;
849 }
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));
854 err = -EAGAIN;
855 }
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));
860 err = -EAGAIN;
861 }
862
863 if (!test_bit(__I40E_DOWN, &pf->state)) {
864 /* Give it a little more time to try to come back */
865 msleep(75);
866 if (!test_bit(__I40E_DOWN, &pf->state))
867 return i40e_nway_reset(netdev);
868 }
869
870 return err;
871 }
872
873 static u32 i40e_get_msglevel(struct net_device *netdev)
874 {
875 struct i40e_netdev_priv *np = netdev_priv(netdev);
876 struct i40e_pf *pf = np->vsi->back;
877
878 return pf->msg_enable;
879 }
880
881 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
882 {
883 struct i40e_netdev_priv *np = netdev_priv(netdev);
884 struct i40e_pf *pf = np->vsi->back;
885
886 if (I40E_DEBUG_USER & data)
887 pf->hw.debug_mask = data;
888 pf->msg_enable = data;
889 }
890
891 static int i40e_get_regs_len(struct net_device *netdev)
892 {
893 int reg_count = 0;
894 int i;
895
896 for (i = 0; i40e_reg_list[i].offset != 0; i++)
897 reg_count += i40e_reg_list[i].elements;
898
899 return reg_count * sizeof(u32);
900 }
901
902 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
903 void *p)
904 {
905 struct i40e_netdev_priv *np = netdev_priv(netdev);
906 struct i40e_pf *pf = np->vsi->back;
907 struct i40e_hw *hw = &pf->hw;
908 u32 *reg_buf = p;
909 int i, j, ri;
910 u32 reg;
911
912 /* Tell ethtool which driver-version-specific regs output we have.
913 *
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.
918 */
919 regs->version = 1;
920
921 /* loop through the diags reg table for what to print */
922 ri = 0;
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);
928 }
929 }
930
931 }
932
933 static int i40e_get_eeprom(struct net_device *netdev,
934 struct ethtool_eeprom *eeprom, u8 *bytes)
935 {
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;
940 u8 *eeprom_buff;
941 u16 i, sectors;
942 bool last;
943 u32 magic;
944
945 #define I40E_NVM_SECTOR_SIZE 4096
946 if (eeprom->len == 0)
947 return -EINVAL;
948
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;
953 int errno;
954
955 /* make sure it is the right magic for NVMUpdate */
956 if ((eeprom->magic >> 16) != hw->device_id)
957 return -EINVAL;
958
959 cmd = (struct i40e_nvm_access *)eeprom;
960 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
961 if (ret_val &&
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);
969
970 return errno;
971 }
972
973 /* normal ethtool get_eeprom support */
974 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
975
976 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
977 if (!eeprom_buff)
978 return -ENOMEM;
979
980 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
981 if (ret_val) {
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);
985 goto free_buff;
986 }
987
988 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
989 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
990 len = I40E_NVM_SECTOR_SIZE;
991 last = false;
992 for (i = 0; i < sectors; i++) {
993 if (i == (sectors - 1)) {
994 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
995 last = true;
996 }
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),
1000 last, NULL);
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",
1004 offset);
1005 break;
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",
1010 offset);
1011 break;
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);
1016 break;
1017 }
1018 }
1019
1020 i40e_release_nvm(hw);
1021 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
1022 free_buff:
1023 kfree(eeprom_buff);
1024 return ret_val;
1025 }
1026
1027 static int i40e_get_eeprom_len(struct net_device *netdev)
1028 {
1029 struct i40e_netdev_priv *np = netdev_priv(netdev);
1030 struct i40e_hw *hw = &np->vsi->back->hw;
1031 u32 val;
1032
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);
1038 return val;
1039 }
1040
1041 static int i40e_set_eeprom(struct net_device *netdev,
1042 struct ethtool_eeprom *eeprom, u8 *bytes)
1043 {
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;
1048 int ret_val = 0;
1049 int errno;
1050 u32 magic;
1051
1052 /* normal ethtool set_eeprom is not supported */
1053 magic = hw->vendor_id | (hw->device_id << 16);
1054 if (eeprom->magic == magic)
1055 return -EOPNOTSUPP;
1056
1057 /* check for NVMUpdate access method */
1058 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1059 return -EINVAL;
1060
1061 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1062 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1063 return -EBUSY;
1064
1065 cmd = (struct i40e_nvm_access *)eeprom;
1066 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1067 if (ret_val &&
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);
1076
1077 return errno;
1078 }
1079
1080 static void i40e_get_drvinfo(struct net_device *netdev,
1081 struct ethtool_drvinfo *drvinfo)
1082 {
1083 struct i40e_netdev_priv *np = netdev_priv(netdev);
1084 struct i40e_vsi *vsi = np->vsi;
1085 struct i40e_pf *pf = vsi->back;
1086
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;
1095 }
1096
1097 static void i40e_get_ringparam(struct net_device *netdev,
1098 struct ethtool_ringparam *ring)
1099 {
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];
1103
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;
1112 }
1113
1114 static int i40e_set_ringparam(struct net_device *netdev,
1115 struct ethtool_ringparam *ring)
1116 {
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;
1122 int i, err = 0;
1123
1124 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1125 return -EINVAL;
1126
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) {
1131 netdev_info(netdev,
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);
1135 return -EINVAL;
1136 }
1137
1138 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1139 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1140
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))
1144 return 0;
1145
1146 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1147 usleep_range(1000, 2000);
1148
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;
1154 }
1155 goto done;
1156 }
1157
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.
1161 */
1162
1163 /* alloc updated Tx resources */
1164 if (new_tx_count != vsi->tx_rings[0]->count) {
1165 netdev_info(netdev,
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);
1170 if (!tx_rings) {
1171 err = -ENOMEM;
1172 goto done;
1173 }
1174
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
1180 * setup call
1181 */
1182 tx_rings[i].desc = NULL;
1183 tx_rings[i].rx_bi = NULL;
1184 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1185 if (err) {
1186 while (i) {
1187 i--;
1188 i40e_free_tx_resources(&tx_rings[i]);
1189 }
1190 kfree(tx_rings);
1191 tx_rings = NULL;
1192
1193 goto done;
1194 }
1195 }
1196 }
1197
1198 /* alloc updated Rx resources */
1199 if (new_rx_count != vsi->rx_rings[0]->count) {
1200 netdev_info(netdev,
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);
1205 if (!rx_rings) {
1206 err = -ENOMEM;
1207 goto free_tx;
1208 }
1209
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
1215 * setup call
1216 */
1217 rx_rings[i].desc = NULL;
1218 rx_rings[i].rx_bi = NULL;
1219 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1220 if (err) {
1221 while (i) {
1222 i--;
1223 i40e_free_rx_resources(&rx_rings[i]);
1224 }
1225 kfree(rx_rings);
1226 rx_rings = NULL;
1227
1228 goto free_tx;
1229 }
1230 }
1231 }
1232
1233 /* Bring interface down, copy in the new ring info,
1234 * then restore the interface
1235 */
1236 i40e_down(vsi);
1237
1238 if (tx_rings) {
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];
1242 }
1243 kfree(tx_rings);
1244 tx_rings = NULL;
1245 }
1246
1247 if (rx_rings) {
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];
1251 }
1252 kfree(rx_rings);
1253 rx_rings = NULL;
1254 }
1255
1256 i40e_up(vsi);
1257
1258 free_tx:
1259 /* error cleanup if the Rx allocations failed after getting Tx */
1260 if (tx_rings) {
1261 for (i = 0; i < vsi->num_queue_pairs; i++)
1262 i40e_free_tx_resources(&tx_rings[i]);
1263 kfree(tx_rings);
1264 tx_rings = NULL;
1265 }
1266
1267 done:
1268 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1269
1270 return err;
1271 }
1272
1273 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1274 {
1275 struct i40e_netdev_priv *np = netdev_priv(netdev);
1276 struct i40e_vsi *vsi = np->vsi;
1277 struct i40e_pf *pf = vsi->back;
1278
1279 switch (sset) {
1280 case ETH_SS_TEST:
1281 return I40E_TEST_LEN;
1282 case ETH_SS_STATS:
1283 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
1284 int len = I40E_PF_STATS_LEN(netdev);
1285
1286 if ((pf->lan_veb != I40E_NO_VEB) &&
1287 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
1288 len += I40E_VEB_STATS_TOTAL;
1289 return len;
1290 } else {
1291 return I40E_VSI_STATS_LEN(netdev);
1292 }
1293 case ETH_SS_PRIV_FLAGS:
1294 return I40E_PRIV_FLAGS_STR_LEN;
1295 default:
1296 return -EOPNOTSUPP;
1297 }
1298 }
1299
1300 static void i40e_get_ethtool_stats(struct net_device *netdev,
1301 struct ethtool_stats *stats, u64 *data)
1302 {
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;
1307 int i = 0;
1308 char *p;
1309 int j;
1310 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1311 unsigned int start;
1312
1313 i40e_update_stats(vsi);
1314
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;
1319 }
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;
1324 }
1325 #ifdef I40E_FCOE
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;
1330 }
1331 #endif
1332 rcu_read_lock();
1333 for (j = 0; j < vsi->num_queue_pairs; j++) {
1334 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
1335
1336 if (!tx_ring)
1337 continue;
1338
1339 /* process Tx ring statistics */
1340 do {
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));
1345 i += 2;
1346
1347 /* Rx ring is the 2nd half of the queue pair */
1348 rx_ring = &tx_ring[1];
1349 do {
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));
1354 i += 2;
1355 }
1356 rcu_read_unlock();
1357 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1358 return;
1359
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];
1363
1364 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1365 p = (char *)veb;
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;
1369 }
1370 }
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;
1375 }
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];
1379 }
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];
1383 }
1384 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1385 data[i++] = pf->stats.priority_xon_2_xoff[j];
1386 }
1387
1388 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1389 u8 *data)
1390 {
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;
1395 int i;
1396
1397 switch (stringset) {
1398 case ETH_SS_TEST:
1399 for (i = 0; i < I40E_TEST_LEN; i++) {
1400 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1401 data += ETH_GSTRING_LEN;
1402 }
1403 break;
1404 case ETH_SS_STATS:
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;
1409 }
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;
1414 }
1415 #ifdef I40E_FCOE
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;
1420 }
1421 #endif
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;
1431 }
1432 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1433 return;
1434
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;
1441 }
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;
1455 }
1456 }
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;
1461 }
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;
1469 }
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;
1477 }
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;
1482 }
1483 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1484 break;
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],
1488 ETH_GSTRING_LEN);
1489 data += ETH_GSTRING_LEN;
1490 }
1491 break;
1492 default:
1493 break;
1494 }
1495 }
1496
1497 static int i40e_get_ts_info(struct net_device *dev,
1498 struct ethtool_ts_info *info)
1499 {
1500 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1501
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);
1505
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;
1512
1513 if (pf->ptp_clock)
1514 info->phc_index = ptp_clock_index(pf->ptp_clock);
1515 else
1516 info->phc_index = -1;
1517
1518 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
1519
1520 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1521 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1522 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
1523
1524 return 0;
1525 }
1526
1527 static int i40e_link_test(struct net_device *netdev, u64 *data)
1528 {
1529 struct i40e_netdev_priv *np = netdev_priv(netdev);
1530 struct i40e_pf *pf = np->vsi->back;
1531 i40e_status status;
1532 bool link_up = false;
1533
1534 netif_info(pf, hw, netdev, "link test\n");
1535 status = i40e_get_link_status(&pf->hw, &link_up);
1536 if (status) {
1537 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1538 *data = 1;
1539 return *data;
1540 }
1541
1542 if (link_up)
1543 *data = 0;
1544 else
1545 *data = 1;
1546
1547 return *data;
1548 }
1549
1550 static int i40e_reg_test(struct net_device *netdev, u64 *data)
1551 {
1552 struct i40e_netdev_priv *np = netdev_priv(netdev);
1553 struct i40e_pf *pf = np->vsi->back;
1554
1555 netif_info(pf, hw, netdev, "register test\n");
1556 *data = i40e_diag_reg_test(&pf->hw);
1557
1558 return *data;
1559 }
1560
1561 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
1562 {
1563 struct i40e_netdev_priv *np = netdev_priv(netdev);
1564 struct i40e_pf *pf = np->vsi->back;
1565
1566 netif_info(pf, hw, netdev, "eeprom test\n");
1567 *data = i40e_diag_eeprom_test(&pf->hw);
1568
1569 /* forcebly clear the NVM Update state machine */
1570 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1571
1572 return *data;
1573 }
1574
1575 static int i40e_intr_test(struct net_device *netdev, u64 *data)
1576 {
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;
1580
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);
1590
1591 return *data;
1592 }
1593
1594 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
1595 {
1596 struct i40e_netdev_priv *np = netdev_priv(netdev);
1597 struct i40e_pf *pf = np->vsi->back;
1598
1599 netif_info(pf, hw, netdev, "loopback test not implemented\n");
1600 *data = 0;
1601
1602 return *data;
1603 }
1604
1605 static inline bool i40e_active_vfs(struct i40e_pf *pf)
1606 {
1607 struct i40e_vf *vfs = pf->vf;
1608 int i;
1609
1610 for (i = 0; i < pf->num_alloc_vfs; i++)
1611 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
1612 return true;
1613 return false;
1614 }
1615
1616 static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1617 {
1618 struct i40e_vsi **vsi = pf->vsi;
1619 int i;
1620
1621 for (i = 0; i < pf->num_alloc_vsi; i++) {
1622 if (!vsi[i])
1623 continue;
1624 if (vsi[i]->type == I40E_VSI_VMDQ2)
1625 return true;
1626 }
1627
1628 return false;
1629 }
1630
1631 static void i40e_diag_test(struct net_device *netdev,
1632 struct ethtool_test *eth_test, u64 *data)
1633 {
1634 struct i40e_netdev_priv *np = netdev_priv(netdev);
1635 bool if_running = netif_running(netdev);
1636 struct i40e_pf *pf = np->vsi->back;
1637
1638 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1639 /* Offline tests */
1640 netif_info(pf, drv, netdev, "offline testing starting\n");
1641
1642 set_bit(__I40E_TESTING, &pf->state);
1643
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);
1654 goto skip_ol_tests;
1655 }
1656
1657 /* If the device is online then take it offline */
1658 if (if_running)
1659 /* indicate we're in test mode */
1660 dev_close(netdev);
1661 else
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
1666 */
1667 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1668
1669 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1670 eth_test->flags |= ETH_TEST_FL_FAILED;
1671
1672 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
1673 eth_test->flags |= ETH_TEST_FL_FAILED;
1674
1675 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
1676 eth_test->flags |= ETH_TEST_FL_FAILED;
1677
1678 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
1679 eth_test->flags |= ETH_TEST_FL_FAILED;
1680
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;
1684
1685 clear_bit(__I40E_TESTING, &pf->state);
1686 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1687
1688 if (if_running)
1689 dev_open(netdev);
1690 } else {
1691 /* Online tests */
1692 netif_info(pf, drv, netdev, "online testing starting\n");
1693
1694 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1695 eth_test->flags |= ETH_TEST_FL_FAILED;
1696
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;
1702 }
1703
1704 skip_ol_tests:
1705
1706 netif_info(pf, drv, netdev, "testing finished\n");
1707 }
1708
1709 static void i40e_get_wol(struct net_device *netdev,
1710 struct ethtool_wolinfo *wol)
1711 {
1712 struct i40e_netdev_priv *np = netdev_priv(netdev);
1713 struct i40e_pf *pf = np->vsi->back;
1714 struct i40e_hw *hw = &pf->hw;
1715 u16 wol_nvm_bits;
1716
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)) {
1720 wol->supported = 0;
1721 wol->wolopts = 0;
1722 } else {
1723 wol->supported = WAKE_MAGIC;
1724 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1725 }
1726 }
1727
1728 /**
1729 * i40e_set_wol - set the WakeOnLAN configuration
1730 * @netdev: the netdev in question
1731 * @wol: the ethtool WoL setting data
1732 **/
1733 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1734 {
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;
1739 u16 wol_nvm_bits;
1740
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);
1744 return -EOPNOTSUPP;
1745 }
1746
1747 if (vsi != pf->vsi[pf->lan_vsi])
1748 return -EOPNOTSUPP;
1749
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)
1753 return -EOPNOTSUPP;
1754
1755 /* only magic packet is supported */
1756 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1757 return -EOPNOTSUPP;
1758
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);
1763 }
1764
1765 return 0;
1766 }
1767
1768 static int i40e_set_phys_id(struct net_device *netdev,
1769 enum ethtool_phys_id_state state)
1770 {
1771 struct i40e_netdev_priv *np = netdev_priv(netdev);
1772 struct i40e_pf *pf = np->vsi->back;
1773 struct i40e_hw *hw = &pf->hw;
1774 int blink_freq = 2;
1775
1776 switch (state) {
1777 case ETHTOOL_ID_ACTIVE:
1778 pf->led_status = i40e_led_get(hw);
1779 return blink_freq;
1780 case ETHTOOL_ID_ON:
1781 i40e_led_set(hw, 0xF, false);
1782 break;
1783 case ETHTOOL_ID_OFF:
1784 i40e_led_set(hw, 0x0, false);
1785 break;
1786 case ETHTOOL_ID_INACTIVE:
1787 i40e_led_set(hw, pf->led_status, false);
1788 break;
1789 default:
1790 break;
1791 }
1792
1793 return 0;
1794 }
1795
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)
1799 */
1800
1801 static int i40e_get_coalesce(struct net_device *netdev,
1802 struct ethtool_coalesce *ec)
1803 {
1804 struct i40e_netdev_priv *np = netdev_priv(netdev);
1805 struct i40e_vsi *vsi = np->vsi;
1806
1807 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1808 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1809
1810 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1811 ec->use_adaptive_rx_coalesce = 1;
1812
1813 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1814 ec->use_adaptive_tx_coalesce = 1;
1815
1816 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1817 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1818
1819 return 0;
1820 }
1821
1822 static int i40e_set_coalesce(struct net_device *netdev,
1823 struct ethtool_coalesce *ec)
1824 {
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;
1830 u16 vector;
1831 int i;
1832
1833 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1834 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1835
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");
1844 } else {
1845 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
1846 return -EINVAL;
1847 }
1848
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");
1856 } else {
1857 netif_info(pf, drv, netdev,
1858 "Invalid value, tx-usecs range is 0-8160\n");
1859 return -EINVAL;
1860 }
1861
1862 if (ec->use_adaptive_rx_coalesce)
1863 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1864 else
1865 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1866
1867 if (ec->use_adaptive_tx_coalesce)
1868 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1869 else
1870 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1871
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);
1878 i40e_flush(hw);
1879 }
1880
1881 return 0;
1882 }
1883
1884 /**
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
1888 *
1889 * Returns Success if the flow is supported, else Invalid Input.
1890 **/
1891 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1892 {
1893 cmd->data = 0;
1894
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;
1898 return 0;
1899 }
1900 /* Report default options for RSS on i40e */
1901 switch (cmd->flow_type) {
1902 case TCP_V4_FLOW:
1903 case UDP_V4_FLOW:
1904 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1905 /* fall through to add IP fields */
1906 case SCTP_V4_FLOW:
1907 case AH_ESP_V4_FLOW:
1908 case AH_V4_FLOW:
1909 case ESP_V4_FLOW:
1910 case IPV4_FLOW:
1911 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1912 break;
1913 case TCP_V6_FLOW:
1914 case UDP_V6_FLOW:
1915 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1916 /* fall through to add IP fields */
1917 case SCTP_V6_FLOW:
1918 case AH_ESP_V6_FLOW:
1919 case AH_V6_FLOW:
1920 case ESP_V6_FLOW:
1921 case IPV6_FLOW:
1922 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1923 break;
1924 default:
1925 return -EINVAL;
1926 }
1927
1928 return 0;
1929 }
1930
1931 /**
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
1936 *
1937 * This function populates both the total and actual rule count of
1938 * the ethtool flow classification command
1939 *
1940 * Returns 0 on success or -EMSGSIZE if entry not found
1941 **/
1942 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1943 struct ethtool_rxnfc *cmd,
1944 u32 *rule_locs)
1945 {
1946 struct i40e_fdir_filter *rule;
1947 struct hlist_node *node2;
1948 int cnt = 0;
1949
1950 /* report total rule count */
1951 cmd->data = i40e_get_fd_cnt_all(pf);
1952
1953 hlist_for_each_entry_safe(rule, node2,
1954 &pf->fdir_filter_list, fdir_node) {
1955 if (cnt == cmd->rule_cnt)
1956 return -EMSGSIZE;
1957
1958 rule_locs[cnt] = rule->fd_id;
1959 cnt++;
1960 }
1961
1962 cmd->rule_cnt = cnt;
1963
1964 return 0;
1965 }
1966
1967 /**
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
1971 *
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
1974 *
1975 * Returns 0 on success or -EINVAL if filter not found
1976 **/
1977 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1978 struct ethtool_rxnfc *cmd)
1979 {
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;
1984
1985 hlist_for_each_entry_safe(rule, node2,
1986 &pf->fdir_filter_list, fdir_node) {
1987 if (fsp->location <= rule->fd_id)
1988 break;
1989 }
1990
1991 if (!rule || fsp->location != rule->fd_id)
1992 return -EINVAL;
1993
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;
1999 }
2000
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.
2003 */
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];
2008
2009 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2010 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2011 else
2012 fsp->ring_cookie = rule->q_index;
2013
2014 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2015 struct i40e_vsi *vsi;
2016
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);
2021 }
2022 }
2023
2024 return 0;
2025 }
2026
2027 /**
2028 * i40e_get_rxnfc - command to get RX flow classification rules
2029 * @netdev: network interface device structure
2030 * @cmd: ethtool rxnfc command
2031 *
2032 * Returns Success if the command is supported.
2033 **/
2034 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2035 u32 *rule_locs)
2036 {
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;
2041
2042 switch (cmd->cmd) {
2043 case ETHTOOL_GRXRINGS:
2044 cmd->data = vsi->alloc_queue_pairs;
2045 ret = 0;
2046 break;
2047 case ETHTOOL_GRXFH:
2048 ret = i40e_get_rss_hash_opts(pf, cmd);
2049 break;
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);
2054 ret = 0;
2055 break;
2056 case ETHTOOL_GRXCLSRULE:
2057 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
2058 break;
2059 case ETHTOOL_GRXCLSRLALL:
2060 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2061 break;
2062 default:
2063 break;
2064 }
2065
2066 return ret;
2067 }
2068
2069 /**
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
2073 *
2074 * Returns Success if the flow input set is supported.
2075 **/
2076 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2077 {
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);
2081
2082 /* RSS does not support anything other than hashing
2083 * to queues on src and dst IPs and ports
2084 */
2085 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2086 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2087 return -EINVAL;
2088
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))
2092 return -EINVAL;
2093
2094 switch (nfc->flow_type) {
2095 case TCP_V4_FLOW:
2096 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2097 case 0:
2098 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2099 break;
2100 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2101 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2102 break;
2103 default:
2104 return -EINVAL;
2105 }
2106 break;
2107 case TCP_V6_FLOW:
2108 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2109 case 0:
2110 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2111 break;
2112 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2113 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2114 break;
2115 default:
2116 return -EINVAL;
2117 }
2118 break;
2119 case UDP_V4_FLOW:
2120 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2121 case 0:
2122 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2123 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2124 break;
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));
2128 break;
2129 default:
2130 return -EINVAL;
2131 }
2132 break;
2133 case UDP_V6_FLOW:
2134 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2135 case 0:
2136 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2137 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2138 break;
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));
2142 break;
2143 default:
2144 return -EINVAL;
2145 }
2146 break;
2147 case AH_ESP_V4_FLOW:
2148 case AH_V4_FLOW:
2149 case ESP_V4_FLOW:
2150 case SCTP_V4_FLOW:
2151 if ((nfc->data & RXH_L4_B_0_1) ||
2152 (nfc->data & RXH_L4_B_2_3))
2153 return -EINVAL;
2154 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2155 break;
2156 case AH_ESP_V6_FLOW:
2157 case AH_V6_FLOW:
2158 case ESP_V6_FLOW:
2159 case SCTP_V6_FLOW:
2160 if ((nfc->data & RXH_L4_B_0_1) ||
2161 (nfc->data & RXH_L4_B_2_3))
2162 return -EINVAL;
2163 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2164 break;
2165 case IPV4_FLOW:
2166 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2167 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
2168 break;
2169 case IPV6_FLOW:
2170 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2171 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
2172 break;
2173 default:
2174 return -EINVAL;
2175 }
2176
2177 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2178 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2179 i40e_flush(hw);
2180
2181 /* Save setting for future output/update */
2182 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2183
2184 return 0;
2185 }
2186
2187 /**
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
2191 *
2192 * Returns true if the two input set match
2193 **/
2194 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2195 struct i40e_fdir_filter *input)
2196 {
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))
2201 return false;
2202 return true;
2203 }
2204
2205 /**
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
2211 *
2212 * This function updates (or deletes) a Flow Director entry from
2213 * the hlist of the corresponding PF
2214 *
2215 * Returns 0 on success
2216 **/
2217 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2218 struct i40e_fdir_filter *input,
2219 u16 sw_idx,
2220 struct ethtool_rxnfc *cmd)
2221 {
2222 struct i40e_fdir_filter *rule, *parent;
2223 struct i40e_pf *pf = vsi->back;
2224 struct hlist_node *node2;
2225 int err = -EINVAL;
2226
2227 parent = NULL;
2228 rule = NULL;
2229
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)
2234 break;
2235 parent = rule;
2236 }
2237
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);
2242 else if (!input)
2243 err = i40e_add_del_fdir(vsi, rule, false);
2244 hlist_del(&rule->fdir_node);
2245 kfree(rule);
2246 pf->fdir_pf_active_filters--;
2247 }
2248
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
2251 */
2252 if (!input)
2253 return err;
2254
2255 /* initialize node and set software index */
2256 INIT_HLIST_NODE(&input->fdir_node);
2257
2258 /* add filter to the list */
2259 if (parent)
2260 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
2261 else
2262 hlist_add_head(&input->fdir_node,
2263 &pf->fdir_filter_list);
2264
2265 /* update counts */
2266 pf->fdir_pf_active_filters++;
2267
2268 return 0;
2269 }
2270
2271 /**
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
2275 *
2276 * The function removes a Flow Director filter entry from the
2277 * hlist of the corresponding PF
2278 *
2279 * Returns 0 on success
2280 */
2281 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2282 struct ethtool_rxnfc *cmd)
2283 {
2284 struct ethtool_rx_flow_spec *fsp =
2285 (struct ethtool_rx_flow_spec *)&cmd->fs;
2286 struct i40e_pf *pf = vsi->back;
2287 int ret = 0;
2288
2289 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2290 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2291 return -EBUSY;
2292
2293 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2294 return -EBUSY;
2295
2296 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
2297
2298 i40e_fdir_check_and_reenable(pf);
2299 return ret;
2300 }
2301
2302 /**
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
2306 *
2307 * Add Flow Director filters for a specific flow spec based on their
2308 * protocol. Returns 0 if the filters were successfully added.
2309 **/
2310 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2311 struct ethtool_rxnfc *cmd)
2312 {
2313 struct ethtool_rx_flow_spec *fsp;
2314 struct i40e_fdir_filter *input;
2315 struct i40e_pf *pf;
2316 int ret = -EINVAL;
2317 u16 vf_id;
2318
2319 if (!vsi)
2320 return -EINVAL;
2321
2322 pf = vsi->back;
2323
2324 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2325 return -EOPNOTSUPP;
2326
2327 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
2328 return -ENOSPC;
2329
2330 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2331 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2332 return -EBUSY;
2333
2334 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2335 return -EBUSY;
2336
2337 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2338
2339 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2340 pf->hw.func_caps.fd_filters_guaranteed)) {
2341 return -EINVAL;
2342 }
2343
2344 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2345 (fsp->ring_cookie >= vsi->num_queue_pairs))
2346 return -EINVAL;
2347
2348 input = kzalloc(sizeof(*input), GFP_KERNEL);
2349
2350 if (!input)
2351 return -ENOMEM;
2352
2353 input->fd_id = fsp->location;
2354
2355 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2356 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2357 else
2358 input->dest_ctl =
2359 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2360
2361 input->q_index = fsp->ring_cookie;
2362 input->flex_off = 0;
2363 input->pctype = 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;
2369
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.
2372 */
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;
2377
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");
2381 goto free_input;
2382 }
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");
2388 goto free_input;
2389 }
2390 }
2391
2392 ret = i40e_add_del_fdir(vsi, input, true);
2393 free_input:
2394 if (ret)
2395 kfree(input);
2396 else
2397 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2398
2399 return ret;
2400 }
2401
2402 /**
2403 * i40e_set_rxnfc - command to set RX flow classification rules
2404 * @netdev: network interface device structure
2405 * @cmd: ethtool rxnfc command
2406 *
2407 * Returns Success if the command is supported.
2408 **/
2409 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2410 {
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;
2415
2416 switch (cmd->cmd) {
2417 case ETHTOOL_SRXFH:
2418 ret = i40e_set_rss_hash_opt(pf, cmd);
2419 break;
2420 case ETHTOOL_SRXCLSRLINS:
2421 ret = i40e_add_fdir_ethtool(vsi, cmd);
2422 break;
2423 case ETHTOOL_SRXCLSRLDEL:
2424 ret = i40e_del_fdir_entry(vsi, cmd);
2425 break;
2426 default:
2427 break;
2428 }
2429
2430 return ret;
2431 }
2432
2433 /**
2434 * i40e_max_channels - get Max number of combined channels supported
2435 * @vsi: vsi pointer
2436 **/
2437 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2438 {
2439 /* TODO: This code assumes DCB and FD is disabled for now. */
2440 return vsi->alloc_queue_pairs;
2441 }
2442
2443 /**
2444 * i40e_get_channels - Get the current channels enabled and max supported etc.
2445 * @netdev: network interface device structure
2446 * @ch: ethtool channels structure
2447 *
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.
2452 **/
2453 static void i40e_get_channels(struct net_device *dev,
2454 struct ethtool_channels *ch)
2455 {
2456 struct i40e_netdev_priv *np = netdev_priv(dev);
2457 struct i40e_vsi *vsi = np->vsi;
2458 struct i40e_pf *pf = vsi->back;
2459
2460 /* report maximum channels */
2461 ch->max_combined = i40e_max_channels(vsi);
2462
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;
2466
2467 /* Note: This code assumes DCB is disabled for now. */
2468 ch->combined_count = vsi->num_queue_pairs;
2469 }
2470
2471 /**
2472 * i40e_set_channels - Set the new channels count.
2473 * @netdev: network interface device structure
2474 * @ch: ethtool channels structure
2475 *
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.
2478 **/
2479 static int i40e_set_channels(struct net_device *dev,
2480 struct ethtool_channels *ch)
2481 {
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;
2486 int new_count;
2487
2488 /* We do not support setting channels for any other VSI at present */
2489 if (vsi->type != I40E_VSI_MAIN)
2490 return -EINVAL;
2491
2492 /* verify they are not requesting separate vectors */
2493 if (!count || ch->rx_count || ch->tx_count)
2494 return -EINVAL;
2495
2496 /* verify other_count has not changed */
2497 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
2498 return -EINVAL;
2499
2500 /* verify the number of channels does not exceed hardware limits */
2501 if (count > i40e_max_channels(vsi))
2502 return -EINVAL;
2503
2504 /* update feature limits from largest to smallest supported values */
2505 /* TODO: Flow director limit, DCB etc */
2506
2507 /* use rss_reconfig to rebuild with new queue count and update traffic
2508 * class queue mapping
2509 */
2510 new_count = i40e_reconfig_rss_queues(pf, count);
2511 if (new_count > 0)
2512 return 0;
2513 else
2514 return -EINVAL;
2515 }
2516
2517 #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2518 /**
2519 * i40e_get_rxfh_key_size - get the RSS hash key size
2520 * @netdev: network interface device structure
2521 *
2522 * Returns the table size.
2523 **/
2524 static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2525 {
2526 return I40E_HKEY_ARRAY_SIZE;
2527 }
2528
2529 /**
2530 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2531 * @netdev: network interface device structure
2532 *
2533 * Returns the table size.
2534 **/
2535 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2536 {
2537 return I40E_HLUT_ARRAY_SIZE;
2538 }
2539
2540 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2541 u8 *hfunc)
2542 {
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;
2547 u32 reg_val;
2548 int i, j;
2549
2550 if (hfunc)
2551 *hfunc = ETH_RSS_HASH_TOP;
2552
2553 if (!indir)
2554 return 0;
2555
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;
2562 }
2563
2564 if (key) {
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);
2571 }
2572 }
2573 return 0;
2574 }
2575
2576 /**
2577 * i40e_set_rxfh - set the rx flow hash indirection table
2578 * @netdev: network interface device structure
2579 * @indir: indirection table
2580 * @key: hash key
2581 *
2582 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
2583 * returns 0 after programming the table.
2584 **/
2585 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2586 const u8 *key, const u8 hfunc)
2587 {
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;
2592 u32 reg_val;
2593 int i, j;
2594
2595 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2596 return -EOPNOTSUPP;
2597
2598 if (!indir)
2599 return 0;
2600
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);
2607 }
2608
2609 if (key) {
2610 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2611 reg_val = key[j++];
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);
2616 }
2617 }
2618 return 0;
2619 }
2620
2621 /**
2622 * i40e_get_priv_flags - report device private flags
2623 * @dev: network interface device structure
2624 *
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
2627 * array.
2628 *
2629 * Returns a u32 bitmap of flags.
2630 **/
2631 static u32 i40e_get_priv_flags(struct net_device *dev)
2632 {
2633 struct i40e_netdev_priv *np = netdev_priv(dev);
2634 struct i40e_vsi *vsi = np->vsi;
2635 struct i40e_pf *pf = vsi->back;
2636 u32 ret_flags = 0;
2637
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;
2642
2643 return ret_flags;
2644 }
2645
2646 /**
2647 * i40e_set_priv_flags - set private flags
2648 * @dev: network interface device structure
2649 * @flags: bit flags to be set
2650 **/
2651 static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2652 {
2653 struct i40e_netdev_priv *np = netdev_priv(dev);
2654 struct i40e_vsi *vsi = np->vsi;
2655 struct i40e_pf *pf = vsi->back;
2656
2657 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2658 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2659 else
2660 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2661
2662 return 0;
2663 }
2664
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,
2702 };
2703
2704 void i40e_set_ethtool_ops(struct net_device *netdev)
2705 {
2706 netdev->ethtool_ops = &i40e_ethtool_ops;
2707 }
This page took 0.088108 seconds and 6 git commands to generate.