1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* ethtool support for ice */
9 char stat_string[ETH_GSTRING_LEN];
14 #define ICE_STAT(_type, _name, _stat) { \
15 .stat_string = _name, \
16 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
17 .stat_offset = offsetof(_type, _stat) \
20 #define ICE_VSI_STAT(_name, _stat) \
21 ICE_STAT(struct ice_vsi, _name, _stat)
22 #define ICE_PF_STAT(_name, _stat) \
23 ICE_STAT(struct ice_pf, _name, _stat)
25 static int ice_q_stats_len(struct net_device *netdev)
27 struct ice_netdev_priv *np = netdev_priv(netdev);
29 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
30 (sizeof(struct ice_q_stats) / sizeof(u64)));
33 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats)
34 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats)
36 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_VSI_STATS_LEN + \
39 static const struct ice_stats ice_gstrings_vsi_stats[] = {
40 ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
41 ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
42 ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
43 ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
44 ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
45 ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
46 ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
47 ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
48 ICE_VSI_STAT("rx_discards", eth_stats.rx_discards),
49 ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
50 ICE_VSI_STAT("tx_linearize", tx_linearize),
51 ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
52 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
53 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
56 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
57 * but they aren't. This device is capable of supporting multiple
58 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
59 * netdevs whereas the PF_STATs are for the physical function that's
60 * hosting these netdevs.
62 * The PF_STATs are appended to the netdev stats only when ethtool -S
63 * is queried on the base PF netdev.
65 static const struct ice_stats ice_gstrings_pf_stats[] = {
66 ICE_PF_STAT("tx_bytes", stats.eth.tx_bytes),
67 ICE_PF_STAT("rx_bytes", stats.eth.rx_bytes),
68 ICE_PF_STAT("tx_unicast", stats.eth.tx_unicast),
69 ICE_PF_STAT("rx_unicast", stats.eth.rx_unicast),
70 ICE_PF_STAT("tx_multicast", stats.eth.tx_multicast),
71 ICE_PF_STAT("rx_multicast", stats.eth.rx_multicast),
72 ICE_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
73 ICE_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
74 ICE_PF_STAT("tx_errors", stats.eth.tx_errors),
75 ICE_PF_STAT("tx_size_64", stats.tx_size_64),
76 ICE_PF_STAT("rx_size_64", stats.rx_size_64),
77 ICE_PF_STAT("tx_size_127", stats.tx_size_127),
78 ICE_PF_STAT("rx_size_127", stats.rx_size_127),
79 ICE_PF_STAT("tx_size_255", stats.tx_size_255),
80 ICE_PF_STAT("rx_size_255", stats.rx_size_255),
81 ICE_PF_STAT("tx_size_511", stats.tx_size_511),
82 ICE_PF_STAT("rx_size_511", stats.rx_size_511),
83 ICE_PF_STAT("tx_size_1023", stats.tx_size_1023),
84 ICE_PF_STAT("rx_size_1023", stats.rx_size_1023),
85 ICE_PF_STAT("tx_size_1522", stats.tx_size_1522),
86 ICE_PF_STAT("rx_size_1522", stats.rx_size_1522),
87 ICE_PF_STAT("tx_size_big", stats.tx_size_big),
88 ICE_PF_STAT("rx_size_big", stats.rx_size_big),
89 ICE_PF_STAT("link_xon_tx", stats.link_xon_tx),
90 ICE_PF_STAT("link_xon_rx", stats.link_xon_rx),
91 ICE_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
92 ICE_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
93 ICE_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
94 ICE_PF_STAT("rx_undersize", stats.rx_undersize),
95 ICE_PF_STAT("rx_fragments", stats.rx_fragments),
96 ICE_PF_STAT("rx_oversize", stats.rx_oversize),
97 ICE_PF_STAT("rx_jabber", stats.rx_jabber),
98 ICE_PF_STAT("rx_csum_bad", hw_csum_rx_error),
99 ICE_PF_STAT("rx_length_errors", stats.rx_len_errors),
100 ICE_PF_STAT("rx_dropped", stats.eth.rx_discards),
101 ICE_PF_STAT("rx_crc_errors", stats.crc_errors),
102 ICE_PF_STAT("illegal_bytes", stats.illegal_bytes),
103 ICE_PF_STAT("mac_local_faults", stats.mac_local_faults),
104 ICE_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
107 static const u32 ice_regs_dump_list[] = {
118 * ice_nvm_version_str - format the NVM version strings
119 * @hw: ptr to the hardware info
121 static char *ice_nvm_version_str(struct ice_hw *hw)
123 static char buf[ICE_ETHTOOL_FWVER_LEN];
128 full_ver = hw->nvm.oem_ver;
129 ver = (u8)((full_ver & ICE_OEM_VER_MASK) >> ICE_OEM_VER_SHIFT);
130 build = (u16)((full_ver & ICE_OEM_VER_BUILD_MASK) >>
131 ICE_OEM_VER_BUILD_SHIFT);
132 patch = (u8)(full_ver & ICE_OEM_VER_PATCH_MASK);
134 snprintf(buf, sizeof(buf), "%x.%02x 0x%x %d.%d.%d",
135 (hw->nvm.ver & ICE_NVM_VER_HI_MASK) >> ICE_NVM_VER_HI_SHIFT,
136 (hw->nvm.ver & ICE_NVM_VER_LO_MASK) >> ICE_NVM_VER_LO_SHIFT,
137 hw->nvm.eetrack, ver, build, patch);
143 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
145 struct ice_netdev_priv *np = netdev_priv(netdev);
146 struct ice_vsi *vsi = np->vsi;
147 struct ice_pf *pf = vsi->back;
149 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
150 strlcpy(drvinfo->version, ice_drv_ver, sizeof(drvinfo->version));
151 strlcpy(drvinfo->fw_version, ice_nvm_version_str(&pf->hw),
152 sizeof(drvinfo->fw_version));
153 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
154 sizeof(drvinfo->bus_info));
157 static int ice_get_regs_len(struct net_device __always_unused *netdev)
159 return sizeof(ice_regs_dump_list);
163 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
165 struct ice_netdev_priv *np = netdev_priv(netdev);
166 struct ice_pf *pf = np->vsi->back;
167 struct ice_hw *hw = &pf->hw;
168 u32 *regs_buf = (u32 *)p;
173 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
174 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
177 static u32 ice_get_msglevel(struct net_device *netdev)
179 struct ice_netdev_priv *np = netdev_priv(netdev);
180 struct ice_pf *pf = np->vsi->back;
182 #ifndef CONFIG_DYNAMIC_DEBUG
183 if (pf->hw.debug_mask)
184 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
186 #endif /* !CONFIG_DYNAMIC_DEBUG */
188 return pf->msg_enable;
191 static void ice_set_msglevel(struct net_device *netdev, u32 data)
193 struct ice_netdev_priv *np = netdev_priv(netdev);
194 struct ice_pf *pf = np->vsi->back;
196 #ifndef CONFIG_DYNAMIC_DEBUG
197 if (ICE_DBG_USER & data)
198 pf->hw.debug_mask = data;
200 pf->msg_enable = data;
202 pf->msg_enable = data;
203 #endif /* !CONFIG_DYNAMIC_DEBUG */
206 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
208 struct ice_netdev_priv *np = netdev_priv(netdev);
209 struct ice_vsi *vsi = np->vsi;
210 char *p = (char *)data;
215 for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
216 snprintf(p, ETH_GSTRING_LEN, "%s",
217 ice_gstrings_vsi_stats[i].stat_string);
218 p += ETH_GSTRING_LEN;
221 ice_for_each_alloc_txq(vsi, i) {
222 snprintf(p, ETH_GSTRING_LEN,
223 "tx-queue-%u.tx_packets", i);
224 p += ETH_GSTRING_LEN;
225 snprintf(p, ETH_GSTRING_LEN, "tx-queue-%u.tx_bytes", i);
226 p += ETH_GSTRING_LEN;
229 ice_for_each_alloc_rxq(vsi, i) {
230 snprintf(p, ETH_GSTRING_LEN,
231 "rx-queue-%u.rx_packets", i);
232 p += ETH_GSTRING_LEN;
233 snprintf(p, ETH_GSTRING_LEN, "rx-queue-%u.rx_bytes", i);
234 p += ETH_GSTRING_LEN;
237 if (vsi->type != ICE_VSI_PF)
240 for (i = 0; i < ICE_PF_STATS_LEN; i++) {
241 snprintf(p, ETH_GSTRING_LEN, "port.%s",
242 ice_gstrings_pf_stats[i].stat_string);
243 p += ETH_GSTRING_LEN;
252 static int ice_get_sset_count(struct net_device *netdev, int sset)
256 /* The number (and order) of strings reported *must* remain
257 * constant for a given netdevice. This function must not
258 * report a different number based on run time parameters
259 * (such as the number of queues in use, or the setting of
260 * a private ethtool flag). This is due to the nature of the
263 * Userspace programs such as ethtool must make 3 separate
264 * ioctl requests, one for size, one for the strings, and
265 * finally one for the stats. Since these cross into
266 * userspace, changes to the number or size could result in
267 * undefined memory access or incorrect string<->value
268 * correlations for statistics.
270 * Even if it appears to be safe, changes to the size or
271 * order of strings will suffer from race conditions and are
274 return ICE_ALL_STATS_LEN(netdev);
281 ice_get_ethtool_stats(struct net_device *netdev,
282 struct ethtool_stats __always_unused *stats, u64 *data)
284 struct ice_netdev_priv *np = netdev_priv(netdev);
285 struct ice_vsi *vsi = np->vsi;
286 struct ice_pf *pf = vsi->back;
287 struct ice_ring *ring;
292 for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
293 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
294 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
295 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
298 /* populate per queue stats */
301 ice_for_each_alloc_txq(vsi, j) {
302 ring = READ_ONCE(vsi->tx_rings[j]);
304 data[i++] = ring->stats.pkts;
305 data[i++] = ring->stats.bytes;
312 ice_for_each_alloc_rxq(vsi, j) {
313 ring = READ_ONCE(vsi->rx_rings[j]);
315 data[i++] = ring->stats.pkts;
316 data[i++] = ring->stats.bytes;
325 if (vsi->type != ICE_VSI_PF)
328 for (j = 0; j < ICE_PF_STATS_LEN; j++) {
329 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
330 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
331 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
336 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
337 * @netdev: network interface device structure
338 * @ks: ethtool link ksettings struct to fill out
340 static void ice_phy_type_to_ethtool(struct net_device *netdev,
341 struct ethtool_link_ksettings *ks)
343 struct ice_netdev_priv *np = netdev_priv(netdev);
344 struct ice_link_status *hw_link_info;
345 struct ice_vsi *vsi = np->vsi;
348 hw_link_info = &vsi->port_info->phy.link_info;
349 phy_types_low = vsi->port_info->phy.phy_type_low;
351 ethtool_link_ksettings_zero_link_mode(ks, supported);
352 ethtool_link_ksettings_zero_link_mode(ks, advertising);
354 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
355 phy_types_low & ICE_PHY_TYPE_LOW_100M_SGMII) {
356 ethtool_link_ksettings_add_link_mode(ks, supported,
358 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100MB)
359 ethtool_link_ksettings_add_link_mode(ks, advertising,
362 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
363 phy_types_low & ICE_PHY_TYPE_LOW_1G_SGMII) {
364 ethtool_link_ksettings_add_link_mode(ks, supported,
366 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
367 ethtool_link_ksettings_add_link_mode(ks, advertising,
370 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX) {
371 ethtool_link_ksettings_add_link_mode(ks, supported,
373 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
374 ethtool_link_ksettings_add_link_mode(ks, advertising,
377 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_SX ||
378 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_LX) {
379 ethtool_link_ksettings_add_link_mode(ks, supported,
381 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
382 ethtool_link_ksettings_add_link_mode(ks, advertising,
385 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T) {
386 ethtool_link_ksettings_add_link_mode(ks, supported,
388 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
389 ethtool_link_ksettings_add_link_mode(ks, advertising,
392 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_X ||
393 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX) {
394 ethtool_link_ksettings_add_link_mode(ks, supported,
396 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
397 ethtool_link_ksettings_add_link_mode(ks, advertising,
400 if (phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
401 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR) {
402 ethtool_link_ksettings_add_link_mode(ks, supported,
404 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_5GB)
405 ethtool_link_ksettings_add_link_mode(ks, advertising,
408 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
409 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_DA ||
410 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC ||
411 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_C2C) {
412 ethtool_link_ksettings_add_link_mode(ks, supported,
414 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
415 ethtool_link_ksettings_add_link_mode(ks, advertising,
418 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1) {
419 ethtool_link_ksettings_add_link_mode(ks, supported,
421 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
422 ethtool_link_ksettings_add_link_mode(ks, advertising,
425 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_SR) {
426 ethtool_link_ksettings_add_link_mode(ks, supported,
428 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
429 ethtool_link_ksettings_add_link_mode(ks, advertising,
432 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_LR) {
433 ethtool_link_ksettings_add_link_mode(ks, supported,
435 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
436 ethtool_link_ksettings_add_link_mode(ks, advertising,
439 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
440 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
441 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
442 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
443 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC ||
444 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_C2C) {
445 ethtool_link_ksettings_add_link_mode(ks, supported,
447 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
448 ethtool_link_ksettings_add_link_mode(ks, advertising,
451 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_SR ||
452 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_LR) {
453 ethtool_link_ksettings_add_link_mode(ks, supported,
455 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
456 ethtool_link_ksettings_add_link_mode(ks, advertising,
459 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
460 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
461 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1) {
462 ethtool_link_ksettings_add_link_mode(ks, supported,
464 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
465 ethtool_link_ksettings_add_link_mode(ks, advertising,
468 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
469 ethtool_link_ksettings_add_link_mode(ks, supported,
471 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
472 ethtool_link_ksettings_add_link_mode(ks, advertising,
475 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
476 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC ||
477 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI) {
478 ethtool_link_ksettings_add_link_mode(ks, supported,
480 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
481 ethtool_link_ksettings_add_link_mode(ks, advertising,
484 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_SR4) {
485 ethtool_link_ksettings_add_link_mode(ks, supported,
487 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
488 ethtool_link_ksettings_add_link_mode(ks, advertising,
491 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_LR4) {
492 ethtool_link_ksettings_add_link_mode(ks, supported,
494 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
495 ethtool_link_ksettings_add_link_mode(ks, advertising,
499 /* Autoneg PHY types */
500 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
501 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
502 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX ||
503 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T ||
504 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX ||
505 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
506 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR ||
507 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
508 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 ||
509 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
510 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
511 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
512 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
513 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
514 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
515 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1 ||
516 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
517 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
518 ethtool_link_ksettings_add_link_mode(ks, supported,
520 ethtool_link_ksettings_add_link_mode(ks, advertising,
525 #define TEST_SET_BITS_TIMEOUT 50
526 #define TEST_SET_BITS_SLEEP_MAX 2000
527 #define TEST_SET_BITS_SLEEP_MIN 1000
530 * ice_get_settings_link_up - Get Link settings for when link is up
531 * @ks: ethtool ksettings to fill in
532 * @netdev: network interface device structure
534 static void ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
535 struct net_device *netdev)
537 struct ice_netdev_priv *np = netdev_priv(netdev);
538 struct ethtool_link_ksettings cap_ksettings;
539 struct ice_link_status *link_info;
540 struct ice_vsi *vsi = np->vsi;
541 bool unrecog_phy_low = false;
543 link_info = &vsi->port_info->phy.link_info;
545 /* Initialize supported and advertised settings based on phy settings */
546 switch (link_info->phy_type_low) {
547 case ICE_PHY_TYPE_LOW_100BASE_TX:
548 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
549 ethtool_link_ksettings_add_link_mode(ks, supported,
551 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
552 ethtool_link_ksettings_add_link_mode(ks, advertising,
555 case ICE_PHY_TYPE_LOW_100M_SGMII:
556 ethtool_link_ksettings_add_link_mode(ks, supported,
559 case ICE_PHY_TYPE_LOW_1000BASE_T:
560 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
561 ethtool_link_ksettings_add_link_mode(ks, supported,
563 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
564 ethtool_link_ksettings_add_link_mode(ks, advertising,
567 case ICE_PHY_TYPE_LOW_1G_SGMII:
568 ethtool_link_ksettings_add_link_mode(ks, supported,
571 case ICE_PHY_TYPE_LOW_1000BASE_SX:
572 case ICE_PHY_TYPE_LOW_1000BASE_LX:
573 ethtool_link_ksettings_add_link_mode(ks, supported,
576 case ICE_PHY_TYPE_LOW_1000BASE_KX:
577 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
578 ethtool_link_ksettings_add_link_mode(ks, supported,
580 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
581 ethtool_link_ksettings_add_link_mode(ks, advertising,
584 case ICE_PHY_TYPE_LOW_2500BASE_T:
585 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
586 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
587 ethtool_link_ksettings_add_link_mode(ks, supported,
589 ethtool_link_ksettings_add_link_mode(ks, advertising,
592 case ICE_PHY_TYPE_LOW_2500BASE_X:
593 ethtool_link_ksettings_add_link_mode(ks, supported,
596 case ICE_PHY_TYPE_LOW_2500BASE_KX:
597 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
598 ethtool_link_ksettings_add_link_mode(ks, supported,
600 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
601 ethtool_link_ksettings_add_link_mode(ks, advertising,
604 case ICE_PHY_TYPE_LOW_5GBASE_T:
605 case ICE_PHY_TYPE_LOW_5GBASE_KR:
606 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
607 ethtool_link_ksettings_add_link_mode(ks, supported,
609 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
610 ethtool_link_ksettings_add_link_mode(ks, advertising,
613 case ICE_PHY_TYPE_LOW_10GBASE_T:
614 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
615 ethtool_link_ksettings_add_link_mode(ks, supported,
617 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
618 ethtool_link_ksettings_add_link_mode(ks, advertising,
621 case ICE_PHY_TYPE_LOW_10G_SFI_DA:
622 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
623 case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
624 ethtool_link_ksettings_add_link_mode(ks, supported,
627 case ICE_PHY_TYPE_LOW_10GBASE_SR:
628 ethtool_link_ksettings_add_link_mode(ks, supported,
631 case ICE_PHY_TYPE_LOW_10GBASE_LR:
632 ethtool_link_ksettings_add_link_mode(ks, supported,
635 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
636 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
637 ethtool_link_ksettings_add_link_mode(ks, supported,
639 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
640 ethtool_link_ksettings_add_link_mode(ks, advertising,
643 case ICE_PHY_TYPE_LOW_25GBASE_T:
644 case ICE_PHY_TYPE_LOW_25GBASE_CR:
645 case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
646 case ICE_PHY_TYPE_LOW_25GBASE_CR1:
647 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
648 ethtool_link_ksettings_add_link_mode(ks, supported,
650 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
651 ethtool_link_ksettings_add_link_mode(ks, advertising,
654 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
655 ethtool_link_ksettings_add_link_mode(ks, supported,
658 case ICE_PHY_TYPE_LOW_25GBASE_SR:
659 case ICE_PHY_TYPE_LOW_25GBASE_LR:
660 ethtool_link_ksettings_add_link_mode(ks, supported,
663 case ICE_PHY_TYPE_LOW_25GBASE_KR:
664 case ICE_PHY_TYPE_LOW_25GBASE_KR1:
665 case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
666 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
667 ethtool_link_ksettings_add_link_mode(ks, supported,
669 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
670 ethtool_link_ksettings_add_link_mode(ks, advertising,
673 case ICE_PHY_TYPE_LOW_40GBASE_CR4:
674 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
675 ethtool_link_ksettings_add_link_mode(ks, supported,
677 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
678 ethtool_link_ksettings_add_link_mode(ks, advertising,
681 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
682 case ICE_PHY_TYPE_LOW_40G_XLAUI:
683 ethtool_link_ksettings_add_link_mode(ks, supported,
686 case ICE_PHY_TYPE_LOW_40GBASE_SR4:
687 ethtool_link_ksettings_add_link_mode(ks, supported,
690 case ICE_PHY_TYPE_LOW_40GBASE_LR4:
691 ethtool_link_ksettings_add_link_mode(ks, supported,
694 case ICE_PHY_TYPE_LOW_40GBASE_KR4:
695 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
696 ethtool_link_ksettings_add_link_mode(ks, supported,
698 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
699 ethtool_link_ksettings_add_link_mode(ks, advertising,
703 unrecog_phy_low = true;
706 if (unrecog_phy_low) {
707 /* if we got here and link is up something bad is afoot */
708 netdev_info(netdev, "WARNING: Unrecognized PHY_Low (0x%llx).\n",
709 (u64)link_info->phy_type_low);
712 /* Now that we've worked out everything that could be supported by the
713 * current PHY type, get what is supported by the NVM and intersect
714 * them to get what is truly supported
716 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
717 ice_phy_type_to_ethtool(netdev, &cap_ksettings);
718 ethtool_intersect_link_masks(ks, &cap_ksettings);
720 switch (link_info->link_speed) {
721 case ICE_AQ_LINK_SPEED_40GB:
722 ks->base.speed = SPEED_40000;
724 case ICE_AQ_LINK_SPEED_25GB:
725 ks->base.speed = SPEED_25000;
727 case ICE_AQ_LINK_SPEED_20GB:
728 ks->base.speed = SPEED_20000;
730 case ICE_AQ_LINK_SPEED_10GB:
731 ks->base.speed = SPEED_10000;
733 case ICE_AQ_LINK_SPEED_5GB:
734 ks->base.speed = SPEED_5000;
736 case ICE_AQ_LINK_SPEED_2500MB:
737 ks->base.speed = SPEED_2500;
739 case ICE_AQ_LINK_SPEED_1000MB:
740 ks->base.speed = SPEED_1000;
742 case ICE_AQ_LINK_SPEED_100MB:
743 ks->base.speed = SPEED_100;
747 "WARNING: Unrecognized link_speed (0x%x).\n",
748 link_info->link_speed);
751 ks->base.duplex = DUPLEX_FULL;
755 * ice_get_settings_link_down - Get the Link settings when link is down
756 * @ks: ethtool ksettings to fill in
757 * @netdev: network interface device structure
759 * Reports link settings that can be determined when link is down
762 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
763 struct net_device __always_unused *netdev)
765 /* link is down and the driver needs to fall back on
766 * supported phy types to figure out what info to display
768 ice_phy_type_to_ethtool(netdev, ks);
770 /* With no link, speed and duplex are unknown */
771 ks->base.speed = SPEED_UNKNOWN;
772 ks->base.duplex = DUPLEX_UNKNOWN;
776 * ice_get_link_ksettings - Get Link Speed and Duplex settings
777 * @netdev: network interface device structure
778 * @ks: ethtool ksettings
780 * Reports speed/duplex settings based on media_type
782 static int ice_get_link_ksettings(struct net_device *netdev,
783 struct ethtool_link_ksettings *ks)
785 struct ice_netdev_priv *np = netdev_priv(netdev);
786 struct ice_link_status *hw_link_info;
787 struct ice_vsi *vsi = np->vsi;
789 ethtool_link_ksettings_zero_link_mode(ks, supported);
790 ethtool_link_ksettings_zero_link_mode(ks, advertising);
791 hw_link_info = &vsi->port_info->phy.link_info;
793 /* set speed and duplex */
794 if (hw_link_info->link_info & ICE_AQ_LINK_UP)
795 ice_get_settings_link_up(ks, netdev);
797 ice_get_settings_link_down(ks, netdev);
799 /* set autoneg settings */
800 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
801 AUTONEG_ENABLE : AUTONEG_DISABLE;
803 /* set media type settings */
804 switch (vsi->port_info->phy.media_type) {
805 case ICE_MEDIA_FIBER:
806 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
807 ks->base.port = PORT_FIBRE;
809 case ICE_MEDIA_BASET:
810 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
811 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
812 ks->base.port = PORT_TP;
814 case ICE_MEDIA_BACKPLANE:
815 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
816 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
817 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
818 ethtool_link_ksettings_add_link_mode(ks, advertising,
820 ks->base.port = PORT_NONE;
823 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
824 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
825 ks->base.port = PORT_DA;
828 ks->base.port = PORT_OTHER;
832 /* flow control is symmetric and always supported */
833 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
835 switch (vsi->port_info->fc.req_mode) {
837 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
839 case ICE_FC_TX_PAUSE:
840 ethtool_link_ksettings_add_link_mode(ks, advertising,
843 case ICE_FC_RX_PAUSE:
844 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
845 ethtool_link_ksettings_add_link_mode(ks, advertising,
850 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
851 ethtool_link_ksettings_del_link_mode(ks, advertising,
860 * ice_ksettings_find_adv_link_speed - Find advertising link speed
861 * @ks: ethtool ksettings
864 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
866 u16 adv_link_speed = 0;
868 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
870 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
871 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
873 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
874 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
876 ethtool_link_ksettings_test_link_mode(ks, advertising,
878 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
879 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
881 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
882 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
884 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
885 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
887 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
888 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
890 ethtool_link_ksettings_test_link_mode(ks, advertising,
892 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
893 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
895 ethtool_link_ksettings_test_link_mode(ks, advertising,
897 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
898 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
900 ethtool_link_ksettings_test_link_mode(ks, advertising,
902 ethtool_link_ksettings_test_link_mode(ks, advertising,
904 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
905 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
906 40000baseCR4_Full) ||
907 ethtool_link_ksettings_test_link_mode(ks, advertising,
908 40000baseSR4_Full) ||
909 ethtool_link_ksettings_test_link_mode(ks, advertising,
910 40000baseLR4_Full) ||
911 ethtool_link_ksettings_test_link_mode(ks, advertising,
913 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
915 return adv_link_speed;
921 * @ks: ethtool_link_ksettings
922 * @config: configuration that will be sent down to FW
923 * @autoneg_enabled: autonegotiation is enabled or not
924 * @autoneg_changed: will there a change in autonegotiation
925 * @netdev: network interface device structure
927 * Setup PHY autonegotiation feature
930 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
931 struct ice_aqc_set_phy_cfg_data *config,
932 u8 autoneg_enabled, u8 *autoneg_changed,
933 struct net_device *netdev)
937 *autoneg_changed = 0;
940 if (autoneg_enabled == AUTONEG_ENABLE) {
941 /* If autoneg was not already enabled */
942 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
943 /* If autoneg is not supported, return error */
944 if (!ethtool_link_ksettings_test_link_mode(ks,
947 netdev_info(netdev, "Autoneg not supported on this phy.\n");
950 /* Autoneg is allowed to change */
951 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
952 *autoneg_changed = 1;
956 /* If autoneg is currently enabled */
957 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
958 /* If autoneg is supported 10GBASE_T is the only phy
959 * that can disable it, so otherwise return error
961 if (ethtool_link_ksettings_test_link_mode(ks,
964 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
967 /* Autoneg is allowed to change */
968 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
969 *autoneg_changed = 1;
978 * ice_set_link_ksettings - Set Speed and Duplex
979 * @netdev: network interface device structure
980 * @ks: ethtool ksettings
982 * Set speed/duplex per media_types advertised/forced
984 static int ice_set_link_ksettings(struct net_device *netdev,
985 const struct ethtool_link_ksettings *ks)
987 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT, lport = 0;
988 struct ice_netdev_priv *np = netdev_priv(netdev);
989 struct ethtool_link_ksettings safe_ks, copy_ks;
990 struct ice_aqc_get_phy_caps_data *abilities;
991 u16 adv_link_speed, curr_link_speed, idx;
992 struct ice_aqc_set_phy_cfg_data config;
993 struct ice_pf *pf = np->vsi->back;
994 struct ice_port_info *p;
995 u8 autoneg_changed = 0;
996 enum ice_status status;
1001 p = np->vsi->port_info;
1006 /* Check if this is lan vsi */
1007 for (idx = 0 ; idx < pf->num_alloc_vsi ; idx++) {
1008 if (pf->vsi[idx]->type == ICE_VSI_PF) {
1009 if (np->vsi != pf->vsi[idx])
1015 if (p->phy.media_type != ICE_MEDIA_BASET &&
1016 p->phy.media_type != ICE_MEDIA_FIBER &&
1017 p->phy.media_type != ICE_MEDIA_BACKPLANE &&
1018 p->phy.media_type != ICE_MEDIA_DA &&
1019 p->phy.link_info.link_info & ICE_AQ_LINK_UP)
1022 /* copy the ksettings to copy_ks to avoid modifying the original */
1023 memcpy(©_ks, ks, sizeof(struct ethtool_link_ksettings));
1025 /* save autoneg out of ksettings */
1026 autoneg = copy_ks.base.autoneg;
1028 memset(&safe_ks, 0, sizeof(safe_ks));
1030 /* Get link modes supported by hardware.*/
1031 ice_phy_type_to_ethtool(netdev, &safe_ks);
1033 /* and check against modes requested by user.
1034 * Return an error if unsupported mode was set.
1036 if (!bitmap_subset(copy_ks.link_modes.advertising,
1037 safe_ks.link_modes.supported,
1038 __ETHTOOL_LINK_MODE_MASK_NBITS))
1041 /* get our own copy of the bits to check against */
1042 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
1043 safe_ks.base.cmd = copy_ks.base.cmd;
1044 safe_ks.base.link_mode_masks_nwords =
1045 copy_ks.base.link_mode_masks_nwords;
1046 ice_get_link_ksettings(netdev, &safe_ks);
1048 /* set autoneg back to what it currently is */
1049 copy_ks.base.autoneg = safe_ks.base.autoneg;
1050 /* we don't compare the speed */
1051 copy_ks.base.speed = safe_ks.base.speed;
1053 /* If copy_ks.base and safe_ks.base are not the same now, then they are
1054 * trying to set something that we do not support.
1056 if (memcmp(©_ks.base, &safe_ks.base,
1057 sizeof(struct ethtool_link_settings)))
1060 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
1064 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
1067 abilities = devm_kzalloc(&pf->pdev->dev, sizeof(*abilities),
1072 /* Get the current phy config */
1073 status = ice_aq_get_phy_caps(p, false, ICE_AQC_REPORT_SW_CFG, abilities,
1080 /* Copy abilities to config in case autoneg is not set below */
1081 memset(&config, 0, sizeof(struct ice_aqc_set_phy_cfg_data));
1082 config.caps = abilities->caps & ~ICE_AQC_PHY_AN_MODE;
1083 if (abilities->caps & ICE_AQC_PHY_AN_MODE)
1084 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1087 err = ice_setup_autoneg(p, &safe_ks, &config, autoneg, &autoneg_changed,
1093 /* Call to get the current link speed */
1094 p->phy.get_link_info = true;
1095 status = ice_get_link_status(p, &linkup);
1101 curr_link_speed = p->phy.link_info.link_speed;
1102 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
1104 /* If speed didn't get set, set it to what it currently is.
1105 * This is needed because if advertise is 0 (as it is when autoneg
1106 * is disabled) then speed won't get set.
1108 if (!adv_link_speed)
1109 adv_link_speed = curr_link_speed;
1111 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
1112 ice_update_phy_type(&phy_type_low, adv_link_speed);
1114 if (!autoneg_changed && adv_link_speed == curr_link_speed) {
1115 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1119 /* copy over the rest of the abilities */
1120 config.low_power_ctrl = abilities->low_power_ctrl;
1121 config.eee_cap = abilities->eee_cap;
1122 config.eeer_value = abilities->eeer_value;
1123 config.link_fec_opt = abilities->link_fec_options;
1125 /* save the requested speeds */
1126 p->phy.link_info.req_speeds = adv_link_speed;
1128 /* set link and auto negotiation so changes take effect */
1129 config.caps |= ICE_AQ_PHY_ENA_LINK;
1132 config.phy_type_low = cpu_to_le64(phy_type_low) &
1133 abilities->phy_type_low;
1136 netdev_info(netdev, "Nothing changed. No PHY_TYPE is corresponded to advertised link speed.\n");
1140 /* If link is up put link down */
1141 if (p->phy.link_info.link_info & ICE_AQ_LINK_UP) {
1142 /* Tell the OS link is going down, the link will go
1143 * back up when fw says it is ready asynchronously
1145 ice_print_link_msg(np->vsi, false);
1146 netif_carrier_off(netdev);
1147 netif_tx_stop_all_queues(netdev);
1150 /* make the aq call */
1151 status = ice_aq_set_phy_cfg(&pf->hw, lport, &config, NULL);
1153 netdev_info(netdev, "Set phy config failed,\n");
1158 devm_kfree(&pf->pdev->dev, abilities);
1159 clear_bit(__ICE_CFG_BUSY, pf->state);
1165 * ice_get_rxnfc - command to get RX flow classification rules
1166 * @netdev: network interface device structure
1167 * @cmd: ethtool rxnfc command
1168 * @rule_locs: buffer to rturn Rx flow classification rules
1170 * Returns Success if the command is supported.
1172 static int ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1173 u32 __always_unused *rule_locs)
1175 struct ice_netdev_priv *np = netdev_priv(netdev);
1176 struct ice_vsi *vsi = np->vsi;
1177 int ret = -EOPNOTSUPP;
1180 case ETHTOOL_GRXRINGS:
1181 cmd->data = vsi->rss_size;
1192 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
1194 struct ice_netdev_priv *np = netdev_priv(netdev);
1195 struct ice_vsi *vsi = np->vsi;
1197 ring->rx_max_pending = ICE_MAX_NUM_DESC;
1198 ring->tx_max_pending = ICE_MAX_NUM_DESC;
1199 ring->rx_pending = vsi->rx_rings[0]->count;
1200 ring->tx_pending = vsi->tx_rings[0]->count;
1202 /* Rx mini and jumbo rings are not supported */
1203 ring->rx_mini_max_pending = 0;
1204 ring->rx_jumbo_max_pending = 0;
1205 ring->rx_mini_pending = 0;
1206 ring->rx_jumbo_pending = 0;
1210 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
1212 struct ice_ring *tx_rings = NULL, *rx_rings = NULL;
1213 struct ice_netdev_priv *np = netdev_priv(netdev);
1214 struct ice_vsi *vsi = np->vsi;
1215 struct ice_pf *pf = vsi->back;
1216 int i, timeout = 50, err = 0;
1217 u32 new_rx_cnt, new_tx_cnt;
1219 if (ring->tx_pending > ICE_MAX_NUM_DESC ||
1220 ring->tx_pending < ICE_MIN_NUM_DESC ||
1221 ring->rx_pending > ICE_MAX_NUM_DESC ||
1222 ring->rx_pending < ICE_MIN_NUM_DESC) {
1223 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
1224 ring->tx_pending, ring->rx_pending,
1225 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
1226 ICE_REQ_DESC_MULTIPLE);
1230 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
1231 if (new_tx_cnt != ring->tx_pending)
1233 "Requested Tx descriptor count rounded up to %d\n",
1235 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
1236 if (new_rx_cnt != ring->rx_pending)
1238 "Requested Rx descriptor count rounded up to %d\n",
1241 /* if nothing to do return success */
1242 if (new_tx_cnt == vsi->tx_rings[0]->count &&
1243 new_rx_cnt == vsi->rx_rings[0]->count) {
1244 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
1248 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
1252 usleep_range(1000, 2000);
1255 /* set for the next time the netdev is started */
1256 if (!netif_running(vsi->netdev)) {
1257 for (i = 0; i < vsi->alloc_txq; i++)
1258 vsi->tx_rings[i]->count = new_tx_cnt;
1259 for (i = 0; i < vsi->alloc_rxq; i++)
1260 vsi->rx_rings[i]->count = new_rx_cnt;
1261 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
1265 if (new_tx_cnt == vsi->tx_rings[0]->count)
1268 /* alloc updated Tx resources */
1269 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
1270 vsi->tx_rings[0]->count, new_tx_cnt);
1272 tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_txq,
1273 sizeof(struct ice_ring), GFP_KERNEL);
1279 for (i = 0; i < vsi->alloc_txq; i++) {
1280 /* clone ring and setup updated count */
1281 tx_rings[i] = *vsi->tx_rings[i];
1282 tx_rings[i].count = new_tx_cnt;
1283 tx_rings[i].desc = NULL;
1284 tx_rings[i].tx_buf = NULL;
1285 err = ice_setup_tx_ring(&tx_rings[i]);
1289 ice_clean_tx_ring(&tx_rings[i]);
1291 devm_kfree(&pf->pdev->dev, tx_rings);
1297 if (new_rx_cnt == vsi->rx_rings[0]->count)
1300 /* alloc updated Rx resources */
1301 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
1302 vsi->rx_rings[0]->count, new_rx_cnt);
1304 rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_rxq,
1305 sizeof(struct ice_ring), GFP_KERNEL);
1311 for (i = 0; i < vsi->alloc_rxq; i++) {
1312 /* clone ring and setup updated count */
1313 rx_rings[i] = *vsi->rx_rings[i];
1314 rx_rings[i].count = new_rx_cnt;
1315 rx_rings[i].desc = NULL;
1316 rx_rings[i].rx_buf = NULL;
1317 /* this is to allow wr32 to have something to write to
1318 * during early allocation of Rx buffers
1320 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
1322 err = ice_setup_rx_ring(&rx_rings[i]);
1326 /* allocate Rx buffers */
1327 err = ice_alloc_rx_bufs(&rx_rings[i],
1328 ICE_DESC_UNUSED(&rx_rings[i]));
1333 ice_free_rx_ring(&rx_rings[i]);
1335 devm_kfree(&pf->pdev->dev, rx_rings);
1342 /* Bring interface down, copy in the new ring info, then restore the
1343 * interface. if VSI is up, bring it down and then back up
1345 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
1349 for (i = 0; i < vsi->alloc_txq; i++) {
1350 ice_free_tx_ring(vsi->tx_rings[i]);
1351 *vsi->tx_rings[i] = tx_rings[i];
1353 devm_kfree(&pf->pdev->dev, tx_rings);
1357 for (i = 0; i < vsi->alloc_rxq; i++) {
1358 ice_free_rx_ring(vsi->rx_rings[i]);
1359 /* copy the real tail offset */
1360 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1361 /* this is to fake out the allocation routine
1362 * into thinking it has to realloc everything
1363 * but the recycling logic will let us re-use
1364 * the buffers allocated above
1366 rx_rings[i].next_to_use = 0;
1367 rx_rings[i].next_to_clean = 0;
1368 rx_rings[i].next_to_alloc = 0;
1369 *vsi->rx_rings[i] = rx_rings[i];
1371 devm_kfree(&pf->pdev->dev, rx_rings);
1379 /* error cleanup if the Rx allocations failed after getting Tx */
1381 for (i = 0; i < vsi->alloc_txq; i++)
1382 ice_free_tx_ring(&tx_rings[i]);
1383 devm_kfree(&pf->pdev->dev, tx_rings);
1387 clear_bit(__ICE_CFG_BUSY, pf->state);
1391 static int ice_nway_reset(struct net_device *netdev)
1393 /* restart autonegotiation */
1394 struct ice_netdev_priv *np = netdev_priv(netdev);
1395 struct ice_vsi *vsi = np->vsi;
1396 struct ice_port_info *pi;
1397 enum ice_status status;
1399 pi = vsi->port_info;
1400 /* If VSI state is up, then restart autoneg with link up */
1401 if (!test_bit(__ICE_DOWN, vsi->back->state))
1402 status = ice_aq_set_link_restart_an(pi, true, NULL);
1404 status = ice_aq_set_link_restart_an(pi, false, NULL);
1407 netdev_info(netdev, "link restart failed, err %d aq_err %d\n",
1408 status, pi->hw->adminq.sq_last_status);
1416 * ice_get_pauseparam - Get Flow Control status
1417 * @netdev: network interface device structure
1418 * @pause: ethernet pause (flow control) parameters
1421 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
1423 struct ice_netdev_priv *np = netdev_priv(netdev);
1424 struct ice_port_info *pi;
1426 pi = np->vsi->port_info;
1428 ((pi->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) ?
1429 AUTONEG_ENABLE : AUTONEG_DISABLE);
1431 if (pi->fc.current_mode == ICE_FC_RX_PAUSE) {
1432 pause->rx_pause = 1;
1433 } else if (pi->fc.current_mode == ICE_FC_TX_PAUSE) {
1434 pause->tx_pause = 1;
1435 } else if (pi->fc.current_mode == ICE_FC_FULL) {
1436 pause->rx_pause = 1;
1437 pause->tx_pause = 1;
1442 * ice_set_pauseparam - Set Flow Control parameter
1443 * @netdev: network interface device structure
1444 * @pause: return Tx/Rx flow control status
1447 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
1449 struct ice_netdev_priv *np = netdev_priv(netdev);
1450 struct ice_link_status *hw_link_info;
1451 struct ice_pf *pf = np->vsi->back;
1452 struct ice_vsi *vsi = np->vsi;
1453 struct ice_hw *hw = &pf->hw;
1454 struct ice_port_info *pi;
1455 enum ice_status status;
1460 pi = vsi->port_info;
1461 hw_link_info = &pi->phy.link_info;
1462 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
1464 /* Changing the port's flow control is not supported if this isn't the
1467 if (vsi->type != ICE_VSI_PF) {
1468 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
1472 if (pause->autoneg != (hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
1473 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1477 /* If we have link and don't have autoneg */
1478 if (!test_bit(__ICE_DOWN, pf->state) &&
1479 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
1480 /* Send message that it might not necessarily work*/
1481 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1484 if (pause->rx_pause && pause->tx_pause)
1485 pi->fc.req_mode = ICE_FC_FULL;
1486 else if (pause->rx_pause && !pause->tx_pause)
1487 pi->fc.req_mode = ICE_FC_RX_PAUSE;
1488 else if (!pause->rx_pause && pause->tx_pause)
1489 pi->fc.req_mode = ICE_FC_TX_PAUSE;
1490 else if (!pause->rx_pause && !pause->tx_pause)
1491 pi->fc.req_mode = ICE_FC_NONE;
1495 /* Tell the OS link is going down, the link will go back up when fw
1496 * says it is ready asynchronously
1498 ice_print_link_msg(vsi, false);
1499 netif_carrier_off(netdev);
1500 netif_tx_stop_all_queues(netdev);
1502 /* Set the FC mode and only restart AN if link is up */
1503 status = ice_set_fc(pi, &aq_failures, link_up);
1505 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
1506 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %d\n",
1507 status, hw->adminq.sq_last_status);
1509 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
1510 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %d\n",
1511 status, hw->adminq.sq_last_status);
1513 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
1514 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %d\n",
1515 status, hw->adminq.sq_last_status);
1519 if (!test_bit(__ICE_DOWN, pf->state)) {
1520 /* Give it a little more time to try to come back. If still
1521 * down, restart autoneg link or reinitialize the interface.
1524 if (!test_bit(__ICE_DOWN, pf->state))
1525 return ice_nway_reset(netdev);
1535 * ice_get_rxfh_key_size - get the RSS hash key size
1536 * @netdev: network interface device structure
1538 * Returns the table size.
1540 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
1542 return ICE_VSIQF_HKEY_ARRAY_SIZE;
1546 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
1547 * @netdev: network interface device structure
1549 * Returns the table size.
1551 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
1553 struct ice_netdev_priv *np = netdev_priv(netdev);
1555 return np->vsi->rss_table_size;
1559 * ice_get_rxfh - get the Rx flow hash indirection table
1560 * @netdev: network interface device structure
1561 * @indir: indirection table
1563 * @hfunc: hash function
1565 * Reads the indirection table directly from the hardware.
1568 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
1570 struct ice_netdev_priv *np = netdev_priv(netdev);
1571 struct ice_vsi *vsi = np->vsi;
1572 struct ice_pf *pf = vsi->back;
1577 *hfunc = ETH_RSS_HASH_TOP;
1582 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
1583 /* RSS not supported return error here */
1584 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
1588 lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
1592 if (ice_get_rss(vsi, key, lut, vsi->rss_table_size)) {
1597 for (i = 0; i < vsi->rss_table_size; i++)
1598 indir[i] = (u32)(lut[i]);
1601 devm_kfree(&pf->pdev->dev, lut);
1606 * ice_set_rxfh - set the Rx flow hash indirection table
1607 * @netdev: network interface device structure
1608 * @indir: indirection table
1610 * @hfunc: hash function
1612 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
1613 * returns 0 after programming the table.
1615 static int ice_set_rxfh(struct net_device *netdev, const u32 *indir,
1616 const u8 *key, const u8 hfunc)
1618 struct ice_netdev_priv *np = netdev_priv(netdev);
1619 struct ice_vsi *vsi = np->vsi;
1620 struct ice_pf *pf = vsi->back;
1623 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1626 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
1627 /* RSS not supported return error here */
1628 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
1633 if (!vsi->rss_hkey_user) {
1634 vsi->rss_hkey_user =
1635 devm_kzalloc(&pf->pdev->dev,
1636 ICE_VSIQF_HKEY_ARRAY_SIZE,
1638 if (!vsi->rss_hkey_user)
1641 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
1642 seed = vsi->rss_hkey_user;
1645 if (!vsi->rss_lut_user) {
1646 vsi->rss_lut_user = devm_kzalloc(&pf->pdev->dev,
1647 vsi->rss_table_size,
1649 if (!vsi->rss_lut_user)
1653 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
1657 for (i = 0; i < vsi->rss_table_size; i++)
1658 vsi->rss_lut_user[i] = (u8)(indir[i]);
1660 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
1664 if (ice_set_rss(vsi, seed, vsi->rss_lut_user, vsi->rss_table_size))
1670 static const struct ethtool_ops ice_ethtool_ops = {
1671 .get_link_ksettings = ice_get_link_ksettings,
1672 .set_link_ksettings = ice_set_link_ksettings,
1673 .get_drvinfo = ice_get_drvinfo,
1674 .get_regs_len = ice_get_regs_len,
1675 .get_regs = ice_get_regs,
1676 .get_msglevel = ice_get_msglevel,
1677 .set_msglevel = ice_set_msglevel,
1678 .get_link = ethtool_op_get_link,
1679 .get_strings = ice_get_strings,
1680 .get_ethtool_stats = ice_get_ethtool_stats,
1681 .get_sset_count = ice_get_sset_count,
1682 .get_rxnfc = ice_get_rxnfc,
1683 .get_ringparam = ice_get_ringparam,
1684 .set_ringparam = ice_set_ringparam,
1685 .nway_reset = ice_nway_reset,
1686 .get_pauseparam = ice_get_pauseparam,
1687 .set_pauseparam = ice_set_pauseparam,
1688 .get_rxfh_key_size = ice_get_rxfh_key_size,
1689 .get_rxfh_indir_size = ice_get_rxfh_indir_size,
1690 .get_rxfh = ice_get_rxfh,
1691 .set_rxfh = ice_set_rxfh,
1695 * ice_set_ethtool_ops - setup netdev ethtool ops
1696 * @netdev: network interface device structure
1698 * setup netdev ethtool ops with ice specific ops
1700 void ice_set_ethtool_ops(struct net_device *netdev)
1702 netdev->ethtool_ops = &ice_ethtool_ops;