ice: Add VF promiscuous support
[linux-2.6-microblaze.git] / drivers / net / ethernet / intel / ice / ice_ethtool.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
3
4 /* ethtool support for ice */
5
6 #include "ice.h"
7 #include "ice_flow.h"
8 #include "ice_lib.h"
9 #include "ice_dcb_lib.h"
10
11 struct ice_stats {
12         char stat_string[ETH_GSTRING_LEN];
13         int sizeof_stat;
14         int stat_offset;
15 };
16
17 #define ICE_STAT(_type, _name, _stat) { \
18         .stat_string = _name, \
19         .sizeof_stat = sizeof_field(_type, _stat), \
20         .stat_offset = offsetof(_type, _stat) \
21 }
22
23 #define ICE_VSI_STAT(_name, _stat) \
24                 ICE_STAT(struct ice_vsi, _name, _stat)
25 #define ICE_PF_STAT(_name, _stat) \
26                 ICE_STAT(struct ice_pf, _name, _stat)
27
28 static int ice_q_stats_len(struct net_device *netdev)
29 {
30         struct ice_netdev_priv *np = netdev_priv(netdev);
31
32         return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
33                 (sizeof(struct ice_q_stats) / sizeof(u64)));
34 }
35
36 #define ICE_PF_STATS_LEN        ARRAY_SIZE(ice_gstrings_pf_stats)
37 #define ICE_VSI_STATS_LEN       ARRAY_SIZE(ice_gstrings_vsi_stats)
38
39 #define ICE_PFC_STATS_LEN ( \
40                 (sizeof_field(struct ice_pf, stats.priority_xoff_rx) + \
41                  sizeof_field(struct ice_pf, stats.priority_xon_rx) + \
42                  sizeof_field(struct ice_pf, stats.priority_xoff_tx) + \
43                  sizeof_field(struct ice_pf, stats.priority_xon_tx)) \
44                  / sizeof(u64))
45 #define ICE_ALL_STATS_LEN(n)    (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
46                                  ICE_VSI_STATS_LEN + ice_q_stats_len(n))
47
48 static const struct ice_stats ice_gstrings_vsi_stats[] = {
49         ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
50         ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
51         ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
52         ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
53         ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
54         ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
55         ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
56         ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
57         ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards),
58         ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
59         ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
60         ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
61         ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
62         ICE_VSI_STAT("tx_linearize", tx_linearize),
63 };
64
65 enum ice_ethtool_test_id {
66         ICE_ETH_TEST_REG = 0,
67         ICE_ETH_TEST_EEPROM,
68         ICE_ETH_TEST_INTR,
69         ICE_ETH_TEST_LOOP,
70         ICE_ETH_TEST_LINK,
71 };
72
73 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
74         "Register test  (offline)",
75         "EEPROM test    (offline)",
76         "Interrupt test (offline)",
77         "Loopback test  (offline)",
78         "Link test   (on/offline)",
79 };
80
81 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
82
83 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
84  * but they aren't. This device is capable of supporting multiple
85  * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
86  * netdevs whereas the PF_STATs are for the physical function that's
87  * hosting these netdevs.
88  *
89  * The PF_STATs are appended to the netdev stats only when ethtool -S
90  * is queried on the base PF netdev.
91  */
92 static const struct ice_stats ice_gstrings_pf_stats[] = {
93         ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
94         ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
95         ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
96         ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
97         ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
98         ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
99         ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
100         ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
101         ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
102         ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
103         ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
104         ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
105         ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
106         ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
107         ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
108         ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
109         ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
110         ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
111         ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
112         ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
113         ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
114         ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
115         ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
116         ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
117         ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
118         ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
119         ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
120         ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
121         ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
122         ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
123         ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
124         ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
125         ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
126         ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors),
127         ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
128         ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
129         ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
130         ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
131         ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
132 };
133
134 static const u32 ice_regs_dump_list[] = {
135         PFGEN_STATE,
136         PRTGEN_STATUS,
137         QRX_CTRL(0),
138         QINT_TQCTL(0),
139         QINT_RQCTL(0),
140         PFINT_OICR_ENA,
141         QRX_ITR(0),
142         PF0INT_ITR_0(0),
143         PF0INT_ITR_1(0),
144         PF0INT_ITR_2(0),
145 };
146
147 struct ice_priv_flag {
148         char name[ETH_GSTRING_LEN];
149         u32 bitno;                      /* bit position in pf->flags */
150 };
151
152 #define ICE_PRIV_FLAG(_name, _bitno) { \
153         .name = _name, \
154         .bitno = _bitno, \
155 }
156
157 static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
158         ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
159         ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
160         ICE_PRIV_FLAG("vf-true-promisc-support",
161                       ICE_FLAG_VF_TRUE_PROMISC_ENA),
162         ICE_PRIV_FLAG("mdd-auto-reset-vf", ICE_FLAG_MDD_AUTO_RESET_VF),
163         ICE_PRIV_FLAG("legacy-rx", ICE_FLAG_LEGACY_RX),
164 };
165
166 #define ICE_PRIV_FLAG_ARRAY_SIZE        ARRAY_SIZE(ice_gstrings_priv_flags)
167
168 static void
169 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
170 {
171         struct ice_netdev_priv *np = netdev_priv(netdev);
172         struct ice_vsi *vsi = np->vsi;
173         struct ice_pf *pf = vsi->back;
174         struct ice_hw *hw = &pf->hw;
175         struct ice_orom_info *orom;
176         struct ice_nvm_info *nvm;
177
178         nvm = &hw->nvm;
179         orom = &nvm->orom;
180
181         strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
182         strscpy(drvinfo->version, ice_drv_ver, sizeof(drvinfo->version));
183
184         /* Display NVM version (from which the firmware version can be
185          * determined) which contains more pertinent information.
186          */
187         snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
188                  "%x.%02x 0x%x %d.%d.%d", nvm->major_ver, nvm->minor_ver,
189                  nvm->eetrack, orom->major, orom->build, orom->patch);
190
191         strscpy(drvinfo->bus_info, pci_name(pf->pdev),
192                 sizeof(drvinfo->bus_info));
193         drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
194 }
195
196 static int ice_get_regs_len(struct net_device __always_unused *netdev)
197 {
198         return sizeof(ice_regs_dump_list);
199 }
200
201 static void
202 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
203 {
204         struct ice_netdev_priv *np = netdev_priv(netdev);
205         struct ice_pf *pf = np->vsi->back;
206         struct ice_hw *hw = &pf->hw;
207         u32 *regs_buf = (u32 *)p;
208         int i;
209
210         regs->version = 1;
211
212         for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
213                 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
214 }
215
216 static u32 ice_get_msglevel(struct net_device *netdev)
217 {
218         struct ice_netdev_priv *np = netdev_priv(netdev);
219         struct ice_pf *pf = np->vsi->back;
220
221 #ifndef CONFIG_DYNAMIC_DEBUG
222         if (pf->hw.debug_mask)
223                 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
224                             pf->hw.debug_mask);
225 #endif /* !CONFIG_DYNAMIC_DEBUG */
226
227         return pf->msg_enable;
228 }
229
230 static void ice_set_msglevel(struct net_device *netdev, u32 data)
231 {
232         struct ice_netdev_priv *np = netdev_priv(netdev);
233         struct ice_pf *pf = np->vsi->back;
234
235 #ifndef CONFIG_DYNAMIC_DEBUG
236         if (ICE_DBG_USER & data)
237                 pf->hw.debug_mask = data;
238         else
239                 pf->msg_enable = data;
240 #else
241         pf->msg_enable = data;
242 #endif /* !CONFIG_DYNAMIC_DEBUG */
243 }
244
245 static int ice_get_eeprom_len(struct net_device *netdev)
246 {
247         struct ice_netdev_priv *np = netdev_priv(netdev);
248         struct ice_pf *pf = np->vsi->back;
249
250         return (int)pf->hw.nvm.flash_size;
251 }
252
253 static int
254 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
255                u8 *bytes)
256 {
257         struct ice_netdev_priv *np = netdev_priv(netdev);
258         struct ice_vsi *vsi = np->vsi;
259         struct ice_pf *pf = vsi->back;
260         struct ice_hw *hw = &pf->hw;
261         enum ice_status status;
262         struct device *dev;
263         int ret = 0;
264         u8 *buf;
265
266         dev = ice_pf_to_dev(pf);
267
268         eeprom->magic = hw->vendor_id | (hw->device_id << 16);
269         netdev_dbg(netdev, "GEEPROM cmd 0x%08x, offset 0x%08x, len 0x%08x\n",
270                    eeprom->cmd, eeprom->offset, eeprom->len);
271
272         buf = kzalloc(eeprom->len, GFP_KERNEL);
273         if (!buf)
274                 return -ENOMEM;
275
276         status = ice_acquire_nvm(hw, ICE_RES_READ);
277         if (status) {
278                 dev_err(dev, "ice_acquire_nvm failed, err %d aq_err %d\n",
279                         status, hw->adminq.sq_last_status);
280                 ret = -EIO;
281                 goto out;
282         }
283
284         status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf,
285                                    false);
286         if (status) {
287                 dev_err(dev, "ice_read_flat_nvm failed, err %d aq_err %d\n",
288                         status, hw->adminq.sq_last_status);
289                 ret = -EIO;
290                 goto release;
291         }
292
293         memcpy(bytes, buf, eeprom->len);
294 release:
295         ice_release_nvm(hw);
296 out:
297         kfree(buf);
298         return ret;
299 }
300
301 /**
302  * ice_active_vfs - check if there are any active VFs
303  * @pf: board private structure
304  *
305  * Returns true if an active VF is found, otherwise returns false
306  */
307 static bool ice_active_vfs(struct ice_pf *pf)
308 {
309         int i;
310
311         ice_for_each_vf(pf, i) {
312                 struct ice_vf *vf = &pf->vf[i];
313
314                 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
315                         return true;
316         }
317
318         return false;
319 }
320
321 /**
322  * ice_link_test - perform a link test on a given net_device
323  * @netdev: network interface device structure
324  *
325  * This function performs one of the self-tests required by ethtool.
326  * Returns 0 on success, non-zero on failure.
327  */
328 static u64 ice_link_test(struct net_device *netdev)
329 {
330         struct ice_netdev_priv *np = netdev_priv(netdev);
331         enum ice_status status;
332         bool link_up = false;
333
334         netdev_info(netdev, "link test\n");
335         status = ice_get_link_status(np->vsi->port_info, &link_up);
336         if (status) {
337                 netdev_err(netdev, "link query error, status = %d\n", status);
338                 return 1;
339         }
340
341         if (!link_up)
342                 return 2;
343
344         return 0;
345 }
346
347 /**
348  * ice_eeprom_test - perform an EEPROM test on a given net_device
349  * @netdev: network interface device structure
350  *
351  * This function performs one of the self-tests required by ethtool.
352  * Returns 0 on success, non-zero on failure.
353  */
354 static u64 ice_eeprom_test(struct net_device *netdev)
355 {
356         struct ice_netdev_priv *np = netdev_priv(netdev);
357         struct ice_pf *pf = np->vsi->back;
358
359         netdev_info(netdev, "EEPROM test\n");
360         return !!(ice_nvm_validate_checksum(&pf->hw));
361 }
362
363 /**
364  * ice_reg_pattern_test
365  * @hw: pointer to the HW struct
366  * @reg: reg to be tested
367  * @mask: bits to be touched
368  */
369 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
370 {
371         struct ice_pf *pf = (struct ice_pf *)hw->back;
372         struct device *dev = ice_pf_to_dev(pf);
373         static const u32 patterns[] = {
374                 0x5A5A5A5A, 0xA5A5A5A5,
375                 0x00000000, 0xFFFFFFFF
376         };
377         u32 val, orig_val;
378         int i;
379
380         orig_val = rd32(hw, reg);
381         for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
382                 u32 pattern = patterns[i] & mask;
383
384                 wr32(hw, reg, pattern);
385                 val = rd32(hw, reg);
386                 if (val == pattern)
387                         continue;
388                 dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
389                         , __func__, reg, pattern, val);
390                 return 1;
391         }
392
393         wr32(hw, reg, orig_val);
394         val = rd32(hw, reg);
395         if (val != orig_val) {
396                 dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
397                         , __func__, reg, orig_val, val);
398                 return 1;
399         }
400
401         return 0;
402 }
403
404 /**
405  * ice_reg_test - perform a register test on a given net_device
406  * @netdev: network interface device structure
407  *
408  * This function performs one of the self-tests required by ethtool.
409  * Returns 0 on success, non-zero on failure.
410  */
411 static u64 ice_reg_test(struct net_device *netdev)
412 {
413         struct ice_netdev_priv *np = netdev_priv(netdev);
414         struct ice_hw *hw = np->vsi->port_info->hw;
415         u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
416                 hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
417         struct ice_diag_reg_test_info {
418                 u32 address;
419                 u32 mask;
420                 u32 elem_num;
421                 u32 elem_size;
422         } ice_reg_list[] = {
423                 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
424                         GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
425                 {GLINT_ITR(1, 0), 0x00000fff, int_elements,
426                         GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
427                 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
428                         GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
429                 {GLINT_CTL, 0xffff0001, 1, 0}
430         };
431         int i;
432
433         netdev_dbg(netdev, "Register test\n");
434         for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
435                 u32 j;
436
437                 for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
438                         u32 mask = ice_reg_list[i].mask;
439                         u32 reg = ice_reg_list[i].address +
440                                 (j * ice_reg_list[i].elem_size);
441
442                         /* bail on failure (non-zero return) */
443                         if (ice_reg_pattern_test(hw, reg, mask))
444                                 return 1;
445                 }
446         }
447
448         return 0;
449 }
450
451 /**
452  * ice_lbtest_prepare_rings - configure Tx/Rx test rings
453  * @vsi: pointer to the VSI structure
454  *
455  * Function configures rings of a VSI for loopback test without
456  * enabling interrupts or informing the kernel about new queues.
457  *
458  * Returns 0 on success, negative on failure.
459  */
460 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
461 {
462         int status;
463
464         status = ice_vsi_setup_tx_rings(vsi);
465         if (status)
466                 goto err_setup_tx_ring;
467
468         status = ice_vsi_setup_rx_rings(vsi);
469         if (status)
470                 goto err_setup_rx_ring;
471
472         status = ice_vsi_cfg(vsi);
473         if (status)
474                 goto err_setup_rx_ring;
475
476         status = ice_vsi_start_all_rx_rings(vsi);
477         if (status)
478                 goto err_start_rx_ring;
479
480         return status;
481
482 err_start_rx_ring:
483         ice_vsi_free_rx_rings(vsi);
484 err_setup_rx_ring:
485         ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
486 err_setup_tx_ring:
487         ice_vsi_free_tx_rings(vsi);
488
489         return status;
490 }
491
492 /**
493  * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
494  * @vsi: pointer to the VSI structure
495  *
496  * Function stops and frees VSI rings after a loopback test.
497  * Returns 0 on success, negative on failure.
498  */
499 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
500 {
501         int status;
502
503         status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
504         if (status)
505                 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
506                            vsi->vsi_num, status);
507
508         status = ice_vsi_stop_all_rx_rings(vsi);
509         if (status)
510                 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
511                            vsi->vsi_num, status);
512
513         ice_vsi_free_tx_rings(vsi);
514         ice_vsi_free_rx_rings(vsi);
515
516         return status;
517 }
518
519 /**
520  * ice_lbtest_create_frame - create test packet
521  * @pf: pointer to the PF structure
522  * @ret_data: allocated frame buffer
523  * @size: size of the packet data
524  *
525  * Function allocates a frame with a test pattern on specific offsets.
526  * Returns 0 on success, non-zero on failure.
527  */
528 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
529 {
530         u8 *data;
531
532         if (!pf)
533                 return -EINVAL;
534
535         data = devm_kzalloc(ice_pf_to_dev(pf), size, GFP_KERNEL);
536         if (!data)
537                 return -ENOMEM;
538
539         /* Since the ethernet test frame should always be at least
540          * 64 bytes long, fill some octets in the payload with test data.
541          */
542         memset(data, 0xFF, size);
543         data[32] = 0xDE;
544         data[42] = 0xAD;
545         data[44] = 0xBE;
546         data[46] = 0xEF;
547
548         *ret_data = data;
549
550         return 0;
551 }
552
553 /**
554  * ice_lbtest_check_frame - verify received loopback frame
555  * @frame: pointer to the raw packet data
556  *
557  * Function verifies received test frame with a pattern.
558  * Returns true if frame matches the pattern, false otherwise.
559  */
560 static bool ice_lbtest_check_frame(u8 *frame)
561 {
562         /* Validate bytes of a frame under offsets chosen earlier */
563         if (frame[32] == 0xDE &&
564             frame[42] == 0xAD &&
565             frame[44] == 0xBE &&
566             frame[46] == 0xEF &&
567             frame[48] == 0xFF)
568                 return true;
569
570         return false;
571 }
572
573 /**
574  * ice_diag_send - send test frames to the test ring
575  * @tx_ring: pointer to the transmit ring
576  * @data: pointer to the raw packet data
577  * @size: size of the packet to send
578  *
579  * Function sends loopback packets on a test Tx ring.
580  */
581 static int ice_diag_send(struct ice_ring *tx_ring, u8 *data, u16 size)
582 {
583         struct ice_tx_desc *tx_desc;
584         struct ice_tx_buf *tx_buf;
585         dma_addr_t dma;
586         u64 td_cmd;
587
588         tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
589         tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
590
591         dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
592         if (dma_mapping_error(tx_ring->dev, dma))
593                 return -EINVAL;
594
595         tx_desc->buf_addr = cpu_to_le64(dma);
596
597         /* These flags are required for a descriptor to be pushed out */
598         td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
599         tx_desc->cmd_type_offset_bsz =
600                 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
601                             (td_cmd << ICE_TXD_QW1_CMD_S) |
602                             ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
603                             ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
604                             ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
605
606         tx_buf->next_to_watch = tx_desc;
607
608         /* Force memory write to complete before letting h/w know
609          * there are new descriptors to fetch.
610          */
611         wmb();
612
613         tx_ring->next_to_use++;
614         if (tx_ring->next_to_use >= tx_ring->count)
615                 tx_ring->next_to_use = 0;
616
617         writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
618
619         /* Wait until the packets get transmitted to the receive queue. */
620         usleep_range(1000, 2000);
621         dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
622
623         return 0;
624 }
625
626 #define ICE_LB_FRAME_SIZE 64
627 /**
628  * ice_lbtest_receive_frames - receive and verify test frames
629  * @rx_ring: pointer to the receive ring
630  *
631  * Function receives loopback packets and verify their correctness.
632  * Returns number of received valid frames.
633  */
634 static int ice_lbtest_receive_frames(struct ice_ring *rx_ring)
635 {
636         struct ice_rx_buf *rx_buf;
637         int valid_frames, i;
638         u8 *received_buf;
639
640         valid_frames = 0;
641
642         for (i = 0; i < rx_ring->count; i++) {
643                 union ice_32b_rx_flex_desc *rx_desc;
644
645                 rx_desc = ICE_RX_DESC(rx_ring, i);
646
647                 if (!(rx_desc->wb.status_error0 &
648                     cpu_to_le16(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)))
649                         continue;
650
651                 rx_buf = &rx_ring->rx_buf[i];
652                 received_buf = page_address(rx_buf->page) + rx_buf->page_offset;
653
654                 if (ice_lbtest_check_frame(received_buf))
655                         valid_frames++;
656         }
657
658         return valid_frames;
659 }
660
661 /**
662  * ice_loopback_test - perform a loopback test on a given net_device
663  * @netdev: network interface device structure
664  *
665  * This function performs one of the self-tests required by ethtool.
666  * Returns 0 on success, non-zero on failure.
667  */
668 static u64 ice_loopback_test(struct net_device *netdev)
669 {
670         struct ice_netdev_priv *np = netdev_priv(netdev);
671         struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
672         struct ice_pf *pf = orig_vsi->back;
673         struct ice_ring *tx_ring, *rx_ring;
674         u8 broadcast[ETH_ALEN], ret = 0;
675         int num_frames, valid_frames;
676         LIST_HEAD(tmp_list);
677         struct device *dev;
678         u8 *tx_frame;
679         int i;
680
681         dev = ice_pf_to_dev(pf);
682         netdev_info(netdev, "loopback test\n");
683
684         test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
685         if (!test_vsi) {
686                 netdev_err(netdev, "Failed to create a VSI for the loopback test\n");
687                 return 1;
688         }
689
690         test_vsi->netdev = netdev;
691         tx_ring = test_vsi->tx_rings[0];
692         rx_ring = test_vsi->rx_rings[0];
693
694         if (ice_lbtest_prepare_rings(test_vsi)) {
695                 ret = 2;
696                 goto lbtest_vsi_close;
697         }
698
699         if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
700                 ret = 3;
701                 goto lbtest_rings_dis;
702         }
703
704         /* Enable MAC loopback in firmware */
705         if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
706                 ret = 4;
707                 goto lbtest_mac_dis;
708         }
709
710         /* Test VSI needs to receive broadcast packets */
711         eth_broadcast_addr(broadcast);
712         if (ice_add_mac_to_list(test_vsi, &tmp_list, broadcast)) {
713                 ret = 5;
714                 goto lbtest_mac_dis;
715         }
716
717         if (ice_add_mac(&pf->hw, &tmp_list)) {
718                 ret = 6;
719                 goto free_mac_list;
720         }
721
722         if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
723                 ret = 7;
724                 goto remove_mac_filters;
725         }
726
727         num_frames = min_t(int, tx_ring->count, 32);
728         for (i = 0; i < num_frames; i++) {
729                 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
730                         ret = 8;
731                         goto lbtest_free_frame;
732                 }
733         }
734
735         valid_frames = ice_lbtest_receive_frames(rx_ring);
736         if (!valid_frames)
737                 ret = 9;
738         else if (valid_frames != num_frames)
739                 ret = 10;
740
741 lbtest_free_frame:
742         devm_kfree(dev, tx_frame);
743 remove_mac_filters:
744         if (ice_remove_mac(&pf->hw, &tmp_list))
745                 netdev_err(netdev, "Could not remove MAC filter for the test VSI\n");
746 free_mac_list:
747         ice_free_fltr_list(dev, &tmp_list);
748 lbtest_mac_dis:
749         /* Disable MAC loopback after the test is completed. */
750         if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
751                 netdev_err(netdev, "Could not disable MAC loopback\n");
752 lbtest_rings_dis:
753         if (ice_lbtest_disable_rings(test_vsi))
754                 netdev_err(netdev, "Could not disable test rings\n");
755 lbtest_vsi_close:
756         test_vsi->netdev = NULL;
757         if (ice_vsi_release(test_vsi))
758                 netdev_err(netdev, "Failed to remove the test VSI\n");
759
760         return ret;
761 }
762
763 /**
764  * ice_intr_test - perform an interrupt test on a given net_device
765  * @netdev: network interface device structure
766  *
767  * This function performs one of the self-tests required by ethtool.
768  * Returns 0 on success, non-zero on failure.
769  */
770 static u64 ice_intr_test(struct net_device *netdev)
771 {
772         struct ice_netdev_priv *np = netdev_priv(netdev);
773         struct ice_pf *pf = np->vsi->back;
774         u16 swic_old = pf->sw_int_count;
775
776         netdev_info(netdev, "interrupt test\n");
777
778         wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_idx),
779              GLINT_DYN_CTL_SW_ITR_INDX_M |
780              GLINT_DYN_CTL_INTENA_MSK_M |
781              GLINT_DYN_CTL_SWINT_TRIG_M);
782
783         usleep_range(1000, 2000);
784         return (swic_old == pf->sw_int_count);
785 }
786
787 /**
788  * ice_self_test - handler function for performing a self-test by ethtool
789  * @netdev: network interface device structure
790  * @eth_test: ethtool_test structure
791  * @data: required by ethtool.self_test
792  *
793  * This function is called after invoking 'ethtool -t devname' command where
794  * devname is the name of the network device on which ethtool should operate.
795  * It performs a set of self-tests to check if a device works properly.
796  */
797 static void
798 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
799               u64 *data)
800 {
801         struct ice_netdev_priv *np = netdev_priv(netdev);
802         bool if_running = netif_running(netdev);
803         struct ice_pf *pf = np->vsi->back;
804         struct device *dev;
805
806         dev = ice_pf_to_dev(pf);
807
808         if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
809                 netdev_info(netdev, "offline testing starting\n");
810
811                 set_bit(__ICE_TESTING, pf->state);
812
813                 if (ice_active_vfs(pf)) {
814                         dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
815                         data[ICE_ETH_TEST_REG] = 1;
816                         data[ICE_ETH_TEST_EEPROM] = 1;
817                         data[ICE_ETH_TEST_INTR] = 1;
818                         data[ICE_ETH_TEST_LOOP] = 1;
819                         data[ICE_ETH_TEST_LINK] = 1;
820                         eth_test->flags |= ETH_TEST_FL_FAILED;
821                         clear_bit(__ICE_TESTING, pf->state);
822                         goto skip_ol_tests;
823                 }
824                 /* If the device is online then take it offline */
825                 if (if_running)
826                         /* indicate we're in test mode */
827                         ice_stop(netdev);
828
829                 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
830                 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
831                 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
832                 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
833                 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
834
835                 if (data[ICE_ETH_TEST_LINK] ||
836                     data[ICE_ETH_TEST_EEPROM] ||
837                     data[ICE_ETH_TEST_LOOP] ||
838                     data[ICE_ETH_TEST_INTR] ||
839                     data[ICE_ETH_TEST_REG])
840                         eth_test->flags |= ETH_TEST_FL_FAILED;
841
842                 clear_bit(__ICE_TESTING, pf->state);
843
844                 if (if_running) {
845                         int status = ice_open(netdev);
846
847                         if (status) {
848                                 dev_err(dev, "Could not open device %s, err %d\n",
849                                         pf->int_name, status);
850                         }
851                 }
852         } else {
853                 /* Online tests */
854                 netdev_info(netdev, "online testing starting\n");
855
856                 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
857                 if (data[ICE_ETH_TEST_LINK])
858                         eth_test->flags |= ETH_TEST_FL_FAILED;
859
860                 /* Offline only tests, not run in online; pass by default */
861                 data[ICE_ETH_TEST_REG] = 0;
862                 data[ICE_ETH_TEST_EEPROM] = 0;
863                 data[ICE_ETH_TEST_INTR] = 0;
864                 data[ICE_ETH_TEST_LOOP] = 0;
865         }
866
867 skip_ol_tests:
868         netdev_info(netdev, "testing finished\n");
869 }
870
871 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
872 {
873         struct ice_netdev_priv *np = netdev_priv(netdev);
874         struct ice_vsi *vsi = np->vsi;
875         char *p = (char *)data;
876         unsigned int i;
877
878         switch (stringset) {
879         case ETH_SS_STATS:
880                 for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
881                         snprintf(p, ETH_GSTRING_LEN, "%s",
882                                  ice_gstrings_vsi_stats[i].stat_string);
883                         p += ETH_GSTRING_LEN;
884                 }
885
886                 ice_for_each_alloc_txq(vsi, i) {
887                         snprintf(p, ETH_GSTRING_LEN,
888                                  "tx_queue_%u_packets", i);
889                         p += ETH_GSTRING_LEN;
890                         snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
891                         p += ETH_GSTRING_LEN;
892                 }
893
894                 ice_for_each_alloc_rxq(vsi, i) {
895                         snprintf(p, ETH_GSTRING_LEN,
896                                  "rx_queue_%u_packets", i);
897                         p += ETH_GSTRING_LEN;
898                         snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
899                         p += ETH_GSTRING_LEN;
900                 }
901
902                 if (vsi->type != ICE_VSI_PF)
903                         return;
904
905                 for (i = 0; i < ICE_PF_STATS_LEN; i++) {
906                         snprintf(p, ETH_GSTRING_LEN, "%s",
907                                  ice_gstrings_pf_stats[i].stat_string);
908                         p += ETH_GSTRING_LEN;
909                 }
910
911                 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
912                         snprintf(p, ETH_GSTRING_LEN,
913                                  "tx_priority_%u_xon.nic", i);
914                         p += ETH_GSTRING_LEN;
915                         snprintf(p, ETH_GSTRING_LEN,
916                                  "tx_priority_%u_xoff.nic", i);
917                         p += ETH_GSTRING_LEN;
918                 }
919                 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
920                         snprintf(p, ETH_GSTRING_LEN,
921                                  "rx_priority_%u_xon.nic", i);
922                         p += ETH_GSTRING_LEN;
923                         snprintf(p, ETH_GSTRING_LEN,
924                                  "rx_priority_%u_xoff.nic", i);
925                         p += ETH_GSTRING_LEN;
926                 }
927                 break;
928         case ETH_SS_TEST:
929                 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
930                 break;
931         case ETH_SS_PRIV_FLAGS:
932                 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
933                         snprintf(p, ETH_GSTRING_LEN, "%s",
934                                  ice_gstrings_priv_flags[i].name);
935                         p += ETH_GSTRING_LEN;
936                 }
937                 break;
938         default:
939                 break;
940         }
941 }
942
943 static int
944 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
945 {
946         struct ice_netdev_priv *np = netdev_priv(netdev);
947         bool led_active;
948
949         switch (state) {
950         case ETHTOOL_ID_ACTIVE:
951                 led_active = true;
952                 break;
953         case ETHTOOL_ID_INACTIVE:
954                 led_active = false;
955                 break;
956         default:
957                 return -EINVAL;
958         }
959
960         if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
961                 return -EIO;
962
963         return 0;
964 }
965
966 /**
967  * ice_set_fec_cfg - Set link FEC options
968  * @netdev: network interface device structure
969  * @req_fec: FEC mode to configure
970  */
971 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
972 {
973         struct ice_netdev_priv *np = netdev_priv(netdev);
974         struct ice_aqc_set_phy_cfg_data config = { 0 };
975         struct ice_aqc_get_phy_caps_data *caps;
976         struct ice_vsi *vsi = np->vsi;
977         u8 sw_cfg_caps, sw_cfg_fec;
978         struct ice_port_info *pi;
979         enum ice_status status;
980         int err = 0;
981
982         pi = vsi->port_info;
983         if (!pi)
984                 return -EOPNOTSUPP;
985
986         /* Changing the FEC parameters is not supported if not the PF VSI */
987         if (vsi->type != ICE_VSI_PF) {
988                 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
989                 return -EOPNOTSUPP;
990         }
991
992         /* Get last SW configuration */
993         caps = kzalloc(sizeof(*caps), GFP_KERNEL);
994         if (!caps)
995                 return -ENOMEM;
996
997         status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
998                                      caps, NULL);
999         if (status) {
1000                 err = -EAGAIN;
1001                 goto done;
1002         }
1003
1004         /* Copy SW configuration returned from PHY caps to PHY config */
1005         ice_copy_phy_caps_to_cfg(caps, &config);
1006         sw_cfg_caps = caps->caps;
1007         sw_cfg_fec = caps->link_fec_options;
1008
1009         /* Get toloplogy caps, then copy PHY FEC topoloy caps to PHY config */
1010         memset(caps, 0, sizeof(*caps));
1011
1012         status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1013                                      caps, NULL);
1014         if (status) {
1015                 err = -EAGAIN;
1016                 goto done;
1017         }
1018
1019         config.caps |= (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC);
1020         config.link_fec_opt = caps->link_fec_options;
1021
1022         ice_cfg_phy_fec(&config, req_fec);
1023
1024         /* If FEC mode has changed, then set PHY configuration and enable AN. */
1025         if ((config.caps & ICE_AQ_PHY_ENA_AUTO_FEC) !=
1026             (sw_cfg_caps & ICE_AQC_PHY_EN_AUTO_FEC) ||
1027             config.link_fec_opt != sw_cfg_fec) {
1028                 if (caps->caps & ICE_AQC_PHY_AN_MODE)
1029                         config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1030
1031                 status = ice_aq_set_phy_cfg(pi->hw, pi->lport, &config, NULL);
1032
1033                 if (status)
1034                         err = -EAGAIN;
1035         }
1036
1037 done:
1038         kfree(caps);
1039         return err;
1040 }
1041
1042 /**
1043  * ice_set_fecparam - Set FEC link options
1044  * @netdev: network interface device structure
1045  * @fecparam: Ethtool structure to retrieve FEC parameters
1046  */
1047 static int
1048 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1049 {
1050         struct ice_netdev_priv *np = netdev_priv(netdev);
1051         struct ice_vsi *vsi = np->vsi;
1052         enum ice_fec_mode fec;
1053
1054         switch (fecparam->fec) {
1055         case ETHTOOL_FEC_AUTO:
1056                 fec = ICE_FEC_AUTO;
1057                 break;
1058         case ETHTOOL_FEC_RS:
1059                 fec = ICE_FEC_RS;
1060                 break;
1061         case ETHTOOL_FEC_BASER:
1062                 fec = ICE_FEC_BASER;
1063                 break;
1064         case ETHTOOL_FEC_OFF:
1065         case ETHTOOL_FEC_NONE:
1066                 fec = ICE_FEC_NONE;
1067                 break;
1068         default:
1069                 dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n",
1070                          fecparam->fec);
1071                 return -EINVAL;
1072         }
1073
1074         return ice_set_fec_cfg(netdev, fec);
1075 }
1076
1077 /**
1078  * ice_get_fecparam - Get link FEC options
1079  * @netdev: network interface device structure
1080  * @fecparam: Ethtool structure to retrieve FEC parameters
1081  */
1082 static int
1083 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1084 {
1085         struct ice_netdev_priv *np = netdev_priv(netdev);
1086         struct ice_aqc_get_phy_caps_data *caps;
1087         struct ice_link_status *link_info;
1088         struct ice_vsi *vsi = np->vsi;
1089         struct ice_port_info *pi;
1090         enum ice_status status;
1091         int err = 0;
1092
1093         pi = vsi->port_info;
1094
1095         if (!pi)
1096                 return -EOPNOTSUPP;
1097         link_info = &pi->phy.link_info;
1098
1099         /* Set FEC mode based on negotiated link info */
1100         switch (link_info->fec_info) {
1101         case ICE_AQ_LINK_25G_KR_FEC_EN:
1102                 fecparam->active_fec = ETHTOOL_FEC_BASER;
1103                 break;
1104         case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1105         case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1106                 fecparam->active_fec = ETHTOOL_FEC_RS;
1107                 break;
1108         default:
1109                 fecparam->active_fec = ETHTOOL_FEC_OFF;
1110                 break;
1111         }
1112
1113         caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1114         if (!caps)
1115                 return -ENOMEM;
1116
1117         status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1118                                      caps, NULL);
1119         if (status) {
1120                 err = -EAGAIN;
1121                 goto done;
1122         }
1123
1124         /* Set supported/configured FEC modes based on PHY capability */
1125         if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1126                 fecparam->fec |= ETHTOOL_FEC_AUTO;
1127         if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1128             caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1129             caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1130             caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1131                 fecparam->fec |= ETHTOOL_FEC_BASER;
1132         if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1133             caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1134             caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1135                 fecparam->fec |= ETHTOOL_FEC_RS;
1136         if (caps->link_fec_options == 0)
1137                 fecparam->fec |= ETHTOOL_FEC_OFF;
1138
1139 done:
1140         kfree(caps);
1141         return err;
1142 }
1143
1144 /**
1145  * ice_nway_reset - restart autonegotiation
1146  * @netdev: network interface device structure
1147  */
1148 static int ice_nway_reset(struct net_device *netdev)
1149 {
1150         struct ice_netdev_priv *np = netdev_priv(netdev);
1151         struct ice_vsi *vsi = np->vsi;
1152         struct ice_port_info *pi;
1153         enum ice_status status;
1154
1155         pi = vsi->port_info;
1156         /* If VSI state is up, then restart autoneg with link up */
1157         if (!test_bit(__ICE_DOWN, vsi->back->state))
1158                 status = ice_aq_set_link_restart_an(pi, true, NULL);
1159         else
1160                 status = ice_aq_set_link_restart_an(pi, false, NULL);
1161
1162         if (status) {
1163                 netdev_info(netdev, "link restart failed, err %d aq_err %d\n",
1164                             status, pi->hw->adminq.sq_last_status);
1165                 return -EIO;
1166         }
1167
1168         return 0;
1169 }
1170
1171 /**
1172  * ice_get_priv_flags - report device private flags
1173  * @netdev: network interface device structure
1174  *
1175  * The get string set count and the string set should be matched for each
1176  * flag returned.  Add new strings for each flag to the ice_gstrings_priv_flags
1177  * array.
1178  *
1179  * Returns a u32 bitmap of flags.
1180  */
1181 static u32 ice_get_priv_flags(struct net_device *netdev)
1182 {
1183         struct ice_netdev_priv *np = netdev_priv(netdev);
1184         struct ice_vsi *vsi = np->vsi;
1185         struct ice_pf *pf = vsi->back;
1186         u32 i, ret_flags = 0;
1187
1188         for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1189                 const struct ice_priv_flag *priv_flag;
1190
1191                 priv_flag = &ice_gstrings_priv_flags[i];
1192
1193                 if (test_bit(priv_flag->bitno, pf->flags))
1194                         ret_flags |= BIT(i);
1195         }
1196
1197         return ret_flags;
1198 }
1199
1200 /**
1201  * ice_set_priv_flags - set private flags
1202  * @netdev: network interface device structure
1203  * @flags: bit flags to be set
1204  */
1205 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1206 {
1207         struct ice_netdev_priv *np = netdev_priv(netdev);
1208         DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1209         DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1210         struct ice_vsi *vsi = np->vsi;
1211         struct ice_pf *pf = vsi->back;
1212         struct device *dev;
1213         int ret = 0;
1214         u32 i;
1215
1216         if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1217                 return -EINVAL;
1218
1219         dev = ice_pf_to_dev(pf);
1220         set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1221
1222         bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1223         for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1224                 const struct ice_priv_flag *priv_flag;
1225
1226                 priv_flag = &ice_gstrings_priv_flags[i];
1227
1228                 if (flags & BIT(i))
1229                         set_bit(priv_flag->bitno, pf->flags);
1230                 else
1231                         clear_bit(priv_flag->bitno, pf->flags);
1232         }
1233
1234         bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1235
1236         if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1237                 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1238                         enum ice_status status;
1239
1240                         /* Disable FW LLDP engine */
1241                         status = ice_cfg_lldp_mib_change(&pf->hw, false);
1242
1243                         /* If unregistering for LLDP events fails, this is
1244                          * not an error state, as there shouldn't be any
1245                          * events to respond to.
1246                          */
1247                         if (status)
1248                                 dev_info(dev, "Failed to unreg for LLDP events\n");
1249
1250                         /* The AQ call to stop the FW LLDP agent will generate
1251                          * an error if the agent is already stopped.
1252                          */
1253                         status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1254                         if (status)
1255                                 dev_warn(dev, "Fail to stop LLDP agent\n");
1256                         /* Use case for having the FW LLDP agent stopped
1257                          * will likely not need DCB, so failure to init is
1258                          * not a concern of ethtool
1259                          */
1260                         status = ice_init_pf_dcb(pf, true);
1261                         if (status)
1262                                 dev_warn(dev, "Fail to init DCB\n");
1263                 } else {
1264                         enum ice_status status;
1265                         bool dcbx_agent_status;
1266
1267                         /* AQ command to start FW LLDP agent will return an
1268                          * error if the agent is already started
1269                          */
1270                         status = ice_aq_start_lldp(&pf->hw, true, NULL);
1271                         if (status)
1272                                 dev_warn(dev, "Fail to start LLDP Agent\n");
1273
1274                         /* AQ command to start FW DCBX agent will fail if
1275                          * the agent is already started
1276                          */
1277                         status = ice_aq_start_stop_dcbx(&pf->hw, true,
1278                                                         &dcbx_agent_status,
1279                                                         NULL);
1280                         if (status)
1281                                 dev_dbg(dev, "Failed to start FW DCBX\n");
1282
1283                         dev_info(dev, "FW DCBX agent is %s\n",
1284                                  dcbx_agent_status ? "ACTIVE" : "DISABLED");
1285
1286                         /* Failure to configure MIB change or init DCB is not
1287                          * relevant to ethtool.  Print notification that
1288                          * registration/init failed but do not return error
1289                          * state to ethtool
1290                          */
1291                         status = ice_init_pf_dcb(pf, true);
1292                         if (status)
1293                                 dev_dbg(dev, "Fail to init DCB\n");
1294
1295                         /* Remove rule to direct LLDP packets to default VSI.
1296                          * The FW LLDP engine will now be consuming them.
1297                          */
1298                         ice_cfg_sw_lldp(vsi, false, false);
1299
1300                         /* Register for MIB change events */
1301                         status = ice_cfg_lldp_mib_change(&pf->hw, true);
1302                         if (status)
1303                                 dev_dbg(dev, "Fail to enable MIB change events\n");
1304
1305                         ice_nway_reset(netdev);
1306                 }
1307         }
1308         if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) {
1309                 /* down and up VSI so that changes of Rx cfg are reflected. */
1310                 ice_down(vsi);
1311                 ice_up(vsi);
1312         }
1313         /* don't allow modification of this flag when a single VF is in
1314          * promiscuous mode because it's not supported
1315          */
1316         if (test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, change_flags) &&
1317             ice_is_any_vf_in_promisc(pf)) {
1318                 dev_err(dev, "Changing vf-true-promisc-support flag while VF(s) are in promiscuous mode not supported\n");
1319                 /* toggle bit back to previous state */
1320                 change_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags);
1321                 ret = -EAGAIN;
1322         }
1323         clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1324         return ret;
1325 }
1326
1327 static int ice_get_sset_count(struct net_device *netdev, int sset)
1328 {
1329         switch (sset) {
1330         case ETH_SS_STATS:
1331                 /* The number (and order) of strings reported *must* remain
1332                  * constant for a given netdevice. This function must not
1333                  * report a different number based on run time parameters
1334                  * (such as the number of queues in use, or the setting of
1335                  * a private ethtool flag). This is due to the nature of the
1336                  * ethtool stats API.
1337                  *
1338                  * Userspace programs such as ethtool must make 3 separate
1339                  * ioctl requests, one for size, one for the strings, and
1340                  * finally one for the stats. Since these cross into
1341                  * userspace, changes to the number or size could result in
1342                  * undefined memory access or incorrect string<->value
1343                  * correlations for statistics.
1344                  *
1345                  * Even if it appears to be safe, changes to the size or
1346                  * order of strings will suffer from race conditions and are
1347                  * not safe.
1348                  */
1349                 return ICE_ALL_STATS_LEN(netdev);
1350         case ETH_SS_TEST:
1351                 return ICE_TEST_LEN;
1352         case ETH_SS_PRIV_FLAGS:
1353                 return ICE_PRIV_FLAG_ARRAY_SIZE;
1354         default:
1355                 return -EOPNOTSUPP;
1356         }
1357 }
1358
1359 static void
1360 ice_get_ethtool_stats(struct net_device *netdev,
1361                       struct ethtool_stats __always_unused *stats, u64 *data)
1362 {
1363         struct ice_netdev_priv *np = netdev_priv(netdev);
1364         struct ice_vsi *vsi = np->vsi;
1365         struct ice_pf *pf = vsi->back;
1366         struct ice_ring *ring;
1367         unsigned int j;
1368         int i = 0;
1369         char *p;
1370
1371         ice_update_pf_stats(pf);
1372         ice_update_vsi_stats(vsi);
1373
1374         for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1375                 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1376                 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1377                              sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1378         }
1379
1380         /* populate per queue stats */
1381         rcu_read_lock();
1382
1383         ice_for_each_alloc_txq(vsi, j) {
1384                 ring = READ_ONCE(vsi->tx_rings[j]);
1385                 if (ring) {
1386                         data[i++] = ring->stats.pkts;
1387                         data[i++] = ring->stats.bytes;
1388                 } else {
1389                         data[i++] = 0;
1390                         data[i++] = 0;
1391                 }
1392         }
1393
1394         ice_for_each_alloc_rxq(vsi, j) {
1395                 ring = READ_ONCE(vsi->rx_rings[j]);
1396                 if (ring) {
1397                         data[i++] = ring->stats.pkts;
1398                         data[i++] = ring->stats.bytes;
1399                 } else {
1400                         data[i++] = 0;
1401                         data[i++] = 0;
1402                 }
1403         }
1404
1405         rcu_read_unlock();
1406
1407         if (vsi->type != ICE_VSI_PF)
1408                 return;
1409
1410         for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1411                 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1412                 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1413                              sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1414         }
1415
1416         for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1417                 data[i++] = pf->stats.priority_xon_tx[j];
1418                 data[i++] = pf->stats.priority_xoff_tx[j];
1419         }
1420
1421         for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1422                 data[i++] = pf->stats.priority_xon_rx[j];
1423                 data[i++] = pf->stats.priority_xoff_rx[j];
1424         }
1425 }
1426
1427 /**
1428  * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1429  * @netdev: network interface device structure
1430  * @ks: ethtool link ksettings struct to fill out
1431  */
1432 static void
1433 ice_phy_type_to_ethtool(struct net_device *netdev,
1434                         struct ethtool_link_ksettings *ks)
1435 {
1436         struct ice_netdev_priv *np = netdev_priv(netdev);
1437         struct ice_link_status *hw_link_info;
1438         bool need_add_adv_mode = false;
1439         struct ice_vsi *vsi = np->vsi;
1440         u64 phy_types_high;
1441         u64 phy_types_low;
1442
1443         hw_link_info = &vsi->port_info->phy.link_info;
1444         phy_types_low = vsi->port_info->phy.phy_type_low;
1445         phy_types_high = vsi->port_info->phy.phy_type_high;
1446
1447         ethtool_link_ksettings_zero_link_mode(ks, supported);
1448         ethtool_link_ksettings_zero_link_mode(ks, advertising);
1449
1450         if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1451             phy_types_low & ICE_PHY_TYPE_LOW_100M_SGMII) {
1452                 ethtool_link_ksettings_add_link_mode(ks, supported,
1453                                                      100baseT_Full);
1454                 if (!hw_link_info->req_speeds ||
1455                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100MB)
1456                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1457                                                              100baseT_Full);
1458         }
1459         if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1460             phy_types_low & ICE_PHY_TYPE_LOW_1G_SGMII) {
1461                 ethtool_link_ksettings_add_link_mode(ks, supported,
1462                                                      1000baseT_Full);
1463                 if (!hw_link_info->req_speeds ||
1464                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1465                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1466                                                              1000baseT_Full);
1467         }
1468         if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX) {
1469                 ethtool_link_ksettings_add_link_mode(ks, supported,
1470                                                      1000baseKX_Full);
1471                 if (!hw_link_info->req_speeds ||
1472                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1473                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1474                                                              1000baseKX_Full);
1475         }
1476         if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_SX ||
1477             phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_LX) {
1478                 ethtool_link_ksettings_add_link_mode(ks, supported,
1479                                                      1000baseX_Full);
1480                 if (!hw_link_info->req_speeds ||
1481                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1482                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1483                                                              1000baseX_Full);
1484         }
1485         if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T) {
1486                 ethtool_link_ksettings_add_link_mode(ks, supported,
1487                                                      2500baseT_Full);
1488                 if (!hw_link_info->req_speeds ||
1489                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1490                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1491                                                              2500baseT_Full);
1492         }
1493         if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_X ||
1494             phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX) {
1495                 ethtool_link_ksettings_add_link_mode(ks, supported,
1496                                                      2500baseX_Full);
1497                 if (!hw_link_info->req_speeds ||
1498                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1499                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1500                                                              2500baseX_Full);
1501         }
1502         if (phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1503             phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR) {
1504                 ethtool_link_ksettings_add_link_mode(ks, supported,
1505                                                      5000baseT_Full);
1506                 if (!hw_link_info->req_speeds ||
1507                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_5GB)
1508                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1509                                                              5000baseT_Full);
1510         }
1511         if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1512             phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_DA ||
1513             phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC ||
1514             phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_C2C) {
1515                 ethtool_link_ksettings_add_link_mode(ks, supported,
1516                                                      10000baseT_Full);
1517                 if (!hw_link_info->req_speeds ||
1518                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1519                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1520                                                              10000baseT_Full);
1521         }
1522         if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1) {
1523                 ethtool_link_ksettings_add_link_mode(ks, supported,
1524                                                      10000baseKR_Full);
1525                 if (!hw_link_info->req_speeds ||
1526                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1527                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1528                                                              10000baseKR_Full);
1529         }
1530         if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_SR) {
1531                 ethtool_link_ksettings_add_link_mode(ks, supported,
1532                                                      10000baseSR_Full);
1533                 if (!hw_link_info->req_speeds ||
1534                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1535                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1536                                                              10000baseSR_Full);
1537         }
1538         if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_LR) {
1539                 ethtool_link_ksettings_add_link_mode(ks, supported,
1540                                                      10000baseLR_Full);
1541                 if (!hw_link_info->req_speeds ||
1542                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1543                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1544                                                              10000baseLR_Full);
1545         }
1546         if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1547             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1548             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1549             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1550             phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC ||
1551             phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_C2C) {
1552                 ethtool_link_ksettings_add_link_mode(ks, supported,
1553                                                      25000baseCR_Full);
1554                 if (!hw_link_info->req_speeds ||
1555                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1556                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1557                                                              25000baseCR_Full);
1558         }
1559         if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_SR ||
1560             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_LR) {
1561                 ethtool_link_ksettings_add_link_mode(ks, supported,
1562                                                      25000baseSR_Full);
1563                 if (!hw_link_info->req_speeds ||
1564                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1565                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1566                                                              25000baseSR_Full);
1567         }
1568         if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1569             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1570             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1) {
1571                 ethtool_link_ksettings_add_link_mode(ks, supported,
1572                                                      25000baseKR_Full);
1573                 if (!hw_link_info->req_speeds ||
1574                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1575                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1576                                                              25000baseKR_Full);
1577         }
1578         if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1579                 ethtool_link_ksettings_add_link_mode(ks, supported,
1580                                                      40000baseKR4_Full);
1581                 if (!hw_link_info->req_speeds ||
1582                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1583                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1584                                                              40000baseKR4_Full);
1585         }
1586         if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1587             phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC ||
1588             phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI) {
1589                 ethtool_link_ksettings_add_link_mode(ks, supported,
1590                                                      40000baseCR4_Full);
1591                 if (!hw_link_info->req_speeds ||
1592                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1593                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1594                                                              40000baseCR4_Full);
1595         }
1596         if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_SR4) {
1597                 ethtool_link_ksettings_add_link_mode(ks, supported,
1598                                                      40000baseSR4_Full);
1599                 if (!hw_link_info->req_speeds ||
1600                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1601                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1602                                                              40000baseSR4_Full);
1603         }
1604         if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_LR4) {
1605                 ethtool_link_ksettings_add_link_mode(ks, supported,
1606                                                      40000baseLR4_Full);
1607                 if (!hw_link_info->req_speeds ||
1608                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1609                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1610                                                              40000baseLR4_Full);
1611         }
1612         if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1613             phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC ||
1614             phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2 ||
1615             phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC ||
1616             phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2 ||
1617             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1618             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR ||
1619             phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC ||
1620             phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1) {
1621                 ethtool_link_ksettings_add_link_mode(ks, supported,
1622                                                      50000baseCR2_Full);
1623                 if (!hw_link_info->req_speeds ||
1624                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1625                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1626                                                              50000baseCR2_Full);
1627         }
1628         if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1629             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1630                 ethtool_link_ksettings_add_link_mode(ks, supported,
1631                                                      50000baseKR2_Full);
1632                 if (!hw_link_info->req_speeds ||
1633                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1634                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1635                                                              50000baseKR2_Full);
1636         }
1637         if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR2 ||
1638             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR2 ||
1639             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_FR ||
1640             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR) {
1641                 ethtool_link_ksettings_add_link_mode(ks, supported,
1642                                                      50000baseSR2_Full);
1643                 if (!hw_link_info->req_speeds ||
1644                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1645                         ethtool_link_ksettings_add_link_mode(ks, advertising,
1646                                                              50000baseSR2_Full);
1647         }
1648         if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1649             phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC ||
1650             phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4 ||
1651             phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC ||
1652             phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4 ||
1653             phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 ||
1654             phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2  ||
1655             phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC ||
1656             phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2 ||
1657             phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC ||
1658             phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2) {
1659                 ethtool_link_ksettings_add_link_mode(ks, supported,
1660                                                      100000baseCR4_Full);
1661                 if (!hw_link_info->req_speeds ||
1662                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1663                         need_add_adv_mode = true;
1664         }
1665         if (need_add_adv_mode) {
1666                 need_add_adv_mode = false;
1667                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1668                                                      100000baseCR4_Full);
1669         }
1670         if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR4 ||
1671             phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR2) {
1672                 ethtool_link_ksettings_add_link_mode(ks, supported,
1673                                                      100000baseSR4_Full);
1674                 if (!hw_link_info->req_speeds ||
1675                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1676                         need_add_adv_mode = true;
1677         }
1678         if (need_add_adv_mode) {
1679                 need_add_adv_mode = false;
1680                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1681                                                      100000baseSR4_Full);
1682         }
1683         if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_LR4 ||
1684             phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_DR) {
1685                 ethtool_link_ksettings_add_link_mode(ks, supported,
1686                                                      100000baseLR4_ER4_Full);
1687                 if (!hw_link_info->req_speeds ||
1688                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1689                         need_add_adv_mode = true;
1690         }
1691         if (need_add_adv_mode) {
1692                 need_add_adv_mode = false;
1693                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1694                                                      100000baseLR4_ER4_Full);
1695         }
1696         if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1697             phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1698             phy_types_high & ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4) {
1699                 ethtool_link_ksettings_add_link_mode(ks, supported,
1700                                                      100000baseKR4_Full);
1701                 if (!hw_link_info->req_speeds ||
1702                     hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1703                         need_add_adv_mode = true;
1704         }
1705         if (need_add_adv_mode)
1706                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1707                                                      100000baseKR4_Full);
1708
1709         /* Autoneg PHY types */
1710         if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1711             phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1712             phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX ||
1713             phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T ||
1714             phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX ||
1715             phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1716             phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR ||
1717             phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1718             phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 ||
1719             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1720             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1721             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1722             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1723             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1724             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1725             phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1 ||
1726             phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1727             phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1728                 ethtool_link_ksettings_add_link_mode(ks, supported,
1729                                                      Autoneg);
1730                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1731                                                      Autoneg);
1732         }
1733         if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1734             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1735             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1736             phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1737                 ethtool_link_ksettings_add_link_mode(ks, supported,
1738                                                      Autoneg);
1739                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1740                                                      Autoneg);
1741         }
1742         if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1743             phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1744             phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1745             phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2) {
1746                 ethtool_link_ksettings_add_link_mode(ks, supported,
1747                                                      Autoneg);
1748                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1749                                                      Autoneg);
1750         }
1751 }
1752
1753 #define TEST_SET_BITS_TIMEOUT   50
1754 #define TEST_SET_BITS_SLEEP_MAX 2000
1755 #define TEST_SET_BITS_SLEEP_MIN 1000
1756
1757 /**
1758  * ice_get_settings_link_up - Get Link settings for when link is up
1759  * @ks: ethtool ksettings to fill in
1760  * @netdev: network interface device structure
1761  */
1762 static void
1763 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
1764                          struct net_device *netdev)
1765 {
1766         struct ice_netdev_priv *np = netdev_priv(netdev);
1767         struct ice_port_info *pi = np->vsi->port_info;
1768         struct ice_link_status *link_info;
1769         struct ice_vsi *vsi = np->vsi;
1770
1771         link_info = &vsi->port_info->phy.link_info;
1772
1773         /* Get supported and advertised settings from PHY ability with media */
1774         ice_phy_type_to_ethtool(netdev, ks);
1775
1776         switch (link_info->link_speed) {
1777         case ICE_AQ_LINK_SPEED_100GB:
1778                 ks->base.speed = SPEED_100000;
1779                 break;
1780         case ICE_AQ_LINK_SPEED_50GB:
1781                 ks->base.speed = SPEED_50000;
1782                 break;
1783         case ICE_AQ_LINK_SPEED_40GB:
1784                 ks->base.speed = SPEED_40000;
1785                 break;
1786         case ICE_AQ_LINK_SPEED_25GB:
1787                 ks->base.speed = SPEED_25000;
1788                 break;
1789         case ICE_AQ_LINK_SPEED_20GB:
1790                 ks->base.speed = SPEED_20000;
1791                 break;
1792         case ICE_AQ_LINK_SPEED_10GB:
1793                 ks->base.speed = SPEED_10000;
1794                 break;
1795         case ICE_AQ_LINK_SPEED_5GB:
1796                 ks->base.speed = SPEED_5000;
1797                 break;
1798         case ICE_AQ_LINK_SPEED_2500MB:
1799                 ks->base.speed = SPEED_2500;
1800                 break;
1801         case ICE_AQ_LINK_SPEED_1000MB:
1802                 ks->base.speed = SPEED_1000;
1803                 break;
1804         case ICE_AQ_LINK_SPEED_100MB:
1805                 ks->base.speed = SPEED_100;
1806                 break;
1807         default:
1808                 netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n",
1809                             link_info->link_speed);
1810                 break;
1811         }
1812         ks->base.duplex = DUPLEX_FULL;
1813
1814         if (link_info->an_info & ICE_AQ_AN_COMPLETED)
1815                 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1816                                                      Autoneg);
1817
1818         /* Set flow control negotiated Rx/Tx pause */
1819         switch (pi->fc.current_mode) {
1820         case ICE_FC_FULL:
1821                 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1822                 break;
1823         case ICE_FC_TX_PAUSE:
1824                 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1825                 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1826                                                      Asym_Pause);
1827                 break;
1828         case ICE_FC_RX_PAUSE:
1829                 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1830                                                      Asym_Pause);
1831                 break;
1832         case ICE_FC_PFC:
1833         default:
1834                 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
1835                 ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
1836                                                      Asym_Pause);
1837                 break;
1838         }
1839 }
1840
1841 /**
1842  * ice_get_settings_link_down - Get the Link settings when link is down
1843  * @ks: ethtool ksettings to fill in
1844  * @netdev: network interface device structure
1845  *
1846  * Reports link settings that can be determined when link is down
1847  */
1848 static void
1849 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
1850                            struct net_device *netdev)
1851 {
1852         /* link is down and the driver needs to fall back on
1853          * supported PHY types to figure out what info to display
1854          */
1855         ice_phy_type_to_ethtool(netdev, ks);
1856
1857         /* With no link, speed and duplex are unknown */
1858         ks->base.speed = SPEED_UNKNOWN;
1859         ks->base.duplex = DUPLEX_UNKNOWN;
1860 }
1861
1862 /**
1863  * ice_get_link_ksettings - Get Link Speed and Duplex settings
1864  * @netdev: network interface device structure
1865  * @ks: ethtool ksettings
1866  *
1867  * Reports speed/duplex settings based on media_type
1868  */
1869 static int
1870 ice_get_link_ksettings(struct net_device *netdev,
1871                        struct ethtool_link_ksettings *ks)
1872 {
1873         struct ice_netdev_priv *np = netdev_priv(netdev);
1874         struct ice_aqc_get_phy_caps_data *caps;
1875         struct ice_link_status *hw_link_info;
1876         struct ice_vsi *vsi = np->vsi;
1877         enum ice_status status;
1878         int err = 0;
1879
1880         ethtool_link_ksettings_zero_link_mode(ks, supported);
1881         ethtool_link_ksettings_zero_link_mode(ks, advertising);
1882         ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
1883         hw_link_info = &vsi->port_info->phy.link_info;
1884
1885         /* set speed and duplex */
1886         if (hw_link_info->link_info & ICE_AQ_LINK_UP)
1887                 ice_get_settings_link_up(ks, netdev);
1888         else
1889                 ice_get_settings_link_down(ks, netdev);
1890
1891         /* set autoneg settings */
1892         ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
1893                 AUTONEG_ENABLE : AUTONEG_DISABLE;
1894
1895         /* set media type settings */
1896         switch (vsi->port_info->phy.media_type) {
1897         case ICE_MEDIA_FIBER:
1898                 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1899                 ks->base.port = PORT_FIBRE;
1900                 break;
1901         case ICE_MEDIA_BASET:
1902                 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
1903                 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
1904                 ks->base.port = PORT_TP;
1905                 break;
1906         case ICE_MEDIA_BACKPLANE:
1907                 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1908                 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
1909                 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1910                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1911                                                      Backplane);
1912                 ks->base.port = PORT_NONE;
1913                 break;
1914         case ICE_MEDIA_DA:
1915                 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1916                 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
1917                 ks->base.port = PORT_DA;
1918                 break;
1919         default:
1920                 ks->base.port = PORT_OTHER;
1921                 break;
1922         }
1923
1924         /* flow control is symmetric and always supported */
1925         ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
1926
1927         caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1928         if (!caps)
1929                 return -ENOMEM;
1930
1931         status = ice_aq_get_phy_caps(vsi->port_info, false,
1932                                      ICE_AQC_REPORT_SW_CFG, caps, NULL);
1933         if (status) {
1934                 err = -EIO;
1935                 goto done;
1936         }
1937
1938         /* Set the advertised flow control based on the PHY capability */
1939         if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
1940             (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
1941                 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1942                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1943                                                      Asym_Pause);
1944         } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
1945                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1946                                                      Asym_Pause);
1947         } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
1948                 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1949                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1950                                                      Asym_Pause);
1951         } else {
1952                 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
1953                 ethtool_link_ksettings_del_link_mode(ks, advertising,
1954                                                      Asym_Pause);
1955         }
1956
1957         /* Set advertised FEC modes based on PHY capability */
1958         ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
1959
1960         if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1961             caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1962                 ethtool_link_ksettings_add_link_mode(ks, advertising,
1963                                                      FEC_BASER);
1964         if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1965             caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
1966                 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
1967
1968         status = ice_aq_get_phy_caps(vsi->port_info, false,
1969                                      ICE_AQC_REPORT_TOPO_CAP, caps, NULL);
1970         if (status) {
1971                 err = -EIO;
1972                 goto done;
1973         }
1974
1975         /* Set supported FEC modes based on PHY capability */
1976         ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
1977
1978         if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1979             caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
1980                 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
1981         if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1982                 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
1983
1984 done:
1985         kfree(caps);
1986         return err;
1987 }
1988
1989 /**
1990  * ice_ksettings_find_adv_link_speed - Find advertising link speed
1991  * @ks: ethtool ksettings
1992  */
1993 static u16
1994 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
1995 {
1996         u16 adv_link_speed = 0;
1997
1998         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1999                                                   100baseT_Full))
2000                 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
2001         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2002                                                   1000baseX_Full))
2003                 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2004         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2005                                                   1000baseT_Full) ||
2006             ethtool_link_ksettings_test_link_mode(ks, advertising,
2007                                                   1000baseKX_Full))
2008                 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2009         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2010                                                   2500baseT_Full))
2011                 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2012         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2013                                                   2500baseX_Full))
2014                 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2015         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2016                                                   5000baseT_Full))
2017                 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
2018         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2019                                                   10000baseT_Full) ||
2020             ethtool_link_ksettings_test_link_mode(ks, advertising,
2021                                                   10000baseKR_Full))
2022                 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2023         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2024                                                   10000baseSR_Full) ||
2025             ethtool_link_ksettings_test_link_mode(ks, advertising,
2026                                                   10000baseLR_Full))
2027                 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2028         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2029                                                   25000baseCR_Full) ||
2030             ethtool_link_ksettings_test_link_mode(ks, advertising,
2031                                                   25000baseSR_Full) ||
2032             ethtool_link_ksettings_test_link_mode(ks, advertising,
2033                                                   25000baseKR_Full))
2034                 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
2035         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2036                                                   40000baseCR4_Full) ||
2037             ethtool_link_ksettings_test_link_mode(ks, advertising,
2038                                                   40000baseSR4_Full) ||
2039             ethtool_link_ksettings_test_link_mode(ks, advertising,
2040                                                   40000baseLR4_Full) ||
2041             ethtool_link_ksettings_test_link_mode(ks, advertising,
2042                                                   40000baseKR4_Full))
2043                 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
2044         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2045                                                   50000baseCR2_Full) ||
2046             ethtool_link_ksettings_test_link_mode(ks, advertising,
2047                                                   50000baseKR2_Full))
2048                 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2049         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2050                                                   50000baseSR2_Full))
2051                 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2052         if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2053                                                   100000baseCR4_Full) ||
2054             ethtool_link_ksettings_test_link_mode(ks, advertising,
2055                                                   100000baseSR4_Full) ||
2056             ethtool_link_ksettings_test_link_mode(ks, advertising,
2057                                                   100000baseLR4_ER4_Full) ||
2058             ethtool_link_ksettings_test_link_mode(ks, advertising,
2059                                                   100000baseKR4_Full))
2060                 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB;
2061
2062         return adv_link_speed;
2063 }
2064
2065 /**
2066  * ice_setup_autoneg
2067  * @p: port info
2068  * @ks: ethtool_link_ksettings
2069  * @config: configuration that will be sent down to FW
2070  * @autoneg_enabled: autonegotiation is enabled or not
2071  * @autoneg_changed: will there a change in autonegotiation
2072  * @netdev: network interface device structure
2073  *
2074  * Setup PHY autonegotiation feature
2075  */
2076 static int
2077 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2078                   struct ice_aqc_set_phy_cfg_data *config,
2079                   u8 autoneg_enabled, u8 *autoneg_changed,
2080                   struct net_device *netdev)
2081 {
2082         int err = 0;
2083
2084         *autoneg_changed = 0;
2085
2086         /* Check autoneg */
2087         if (autoneg_enabled == AUTONEG_ENABLE) {
2088                 /* If autoneg was not already enabled */
2089                 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2090                         /* If autoneg is not supported, return error */
2091                         if (!ethtool_link_ksettings_test_link_mode(ks,
2092                                                                    supported,
2093                                                                    Autoneg)) {
2094                                 netdev_info(netdev, "Autoneg not supported on this phy.\n");
2095                                 err = -EINVAL;
2096                         } else {
2097                                 /* Autoneg is allowed to change */
2098                                 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2099                                 *autoneg_changed = 1;
2100                         }
2101                 }
2102         } else {
2103                 /* If autoneg is currently enabled */
2104                 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2105                         /* If autoneg is supported 10GBASE_T is the only PHY
2106                          * that can disable it, so otherwise return error
2107                          */
2108                         if (ethtool_link_ksettings_test_link_mode(ks,
2109                                                                   supported,
2110                                                                   Autoneg)) {
2111                                 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2112                                 err = -EINVAL;
2113                         } else {
2114                                 /* Autoneg is allowed to change */
2115                                 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2116                                 *autoneg_changed = 1;
2117                         }
2118                 }
2119         }
2120
2121         return err;
2122 }
2123
2124 /**
2125  * ice_set_link_ksettings - Set Speed and Duplex
2126  * @netdev: network interface device structure
2127  * @ks: ethtool ksettings
2128  *
2129  * Set speed/duplex per media_types advertised/forced
2130  */
2131 static int
2132 ice_set_link_ksettings(struct net_device *netdev,
2133                        const struct ethtool_link_ksettings *ks)
2134 {
2135         u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT, lport = 0;
2136         struct ice_netdev_priv *np = netdev_priv(netdev);
2137         struct ethtool_link_ksettings safe_ks, copy_ks;
2138         struct ice_aqc_get_phy_caps_data *abilities;
2139         u16 adv_link_speed, curr_link_speed, idx;
2140         struct ice_aqc_set_phy_cfg_data config;
2141         struct ice_pf *pf = np->vsi->back;
2142         struct ice_port_info *p;
2143         u8 autoneg_changed = 0;
2144         enum ice_status status;
2145         u64 phy_type_high;
2146         u64 phy_type_low;
2147         int err = 0;
2148         bool linkup;
2149
2150         p = np->vsi->port_info;
2151
2152         if (!p)
2153                 return -EOPNOTSUPP;
2154
2155         /* Check if this is LAN VSI */
2156         ice_for_each_vsi(pf, idx)
2157                 if (pf->vsi[idx]->type == ICE_VSI_PF) {
2158                         if (np->vsi != pf->vsi[idx])
2159                                 return -EOPNOTSUPP;
2160                         break;
2161                 }
2162
2163         if (p->phy.media_type != ICE_MEDIA_BASET &&
2164             p->phy.media_type != ICE_MEDIA_FIBER &&
2165             p->phy.media_type != ICE_MEDIA_BACKPLANE &&
2166             p->phy.media_type != ICE_MEDIA_DA &&
2167             p->phy.link_info.link_info & ICE_AQ_LINK_UP)
2168                 return -EOPNOTSUPP;
2169
2170         /* copy the ksettings to copy_ks to avoid modifying the original */
2171         memcpy(&copy_ks, ks, sizeof(copy_ks));
2172
2173         /* save autoneg out of ksettings */
2174         autoneg = copy_ks.base.autoneg;
2175
2176         memset(&safe_ks, 0, sizeof(safe_ks));
2177
2178         /* Get link modes supported by hardware.*/
2179         ice_phy_type_to_ethtool(netdev, &safe_ks);
2180
2181         /* and check against modes requested by user.
2182          * Return an error if unsupported mode was set.
2183          */
2184         if (!bitmap_subset(copy_ks.link_modes.advertising,
2185                            safe_ks.link_modes.supported,
2186                            __ETHTOOL_LINK_MODE_MASK_NBITS))
2187                 return -EINVAL;
2188
2189         /* get our own copy of the bits to check against */
2190         memset(&safe_ks, 0, sizeof(safe_ks));
2191         safe_ks.base.cmd = copy_ks.base.cmd;
2192         safe_ks.base.link_mode_masks_nwords =
2193                 copy_ks.base.link_mode_masks_nwords;
2194         ice_get_link_ksettings(netdev, &safe_ks);
2195
2196         /* set autoneg back to what it currently is */
2197         copy_ks.base.autoneg = safe_ks.base.autoneg;
2198         /* we don't compare the speed */
2199         copy_ks.base.speed = safe_ks.base.speed;
2200
2201         /* If copy_ks.base and safe_ks.base are not the same now, then they are
2202          * trying to set something that we do not support.
2203          */
2204         if (memcmp(&copy_ks.base, &safe_ks.base, sizeof(copy_ks.base)))
2205                 return -EOPNOTSUPP;
2206
2207         while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2208                 timeout--;
2209                 if (!timeout)
2210                         return -EBUSY;
2211                 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2212         }
2213
2214         abilities = kzalloc(sizeof(*abilities), GFP_KERNEL);
2215         if (!abilities)
2216                 return -ENOMEM;
2217
2218         /* Get the current PHY config */
2219         status = ice_aq_get_phy_caps(p, false, ICE_AQC_REPORT_SW_CFG, abilities,
2220                                      NULL);
2221         if (status) {
2222                 err = -EAGAIN;
2223                 goto done;
2224         }
2225
2226         /* Copy abilities to config in case autoneg is not set below */
2227         memset(&config, 0, sizeof(config));
2228         config.caps = abilities->caps & ~ICE_AQC_PHY_AN_MODE;
2229         if (abilities->caps & ICE_AQC_PHY_AN_MODE)
2230                 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2231
2232         /* Check autoneg */
2233         err = ice_setup_autoneg(p, &safe_ks, &config, autoneg, &autoneg_changed,
2234                                 netdev);
2235
2236         if (err)
2237                 goto done;
2238
2239         /* Call to get the current link speed */
2240         p->phy.get_link_info = true;
2241         status = ice_get_link_status(p, &linkup);
2242         if (status) {
2243                 err = -EAGAIN;
2244                 goto done;
2245         }
2246
2247         curr_link_speed = p->phy.link_info.link_speed;
2248         adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2249
2250         /* If speed didn't get set, set it to what it currently is.
2251          * This is needed because if advertise is 0 (as it is when autoneg
2252          * is disabled) then speed won't get set.
2253          */
2254         if (!adv_link_speed)
2255                 adv_link_speed = curr_link_speed;
2256
2257         /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2258         ice_update_phy_type(&phy_type_low, &phy_type_high, adv_link_speed);
2259
2260         if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2261                 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2262                 goto done;
2263         }
2264
2265         /* copy over the rest of the abilities */
2266         config.low_power_ctrl = abilities->low_power_ctrl;
2267         config.eee_cap = abilities->eee_cap;
2268         config.eeer_value = abilities->eeer_value;
2269         config.link_fec_opt = abilities->link_fec_options;
2270
2271         /* save the requested speeds */
2272         p->phy.link_info.req_speeds = adv_link_speed;
2273
2274         /* set link and auto negotiation so changes take effect */
2275         config.caps |= ICE_AQ_PHY_ENA_LINK;
2276
2277         if (phy_type_low || phy_type_high) {
2278                 config.phy_type_high = cpu_to_le64(phy_type_high) &
2279                         abilities->phy_type_high;
2280                 config.phy_type_low = cpu_to_le64(phy_type_low) &
2281                         abilities->phy_type_low;
2282         } else {
2283                 err = -EAGAIN;
2284                 netdev_info(netdev, "Nothing changed. No PHY_TYPE is corresponded to advertised link speed.\n");
2285                 goto done;
2286         }
2287
2288         /* If link is up put link down */
2289         if (p->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2290                 /* Tell the OS link is going down, the link will go
2291                  * back up when fw says it is ready asynchronously
2292                  */
2293                 ice_print_link_msg(np->vsi, false);
2294                 netif_carrier_off(netdev);
2295                 netif_tx_stop_all_queues(netdev);
2296         }
2297
2298         /* make the aq call */
2299         status = ice_aq_set_phy_cfg(&pf->hw, lport, &config, NULL);
2300         if (status) {
2301                 netdev_info(netdev, "Set phy config failed,\n");
2302                 err = -EAGAIN;
2303         }
2304
2305 done:
2306         kfree(abilities);
2307         clear_bit(__ICE_CFG_BUSY, pf->state);
2308
2309         return err;
2310 }
2311
2312 /**
2313  * ice_parse_hdrs - parses headers from RSS hash input
2314  * @nfc: ethtool rxnfc command
2315  *
2316  * This function parses the rxnfc command and returns intended
2317  * header types for RSS configuration
2318  */
2319 static u32 ice_parse_hdrs(struct ethtool_rxnfc *nfc)
2320 {
2321         u32 hdrs = ICE_FLOW_SEG_HDR_NONE;
2322
2323         switch (nfc->flow_type) {
2324         case TCP_V4_FLOW:
2325                 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4;
2326                 break;
2327         case UDP_V4_FLOW:
2328                 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4;
2329                 break;
2330         case SCTP_V4_FLOW:
2331                 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4;
2332                 break;
2333         case TCP_V6_FLOW:
2334                 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6;
2335                 break;
2336         case UDP_V6_FLOW:
2337                 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6;
2338                 break;
2339         case SCTP_V6_FLOW:
2340                 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6;
2341                 break;
2342         default:
2343                 break;
2344         }
2345         return hdrs;
2346 }
2347
2348 #define ICE_FLOW_HASH_FLD_IPV4_SA       BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)
2349 #define ICE_FLOW_HASH_FLD_IPV6_SA       BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)
2350 #define ICE_FLOW_HASH_FLD_IPV4_DA       BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)
2351 #define ICE_FLOW_HASH_FLD_IPV6_DA       BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)
2352 #define ICE_FLOW_HASH_FLD_TCP_SRC_PORT  BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)
2353 #define ICE_FLOW_HASH_FLD_TCP_DST_PORT  BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)
2354 #define ICE_FLOW_HASH_FLD_UDP_SRC_PORT  BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)
2355 #define ICE_FLOW_HASH_FLD_UDP_DST_PORT  BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)
2356 #define ICE_FLOW_HASH_FLD_SCTP_SRC_PORT \
2357         BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)
2358 #define ICE_FLOW_HASH_FLD_SCTP_DST_PORT \
2359         BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)
2360
2361 /**
2362  * ice_parse_hash_flds - parses hash fields from RSS hash input
2363  * @nfc: ethtool rxnfc command
2364  *
2365  * This function parses the rxnfc command and returns intended
2366  * hash fields for RSS configuration
2367  */
2368 static u64 ice_parse_hash_flds(struct ethtool_rxnfc *nfc)
2369 {
2370         u64 hfld = ICE_HASH_INVALID;
2371
2372         if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) {
2373                 switch (nfc->flow_type) {
2374                 case TCP_V4_FLOW:
2375                 case UDP_V4_FLOW:
2376                 case SCTP_V4_FLOW:
2377                         if (nfc->data & RXH_IP_SRC)
2378                                 hfld |= ICE_FLOW_HASH_FLD_IPV4_SA;
2379                         if (nfc->data & RXH_IP_DST)
2380                                 hfld |= ICE_FLOW_HASH_FLD_IPV4_DA;
2381                         break;
2382                 case TCP_V6_FLOW:
2383                 case UDP_V6_FLOW:
2384                 case SCTP_V6_FLOW:
2385                         if (nfc->data & RXH_IP_SRC)
2386                                 hfld |= ICE_FLOW_HASH_FLD_IPV6_SA;
2387                         if (nfc->data & RXH_IP_DST)
2388                                 hfld |= ICE_FLOW_HASH_FLD_IPV6_DA;
2389                         break;
2390                 default:
2391                         break;
2392                 }
2393         }
2394
2395         if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) {
2396                 switch (nfc->flow_type) {
2397                 case TCP_V4_FLOW:
2398                 case TCP_V6_FLOW:
2399                         if (nfc->data & RXH_L4_B_0_1)
2400                                 hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT;
2401                         if (nfc->data & RXH_L4_B_2_3)
2402                                 hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT;
2403                         break;
2404                 case UDP_V4_FLOW:
2405                 case UDP_V6_FLOW:
2406                         if (nfc->data & RXH_L4_B_0_1)
2407                                 hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT;
2408                         if (nfc->data & RXH_L4_B_2_3)
2409                                 hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT;
2410                         break;
2411                 case SCTP_V4_FLOW:
2412                 case SCTP_V6_FLOW:
2413                         if (nfc->data & RXH_L4_B_0_1)
2414                                 hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT;
2415                         if (nfc->data & RXH_L4_B_2_3)
2416                                 hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT;
2417                         break;
2418                 default:
2419                         break;
2420                 }
2421         }
2422
2423         return hfld;
2424 }
2425
2426 /**
2427  * ice_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2428  * @vsi: the VSI being configured
2429  * @nfc: ethtool rxnfc command
2430  *
2431  * Returns Success if the flow input set is supported.
2432  */
2433 static int
2434 ice_set_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2435 {
2436         struct ice_pf *pf = vsi->back;
2437         enum ice_status status;
2438         struct device *dev;
2439         u64 hashed_flds;
2440         u32 hdrs;
2441
2442         dev = ice_pf_to_dev(pf);
2443         if (ice_is_safe_mode(pf)) {
2444                 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2445                         vsi->vsi_num);
2446                 return -EINVAL;
2447         }
2448
2449         hashed_flds = ice_parse_hash_flds(nfc);
2450         if (hashed_flds == ICE_HASH_INVALID) {
2451                 dev_dbg(dev, "Invalid hash fields, vsi num = %d\n",
2452                         vsi->vsi_num);
2453                 return -EINVAL;
2454         }
2455
2456         hdrs = ice_parse_hdrs(nfc);
2457         if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2458                 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2459                         vsi->vsi_num);
2460                 return -EINVAL;
2461         }
2462
2463         status = ice_add_rss_cfg(&pf->hw, vsi->idx, hashed_flds, hdrs);
2464         if (status) {
2465                 dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %d\n",
2466                         vsi->vsi_num, status);
2467                 return -EINVAL;
2468         }
2469
2470         return 0;
2471 }
2472
2473 /**
2474  * ice_get_rss_hash_opt - Retrieve hash fields for a given flow-type
2475  * @vsi: the VSI being configured
2476  * @nfc: ethtool rxnfc command
2477  */
2478 static void
2479 ice_get_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2480 {
2481         struct ice_pf *pf = vsi->back;
2482         struct device *dev;
2483         u64 hash_flds;
2484         u32 hdrs;
2485
2486         dev = ice_pf_to_dev(pf);
2487
2488         nfc->data = 0;
2489         if (ice_is_safe_mode(pf)) {
2490                 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2491                         vsi->vsi_num);
2492                 return;
2493         }
2494
2495         hdrs = ice_parse_hdrs(nfc);
2496         if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2497                 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2498                         vsi->vsi_num);
2499                 return;
2500         }
2501
2502         hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs);
2503         if (hash_flds == ICE_HASH_INVALID) {
2504                 dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n",
2505                         vsi->vsi_num);
2506                 return;
2507         }
2508
2509         if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA ||
2510             hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA)
2511                 nfc->data |= (u64)RXH_IP_SRC;
2512
2513         if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA ||
2514             hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA)
2515                 nfc->data |= (u64)RXH_IP_DST;
2516
2517         if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT ||
2518             hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT ||
2519             hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT)
2520                 nfc->data |= (u64)RXH_L4_B_0_1;
2521
2522         if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT ||
2523             hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT ||
2524             hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)
2525                 nfc->data |= (u64)RXH_L4_B_2_3;
2526 }
2527
2528 /**
2529  * ice_set_rxnfc - command to set Rx flow rules.
2530  * @netdev: network interface device structure
2531  * @cmd: ethtool rxnfc command
2532  *
2533  * Returns 0 for success and negative values for errors
2534  */
2535 static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2536 {
2537         struct ice_netdev_priv *np = netdev_priv(netdev);
2538         struct ice_vsi *vsi = np->vsi;
2539
2540         switch (cmd->cmd) {
2541         case ETHTOOL_SRXFH:
2542                 return ice_set_rss_hash_opt(vsi, cmd);
2543         default:
2544                 break;
2545         }
2546         return -EOPNOTSUPP;
2547 }
2548
2549 /**
2550  * ice_get_rxnfc - command to get Rx flow classification rules
2551  * @netdev: network interface device structure
2552  * @cmd: ethtool rxnfc command
2553  * @rule_locs: buffer to rturn Rx flow classification rules
2554  *
2555  * Returns Success if the command is supported.
2556  */
2557 static int
2558 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2559               u32 __always_unused *rule_locs)
2560 {
2561         struct ice_netdev_priv *np = netdev_priv(netdev);
2562         struct ice_vsi *vsi = np->vsi;
2563         int ret = -EOPNOTSUPP;
2564
2565         switch (cmd->cmd) {
2566         case ETHTOOL_GRXRINGS:
2567                 cmd->data = vsi->rss_size;
2568                 ret = 0;
2569                 break;
2570         case ETHTOOL_GRXFH:
2571                 ice_get_rss_hash_opt(vsi, cmd);
2572                 ret = 0;
2573                 break;
2574         default:
2575                 break;
2576         }
2577
2578         return ret;
2579 }
2580
2581 static void
2582 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2583 {
2584         struct ice_netdev_priv *np = netdev_priv(netdev);
2585         struct ice_vsi *vsi = np->vsi;
2586
2587         ring->rx_max_pending = ICE_MAX_NUM_DESC;
2588         ring->tx_max_pending = ICE_MAX_NUM_DESC;
2589         ring->rx_pending = vsi->rx_rings[0]->count;
2590         ring->tx_pending = vsi->tx_rings[0]->count;
2591
2592         /* Rx mini and jumbo rings are not supported */
2593         ring->rx_mini_max_pending = 0;
2594         ring->rx_jumbo_max_pending = 0;
2595         ring->rx_mini_pending = 0;
2596         ring->rx_jumbo_pending = 0;
2597 }
2598
2599 static int
2600 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2601 {
2602         struct ice_ring *tx_rings = NULL, *rx_rings = NULL;
2603         struct ice_netdev_priv *np = netdev_priv(netdev);
2604         struct ice_ring *xdp_rings = NULL;
2605         struct ice_vsi *vsi = np->vsi;
2606         struct ice_pf *pf = vsi->back;
2607         int i, timeout = 50, err = 0;
2608         u32 new_rx_cnt, new_tx_cnt;
2609
2610         if (ring->tx_pending > ICE_MAX_NUM_DESC ||
2611             ring->tx_pending < ICE_MIN_NUM_DESC ||
2612             ring->rx_pending > ICE_MAX_NUM_DESC ||
2613             ring->rx_pending < ICE_MIN_NUM_DESC) {
2614                 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2615                            ring->tx_pending, ring->rx_pending,
2616                            ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
2617                            ICE_REQ_DESC_MULTIPLE);
2618                 return -EINVAL;
2619         }
2620
2621         new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
2622         if (new_tx_cnt != ring->tx_pending)
2623                 netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n",
2624                             new_tx_cnt);
2625         new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
2626         if (new_rx_cnt != ring->rx_pending)
2627                 netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n",
2628                             new_rx_cnt);
2629
2630         /* if nothing to do return success */
2631         if (new_tx_cnt == vsi->tx_rings[0]->count &&
2632             new_rx_cnt == vsi->rx_rings[0]->count) {
2633                 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
2634                 return 0;
2635         }
2636
2637         /* If there is a AF_XDP UMEM attached to any of Rx rings,
2638          * disallow changing the number of descriptors -- regardless
2639          * if the netdev is running or not.
2640          */
2641         if (ice_xsk_any_rx_ring_ena(vsi))
2642                 return -EBUSY;
2643
2644         while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2645                 timeout--;
2646                 if (!timeout)
2647                         return -EBUSY;
2648                 usleep_range(1000, 2000);
2649         }
2650
2651         /* set for the next time the netdev is started */
2652         if (!netif_running(vsi->netdev)) {
2653                 for (i = 0; i < vsi->alloc_txq; i++)
2654                         vsi->tx_rings[i]->count = new_tx_cnt;
2655                 for (i = 0; i < vsi->alloc_rxq; i++)
2656                         vsi->rx_rings[i]->count = new_rx_cnt;
2657                 if (ice_is_xdp_ena_vsi(vsi))
2658                         for (i = 0; i < vsi->num_xdp_txq; i++)
2659                                 vsi->xdp_rings[i]->count = new_tx_cnt;
2660                 vsi->num_tx_desc = new_tx_cnt;
2661                 vsi->num_rx_desc = new_rx_cnt;
2662                 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
2663                 goto done;
2664         }
2665
2666         if (new_tx_cnt == vsi->tx_rings[0]->count)
2667                 goto process_rx;
2668
2669         /* alloc updated Tx resources */
2670         netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
2671                     vsi->tx_rings[0]->count, new_tx_cnt);
2672
2673         tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
2674         if (!tx_rings) {
2675                 err = -ENOMEM;
2676                 goto done;
2677         }
2678
2679         ice_for_each_txq(vsi, i) {
2680                 /* clone ring and setup updated count */
2681                 tx_rings[i] = *vsi->tx_rings[i];
2682                 tx_rings[i].count = new_tx_cnt;
2683                 tx_rings[i].desc = NULL;
2684                 tx_rings[i].tx_buf = NULL;
2685                 err = ice_setup_tx_ring(&tx_rings[i]);
2686                 if (err) {
2687                         while (i--)
2688                                 ice_clean_tx_ring(&tx_rings[i]);
2689                         kfree(tx_rings);
2690                         goto done;
2691                 }
2692         }
2693
2694         if (!ice_is_xdp_ena_vsi(vsi))
2695                 goto process_rx;
2696
2697         /* alloc updated XDP resources */
2698         netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
2699                     vsi->xdp_rings[0]->count, new_tx_cnt);
2700
2701         xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
2702         if (!xdp_rings) {
2703                 err = -ENOMEM;
2704                 goto free_tx;
2705         }
2706
2707         for (i = 0; i < vsi->num_xdp_txq; i++) {
2708                 /* clone ring and setup updated count */
2709                 xdp_rings[i] = *vsi->xdp_rings[i];
2710                 xdp_rings[i].count = new_tx_cnt;
2711                 xdp_rings[i].desc = NULL;
2712                 xdp_rings[i].tx_buf = NULL;
2713                 err = ice_setup_tx_ring(&xdp_rings[i]);
2714                 if (err) {
2715                         while (i--)
2716                                 ice_clean_tx_ring(&xdp_rings[i]);
2717                         kfree(xdp_rings);
2718                         goto free_tx;
2719                 }
2720                 ice_set_ring_xdp(&xdp_rings[i]);
2721         }
2722
2723 process_rx:
2724         if (new_rx_cnt == vsi->rx_rings[0]->count)
2725                 goto process_link;
2726
2727         /* alloc updated Rx resources */
2728         netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
2729                     vsi->rx_rings[0]->count, new_rx_cnt);
2730
2731         rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
2732         if (!rx_rings) {
2733                 err = -ENOMEM;
2734                 goto done;
2735         }
2736
2737         ice_for_each_rxq(vsi, i) {
2738                 /* clone ring and setup updated count */
2739                 rx_rings[i] = *vsi->rx_rings[i];
2740                 rx_rings[i].count = new_rx_cnt;
2741                 rx_rings[i].desc = NULL;
2742                 rx_rings[i].rx_buf = NULL;
2743                 /* this is to allow wr32 to have something to write to
2744                  * during early allocation of Rx buffers
2745                  */
2746                 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
2747
2748                 err = ice_setup_rx_ring(&rx_rings[i]);
2749                 if (err)
2750                         goto rx_unwind;
2751
2752                 /* allocate Rx buffers */
2753                 err = ice_alloc_rx_bufs(&rx_rings[i],
2754                                         ICE_DESC_UNUSED(&rx_rings[i]));
2755 rx_unwind:
2756                 if (err) {
2757                         while (i) {
2758                                 i--;
2759                                 ice_free_rx_ring(&rx_rings[i]);
2760                         }
2761                         kfree(rx_rings);
2762                         err = -ENOMEM;
2763                         goto free_tx;
2764                 }
2765         }
2766
2767 process_link:
2768         /* Bring interface down, copy in the new ring info, then restore the
2769          * interface. if VSI is up, bring it down and then back up
2770          */
2771         if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
2772                 ice_down(vsi);
2773
2774                 if (tx_rings) {
2775                         ice_for_each_txq(vsi, i) {
2776                                 ice_free_tx_ring(vsi->tx_rings[i]);
2777                                 *vsi->tx_rings[i] = tx_rings[i];
2778                         }
2779                         kfree(tx_rings);
2780                 }
2781
2782                 if (rx_rings) {
2783                         ice_for_each_rxq(vsi, i) {
2784                                 ice_free_rx_ring(vsi->rx_rings[i]);
2785                                 /* copy the real tail offset */
2786                                 rx_rings[i].tail = vsi->rx_rings[i]->tail;
2787                                 /* this is to fake out the allocation routine
2788                                  * into thinking it has to realloc everything
2789                                  * but the recycling logic will let us re-use
2790                                  * the buffers allocated above
2791                                  */
2792                                 rx_rings[i].next_to_use = 0;
2793                                 rx_rings[i].next_to_clean = 0;
2794                                 rx_rings[i].next_to_alloc = 0;
2795                                 *vsi->rx_rings[i] = rx_rings[i];
2796                         }
2797                         kfree(rx_rings);
2798                 }
2799
2800                 if (xdp_rings) {
2801                         for (i = 0; i < vsi->num_xdp_txq; i++) {
2802                                 ice_free_tx_ring(vsi->xdp_rings[i]);
2803                                 *vsi->xdp_rings[i] = xdp_rings[i];
2804                         }
2805                         kfree(xdp_rings);
2806                 }
2807
2808                 vsi->num_tx_desc = new_tx_cnt;
2809                 vsi->num_rx_desc = new_rx_cnt;
2810                 ice_up(vsi);
2811         }
2812         goto done;
2813
2814 free_tx:
2815         /* error cleanup if the Rx allocations failed after getting Tx */
2816         if (tx_rings) {
2817                 ice_for_each_txq(vsi, i)
2818                         ice_free_tx_ring(&tx_rings[i]);
2819                 kfree(tx_rings);
2820         }
2821
2822 done:
2823         clear_bit(__ICE_CFG_BUSY, pf->state);
2824         return err;
2825 }
2826
2827 /**
2828  * ice_get_pauseparam - Get Flow Control status
2829  * @netdev: network interface device structure
2830  * @pause: ethernet pause (flow control) parameters
2831  *
2832  * Get requested flow control status from PHY capability.
2833  * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2834  * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2835  * the negotiated Rx/Tx pause via lp_advertising.
2836  */
2837 static void
2838 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2839 {
2840         struct ice_netdev_priv *np = netdev_priv(netdev);
2841         struct ice_port_info *pi = np->vsi->port_info;
2842         struct ice_aqc_get_phy_caps_data *pcaps;
2843         struct ice_dcbx_cfg *dcbx_cfg;
2844         enum ice_status status;
2845
2846         /* Initialize pause params */
2847         pause->rx_pause = 0;
2848         pause->tx_pause = 0;
2849
2850         dcbx_cfg = &pi->local_dcbx_cfg;
2851
2852         pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2853         if (!pcaps)
2854                 return;
2855
2856         /* Get current PHY config */
2857         status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2858                                      NULL);
2859         if (status)
2860                 goto out;
2861
2862         pause->autoneg = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2863                         AUTONEG_ENABLE : AUTONEG_DISABLE);
2864
2865         if (dcbx_cfg->pfc.pfcena)
2866                 /* PFC enabled so report LFC as off */
2867                 goto out;
2868
2869         if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2870                 pause->tx_pause = 1;
2871         if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2872                 pause->rx_pause = 1;
2873
2874 out:
2875         kfree(pcaps);
2876 }
2877
2878 /**
2879  * ice_set_pauseparam - Set Flow Control parameter
2880  * @netdev: network interface device structure
2881  * @pause: return Tx/Rx flow control status
2882  */
2883 static int
2884 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2885 {
2886         struct ice_netdev_priv *np = netdev_priv(netdev);
2887         struct ice_aqc_get_phy_caps_data *pcaps;
2888         struct ice_link_status *hw_link_info;
2889         struct ice_pf *pf = np->vsi->back;
2890         struct ice_dcbx_cfg *dcbx_cfg;
2891         struct ice_vsi *vsi = np->vsi;
2892         struct ice_hw *hw = &pf->hw;
2893         struct ice_port_info *pi;
2894         enum ice_status status;
2895         u8 aq_failures;
2896         bool link_up;
2897         int err = 0;
2898         u32 is_an;
2899
2900         pi = vsi->port_info;
2901         hw_link_info = &pi->phy.link_info;
2902         dcbx_cfg = &pi->local_dcbx_cfg;
2903         link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
2904
2905         /* Changing the port's flow control is not supported if this isn't the
2906          * PF VSI
2907          */
2908         if (vsi->type != ICE_VSI_PF) {
2909                 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
2910                 return -EOPNOTSUPP;
2911         }
2912
2913         /* Get pause param reports configured and negotiated flow control pause
2914          * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
2915          * defined get pause param pause->autoneg reports SW configured setting,
2916          * so compare pause->autoneg with SW configured to prevent the user from
2917          * using set pause param to chance autoneg.
2918          */
2919         pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2920         if (!pcaps)
2921                 return -ENOMEM;
2922
2923         /* Get current PHY config */
2924         status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2925                                      NULL);
2926         if (status) {
2927                 kfree(pcaps);
2928                 return -EIO;
2929         }
2930
2931         is_an = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2932                         AUTONEG_ENABLE : AUTONEG_DISABLE);
2933
2934         kfree(pcaps);
2935
2936         if (pause->autoneg != is_an) {
2937                 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
2938                 return -EOPNOTSUPP;
2939         }
2940
2941         /* If we have link and don't have autoneg */
2942         if (!test_bit(__ICE_DOWN, pf->state) &&
2943             !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
2944                 /* Send message that it might not necessarily work*/
2945                 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
2946         }
2947
2948         if (dcbx_cfg->pfc.pfcena) {
2949                 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
2950                 return -EOPNOTSUPP;
2951         }
2952         if (pause->rx_pause && pause->tx_pause)
2953                 pi->fc.req_mode = ICE_FC_FULL;
2954         else if (pause->rx_pause && !pause->tx_pause)
2955                 pi->fc.req_mode = ICE_FC_RX_PAUSE;
2956         else if (!pause->rx_pause && pause->tx_pause)
2957                 pi->fc.req_mode = ICE_FC_TX_PAUSE;
2958         else if (!pause->rx_pause && !pause->tx_pause)
2959                 pi->fc.req_mode = ICE_FC_NONE;
2960         else
2961                 return -EINVAL;
2962
2963         /* Set the FC mode and only restart AN if link is up */
2964         status = ice_set_fc(pi, &aq_failures, link_up);
2965
2966         if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
2967                 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %d\n",
2968                             status, hw->adminq.sq_last_status);
2969                 err = -EAGAIN;
2970         } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
2971                 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %d\n",
2972                             status, hw->adminq.sq_last_status);
2973                 err = -EAGAIN;
2974         } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
2975                 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %d\n",
2976                             status, hw->adminq.sq_last_status);
2977                 err = -EAGAIN;
2978         }
2979
2980         if (!test_bit(__ICE_DOWN, pf->state)) {
2981                 /* Give it a little more time to try to come back. If still
2982                  * down, restart autoneg link or reinitialize the interface.
2983                  */
2984                 msleep(75);
2985                 if (!test_bit(__ICE_DOWN, pf->state))
2986                         return ice_nway_reset(netdev);
2987
2988                 ice_down(vsi);
2989                 ice_up(vsi);
2990         }
2991
2992         return err;
2993 }
2994
2995 /**
2996  * ice_get_rxfh_key_size - get the RSS hash key size
2997  * @netdev: network interface device structure
2998  *
2999  * Returns the table size.
3000  */
3001 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
3002 {
3003         return ICE_VSIQF_HKEY_ARRAY_SIZE;
3004 }
3005
3006 /**
3007  * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
3008  * @netdev: network interface device structure
3009  *
3010  * Returns the table size.
3011  */
3012 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
3013 {
3014         struct ice_netdev_priv *np = netdev_priv(netdev);
3015
3016         return np->vsi->rss_table_size;
3017 }
3018
3019 /**
3020  * ice_get_rxfh - get the Rx flow hash indirection table
3021  * @netdev: network interface device structure
3022  * @indir: indirection table
3023  * @key: hash key
3024  * @hfunc: hash function
3025  *
3026  * Reads the indirection table directly from the hardware.
3027  */
3028 static int
3029 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
3030 {
3031         struct ice_netdev_priv *np = netdev_priv(netdev);
3032         struct ice_vsi *vsi = np->vsi;
3033         struct ice_pf *pf = vsi->back;
3034         int ret = 0, i;
3035         u8 *lut;
3036
3037         if (hfunc)
3038                 *hfunc = ETH_RSS_HASH_TOP;
3039
3040         if (!indir)
3041                 return 0;
3042
3043         if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3044                 /* RSS not supported return error here */
3045                 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3046                 return -EIO;
3047         }
3048
3049         lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3050         if (!lut)
3051                 return -ENOMEM;
3052
3053         if (ice_get_rss(vsi, key, lut, vsi->rss_table_size)) {
3054                 ret = -EIO;
3055                 goto out;
3056         }
3057
3058         for (i = 0; i < vsi->rss_table_size; i++)
3059                 indir[i] = (u32)(lut[i]);
3060
3061 out:
3062         kfree(lut);
3063         return ret;
3064 }
3065
3066 /**
3067  * ice_set_rxfh - set the Rx flow hash indirection table
3068  * @netdev: network interface device structure
3069  * @indir: indirection table
3070  * @key: hash key
3071  * @hfunc: hash function
3072  *
3073  * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3074  * returns 0 after programming the table.
3075  */
3076 static int
3077 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key,
3078              const u8 hfunc)
3079 {
3080         struct ice_netdev_priv *np = netdev_priv(netdev);
3081         struct ice_vsi *vsi = np->vsi;
3082         struct ice_pf *pf = vsi->back;
3083         struct device *dev;
3084         u8 *seed = NULL;
3085
3086         dev = ice_pf_to_dev(pf);
3087         if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3088                 return -EOPNOTSUPP;
3089
3090         if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3091                 /* RSS not supported return error here */
3092                 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3093                 return -EIO;
3094         }
3095
3096         if (key) {
3097                 if (!vsi->rss_hkey_user) {
3098                         vsi->rss_hkey_user =
3099                                 devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE,
3100                                              GFP_KERNEL);
3101                         if (!vsi->rss_hkey_user)
3102                                 return -ENOMEM;
3103                 }
3104                 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
3105                 seed = vsi->rss_hkey_user;
3106         }
3107
3108         if (!vsi->rss_lut_user) {
3109                 vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size,
3110                                                  GFP_KERNEL);
3111                 if (!vsi->rss_lut_user)
3112                         return -ENOMEM;
3113         }
3114
3115         /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3116         if (indir) {
3117                 int i;
3118
3119                 for (i = 0; i < vsi->rss_table_size; i++)
3120                         vsi->rss_lut_user[i] = (u8)(indir[i]);
3121         } else {
3122                 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3123                                  vsi->rss_size);
3124         }
3125
3126         if (ice_set_rss(vsi, seed, vsi->rss_lut_user, vsi->rss_table_size))
3127                 return -EIO;
3128
3129         return 0;
3130 }
3131
3132 /**
3133  * ice_get_max_txq - return the maximum number of Tx queues for in a PF
3134  * @pf: PF structure
3135  */
3136 static int ice_get_max_txq(struct ice_pf *pf)
3137 {
3138         return min_t(int, num_online_cpus(),
3139                      pf->hw.func_caps.common_cap.num_txq);
3140 }
3141
3142 /**
3143  * ice_get_max_rxq - return the maximum number of Rx queues for in a PF
3144  * @pf: PF structure
3145  */
3146 static int ice_get_max_rxq(struct ice_pf *pf)
3147 {
3148         return min_t(int, num_online_cpus(),
3149                      pf->hw.func_caps.common_cap.num_rxq);
3150 }
3151
3152 /**
3153  * ice_get_combined_cnt - return the current number of combined channels
3154  * @vsi: PF VSI pointer
3155  *
3156  * Go through all queue vectors and count ones that have both Rx and Tx ring
3157  * attached
3158  */
3159 static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
3160 {
3161         u32 combined = 0;
3162         int q_idx;
3163
3164         ice_for_each_q_vector(vsi, q_idx) {
3165                 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3166
3167                 if (q_vector->rx.ring && q_vector->tx.ring)
3168                         combined++;
3169         }
3170
3171         return combined;
3172 }
3173
3174 /**
3175  * ice_get_channels - get the current and max supported channels
3176  * @dev: network interface device structure
3177  * @ch: ethtool channel data structure
3178  */
3179 static void
3180 ice_get_channels(struct net_device *dev, struct ethtool_channels *ch)
3181 {
3182         struct ice_netdev_priv *np = netdev_priv(dev);
3183         struct ice_vsi *vsi = np->vsi;
3184         struct ice_pf *pf = vsi->back;
3185
3186         /* check to see if VSI is active */
3187         if (test_bit(__ICE_DOWN, vsi->state))
3188                 return;
3189
3190         /* report maximum channels */
3191         ch->max_rx = ice_get_max_rxq(pf);
3192         ch->max_tx = ice_get_max_txq(pf);
3193         ch->max_combined = min_t(int, ch->max_rx, ch->max_tx);
3194
3195         /* report current channels */
3196         ch->combined_count = ice_get_combined_cnt(vsi);
3197         ch->rx_count = vsi->num_rxq - ch->combined_count;
3198         ch->tx_count = vsi->num_txq - ch->combined_count;
3199 }
3200
3201 /**
3202  * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size
3203  * @vsi: VSI to reconfigure RSS LUT on
3204  * @req_rss_size: requested range of queue numbers for hashing
3205  *
3206  * Set the VSI's RSS parameters, configure the RSS LUT based on these.
3207  */
3208 static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size)
3209 {
3210         struct ice_pf *pf = vsi->back;
3211         enum ice_status status;
3212         struct device *dev;
3213         struct ice_hw *hw;
3214         int err = 0;
3215         u8 *lut;
3216
3217         dev = ice_pf_to_dev(pf);
3218         hw = &pf->hw;
3219
3220         if (!req_rss_size)
3221                 return -EINVAL;
3222
3223         lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3224         if (!lut)
3225                 return -ENOMEM;
3226
3227         /* set RSS LUT parameters */
3228         if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3229                 vsi->rss_size = 1;
3230         } else {
3231                 struct ice_hw_common_caps *caps = &hw->func_caps.common_cap;
3232
3233                 vsi->rss_size = min_t(int, req_rss_size,
3234                                       BIT(caps->rss_table_entry_width));
3235         }
3236
3237         /* create/set RSS LUT */
3238         ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
3239         status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type, lut,
3240                                     vsi->rss_table_size);
3241         if (status) {
3242                 dev_err(dev, "Cannot set RSS lut, err %d aq_err %d\n",
3243                         status, hw->adminq.rq_last_status);
3244                 err = -EIO;
3245         }
3246
3247         kfree(lut);
3248         return err;
3249 }
3250
3251 /**
3252  * ice_set_channels - set the number channels
3253  * @dev: network interface device structure
3254  * @ch: ethtool channel data structure
3255  */
3256 static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
3257 {
3258         struct ice_netdev_priv *np = netdev_priv(dev);
3259         struct ice_vsi *vsi = np->vsi;
3260         struct ice_pf *pf = vsi->back;
3261         int new_rx = 0, new_tx = 0;
3262         u32 curr_combined;
3263
3264         /* do not support changing channels in Safe Mode */
3265         if (ice_is_safe_mode(pf)) {
3266                 netdev_err(dev, "Changing channel in Safe Mode is not supported\n");
3267                 return -EOPNOTSUPP;
3268         }
3269         /* do not support changing other_count */
3270         if (ch->other_count)
3271                 return -EINVAL;
3272
3273         curr_combined = ice_get_combined_cnt(vsi);
3274
3275         /* these checks are for cases where user didn't specify a particular
3276          * value on cmd line but we get non-zero value anyway via
3277          * get_channels(); look at ethtool.c in ethtool repository (the user
3278          * space part), particularly, do_schannels() routine
3279          */
3280         if (ch->rx_count == vsi->num_rxq - curr_combined)
3281                 ch->rx_count = 0;
3282         if (ch->tx_count == vsi->num_txq - curr_combined)
3283                 ch->tx_count = 0;
3284         if (ch->combined_count == curr_combined)
3285                 ch->combined_count = 0;
3286
3287         if (!(ch->combined_count || (ch->rx_count && ch->tx_count))) {
3288                 netdev_err(dev, "Please specify at least 1 Rx and 1 Tx channel\n");
3289                 return -EINVAL;
3290         }
3291
3292         new_rx = ch->combined_count + ch->rx_count;
3293         new_tx = ch->combined_count + ch->tx_count;
3294
3295         if (new_rx > ice_get_max_rxq(pf)) {
3296                 netdev_err(dev, "Maximum allowed Rx channels is %d\n",
3297                            ice_get_max_rxq(pf));
3298                 return -EINVAL;
3299         }
3300         if (new_tx > ice_get_max_txq(pf)) {
3301                 netdev_err(dev, "Maximum allowed Tx channels is %d\n",
3302                            ice_get_max_txq(pf));
3303                 return -EINVAL;
3304         }
3305
3306         ice_vsi_recfg_qs(vsi, new_rx, new_tx);
3307
3308         if (new_rx && !netif_is_rxfh_configured(dev))
3309                 return ice_vsi_set_dflt_rss_lut(vsi, new_rx);
3310
3311         return 0;
3312 }
3313
3314 enum ice_container_type {
3315         ICE_RX_CONTAINER,
3316         ICE_TX_CONTAINER,
3317 };
3318
3319 /**
3320  * ice_get_rc_coalesce - get ITR values for specific ring container
3321  * @ec: ethtool structure to fill with driver's coalesce settings
3322  * @c_type: container type, Rx or Tx
3323  * @rc: ring container that the ITR values will come from
3324  *
3325  * Query the device for ice_ring_container specific ITR values. This is
3326  * done per ice_ring_container because each q_vector can have 1 or more rings
3327  * and all of said ring(s) will have the same ITR values.
3328  *
3329  * Returns 0 on success, negative otherwise.
3330  */
3331 static int
3332 ice_get_rc_coalesce(struct ethtool_coalesce *ec, enum ice_container_type c_type,
3333                     struct ice_ring_container *rc)
3334 {
3335         struct ice_pf *pf;
3336
3337         if (!rc->ring)
3338                 return -EINVAL;
3339
3340         pf = rc->ring->vsi->back;
3341
3342         switch (c_type) {
3343         case ICE_RX_CONTAINER:
3344                 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3345                 ec->rx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3346                 ec->rx_coalesce_usecs_high = rc->ring->q_vector->intrl;
3347                 break;
3348         case ICE_TX_CONTAINER:
3349                 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3350                 ec->tx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3351                 break;
3352         default:
3353                 dev_dbg(ice_pf_to_dev(pf), "Invalid c_type %d\n", c_type);
3354                 return -EINVAL;
3355         }
3356
3357         return 0;
3358 }
3359
3360 /**
3361  * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3362  * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3363  * @ec: coalesce settings to program the device with
3364  * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3365  *
3366  * Return 0 on success, and negative under the following conditions:
3367  * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3368  * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3369  */
3370 static int
3371 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3372 {
3373         if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3374                 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3375                                         &vsi->rx_rings[q_num]->q_vector->rx))
3376                         return -EINVAL;
3377                 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3378                                         &vsi->tx_rings[q_num]->q_vector->tx))
3379                         return -EINVAL;
3380         } else if (q_num < vsi->num_rxq) {
3381                 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3382                                         &vsi->rx_rings[q_num]->q_vector->rx))
3383                         return -EINVAL;
3384         } else if (q_num < vsi->num_txq) {
3385                 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3386                                         &vsi->tx_rings[q_num]->q_vector->tx))
3387                         return -EINVAL;
3388         } else {
3389                 return -EINVAL;
3390         }
3391
3392         return 0;
3393 }
3394
3395 /**
3396  * __ice_get_coalesce - get ITR/INTRL values for the device
3397  * @netdev: pointer to the netdev associated with this query
3398  * @ec: ethtool structure to fill with driver's coalesce settings
3399  * @q_num: queue number to get the coalesce settings for
3400  *
3401  * If the caller passes in a negative q_num then we return coalesce settings
3402  * based on queue number 0, else use the actual q_num passed in.
3403  */
3404 static int
3405 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3406                    int q_num)
3407 {
3408         struct ice_netdev_priv *np = netdev_priv(netdev);
3409         struct ice_vsi *vsi = np->vsi;
3410
3411         if (q_num < 0)
3412                 q_num = 0;
3413
3414         if (ice_get_q_coalesce(vsi, ec, q_num))
3415                 return -EINVAL;
3416
3417         return 0;
3418 }
3419
3420 static int
3421 ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3422 {
3423         return __ice_get_coalesce(netdev, ec, -1);
3424 }
3425
3426 static int
3427 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
3428                        struct ethtool_coalesce *ec)
3429 {
3430         return __ice_get_coalesce(netdev, ec, q_num);
3431 }
3432
3433 /**
3434  * ice_set_rc_coalesce - set ITR values for specific ring container
3435  * @c_type: container type, Rx or Tx
3436  * @ec: ethtool structure from user to update ITR settings
3437  * @rc: ring container that the ITR values will come from
3438  * @vsi: VSI associated to the ring container
3439  *
3440  * Set specific ITR values. This is done per ice_ring_container because each
3441  * q_vector can have 1 or more rings and all of said ring(s) will have the same
3442  * ITR values.
3443  *
3444  * Returns 0 on success, negative otherwise.
3445  */
3446 static int
3447 ice_set_rc_coalesce(enum ice_container_type c_type, struct ethtool_coalesce *ec,
3448                     struct ice_ring_container *rc, struct ice_vsi *vsi)
3449 {
3450         const char *c_type_str = (c_type == ICE_RX_CONTAINER) ? "rx" : "tx";
3451         u32 use_adaptive_coalesce, coalesce_usecs;
3452         struct ice_pf *pf = vsi->back;
3453         u16 itr_setting;
3454
3455         if (!rc->ring)
3456                 return -EINVAL;
3457
3458         switch (c_type) {
3459         case ICE_RX_CONTAINER:
3460                 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
3461                     (ec->rx_coalesce_usecs_high &&
3462                      ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
3463                         netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3464                                     c_type_str, pf->hw.intrl_gran,
3465                                     ICE_MAX_INTRL);
3466                         return -EINVAL;
3467                 }
3468                 if (ec->rx_coalesce_usecs_high != rc->ring->q_vector->intrl) {
3469                         rc->ring->q_vector->intrl = ec->rx_coalesce_usecs_high;
3470                         wr32(&pf->hw, GLINT_RATE(rc->ring->q_vector->reg_idx),
3471                              ice_intrl_usec_to_reg(ec->rx_coalesce_usecs_high,
3472                                                    pf->hw.intrl_gran));
3473                 }
3474
3475                 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
3476                 coalesce_usecs = ec->rx_coalesce_usecs;
3477
3478                 break;
3479         case ICE_TX_CONTAINER:
3480                 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
3481                 coalesce_usecs = ec->tx_coalesce_usecs;
3482
3483                 break;
3484         default:
3485                 dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n",
3486                         c_type);
3487                 return -EINVAL;
3488         }
3489
3490         itr_setting = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3491         if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
3492                 netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3493                             c_type_str, c_type_str);
3494                 return -EINVAL;
3495         }
3496
3497         if (coalesce_usecs > ICE_ITR_MAX) {
3498                 netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n",
3499                             c_type_str, ICE_ITR_MAX);
3500                 return -EINVAL;
3501         }
3502
3503         if (use_adaptive_coalesce) {
3504                 rc->itr_setting |= ICE_ITR_DYNAMIC;
3505         } else {
3506                 /* save the user set usecs */
3507                 rc->itr_setting = coalesce_usecs;
3508                 /* device ITR granularity is in 2 usec increments */
3509                 rc->target_itr = ITR_REG_ALIGN(rc->itr_setting);
3510         }
3511
3512         return 0;
3513 }
3514
3515 /**
3516  * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3517  * @vsi: VSI associated to the queue that need updating
3518  * @ec: coalesce settings to program the device with
3519  * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3520  *
3521  * Return 0 on success, and negative under the following conditions:
3522  * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3523  * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3524  */
3525 static int
3526 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3527 {
3528         if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3529                 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3530                                         &vsi->rx_rings[q_num]->q_vector->rx,
3531                                         vsi))
3532                         return -EINVAL;
3533
3534                 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3535                                         &vsi->tx_rings[q_num]->q_vector->tx,
3536                                         vsi))
3537                         return -EINVAL;
3538         } else if (q_num < vsi->num_rxq) {
3539                 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3540                                         &vsi->rx_rings[q_num]->q_vector->rx,
3541                                         vsi))
3542                         return -EINVAL;
3543         } else if (q_num < vsi->num_txq) {
3544                 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3545                                         &vsi->tx_rings[q_num]->q_vector->tx,
3546                                         vsi))
3547                         return -EINVAL;
3548         } else {
3549                 return -EINVAL;
3550         }
3551
3552         return 0;
3553 }
3554
3555 /**
3556  * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs
3557  * @netdev: netdev used for print
3558  * @itr_setting: previous user setting
3559  * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled
3560  * @coalesce_usecs: requested value of [tx|rx]-usecs
3561  * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs
3562  */
3563 static void
3564 ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting,
3565                        u32 use_adaptive_coalesce, u32 coalesce_usecs,
3566                        const char *c_type_str)
3567 {
3568         if (use_adaptive_coalesce)
3569                 return;
3570
3571         itr_setting = ITR_TO_REG(itr_setting);
3572
3573         if (itr_setting != coalesce_usecs && (coalesce_usecs % 2))
3574                 netdev_info(netdev, "User set %s-usecs to %d, device only supports even values. Rounding down and attempting to set %s-usecs to %d\n",
3575                             c_type_str, coalesce_usecs, c_type_str,
3576                             ITR_REG_ALIGN(coalesce_usecs));
3577 }
3578
3579 /**
3580  * __ice_set_coalesce - set ITR/INTRL values for the device
3581  * @netdev: pointer to the netdev associated with this query
3582  * @ec: ethtool structure to fill with driver's coalesce settings
3583  * @q_num: queue number to get the coalesce settings for
3584  *
3585  * If the caller passes in a negative q_num then we set the coalesce settings
3586  * for all Tx/Rx queues, else use the actual q_num passed in.
3587  */
3588 static int
3589 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3590                    int q_num)
3591 {
3592         struct ice_netdev_priv *np = netdev_priv(netdev);
3593         struct ice_vsi *vsi = np->vsi;
3594
3595         if (q_num < 0) {
3596                 struct ice_q_vector *q_vector = vsi->q_vectors[0];
3597                 int v_idx;
3598
3599                 if (q_vector) {
3600                         ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting,
3601                                                ec->use_adaptive_rx_coalesce,
3602                                                ec->rx_coalesce_usecs, "rx");
3603
3604                         ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting,
3605                                                ec->use_adaptive_tx_coalesce,
3606                                                ec->tx_coalesce_usecs, "tx");
3607                 }
3608
3609                 ice_for_each_q_vector(vsi, v_idx) {
3610                         /* In some cases if DCB is configured the num_[rx|tx]q
3611                          * can be less than vsi->num_q_vectors. This check
3612                          * accounts for that so we don't report a false failure
3613                          */
3614                         if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq)
3615                                 goto set_complete;
3616
3617                         if (ice_set_q_coalesce(vsi, ec, v_idx))
3618                                 return -EINVAL;
3619                 }
3620                 goto set_complete;
3621         }
3622
3623         if (ice_set_q_coalesce(vsi, ec, q_num))
3624                 return -EINVAL;
3625
3626 set_complete:
3627
3628         return 0;
3629 }
3630
3631 static int
3632 ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3633 {
3634         return __ice_set_coalesce(netdev, ec, -1);
3635 }
3636
3637 static int
3638 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
3639                        struct ethtool_coalesce *ec)
3640 {
3641         return __ice_set_coalesce(netdev, ec, q_num);
3642 }
3643
3644 #define ICE_I2C_EEPROM_DEV_ADDR         0xA0
3645 #define ICE_I2C_EEPROM_DEV_ADDR2        0xA2
3646 #define ICE_MODULE_TYPE_SFP             0x03
3647 #define ICE_MODULE_TYPE_QSFP_PLUS       0x0D
3648 #define ICE_MODULE_TYPE_QSFP28          0x11
3649 #define ICE_MODULE_SFF_ADDR_MODE        0x04
3650 #define ICE_MODULE_SFF_DIAG_CAPAB       0x40
3651 #define ICE_MODULE_REVISION_ADDR        0x01
3652 #define ICE_MODULE_SFF_8472_COMP        0x5E
3653 #define ICE_MODULE_SFF_8472_SWAP        0x5C
3654 #define ICE_MODULE_QSFP_MAX_LEN         640
3655
3656 /**
3657  * ice_get_module_info - get SFF module type and revision information
3658  * @netdev: network interface device structure
3659  * @modinfo: module EEPROM size and layout information structure
3660  */
3661 static int
3662 ice_get_module_info(struct net_device *netdev,
3663                     struct ethtool_modinfo *modinfo)
3664 {
3665         struct ice_netdev_priv *np = netdev_priv(netdev);
3666         struct ice_vsi *vsi = np->vsi;
3667         struct ice_pf *pf = vsi->back;
3668         struct ice_hw *hw = &pf->hw;
3669         enum ice_status status;
3670         u8 sff8472_comp = 0;
3671         u8 sff8472_swap = 0;
3672         u8 sff8636_rev = 0;
3673         u8 value = 0;
3674
3675         status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
3676                                    0, &value, 1, 0, NULL);
3677         if (status)
3678                 return -EIO;
3679
3680         switch (value) {
3681         case ICE_MODULE_TYPE_SFP:
3682                 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3683                                            ICE_MODULE_SFF_8472_COMP, 0x00, 0,
3684                                            &sff8472_comp, 1, 0, NULL);
3685                 if (status)
3686                         return -EIO;
3687                 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3688                                            ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
3689                                            &sff8472_swap, 1, 0, NULL);
3690                 if (status)
3691                         return -EIO;
3692
3693                 if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
3694                         modinfo->type = ETH_MODULE_SFF_8079;
3695                         modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3696                 } else if (sff8472_comp &&
3697                            (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
3698                         modinfo->type = ETH_MODULE_SFF_8472;
3699                         modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
3700                 } else {
3701                         modinfo->type = ETH_MODULE_SFF_8079;
3702                         modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3703                 }
3704                 break;
3705         case ICE_MODULE_TYPE_QSFP_PLUS:
3706         case ICE_MODULE_TYPE_QSFP28:
3707                 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3708                                            ICE_MODULE_REVISION_ADDR, 0x00, 0,
3709                                            &sff8636_rev, 1, 0, NULL);
3710                 if (status)
3711                         return -EIO;
3712                 /* Check revision compliance */
3713                 if (sff8636_rev > 0x02) {
3714                         /* Module is SFF-8636 compliant */
3715                         modinfo->type = ETH_MODULE_SFF_8636;
3716                         modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3717                 } else {
3718                         modinfo->type = ETH_MODULE_SFF_8436;
3719                         modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3720                 }
3721                 break;
3722         default:
3723                 netdev_warn(netdev, "SFF Module Type not recognized.\n");
3724                 return -EINVAL;
3725         }
3726         return 0;
3727 }
3728
3729 /**
3730  * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
3731  * @netdev: network interface device structure
3732  * @ee: EEPROM dump request structure
3733  * @data: buffer to be filled with EEPROM contents
3734  */
3735 static int
3736 ice_get_module_eeprom(struct net_device *netdev,
3737                       struct ethtool_eeprom *ee, u8 *data)
3738 {
3739         struct ice_netdev_priv *np = netdev_priv(netdev);
3740         u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
3741         struct ice_vsi *vsi = np->vsi;
3742         struct ice_pf *pf = vsi->back;
3743         struct ice_hw *hw = &pf->hw;
3744         enum ice_status status;
3745         bool is_sfp = false;
3746         u16 offset = 0;
3747         u8 value = 0;
3748         u8 page = 0;
3749         int i;
3750
3751         status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0,
3752                                    &value, 1, 0, NULL);
3753         if (status)
3754                 return -EIO;
3755
3756         if (!ee || !ee->len || !data)
3757                 return -EINVAL;
3758
3759         if (value == ICE_MODULE_TYPE_SFP)
3760                 is_sfp = true;
3761
3762         for (i = 0; i < ee->len; i++) {
3763                 offset = i + ee->offset;
3764
3765                 /* Check if we need to access the other memory page */
3766                 if (is_sfp) {
3767                         if (offset >= ETH_MODULE_SFF_8079_LEN) {
3768                                 offset -= ETH_MODULE_SFF_8079_LEN;
3769                                 addr = ICE_I2C_EEPROM_DEV_ADDR2;
3770                         }
3771                 } else {
3772                         while (offset >= ETH_MODULE_SFF_8436_LEN) {
3773                                 /* Compute memory page number and offset. */
3774                                 offset -= ETH_MODULE_SFF_8436_LEN / 2;
3775                                 page++;
3776                         }
3777                 }
3778
3779                 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, !is_sfp,
3780                                            &value, 1, 0, NULL);
3781                 if (status)
3782                         value = 0;
3783                 data[i] = value;
3784         }
3785         return 0;
3786 }
3787
3788 static const struct ethtool_ops ice_ethtool_ops = {
3789         .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
3790                                      ETHTOOL_COALESCE_USE_ADAPTIVE |
3791                                      ETHTOOL_COALESCE_RX_USECS_HIGH,
3792         .get_link_ksettings     = ice_get_link_ksettings,
3793         .set_link_ksettings     = ice_set_link_ksettings,
3794         .get_drvinfo            = ice_get_drvinfo,
3795         .get_regs_len           = ice_get_regs_len,
3796         .get_regs               = ice_get_regs,
3797         .get_msglevel           = ice_get_msglevel,
3798         .set_msglevel           = ice_set_msglevel,
3799         .self_test              = ice_self_test,
3800         .get_link               = ethtool_op_get_link,
3801         .get_eeprom_len         = ice_get_eeprom_len,
3802         .get_eeprom             = ice_get_eeprom,
3803         .get_coalesce           = ice_get_coalesce,
3804         .set_coalesce           = ice_set_coalesce,
3805         .get_strings            = ice_get_strings,
3806         .set_phys_id            = ice_set_phys_id,
3807         .get_ethtool_stats      = ice_get_ethtool_stats,
3808         .get_priv_flags         = ice_get_priv_flags,
3809         .set_priv_flags         = ice_set_priv_flags,
3810         .get_sset_count         = ice_get_sset_count,
3811         .get_rxnfc              = ice_get_rxnfc,
3812         .set_rxnfc              = ice_set_rxnfc,
3813         .get_ringparam          = ice_get_ringparam,
3814         .set_ringparam          = ice_set_ringparam,
3815         .nway_reset             = ice_nway_reset,
3816         .get_pauseparam         = ice_get_pauseparam,
3817         .set_pauseparam         = ice_set_pauseparam,
3818         .get_rxfh_key_size      = ice_get_rxfh_key_size,
3819         .get_rxfh_indir_size    = ice_get_rxfh_indir_size,
3820         .get_rxfh               = ice_get_rxfh,
3821         .set_rxfh               = ice_set_rxfh,
3822         .get_channels           = ice_get_channels,
3823         .set_channels           = ice_set_channels,
3824         .get_ts_info            = ethtool_op_get_ts_info,
3825         .get_per_queue_coalesce = ice_get_per_q_coalesce,
3826         .set_per_queue_coalesce = ice_set_per_q_coalesce,
3827         .get_fecparam           = ice_get_fecparam,
3828         .set_fecparam           = ice_set_fecparam,
3829         .get_module_info        = ice_get_module_info,
3830         .get_module_eeprom      = ice_get_module_eeprom,
3831 };
3832
3833 static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
3834         .get_link_ksettings     = ice_get_link_ksettings,
3835         .set_link_ksettings     = ice_set_link_ksettings,
3836         .get_drvinfo            = ice_get_drvinfo,
3837         .get_regs_len           = ice_get_regs_len,
3838         .get_regs               = ice_get_regs,
3839         .get_msglevel           = ice_get_msglevel,
3840         .set_msglevel           = ice_set_msglevel,
3841         .get_link               = ethtool_op_get_link,
3842         .get_eeprom_len         = ice_get_eeprom_len,
3843         .get_eeprom             = ice_get_eeprom,
3844         .get_strings            = ice_get_strings,
3845         .get_ethtool_stats      = ice_get_ethtool_stats,
3846         .get_sset_count         = ice_get_sset_count,
3847         .get_ringparam          = ice_get_ringparam,
3848         .set_ringparam          = ice_set_ringparam,
3849         .nway_reset             = ice_nway_reset,
3850         .get_channels           = ice_get_channels,
3851 };
3852
3853 /**
3854  * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
3855  * @netdev: network interface device structure
3856  */
3857 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
3858 {
3859         netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
3860 }
3861
3862 /**
3863  * ice_set_ethtool_ops - setup netdev ethtool ops
3864  * @netdev: network interface device structure
3865  *
3866  * setup netdev ethtool ops with ice specific ops
3867  */
3868 void ice_set_ethtool_ops(struct net_device *netdev)
3869 {
3870         netdev->ethtool_ops = &ice_ethtool_ops;
3871 }