i40e: Add dual speed module support
[deliverable/linux.git] / drivers / net / ethernet / intel / i40e / i40e_ethtool.c
CommitLineData
c7d05ca8
JB
1/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
dc641b73 4 * Copyright(c) 2013 - 2014 Intel Corporation.
c7d05ca8
JB
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 *
dc641b73
GR
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/>.
c7d05ca8
JB
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
32struct 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#define I40E_NETDEV_STAT(_net_stat) \
44 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
45#define I40E_PF_STAT(_name, _stat) \
46 I40E_STAT(struct i40e_pf, _name, _stat)
47#define I40E_VSI_STAT(_name, _stat) \
48 I40E_STAT(struct i40e_vsi, _name, _stat)
8eab9cfd
SN
49#define I40E_VEB_STAT(_name, _stat) \
50 I40E_STAT(struct i40e_veb, _name, _stat)
c7d05ca8
JB
51
52static const struct i40e_stats i40e_gstrings_net_stats[] = {
53 I40E_NETDEV_STAT(rx_packets),
54 I40E_NETDEV_STAT(tx_packets),
55 I40E_NETDEV_STAT(rx_bytes),
56 I40E_NETDEV_STAT(tx_bytes),
57 I40E_NETDEV_STAT(rx_errors),
58 I40E_NETDEV_STAT(tx_errors),
59 I40E_NETDEV_STAT(rx_dropped),
60 I40E_NETDEV_STAT(tx_dropped),
c7d05ca8
JB
61 I40E_NETDEV_STAT(collisions),
62 I40E_NETDEV_STAT(rx_length_errors),
63 I40E_NETDEV_STAT(rx_crc_errors),
64};
65
8eab9cfd
SN
66static const struct i40e_stats i40e_gstrings_veb_stats[] = {
67 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
68 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
69 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
70 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
71 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
72 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
73 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
74 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
75 I40E_VEB_STAT("rx_discards", stats.rx_discards),
76 I40E_VEB_STAT("tx_discards", stats.tx_discards),
77 I40E_VEB_STAT("tx_errors", stats.tx_errors),
78 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
79};
80
41a9e55c 81static const struct i40e_stats i40e_gstrings_misc_stats[] = {
418631d4
SN
82 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
83 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
84 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
85 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
41a9e55c
SN
86 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
87 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
418631d4 88 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
41a9e55c
SN
89};
90
1eaa3840
ASJ
91static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
92 struct ethtool_rxnfc *cmd);
17a73f6b 93
c7d05ca8
JB
94/* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
100 *
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
103 */
104static struct i40e_stats i40e_gstrings_stats[] = {
105 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
106 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
532d283d
SN
107 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
108 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
109 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
110 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
111 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
112 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
c7d05ca8
JB
113 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
114 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
115 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
a47a15f4 121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
8a3c91cc 122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
c7d05ca8
JB
123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
beb0dff1 147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
60793f4a 148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
433c47de
ASJ
149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
151
bee5af7e
ASJ
152 /* LPI stats */
153 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
154 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
155 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
156 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
c7d05ca8
JB
157};
158
38e00438
VD
159#ifdef I40E_FCOE
160static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
161 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
162 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
163 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
164 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
165 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
166 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
167 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
168 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
169};
170
171#endif /* I40E_FCOE */
c7d05ca8 172#define I40E_QUEUE_STATS_LEN(n) \
31cd840e
SN
173 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
174 * 2 /* Tx and Rx together */ \
175 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
c7d05ca8
JB
176#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
177#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
41a9e55c 178#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
38e00438
VD
179#ifdef I40E_FCOE
180#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
181#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
182 I40E_FCOE_STATS_LEN + \
183 I40E_MISC_STATS_LEN + \
184 I40E_QUEUE_STATS_LEN((n)))
185#else
c7d05ca8 186#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
41a9e55c 187 I40E_MISC_STATS_LEN + \
c7d05ca8 188 I40E_QUEUE_STATS_LEN((n)))
38e00438 189#endif /* I40E_FCOE */
c7d05ca8
JB
190#define I40E_PFC_STATS_LEN ( \
191 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
192 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
196 / sizeof(u64))
8eab9cfd 197#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
c7d05ca8
JB
198#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
199 I40E_PFC_STATS_LEN + \
200 I40E_VSI_STATS_LEN((n)))
201
202enum i40e_ethtool_test_id {
203 I40E_ETH_TEST_REG = 0,
204 I40E_ETH_TEST_EEPROM,
205 I40E_ETH_TEST_INTR,
206 I40E_ETH_TEST_LOOPBACK,
207 I40E_ETH_TEST_LINK,
208};
209
210static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
211 "Register test (offline)",
212 "Eeprom test (offline)",
213 "Interrupt test (offline)",
214 "Loopback test (offline)",
215 "Link test (on/offline)"
216};
217
218#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
219
220/**
221 * i40e_get_settings - Get Link Speed and Duplex settings
222 * @netdev: network interface device structure
223 * @ecmd: ethtool command
224 *
225 * Reports speed/duplex settings based on media_type
226 **/
227static int i40e_get_settings(struct net_device *netdev,
228 struct ethtool_cmd *ecmd)
229{
230 struct i40e_netdev_priv *np = netdev_priv(netdev);
231 struct i40e_pf *pf = np->vsi->back;
232 struct i40e_hw *hw = &pf->hw;
233 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
234 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
235 u32 link_speed = hw_link_info->link_speed;
236
237 /* hardware is either in 40G mode or 10G mode
238 * NOTE: this section initializes supported and advertising
239 */
4e91bcd5
JB
240 if (!link_up) {
241 /* link is down and the driver needs to fall back on
242 * device ID to determine what kinds of info to display,
243 * it's mostly a guess that may change when link is up
244 */
245 switch (hw->device_id) {
246 case I40E_DEV_ID_QSFP_A:
247 case I40E_DEV_ID_QSFP_B:
248 case I40E_DEV_ID_QSFP_C:
249 /* pluggable QSFP */
250 ecmd->supported = SUPPORTED_40000baseSR4_Full |
251 SUPPORTED_40000baseCR4_Full |
252 SUPPORTED_40000baseLR4_Full;
253 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
254 ADVERTISED_40000baseCR4_Full |
255 ADVERTISED_40000baseLR4_Full;
256 break;
257 case I40E_DEV_ID_KX_B:
258 /* backplane 40G */
259 ecmd->supported = SUPPORTED_40000baseKR4_Full;
260 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
261 break;
262 case I40E_DEV_ID_KX_C:
263 /* backplane 10G */
264 ecmd->supported = SUPPORTED_10000baseKR_Full;
265 ecmd->advertising = ADVERTISED_10000baseKR_Full;
266 break;
267 default:
268 /* all the rest are 10G/1G */
269 ecmd->supported = SUPPORTED_10000baseT_Full |
270 SUPPORTED_1000baseT_Full;
271 ecmd->advertising = ADVERTISED_10000baseT_Full |
272 ADVERTISED_1000baseT_Full;
273 break;
274 }
275
276 /* skip phy_type use as it is zero when link is down */
277 goto no_valid_phy_type;
278 }
279
c7d05ca8
JB
280 switch (hw_link_info->phy_type) {
281 case I40E_PHY_TYPE_40GBASE_CR4:
282 case I40E_PHY_TYPE_40GBASE_CR4_CU:
4e91bcd5
JB
283 ecmd->supported = SUPPORTED_Autoneg |
284 SUPPORTED_40000baseCR4_Full;
285 ecmd->advertising = ADVERTISED_Autoneg |
286 ADVERTISED_40000baseCR4_Full;
c7d05ca8
JB
287 break;
288 case I40E_PHY_TYPE_40GBASE_KR4:
4e91bcd5
JB
289 ecmd->supported = SUPPORTED_Autoneg |
290 SUPPORTED_40000baseKR4_Full;
291 ecmd->advertising = ADVERTISED_Autoneg |
292 ADVERTISED_40000baseKR4_Full;
c7d05ca8
JB
293 break;
294 case I40E_PHY_TYPE_40GBASE_SR4:
4e91bcd5
JB
295 case I40E_PHY_TYPE_XLPPI:
296 case I40E_PHY_TYPE_XLAUI:
c7d05ca8 297 ecmd->supported = SUPPORTED_40000baseSR4_Full;
c7d05ca8
JB
298 break;
299 case I40E_PHY_TYPE_40GBASE_LR4:
300 ecmd->supported = SUPPORTED_40000baseLR4_Full;
c7d05ca8
JB
301 break;
302 case I40E_PHY_TYPE_10GBASE_KX4:
4e91bcd5
JB
303 ecmd->supported = SUPPORTED_Autoneg |
304 SUPPORTED_10000baseKX4_Full;
305 ecmd->advertising = ADVERTISED_Autoneg |
306 ADVERTISED_10000baseKX4_Full;
c7d05ca8
JB
307 break;
308 case I40E_PHY_TYPE_10GBASE_KR:
4e91bcd5
JB
309 ecmd->supported = SUPPORTED_Autoneg |
310 SUPPORTED_10000baseKR_Full;
311 ecmd->advertising = ADVERTISED_Autoneg |
312 ADVERTISED_10000baseKR_Full;
c7d05ca8 313 break;
4e91bcd5
JB
314 case I40E_PHY_TYPE_10GBASE_SR:
315 case I40E_PHY_TYPE_10GBASE_LR:
124ed15b
CS
316 case I40E_PHY_TYPE_1000BASE_SX:
317 case I40E_PHY_TYPE_1000BASE_LX:
4e91bcd5 318 ecmd->supported = SUPPORTED_10000baseT_Full;
124ed15b 319 ecmd->supported |= SUPPORTED_1000baseT_Full;
4e91bcd5
JB
320 break;
321 case I40E_PHY_TYPE_10GBASE_CR1_CU:
322 case I40E_PHY_TYPE_10GBASE_CR1:
323 case I40E_PHY_TYPE_10GBASE_T:
324 ecmd->supported = SUPPORTED_Autoneg |
325 SUPPORTED_10000baseT_Full;
326 ecmd->advertising = ADVERTISED_Autoneg |
327 ADVERTISED_10000baseT_Full;
328 break;
329 case I40E_PHY_TYPE_XAUI:
330 case I40E_PHY_TYPE_XFI:
331 case I40E_PHY_TYPE_SFI:
332 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
333 ecmd->supported = SUPPORTED_10000baseT_Full;
334 break;
335 case I40E_PHY_TYPE_1000BASE_KX:
336 case I40E_PHY_TYPE_1000BASE_T:
337 ecmd->supported = SUPPORTED_Autoneg |
338 SUPPORTED_1000baseT_Full;
339 ecmd->advertising = ADVERTISED_Autoneg |
340 ADVERTISED_1000baseT_Full;
c7d05ca8 341 break;
4e91bcd5
JB
342 case I40E_PHY_TYPE_100BASE_TX:
343 ecmd->supported = SUPPORTED_Autoneg |
344 SUPPORTED_100baseT_Full;
345 ecmd->advertising = ADVERTISED_Autoneg |
346 ADVERTISED_100baseT_Full;
347 break;
348 case I40E_PHY_TYPE_SGMII:
349 ecmd->supported = SUPPORTED_Autoneg |
350 SUPPORTED_1000baseT_Full |
351 SUPPORTED_100baseT_Full;
352 ecmd->advertising = ADVERTISED_Autoneg |
353 ADVERTISED_1000baseT_Full |
354 ADVERTISED_100baseT_Full;
355 break;
356 default:
357 /* if we got here and link is up something bad is afoot */
124ed15b
CS
358 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
359 hw_link_info->phy_type);
c7d05ca8
JB
360 }
361
4e91bcd5
JB
362no_valid_phy_type:
363 /* this is if autoneg is enabled or disabled */
c9a3d471
JB
364 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
365 AUTONEG_ENABLE : AUTONEG_DISABLE);
c7d05ca8 366
c9a3d471
JB
367 switch (hw->phy.media_type) {
368 case I40E_MEDIA_TYPE_BACKPLANE:
4e91bcd5
JB
369 ecmd->supported |= SUPPORTED_Autoneg |
370 SUPPORTED_Backplane;
371 ecmd->advertising |= ADVERTISED_Autoneg |
372 ADVERTISED_Backplane;
c7d05ca8 373 ecmd->port = PORT_NONE;
c9a3d471
JB
374 break;
375 case I40E_MEDIA_TYPE_BASET:
c7d05ca8
JB
376 ecmd->supported |= SUPPORTED_TP;
377 ecmd->advertising |= ADVERTISED_TP;
378 ecmd->port = PORT_TP;
c9a3d471
JB
379 break;
380 case I40E_MEDIA_TYPE_DA:
381 case I40E_MEDIA_TYPE_CX4:
be405eb0
JB
382 ecmd->supported |= SUPPORTED_FIBRE;
383 ecmd->advertising |= ADVERTISED_FIBRE;
384 ecmd->port = PORT_DA;
c9a3d471
JB
385 break;
386 case I40E_MEDIA_TYPE_FIBER:
c7d05ca8 387 ecmd->supported |= SUPPORTED_FIBRE;
c7d05ca8 388 ecmd->port = PORT_FIBRE;
c9a3d471
JB
389 break;
390 case I40E_MEDIA_TYPE_UNKNOWN:
391 default:
392 ecmd->port = PORT_OTHER;
393 break;
c7d05ca8
JB
394 }
395
396 ecmd->transceiver = XCVR_EXTERNAL;
397
4e91bcd5
JB
398 ecmd->supported |= SUPPORTED_Pause;
399
400 switch (hw->fc.current_mode) {
401 case I40E_FC_FULL:
402 ecmd->advertising |= ADVERTISED_Pause;
403 break;
404 case I40E_FC_TX_PAUSE:
405 ecmd->advertising |= ADVERTISED_Asym_Pause;
406 break;
407 case I40E_FC_RX_PAUSE:
408 ecmd->advertising |= (ADVERTISED_Pause |
409 ADVERTISED_Asym_Pause);
410 break;
411 default:
412 ecmd->advertising &= ~(ADVERTISED_Pause |
413 ADVERTISED_Asym_Pause);
414 break;
415 }
416
c7d05ca8
JB
417 if (link_up) {
418 switch (link_speed) {
419 case I40E_LINK_SPEED_40GB:
420 /* need a SPEED_40000 in ethtool.h */
421 ethtool_cmd_speed_set(ecmd, 40000);
422 break;
423 case I40E_LINK_SPEED_10GB:
424 ethtool_cmd_speed_set(ecmd, SPEED_10000);
425 break;
4e91bcd5
JB
426 case I40E_LINK_SPEED_1GB:
427 ethtool_cmd_speed_set(ecmd, SPEED_1000);
428 break;
c7d05ca8
JB
429 default:
430 break;
431 }
432 ecmd->duplex = DUPLEX_FULL;
433 } else {
434 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
435 ecmd->duplex = DUPLEX_UNKNOWN;
436 }
437
438 return 0;
439}
440
bf9c7141
CS
441/**
442 * i40e_set_settings - Set Speed and Duplex
443 * @netdev: network interface device structure
444 * @ecmd: ethtool command
445 *
446 * Set speed/duplex per media_types advertised/forced
447 **/
448static int i40e_set_settings(struct net_device *netdev,
449 struct ethtool_cmd *ecmd)
450{
451 struct i40e_netdev_priv *np = netdev_priv(netdev);
452 struct i40e_aq_get_phy_abilities_resp abilities;
453 struct i40e_aq_set_phy_config config;
454 struct i40e_pf *pf = np->vsi->back;
455 struct i40e_vsi *vsi = np->vsi;
456 struct i40e_hw *hw = &pf->hw;
457 struct ethtool_cmd safe_ecmd;
458 i40e_status status = 0;
459 bool change = false;
460 int err = 0;
461 u8 autoneg;
462 u32 advertise;
463
464 if (vsi != pf->vsi[pf->lan_vsi])
465 return -EOPNOTSUPP;
466
467 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
468 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
469 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE)
470 return -EOPNOTSUPP;
471
472 /* get our own copy of the bits to check against */
473 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
474 i40e_get_settings(netdev, &safe_ecmd);
475
476 /* save autoneg and speed out of ecmd */
477 autoneg = ecmd->autoneg;
478 advertise = ecmd->advertising;
479
480 /* set autoneg and speed back to what they currently are */
481 ecmd->autoneg = safe_ecmd.autoneg;
482 ecmd->advertising = safe_ecmd.advertising;
483
484 ecmd->cmd = safe_ecmd.cmd;
485 /* If ecmd and safe_ecmd are not the same now, then they are
486 * trying to set something that we do not support
487 */
488 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
489 return -EOPNOTSUPP;
490
491 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
492 usleep_range(1000, 2000);
493
494 /* Get the current phy config */
495 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
496 NULL);
497 if (status)
498 return -EAGAIN;
499
124ed15b 500 /* Copy abilities to config in case autoneg is not
bf9c7141
CS
501 * set below
502 */
503 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
bf9c7141
CS
504 config.abilities = abilities.abilities;
505
506 /* Check autoneg */
507 if (autoneg == AUTONEG_ENABLE) {
508 /* If autoneg is not supported, return error */
509 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
510 netdev_info(netdev, "Autoneg not supported on this phy\n");
511 return -EINVAL;
512 }
513 /* If autoneg was not already enabled */
514 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
515 config.abilities = abilities.abilities |
516 I40E_AQ_PHY_ENABLE_AN;
517 change = true;
518 }
519 } else {
520 /* If autoneg is supported 10GBASE_T is the only phy that
521 * can disable it, so otherwise return error
522 */
523 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
524 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
525 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
526 return -EINVAL;
527 }
528 /* If autoneg is currently enabled */
529 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
530 config.abilities = abilities.abilities |
531 ~I40E_AQ_PHY_ENABLE_AN;
532 change = true;
533 }
534 }
535
536 if (advertise & ~safe_ecmd.supported)
537 return -EINVAL;
538
539 if (advertise & ADVERTISED_100baseT_Full)
124ed15b 540 config.link_speed |= I40E_LINK_SPEED_100MB;
bf9c7141
CS
541 if (advertise & ADVERTISED_1000baseT_Full ||
542 advertise & ADVERTISED_1000baseKX_Full)
124ed15b 543 config.link_speed |= I40E_LINK_SPEED_1GB;
bf9c7141
CS
544 if (advertise & ADVERTISED_10000baseT_Full ||
545 advertise & ADVERTISED_10000baseKX4_Full ||
546 advertise & ADVERTISED_10000baseKR_Full)
124ed15b 547 config.link_speed |= I40E_LINK_SPEED_10GB;
bf9c7141
CS
548 if (advertise & ADVERTISED_40000baseKR4_Full ||
549 advertise & ADVERTISED_40000baseCR4_Full ||
550 advertise & ADVERTISED_40000baseSR4_Full ||
551 advertise & ADVERTISED_40000baseLR4_Full)
124ed15b 552 config.link_speed |= I40E_LINK_SPEED_40GB;
bf9c7141 553
124ed15b 554 if (change || (abilities.link_speed != config.link_speed)) {
bf9c7141
CS
555 /* copy over the rest of the abilities */
556 config.phy_type = abilities.phy_type;
557 config.eee_capability = abilities.eee_capability;
558 config.eeer = abilities.eeer_val;
559 config.low_power_ctrl = abilities.d3_lpan;
560
561 /* If link is up set link and an so changes take effect */
562 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
563 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
564
565 /* make the aq call */
566 status = i40e_aq_set_phy_config(hw, &config, NULL);
567 if (status) {
568 netdev_info(netdev, "Set phy config failed with error %d.\n",
569 status);
570 return -EAGAIN;
571 }
572
573 status = i40e_update_link_info(hw, true);
574 if (status)
575 netdev_info(netdev, "Updating link info failed with error %d\n",
576 status);
577
578 } else {
579 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
580 }
581
582 return err;
583}
584
a6599721
JB
585static int i40e_nway_reset(struct net_device *netdev)
586{
587 /* restart autonegotiation */
588 struct i40e_netdev_priv *np = netdev_priv(netdev);
589 struct i40e_pf *pf = np->vsi->back;
590 struct i40e_hw *hw = &pf->hw;
591 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
592 i40e_status ret = 0;
593
594 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
595 if (ret) {
596 netdev_info(netdev, "link restart failed, aq_err=%d\n",
597 pf->hw.aq.asq_last_status);
598 return -EIO;
599 }
600
601 return 0;
602}
603
c7d05ca8
JB
604/**
605 * i40e_get_pauseparam - Get Flow Control status
606 * Return tx/rx-pause status
607 **/
608static void i40e_get_pauseparam(struct net_device *netdev,
609 struct ethtool_pauseparam *pause)
610{
611 struct i40e_netdev_priv *np = netdev_priv(netdev);
612 struct i40e_pf *pf = np->vsi->back;
613 struct i40e_hw *hw = &pf->hw;
614 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
615
616 pause->autoneg =
617 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
618 AUTONEG_ENABLE : AUTONEG_DISABLE);
619
d52c20b7 620 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
c7d05ca8 621 pause->rx_pause = 1;
d52c20b7 622 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
c7d05ca8 623 pause->tx_pause = 1;
d52c20b7
JB
624 } else if (hw->fc.current_mode == I40E_FC_FULL) {
625 pause->rx_pause = 1;
626 pause->tx_pause = 1;
627 }
c7d05ca8
JB
628}
629
2becc35a
CS
630/**
631 * i40e_set_pauseparam - Set Flow Control parameter
632 * @netdev: network interface device structure
633 * @pause: return tx/rx flow control status
634 **/
635static int i40e_set_pauseparam(struct net_device *netdev,
636 struct ethtool_pauseparam *pause)
637{
638 struct i40e_netdev_priv *np = netdev_priv(netdev);
639 struct i40e_pf *pf = np->vsi->back;
640 struct i40e_vsi *vsi = np->vsi;
641 struct i40e_hw *hw = &pf->hw;
642 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
643 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
644 i40e_status status;
645 u8 aq_failures;
7d62dac6 646 int err = 0;
2becc35a
CS
647
648 if (vsi != pf->vsi[pf->lan_vsi])
649 return -EOPNOTSUPP;
650
651 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
652 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
653 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
654 return -EOPNOTSUPP;
655 }
656
657 /* If we have link and don't have autoneg */
658 if (!test_bit(__I40E_DOWN, &pf->state) &&
659 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
660 /* Send message that it might not necessarily work*/
661 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
662 }
663
664 if (hw->fc.current_mode == I40E_FC_PFC) {
665 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
666 return -EOPNOTSUPP;
667 }
668
669 if (pause->rx_pause && pause->tx_pause)
670 hw->fc.requested_mode = I40E_FC_FULL;
671 else if (pause->rx_pause && !pause->tx_pause)
672 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
673 else if (!pause->rx_pause && pause->tx_pause)
674 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
675 else if (!pause->rx_pause && !pause->tx_pause)
676 hw->fc.requested_mode = I40E_FC_NONE;
677 else
678 return -EINVAL;
679
680 /* Set the fc mode and only restart an if link is up*/
681 status = i40e_set_fc(hw, &aq_failures, link_up);
682
683 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
684 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
685 status, hw->aq.asq_last_status);
686 err = -EAGAIN;
687 }
688 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
689 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
690 status, hw->aq.asq_last_status);
691 err = -EAGAIN;
692 }
693 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
694 netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n",
695 status, hw->aq.asq_last_status);
696 err = -EAGAIN;
697 }
698
7d62dac6
CS
699 if (!test_bit(__I40E_DOWN, &pf->state)) {
700 /* Give it a little more time to try to come back */
701 msleep(75);
702 if (!test_bit(__I40E_DOWN, &pf->state))
703 return i40e_nway_reset(netdev);
704 }
2becc35a
CS
705
706 return err;
707}
708
c7d05ca8
JB
709static u32 i40e_get_msglevel(struct net_device *netdev)
710{
711 struct i40e_netdev_priv *np = netdev_priv(netdev);
712 struct i40e_pf *pf = np->vsi->back;
713
714 return pf->msg_enable;
715}
716
717static void i40e_set_msglevel(struct net_device *netdev, u32 data)
718{
719 struct i40e_netdev_priv *np = netdev_priv(netdev);
720 struct i40e_pf *pf = np->vsi->back;
721
722 if (I40E_DEBUG_USER & data)
723 pf->hw.debug_mask = data;
724 pf->msg_enable = data;
725}
726
727static int i40e_get_regs_len(struct net_device *netdev)
728{
729 int reg_count = 0;
730 int i;
731
732 for (i = 0; i40e_reg_list[i].offset != 0; i++)
733 reg_count += i40e_reg_list[i].elements;
734
735 return reg_count * sizeof(u32);
736}
737
738static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
739 void *p)
740{
741 struct i40e_netdev_priv *np = netdev_priv(netdev);
742 struct i40e_pf *pf = np->vsi->back;
743 struct i40e_hw *hw = &pf->hw;
744 u32 *reg_buf = p;
745 int i, j, ri;
746 u32 reg;
747
748 /* Tell ethtool which driver-version-specific regs output we have.
749 *
750 * At some point, if we have ethtool doing special formatting of
751 * this data, it will rely on this version number to know how to
752 * interpret things. Hence, this needs to be updated if/when the
753 * diags register table is changed.
754 */
755 regs->version = 1;
756
757 /* loop through the diags reg table for what to print */
758 ri = 0;
759 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
760 for (j = 0; j < i40e_reg_list[i].elements; j++) {
761 reg = i40e_reg_list[i].offset
762 + (j * i40e_reg_list[i].stride);
763 reg_buf[ri++] = rd32(hw, reg);
764 }
765 }
766
767}
768
769static int i40e_get_eeprom(struct net_device *netdev,
770 struct ethtool_eeprom *eeprom, u8 *bytes)
771{
772 struct i40e_netdev_priv *np = netdev_priv(netdev);
773 struct i40e_hw *hw = &np->vsi->back->hw;
e5e0a5db
ASJ
774 struct i40e_pf *pf = np->vsi->back;
775 int ret_val = 0, len;
776 u8 *eeprom_buff;
777 u16 i, sectors;
778 bool last;
cd552cb4
SN
779 u32 magic;
780
e5e0a5db 781#define I40E_NVM_SECTOR_SIZE 4096
c7d05ca8
JB
782 if (eeprom->len == 0)
783 return -EINVAL;
784
cd552cb4
SN
785 /* check for NVMUpdate access method */
786 magic = hw->vendor_id | (hw->device_id << 16);
787 if (eeprom->magic && eeprom->magic != magic) {
788 int errno;
789
790 /* make sure it is the right magic for NVMUpdate */
791 if ((eeprom->magic >> 16) != hw->device_id)
792 return -EINVAL;
793
794 ret_val = i40e_nvmupd_command(hw,
795 (struct i40e_nvm_access *)eeprom,
796 bytes, &errno);
797 if (ret_val)
798 dev_info(&pf->pdev->dev,
799 "NVMUpdate read failed err=%d status=0x%x\n",
800 ret_val, hw->aq.asq_last_status);
801
802 return errno;
803 }
804
805 /* normal ethtool get_eeprom support */
c7d05ca8
JB
806 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
807
e5e0a5db 808 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
c7d05ca8
JB
809 if (!eeprom_buff)
810 return -ENOMEM;
811
e5e0a5db
ASJ
812 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
813 if (ret_val) {
814 dev_info(&pf->pdev->dev,
815 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
816 ret_val, hw->aq.asq_last_status);
817 goto free_buff;
c7d05ca8
JB
818 }
819
e5e0a5db
ASJ
820 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
821 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
822 len = I40E_NVM_SECTOR_SIZE;
823 last = false;
824 for (i = 0; i < sectors; i++) {
825 if (i == (sectors - 1)) {
826 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
827 last = true;
828 }
829 ret_val = i40e_aq_read_nvm(hw, 0x0,
830 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
831 len,
cd552cb4 832 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
e5e0a5db
ASJ
833 last, NULL);
834 if (ret_val) {
835 dev_info(&pf->pdev->dev,
836 "read NVM failed err=%d status=0x%x\n",
837 ret_val, hw->aq.asq_last_status);
838 goto release_nvm;
839 }
840 }
c7d05ca8 841
e5e0a5db
ASJ
842release_nvm:
843 i40e_release_nvm(hw);
cd552cb4 844 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
e5e0a5db 845free_buff:
c7d05ca8 846 kfree(eeprom_buff);
c7d05ca8
JB
847 return ret_val;
848}
849
850static int i40e_get_eeprom_len(struct net_device *netdev)
851{
852 struct i40e_netdev_priv *np = netdev_priv(netdev);
853 struct i40e_hw *hw = &np->vsi->back->hw;
e5e0a5db
ASJ
854 u32 val;
855
856 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
857 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
858 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
859 /* register returns value in power of 2, 64Kbyte chunks. */
860 val = (64 * 1024) * (1 << val);
861 return val;
c7d05ca8
JB
862}
863
cd552cb4
SN
864static int i40e_set_eeprom(struct net_device *netdev,
865 struct ethtool_eeprom *eeprom, u8 *bytes)
866{
867 struct i40e_netdev_priv *np = netdev_priv(netdev);
868 struct i40e_hw *hw = &np->vsi->back->hw;
869 struct i40e_pf *pf = np->vsi->back;
870 int ret_val = 0;
871 int errno;
872 u32 magic;
873
874 /* normal ethtool set_eeprom is not supported */
875 magic = hw->vendor_id | (hw->device_id << 16);
876 if (eeprom->magic == magic)
877 return -EOPNOTSUPP;
878
879 /* check for NVMUpdate access method */
880 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
881 return -EINVAL;
882
883 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
884 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
885 return -EBUSY;
886
887 ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom,
888 bytes, &errno);
889 if (ret_val)
890 dev_info(&pf->pdev->dev,
891 "NVMUpdate write failed err=%d status=0x%x\n",
892 ret_val, hw->aq.asq_last_status);
893
894 return errno;
895}
896
c7d05ca8
JB
897static void i40e_get_drvinfo(struct net_device *netdev,
898 struct ethtool_drvinfo *drvinfo)
899{
900 struct i40e_netdev_priv *np = netdev_priv(netdev);
901 struct i40e_vsi *vsi = np->vsi;
902 struct i40e_pf *pf = vsi->back;
903
904 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
905 strlcpy(drvinfo->version, i40e_driver_version_str,
906 sizeof(drvinfo->version));
907 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
908 sizeof(drvinfo->fw_version));
909 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
910 sizeof(drvinfo->bus_info));
911}
912
913static void i40e_get_ringparam(struct net_device *netdev,
914 struct ethtool_ringparam *ring)
915{
916 struct i40e_netdev_priv *np = netdev_priv(netdev);
917 struct i40e_pf *pf = np->vsi->back;
918 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
919
920 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
921 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
922 ring->rx_mini_max_pending = 0;
923 ring->rx_jumbo_max_pending = 0;
9f65e15b
AD
924 ring->rx_pending = vsi->rx_rings[0]->count;
925 ring->tx_pending = vsi->tx_rings[0]->count;
c7d05ca8
JB
926 ring->rx_mini_pending = 0;
927 ring->rx_jumbo_pending = 0;
928}
929
930static int i40e_set_ringparam(struct net_device *netdev,
931 struct ethtool_ringparam *ring)
932{
933 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
934 struct i40e_netdev_priv *np = netdev_priv(netdev);
935 struct i40e_vsi *vsi = np->vsi;
936 struct i40e_pf *pf = vsi->back;
937 u32 new_rx_count, new_tx_count;
938 int i, err = 0;
939
940 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
941 return -EINVAL;
942
1fa18370
SN
943 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
944 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
945 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
946 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
947 netdev_info(netdev,
948 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
949 ring->tx_pending, ring->rx_pending,
950 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
951 return -EINVAL;
952 }
953
954 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
955 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
c7d05ca8
JB
956
957 /* if nothing to do return success */
9f65e15b
AD
958 if ((new_tx_count == vsi->tx_rings[0]->count) &&
959 (new_rx_count == vsi->rx_rings[0]->count))
c7d05ca8
JB
960 return 0;
961
962 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
963 usleep_range(1000, 2000);
964
965 if (!netif_running(vsi->netdev)) {
966 /* simple case - set for the next time the netdev is started */
967 for (i = 0; i < vsi->num_queue_pairs; i++) {
9f65e15b
AD
968 vsi->tx_rings[i]->count = new_tx_count;
969 vsi->rx_rings[i]->count = new_rx_count;
c7d05ca8
JB
970 }
971 goto done;
972 }
973
974 /* We can't just free everything and then setup again,
975 * because the ISRs in MSI-X mode get passed pointers
976 * to the Tx and Rx ring structs.
977 */
978
979 /* alloc updated Tx resources */
9f65e15b 980 if (new_tx_count != vsi->tx_rings[0]->count) {
c7d05ca8
JB
981 netdev_info(netdev,
982 "Changing Tx descriptor count from %d to %d.\n",
9f65e15b 983 vsi->tx_rings[0]->count, new_tx_count);
c7d05ca8
JB
984 tx_rings = kcalloc(vsi->alloc_queue_pairs,
985 sizeof(struct i40e_ring), GFP_KERNEL);
986 if (!tx_rings) {
987 err = -ENOMEM;
988 goto done;
989 }
990
991 for (i = 0; i < vsi->num_queue_pairs; i++) {
992 /* clone ring and setup updated count */
9f65e15b 993 tx_rings[i] = *vsi->tx_rings[i];
c7d05ca8
JB
994 tx_rings[i].count = new_tx_count;
995 err = i40e_setup_tx_descriptors(&tx_rings[i]);
996 if (err) {
997 while (i) {
998 i--;
999 i40e_free_tx_resources(&tx_rings[i]);
1000 }
1001 kfree(tx_rings);
1002 tx_rings = NULL;
1003
1004 goto done;
1005 }
1006 }
1007 }
1008
1009 /* alloc updated Rx resources */
9f65e15b 1010 if (new_rx_count != vsi->rx_rings[0]->count) {
c7d05ca8
JB
1011 netdev_info(netdev,
1012 "Changing Rx descriptor count from %d to %d\n",
9f65e15b 1013 vsi->rx_rings[0]->count, new_rx_count);
c7d05ca8
JB
1014 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1015 sizeof(struct i40e_ring), GFP_KERNEL);
1016 if (!rx_rings) {
1017 err = -ENOMEM;
1018 goto free_tx;
1019 }
1020
1021 for (i = 0; i < vsi->num_queue_pairs; i++) {
1022 /* clone ring and setup updated count */
9f65e15b 1023 rx_rings[i] = *vsi->rx_rings[i];
c7d05ca8
JB
1024 rx_rings[i].count = new_rx_count;
1025 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1026 if (err) {
1027 while (i) {
1028 i--;
1029 i40e_free_rx_resources(&rx_rings[i]);
1030 }
1031 kfree(rx_rings);
1032 rx_rings = NULL;
1033
1034 goto free_tx;
1035 }
1036 }
1037 }
1038
1039 /* Bring interface down, copy in the new ring info,
1040 * then restore the interface
1041 */
1042 i40e_down(vsi);
1043
1044 if (tx_rings) {
1045 for (i = 0; i < vsi->num_queue_pairs; i++) {
9f65e15b
AD
1046 i40e_free_tx_resources(vsi->tx_rings[i]);
1047 *vsi->tx_rings[i] = tx_rings[i];
c7d05ca8
JB
1048 }
1049 kfree(tx_rings);
1050 tx_rings = NULL;
1051 }
1052
1053 if (rx_rings) {
1054 for (i = 0; i < vsi->num_queue_pairs; i++) {
9f65e15b
AD
1055 i40e_free_rx_resources(vsi->rx_rings[i]);
1056 *vsi->rx_rings[i] = rx_rings[i];
c7d05ca8
JB
1057 }
1058 kfree(rx_rings);
1059 rx_rings = NULL;
1060 }
1061
1062 i40e_up(vsi);
1063
1064free_tx:
1065 /* error cleanup if the Rx allocations failed after getting Tx */
1066 if (tx_rings) {
1067 for (i = 0; i < vsi->num_queue_pairs; i++)
1068 i40e_free_tx_resources(&tx_rings[i]);
1069 kfree(tx_rings);
1070 tx_rings = NULL;
1071 }
1072
1073done:
1074 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1075
1076 return err;
1077}
1078
1079static int i40e_get_sset_count(struct net_device *netdev, int sset)
1080{
1081 struct i40e_netdev_priv *np = netdev_priv(netdev);
1082 struct i40e_vsi *vsi = np->vsi;
1083 struct i40e_pf *pf = vsi->back;
1084
1085 switch (sset) {
1086 case ETH_SS_TEST:
1087 return I40E_TEST_LEN;
1088 case ETH_SS_STATS:
8eab9cfd
SN
1089 if (vsi == pf->vsi[pf->lan_vsi]) {
1090 int len = I40E_PF_STATS_LEN(netdev);
1091
1092 if (pf->lan_veb != I40E_NO_VEB)
1093 len += I40E_VEB_STATS_LEN;
1094 return len;
1095 } else {
c7d05ca8 1096 return I40E_VSI_STATS_LEN(netdev);
8eab9cfd 1097 }
c7d05ca8
JB
1098 default:
1099 return -EOPNOTSUPP;
1100 }
1101}
1102
1103static void i40e_get_ethtool_stats(struct net_device *netdev,
1104 struct ethtool_stats *stats, u64 *data)
1105{
1106 struct i40e_netdev_priv *np = netdev_priv(netdev);
e7046ee1 1107 struct i40e_ring *tx_ring, *rx_ring;
c7d05ca8
JB
1108 struct i40e_vsi *vsi = np->vsi;
1109 struct i40e_pf *pf = vsi->back;
1110 int i = 0;
1111 char *p;
1112 int j;
1113 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
980e9b11 1114 unsigned int start;
c7d05ca8
JB
1115
1116 i40e_update_stats(vsi);
1117
1118 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1119 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1120 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1121 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1122 }
41a9e55c
SN
1123 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1124 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1125 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1126 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1127 }
38e00438
VD
1128#ifdef I40E_FCOE
1129 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1130 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1131 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1132 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1133 }
1134#endif
980e9b11 1135 rcu_read_lock();
99c472a3 1136 for (j = 0; j < vsi->num_queue_pairs; j++) {
e7046ee1 1137 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
980e9b11
AD
1138
1139 if (!tx_ring)
1140 continue;
1141
1142 /* process Tx ring statistics */
1143 do {
57a7744e 1144 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
980e9b11
AD
1145 data[i] = tx_ring->stats.packets;
1146 data[i + 1] = tx_ring->stats.bytes;
57a7744e 1147 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
99c472a3 1148 i += 2;
980e9b11
AD
1149
1150 /* Rx ring is the 2nd half of the queue pair */
1151 rx_ring = &tx_ring[1];
1152 do {
57a7744e 1153 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
99c472a3
CS
1154 data[i] = rx_ring->stats.packets;
1155 data[i + 1] = rx_ring->stats.bytes;
57a7744e 1156 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
99c472a3 1157 i += 2;
c7d05ca8 1158 }
980e9b11 1159 rcu_read_unlock();
8eab9cfd
SN
1160 if (vsi != pf->vsi[pf->lan_vsi])
1161 return;
1162
1163 if (pf->lan_veb != I40E_NO_VEB) {
1164 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1165 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1166 p = (char *)veb;
1167 p += i40e_gstrings_veb_stats[j].stat_offset;
1168 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1169 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
c7d05ca8 1170 }
c7d05ca8 1171 }
8eab9cfd
SN
1172 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1173 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1174 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1175 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1176 }
1177 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1178 data[i++] = pf->stats.priority_xon_tx[j];
1179 data[i++] = pf->stats.priority_xoff_tx[j];
1180 }
1181 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1182 data[i++] = pf->stats.priority_xon_rx[j];
1183 data[i++] = pf->stats.priority_xoff_rx[j];
1184 }
1185 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1186 data[i++] = pf->stats.priority_xon_2_xoff[j];
c7d05ca8
JB
1187}
1188
1189static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1190 u8 *data)
1191{
1192 struct i40e_netdev_priv *np = netdev_priv(netdev);
1193 struct i40e_vsi *vsi = np->vsi;
1194 struct i40e_pf *pf = vsi->back;
1195 char *p = (char *)data;
1196 int i;
1197
1198 switch (stringset) {
1199 case ETH_SS_TEST:
1200 for (i = 0; i < I40E_TEST_LEN; i++) {
1201 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1202 data += ETH_GSTRING_LEN;
1203 }
1204 break;
1205 case ETH_SS_STATS:
1206 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1207 snprintf(p, ETH_GSTRING_LEN, "%s",
1208 i40e_gstrings_net_stats[i].stat_string);
1209 p += ETH_GSTRING_LEN;
1210 }
41a9e55c
SN
1211 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1212 snprintf(p, ETH_GSTRING_LEN, "%s",
1213 i40e_gstrings_misc_stats[i].stat_string);
1214 p += ETH_GSTRING_LEN;
1215 }
38e00438
VD
1216#ifdef I40E_FCOE
1217 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1218 snprintf(p, ETH_GSTRING_LEN, "%s",
1219 i40e_gstrings_fcoe_stats[i].stat_string);
1220 p += ETH_GSTRING_LEN;
1221 }
1222#endif
c7d05ca8
JB
1223 for (i = 0; i < vsi->num_queue_pairs; i++) {
1224 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1225 p += ETH_GSTRING_LEN;
1226 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1227 p += ETH_GSTRING_LEN;
c7d05ca8
JB
1228 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1229 p += ETH_GSTRING_LEN;
1230 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1231 p += ETH_GSTRING_LEN;
1232 }
8eab9cfd
SN
1233 if (vsi != pf->vsi[pf->lan_vsi])
1234 return;
1235
1236 if (pf->lan_veb != I40E_NO_VEB) {
1237 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1238 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1239 i40e_gstrings_veb_stats[i].stat_string);
c7d05ca8
JB
1240 p += ETH_GSTRING_LEN;
1241 }
1242 }
8eab9cfd
SN
1243 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1244 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1245 i40e_gstrings_stats[i].stat_string);
1246 p += ETH_GSTRING_LEN;
1247 }
1248 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1249 snprintf(p, ETH_GSTRING_LEN,
1250 "port.tx_priority_%u_xon", i);
1251 p += ETH_GSTRING_LEN;
1252 snprintf(p, ETH_GSTRING_LEN,
1253 "port.tx_priority_%u_xoff", i);
1254 p += ETH_GSTRING_LEN;
1255 }
1256 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1257 snprintf(p, ETH_GSTRING_LEN,
1258 "port.rx_priority_%u_xon", i);
1259 p += ETH_GSTRING_LEN;
1260 snprintf(p, ETH_GSTRING_LEN,
1261 "port.rx_priority_%u_xoff", i);
1262 p += ETH_GSTRING_LEN;
1263 }
1264 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1265 snprintf(p, ETH_GSTRING_LEN,
1266 "port.rx_priority_%u_xon_2_xoff", i);
1267 p += ETH_GSTRING_LEN;
1268 }
c7d05ca8
JB
1269 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1270 break;
1271 }
1272}
1273
1274static int i40e_get_ts_info(struct net_device *dev,
1275 struct ethtool_ts_info *info)
1276{
beb0dff1
JK
1277 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1278
1279 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1280 SOF_TIMESTAMPING_RX_SOFTWARE |
1281 SOF_TIMESTAMPING_SOFTWARE |
1282 SOF_TIMESTAMPING_TX_HARDWARE |
1283 SOF_TIMESTAMPING_RX_HARDWARE |
1284 SOF_TIMESTAMPING_RAW_HARDWARE;
1285
1286 if (pf->ptp_clock)
1287 info->phc_index = ptp_clock_index(pf->ptp_clock);
1288 else
1289 info->phc_index = -1;
1290
1291 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1292
1293 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1294 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1295 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1296 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1297 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1298 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1299 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1300 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1301 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1302 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1303 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1304 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1305
1306 return 0;
c7d05ca8
JB
1307}
1308
7b086397 1309static int i40e_link_test(struct net_device *netdev, u64 *data)
c7d05ca8 1310{
7b086397
SN
1311 struct i40e_netdev_priv *np = netdev_priv(netdev);
1312 struct i40e_pf *pf = np->vsi->back;
1313
b03aaa9c 1314 netif_info(pf, hw, netdev, "link test\n");
c7d05ca8
JB
1315 if (i40e_get_link_status(&pf->hw))
1316 *data = 0;
1317 else
1318 *data = 1;
1319
1320 return *data;
1321}
1322
7b086397 1323static int i40e_reg_test(struct net_device *netdev, u64 *data)
c7d05ca8 1324{
7b086397
SN
1325 struct i40e_netdev_priv *np = netdev_priv(netdev);
1326 struct i40e_pf *pf = np->vsi->back;
c7d05ca8 1327
b03aaa9c 1328 netif_info(pf, hw, netdev, "register test\n");
7b086397 1329 *data = i40e_diag_reg_test(&pf->hw);
c7d05ca8 1330
7b086397 1331 return *data;
c7d05ca8
JB
1332}
1333
7b086397 1334static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
c7d05ca8 1335{
7b086397
SN
1336 struct i40e_netdev_priv *np = netdev_priv(netdev);
1337 struct i40e_pf *pf = np->vsi->back;
c7d05ca8 1338
b03aaa9c 1339 netif_info(pf, hw, netdev, "eeprom test\n");
7b086397 1340 *data = i40e_diag_eeprom_test(&pf->hw);
c7d05ca8 1341
7b086397 1342 return *data;
c7d05ca8
JB
1343}
1344
7b086397 1345static int i40e_intr_test(struct net_device *netdev, u64 *data)
c7d05ca8 1346{
7b086397
SN
1347 struct i40e_netdev_priv *np = netdev_priv(netdev);
1348 struct i40e_pf *pf = np->vsi->back;
cd92e72f
SN
1349 u16 swc_old = pf->sw_int_count;
1350
b03aaa9c 1351 netif_info(pf, hw, netdev, "interrupt test\n");
cd92e72f
SN
1352 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1353 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1354 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
1355 usleep_range(1000, 2000);
1356 *data = (swc_old == pf->sw_int_count);
c7d05ca8
JB
1357
1358 return *data;
1359}
1360
7b086397 1361static int i40e_loopback_test(struct net_device *netdev, u64 *data)
c7d05ca8 1362{
b03aaa9c
SN
1363 struct i40e_netdev_priv *np = netdev_priv(netdev);
1364 struct i40e_pf *pf = np->vsi->back;
1365
1366 netif_info(pf, hw, netdev, "loopback test not implemented\n");
cd92e72f 1367 *data = 0;
c7d05ca8
JB
1368
1369 return *data;
1370}
1371
1372static void i40e_diag_test(struct net_device *netdev,
1373 struct ethtool_test *eth_test, u64 *data)
1374{
1375 struct i40e_netdev_priv *np = netdev_priv(netdev);
1376 struct i40e_pf *pf = np->vsi->back;
1377
c7d05ca8
JB
1378 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1379 /* Offline tests */
b03aaa9c 1380 netif_info(pf, drv, netdev, "offline testing starting\n");
c7d05ca8 1381
f551b438
SN
1382 set_bit(__I40E_TESTING, &pf->state);
1383
c7d05ca8
JB
1384 /* Link test performed before hardware reset
1385 * so autoneg doesn't interfere with test result
1386 */
7b086397 1387 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
c7d05ca8
JB
1388 eth_test->flags |= ETH_TEST_FL_FAILED;
1389
7b086397 1390 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
c7d05ca8
JB
1391 eth_test->flags |= ETH_TEST_FL_FAILED;
1392
7b086397 1393 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
c7d05ca8
JB
1394 eth_test->flags |= ETH_TEST_FL_FAILED;
1395
7b086397 1396 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
c7d05ca8
JB
1397 eth_test->flags |= ETH_TEST_FL_FAILED;
1398
f551b438
SN
1399 /* run reg test last, a reset is required after it */
1400 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1401 eth_test->flags |= ETH_TEST_FL_FAILED;
1402
1403 clear_bit(__I40E_TESTING, &pf->state);
1404 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
c7d05ca8 1405 } else {
c7d05ca8 1406 /* Online tests */
b03aaa9c
SN
1407 netif_info(pf, drv, netdev, "online testing starting\n");
1408
7b086397 1409 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
c7d05ca8
JB
1410 eth_test->flags |= ETH_TEST_FL_FAILED;
1411
1412 /* Offline only tests, not run in online; pass by default */
1413 data[I40E_ETH_TEST_REG] = 0;
1414 data[I40E_ETH_TEST_EEPROM] = 0;
1415 data[I40E_ETH_TEST_INTR] = 0;
1416 data[I40E_ETH_TEST_LOOPBACK] = 0;
c7d05ca8 1417 }
c140c17b 1418
b03aaa9c 1419 netif_info(pf, drv, netdev, "testing finished\n");
c7d05ca8
JB
1420}
1421
1422static void i40e_get_wol(struct net_device *netdev,
1423 struct ethtool_wolinfo *wol)
1424{
8e2773ae
SN
1425 struct i40e_netdev_priv *np = netdev_priv(netdev);
1426 struct i40e_pf *pf = np->vsi->back;
1427 struct i40e_hw *hw = &pf->hw;
1428 u16 wol_nvm_bits;
1429
1430 /* NVM bit on means WoL disabled for the port */
1431 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1432 if ((1 << hw->port) & wol_nvm_bits) {
1433 wol->supported = 0;
1434 wol->wolopts = 0;
1435 } else {
1436 wol->supported = WAKE_MAGIC;
1437 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1438 }
1439}
1440
1441static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1442{
1443 struct i40e_netdev_priv *np = netdev_priv(netdev);
1444 struct i40e_pf *pf = np->vsi->back;
1445 struct i40e_hw *hw = &pf->hw;
1446 u16 wol_nvm_bits;
1447
1448 /* NVM bit on means WoL disabled for the port */
1449 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1450 if (((1 << hw->port) & wol_nvm_bits))
1451 return -EOPNOTSUPP;
1452
1453 /* only magic packet is supported */
1454 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1455 return -EOPNOTSUPP;
1456
1457 /* is this a new value? */
1458 if (pf->wol_en != !!wol->wolopts) {
1459 pf->wol_en = !!wol->wolopts;
1460 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1461 }
1462
c7d05ca8
JB
1463 return 0;
1464}
1465
1466static int i40e_set_phys_id(struct net_device *netdev,
1467 enum ethtool_phys_id_state state)
1468{
1469 struct i40e_netdev_priv *np = netdev_priv(netdev);
1470 struct i40e_pf *pf = np->vsi->back;
1471 struct i40e_hw *hw = &pf->hw;
1472 int blink_freq = 2;
1473
1474 switch (state) {
1475 case ETHTOOL_ID_ACTIVE:
1476 pf->led_status = i40e_led_get(hw);
1477 return blink_freq;
1478 case ETHTOOL_ID_ON:
0556a9e3 1479 i40e_led_set(hw, 0xF, false);
c7d05ca8
JB
1480 break;
1481 case ETHTOOL_ID_OFF:
0556a9e3 1482 i40e_led_set(hw, 0x0, false);
c7d05ca8
JB
1483 break;
1484 case ETHTOOL_ID_INACTIVE:
0556a9e3 1485 i40e_led_set(hw, pf->led_status, false);
c7d05ca8
JB
1486 break;
1487 }
1488
1489 return 0;
1490}
1491
1492/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1493 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1494 * 125us (8000 interrupts per second) == ITR(62)
1495 */
1496
1497static int i40e_get_coalesce(struct net_device *netdev,
1498 struct ethtool_coalesce *ec)
1499{
1500 struct i40e_netdev_priv *np = netdev_priv(netdev);
1501 struct i40e_vsi *vsi = np->vsi;
1502
1503 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1504 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1505
1506 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
32f5f54a 1507 ec->use_adaptive_rx_coalesce = 1;
c7d05ca8
JB
1508
1509 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
32f5f54a
MW
1510 ec->use_adaptive_tx_coalesce = 1;
1511
1512 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1513 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
c7d05ca8
JB
1514
1515 return 0;
1516}
1517
1518static int i40e_set_coalesce(struct net_device *netdev,
1519 struct ethtool_coalesce *ec)
1520{
1521 struct i40e_netdev_priv *np = netdev_priv(netdev);
1522 struct i40e_q_vector *q_vector;
1523 struct i40e_vsi *vsi = np->vsi;
1524 struct i40e_pf *pf = vsi->back;
1525 struct i40e_hw *hw = &pf->hw;
1526 u16 vector;
1527 int i;
1528
1529 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1530 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1531
5c2cebda 1532 vector = vsi->base_vector;
32f5f54a 1533 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
5c2cebda 1534 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
c7d05ca8 1535 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
5c2cebda
CW
1536 } else if (ec->rx_coalesce_usecs == 0) {
1537 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1538 i40e_irq_dynamic_disable(vsi, vector);
1539 if (ec->use_adaptive_rx_coalesce)
1540 netif_info(pf, drv, netdev,
1541 "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n");
1542 } else {
1543 netif_info(pf, drv, netdev,
1544 "Invalid value, Rx-usecs range is 0, 8-8160\n");
32f5f54a 1545 return -EINVAL;
5c2cebda 1546 }
c7d05ca8 1547
32f5f54a 1548 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
5c2cebda 1549 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
c7d05ca8 1550 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
5c2cebda
CW
1551 } else if (ec->tx_coalesce_usecs == 0) {
1552 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1553 i40e_irq_dynamic_disable(vsi, vector);
1554 if (ec->use_adaptive_tx_coalesce)
1555 netif_info(pf, drv, netdev,
1556 "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n");
1557 } else {
1558 netif_info(pf, drv, netdev,
1559 "Invalid value, Tx-usecs range is 0, 8-8160\n");
32f5f54a 1560 return -EINVAL;
5c2cebda 1561 }
32f5f54a
MW
1562
1563 if (ec->use_adaptive_rx_coalesce)
1564 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1565 else
1566 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1567
1568 if (ec->use_adaptive_tx_coalesce)
1569 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1570 else
1571 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
c7d05ca8 1572
493fb300
AD
1573 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1574 q_vector = vsi->q_vectors[i];
c7d05ca8
JB
1575 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1576 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1577 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1578 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1579 i40e_flush(hw);
1580 }
1581
1582 return 0;
1583}
1584
1585/**
1586 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1587 * @pf: pointer to the physical function struct
1588 * @cmd: ethtool rxnfc command
1589 *
1590 * Returns Success if the flow is supported, else Invalid Input.
1591 **/
1592static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1593{
1594 cmd->data = 0;
1595
1596 /* Report default options for RSS on i40e */
1597 switch (cmd->flow_type) {
1598 case TCP_V4_FLOW:
1599 case UDP_V4_FLOW:
1600 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1601 /* fall through to add IP fields */
1602 case SCTP_V4_FLOW:
1603 case AH_ESP_V4_FLOW:
1604 case AH_V4_FLOW:
1605 case ESP_V4_FLOW:
1606 case IPV4_FLOW:
1607 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1608 break;
1609 case TCP_V6_FLOW:
1610 case UDP_V6_FLOW:
1611 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1612 /* fall through to add IP fields */
1613 case SCTP_V6_FLOW:
1614 case AH_ESP_V6_FLOW:
1615 case AH_V6_FLOW:
1616 case ESP_V6_FLOW:
1617 case IPV6_FLOW:
1618 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1619 break;
1620 default:
1621 return -EINVAL;
1622 }
1623
1624 return 0;
1625}
1626
17a73f6b
JG
1627/**
1628 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1629 * @pf: Pointer to the physical function struct
1630 * @cmd: The command to get or set Rx flow classification rules
1631 * @rule_locs: Array of used rule locations
1632 *
1633 * This function populates both the total and actual rule count of
1634 * the ethtool flow classification command
1635 *
1636 * Returns 0 on success or -EMSGSIZE if entry not found
1637 **/
1638static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1639 struct ethtool_rxnfc *cmd,
1640 u32 *rule_locs)
1641{
1642 struct i40e_fdir_filter *rule;
1643 struct hlist_node *node2;
1644 int cnt = 0;
1645
1646 /* report total rule count */
082def10 1647 cmd->data = i40e_get_fd_cnt_all(pf);
17a73f6b
JG
1648
1649 hlist_for_each_entry_safe(rule, node2,
1650 &pf->fdir_filter_list, fdir_node) {
1651 if (cnt == cmd->rule_cnt)
1652 return -EMSGSIZE;
1653
1654 rule_locs[cnt] = rule->fd_id;
1655 cnt++;
1656 }
1657
1658 cmd->rule_cnt = cnt;
1659
1660 return 0;
1661}
1662
1663/**
1664 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1665 * @pf: Pointer to the physical function struct
1666 * @cmd: The command to get or set Rx flow classification rules
1667 *
1668 * This function looks up a filter based on the Rx flow classification
1669 * command and fills the flow spec info for it if found
1670 *
1671 * Returns 0 on success or -EINVAL if filter not found
1672 **/
1673static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1674 struct ethtool_rxnfc *cmd)
1675{
1676 struct ethtool_rx_flow_spec *fsp =
1677 (struct ethtool_rx_flow_spec *)&cmd->fs;
1678 struct i40e_fdir_filter *rule = NULL;
1679 struct hlist_node *node2;
1680
17a73f6b
JG
1681 hlist_for_each_entry_safe(rule, node2,
1682 &pf->fdir_filter_list, fdir_node) {
1683 if (fsp->location <= rule->fd_id)
1684 break;
1685 }
1686
1687 if (!rule || fsp->location != rule->fd_id)
1688 return -EINVAL;
1689
1690 fsp->flow_type = rule->flow_type;
7d54eb2c
ASJ
1691 if (fsp->flow_type == IP_USER_FLOW) {
1692 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1693 fsp->h_u.usr_ip4_spec.proto = 0;
1694 fsp->m_u.usr_ip4_spec.proto = 0;
1695 }
1696
04b73bd7
ASJ
1697 /* Reverse the src and dest notion, since the HW views them from
1698 * Tx perspective where as the user expects it from Rx filter view.
1699 */
1700 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1701 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1702 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1703 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
387ce1a9
ASJ
1704
1705 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1706 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1707 else
1708 fsp->ring_cookie = rule->q_index;
17a73f6b
JG
1709
1710 return 0;
1711}
1712
c7d05ca8
JB
1713/**
1714 * i40e_get_rxnfc - command to get RX flow classification rules
1715 * @netdev: network interface device structure
1716 * @cmd: ethtool rxnfc command
1717 *
1718 * Returns Success if the command is supported.
1719 **/
1720static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1721 u32 *rule_locs)
1722{
1723 struct i40e_netdev_priv *np = netdev_priv(netdev);
1724 struct i40e_vsi *vsi = np->vsi;
1725 struct i40e_pf *pf = vsi->back;
1726 int ret = -EOPNOTSUPP;
1727
1728 switch (cmd->cmd) {
1729 case ETHTOOL_GRXRINGS:
1730 cmd->data = vsi->alloc_queue_pairs;
1731 ret = 0;
1732 break;
1733 case ETHTOOL_GRXFH:
1734 ret = i40e_get_rss_hash_opts(pf, cmd);
1735 break;
1736 case ETHTOOL_GRXCLSRLCNT:
17a73f6b 1737 cmd->rule_cnt = pf->fdir_pf_active_filters;
082def10
ASJ
1738 /* report total rule count */
1739 cmd->data = i40e_get_fd_cnt_all(pf);
c7d05ca8
JB
1740 ret = 0;
1741 break;
1742 case ETHTOOL_GRXCLSRULE:
17a73f6b 1743 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
c7d05ca8
JB
1744 break;
1745 case ETHTOOL_GRXCLSRLALL:
17a73f6b
JG
1746 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1747 break;
c7d05ca8
JB
1748 default:
1749 break;
1750 }
1751
1752 return ret;
1753}
1754
1755/**
1756 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1757 * @pf: pointer to the physical function struct
1758 * @cmd: ethtool rxnfc command
1759 *
1760 * Returns Success if the flow input set is supported.
1761 **/
1762static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1763{
1764 struct i40e_hw *hw = &pf->hw;
1765 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1766 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1767
1768 /* RSS does not support anything other than hashing
1769 * to queues on src and dst IPs and ports
1770 */
1771 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1772 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1773 return -EINVAL;
1774
1775 /* We need at least the IP SRC and DEST fields for hashing */
1776 if (!(nfc->data & RXH_IP_SRC) ||
1777 !(nfc->data & RXH_IP_DST))
1778 return -EINVAL;
1779
1780 switch (nfc->flow_type) {
1781 case TCP_V4_FLOW:
1782 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1783 case 0:
1784 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1785 break;
1786 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1787 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1788 break;
1789 default:
1790 return -EINVAL;
1791 }
1792 break;
1793 case TCP_V6_FLOW:
1794 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1795 case 0:
1796 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1797 break;
1798 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1799 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1800 break;
1801 default:
1802 return -EINVAL;
1803 }
1804 break;
1805 case UDP_V4_FLOW:
1806 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1807 case 0:
b2d36c03
KS
1808 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1809 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
c7d05ca8
JB
1810 break;
1811 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
b2d36c03
KS
1812 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1813 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
c7d05ca8
JB
1814 break;
1815 default:
1816 return -EINVAL;
1817 }
1818 break;
1819 case UDP_V6_FLOW:
1820 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1821 case 0:
b2d36c03
KS
1822 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1823 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
c7d05ca8
JB
1824 break;
1825 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
b2d36c03
KS
1826 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1827 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
c7d05ca8
JB
1828 break;
1829 default:
1830 return -EINVAL;
1831 }
1832 break;
1833 case AH_ESP_V4_FLOW:
1834 case AH_V4_FLOW:
1835 case ESP_V4_FLOW:
1836 case SCTP_V4_FLOW:
1837 if ((nfc->data & RXH_L4_B_0_1) ||
1838 (nfc->data & RXH_L4_B_2_3))
1839 return -EINVAL;
1840 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1841 break;
1842 case AH_ESP_V6_FLOW:
1843 case AH_V6_FLOW:
1844 case ESP_V6_FLOW:
1845 case SCTP_V6_FLOW:
1846 if ((nfc->data & RXH_L4_B_0_1) ||
1847 (nfc->data & RXH_L4_B_2_3))
1848 return -EINVAL;
1849 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1850 break;
1851 case IPV4_FLOW:
1852 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1853 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1854 break;
1855 case IPV6_FLOW:
1856 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1857 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1858 break;
1859 default:
1860 return -EINVAL;
1861 }
1862
1863 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1864 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1865 i40e_flush(hw);
1866
1867 return 0;
1868}
1869
43fddb75
ASJ
1870/**
1871 * i40e_match_fdir_input_set - Match a new filter against an existing one
1872 * @rule: The filter already added
1873 * @input: The new filter to comapre against
1874 *
1875 * Returns true if the two input set match
1876 **/
1877static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1878 struct i40e_fdir_filter *input)
1879{
1880 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1881 (rule->src_ip[0] != input->src_ip[0]) ||
1882 (rule->dst_port != input->dst_port) ||
1883 (rule->src_port != input->src_port))
1884 return false;
1885 return true;
1886}
1887
c7d05ca8 1888/**
17a73f6b
JG
1889 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1890 * @vsi: Pointer to the targeted VSI
1891 * @input: The filter to update or NULL to indicate deletion
1892 * @sw_idx: Software index to the filter
1893 * @cmd: The command to get or set Rx flow classification rules
c7d05ca8 1894 *
17a73f6b
JG
1895 * This function updates (or deletes) a Flow Director entry from
1896 * the hlist of the corresponding PF
1897 *
1898 * Returns 0 on success
c7d05ca8 1899 **/
17a73f6b
JG
1900static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1901 struct i40e_fdir_filter *input,
1902 u16 sw_idx,
1903 struct ethtool_rxnfc *cmd)
c7d05ca8 1904{
17a73f6b 1905 struct i40e_fdir_filter *rule, *parent;
c7d05ca8 1906 struct i40e_pf *pf = vsi->back;
17a73f6b
JG
1907 struct hlist_node *node2;
1908 int err = -EINVAL;
c7d05ca8 1909
17a73f6b
JG
1910 parent = NULL;
1911 rule = NULL;
c7d05ca8 1912
17a73f6b
JG
1913 hlist_for_each_entry_safe(rule, node2,
1914 &pf->fdir_filter_list, fdir_node) {
1915 /* hash found, or no matching entry */
1916 if (rule->fd_id >= sw_idx)
1917 break;
1918 parent = rule;
c7d05ca8
JB
1919 }
1920
17a73f6b
JG
1921 /* if there is an old rule occupying our place remove it */
1922 if (rule && (rule->fd_id == sw_idx)) {
43fddb75
ASJ
1923 if (input && !i40e_match_fdir_input_set(rule, input))
1924 err = i40e_add_del_fdir(vsi, rule, false);
1925 else if (!input)
1926 err = i40e_add_del_fdir(vsi, rule, false);
17a73f6b
JG
1927 hlist_del(&rule->fdir_node);
1928 kfree(rule);
1929 pf->fdir_pf_active_filters--;
cbf61325
ASJ
1930 }
1931
17a73f6b
JG
1932 /* If no input this was a delete, err should be 0 if a rule was
1933 * successfully found and removed from the list else -EINVAL
1934 */
1935 if (!input)
1936 return err;
c7d05ca8 1937
17a73f6b
JG
1938 /* initialize node and set software index */
1939 INIT_HLIST_NODE(&input->fdir_node);
c7d05ca8 1940
17a73f6b
JG
1941 /* add filter to the list */
1942 if (parent)
1d023284 1943 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
17a73f6b
JG
1944 else
1945 hlist_add_head(&input->fdir_node,
1946 &pf->fdir_filter_list);
c7d05ca8 1947
17a73f6b
JG
1948 /* update counts */
1949 pf->fdir_pf_active_filters++;
c7d05ca8 1950
17a73f6b 1951 return 0;
c7d05ca8
JB
1952}
1953
1954/**
17a73f6b
JG
1955 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1956 * @vsi: Pointer to the targeted VSI
1957 * @cmd: The command to get or set Rx flow classification rules
c7d05ca8 1958 *
17a73f6b
JG
1959 * The function removes a Flow Director filter entry from the
1960 * hlist of the corresponding PF
c7d05ca8 1961 *
17a73f6b
JG
1962 * Returns 0 on success
1963 */
1964static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1965 struct ethtool_rxnfc *cmd)
c7d05ca8 1966{
17a73f6b
JG
1967 struct ethtool_rx_flow_spec *fsp =
1968 (struct ethtool_rx_flow_spec *)&cmd->fs;
c7d05ca8 1969 struct i40e_pf *pf = vsi->back;
17a73f6b 1970 int ret = 0;
c7d05ca8 1971
60793f4a
ASJ
1972 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1973 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1974 return -EBUSY;
1975
1e1be8f6
ASJ
1976 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
1977 return -EBUSY;
1978
17a73f6b 1979 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
c7d05ca8 1980
55a5e60b 1981 i40e_fdir_check_and_reenable(pf);
17a73f6b 1982 return ret;
c7d05ca8
JB
1983}
1984
1985/**
1eaa3840 1986 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
c7d05ca8
JB
1987 * @vsi: pointer to the targeted VSI
1988 * @cmd: command to get or set RX flow classification rules
c7d05ca8 1989 *
1eaa3840
ASJ
1990 * Add Flow Director filters for a specific flow spec based on their
1991 * protocol. Returns 0 if the filters were successfully added.
c7d05ca8 1992 **/
1eaa3840
ASJ
1993static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1994 struct ethtool_rxnfc *cmd)
c7d05ca8 1995{
17a73f6b
JG
1996 struct ethtool_rx_flow_spec *fsp;
1997 struct i40e_fdir_filter *input;
c7d05ca8 1998 struct i40e_pf *pf;
17a73f6b 1999 int ret = -EINVAL;
c7d05ca8
JB
2000
2001 if (!vsi)
2002 return -EINVAL;
2003
2004 pf = vsi->back;
2005
55a5e60b
ASJ
2006 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2007 return -EOPNOTSUPP;
2008
1eaa3840 2009 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
55a5e60b
ASJ
2010 return -ENOSPC;
2011
60793f4a
ASJ
2012 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2013 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2014 return -EBUSY;
2015
1e1be8f6
ASJ
2016 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2017 return -EBUSY;
2018
55a5e60b
ASJ
2019 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2020
17a73f6b
JG
2021 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2022 pf->hw.func_caps.fd_filters_guaranteed)) {
c7d05ca8 2023 return -EINVAL;
17a73f6b 2024 }
c7d05ca8 2025
387ce1a9
ASJ
2026 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2027 (fsp->ring_cookie >= vsi->num_queue_pairs))
17a73f6b 2028 return -EINVAL;
c7d05ca8 2029
17a73f6b 2030 input = kzalloc(sizeof(*input), GFP_KERNEL);
c7d05ca8 2031
17a73f6b
JG
2032 if (!input)
2033 return -ENOMEM;
c7d05ca8 2034
17a73f6b
JG
2035 input->fd_id = fsp->location;
2036
35a91fdd
ASJ
2037 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2038 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2039 else
2040 input->dest_ctl =
2041 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2042
17a73f6b
JG
2043 input->q_index = fsp->ring_cookie;
2044 input->flex_off = 0;
2045 input->pctype = 0;
2046 input->dest_vsi = vsi->id;
17a73f6b 2047 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
433c47de 2048 input->cnt_index = pf->fd_sb_cnt_idx;
17a73f6b
JG
2049 input->flow_type = fsp->flow_type;
2050 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
04b73bd7
ASJ
2051
2052 /* Reverse the src and dest notion, since the HW expects them to be from
2053 * Tx perspective where as the input from user is from Rx filter view.
2054 */
2055 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2056 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2057 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2058 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
17a73f6b 2059
1eaa3840
ASJ
2060 ret = i40e_add_del_fdir(vsi, input, true);
2061 if (ret)
17a73f6b 2062 kfree(input);
17a73f6b 2063 else
1eaa3840 2064 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
c7d05ca8
JB
2065
2066 return ret;
2067}
8fb905b3 2068
c7d05ca8
JB
2069/**
2070 * i40e_set_rxnfc - command to set RX flow classification rules
2071 * @netdev: network interface device structure
2072 * @cmd: ethtool rxnfc command
2073 *
2074 * Returns Success if the command is supported.
2075 **/
2076static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2077{
2078 struct i40e_netdev_priv *np = netdev_priv(netdev);
2079 struct i40e_vsi *vsi = np->vsi;
2080 struct i40e_pf *pf = vsi->back;
2081 int ret = -EOPNOTSUPP;
2082
2083 switch (cmd->cmd) {
2084 case ETHTOOL_SRXFH:
2085 ret = i40e_set_rss_hash_opt(pf, cmd);
2086 break;
2087 case ETHTOOL_SRXCLSRLINS:
1eaa3840 2088 ret = i40e_add_fdir_ethtool(vsi, cmd);
c7d05ca8
JB
2089 break;
2090 case ETHTOOL_SRXCLSRLDEL:
17a73f6b 2091 ret = i40e_del_fdir_entry(vsi, cmd);
c7d05ca8
JB
2092 break;
2093 default:
2094 break;
2095 }
2096
2097 return ret;
2098}
2099
4b7820ca
ASJ
2100/**
2101 * i40e_max_channels - get Max number of combined channels supported
2102 * @vsi: vsi pointer
2103 **/
2104static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2105{
2106 /* TODO: This code assumes DCB and FD is disabled for now. */
2107 return vsi->alloc_queue_pairs;
2108}
2109
2110/**
2111 * i40e_get_channels - Get the current channels enabled and max supported etc.
2112 * @netdev: network interface device structure
2113 * @ch: ethtool channels structure
2114 *
2115 * We don't support separate tx and rx queues as channels. The other count
2116 * represents how many queues are being used for control. max_combined counts
2117 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2118 * q_vectors since we support a lot more queue pairs than q_vectors.
2119 **/
2120static void i40e_get_channels(struct net_device *dev,
2121 struct ethtool_channels *ch)
2122{
2123 struct i40e_netdev_priv *np = netdev_priv(dev);
2124 struct i40e_vsi *vsi = np->vsi;
2125 struct i40e_pf *pf = vsi->back;
2126
2127 /* report maximum channels */
2128 ch->max_combined = i40e_max_channels(vsi);
2129
2130 /* report info for other vector */
60ea5f83 2131 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
4b7820ca
ASJ
2132 ch->max_other = ch->other_count;
2133
2134 /* Note: This code assumes DCB is disabled for now. */
2135 ch->combined_count = vsi->num_queue_pairs;
2136}
2137
2138/**
2139 * i40e_set_channels - Set the new channels count.
2140 * @netdev: network interface device structure
2141 * @ch: ethtool channels structure
2142 *
2143 * The new channels count may not be the same as requested by the user
2144 * since it gets rounded down to a power of 2 value.
2145 **/
2146static int i40e_set_channels(struct net_device *dev,
2147 struct ethtool_channels *ch)
2148{
2149 struct i40e_netdev_priv *np = netdev_priv(dev);
2150 unsigned int count = ch->combined_count;
2151 struct i40e_vsi *vsi = np->vsi;
2152 struct i40e_pf *pf = vsi->back;
2153 int new_count;
2154
2155 /* We do not support setting channels for any other VSI at present */
2156 if (vsi->type != I40E_VSI_MAIN)
2157 return -EINVAL;
2158
2159 /* verify they are not requesting separate vectors */
2160 if (!count || ch->rx_count || ch->tx_count)
2161 return -EINVAL;
2162
2163 /* verify other_count has not changed */
60ea5f83 2164 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
4b7820ca
ASJ
2165 return -EINVAL;
2166
2167 /* verify the number of channels does not exceed hardware limits */
2168 if (count > i40e_max_channels(vsi))
2169 return -EINVAL;
2170
2171 /* update feature limits from largest to smallest supported values */
2172 /* TODO: Flow director limit, DCB etc */
2173
2174 /* cap RSS limit */
2175 if (count > pf->rss_size_max)
2176 count = pf->rss_size_max;
2177
2178 /* use rss_reconfig to rebuild with new queue count and update traffic
2179 * class queue mapping
2180 */
2181 new_count = i40e_reconfig_rss_queues(pf, count);
5f90f422 2182 if (new_count > 0)
4b7820ca
ASJ
2183 return 0;
2184 else
2185 return -EINVAL;
2186}
2187
c7d05ca8
JB
2188static const struct ethtool_ops i40e_ethtool_ops = {
2189 .get_settings = i40e_get_settings,
bf9c7141 2190 .set_settings = i40e_set_settings,
c7d05ca8
JB
2191 .get_drvinfo = i40e_get_drvinfo,
2192 .get_regs_len = i40e_get_regs_len,
2193 .get_regs = i40e_get_regs,
2194 .nway_reset = i40e_nway_reset,
2195 .get_link = ethtool_op_get_link,
2196 .get_wol = i40e_get_wol,
8e2773ae 2197 .set_wol = i40e_set_wol,
cd552cb4 2198 .set_eeprom = i40e_set_eeprom,
c7d05ca8
JB
2199 .get_eeprom_len = i40e_get_eeprom_len,
2200 .get_eeprom = i40e_get_eeprom,
2201 .get_ringparam = i40e_get_ringparam,
2202 .set_ringparam = i40e_set_ringparam,
2203 .get_pauseparam = i40e_get_pauseparam,
2becc35a 2204 .set_pauseparam = i40e_set_pauseparam,
c7d05ca8
JB
2205 .get_msglevel = i40e_get_msglevel,
2206 .set_msglevel = i40e_set_msglevel,
2207 .get_rxnfc = i40e_get_rxnfc,
2208 .set_rxnfc = i40e_set_rxnfc,
2209 .self_test = i40e_diag_test,
2210 .get_strings = i40e_get_strings,
2211 .set_phys_id = i40e_set_phys_id,
2212 .get_sset_count = i40e_get_sset_count,
2213 .get_ethtool_stats = i40e_get_ethtool_stats,
2214 .get_coalesce = i40e_get_coalesce,
2215 .set_coalesce = i40e_set_coalesce,
4b7820ca
ASJ
2216 .get_channels = i40e_get_channels,
2217 .set_channels = i40e_set_channels,
c7d05ca8
JB
2218 .get_ts_info = i40e_get_ts_info,
2219};
2220
2221void i40e_set_ethtool_ops(struct net_device *netdev)
2222{
7ad24ea4 2223 netdev->ethtool_ops = &i40e_ethtool_ops;
c7d05ca8 2224}
This page took 0.219266 seconds and 5 git commands to generate.