]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/intel/i40e/i40e_ethtool.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/next...
[karo-tx-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_SR4:
277                 ecmd->supported = SUPPORTED_40000baseSR4_Full;
278                 break;
279         case I40E_PHY_TYPE_40GBASE_LR4:
280                 ecmd->supported = SUPPORTED_40000baseLR4_Full;
281                 break;
282         case I40E_PHY_TYPE_10GBASE_SR:
283         case I40E_PHY_TYPE_10GBASE_LR:
284         case I40E_PHY_TYPE_1000BASE_SX:
285         case I40E_PHY_TYPE_1000BASE_LX:
286                 ecmd->supported = SUPPORTED_10000baseT_Full;
287                 if (hw_link_info->module_type[2] &
288                     I40E_MODULE_TYPE_1000BASE_SX ||
289                     hw_link_info->module_type[2] &
290                     I40E_MODULE_TYPE_1000BASE_LX) {
291                         ecmd->supported |= SUPPORTED_1000baseT_Full;
292                         if (hw_link_info->requested_speeds &
293                             I40E_LINK_SPEED_1GB)
294                                 ecmd->advertising |= ADVERTISED_1000baseT_Full;
295                 }
296                 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
297                         ecmd->advertising |= ADVERTISED_10000baseT_Full;
298                 break;
299         case I40E_PHY_TYPE_10GBASE_T:
300         case I40E_PHY_TYPE_1000BASE_T:
301         case I40E_PHY_TYPE_100BASE_TX:
302                 ecmd->supported = SUPPORTED_Autoneg |
303                                   SUPPORTED_10000baseT_Full |
304                                   SUPPORTED_1000baseT_Full |
305                                   SUPPORTED_100baseT_Full;
306                 ecmd->advertising = ADVERTISED_Autoneg;
307                 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
308                         ecmd->advertising |= ADVERTISED_10000baseT_Full;
309                 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
310                         ecmd->advertising |= ADVERTISED_1000baseT_Full;
311                 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
312                         ecmd->advertising |= ADVERTISED_100baseT_Full;
313                 break;
314         case I40E_PHY_TYPE_10GBASE_CR1_CU:
315         case I40E_PHY_TYPE_10GBASE_CR1:
316                 ecmd->supported = SUPPORTED_Autoneg |
317                                   SUPPORTED_10000baseT_Full;
318                 ecmd->advertising = ADVERTISED_Autoneg |
319                                     ADVERTISED_10000baseT_Full;
320                 break;
321         case I40E_PHY_TYPE_XAUI:
322         case I40E_PHY_TYPE_XFI:
323         case I40E_PHY_TYPE_SFI:
324         case I40E_PHY_TYPE_10GBASE_SFPP_CU:
325         case I40E_PHY_TYPE_10GBASE_AOC:
326                 ecmd->supported = SUPPORTED_10000baseT_Full;
327                 break;
328         case I40E_PHY_TYPE_SGMII:
329                 ecmd->supported = SUPPORTED_Autoneg |
330                                   SUPPORTED_1000baseT_Full |
331                                   SUPPORTED_100baseT_Full;
332                 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
333                         ecmd->advertising |= ADVERTISED_1000baseT_Full;
334                 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
335                         ecmd->advertising |= ADVERTISED_100baseT_Full;
336                 break;
337         /* Backplane is set based on supported phy types in get_settings
338          * so don't set anything here but don't warn either
339          */
340         case I40E_PHY_TYPE_40GBASE_KR4:
341         case I40E_PHY_TYPE_20GBASE_KR2:
342         case I40E_PHY_TYPE_10GBASE_KR:
343         case I40E_PHY_TYPE_10GBASE_KX4:
344         case I40E_PHY_TYPE_1000BASE_KX:
345                 break;
346         default:
347                 /* if we got here and link is up something bad is afoot */
348                 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
349                             hw_link_info->phy_type);
350         }
351
352         /* Set speed and duplex */
353         switch (link_speed) {
354         case I40E_LINK_SPEED_40GB:
355                 ethtool_cmd_speed_set(ecmd, SPEED_40000);
356                 break;
357         case I40E_LINK_SPEED_20GB:
358                 ethtool_cmd_speed_set(ecmd, SPEED_20000);
359                 break;
360         case I40E_LINK_SPEED_10GB:
361                 ethtool_cmd_speed_set(ecmd, SPEED_10000);
362                 break;
363         case I40E_LINK_SPEED_1GB:
364                 ethtool_cmd_speed_set(ecmd, SPEED_1000);
365                 break;
366         case I40E_LINK_SPEED_100MB:
367                 ethtool_cmd_speed_set(ecmd, SPEED_100);
368                 break;
369         default:
370                 break;
371         }
372         ecmd->duplex = DUPLEX_FULL;
373 }
374
375 /**
376  * i40e_get_settings_link_down - Get the Link settings for when link is down
377  * @hw: hw structure
378  * @ecmd: ethtool command to fill in
379  *
380  * Reports link settings that can be determined when link is down
381  **/
382 static void i40e_get_settings_link_down(struct i40e_hw *hw,
383                                         struct ethtool_cmd *ecmd)
384 {
385         enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
386
387         /* link is down and the driver needs to fall back on
388          * supported phy types to figure out what info to display
389          */
390         ecmd->supported = 0x0;
391         ecmd->advertising = 0x0;
392         if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
393                 ecmd->supported |= SUPPORTED_Autoneg |
394                                    SUPPORTED_1000baseT_Full |
395                                    SUPPORTED_100baseT_Full;
396                 ecmd->advertising |= ADVERTISED_Autoneg |
397                                      ADVERTISED_1000baseT_Full |
398                                      ADVERTISED_100baseT_Full;
399         }
400         if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
401             phy_types & I40E_CAP_PHY_TYPE_XFI ||
402             phy_types & I40E_CAP_PHY_TYPE_SFI ||
403             phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
404             phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
405                 ecmd->supported |= SUPPORTED_10000baseT_Full;
406         if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
407             phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
408             phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
409             phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
410             phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
411                 ecmd->supported |= SUPPORTED_Autoneg |
412                                    SUPPORTED_10000baseT_Full;
413                 ecmd->advertising |= ADVERTISED_Autoneg |
414                                      ADVERTISED_10000baseT_Full;
415         }
416         if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
417             phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
418             phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
419                 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
420         if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
421             phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
422                 ecmd->supported |= SUPPORTED_Autoneg |
423                                   SUPPORTED_40000baseCR4_Full;
424                 ecmd->advertising |= ADVERTISED_Autoneg |
425                                     ADVERTISED_40000baseCR4_Full;
426         }
427         if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
428                 ecmd->supported |= SUPPORTED_Autoneg |
429                                    SUPPORTED_100baseT_Full;
430                 ecmd->advertising |= ADVERTISED_Autoneg |
431                                      ADVERTISED_100baseT_Full;
432         }
433         if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
434             phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
435             phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
436             phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
437                 ecmd->supported |= SUPPORTED_Autoneg |
438                                    SUPPORTED_1000baseT_Full;
439                 ecmd->advertising |= ADVERTISED_Autoneg |
440                                      ADVERTISED_1000baseT_Full;
441         }
442         if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
443                 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
444         if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
445                 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
446
447         /* With no link speed and duplex are unknown */
448         ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
449         ecmd->duplex = DUPLEX_UNKNOWN;
450 }
451
452 /**
453  * i40e_get_settings - Get Link Speed and Duplex settings
454  * @netdev: network interface device structure
455  * @ecmd: ethtool command
456  *
457  * Reports speed/duplex settings based on media_type
458  **/
459 static int i40e_get_settings(struct net_device *netdev,
460                              struct ethtool_cmd *ecmd)
461 {
462         struct i40e_netdev_priv *np = netdev_priv(netdev);
463         struct i40e_pf *pf = np->vsi->back;
464         struct i40e_hw *hw = &pf->hw;
465         struct i40e_link_status *hw_link_info = &hw->phy.link_info;
466         bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
467
468         if (link_up)
469                 i40e_get_settings_link_up(hw, ecmd, netdev);
470         else
471                 i40e_get_settings_link_down(hw, ecmd);
472
473         /* Now set the settings that don't rely on link being up/down */
474
475         /* For backplane, supported and advertised are only reliant on the
476          * phy types the NVM specifies are supported.
477          */
478         if (hw->device_id == I40E_DEV_ID_KX_B ||
479             hw->device_id == I40E_DEV_ID_KX_C ||
480             hw->device_id == I40E_DEV_ID_20G_KR2 ||
481             hw->device_id ==  I40E_DEV_ID_20G_KR2_A) {
482                 ecmd->supported = SUPPORTED_Autoneg;
483                 ecmd->advertising = ADVERTISED_Autoneg;
484                 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
485                         ecmd->supported |= SUPPORTED_40000baseKR4_Full;
486                         ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
487                 }
488                 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
489                         ecmd->supported |= SUPPORTED_20000baseKR2_Full;
490                         ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
491                 }
492                 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
493                         ecmd->supported |= SUPPORTED_10000baseKR_Full;
494                         ecmd->advertising |= ADVERTISED_10000baseKR_Full;
495                 }
496                 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
497                         ecmd->supported |= SUPPORTED_10000baseKX4_Full;
498                         ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
499                 }
500                 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
501                         ecmd->supported |= SUPPORTED_1000baseKX_Full;
502                         ecmd->advertising |= ADVERTISED_1000baseKX_Full;
503                 }
504         }
505
506         /* Set autoneg settings */
507         ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
508                           AUTONEG_ENABLE : AUTONEG_DISABLE);
509
510         switch (hw->phy.media_type) {
511         case I40E_MEDIA_TYPE_BACKPLANE:
512                 ecmd->supported |= SUPPORTED_Autoneg |
513                                    SUPPORTED_Backplane;
514                 ecmd->advertising |= ADVERTISED_Autoneg |
515                                      ADVERTISED_Backplane;
516                 ecmd->port = PORT_NONE;
517                 break;
518         case I40E_MEDIA_TYPE_BASET:
519                 ecmd->supported |= SUPPORTED_TP;
520                 ecmd->advertising |= ADVERTISED_TP;
521                 ecmd->port = PORT_TP;
522                 break;
523         case I40E_MEDIA_TYPE_DA:
524         case I40E_MEDIA_TYPE_CX4:
525                 ecmd->supported |= SUPPORTED_FIBRE;
526                 ecmd->advertising |= ADVERTISED_FIBRE;
527                 ecmd->port = PORT_DA;
528                 break;
529         case I40E_MEDIA_TYPE_FIBER:
530                 ecmd->supported |= SUPPORTED_FIBRE;
531                 ecmd->port = PORT_FIBRE;
532                 break;
533         case I40E_MEDIA_TYPE_UNKNOWN:
534         default:
535                 ecmd->port = PORT_OTHER;
536                 break;
537         }
538
539         /* Set transceiver */
540         ecmd->transceiver = XCVR_EXTERNAL;
541
542         /* Set flow control settings */
543         ecmd->supported |= SUPPORTED_Pause;
544
545         switch (hw->fc.requested_mode) {
546         case I40E_FC_FULL:
547                 ecmd->advertising |= ADVERTISED_Pause;
548                 break;
549         case I40E_FC_TX_PAUSE:
550                 ecmd->advertising |= ADVERTISED_Asym_Pause;
551                 break;
552         case I40E_FC_RX_PAUSE:
553                 ecmd->advertising |= (ADVERTISED_Pause |
554                                       ADVERTISED_Asym_Pause);
555                 break;
556         default:
557                 ecmd->advertising &= ~(ADVERTISED_Pause |
558                                        ADVERTISED_Asym_Pause);
559                 break;
560         }
561
562         return 0;
563 }
564
565 /**
566  * i40e_set_settings - Set Speed and Duplex
567  * @netdev: network interface device structure
568  * @ecmd: ethtool command
569  *
570  * Set speed/duplex per media_types advertised/forced
571  **/
572 static int i40e_set_settings(struct net_device *netdev,
573                              struct ethtool_cmd *ecmd)
574 {
575         struct i40e_netdev_priv *np = netdev_priv(netdev);
576         struct i40e_aq_get_phy_abilities_resp abilities;
577         struct i40e_aq_set_phy_config config;
578         struct i40e_pf *pf = np->vsi->back;
579         struct i40e_vsi *vsi = np->vsi;
580         struct i40e_hw *hw = &pf->hw;
581         struct ethtool_cmd safe_ecmd;
582         i40e_status status = 0;
583         bool change = false;
584         int err = 0;
585         u8 autoneg;
586         u32 advertise;
587
588         /* Changing port settings is not supported if this isn't the
589          * port's controlling PF
590          */
591         if (hw->partition_id != 1) {
592                 i40e_partition_setting_complaint(pf);
593                 return -EOPNOTSUPP;
594         }
595
596         if (vsi != pf->vsi[pf->lan_vsi])
597                 return -EOPNOTSUPP;
598
599         if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
600             hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
601             hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
602             hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
603                 return -EOPNOTSUPP;
604
605         if (hw->device_id == I40E_DEV_ID_KX_B ||
606             hw->device_id == I40E_DEV_ID_KX_C ||
607             hw->device_id == I40E_DEV_ID_20G_KR2 ||
608             hw->device_id == I40E_DEV_ID_20G_KR2_A) {
609                 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
610                 return -EOPNOTSUPP;
611         }
612
613         /* get our own copy of the bits to check against */
614         memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
615         i40e_get_settings(netdev, &safe_ecmd);
616
617         /* save autoneg and speed out of ecmd */
618         autoneg = ecmd->autoneg;
619         advertise = ecmd->advertising;
620
621         /* set autoneg and speed back to what they currently are */
622         ecmd->autoneg = safe_ecmd.autoneg;
623         ecmd->advertising = safe_ecmd.advertising;
624
625         ecmd->cmd = safe_ecmd.cmd;
626         /* If ecmd and safe_ecmd are not the same now, then they are
627          * trying to set something that we do not support
628          */
629         if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
630                 return -EOPNOTSUPP;
631
632         while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
633                 usleep_range(1000, 2000);
634
635         /* Get the current phy config */
636         status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
637                                               NULL);
638         if (status)
639                 return -EAGAIN;
640
641         /* Copy abilities to config in case autoneg is not
642          * set below
643          */
644         memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
645         config.abilities = abilities.abilities;
646
647         /* Check autoneg */
648         if (autoneg == AUTONEG_ENABLE) {
649                 /* If autoneg is not supported, return error */
650                 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
651                         netdev_info(netdev, "Autoneg not supported on this phy\n");
652                         return -EINVAL;
653                 }
654                 /* If autoneg was not already enabled */
655                 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
656                         config.abilities = abilities.abilities |
657                                            I40E_AQ_PHY_ENABLE_AN;
658                         change = true;
659                 }
660         } else {
661                 /* If autoneg is supported 10GBASE_T is the only phy that
662                  * can disable it, so otherwise return error
663                  */
664                 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
665                     hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
666                         netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
667                         return -EINVAL;
668                 }
669                 /* If autoneg is currently enabled */
670                 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
671                         config.abilities = abilities.abilities &
672                                            ~I40E_AQ_PHY_ENABLE_AN;
673                         change = true;
674                 }
675         }
676
677         if (advertise & ~safe_ecmd.supported)
678                 return -EINVAL;
679
680         if (advertise & ADVERTISED_100baseT_Full)
681                 config.link_speed |= I40E_LINK_SPEED_100MB;
682         if (advertise & ADVERTISED_1000baseT_Full ||
683             advertise & ADVERTISED_1000baseKX_Full)
684                 config.link_speed |= I40E_LINK_SPEED_1GB;
685         if (advertise & ADVERTISED_10000baseT_Full ||
686             advertise & ADVERTISED_10000baseKX4_Full ||
687             advertise & ADVERTISED_10000baseKR_Full)
688                 config.link_speed |= I40E_LINK_SPEED_10GB;
689         if (advertise & ADVERTISED_20000baseKR2_Full)
690                 config.link_speed |= I40E_LINK_SPEED_20GB;
691         if (advertise & ADVERTISED_40000baseKR4_Full ||
692             advertise & ADVERTISED_40000baseCR4_Full ||
693             advertise & ADVERTISED_40000baseSR4_Full ||
694             advertise & ADVERTISED_40000baseLR4_Full)
695                 config.link_speed |= I40E_LINK_SPEED_40GB;
696
697         /* If speed didn't get set, set it to what it currently is.
698          * This is needed because if advertise is 0 (as it is when autoneg
699          * is disabled) then speed won't get set.
700          */
701         if (!config.link_speed)
702                 config.link_speed = abilities.link_speed;
703
704         if (change || (abilities.link_speed != config.link_speed)) {
705                 /* copy over the rest of the abilities */
706                 config.phy_type = abilities.phy_type;
707                 config.eee_capability = abilities.eee_capability;
708                 config.eeer = abilities.eeer_val;
709                 config.low_power_ctrl = abilities.d3_lpan;
710
711                 /* save the requested speeds */
712                 hw->phy.link_info.requested_speeds = config.link_speed;
713                 /* set link and auto negotiation so changes take effect */
714                 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
715                 /* If link is up put link down */
716                 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
717                         /* Tell the OS link is going down, the link will go
718                          * back up when fw says it is ready asynchronously
719                          */
720                         i40e_print_link_message(vsi, false);
721                         netif_carrier_off(netdev);
722                         netif_tx_stop_all_queues(netdev);
723                 }
724
725                 /* make the aq call */
726                 status = i40e_aq_set_phy_config(hw, &config, NULL);
727                 if (status) {
728                         netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
729                                     i40e_stat_str(hw, status),
730                                     i40e_aq_str(hw, hw->aq.asq_last_status));
731                         return -EAGAIN;
732                 }
733
734                 status = i40e_update_link_info(hw);
735                 if (status)
736                         netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
737                                     i40e_stat_str(hw, status),
738                                     i40e_aq_str(hw, hw->aq.asq_last_status));
739
740         } else {
741                 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
742         }
743
744         return err;
745 }
746
747 static int i40e_nway_reset(struct net_device *netdev)
748 {
749         /* restart autonegotiation */
750         struct i40e_netdev_priv *np = netdev_priv(netdev);
751         struct i40e_pf *pf = np->vsi->back;
752         struct i40e_hw *hw = &pf->hw;
753         bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
754         i40e_status ret = 0;
755
756         ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
757         if (ret) {
758                 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
759                             i40e_stat_str(hw, ret),
760                             i40e_aq_str(hw, hw->aq.asq_last_status));
761                 return -EIO;
762         }
763
764         return 0;
765 }
766
767 /**
768  * i40e_get_pauseparam -  Get Flow Control status
769  * Return tx/rx-pause status
770  **/
771 static void i40e_get_pauseparam(struct net_device *netdev,
772                                 struct ethtool_pauseparam *pause)
773 {
774         struct i40e_netdev_priv *np = netdev_priv(netdev);
775         struct i40e_pf *pf = np->vsi->back;
776         struct i40e_hw *hw = &pf->hw;
777         struct i40e_link_status *hw_link_info = &hw->phy.link_info;
778         struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
779
780         pause->autoneg =
781                 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
782                   AUTONEG_ENABLE : AUTONEG_DISABLE);
783
784         /* PFC enabled so report LFC as off */
785         if (dcbx_cfg->pfc.pfcenable) {
786                 pause->rx_pause = 0;
787                 pause->tx_pause = 0;
788                 return;
789         }
790
791         if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
792                 pause->rx_pause = 1;
793         } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
794                 pause->tx_pause = 1;
795         } else if (hw->fc.current_mode == I40E_FC_FULL) {
796                 pause->rx_pause = 1;
797                 pause->tx_pause = 1;
798         }
799 }
800
801 /**
802  * i40e_set_pauseparam - Set Flow Control parameter
803  * @netdev: network interface device structure
804  * @pause: return tx/rx flow control status
805  **/
806 static int i40e_set_pauseparam(struct net_device *netdev,
807                                struct ethtool_pauseparam *pause)
808 {
809         struct i40e_netdev_priv *np = netdev_priv(netdev);
810         struct i40e_pf *pf = np->vsi->back;
811         struct i40e_vsi *vsi = np->vsi;
812         struct i40e_hw *hw = &pf->hw;
813         struct i40e_link_status *hw_link_info = &hw->phy.link_info;
814         struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
815         bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
816         i40e_status status;
817         u8 aq_failures;
818         int err = 0;
819
820         /* Changing the port's flow control is not supported if this isn't the
821          * port's controlling PF
822          */
823         if (hw->partition_id != 1) {
824                 i40e_partition_setting_complaint(pf);
825                 return -EOPNOTSUPP;
826         }
827
828         if (vsi != pf->vsi[pf->lan_vsi])
829                 return -EOPNOTSUPP;
830
831         if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
832             AUTONEG_ENABLE : AUTONEG_DISABLE)) {
833                 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
834                 return -EOPNOTSUPP;
835         }
836
837         /* If we have link and don't have autoneg */
838         if (!test_bit(__I40E_DOWN, &pf->state) &&
839             !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
840                 /* Send message that it might not necessarily work*/
841                 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
842         }
843
844         if (dcbx_cfg->pfc.pfcenable) {
845                 netdev_info(netdev,
846                             "Priority flow control enabled. Cannot set link flow control.\n");
847                 return -EOPNOTSUPP;
848         }
849
850         if (pause->rx_pause && pause->tx_pause)
851                 hw->fc.requested_mode = I40E_FC_FULL;
852         else if (pause->rx_pause && !pause->tx_pause)
853                 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
854         else if (!pause->rx_pause && pause->tx_pause)
855                 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
856         else if (!pause->rx_pause && !pause->tx_pause)
857                 hw->fc.requested_mode = I40E_FC_NONE;
858         else
859                  return -EINVAL;
860
861         /* Tell the OS link is going down, the link will go back up when fw
862          * says it is ready asynchronously
863          */
864         i40e_print_link_message(vsi, false);
865         netif_carrier_off(netdev);
866         netif_tx_stop_all_queues(netdev);
867
868         /* Set the fc mode and only restart an if link is up*/
869         status = i40e_set_fc(hw, &aq_failures, link_up);
870
871         if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
872                 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
873                             i40e_stat_str(hw, status),
874                             i40e_aq_str(hw, hw->aq.asq_last_status));
875                 err = -EAGAIN;
876         }
877         if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
878                 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
879                             i40e_stat_str(hw, status),
880                             i40e_aq_str(hw, hw->aq.asq_last_status));
881                 err = -EAGAIN;
882         }
883         if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
884                 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
885                             i40e_stat_str(hw, status),
886                             i40e_aq_str(hw, hw->aq.asq_last_status));
887                 err = -EAGAIN;
888         }
889
890         if (!test_bit(__I40E_DOWN, &pf->state)) {
891                 /* Give it a little more time to try to come back */
892                 msleep(75);
893                 if (!test_bit(__I40E_DOWN, &pf->state))
894                         return i40e_nway_reset(netdev);
895         }
896
897         return err;
898 }
899
900 static u32 i40e_get_msglevel(struct net_device *netdev)
901 {
902         struct i40e_netdev_priv *np = netdev_priv(netdev);
903         struct i40e_pf *pf = np->vsi->back;
904
905         return pf->msg_enable;
906 }
907
908 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
909 {
910         struct i40e_netdev_priv *np = netdev_priv(netdev);
911         struct i40e_pf *pf = np->vsi->back;
912
913         if (I40E_DEBUG_USER & data)
914                 pf->hw.debug_mask = data;
915         pf->msg_enable = data;
916 }
917
918 static int i40e_get_regs_len(struct net_device *netdev)
919 {
920         int reg_count = 0;
921         int i;
922
923         for (i = 0; i40e_reg_list[i].offset != 0; i++)
924                 reg_count += i40e_reg_list[i].elements;
925
926         return reg_count * sizeof(u32);
927 }
928
929 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
930                           void *p)
931 {
932         struct i40e_netdev_priv *np = netdev_priv(netdev);
933         struct i40e_pf *pf = np->vsi->back;
934         struct i40e_hw *hw = &pf->hw;
935         u32 *reg_buf = p;
936         int i, j, ri;
937         u32 reg;
938
939         /* Tell ethtool which driver-version-specific regs output we have.
940          *
941          * At some point, if we have ethtool doing special formatting of
942          * this data, it will rely on this version number to know how to
943          * interpret things.  Hence, this needs to be updated if/when the
944          * diags register table is changed.
945          */
946         regs->version = 1;
947
948         /* loop through the diags reg table for what to print */
949         ri = 0;
950         for (i = 0; i40e_reg_list[i].offset != 0; i++) {
951                 for (j = 0; j < i40e_reg_list[i].elements; j++) {
952                         reg = i40e_reg_list[i].offset
953                                 + (j * i40e_reg_list[i].stride);
954                         reg_buf[ri++] = rd32(hw, reg);
955                 }
956         }
957
958 }
959
960 static int i40e_get_eeprom(struct net_device *netdev,
961                            struct ethtool_eeprom *eeprom, u8 *bytes)
962 {
963         struct i40e_netdev_priv *np = netdev_priv(netdev);
964         struct i40e_hw *hw = &np->vsi->back->hw;
965         struct i40e_pf *pf = np->vsi->back;
966         int ret_val = 0, len, offset;
967         u8 *eeprom_buff;
968         u16 i, sectors;
969         bool last;
970         u32 magic;
971
972 #define I40E_NVM_SECTOR_SIZE  4096
973         if (eeprom->len == 0)
974                 return -EINVAL;
975
976         /* check for NVMUpdate access method */
977         magic = hw->vendor_id | (hw->device_id << 16);
978         if (eeprom->magic && eeprom->magic != magic) {
979                 struct i40e_nvm_access *cmd;
980                 int errno;
981
982                 /* make sure it is the right magic for NVMUpdate */
983                 if ((eeprom->magic >> 16) != hw->device_id)
984                         return -EINVAL;
985
986                 cmd = (struct i40e_nvm_access *)eeprom;
987                 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
988                 if (ret_val &&
989                     ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
990                      (hw->debug_mask & I40E_DEBUG_NVM)))
991                         dev_info(&pf->pdev->dev,
992                                  "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
993                                  ret_val, hw->aq.asq_last_status, errno,
994                                  (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
995                                  cmd->offset, cmd->data_size);
996
997                 return errno;
998         }
999
1000         /* normal ethtool get_eeprom support */
1001         eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1002
1003         eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
1004         if (!eeprom_buff)
1005                 return -ENOMEM;
1006
1007         ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1008         if (ret_val) {
1009                 dev_info(&pf->pdev->dev,
1010                          "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1011                          ret_val, hw->aq.asq_last_status);
1012                 goto free_buff;
1013         }
1014
1015         sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1016         sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1017         len = I40E_NVM_SECTOR_SIZE;
1018         last = false;
1019         for (i = 0; i < sectors; i++) {
1020                 if (i == (sectors - 1)) {
1021                         len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1022                         last = true;
1023                 }
1024                 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1025                 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
1026                                 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
1027                                 last, NULL);
1028                 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
1029                         dev_info(&pf->pdev->dev,
1030                                  "read NVM failed, invalid offset 0x%x\n",
1031                                  offset);
1032                         break;
1033                 } else if (ret_val &&
1034                            hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1035                         dev_info(&pf->pdev->dev,
1036                                  "read NVM failed, access, offset 0x%x\n",
1037                                  offset);
1038                         break;
1039                 } else if (ret_val) {
1040                         dev_info(&pf->pdev->dev,
1041                                  "read NVM failed offset %d err=%d status=0x%x\n",
1042                                  offset, ret_val, hw->aq.asq_last_status);
1043                         break;
1044                 }
1045         }
1046
1047         i40e_release_nvm(hw);
1048         memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
1049 free_buff:
1050         kfree(eeprom_buff);
1051         return ret_val;
1052 }
1053
1054 static int i40e_get_eeprom_len(struct net_device *netdev)
1055 {
1056         struct i40e_netdev_priv *np = netdev_priv(netdev);
1057         struct i40e_hw *hw = &np->vsi->back->hw;
1058         u32 val;
1059
1060         val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1061                 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1062                 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1063         /* register returns value in power of 2, 64Kbyte chunks. */
1064         val = (64 * 1024) * BIT(val);
1065         return val;
1066 }
1067
1068 static int i40e_set_eeprom(struct net_device *netdev,
1069                            struct ethtool_eeprom *eeprom, u8 *bytes)
1070 {
1071         struct i40e_netdev_priv *np = netdev_priv(netdev);
1072         struct i40e_hw *hw = &np->vsi->back->hw;
1073         struct i40e_pf *pf = np->vsi->back;
1074         struct i40e_nvm_access *cmd;
1075         int ret_val = 0;
1076         int errno;
1077         u32 magic;
1078
1079         /* normal ethtool set_eeprom is not supported */
1080         magic = hw->vendor_id | (hw->device_id << 16);
1081         if (eeprom->magic == magic)
1082                 return -EOPNOTSUPP;
1083
1084         /* check for NVMUpdate access method */
1085         if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1086                 return -EINVAL;
1087
1088         if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1089             test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1090                 return -EBUSY;
1091
1092         cmd = (struct i40e_nvm_access *)eeprom;
1093         ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1094         if (ret_val &&
1095             ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1096               hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1097              (hw->debug_mask & I40E_DEBUG_NVM)))
1098                 dev_info(&pf->pdev->dev,
1099                          "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1100                          ret_val, hw->aq.asq_last_status, errno,
1101                          (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1102                          cmd->offset, cmd->data_size);
1103
1104         return errno;
1105 }
1106
1107 static void i40e_get_drvinfo(struct net_device *netdev,
1108                              struct ethtool_drvinfo *drvinfo)
1109 {
1110         struct i40e_netdev_priv *np = netdev_priv(netdev);
1111         struct i40e_vsi *vsi = np->vsi;
1112         struct i40e_pf *pf = vsi->back;
1113
1114         strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1115         strlcpy(drvinfo->version, i40e_driver_version_str,
1116                 sizeof(drvinfo->version));
1117         strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1118                 sizeof(drvinfo->fw_version));
1119         strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1120                 sizeof(drvinfo->bus_info));
1121         drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
1122 }
1123
1124 static void i40e_get_ringparam(struct net_device *netdev,
1125                                struct ethtool_ringparam *ring)
1126 {
1127         struct i40e_netdev_priv *np = netdev_priv(netdev);
1128         struct i40e_pf *pf = np->vsi->back;
1129         struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1130
1131         ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1132         ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1133         ring->rx_mini_max_pending = 0;
1134         ring->rx_jumbo_max_pending = 0;
1135         ring->rx_pending = vsi->rx_rings[0]->count;
1136         ring->tx_pending = vsi->tx_rings[0]->count;
1137         ring->rx_mini_pending = 0;
1138         ring->rx_jumbo_pending = 0;
1139 }
1140
1141 static int i40e_set_ringparam(struct net_device *netdev,
1142                               struct ethtool_ringparam *ring)
1143 {
1144         struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1145         struct i40e_netdev_priv *np = netdev_priv(netdev);
1146         struct i40e_vsi *vsi = np->vsi;
1147         struct i40e_pf *pf = vsi->back;
1148         u32 new_rx_count, new_tx_count;
1149         int i, err = 0;
1150
1151         if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1152                 return -EINVAL;
1153
1154         if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1155             ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1156             ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1157             ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1158                 netdev_info(netdev,
1159                             "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1160                             ring->tx_pending, ring->rx_pending,
1161                             I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1162                 return -EINVAL;
1163         }
1164
1165         new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1166         new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1167
1168         /* if nothing to do return success */
1169         if ((new_tx_count == vsi->tx_rings[0]->count) &&
1170             (new_rx_count == vsi->rx_rings[0]->count))
1171                 return 0;
1172
1173         while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1174                 usleep_range(1000, 2000);
1175
1176         if (!netif_running(vsi->netdev)) {
1177                 /* simple case - set for the next time the netdev is started */
1178                 for (i = 0; i < vsi->num_queue_pairs; i++) {
1179                         vsi->tx_rings[i]->count = new_tx_count;
1180                         vsi->rx_rings[i]->count = new_rx_count;
1181                 }
1182                 goto done;
1183         }
1184
1185         /* We can't just free everything and then setup again,
1186          * because the ISRs in MSI-X mode get passed pointers
1187          * to the Tx and Rx ring structs.
1188          */
1189
1190         /* alloc updated Tx resources */
1191         if (new_tx_count != vsi->tx_rings[0]->count) {
1192                 netdev_info(netdev,
1193                             "Changing Tx descriptor count from %d to %d.\n",
1194                             vsi->tx_rings[0]->count, new_tx_count);
1195                 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1196                                    sizeof(struct i40e_ring), GFP_KERNEL);
1197                 if (!tx_rings) {
1198                         err = -ENOMEM;
1199                         goto done;
1200                 }
1201
1202                 for (i = 0; i < vsi->num_queue_pairs; i++) {
1203                         /* clone ring and setup updated count */
1204                         tx_rings[i] = *vsi->tx_rings[i];
1205                         tx_rings[i].count = new_tx_count;
1206                         /* the desc and bi pointers will be reallocated in the
1207                          * setup call
1208                          */
1209                         tx_rings[i].desc = NULL;
1210                         tx_rings[i].rx_bi = NULL;
1211                         err = i40e_setup_tx_descriptors(&tx_rings[i]);
1212                         if (err) {
1213                                 while (i) {
1214                                         i--;
1215                                         i40e_free_tx_resources(&tx_rings[i]);
1216                                 }
1217                                 kfree(tx_rings);
1218                                 tx_rings = NULL;
1219
1220                                 goto done;
1221                         }
1222                 }
1223         }
1224
1225         /* alloc updated Rx resources */
1226         if (new_rx_count != vsi->rx_rings[0]->count) {
1227                 netdev_info(netdev,
1228                             "Changing Rx descriptor count from %d to %d\n",
1229                             vsi->rx_rings[0]->count, new_rx_count);
1230                 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1231                                    sizeof(struct i40e_ring), GFP_KERNEL);
1232                 if (!rx_rings) {
1233                         err = -ENOMEM;
1234                         goto free_tx;
1235                 }
1236
1237                 for (i = 0; i < vsi->num_queue_pairs; i++) {
1238                         /* clone ring and setup updated count */
1239                         rx_rings[i] = *vsi->rx_rings[i];
1240                         rx_rings[i].count = new_rx_count;
1241                         /* the desc and bi pointers will be reallocated in the
1242                          * setup call
1243                          */
1244                         rx_rings[i].desc = NULL;
1245                         rx_rings[i].rx_bi = NULL;
1246                         err = i40e_setup_rx_descriptors(&rx_rings[i]);
1247                         if (err) {
1248                                 while (i) {
1249                                         i--;
1250                                         i40e_free_rx_resources(&rx_rings[i]);
1251                                 }
1252                                 kfree(rx_rings);
1253                                 rx_rings = NULL;
1254
1255                                 goto free_tx;
1256                         }
1257                 }
1258         }
1259
1260         /* Bring interface down, copy in the new ring info,
1261          * then restore the interface
1262          */
1263         i40e_down(vsi);
1264
1265         if (tx_rings) {
1266                 for (i = 0; i < vsi->num_queue_pairs; i++) {
1267                         i40e_free_tx_resources(vsi->tx_rings[i]);
1268                         *vsi->tx_rings[i] = tx_rings[i];
1269                 }
1270                 kfree(tx_rings);
1271                 tx_rings = NULL;
1272         }
1273
1274         if (rx_rings) {
1275                 for (i = 0; i < vsi->num_queue_pairs; i++) {
1276                         i40e_free_rx_resources(vsi->rx_rings[i]);
1277                         *vsi->rx_rings[i] = rx_rings[i];
1278                 }
1279                 kfree(rx_rings);
1280                 rx_rings = NULL;
1281         }
1282
1283         i40e_up(vsi);
1284
1285 free_tx:
1286         /* error cleanup if the Rx allocations failed after getting Tx */
1287         if (tx_rings) {
1288                 for (i = 0; i < vsi->num_queue_pairs; i++)
1289                         i40e_free_tx_resources(&tx_rings[i]);
1290                 kfree(tx_rings);
1291                 tx_rings = NULL;
1292         }
1293
1294 done:
1295         clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1296
1297         return err;
1298 }
1299
1300 static int i40e_get_sset_count(struct net_device *netdev, int sset)
1301 {
1302         struct i40e_netdev_priv *np = netdev_priv(netdev);
1303         struct i40e_vsi *vsi = np->vsi;
1304         struct i40e_pf *pf = vsi->back;
1305
1306         switch (sset) {
1307         case ETH_SS_TEST:
1308                 return I40E_TEST_LEN;
1309         case ETH_SS_STATS:
1310                 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
1311                         int len = I40E_PF_STATS_LEN(netdev);
1312
1313                         if ((pf->lan_veb != I40E_NO_VEB) &&
1314                             (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
1315                                 len += I40E_VEB_STATS_TOTAL;
1316                         return len;
1317                 } else {
1318                         return I40E_VSI_STATS_LEN(netdev);
1319                 }
1320         case ETH_SS_PRIV_FLAGS:
1321                 return I40E_PRIV_FLAGS_STR_LEN;
1322         default:
1323                 return -EOPNOTSUPP;
1324         }
1325 }
1326
1327 static void i40e_get_ethtool_stats(struct net_device *netdev,
1328                                    struct ethtool_stats *stats, u64 *data)
1329 {
1330         struct i40e_netdev_priv *np = netdev_priv(netdev);
1331         struct i40e_ring *tx_ring, *rx_ring;
1332         struct i40e_vsi *vsi = np->vsi;
1333         struct i40e_pf *pf = vsi->back;
1334         int i = 0;
1335         char *p;
1336         int j;
1337         struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
1338         unsigned int start;
1339
1340         i40e_update_stats(vsi);
1341
1342         for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1343                 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1344                 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1345                         sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1346         }
1347         for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1348                 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1349                 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1350                             sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1351         }
1352 #ifdef I40E_FCOE
1353         for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1354                 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1355                 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1356                         sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1357         }
1358 #endif
1359         rcu_read_lock();
1360         for (j = 0; j < vsi->num_queue_pairs; j++) {
1361                 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
1362
1363                 if (!tx_ring)
1364                         continue;
1365
1366                 /* process Tx ring statistics */
1367                 do {
1368                         start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
1369                         data[i] = tx_ring->stats.packets;
1370                         data[i + 1] = tx_ring->stats.bytes;
1371                 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
1372                 i += 2;
1373
1374                 /* Rx ring is the 2nd half of the queue pair */
1375                 rx_ring = &tx_ring[1];
1376                 do {
1377                         start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
1378                         data[i] = rx_ring->stats.packets;
1379                         data[i + 1] = rx_ring->stats.bytes;
1380                 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
1381                 i += 2;
1382         }
1383         rcu_read_unlock();
1384         if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1385                 return;
1386
1387         if ((pf->lan_veb != I40E_NO_VEB) &&
1388             (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1389                 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1390
1391                 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1392                         p = (char *)veb;
1393                         p += i40e_gstrings_veb_stats[j].stat_offset;
1394                         data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1395                                      sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1396                 }
1397         }
1398         for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1399                 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1400                 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1401                              sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1402         }
1403         for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1404                 data[i++] = pf->stats.priority_xon_tx[j];
1405                 data[i++] = pf->stats.priority_xoff_tx[j];
1406         }
1407         for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1408                 data[i++] = pf->stats.priority_xon_rx[j];
1409                 data[i++] = pf->stats.priority_xoff_rx[j];
1410         }
1411         for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1412                 data[i++] = pf->stats.priority_xon_2_xoff[j];
1413 }
1414
1415 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1416                              u8 *data)
1417 {
1418         struct i40e_netdev_priv *np = netdev_priv(netdev);
1419         struct i40e_vsi *vsi = np->vsi;
1420         struct i40e_pf *pf = vsi->back;
1421         char *p = (char *)data;
1422         int i;
1423
1424         switch (stringset) {
1425         case ETH_SS_TEST:
1426                 for (i = 0; i < I40E_TEST_LEN; i++) {
1427                         memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1428                         data += ETH_GSTRING_LEN;
1429                 }
1430                 break;
1431         case ETH_SS_STATS:
1432                 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1433                         snprintf(p, ETH_GSTRING_LEN, "%s",
1434                                  i40e_gstrings_net_stats[i].stat_string);
1435                         p += ETH_GSTRING_LEN;
1436                 }
1437                 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1438                         snprintf(p, ETH_GSTRING_LEN, "%s",
1439                                  i40e_gstrings_misc_stats[i].stat_string);
1440                         p += ETH_GSTRING_LEN;
1441                 }
1442 #ifdef I40E_FCOE
1443                 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1444                         snprintf(p, ETH_GSTRING_LEN, "%s",
1445                                  i40e_gstrings_fcoe_stats[i].stat_string);
1446                         p += ETH_GSTRING_LEN;
1447                 }
1448 #endif
1449                 for (i = 0; i < vsi->num_queue_pairs; i++) {
1450                         snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1451                         p += ETH_GSTRING_LEN;
1452                         snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1453                         p += ETH_GSTRING_LEN;
1454                         snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1455                         p += ETH_GSTRING_LEN;
1456                         snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1457                         p += ETH_GSTRING_LEN;
1458                 }
1459                 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1460                         return;
1461
1462                 if ((pf->lan_veb != I40E_NO_VEB) &&
1463                     (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
1464                         for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1465                                 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1466                                         i40e_gstrings_veb_stats[i].stat_string);
1467                                 p += ETH_GSTRING_LEN;
1468                         }
1469                         for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1470                                 snprintf(p, ETH_GSTRING_LEN,
1471                                          "veb.tc_%u_tx_packets", i);
1472                                 p += ETH_GSTRING_LEN;
1473                                 snprintf(p, ETH_GSTRING_LEN,
1474                                          "veb.tc_%u_tx_bytes", i);
1475                                 p += ETH_GSTRING_LEN;
1476                                 snprintf(p, ETH_GSTRING_LEN,
1477                                          "veb.tc_%u_rx_packets", i);
1478                                 p += ETH_GSTRING_LEN;
1479                                 snprintf(p, ETH_GSTRING_LEN,
1480                                          "veb.tc_%u_rx_bytes", i);
1481                                 p += ETH_GSTRING_LEN;
1482                         }
1483                 }
1484                 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1485                         snprintf(p, ETH_GSTRING_LEN, "port.%s",
1486                                  i40e_gstrings_stats[i].stat_string);
1487                         p += ETH_GSTRING_LEN;
1488                 }
1489                 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1490                         snprintf(p, ETH_GSTRING_LEN,
1491                                  "port.tx_priority_%u_xon", i);
1492                         p += ETH_GSTRING_LEN;
1493                         snprintf(p, ETH_GSTRING_LEN,
1494                                  "port.tx_priority_%u_xoff", i);
1495                         p += ETH_GSTRING_LEN;
1496                 }
1497                 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1498                         snprintf(p, ETH_GSTRING_LEN,
1499                                  "port.rx_priority_%u_xon", i);
1500                         p += ETH_GSTRING_LEN;
1501                         snprintf(p, ETH_GSTRING_LEN,
1502                                  "port.rx_priority_%u_xoff", i);
1503                         p += ETH_GSTRING_LEN;
1504                 }
1505                 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1506                         snprintf(p, ETH_GSTRING_LEN,
1507                                  "port.rx_priority_%u_xon_2_xoff", i);
1508                         p += ETH_GSTRING_LEN;
1509                 }
1510                 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1511                 break;
1512         case ETH_SS_PRIV_FLAGS:
1513                 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1514                         memcpy(data, i40e_priv_flags_strings[i],
1515                                ETH_GSTRING_LEN);
1516                         data += ETH_GSTRING_LEN;
1517                 }
1518                 break;
1519         default:
1520                 break;
1521         }
1522 }
1523
1524 static int i40e_get_ts_info(struct net_device *dev,
1525                             struct ethtool_ts_info *info)
1526 {
1527         struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1528
1529         /* only report HW timestamping if PTP is enabled */
1530         if (!(pf->flags & I40E_FLAG_PTP))
1531                 return ethtool_op_get_ts_info(dev, info);
1532
1533         info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1534                                 SOF_TIMESTAMPING_RX_SOFTWARE |
1535                                 SOF_TIMESTAMPING_SOFTWARE |
1536                                 SOF_TIMESTAMPING_TX_HARDWARE |
1537                                 SOF_TIMESTAMPING_RX_HARDWARE |
1538                                 SOF_TIMESTAMPING_RAW_HARDWARE;
1539
1540         if (pf->ptp_clock)
1541                 info->phc_index = ptp_clock_index(pf->ptp_clock);
1542         else
1543                 info->phc_index = -1;
1544
1545         info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
1546
1547         info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1548                            BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1549                            BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
1550
1551         return 0;
1552 }
1553
1554 static int i40e_link_test(struct net_device *netdev, u64 *data)
1555 {
1556         struct i40e_netdev_priv *np = netdev_priv(netdev);
1557         struct i40e_pf *pf = np->vsi->back;
1558         i40e_status status;
1559         bool link_up = false;
1560
1561         netif_info(pf, hw, netdev, "link test\n");
1562         status = i40e_get_link_status(&pf->hw, &link_up);
1563         if (status) {
1564                 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1565                 *data = 1;
1566                 return *data;
1567         }
1568
1569         if (link_up)
1570                 *data = 0;
1571         else
1572                 *data = 1;
1573
1574         return *data;
1575 }
1576
1577 static int i40e_reg_test(struct net_device *netdev, u64 *data)
1578 {
1579         struct i40e_netdev_priv *np = netdev_priv(netdev);
1580         struct i40e_pf *pf = np->vsi->back;
1581
1582         netif_info(pf, hw, netdev, "register test\n");
1583         *data = i40e_diag_reg_test(&pf->hw);
1584
1585         return *data;
1586 }
1587
1588 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
1589 {
1590         struct i40e_netdev_priv *np = netdev_priv(netdev);
1591         struct i40e_pf *pf = np->vsi->back;
1592
1593         netif_info(pf, hw, netdev, "eeprom test\n");
1594         *data = i40e_diag_eeprom_test(&pf->hw);
1595
1596         /* forcebly clear the NVM Update state machine */
1597         pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1598
1599         return *data;
1600 }
1601
1602 static int i40e_intr_test(struct net_device *netdev, u64 *data)
1603 {
1604         struct i40e_netdev_priv *np = netdev_priv(netdev);
1605         struct i40e_pf *pf = np->vsi->back;
1606         u16 swc_old = pf->sw_int_count;
1607
1608         netif_info(pf, hw, netdev, "interrupt test\n");
1609         wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1610              (I40E_PFINT_DYN_CTL0_INTENA_MASK |
1611               I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1612               I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1613               I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1614               I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
1615         usleep_range(1000, 2000);
1616         *data = (swc_old == pf->sw_int_count);
1617
1618         return *data;
1619 }
1620
1621 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
1622 {
1623         struct i40e_netdev_priv *np = netdev_priv(netdev);
1624         struct i40e_pf *pf = np->vsi->back;
1625
1626         netif_info(pf, hw, netdev, "loopback test not implemented\n");
1627         *data = 0;
1628
1629         return *data;
1630 }
1631
1632 static inline bool i40e_active_vfs(struct i40e_pf *pf)
1633 {
1634         struct i40e_vf *vfs = pf->vf;
1635         int i;
1636
1637         for (i = 0; i < pf->num_alloc_vfs; i++)
1638                 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
1639                         return true;
1640         return false;
1641 }
1642
1643 static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1644 {
1645         struct i40e_vsi **vsi = pf->vsi;
1646         int i;
1647
1648         for (i = 0; i < pf->num_alloc_vsi; i++) {
1649                 if (!vsi[i])
1650                         continue;
1651                 if (vsi[i]->type == I40E_VSI_VMDQ2)
1652                         return true;
1653         }
1654
1655         return false;
1656 }
1657
1658 static void i40e_diag_test(struct net_device *netdev,
1659                            struct ethtool_test *eth_test, u64 *data)
1660 {
1661         struct i40e_netdev_priv *np = netdev_priv(netdev);
1662         bool if_running = netif_running(netdev);
1663         struct i40e_pf *pf = np->vsi->back;
1664
1665         if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1666                 /* Offline tests */
1667                 netif_info(pf, drv, netdev, "offline testing starting\n");
1668
1669                 set_bit(__I40E_TESTING, &pf->state);
1670
1671                 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
1672                         dev_warn(&pf->pdev->dev,
1673                                  "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1674                         data[I40E_ETH_TEST_REG]         = 1;
1675                         data[I40E_ETH_TEST_EEPROM]      = 1;
1676                         data[I40E_ETH_TEST_INTR]        = 1;
1677                         data[I40E_ETH_TEST_LOOPBACK]    = 1;
1678                         data[I40E_ETH_TEST_LINK]        = 1;
1679                         eth_test->flags |= ETH_TEST_FL_FAILED;
1680                         clear_bit(__I40E_TESTING, &pf->state);
1681                         goto skip_ol_tests;
1682                 }
1683
1684                 /* If the device is online then take it offline */
1685                 if (if_running)
1686                         /* indicate we're in test mode */
1687                         dev_close(netdev);
1688                 else
1689                         /* This reset does not affect link - if it is
1690                          * changed to a type of reset that does affect
1691                          * link then the following link test would have
1692                          * to be moved to before the reset
1693                          */
1694                         i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1695
1696                 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1697                         eth_test->flags |= ETH_TEST_FL_FAILED;
1698
1699                 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
1700                         eth_test->flags |= ETH_TEST_FL_FAILED;
1701
1702                 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
1703                         eth_test->flags |= ETH_TEST_FL_FAILED;
1704
1705                 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
1706                         eth_test->flags |= ETH_TEST_FL_FAILED;
1707
1708                 /* run reg test last, a reset is required after it */
1709                 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1710                         eth_test->flags |= ETH_TEST_FL_FAILED;
1711
1712                 clear_bit(__I40E_TESTING, &pf->state);
1713                 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
1714
1715                 if (if_running)
1716                         dev_open(netdev);
1717         } else {
1718                 /* Online tests */
1719                 netif_info(pf, drv, netdev, "online testing starting\n");
1720
1721                 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
1722                         eth_test->flags |= ETH_TEST_FL_FAILED;
1723
1724                 /* Offline only tests, not run in online; pass by default */
1725                 data[I40E_ETH_TEST_REG] = 0;
1726                 data[I40E_ETH_TEST_EEPROM] = 0;
1727                 data[I40E_ETH_TEST_INTR] = 0;
1728                 data[I40E_ETH_TEST_LOOPBACK] = 0;
1729         }
1730
1731 skip_ol_tests:
1732
1733         netif_info(pf, drv, netdev, "testing finished\n");
1734 }
1735
1736 static void i40e_get_wol(struct net_device *netdev,
1737                          struct ethtool_wolinfo *wol)
1738 {
1739         struct i40e_netdev_priv *np = netdev_priv(netdev);
1740         struct i40e_pf *pf = np->vsi->back;
1741         struct i40e_hw *hw = &pf->hw;
1742         u16 wol_nvm_bits;
1743
1744         /* NVM bit on means WoL disabled for the port */
1745         i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1746         if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
1747                 wol->supported = 0;
1748                 wol->wolopts = 0;
1749         } else {
1750                 wol->supported = WAKE_MAGIC;
1751                 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1752         }
1753 }
1754
1755 /**
1756  * i40e_set_wol - set the WakeOnLAN configuration
1757  * @netdev: the netdev in question
1758  * @wol: the ethtool WoL setting data
1759  **/
1760 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1761 {
1762         struct i40e_netdev_priv *np = netdev_priv(netdev);
1763         struct i40e_pf *pf = np->vsi->back;
1764         struct i40e_vsi *vsi = np->vsi;
1765         struct i40e_hw *hw = &pf->hw;
1766         u16 wol_nvm_bits;
1767
1768         /* WoL not supported if this isn't the controlling PF on the port */
1769         if (hw->partition_id != 1) {
1770                 i40e_partition_setting_complaint(pf);
1771                 return -EOPNOTSUPP;
1772         }
1773
1774         if (vsi != pf->vsi[pf->lan_vsi])
1775                 return -EOPNOTSUPP;
1776
1777         /* NVM bit on means WoL disabled for the port */
1778         i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1779         if (BIT(hw->port) & wol_nvm_bits)
1780                 return -EOPNOTSUPP;
1781
1782         /* only magic packet is supported */
1783         if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1784                 return -EOPNOTSUPP;
1785
1786         /* is this a new value? */
1787         if (pf->wol_en != !!wol->wolopts) {
1788                 pf->wol_en = !!wol->wolopts;
1789                 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1790         }
1791
1792         return 0;
1793 }
1794
1795 static int i40e_set_phys_id(struct net_device *netdev,
1796                             enum ethtool_phys_id_state state)
1797 {
1798         struct i40e_netdev_priv *np = netdev_priv(netdev);
1799         struct i40e_pf *pf = np->vsi->back;
1800         struct i40e_hw *hw = &pf->hw;
1801         int blink_freq = 2;
1802
1803         switch (state) {
1804         case ETHTOOL_ID_ACTIVE:
1805                 pf->led_status = i40e_led_get(hw);
1806                 return blink_freq;
1807         case ETHTOOL_ID_ON:
1808                 i40e_led_set(hw, 0xF, false);
1809                 break;
1810         case ETHTOOL_ID_OFF:
1811                 i40e_led_set(hw, 0x0, false);
1812                 break;
1813         case ETHTOOL_ID_INACTIVE:
1814                 i40e_led_set(hw, pf->led_status, false);
1815                 break;
1816         default:
1817                 break;
1818         }
1819
1820         return 0;
1821 }
1822
1823 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1824  * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1825  * 125us (8000 interrupts per second) == ITR(62)
1826  */
1827
1828 static int i40e_get_coalesce(struct net_device *netdev,
1829                              struct ethtool_coalesce *ec)
1830 {
1831         struct i40e_netdev_priv *np = netdev_priv(netdev);
1832         struct i40e_vsi *vsi = np->vsi;
1833
1834         ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1835         ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1836
1837         if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1838                 ec->use_adaptive_rx_coalesce = 1;
1839
1840         if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1841                 ec->use_adaptive_tx_coalesce = 1;
1842
1843         ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1844         ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1845
1846         return 0;
1847 }
1848
1849 static int i40e_set_coalesce(struct net_device *netdev,
1850                              struct ethtool_coalesce *ec)
1851 {
1852         struct i40e_netdev_priv *np = netdev_priv(netdev);
1853         struct i40e_q_vector *q_vector;
1854         struct i40e_vsi *vsi = np->vsi;
1855         struct i40e_pf *pf = vsi->back;
1856         struct i40e_hw *hw = &pf->hw;
1857         u16 vector;
1858         int i;
1859
1860         if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1861                 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1862
1863         vector = vsi->base_vector;
1864         if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1865             (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1866                 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1867         } else if (ec->rx_coalesce_usecs == 0) {
1868                 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1869                 if (ec->use_adaptive_rx_coalesce)
1870                         netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
1871         } else {
1872                 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
1873                 return -EINVAL;
1874         }
1875
1876         if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1877             (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
1878                 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1879         } else if (ec->tx_coalesce_usecs == 0) {
1880                 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1881                 if (ec->use_adaptive_tx_coalesce)
1882                         netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
1883         } else {
1884                 netif_info(pf, drv, netdev,
1885                            "Invalid value, tx-usecs range is 0-8160\n");
1886                 return -EINVAL;
1887         }
1888
1889         if (ec->use_adaptive_rx_coalesce)
1890                 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1891         else
1892                 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1893
1894         if (ec->use_adaptive_tx_coalesce)
1895                 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1896         else
1897                 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1898
1899         for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1900                 q_vector = vsi->q_vectors[i];
1901                 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1902                 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1903                 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1904                 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1905                 i40e_flush(hw);
1906         }
1907
1908         return 0;
1909 }
1910
1911 /**
1912  * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1913  * @pf: pointer to the physical function struct
1914  * @cmd: ethtool rxnfc command
1915  *
1916  * Returns Success if the flow is supported, else Invalid Input.
1917  **/
1918 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1919 {
1920         cmd->data = 0;
1921
1922         if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1923                 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1924                 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1925                 return 0;
1926         }
1927         /* Report default options for RSS on i40e */
1928         switch (cmd->flow_type) {
1929         case TCP_V4_FLOW:
1930         case UDP_V4_FLOW:
1931                 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1932         /* fall through to add IP fields */
1933         case SCTP_V4_FLOW:
1934         case AH_ESP_V4_FLOW:
1935         case AH_V4_FLOW:
1936         case ESP_V4_FLOW:
1937         case IPV4_FLOW:
1938                 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1939                 break;
1940         case TCP_V6_FLOW:
1941         case UDP_V6_FLOW:
1942                 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1943         /* fall through to add IP fields */
1944         case SCTP_V6_FLOW:
1945         case AH_ESP_V6_FLOW:
1946         case AH_V6_FLOW:
1947         case ESP_V6_FLOW:
1948         case IPV6_FLOW:
1949                 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1950                 break;
1951         default:
1952                 return -EINVAL;
1953         }
1954
1955         return 0;
1956 }
1957
1958 /**
1959  * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1960  * @pf: Pointer to the physical function struct
1961  * @cmd: The command to get or set Rx flow classification rules
1962  * @rule_locs: Array of used rule locations
1963  *
1964  * This function populates both the total and actual rule count of
1965  * the ethtool flow classification command
1966  *
1967  * Returns 0 on success or -EMSGSIZE if entry not found
1968  **/
1969 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1970                                      struct ethtool_rxnfc *cmd,
1971                                      u32 *rule_locs)
1972 {
1973         struct i40e_fdir_filter *rule;
1974         struct hlist_node *node2;
1975         int cnt = 0;
1976
1977         /* report total rule count */
1978         cmd->data = i40e_get_fd_cnt_all(pf);
1979
1980         hlist_for_each_entry_safe(rule, node2,
1981                                   &pf->fdir_filter_list, fdir_node) {
1982                 if (cnt == cmd->rule_cnt)
1983                         return -EMSGSIZE;
1984
1985                 rule_locs[cnt] = rule->fd_id;
1986                 cnt++;
1987         }
1988
1989         cmd->rule_cnt = cnt;
1990
1991         return 0;
1992 }
1993
1994 /**
1995  * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1996  * @pf: Pointer to the physical function struct
1997  * @cmd: The command to get or set Rx flow classification rules
1998  *
1999  * This function looks up a filter based on the Rx flow classification
2000  * command and fills the flow spec info for it if found
2001  *
2002  * Returns 0 on success or -EINVAL if filter not found
2003  **/
2004 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2005                                        struct ethtool_rxnfc *cmd)
2006 {
2007         struct ethtool_rx_flow_spec *fsp =
2008                         (struct ethtool_rx_flow_spec *)&cmd->fs;
2009         struct i40e_fdir_filter *rule = NULL;
2010         struct hlist_node *node2;
2011
2012         hlist_for_each_entry_safe(rule, node2,
2013                                   &pf->fdir_filter_list, fdir_node) {
2014                 if (fsp->location <= rule->fd_id)
2015                         break;
2016         }
2017
2018         if (!rule || fsp->location != rule->fd_id)
2019                 return -EINVAL;
2020
2021         fsp->flow_type = rule->flow_type;
2022         if (fsp->flow_type == IP_USER_FLOW) {
2023                 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2024                 fsp->h_u.usr_ip4_spec.proto = 0;
2025                 fsp->m_u.usr_ip4_spec.proto = 0;
2026         }
2027
2028         /* Reverse the src and dest notion, since the HW views them from
2029          * Tx perspective where as the user expects it from Rx filter view.
2030          */
2031         fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2032         fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2033         fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2034         fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
2035
2036         if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2037                 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2038         else
2039                 fsp->ring_cookie = rule->q_index;
2040
2041         if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2042                 struct i40e_vsi *vsi;
2043
2044                 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2045                 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2046                         fsp->h_ext.data[1] = htonl(vsi->vf_id);
2047                         fsp->m_ext.data[1] = htonl(0x1);
2048                 }
2049         }
2050
2051         return 0;
2052 }
2053
2054 /**
2055  * i40e_get_rxnfc - command to get RX flow classification rules
2056  * @netdev: network interface device structure
2057  * @cmd: ethtool rxnfc command
2058  *
2059  * Returns Success if the command is supported.
2060  **/
2061 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2062                           u32 *rule_locs)
2063 {
2064         struct i40e_netdev_priv *np = netdev_priv(netdev);
2065         struct i40e_vsi *vsi = np->vsi;
2066         struct i40e_pf *pf = vsi->back;
2067         int ret = -EOPNOTSUPP;
2068
2069         switch (cmd->cmd) {
2070         case ETHTOOL_GRXRINGS:
2071                 cmd->data = vsi->alloc_queue_pairs;
2072                 ret = 0;
2073                 break;
2074         case ETHTOOL_GRXFH:
2075                 ret = i40e_get_rss_hash_opts(pf, cmd);
2076                 break;
2077         case ETHTOOL_GRXCLSRLCNT:
2078                 cmd->rule_cnt = pf->fdir_pf_active_filters;
2079                 /* report total rule count */
2080                 cmd->data = i40e_get_fd_cnt_all(pf);
2081                 ret = 0;
2082                 break;
2083         case ETHTOOL_GRXCLSRULE:
2084                 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
2085                 break;
2086         case ETHTOOL_GRXCLSRLALL:
2087                 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2088                 break;
2089         default:
2090                 break;
2091         }
2092
2093         return ret;
2094 }
2095
2096 /**
2097  * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2098  * @pf: pointer to the physical function struct
2099  * @cmd: ethtool rxnfc command
2100  *
2101  * Returns Success if the flow input set is supported.
2102  **/
2103 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2104 {
2105         struct i40e_hw *hw = &pf->hw;
2106         u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2107                    ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2108
2109         /* RSS does not support anything other than hashing
2110          * to queues on src and dst IPs and ports
2111          */
2112         if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2113                           RXH_L4_B_0_1 | RXH_L4_B_2_3))
2114                 return -EINVAL;
2115
2116         /* We need at least the IP SRC and DEST fields for hashing */
2117         if (!(nfc->data & RXH_IP_SRC) ||
2118             !(nfc->data & RXH_IP_DST))
2119                 return -EINVAL;
2120
2121         switch (nfc->flow_type) {
2122         case TCP_V4_FLOW:
2123                 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2124                 case 0:
2125                         hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2126                         break;
2127                 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2128                         hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2129                         break;
2130                 default:
2131                         return -EINVAL;
2132                 }
2133                 break;
2134         case TCP_V6_FLOW:
2135                 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2136                 case 0:
2137                         hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2138                         break;
2139                 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2140                         hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2141                         break;
2142                 default:
2143                         return -EINVAL;
2144                 }
2145                 break;
2146         case UDP_V4_FLOW:
2147                 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2148                 case 0:
2149                         hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2150                                   BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2151                         break;
2152                 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2153                         hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2154                                  BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
2155                         break;
2156                 default:
2157                         return -EINVAL;
2158                 }
2159                 break;
2160         case UDP_V6_FLOW:
2161                 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2162                 case 0:
2163                         hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2164                                   BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2165                         break;
2166                 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2167                         hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2168                                  BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
2169                         break;
2170                 default:
2171                         return -EINVAL;
2172                 }
2173                 break;
2174         case AH_ESP_V4_FLOW:
2175         case AH_V4_FLOW:
2176         case ESP_V4_FLOW:
2177         case SCTP_V4_FLOW:
2178                 if ((nfc->data & RXH_L4_B_0_1) ||
2179                     (nfc->data & RXH_L4_B_2_3))
2180                         return -EINVAL;
2181                 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2182                 break;
2183         case AH_ESP_V6_FLOW:
2184         case AH_V6_FLOW:
2185         case ESP_V6_FLOW:
2186         case SCTP_V6_FLOW:
2187                 if ((nfc->data & RXH_L4_B_0_1) ||
2188                     (nfc->data & RXH_L4_B_2_3))
2189                         return -EINVAL;
2190                 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2191                 break;
2192         case IPV4_FLOW:
2193                 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2194                         BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
2195                 break;
2196         case IPV6_FLOW:
2197                 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2198                         BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
2199                 break;
2200         default:
2201                 return -EINVAL;
2202         }
2203
2204         wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2205         wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2206         i40e_flush(hw);
2207
2208         /* Save setting for future output/update */
2209         pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2210
2211         return 0;
2212 }
2213
2214 /**
2215  * i40e_match_fdir_input_set - Match a new filter against an existing one
2216  * @rule: The filter already added
2217  * @input: The new filter to comapre against
2218  *
2219  * Returns true if the two input set match
2220  **/
2221 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2222                                       struct i40e_fdir_filter *input)
2223 {
2224         if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2225             (rule->src_ip[0] != input->src_ip[0]) ||
2226             (rule->dst_port != input->dst_port) ||
2227             (rule->src_port != input->src_port))
2228                 return false;
2229         return true;
2230 }
2231
2232 /**
2233  * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2234  * @vsi: Pointer to the targeted VSI
2235  * @input: The filter to update or NULL to indicate deletion
2236  * @sw_idx: Software index to the filter
2237  * @cmd: The command to get or set Rx flow classification rules
2238  *
2239  * This function updates (or deletes) a Flow Director entry from
2240  * the hlist of the corresponding PF
2241  *
2242  * Returns 0 on success
2243  **/
2244 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2245                                           struct i40e_fdir_filter *input,
2246                                           u16 sw_idx,
2247                                           struct ethtool_rxnfc *cmd)
2248 {
2249         struct i40e_fdir_filter *rule, *parent;
2250         struct i40e_pf *pf = vsi->back;
2251         struct hlist_node *node2;
2252         int err = -EINVAL;
2253
2254         parent = NULL;
2255         rule = NULL;
2256
2257         hlist_for_each_entry_safe(rule, node2,
2258                                   &pf->fdir_filter_list, fdir_node) {
2259                 /* hash found, or no matching entry */
2260                 if (rule->fd_id >= sw_idx)
2261                         break;
2262                 parent = rule;
2263         }
2264
2265         /* if there is an old rule occupying our place remove it */
2266         if (rule && (rule->fd_id == sw_idx)) {
2267                 if (input && !i40e_match_fdir_input_set(rule, input))
2268                         err = i40e_add_del_fdir(vsi, rule, false);
2269                 else if (!input)
2270                         err = i40e_add_del_fdir(vsi, rule, false);
2271                 hlist_del(&rule->fdir_node);
2272                 kfree(rule);
2273                 pf->fdir_pf_active_filters--;
2274         }
2275
2276         /* If no input this was a delete, err should be 0 if a rule was
2277          * successfully found and removed from the list else -EINVAL
2278          */
2279         if (!input)
2280                 return err;
2281
2282         /* initialize node and set software index */
2283         INIT_HLIST_NODE(&input->fdir_node);
2284
2285         /* add filter to the list */
2286         if (parent)
2287                 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
2288         else
2289                 hlist_add_head(&input->fdir_node,
2290                                &pf->fdir_filter_list);
2291
2292         /* update counts */
2293         pf->fdir_pf_active_filters++;
2294
2295         return 0;
2296 }
2297
2298 /**
2299  * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2300  * @vsi: Pointer to the targeted VSI
2301  * @cmd: The command to get or set Rx flow classification rules
2302  *
2303  * The function removes a Flow Director filter entry from the
2304  * hlist of the corresponding PF
2305  *
2306  * Returns 0 on success
2307  */
2308 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2309                                struct ethtool_rxnfc *cmd)
2310 {
2311         struct ethtool_rx_flow_spec *fsp =
2312                 (struct ethtool_rx_flow_spec *)&cmd->fs;
2313         struct i40e_pf *pf = vsi->back;
2314         int ret = 0;
2315
2316         if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2317             test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2318                 return -EBUSY;
2319
2320         if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2321                 return -EBUSY;
2322
2323         ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
2324
2325         i40e_fdir_check_and_reenable(pf);
2326         return ret;
2327 }
2328
2329 /**
2330  * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
2331  * @vsi: pointer to the targeted VSI
2332  * @cmd: command to get or set RX flow classification rules
2333  *
2334  * Add Flow Director filters for a specific flow spec based on their
2335  * protocol.  Returns 0 if the filters were successfully added.
2336  **/
2337 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2338                                  struct ethtool_rxnfc *cmd)
2339 {
2340         struct ethtool_rx_flow_spec *fsp;
2341         struct i40e_fdir_filter *input;
2342         struct i40e_pf *pf;
2343         int ret = -EINVAL;
2344         u16 vf_id;
2345
2346         if (!vsi)
2347                 return -EINVAL;
2348
2349         pf = vsi->back;
2350
2351         if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2352                 return -EOPNOTSUPP;
2353
2354         if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
2355                 return -ENOSPC;
2356
2357         if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2358             test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2359                 return -EBUSY;
2360
2361         if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2362                 return -EBUSY;
2363
2364         fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2365
2366         if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2367                               pf->hw.func_caps.fd_filters_guaranteed)) {
2368                 return -EINVAL;
2369         }
2370
2371         if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2372             (fsp->ring_cookie >= vsi->num_queue_pairs))
2373                 return -EINVAL;
2374
2375         input = kzalloc(sizeof(*input), GFP_KERNEL);
2376
2377         if (!input)
2378                 return -ENOMEM;
2379
2380         input->fd_id = fsp->location;
2381
2382         if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2383                 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2384         else
2385                 input->dest_ctl =
2386                              I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2387
2388         input->q_index = fsp->ring_cookie;
2389         input->flex_off = 0;
2390         input->pctype = 0;
2391         input->dest_vsi = vsi->id;
2392         input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
2393         input->cnt_index  = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
2394         input->flow_type = fsp->flow_type;
2395         input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
2396
2397         /* Reverse the src and dest notion, since the HW expects them to be from
2398          * Tx perspective where as the input from user is from Rx filter view.
2399          */
2400         input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2401         input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2402         input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2403         input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
2404
2405         if (ntohl(fsp->m_ext.data[1])) {
2406                 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2407                         netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2408                         goto free_input;
2409                 }
2410                 vf_id = ntohl(fsp->h_ext.data[1]);
2411                 /* Find vsi id from vf id and override dest vsi */
2412                 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2413                 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2414                         netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2415                         goto free_input;
2416                 }
2417         }
2418
2419         ret = i40e_add_del_fdir(vsi, input, true);
2420 free_input:
2421         if (ret)
2422                 kfree(input);
2423         else
2424                 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2425
2426         return ret;
2427 }
2428
2429 /**
2430  * i40e_set_rxnfc - command to set RX flow classification rules
2431  * @netdev: network interface device structure
2432  * @cmd: ethtool rxnfc command
2433  *
2434  * Returns Success if the command is supported.
2435  **/
2436 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2437 {
2438         struct i40e_netdev_priv *np = netdev_priv(netdev);
2439         struct i40e_vsi *vsi = np->vsi;
2440         struct i40e_pf *pf = vsi->back;
2441         int ret = -EOPNOTSUPP;
2442
2443         switch (cmd->cmd) {
2444         case ETHTOOL_SRXFH:
2445                 ret = i40e_set_rss_hash_opt(pf, cmd);
2446                 break;
2447         case ETHTOOL_SRXCLSRLINS:
2448                 ret = i40e_add_fdir_ethtool(vsi, cmd);
2449                 break;
2450         case ETHTOOL_SRXCLSRLDEL:
2451                 ret = i40e_del_fdir_entry(vsi, cmd);
2452                 break;
2453         default:
2454                 break;
2455         }
2456
2457         return ret;
2458 }
2459
2460 /**
2461  * i40e_max_channels - get Max number of combined channels supported
2462  * @vsi: vsi pointer
2463  **/
2464 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2465 {
2466         /* TODO: This code assumes DCB and FD is disabled for now. */
2467         return vsi->alloc_queue_pairs;
2468 }
2469
2470 /**
2471  * i40e_get_channels - Get the current channels enabled and max supported etc.
2472  * @netdev: network interface device structure
2473  * @ch: ethtool channels structure
2474  *
2475  * We don't support separate tx and rx queues as channels. The other count
2476  * represents how many queues are being used for control. max_combined counts
2477  * how many queue pairs we can support. They may not be mapped 1 to 1 with
2478  * q_vectors since we support a lot more queue pairs than q_vectors.
2479  **/
2480 static void i40e_get_channels(struct net_device *dev,
2481                                struct ethtool_channels *ch)
2482 {
2483         struct i40e_netdev_priv *np = netdev_priv(dev);
2484         struct i40e_vsi *vsi = np->vsi;
2485         struct i40e_pf *pf = vsi->back;
2486
2487         /* report maximum channels */
2488         ch->max_combined = i40e_max_channels(vsi);
2489
2490         /* report info for other vector */
2491         ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
2492         ch->max_other = ch->other_count;
2493
2494         /* Note: This code assumes DCB is disabled for now. */
2495         ch->combined_count = vsi->num_queue_pairs;
2496 }
2497
2498 /**
2499  * i40e_set_channels - Set the new channels count.
2500  * @netdev: network interface device structure
2501  * @ch: ethtool channels structure
2502  *
2503  * The new channels count may not be the same as requested by the user
2504  * since it gets rounded down to a power of 2 value.
2505  **/
2506 static int i40e_set_channels(struct net_device *dev,
2507                               struct ethtool_channels *ch)
2508 {
2509         struct i40e_netdev_priv *np = netdev_priv(dev);
2510         unsigned int count = ch->combined_count;
2511         struct i40e_vsi *vsi = np->vsi;
2512         struct i40e_pf *pf = vsi->back;
2513         int new_count;
2514
2515         /* We do not support setting channels for any other VSI at present */
2516         if (vsi->type != I40E_VSI_MAIN)
2517                 return -EINVAL;
2518
2519         /* verify they are not requesting separate vectors */
2520         if (!count || ch->rx_count || ch->tx_count)
2521                 return -EINVAL;
2522
2523         /* verify other_count has not changed */
2524         if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
2525                 return -EINVAL;
2526
2527         /* verify the number of channels does not exceed hardware limits */
2528         if (count > i40e_max_channels(vsi))
2529                 return -EINVAL;
2530
2531         /* update feature limits from largest to smallest supported values */
2532         /* TODO: Flow director limit, DCB etc */
2533
2534         /* use rss_reconfig to rebuild with new queue count and update traffic
2535          * class queue mapping
2536          */
2537         new_count = i40e_reconfig_rss_queues(pf, count);
2538         if (new_count > 0)
2539                 return 0;
2540         else
2541                 return -EINVAL;
2542 }
2543
2544 #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2545 /**
2546  * i40e_get_rxfh_key_size - get the RSS hash key size
2547  * @netdev: network interface device structure
2548  *
2549  * Returns the table size.
2550  **/
2551 static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2552 {
2553         return I40E_HKEY_ARRAY_SIZE;
2554 }
2555
2556 /**
2557  * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2558  * @netdev: network interface device structure
2559  *
2560  * Returns the table size.
2561  **/
2562 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2563 {
2564         return I40E_HLUT_ARRAY_SIZE;
2565 }
2566
2567 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2568                          u8 *hfunc)
2569 {
2570         struct i40e_netdev_priv *np = netdev_priv(netdev);
2571         struct i40e_vsi *vsi = np->vsi;
2572         struct i40e_pf *pf = vsi->back;
2573         struct i40e_hw *hw = &pf->hw;
2574         u32 reg_val;
2575         int i, j;
2576
2577         if (hfunc)
2578                 *hfunc = ETH_RSS_HASH_TOP;
2579
2580         if (!indir)
2581                 return 0;
2582
2583         for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2584                 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2585                 indir[j++] = reg_val & 0xff;
2586                 indir[j++] = (reg_val >> 8) & 0xff;
2587                 indir[j++] = (reg_val >> 16) & 0xff;
2588                 indir[j++] = (reg_val >> 24) & 0xff;
2589         }
2590
2591         if (key) {
2592                 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2593                         reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2594                         key[j++] = (u8)(reg_val & 0xff);
2595                         key[j++] = (u8)((reg_val >> 8) & 0xff);
2596                         key[j++] = (u8)((reg_val >> 16) & 0xff);
2597                         key[j++] = (u8)((reg_val >> 24) & 0xff);
2598                 }
2599         }
2600         return 0;
2601 }
2602
2603 /**
2604  * i40e_set_rxfh - set the rx flow hash indirection table
2605  * @netdev: network interface device structure
2606  * @indir: indirection table
2607  * @key: hash key
2608  *
2609  * Returns -EINVAL if the table specifies an invalid queue id, otherwise
2610  * returns 0 after programming the table.
2611  **/
2612 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2613                          const u8 *key, const u8 hfunc)
2614 {
2615         struct i40e_netdev_priv *np = netdev_priv(netdev);
2616         struct i40e_vsi *vsi = np->vsi;
2617         struct i40e_pf *pf = vsi->back;
2618         struct i40e_hw *hw = &pf->hw;
2619         u32 reg_val;
2620         int i, j;
2621
2622         if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2623                 return -EOPNOTSUPP;
2624
2625         if (!indir)
2626                 return 0;
2627
2628         for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2629                 reg_val = indir[j++];
2630                 reg_val |= indir[j++] << 8;
2631                 reg_val |= indir[j++] << 16;
2632                 reg_val |= indir[j++] << 24;
2633                 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2634         }
2635
2636         if (key) {
2637                 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2638                         reg_val = key[j++];
2639                         reg_val |= key[j++] << 8;
2640                         reg_val |= key[j++] << 16;
2641                         reg_val |= key[j++] << 24;
2642                         wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2643                 }
2644         }
2645         return 0;
2646 }
2647
2648 /**
2649  * i40e_get_priv_flags - report device private flags
2650  * @dev: network interface device structure
2651  *
2652  * The get string set count and the string set should be matched for each
2653  * flag returned.  Add new strings for each flag to the i40e_priv_flags_strings
2654  * array.
2655  *
2656  * Returns a u32 bitmap of flags.
2657  **/
2658 static u32 i40e_get_priv_flags(struct net_device *dev)
2659 {
2660         struct i40e_netdev_priv *np = netdev_priv(dev);
2661         struct i40e_vsi *vsi = np->vsi;
2662         struct i40e_pf *pf = vsi->back;
2663         u32 ret_flags = 0;
2664
2665         ret_flags |= pf->hw.func_caps.npar_enable ?
2666                 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2667         ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2668                 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
2669
2670         return ret_flags;
2671 }
2672
2673 /**
2674  * i40e_set_priv_flags - set private flags
2675  * @dev: network interface device structure
2676  * @flags: bit flags to be set
2677  **/
2678 static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2679 {
2680         struct i40e_netdev_priv *np = netdev_priv(dev);
2681         struct i40e_vsi *vsi = np->vsi;
2682         struct i40e_pf *pf = vsi->back;
2683
2684         if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2685                 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2686         else
2687                 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2688
2689         return 0;
2690 }
2691
2692 static const struct ethtool_ops i40e_ethtool_ops = {
2693         .get_settings           = i40e_get_settings,
2694         .set_settings           = i40e_set_settings,
2695         .get_drvinfo            = i40e_get_drvinfo,
2696         .get_regs_len           = i40e_get_regs_len,
2697         .get_regs               = i40e_get_regs,
2698         .nway_reset             = i40e_nway_reset,
2699         .get_link               = ethtool_op_get_link,
2700         .get_wol                = i40e_get_wol,
2701         .set_wol                = i40e_set_wol,
2702         .set_eeprom             = i40e_set_eeprom,
2703         .get_eeprom_len         = i40e_get_eeprom_len,
2704         .get_eeprom             = i40e_get_eeprom,
2705         .get_ringparam          = i40e_get_ringparam,
2706         .set_ringparam          = i40e_set_ringparam,
2707         .get_pauseparam         = i40e_get_pauseparam,
2708         .set_pauseparam         = i40e_set_pauseparam,
2709         .get_msglevel           = i40e_get_msglevel,
2710         .set_msglevel           = i40e_set_msglevel,
2711         .get_rxnfc              = i40e_get_rxnfc,
2712         .set_rxnfc              = i40e_set_rxnfc,
2713         .self_test              = i40e_diag_test,
2714         .get_strings            = i40e_get_strings,
2715         .set_phys_id            = i40e_set_phys_id,
2716         .get_sset_count         = i40e_get_sset_count,
2717         .get_ethtool_stats      = i40e_get_ethtool_stats,
2718         .get_coalesce           = i40e_get_coalesce,
2719         .set_coalesce           = i40e_set_coalesce,
2720         .get_rxfh_key_size      = i40e_get_rxfh_key_size,
2721         .get_rxfh_indir_size    = i40e_get_rxfh_indir_size,
2722         .get_rxfh               = i40e_get_rxfh,
2723         .set_rxfh               = i40e_set_rxfh,
2724         .get_channels           = i40e_get_channels,
2725         .set_channels           = i40e_set_channels,
2726         .get_ts_info            = i40e_get_ts_info,
2727         .get_priv_flags         = i40e_get_priv_flags,
2728         .set_priv_flags         = i40e_set_priv_flags,
2729 };
2730
2731 void i40e_set_ethtool_ops(struct net_device *netdev)
2732 {
2733         netdev->ethtool_ops = &i40e_ethtool_ops;
2734 }