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