7f3d34220b13cfc12698a5b3f9a285cb9b3538a8
[firefly-linux-kernel-4.4.55.git] / drivers / net / ethernet / intel / i40e / i40e_ethtool.c
1 /*******************************************************************************
2  *
3  * Intel Ethernet Controller XL710 Family Linux Driver
4  * Copyright(c) 2013 - 2014 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 #define I40E_NETDEV_STAT(_net_stat) \
44                 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
45 #define I40E_PF_STAT(_name, _stat) \
46                 I40E_STAT(struct i40e_pf, _name, _stat)
47 #define I40E_VSI_STAT(_name, _stat) \
48                 I40E_STAT(struct i40e_vsi, _name, _stat)
49
50 static const struct i40e_stats i40e_gstrings_net_stats[] = {
51         I40E_NETDEV_STAT(rx_packets),
52         I40E_NETDEV_STAT(tx_packets),
53         I40E_NETDEV_STAT(rx_bytes),
54         I40E_NETDEV_STAT(tx_bytes),
55         I40E_NETDEV_STAT(rx_errors),
56         I40E_NETDEV_STAT(tx_errors),
57         I40E_NETDEV_STAT(rx_dropped),
58         I40E_NETDEV_STAT(tx_dropped),
59         I40E_NETDEV_STAT(multicast),
60         I40E_NETDEV_STAT(collisions),
61         I40E_NETDEV_STAT(rx_length_errors),
62         I40E_NETDEV_STAT(rx_crc_errors),
63 };
64
65 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
66                                  struct ethtool_rxnfc *cmd);
67
68 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
69  * but they are separate.  This device supports Virtualization, and
70  * as such might have several netdevs supporting VMDq and FCoE going
71  * through a single port.  The NETDEV_STATs are for individual netdevs
72  * seen at the top of the stack, and the PF_STATs are for the physical
73  * function at the bottom of the stack hosting those netdevs.
74  *
75  * The PF_STATs are appended to the netdev stats only when ethtool -S
76  * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
77  */
78 static struct i40e_stats i40e_gstrings_stats[] = {
79         I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
80         I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
81         I40E_PF_STAT("rx_errors", stats.eth.rx_errors),
82         I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
83         I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
84         I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
85         I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
86         I40E_PF_STAT("crc_errors", stats.crc_errors),
87         I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
88         I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
89         I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
90         I40E_PF_STAT("tx_timeout", tx_timeout_count),
91         I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
92         I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
93         I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
94         I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
95         I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
96         I40E_PF_STAT("rx_size_64", stats.rx_size_64),
97         I40E_PF_STAT("rx_size_127", stats.rx_size_127),
98         I40E_PF_STAT("rx_size_255", stats.rx_size_255),
99         I40E_PF_STAT("rx_size_511", stats.rx_size_511),
100         I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
101         I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
102         I40E_PF_STAT("rx_size_big", stats.rx_size_big),
103         I40E_PF_STAT("tx_size_64", stats.tx_size_64),
104         I40E_PF_STAT("tx_size_127", stats.tx_size_127),
105         I40E_PF_STAT("tx_size_255", stats.tx_size_255),
106         I40E_PF_STAT("tx_size_511", stats.tx_size_511),
107         I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
108         I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
109         I40E_PF_STAT("tx_size_big", stats.tx_size_big),
110         I40E_PF_STAT("rx_undersize", stats.rx_undersize),
111         I40E_PF_STAT("rx_fragments", stats.rx_fragments),
112         I40E_PF_STAT("rx_oversize", stats.rx_oversize),
113         I40E_PF_STAT("rx_jabber", stats.rx_jabber),
114         I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
115         I40E_PF_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
116         I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
117         /* LPI stats */
118         I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
119         I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
120         I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
121         I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
122 };
123
124 #define I40E_QUEUE_STATS_LEN(n) \
125         (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
126             * 2 /* Tx and Rx together */                                     \
127             * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
128 #define I40E_GLOBAL_STATS_LEN   ARRAY_SIZE(i40e_gstrings_stats)
129 #define I40E_NETDEV_STATS_LEN   ARRAY_SIZE(i40e_gstrings_net_stats)
130 #define I40E_VSI_STATS_LEN(n)   (I40E_NETDEV_STATS_LEN + \
131                                  I40E_QUEUE_STATS_LEN((n)))
132 #define I40E_PFC_STATS_LEN ( \
133                 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
134                  FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
135                  FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
136                  FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
137                  FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
138                  / sizeof(u64))
139 #define I40E_PF_STATS_LEN(n)    (I40E_GLOBAL_STATS_LEN + \
140                                  I40E_PFC_STATS_LEN + \
141                                  I40E_VSI_STATS_LEN((n)))
142
143 enum i40e_ethtool_test_id {
144         I40E_ETH_TEST_REG = 0,
145         I40E_ETH_TEST_EEPROM,
146         I40E_ETH_TEST_INTR,
147         I40E_ETH_TEST_LOOPBACK,
148         I40E_ETH_TEST_LINK,
149 };
150
151 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
152         "Register test  (offline)",
153         "Eeprom test    (offline)",
154         "Interrupt test (offline)",
155         "Loopback test  (offline)",
156         "Link test   (on/offline)"
157 };
158
159 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
160
161 /**
162  * i40e_get_settings - Get Link Speed and Duplex settings
163  * @netdev: network interface device structure
164  * @ecmd: ethtool command
165  *
166  * Reports speed/duplex settings based on media_type
167  **/
168 static int i40e_get_settings(struct net_device *netdev,
169                              struct ethtool_cmd *ecmd)
170 {
171         struct i40e_netdev_priv *np = netdev_priv(netdev);
172         struct i40e_pf *pf = np->vsi->back;
173         struct i40e_hw *hw = &pf->hw;
174         struct i40e_link_status *hw_link_info = &hw->phy.link_info;
175         bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
176         u32 link_speed = hw_link_info->link_speed;
177
178         /* hardware is either in 40G mode or 10G mode
179          * NOTE: this section initializes supported and advertising
180          */
181         switch (hw_link_info->phy_type) {
182         case I40E_PHY_TYPE_40GBASE_CR4:
183         case I40E_PHY_TYPE_40GBASE_CR4_CU:
184                 ecmd->supported = SUPPORTED_40000baseCR4_Full;
185                 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
186                 break;
187         case I40E_PHY_TYPE_40GBASE_KR4:
188                 ecmd->supported = SUPPORTED_40000baseKR4_Full;
189                 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
190                 break;
191         case I40E_PHY_TYPE_40GBASE_SR4:
192                 ecmd->supported = SUPPORTED_40000baseSR4_Full;
193                 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
194                 break;
195         case I40E_PHY_TYPE_40GBASE_LR4:
196                 ecmd->supported = SUPPORTED_40000baseLR4_Full;
197                 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
198                 break;
199         case I40E_PHY_TYPE_10GBASE_KX4:
200                 ecmd->supported = SUPPORTED_10000baseKX4_Full;
201                 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
202                 break;
203         case I40E_PHY_TYPE_10GBASE_KR:
204                 ecmd->supported = SUPPORTED_10000baseKR_Full;
205                 ecmd->advertising = ADVERTISED_10000baseKR_Full;
206                 break;
207         default:
208                 if (i40e_is_40G_device(hw->device_id)) {
209                         ecmd->supported = SUPPORTED_40000baseSR4_Full;
210                         ecmd->advertising = ADVERTISED_40000baseSR4_Full;
211                 } else {
212                         ecmd->supported = SUPPORTED_10000baseT_Full;
213                         ecmd->advertising = ADVERTISED_10000baseT_Full;
214                 }
215                 break;
216         }
217
218         ecmd->supported |= SUPPORTED_Autoneg;
219         ecmd->advertising |= ADVERTISED_Autoneg;
220         ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
221                           AUTONEG_ENABLE : AUTONEG_DISABLE);
222
223         switch (hw->phy.media_type) {
224         case I40E_MEDIA_TYPE_BACKPLANE:
225                 ecmd->supported |= SUPPORTED_Backplane;
226                 ecmd->advertising |= ADVERTISED_Backplane;
227                 ecmd->port = PORT_NONE;
228                 break;
229         case I40E_MEDIA_TYPE_BASET:
230                 ecmd->supported |= SUPPORTED_TP;
231                 ecmd->advertising |= ADVERTISED_TP;
232                 ecmd->port = PORT_TP;
233                 break;
234         case I40E_MEDIA_TYPE_DA:
235         case I40E_MEDIA_TYPE_CX4:
236                 ecmd->supported |= SUPPORTED_FIBRE;
237                 ecmd->advertising |= ADVERTISED_FIBRE;
238                 ecmd->port = PORT_DA;
239                 break;
240         case I40E_MEDIA_TYPE_FIBER:
241                 ecmd->supported |= SUPPORTED_FIBRE;
242                 ecmd->advertising |= ADVERTISED_FIBRE;
243                 ecmd->port = PORT_FIBRE;
244                 break;
245         case I40E_MEDIA_TYPE_UNKNOWN:
246         default:
247                 ecmd->port = PORT_OTHER;
248                 break;
249         }
250
251         ecmd->transceiver = XCVR_EXTERNAL;
252
253         if (link_up) {
254                 switch (link_speed) {
255                 case I40E_LINK_SPEED_40GB:
256                         /* need a SPEED_40000 in ethtool.h */
257                         ethtool_cmd_speed_set(ecmd, 40000);
258                         break;
259                 case I40E_LINK_SPEED_10GB:
260                         ethtool_cmd_speed_set(ecmd, SPEED_10000);
261                         break;
262                 default:
263                         break;
264                 }
265                 ecmd->duplex = DUPLEX_FULL;
266         } else {
267                 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
268                 ecmd->duplex = DUPLEX_UNKNOWN;
269         }
270
271         return 0;
272 }
273
274 /**
275  * i40e_get_pauseparam -  Get Flow Control status
276  * Return tx/rx-pause status
277  **/
278 static void i40e_get_pauseparam(struct net_device *netdev,
279                                 struct ethtool_pauseparam *pause)
280 {
281         struct i40e_netdev_priv *np = netdev_priv(netdev);
282         struct i40e_pf *pf = np->vsi->back;
283         struct i40e_hw *hw = &pf->hw;
284         struct i40e_link_status *hw_link_info = &hw->phy.link_info;
285
286         pause->autoneg =
287                 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
288                   AUTONEG_ENABLE : AUTONEG_DISABLE);
289
290         if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
291                 pause->rx_pause = 1;
292         } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
293                 pause->tx_pause = 1;
294         } else if (hw->fc.current_mode == I40E_FC_FULL) {
295                 pause->rx_pause = 1;
296                 pause->tx_pause = 1;
297         }
298 }
299
300 static u32 i40e_get_msglevel(struct net_device *netdev)
301 {
302         struct i40e_netdev_priv *np = netdev_priv(netdev);
303         struct i40e_pf *pf = np->vsi->back;
304
305         return pf->msg_enable;
306 }
307
308 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
309 {
310         struct i40e_netdev_priv *np = netdev_priv(netdev);
311         struct i40e_pf *pf = np->vsi->back;
312
313         if (I40E_DEBUG_USER & data)
314                 pf->hw.debug_mask = data;
315         pf->msg_enable = data;
316 }
317
318 static int i40e_get_regs_len(struct net_device *netdev)
319 {
320         int reg_count = 0;
321         int i;
322
323         for (i = 0; i40e_reg_list[i].offset != 0; i++)
324                 reg_count += i40e_reg_list[i].elements;
325
326         return reg_count * sizeof(u32);
327 }
328
329 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
330                           void *p)
331 {
332         struct i40e_netdev_priv *np = netdev_priv(netdev);
333         struct i40e_pf *pf = np->vsi->back;
334         struct i40e_hw *hw = &pf->hw;
335         u32 *reg_buf = p;
336         int i, j, ri;
337         u32 reg;
338
339         /* Tell ethtool which driver-version-specific regs output we have.
340          *
341          * At some point, if we have ethtool doing special formatting of
342          * this data, it will rely on this version number to know how to
343          * interpret things.  Hence, this needs to be updated if/when the
344          * diags register table is changed.
345          */
346         regs->version = 1;
347
348         /* loop through the diags reg table for what to print */
349         ri = 0;
350         for (i = 0; i40e_reg_list[i].offset != 0; i++) {
351                 for (j = 0; j < i40e_reg_list[i].elements; j++) {
352                         reg = i40e_reg_list[i].offset
353                                 + (j * i40e_reg_list[i].stride);
354                         reg_buf[ri++] = rd32(hw, reg);
355                 }
356         }
357
358 }
359
360 static int i40e_get_eeprom(struct net_device *netdev,
361                            struct ethtool_eeprom *eeprom, u8 *bytes)
362 {
363         struct i40e_netdev_priv *np = netdev_priv(netdev);
364         struct i40e_hw *hw = &np->vsi->back->hw;
365         struct i40e_pf *pf = np->vsi->back;
366         int ret_val = 0, len;
367         u8 *eeprom_buff;
368         u16 i, sectors;
369         bool last;
370 #define I40E_NVM_SECTOR_SIZE  4096
371         if (eeprom->len == 0)
372                 return -EINVAL;
373
374         eeprom->magic = hw->vendor_id | (hw->device_id << 16);
375
376         eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
377         if (!eeprom_buff)
378                 return -ENOMEM;
379
380         ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
381         if (ret_val) {
382                 dev_info(&pf->pdev->dev,
383                          "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
384                          ret_val, hw->aq.asq_last_status);
385                 goto free_buff;
386         }
387
388         sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
389         sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
390         len = I40E_NVM_SECTOR_SIZE;
391         last = false;
392         for (i = 0; i < sectors; i++) {
393                 if (i == (sectors - 1)) {
394                         len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
395                         last = true;
396                 }
397                 ret_val = i40e_aq_read_nvm(hw, 0x0,
398                                 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
399                                 len,
400                                 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
401                                 last, NULL);
402                 if (ret_val) {
403                         dev_info(&pf->pdev->dev,
404                                  "read NVM failed err=%d status=0x%x\n",
405                                  ret_val, hw->aq.asq_last_status);
406                         goto release_nvm;
407                 }
408         }
409
410 release_nvm:
411         i40e_release_nvm(hw);
412         memcpy(bytes, eeprom_buff, eeprom->len);
413 free_buff:
414         kfree(eeprom_buff);
415         return ret_val;
416 }
417
418 static int i40e_get_eeprom_len(struct net_device *netdev)
419 {
420         struct i40e_netdev_priv *np = netdev_priv(netdev);
421         struct i40e_hw *hw = &np->vsi->back->hw;
422         u32 val;
423
424         val = (rd32(hw, I40E_GLPCI_LBARCTRL)
425                 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
426                 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
427         /* register returns value in power of 2, 64Kbyte chunks. */
428         val = (64 * 1024) * (1 << val);
429         return val;
430 }
431
432 static void i40e_get_drvinfo(struct net_device *netdev,
433                              struct ethtool_drvinfo *drvinfo)
434 {
435         struct i40e_netdev_priv *np = netdev_priv(netdev);
436         struct i40e_vsi *vsi = np->vsi;
437         struct i40e_pf *pf = vsi->back;
438
439         strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
440         strlcpy(drvinfo->version, i40e_driver_version_str,
441                 sizeof(drvinfo->version));
442         strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
443                 sizeof(drvinfo->fw_version));
444         strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
445                 sizeof(drvinfo->bus_info));
446 }
447
448 static void i40e_get_ringparam(struct net_device *netdev,
449                                struct ethtool_ringparam *ring)
450 {
451         struct i40e_netdev_priv *np = netdev_priv(netdev);
452         struct i40e_pf *pf = np->vsi->back;
453         struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
454
455         ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
456         ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
457         ring->rx_mini_max_pending = 0;
458         ring->rx_jumbo_max_pending = 0;
459         ring->rx_pending = vsi->rx_rings[0]->count;
460         ring->tx_pending = vsi->tx_rings[0]->count;
461         ring->rx_mini_pending = 0;
462         ring->rx_jumbo_pending = 0;
463 }
464
465 static int i40e_set_ringparam(struct net_device *netdev,
466                               struct ethtool_ringparam *ring)
467 {
468         struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
469         struct i40e_netdev_priv *np = netdev_priv(netdev);
470         struct i40e_vsi *vsi = np->vsi;
471         struct i40e_pf *pf = vsi->back;
472         u32 new_rx_count, new_tx_count;
473         int i, err = 0;
474
475         if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
476                 return -EINVAL;
477
478         if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
479             ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
480             ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
481             ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
482                 netdev_info(netdev,
483                             "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
484                             ring->tx_pending, ring->rx_pending,
485                             I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
486                 return -EINVAL;
487         }
488
489         new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
490         new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
491
492         /* if nothing to do return success */
493         if ((new_tx_count == vsi->tx_rings[0]->count) &&
494             (new_rx_count == vsi->rx_rings[0]->count))
495                 return 0;
496
497         while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
498                 usleep_range(1000, 2000);
499
500         if (!netif_running(vsi->netdev)) {
501                 /* simple case - set for the next time the netdev is started */
502                 for (i = 0; i < vsi->num_queue_pairs; i++) {
503                         vsi->tx_rings[i]->count = new_tx_count;
504                         vsi->rx_rings[i]->count = new_rx_count;
505                 }
506                 goto done;
507         }
508
509         /* We can't just free everything and then setup again,
510          * because the ISRs in MSI-X mode get passed pointers
511          * to the Tx and Rx ring structs.
512          */
513
514         /* alloc updated Tx resources */
515         if (new_tx_count != vsi->tx_rings[0]->count) {
516                 netdev_info(netdev,
517                             "Changing Tx descriptor count from %d to %d.\n",
518                             vsi->tx_rings[0]->count, new_tx_count);
519                 tx_rings = kcalloc(vsi->alloc_queue_pairs,
520                                    sizeof(struct i40e_ring), GFP_KERNEL);
521                 if (!tx_rings) {
522                         err = -ENOMEM;
523                         goto done;
524                 }
525
526                 for (i = 0; i < vsi->num_queue_pairs; i++) {
527                         /* clone ring and setup updated count */
528                         tx_rings[i] = *vsi->tx_rings[i];
529                         tx_rings[i].count = new_tx_count;
530                         err = i40e_setup_tx_descriptors(&tx_rings[i]);
531                         if (err) {
532                                 while (i) {
533                                         i--;
534                                         i40e_free_tx_resources(&tx_rings[i]);
535                                 }
536                                 kfree(tx_rings);
537                                 tx_rings = NULL;
538
539                                 goto done;
540                         }
541                 }
542         }
543
544         /* alloc updated Rx resources */
545         if (new_rx_count != vsi->rx_rings[0]->count) {
546                 netdev_info(netdev,
547                             "Changing Rx descriptor count from %d to %d\n",
548                             vsi->rx_rings[0]->count, new_rx_count);
549                 rx_rings = kcalloc(vsi->alloc_queue_pairs,
550                                    sizeof(struct i40e_ring), GFP_KERNEL);
551                 if (!rx_rings) {
552                         err = -ENOMEM;
553                         goto free_tx;
554                 }
555
556                 for (i = 0; i < vsi->num_queue_pairs; i++) {
557                         /* clone ring and setup updated count */
558                         rx_rings[i] = *vsi->rx_rings[i];
559                         rx_rings[i].count = new_rx_count;
560                         err = i40e_setup_rx_descriptors(&rx_rings[i]);
561                         if (err) {
562                                 while (i) {
563                                         i--;
564                                         i40e_free_rx_resources(&rx_rings[i]);
565                                 }
566                                 kfree(rx_rings);
567                                 rx_rings = NULL;
568
569                                 goto free_tx;
570                         }
571                 }
572         }
573
574         /* Bring interface down, copy in the new ring info,
575          * then restore the interface
576          */
577         i40e_down(vsi);
578
579         if (tx_rings) {
580                 for (i = 0; i < vsi->num_queue_pairs; i++) {
581                         i40e_free_tx_resources(vsi->tx_rings[i]);
582                         *vsi->tx_rings[i] = tx_rings[i];
583                 }
584                 kfree(tx_rings);
585                 tx_rings = NULL;
586         }
587
588         if (rx_rings) {
589                 for (i = 0; i < vsi->num_queue_pairs; i++) {
590                         i40e_free_rx_resources(vsi->rx_rings[i]);
591                         *vsi->rx_rings[i] = rx_rings[i];
592                 }
593                 kfree(rx_rings);
594                 rx_rings = NULL;
595         }
596
597         i40e_up(vsi);
598
599 free_tx:
600         /* error cleanup if the Rx allocations failed after getting Tx */
601         if (tx_rings) {
602                 for (i = 0; i < vsi->num_queue_pairs; i++)
603                         i40e_free_tx_resources(&tx_rings[i]);
604                 kfree(tx_rings);
605                 tx_rings = NULL;
606         }
607
608 done:
609         clear_bit(__I40E_CONFIG_BUSY, &pf->state);
610
611         return err;
612 }
613
614 static int i40e_get_sset_count(struct net_device *netdev, int sset)
615 {
616         struct i40e_netdev_priv *np = netdev_priv(netdev);
617         struct i40e_vsi *vsi = np->vsi;
618         struct i40e_pf *pf = vsi->back;
619
620         switch (sset) {
621         case ETH_SS_TEST:
622                 return I40E_TEST_LEN;
623         case ETH_SS_STATS:
624                 if (vsi == pf->vsi[pf->lan_vsi])
625                         return I40E_PF_STATS_LEN(netdev);
626                 else
627                         return I40E_VSI_STATS_LEN(netdev);
628         default:
629                 return -EOPNOTSUPP;
630         }
631 }
632
633 static void i40e_get_ethtool_stats(struct net_device *netdev,
634                                    struct ethtool_stats *stats, u64 *data)
635 {
636         struct i40e_netdev_priv *np = netdev_priv(netdev);
637         struct i40e_vsi *vsi = np->vsi;
638         struct i40e_pf *pf = vsi->back;
639         int i = 0;
640         char *p;
641         int j;
642         struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
643         unsigned int start;
644
645         i40e_update_stats(vsi);
646
647         for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
648                 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
649                 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
650                         sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
651         }
652         rcu_read_lock();
653         for (j = 0; j < vsi->num_queue_pairs; j++) {
654                 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
655                 struct i40e_ring *rx_ring;
656
657                 if (!tx_ring)
658                         continue;
659
660                 /* process Tx ring statistics */
661                 do {
662                         start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
663                         data[i] = tx_ring->stats.packets;
664                         data[i + 1] = tx_ring->stats.bytes;
665                 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
666                 i += 2;
667
668                 /* Rx ring is the 2nd half of the queue pair */
669                 rx_ring = &tx_ring[1];
670                 do {
671                         start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
672                         data[i] = rx_ring->stats.packets;
673                         data[i + 1] = rx_ring->stats.bytes;
674                 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
675                 i += 2;
676         }
677         rcu_read_unlock();
678         if (vsi == pf->vsi[pf->lan_vsi]) {
679                 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
680                         p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
681                         data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
682                                    sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
683                 }
684                 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
685                         data[i++] = pf->stats.priority_xon_tx[j];
686                         data[i++] = pf->stats.priority_xoff_tx[j];
687                 }
688                 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
689                         data[i++] = pf->stats.priority_xon_rx[j];
690                         data[i++] = pf->stats.priority_xoff_rx[j];
691                 }
692                 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
693                         data[i++] = pf->stats.priority_xon_2_xoff[j];
694         }
695 }
696
697 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
698                              u8 *data)
699 {
700         struct i40e_netdev_priv *np = netdev_priv(netdev);
701         struct i40e_vsi *vsi = np->vsi;
702         struct i40e_pf *pf = vsi->back;
703         char *p = (char *)data;
704         int i;
705
706         switch (stringset) {
707         case ETH_SS_TEST:
708                 for (i = 0; i < I40E_TEST_LEN; i++) {
709                         memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
710                         data += ETH_GSTRING_LEN;
711                 }
712                 break;
713         case ETH_SS_STATS:
714                 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
715                         snprintf(p, ETH_GSTRING_LEN, "%s",
716                                  i40e_gstrings_net_stats[i].stat_string);
717                         p += ETH_GSTRING_LEN;
718                 }
719                 for (i = 0; i < vsi->num_queue_pairs; i++) {
720                         snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
721                         p += ETH_GSTRING_LEN;
722                         snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
723                         p += ETH_GSTRING_LEN;
724                         snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
725                         p += ETH_GSTRING_LEN;
726                         snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
727                         p += ETH_GSTRING_LEN;
728                 }
729                 if (vsi == pf->vsi[pf->lan_vsi]) {
730                         for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
731                                 snprintf(p, ETH_GSTRING_LEN, "port.%s",
732                                          i40e_gstrings_stats[i].stat_string);
733                                 p += ETH_GSTRING_LEN;
734                         }
735                         for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
736                                 snprintf(p, ETH_GSTRING_LEN,
737                                          "port.tx_priority_%u_xon", i);
738                                 p += ETH_GSTRING_LEN;
739                                 snprintf(p, ETH_GSTRING_LEN,
740                                          "port.tx_priority_%u_xoff", i);
741                                 p += ETH_GSTRING_LEN;
742                         }
743                         for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
744                                 snprintf(p, ETH_GSTRING_LEN,
745                                          "port.rx_priority_%u_xon", i);
746                                 p += ETH_GSTRING_LEN;
747                                 snprintf(p, ETH_GSTRING_LEN,
748                                          "port.rx_priority_%u_xoff", i);
749                                 p += ETH_GSTRING_LEN;
750                         }
751                         for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
752                                 snprintf(p, ETH_GSTRING_LEN,
753                                          "port.rx_priority_%u_xon_2_xoff", i);
754                                 p += ETH_GSTRING_LEN;
755                         }
756                 }
757                 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
758                 break;
759         }
760 }
761
762 static int i40e_get_ts_info(struct net_device *dev,
763                             struct ethtool_ts_info *info)
764 {
765         struct i40e_pf *pf = i40e_netdev_to_pf(dev);
766
767         info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
768                                 SOF_TIMESTAMPING_RX_SOFTWARE |
769                                 SOF_TIMESTAMPING_SOFTWARE |
770                                 SOF_TIMESTAMPING_TX_HARDWARE |
771                                 SOF_TIMESTAMPING_RX_HARDWARE |
772                                 SOF_TIMESTAMPING_RAW_HARDWARE;
773
774         if (pf->ptp_clock)
775                 info->phc_index = ptp_clock_index(pf->ptp_clock);
776         else
777                 info->phc_index = -1;
778
779         info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
780
781         info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
782                            (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
783                            (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
784                            (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
785                            (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
786                            (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
787                            (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
788                            (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
789                            (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
790                            (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
791                            (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
792                            (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
793
794         return 0;
795 }
796
797 static int i40e_link_test(struct net_device *netdev, u64 *data)
798 {
799         struct i40e_netdev_priv *np = netdev_priv(netdev);
800         struct i40e_pf *pf = np->vsi->back;
801
802         netif_info(pf, hw, netdev, "link test\n");
803         if (i40e_get_link_status(&pf->hw))
804                 *data = 0;
805         else
806                 *data = 1;
807
808         return *data;
809 }
810
811 static int i40e_reg_test(struct net_device *netdev, u64 *data)
812 {
813         struct i40e_netdev_priv *np = netdev_priv(netdev);
814         struct i40e_pf *pf = np->vsi->back;
815
816         netif_info(pf, hw, netdev, "register test\n");
817         *data = i40e_diag_reg_test(&pf->hw);
818
819         return *data;
820 }
821
822 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
823 {
824         struct i40e_netdev_priv *np = netdev_priv(netdev);
825         struct i40e_pf *pf = np->vsi->back;
826
827         netif_info(pf, hw, netdev, "eeprom test\n");
828         *data = i40e_diag_eeprom_test(&pf->hw);
829
830         return *data;
831 }
832
833 static int i40e_intr_test(struct net_device *netdev, u64 *data)
834 {
835         struct i40e_netdev_priv *np = netdev_priv(netdev);
836         struct i40e_pf *pf = np->vsi->back;
837         u16 swc_old = pf->sw_int_count;
838
839         netif_info(pf, hw, netdev, "interrupt test\n");
840         wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
841              (I40E_PFINT_DYN_CTL0_INTENA_MASK |
842               I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
843         usleep_range(1000, 2000);
844         *data = (swc_old == pf->sw_int_count);
845
846         return *data;
847 }
848
849 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
850 {
851         struct i40e_netdev_priv *np = netdev_priv(netdev);
852         struct i40e_pf *pf = np->vsi->back;
853
854         netif_info(pf, hw, netdev, "loopback test not implemented\n");
855         *data = 0;
856
857         return *data;
858 }
859
860 static void i40e_diag_test(struct net_device *netdev,
861                            struct ethtool_test *eth_test, u64 *data)
862 {
863         struct i40e_netdev_priv *np = netdev_priv(netdev);
864         struct i40e_pf *pf = np->vsi->back;
865
866         if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
867                 /* Offline tests */
868                 netif_info(pf, drv, netdev, "offline testing starting\n");
869
870                 set_bit(__I40E_TESTING, &pf->state);
871
872                 /* Link test performed before hardware reset
873                  * so autoneg doesn't interfere with test result
874                  */
875                 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
876                         eth_test->flags |= ETH_TEST_FL_FAILED;
877
878                 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
879                         eth_test->flags |= ETH_TEST_FL_FAILED;
880
881                 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
882                         eth_test->flags |= ETH_TEST_FL_FAILED;
883
884                 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
885                         eth_test->flags |= ETH_TEST_FL_FAILED;
886
887                 /* run reg test last, a reset is required after it */
888                 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
889                         eth_test->flags |= ETH_TEST_FL_FAILED;
890
891                 clear_bit(__I40E_TESTING, &pf->state);
892                 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
893         } else {
894                 /* Online tests */
895                 netif_info(pf, drv, netdev, "online testing starting\n");
896
897                 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
898                         eth_test->flags |= ETH_TEST_FL_FAILED;
899
900                 /* Offline only tests, not run in online; pass by default */
901                 data[I40E_ETH_TEST_REG] = 0;
902                 data[I40E_ETH_TEST_EEPROM] = 0;
903                 data[I40E_ETH_TEST_INTR] = 0;
904                 data[I40E_ETH_TEST_LOOPBACK] = 0;
905         }
906
907         netif_info(pf, drv, netdev, "testing finished\n");
908 }
909
910 static void i40e_get_wol(struct net_device *netdev,
911                          struct ethtool_wolinfo *wol)
912 {
913         struct i40e_netdev_priv *np = netdev_priv(netdev);
914         struct i40e_pf *pf = np->vsi->back;
915         struct i40e_hw *hw = &pf->hw;
916         u16 wol_nvm_bits;
917
918         /* NVM bit on means WoL disabled for the port */
919         i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
920         if ((1 << hw->port) & wol_nvm_bits) {
921                 wol->supported = 0;
922                 wol->wolopts = 0;
923         } else {
924                 wol->supported = WAKE_MAGIC;
925                 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
926         }
927 }
928
929 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
930 {
931         struct i40e_netdev_priv *np = netdev_priv(netdev);
932         struct i40e_pf *pf = np->vsi->back;
933         struct i40e_hw *hw = &pf->hw;
934         u16 wol_nvm_bits;
935
936         /* NVM bit on means WoL disabled for the port */
937         i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
938         if (((1 << hw->port) & wol_nvm_bits))
939                 return -EOPNOTSUPP;
940
941         /* only magic packet is supported */
942         if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
943                 return -EOPNOTSUPP;
944
945         /* is this a new value? */
946         if (pf->wol_en != !!wol->wolopts) {
947                 pf->wol_en = !!wol->wolopts;
948                 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
949         }
950
951         return 0;
952 }
953
954 static int i40e_nway_reset(struct net_device *netdev)
955 {
956         /* restart autonegotiation */
957         struct i40e_netdev_priv *np = netdev_priv(netdev);
958         struct i40e_pf *pf = np->vsi->back;
959         struct i40e_hw *hw = &pf->hw;
960         i40e_status ret = 0;
961
962         ret = i40e_aq_set_link_restart_an(hw, NULL);
963         if (ret) {
964                 netdev_info(netdev, "link restart failed, aq_err=%d\n",
965                             pf->hw.aq.asq_last_status);
966                 return -EIO;
967         }
968
969         return 0;
970 }
971
972 static int i40e_set_phys_id(struct net_device *netdev,
973                             enum ethtool_phys_id_state state)
974 {
975         struct i40e_netdev_priv *np = netdev_priv(netdev);
976         struct i40e_pf *pf = np->vsi->back;
977         struct i40e_hw *hw = &pf->hw;
978         int blink_freq = 2;
979
980         switch (state) {
981         case ETHTOOL_ID_ACTIVE:
982                 pf->led_status = i40e_led_get(hw);
983                 return blink_freq;
984         case ETHTOOL_ID_ON:
985                 i40e_led_set(hw, 0xF, false);
986                 break;
987         case ETHTOOL_ID_OFF:
988                 i40e_led_set(hw, 0x0, false);
989                 break;
990         case ETHTOOL_ID_INACTIVE:
991                 i40e_led_set(hw, pf->led_status, false);
992                 break;
993         }
994
995         return 0;
996 }
997
998 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
999  * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1000  * 125us (8000 interrupts per second) == ITR(62)
1001  */
1002
1003 static int i40e_get_coalesce(struct net_device *netdev,
1004                              struct ethtool_coalesce *ec)
1005 {
1006         struct i40e_netdev_priv *np = netdev_priv(netdev);
1007         struct i40e_vsi *vsi = np->vsi;
1008
1009         ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1010         ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1011
1012         if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1013                 ec->use_adaptive_rx_coalesce = 1;
1014
1015         if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1016                 ec->use_adaptive_tx_coalesce = 1;
1017
1018         ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1019         ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1020
1021         return 0;
1022 }
1023
1024 static int i40e_set_coalesce(struct net_device *netdev,
1025                              struct ethtool_coalesce *ec)
1026 {
1027         struct i40e_netdev_priv *np = netdev_priv(netdev);
1028         struct i40e_q_vector *q_vector;
1029         struct i40e_vsi *vsi = np->vsi;
1030         struct i40e_pf *pf = vsi->back;
1031         struct i40e_hw *hw = &pf->hw;
1032         u16 vector;
1033         int i;
1034
1035         if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1036                 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1037
1038         if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1039             (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
1040                 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1041         else
1042                 return -EINVAL;
1043
1044         if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1045             (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
1046                 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1047         else
1048                 return -EINVAL;
1049
1050         if (ec->use_adaptive_rx_coalesce)
1051                 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1052         else
1053                 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1054
1055         if (ec->use_adaptive_tx_coalesce)
1056                 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1057         else
1058                 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1059
1060         vector = vsi->base_vector;
1061         for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1062                 q_vector = vsi->q_vectors[i];
1063                 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1064                 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1065                 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1066                 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1067                 i40e_flush(hw);
1068         }
1069
1070         return 0;
1071 }
1072
1073 /**
1074  * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1075  * @pf: pointer to the physical function struct
1076  * @cmd: ethtool rxnfc command
1077  *
1078  * Returns Success if the flow is supported, else Invalid Input.
1079  **/
1080 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1081 {
1082         cmd->data = 0;
1083
1084         /* Report default options for RSS on i40e */
1085         switch (cmd->flow_type) {
1086         case TCP_V4_FLOW:
1087         case UDP_V4_FLOW:
1088                 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1089         /* fall through to add IP fields */
1090         case SCTP_V4_FLOW:
1091         case AH_ESP_V4_FLOW:
1092         case AH_V4_FLOW:
1093         case ESP_V4_FLOW:
1094         case IPV4_FLOW:
1095                 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1096                 break;
1097         case TCP_V6_FLOW:
1098         case UDP_V6_FLOW:
1099                 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1100         /* fall through to add IP fields */
1101         case SCTP_V6_FLOW:
1102         case AH_ESP_V6_FLOW:
1103         case AH_V6_FLOW:
1104         case ESP_V6_FLOW:
1105         case IPV6_FLOW:
1106                 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1107                 break;
1108         default:
1109                 return -EINVAL;
1110         }
1111
1112         return 0;
1113 }
1114
1115 /**
1116  * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1117  * @pf: Pointer to the physical function struct
1118  * @cmd: The command to get or set Rx flow classification rules
1119  * @rule_locs: Array of used rule locations
1120  *
1121  * This function populates both the total and actual rule count of
1122  * the ethtool flow classification command
1123  *
1124  * Returns 0 on success or -EMSGSIZE if entry not found
1125  **/
1126 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1127                                      struct ethtool_rxnfc *cmd,
1128                                      u32 *rule_locs)
1129 {
1130         struct i40e_fdir_filter *rule;
1131         struct hlist_node *node2;
1132         int cnt = 0;
1133
1134         /* report total rule count */
1135         cmd->data = pf->hw.fdir_shared_filter_count +
1136                     pf->fdir_pf_filter_count;
1137
1138         hlist_for_each_entry_safe(rule, node2,
1139                                   &pf->fdir_filter_list, fdir_node) {
1140                 if (cnt == cmd->rule_cnt)
1141                         return -EMSGSIZE;
1142
1143                 rule_locs[cnt] = rule->fd_id;
1144                 cnt++;
1145         }
1146
1147         cmd->rule_cnt = cnt;
1148
1149         return 0;
1150 }
1151
1152 /**
1153  * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1154  * @pf: Pointer to the physical function struct
1155  * @cmd: The command to get or set Rx flow classification rules
1156  *
1157  * This function looks up a filter based on the Rx flow classification
1158  * command and fills the flow spec info for it if found
1159  *
1160  * Returns 0 on success or -EINVAL if filter not found
1161  **/
1162 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1163                                        struct ethtool_rxnfc *cmd)
1164 {
1165         struct ethtool_rx_flow_spec *fsp =
1166                         (struct ethtool_rx_flow_spec *)&cmd->fs;
1167         struct i40e_fdir_filter *rule = NULL;
1168         struct hlist_node *node2;
1169
1170         /* report total rule count */
1171         cmd->data = pf->hw.fdir_shared_filter_count +
1172                     pf->fdir_pf_filter_count;
1173
1174         hlist_for_each_entry_safe(rule, node2,
1175                                   &pf->fdir_filter_list, fdir_node) {
1176                 if (fsp->location <= rule->fd_id)
1177                         break;
1178         }
1179
1180         if (!rule || fsp->location != rule->fd_id)
1181                 return -EINVAL;
1182
1183         fsp->flow_type = rule->flow_type;
1184         if (fsp->flow_type == IP_USER_FLOW) {
1185                 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1186                 fsp->h_u.usr_ip4_spec.proto = 0;
1187                 fsp->m_u.usr_ip4_spec.proto = 0;
1188         }
1189
1190         fsp->h_u.tcp_ip4_spec.psrc = rule->src_port;
1191         fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port;
1192         fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0];
1193         fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0];
1194         fsp->ring_cookie = rule->q_index;
1195
1196         return 0;
1197 }
1198
1199 /**
1200  * i40e_get_rxnfc - command to get RX flow classification rules
1201  * @netdev: network interface device structure
1202  * @cmd: ethtool rxnfc command
1203  *
1204  * Returns Success if the command is supported.
1205  **/
1206 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1207                           u32 *rule_locs)
1208 {
1209         struct i40e_netdev_priv *np = netdev_priv(netdev);
1210         struct i40e_vsi *vsi = np->vsi;
1211         struct i40e_pf *pf = vsi->back;
1212         int ret = -EOPNOTSUPP;
1213
1214         switch (cmd->cmd) {
1215         case ETHTOOL_GRXRINGS:
1216                 cmd->data = vsi->alloc_queue_pairs;
1217                 ret = 0;
1218                 break;
1219         case ETHTOOL_GRXFH:
1220                 ret = i40e_get_rss_hash_opts(pf, cmd);
1221                 break;
1222         case ETHTOOL_GRXCLSRLCNT:
1223                 cmd->rule_cnt = pf->fdir_pf_active_filters;
1224                 ret = 0;
1225                 break;
1226         case ETHTOOL_GRXCLSRULE:
1227                 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
1228                 break;
1229         case ETHTOOL_GRXCLSRLALL:
1230                 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1231                 break;
1232         default:
1233                 break;
1234         }
1235
1236         return ret;
1237 }
1238
1239 /**
1240  * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1241  * @pf: pointer to the physical function struct
1242  * @cmd: ethtool rxnfc command
1243  *
1244  * Returns Success if the flow input set is supported.
1245  **/
1246 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1247 {
1248         struct i40e_hw *hw = &pf->hw;
1249         u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1250                    ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1251
1252         /* RSS does not support anything other than hashing
1253          * to queues on src and dst IPs and ports
1254          */
1255         if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1256                           RXH_L4_B_0_1 | RXH_L4_B_2_3))
1257                 return -EINVAL;
1258
1259         /* We need at least the IP SRC and DEST fields for hashing */
1260         if (!(nfc->data & RXH_IP_SRC) ||
1261             !(nfc->data & RXH_IP_DST))
1262                 return -EINVAL;
1263
1264         switch (nfc->flow_type) {
1265         case TCP_V4_FLOW:
1266                 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1267                 case 0:
1268                         hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1269                         break;
1270                 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1271                         hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1272                         break;
1273                 default:
1274                         return -EINVAL;
1275                 }
1276                 break;
1277         case TCP_V6_FLOW:
1278                 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1279                 case 0:
1280                         hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1281                         break;
1282                 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1283                         hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1284                         break;
1285                 default:
1286                         return -EINVAL;
1287                 }
1288                 break;
1289         case UDP_V4_FLOW:
1290                 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1291                 case 0:
1292                         hena &=
1293                         ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1294                         ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1295                         ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1296                         break;
1297                 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1298                         hena |=
1299                         (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP)  |
1300                         ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1301                         ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1302                         break;
1303                 default:
1304                         return -EINVAL;
1305                 }
1306                 break;
1307         case UDP_V6_FLOW:
1308                 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1309                 case 0:
1310                         hena &=
1311                         ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1312                         ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1313                         ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1314                         break;
1315                 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1316                         hena |=
1317                         (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP)  |
1318                         ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1319                         ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1320                         break;
1321                 default:
1322                         return -EINVAL;
1323                 }
1324                 break;
1325         case AH_ESP_V4_FLOW:
1326         case AH_V4_FLOW:
1327         case ESP_V4_FLOW:
1328         case SCTP_V4_FLOW:
1329                 if ((nfc->data & RXH_L4_B_0_1) ||
1330                     (nfc->data & RXH_L4_B_2_3))
1331                         return -EINVAL;
1332                 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1333                 break;
1334         case AH_ESP_V6_FLOW:
1335         case AH_V6_FLOW:
1336         case ESP_V6_FLOW:
1337         case SCTP_V6_FLOW:
1338                 if ((nfc->data & RXH_L4_B_0_1) ||
1339                     (nfc->data & RXH_L4_B_2_3))
1340                         return -EINVAL;
1341                 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1342                 break;
1343         case IPV4_FLOW:
1344                 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1345                         ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1346                 break;
1347         case IPV6_FLOW:
1348                 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1349                         ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1350                 break;
1351         default:
1352                 return -EINVAL;
1353         }
1354
1355         wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1356         wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1357         i40e_flush(hw);
1358
1359         return 0;
1360 }
1361
1362 /**
1363  * i40e_match_fdir_input_set - Match a new filter against an existing one
1364  * @rule: The filter already added
1365  * @input: The new filter to comapre against
1366  *
1367  * Returns true if the two input set match
1368  **/
1369 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1370                                       struct i40e_fdir_filter *input)
1371 {
1372         if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1373             (rule->src_ip[0] != input->src_ip[0]) ||
1374             (rule->dst_port != input->dst_port) ||
1375             (rule->src_port != input->src_port))
1376                 return false;
1377         return true;
1378 }
1379
1380 /**
1381  * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1382  * @vsi: Pointer to the targeted VSI
1383  * @input: The filter to update or NULL to indicate deletion
1384  * @sw_idx: Software index to the filter
1385  * @cmd: The command to get or set Rx flow classification rules
1386  *
1387  * This function updates (or deletes) a Flow Director entry from
1388  * the hlist of the corresponding PF
1389  *
1390  * Returns 0 on success
1391  **/
1392 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1393                                           struct i40e_fdir_filter *input,
1394                                           u16 sw_idx,
1395                                           struct ethtool_rxnfc *cmd)
1396 {
1397         struct i40e_fdir_filter *rule, *parent;
1398         struct i40e_pf *pf = vsi->back;
1399         struct hlist_node *node2;
1400         int err = -EINVAL;
1401
1402         parent = NULL;
1403         rule = NULL;
1404
1405         hlist_for_each_entry_safe(rule, node2,
1406                                   &pf->fdir_filter_list, fdir_node) {
1407                 /* hash found, or no matching entry */
1408                 if (rule->fd_id >= sw_idx)
1409                         break;
1410                 parent = rule;
1411         }
1412
1413         /* if there is an old rule occupying our place remove it */
1414         if (rule && (rule->fd_id == sw_idx)) {
1415                 if (input && !i40e_match_fdir_input_set(rule, input))
1416                         err = i40e_add_del_fdir(vsi, rule, false);
1417                 else if (!input)
1418                         err = i40e_add_del_fdir(vsi, rule, false);
1419                 hlist_del(&rule->fdir_node);
1420                 kfree(rule);
1421                 pf->fdir_pf_active_filters--;
1422         }
1423
1424         /* If no input this was a delete, err should be 0 if a rule was
1425          * successfully found and removed from the list else -EINVAL
1426          */
1427         if (!input)
1428                 return err;
1429
1430         /* initialize node and set software index */
1431         INIT_HLIST_NODE(&input->fdir_node);
1432
1433         /* add filter to the list */
1434         if (parent)
1435                 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1436         else
1437                 hlist_add_head(&input->fdir_node,
1438                                &pf->fdir_filter_list);
1439
1440         /* update counts */
1441         pf->fdir_pf_active_filters++;
1442
1443         return 0;
1444 }
1445
1446 /**
1447  * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1448  * @vsi: Pointer to the targeted VSI
1449  * @cmd: The command to get or set Rx flow classification rules
1450  *
1451  * The function removes a Flow Director filter entry from the
1452  * hlist of the corresponding PF
1453  *
1454  * Returns 0 on success
1455  */
1456 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1457                                struct ethtool_rxnfc *cmd)
1458 {
1459         struct ethtool_rx_flow_spec *fsp =
1460                 (struct ethtool_rx_flow_spec *)&cmd->fs;
1461         struct i40e_pf *pf = vsi->back;
1462         int ret = 0;
1463
1464         ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
1465
1466         i40e_fdir_check_and_reenable(pf);
1467         return ret;
1468 }
1469
1470 /**
1471  * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
1472  * @vsi: pointer to the targeted VSI
1473  * @cmd: command to get or set RX flow classification rules
1474  *
1475  * Add Flow Director filters for a specific flow spec based on their
1476  * protocol.  Returns 0 if the filters were successfully added.
1477  **/
1478 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1479                                  struct ethtool_rxnfc *cmd)
1480 {
1481         struct ethtool_rx_flow_spec *fsp;
1482         struct i40e_fdir_filter *input;
1483         struct i40e_pf *pf;
1484         int ret = -EINVAL;
1485
1486         if (!vsi)
1487                 return -EINVAL;
1488
1489         pf = vsi->back;
1490
1491         if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1492                 return -EOPNOTSUPP;
1493
1494         if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
1495                 return -ENOSPC;
1496
1497         fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1498
1499         if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1500                               pf->hw.func_caps.fd_filters_guaranteed)) {
1501                 return -EINVAL;
1502         }
1503
1504         if (fsp->ring_cookie >= vsi->num_queue_pairs)
1505                 return -EINVAL;
1506
1507         input = kzalloc(sizeof(*input), GFP_KERNEL);
1508
1509         if (!input)
1510                 return -ENOMEM;
1511
1512         input->fd_id = fsp->location;
1513
1514         if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1515                 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1516         else
1517                 input->dest_ctl =
1518                              I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1519
1520         input->q_index = fsp->ring_cookie;
1521         input->flex_off = 0;
1522         input->pctype = 0;
1523         input->dest_vsi = vsi->id;
1524         input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
1525         input->cnt_index = 0;
1526         input->flow_type = fsp->flow_type;
1527         input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
1528         input->src_port = fsp->h_u.tcp_ip4_spec.psrc;
1529         input->dst_port = fsp->h_u.tcp_ip4_spec.pdst;
1530         input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1531         input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
1532
1533         ret = i40e_add_del_fdir(vsi, input, true);
1534         if (ret)
1535                 kfree(input);
1536         else
1537                 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
1538
1539         return ret;
1540 }
1541
1542 /**
1543  * i40e_set_rxnfc - command to set RX flow classification rules
1544  * @netdev: network interface device structure
1545  * @cmd: ethtool rxnfc command
1546  *
1547  * Returns Success if the command is supported.
1548  **/
1549 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1550 {
1551         struct i40e_netdev_priv *np = netdev_priv(netdev);
1552         struct i40e_vsi *vsi = np->vsi;
1553         struct i40e_pf *pf = vsi->back;
1554         int ret = -EOPNOTSUPP;
1555
1556         switch (cmd->cmd) {
1557         case ETHTOOL_SRXFH:
1558                 ret = i40e_set_rss_hash_opt(pf, cmd);
1559                 break;
1560         case ETHTOOL_SRXCLSRLINS:
1561                 ret = i40e_add_fdir_ethtool(vsi, cmd);
1562                 break;
1563         case ETHTOOL_SRXCLSRLDEL:
1564                 ret = i40e_del_fdir_entry(vsi, cmd);
1565                 break;
1566         default:
1567                 break;
1568         }
1569
1570         return ret;
1571 }
1572
1573 /**
1574  * i40e_max_channels - get Max number of combined channels supported
1575  * @vsi: vsi pointer
1576  **/
1577 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1578 {
1579         /* TODO: This code assumes DCB and FD is disabled for now. */
1580         return vsi->alloc_queue_pairs;
1581 }
1582
1583 /**
1584  * i40e_get_channels - Get the current channels enabled and max supported etc.
1585  * @netdev: network interface device structure
1586  * @ch: ethtool channels structure
1587  *
1588  * We don't support separate tx and rx queues as channels. The other count
1589  * represents how many queues are being used for control. max_combined counts
1590  * how many queue pairs we can support. They may not be mapped 1 to 1 with
1591  * q_vectors since we support a lot more queue pairs than q_vectors.
1592  **/
1593 static void i40e_get_channels(struct net_device *dev,
1594                                struct ethtool_channels *ch)
1595 {
1596         struct i40e_netdev_priv *np = netdev_priv(dev);
1597         struct i40e_vsi *vsi = np->vsi;
1598         struct i40e_pf *pf = vsi->back;
1599
1600         /* report maximum channels */
1601         ch->max_combined = i40e_max_channels(vsi);
1602
1603         /* report info for other vector */
1604         ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
1605         ch->max_other = ch->other_count;
1606
1607         /* Note: This code assumes DCB is disabled for now. */
1608         ch->combined_count = vsi->num_queue_pairs;
1609 }
1610
1611 /**
1612  * i40e_set_channels - Set the new channels count.
1613  * @netdev: network interface device structure
1614  * @ch: ethtool channels structure
1615  *
1616  * The new channels count may not be the same as requested by the user
1617  * since it gets rounded down to a power of 2 value.
1618  **/
1619 static int i40e_set_channels(struct net_device *dev,
1620                               struct ethtool_channels *ch)
1621 {
1622         struct i40e_netdev_priv *np = netdev_priv(dev);
1623         unsigned int count = ch->combined_count;
1624         struct i40e_vsi *vsi = np->vsi;
1625         struct i40e_pf *pf = vsi->back;
1626         int new_count;
1627
1628         /* We do not support setting channels for any other VSI at present */
1629         if (vsi->type != I40E_VSI_MAIN)
1630                 return -EINVAL;
1631
1632         /* verify they are not requesting separate vectors */
1633         if (!count || ch->rx_count || ch->tx_count)
1634                 return -EINVAL;
1635
1636         /* verify other_count has not changed */
1637         if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
1638                 return -EINVAL;
1639
1640         /* verify the number of channels does not exceed hardware limits */
1641         if (count > i40e_max_channels(vsi))
1642                 return -EINVAL;
1643
1644         /* update feature limits from largest to smallest supported values */
1645         /* TODO: Flow director limit, DCB etc */
1646
1647         /* cap RSS limit */
1648         if (count > pf->rss_size_max)
1649                 count = pf->rss_size_max;
1650
1651         /* use rss_reconfig to rebuild with new queue count and update traffic
1652          * class queue mapping
1653          */
1654         new_count = i40e_reconfig_rss_queues(pf, count);
1655         if (new_count > 0)
1656                 return 0;
1657         else
1658                 return -EINVAL;
1659 }
1660
1661 static const struct ethtool_ops i40e_ethtool_ops = {
1662         .get_settings           = i40e_get_settings,
1663         .get_drvinfo            = i40e_get_drvinfo,
1664         .get_regs_len           = i40e_get_regs_len,
1665         .get_regs               = i40e_get_regs,
1666         .nway_reset             = i40e_nway_reset,
1667         .get_link               = ethtool_op_get_link,
1668         .get_wol                = i40e_get_wol,
1669         .set_wol                = i40e_set_wol,
1670         .get_eeprom_len         = i40e_get_eeprom_len,
1671         .get_eeprom             = i40e_get_eeprom,
1672         .get_ringparam          = i40e_get_ringparam,
1673         .set_ringparam          = i40e_set_ringparam,
1674         .get_pauseparam         = i40e_get_pauseparam,
1675         .get_msglevel           = i40e_get_msglevel,
1676         .set_msglevel           = i40e_set_msglevel,
1677         .get_rxnfc              = i40e_get_rxnfc,
1678         .set_rxnfc              = i40e_set_rxnfc,
1679         .self_test              = i40e_diag_test,
1680         .get_strings            = i40e_get_strings,
1681         .set_phys_id            = i40e_set_phys_id,
1682         .get_sset_count         = i40e_get_sset_count,
1683         .get_ethtool_stats      = i40e_get_ethtool_stats,
1684         .get_coalesce           = i40e_get_coalesce,
1685         .set_coalesce           = i40e_set_coalesce,
1686         .get_channels           = i40e_get_channels,
1687         .set_channels           = i40e_set_channels,
1688         .get_ts_info            = i40e_get_ts_info,
1689 };
1690
1691 void i40e_set_ethtool_ops(struct net_device *netdev)
1692 {
1693         netdev->ethtool_ops = &i40e_ethtool_ops;
1694 }