Linux Audio

Check our new training course

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