File Index
Files and directories
Sign in
FILE

ice_ethtool.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/ethernet/intel/ice/ice_ethtool.c C
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright (c) 2018, Intel Corporation. */
   3
   4/* ethtool support for ice */
   5
   6#include "ice.h"
   7#include "ice_ethtool.h"
   8#include "ice_flow.h"
   9#include "ice_fltr.h"
  10#include "ice_lib.h"
  11#include "ice_dcb_lib.h"
  12#include <net/dcbnl.h>
  13#include <net/libeth/rx.h>
  14
  15struct ice_stats {
  16	char stat_string[ETH_GSTRING_LEN];
  17	int sizeof_stat;
  18	int stat_offset;
  19};
  20
  21#define ICE_STAT(_type, _name, _stat) { \
  22	.stat_string = _name, \
  23	.sizeof_stat = sizeof_field(_type, _stat), \
  24	.stat_offset = offsetof(_type, _stat) \
  25}
  26
  27#define ICE_VSI_STAT(_name, _stat) \
  28		ICE_STAT(struct ice_vsi, _name, _stat)
  29#define ICE_PF_STAT(_name, _stat) \
  30		ICE_STAT(struct ice_pf, _name, _stat)
  31
  32static int ice_q_stats_len(struct net_device *netdev)
  33{
  34	struct ice_netdev_priv *np = netdev_priv(netdev);
  35
  36	return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
  37		(sizeof(struct ice_q_stats) / sizeof(u64)));
  38}
  39
  40#define ICE_PF_STATS_LEN	ARRAY_SIZE(ice_gstrings_pf_stats)
  41#define ICE_VSI_STATS_LEN	ARRAY_SIZE(ice_gstrings_vsi_stats)
  42
  43#define ICE_PFC_STATS_LEN ( \
  44		(sizeof_field(struct ice_pf, stats.priority_xoff_rx) + \
  45		 sizeof_field(struct ice_pf, stats.priority_xon_rx) + \
  46		 sizeof_field(struct ice_pf, stats.priority_xoff_tx) + \
  47		 sizeof_field(struct ice_pf, stats.priority_xon_tx)) \
  48		 / sizeof(u64))
  49#define ICE_ALL_STATS_LEN(n)	(ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
  50				 ICE_VSI_STATS_LEN + ice_q_stats_len(n))
  51
  52static const struct ice_stats ice_gstrings_vsi_stats[] = {
  53	ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
  54	ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
  55	ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
  56	ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
  57	ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
  58	ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
  59	ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
  60	ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
  61	ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards),
  62	ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
  63	ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
  64	ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
  65	ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
  66	ICE_VSI_STAT("tx_linearize", tx_linearize),
  67	ICE_VSI_STAT("tx_busy", tx_busy),
  68	ICE_VSI_STAT("tx_restart", tx_restart),
  69};
  70
  71enum ice_ethtool_test_id {
  72	ICE_ETH_TEST_REG = 0,
  73	ICE_ETH_TEST_EEPROM,
  74	ICE_ETH_TEST_INTR,
  75	ICE_ETH_TEST_LOOP,
  76	ICE_ETH_TEST_LINK,
  77};
  78
  79static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
  80	"Register test  (offline)",
  81	"EEPROM test    (offline)",
  82	"Interrupt test (offline)",
  83	"Loopback test  (offline)",
  84	"Link test   (on/offline)",
  85};
  86
  87#define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
  88
  89/* These PF_STATs might look like duplicates of some NETDEV_STATs,
  90 * but they aren't. This device is capable of supporting multiple
  91 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
  92 * netdevs whereas the PF_STATs are for the physical function that's
  93 * hosting these netdevs.
  94 *
  95 * The PF_STATs are appended to the netdev stats only when ethtool -S
  96 * is queried on the base PF netdev.
  97 */
  98static const struct ice_stats ice_gstrings_pf_stats[] = {
  99	ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
 100	ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
 101	ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
 102	ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
 103	ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
 104	ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
 105	ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
 106	ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
 107	ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
 108	ICE_PF_STAT("tx_timeout.nic", tx_timeout_count),
 109	ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
 110	ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
 111	ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
 112	ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
 113	ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
 114	ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
 115	ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
 116	ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
 117	ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
 118	ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
 119	ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
 120	ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
 121	ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
 122	ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
 123	ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
 124	ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
 125	ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
 126	ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
 127	ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
 128	ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
 129	ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
 130	ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
 131	ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
 132	ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
 133	ICE_PF_STAT("rx_eipe_error.nic", hw_rx_eipe_error),
 134	ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
 135	ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
 136	ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
 137	ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
 138	ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
 139	ICE_PF_STAT("fdir_sb_match.nic", stats.fd_sb_match),
 140	ICE_PF_STAT("fdir_sb_status.nic", stats.fd_sb_status),
 141	ICE_PF_STAT("tx_hwtstamp_skipped", ptp.tx_hwtstamp_skipped),
 142	ICE_PF_STAT("tx_hwtstamp_timeouts", ptp.tx_hwtstamp_timeouts),
 143	ICE_PF_STAT("tx_hwtstamp_flushed", ptp.tx_hwtstamp_flushed),
 144	ICE_PF_STAT("tx_hwtstamp_discarded", ptp.tx_hwtstamp_discarded),
 145	ICE_PF_STAT("late_cached_phc_updates", ptp.late_cached_phc_updates),
 146};
 147
 148static const u32 ice_regs_dump_list[] = {
 149	PFGEN_STATE,
 150	PRTGEN_STATUS,
 151	QRX_CTRL(0),
 152	QINT_TQCTL(0),
 153	QINT_RQCTL(0),
 154	PFINT_OICR_ENA,
 155	QRX_ITR(0),
 156#define GLDCB_TLPM_PCI_DM			0x000A0180
 157	GLDCB_TLPM_PCI_DM,
 158#define GLDCB_TLPM_TC2PFC			0x000A0194
 159	GLDCB_TLPM_TC2PFC,
 160#define TCDCB_TLPM_WAIT_DM(_i)			(0x000A0080 + ((_i) * 4))
 161	TCDCB_TLPM_WAIT_DM(0),
 162	TCDCB_TLPM_WAIT_DM(1),
 163	TCDCB_TLPM_WAIT_DM(2),
 164	TCDCB_TLPM_WAIT_DM(3),
 165	TCDCB_TLPM_WAIT_DM(4),
 166	TCDCB_TLPM_WAIT_DM(5),
 167	TCDCB_TLPM_WAIT_DM(6),
 168	TCDCB_TLPM_WAIT_DM(7),
 169	TCDCB_TLPM_WAIT_DM(8),
 170	TCDCB_TLPM_WAIT_DM(9),
 171	TCDCB_TLPM_WAIT_DM(10),
 172	TCDCB_TLPM_WAIT_DM(11),
 173	TCDCB_TLPM_WAIT_DM(12),
 174	TCDCB_TLPM_WAIT_DM(13),
 175	TCDCB_TLPM_WAIT_DM(14),
 176	TCDCB_TLPM_WAIT_DM(15),
 177	TCDCB_TLPM_WAIT_DM(16),
 178	TCDCB_TLPM_WAIT_DM(17),
 179	TCDCB_TLPM_WAIT_DM(18),
 180	TCDCB_TLPM_WAIT_DM(19),
 181	TCDCB_TLPM_WAIT_DM(20),
 182	TCDCB_TLPM_WAIT_DM(21),
 183	TCDCB_TLPM_WAIT_DM(22),
 184	TCDCB_TLPM_WAIT_DM(23),
 185	TCDCB_TLPM_WAIT_DM(24),
 186	TCDCB_TLPM_WAIT_DM(25),
 187	TCDCB_TLPM_WAIT_DM(26),
 188	TCDCB_TLPM_WAIT_DM(27),
 189	TCDCB_TLPM_WAIT_DM(28),
 190	TCDCB_TLPM_WAIT_DM(29),
 191	TCDCB_TLPM_WAIT_DM(30),
 192	TCDCB_TLPM_WAIT_DM(31),
 193#define GLPCI_WATMK_CLNT_PIPEMON		0x000BFD90
 194	GLPCI_WATMK_CLNT_PIPEMON,
 195#define GLPCI_CUR_CLNT_COMMON			0x000BFD84
 196	GLPCI_CUR_CLNT_COMMON,
 197#define GLPCI_CUR_CLNT_PIPEMON			0x000BFD88
 198	GLPCI_CUR_CLNT_PIPEMON,
 199#define GLPCI_PCIERR				0x0009DEB0
 200	GLPCI_PCIERR,
 201#define GLPSM_DEBUG_CTL_STATUS			0x000B0600
 202	GLPSM_DEBUG_CTL_STATUS,
 203#define GLPSM0_DEBUG_FIFO_OVERFLOW_DETECT	0x000B0680
 204	GLPSM0_DEBUG_FIFO_OVERFLOW_DETECT,
 205#define GLPSM0_DEBUG_FIFO_UNDERFLOW_DETECT	0x000B0684
 206	GLPSM0_DEBUG_FIFO_UNDERFLOW_DETECT,
 207#define GLPSM0_DEBUG_DT_OUT_OF_WINDOW		0x000B0688
 208	GLPSM0_DEBUG_DT_OUT_OF_WINDOW,
 209#define GLPSM0_DEBUG_INTF_HW_ERROR_DETECT	0x000B069C
 210	GLPSM0_DEBUG_INTF_HW_ERROR_DETECT,
 211#define GLPSM0_DEBUG_MISC_HW_ERROR_DETECT	0x000B06A0
 212	GLPSM0_DEBUG_MISC_HW_ERROR_DETECT,
 213#define GLPSM1_DEBUG_FIFO_OVERFLOW_DETECT	0x000B0E80
 214	GLPSM1_DEBUG_FIFO_OVERFLOW_DETECT,
 215#define GLPSM1_DEBUG_FIFO_UNDERFLOW_DETECT	0x000B0E84
 216	GLPSM1_DEBUG_FIFO_UNDERFLOW_DETECT,
 217#define GLPSM1_DEBUG_SRL_FIFO_OVERFLOW_DETECT	0x000B0E88
 218	GLPSM1_DEBUG_SRL_FIFO_OVERFLOW_DETECT,
 219#define GLPSM1_DEBUG_SRL_FIFO_UNDERFLOW_DETECT  0x000B0E8C
 220	GLPSM1_DEBUG_SRL_FIFO_UNDERFLOW_DETECT,
 221#define GLPSM1_DEBUG_MISC_HW_ERROR_DETECT       0x000B0E90
 222	GLPSM1_DEBUG_MISC_HW_ERROR_DETECT,
 223#define GLPSM2_DEBUG_FIFO_OVERFLOW_DETECT       0x000B1680
 224	GLPSM2_DEBUG_FIFO_OVERFLOW_DETECT,
 225#define GLPSM2_DEBUG_FIFO_UNDERFLOW_DETECT      0x000B1684
 226	GLPSM2_DEBUG_FIFO_UNDERFLOW_DETECT,
 227#define GLPSM2_DEBUG_MISC_HW_ERROR_DETECT       0x000B1688
 228	GLPSM2_DEBUG_MISC_HW_ERROR_DETECT,
 229#define GLTDPU_TCLAN_COMP_BOB(_i)               (0x00049ADC + ((_i) * 4))
 230	GLTDPU_TCLAN_COMP_BOB(1),
 231	GLTDPU_TCLAN_COMP_BOB(2),
 232	GLTDPU_TCLAN_COMP_BOB(3),
 233	GLTDPU_TCLAN_COMP_BOB(4),
 234	GLTDPU_TCLAN_COMP_BOB(5),
 235	GLTDPU_TCLAN_COMP_BOB(6),
 236	GLTDPU_TCLAN_COMP_BOB(7),
 237	GLTDPU_TCLAN_COMP_BOB(8),
 238#define GLTDPU_TCB_CMD_BOB(_i)                  (0x0004975C + ((_i) * 4))
 239	GLTDPU_TCB_CMD_BOB(1),
 240	GLTDPU_TCB_CMD_BOB(2),
 241	GLTDPU_TCB_CMD_BOB(3),
 242	GLTDPU_TCB_CMD_BOB(4),
 243	GLTDPU_TCB_CMD_BOB(5),
 244	GLTDPU_TCB_CMD_BOB(6),
 245	GLTDPU_TCB_CMD_BOB(7),
 246	GLTDPU_TCB_CMD_BOB(8),
 247#define GLTDPU_PSM_UPDATE_BOB(_i)               (0x00049B5C + ((_i) * 4))
 248	GLTDPU_PSM_UPDATE_BOB(1),
 249	GLTDPU_PSM_UPDATE_BOB(2),
 250	GLTDPU_PSM_UPDATE_BOB(3),
 251	GLTDPU_PSM_UPDATE_BOB(4),
 252	GLTDPU_PSM_UPDATE_BOB(5),
 253	GLTDPU_PSM_UPDATE_BOB(6),
 254	GLTDPU_PSM_UPDATE_BOB(7),
 255	GLTDPU_PSM_UPDATE_BOB(8),
 256#define GLTCB_CMD_IN_BOB(_i)                    (0x000AE288 + ((_i) * 4))
 257	GLTCB_CMD_IN_BOB(1),
 258	GLTCB_CMD_IN_BOB(2),
 259	GLTCB_CMD_IN_BOB(3),
 260	GLTCB_CMD_IN_BOB(4),
 261	GLTCB_CMD_IN_BOB(5),
 262	GLTCB_CMD_IN_BOB(6),
 263	GLTCB_CMD_IN_BOB(7),
 264	GLTCB_CMD_IN_BOB(8),
 265#define GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(_i)   (0x000FC148 + ((_i) * 4))
 266	GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(1),
 267	GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(2),
 268	GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(3),
 269	GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(4),
 270	GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(5),
 271	GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(6),
 272	GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(7),
 273	GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(8),
 274#define GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(_i) (0x000FC248 + ((_i) * 4))
 275	GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(1),
 276	GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(2),
 277	GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(3),
 278	GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(4),
 279	GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(5),
 280	GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(6),
 281	GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(7),
 282	GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(8),
 283#define GLLAN_TCLAN_CACHE_CTL_BOB_CTL(_i)       (0x000FC1C8 + ((_i) * 4))
 284	GLLAN_TCLAN_CACHE_CTL_BOB_CTL(1),
 285	GLLAN_TCLAN_CACHE_CTL_BOB_CTL(2),
 286	GLLAN_TCLAN_CACHE_CTL_BOB_CTL(3),
 287	GLLAN_TCLAN_CACHE_CTL_BOB_CTL(4),
 288	GLLAN_TCLAN_CACHE_CTL_BOB_CTL(5),
 289	GLLAN_TCLAN_CACHE_CTL_BOB_CTL(6),
 290	GLLAN_TCLAN_CACHE_CTL_BOB_CTL(7),
 291	GLLAN_TCLAN_CACHE_CTL_BOB_CTL(8),
 292#define GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(_i)  (0x000FC188 + ((_i) * 4))
 293	GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(1),
 294	GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(2),
 295	GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(3),
 296	GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(4),
 297	GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(5),
 298	GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(6),
 299	GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(7),
 300	GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(8),
 301#define GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(_i) (0x000FC288 + ((_i) * 4))
 302	GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(1),
 303	GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(2),
 304	GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(3),
 305	GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(4),
 306	GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(5),
 307	GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(6),
 308	GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(7),
 309	GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(8),
 310#define PRTDCB_TCUPM_REG_CM(_i)			(0x000BC360 + ((_i) * 4))
 311	PRTDCB_TCUPM_REG_CM(0),
 312	PRTDCB_TCUPM_REG_CM(1),
 313	PRTDCB_TCUPM_REG_CM(2),
 314	PRTDCB_TCUPM_REG_CM(3),
 315#define PRTDCB_TCUPM_REG_DM(_i)			(0x000BC3A0 + ((_i) * 4))
 316	PRTDCB_TCUPM_REG_DM(0),
 317	PRTDCB_TCUPM_REG_DM(1),
 318	PRTDCB_TCUPM_REG_DM(2),
 319	PRTDCB_TCUPM_REG_DM(3),
 320#define PRTDCB_TLPM_REG_DM(_i)			(0x000A0000 + ((_i) * 4))
 321	PRTDCB_TLPM_REG_DM(0),
 322	PRTDCB_TLPM_REG_DM(1),
 323	PRTDCB_TLPM_REG_DM(2),
 324	PRTDCB_TLPM_REG_DM(3),
 325};
 326
 327struct ice_priv_flag {
 328	char name[ETH_GSTRING_LEN];
 329	u32 bitno;			/* bit position in pf->flags */
 330};
 331
 332#define ICE_PRIV_FLAG(_name, _bitno) { \
 333	.name = _name, \
 334	.bitno = _bitno, \
 335}
 336
 337static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
 338	ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
 339	ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
 340	ICE_PRIV_FLAG("vf-true-promisc-support",
 341		      ICE_FLAG_VF_TRUE_PROMISC_ENA),
 342	ICE_PRIV_FLAG("mdd-auto-reset-vf", ICE_FLAG_MDD_AUTO_RESET_VF),
 343	ICE_PRIV_FLAG("vf-vlan-pruning", ICE_FLAG_VF_VLAN_PRUNING),
 344};
 345
 346#define ICE_PRIV_FLAG_ARRAY_SIZE	ARRAY_SIZE(ice_gstrings_priv_flags)
 347
 348static const u32 ice_adv_lnk_speed_100[] __initconst = {
 349	ETHTOOL_LINK_MODE_100baseT_Full_BIT,
 350};
 351
 352static const u32 ice_adv_lnk_speed_1000[] __initconst = {
 353	ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
 354	ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
 355	ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
 356};
 357
 358static const u32 ice_adv_lnk_speed_2500[] __initconst = {
 359	ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
 360	ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
 361};
 362
 363static const u32 ice_adv_lnk_speed_5000[] __initconst = {
 364	ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
 365};
 366
 367static const u32 ice_adv_lnk_speed_10000[] __initconst = {
 368	ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
 369	ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
 370	ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
 371	ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
 372};
 373
 374static const u32 ice_adv_lnk_speed_25000[] __initconst = {
 375	ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
 376	ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
 377	ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
 378};
 379
 380static const u32 ice_adv_lnk_speed_40000[] __initconst = {
 381	ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
 382	ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
 383	ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
 384	ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
 385};
 386
 387static const u32 ice_adv_lnk_speed_50000[] __initconst = {
 388	ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
 389	ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
 390	ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
 391};
 392
 393static const u32 ice_adv_lnk_speed_100000[] __initconst = {
 394	ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
 395	ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
 396	ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
 397	ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
 398	ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT,
 399	ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT,
 400	ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT,
 401};
 402
 403static const u32 ice_adv_lnk_speed_200000[] __initconst = {
 404	ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT,
 405	ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT,
 406	ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT,
 407	ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT,
 408	ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT,
 409};
 410
 411static struct ethtool_forced_speed_map ice_adv_lnk_speed_maps[] __ro_after_init = {
 412	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 100),
 413	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 1000),
 414	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 2500),
 415	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 5000),
 416	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 10000),
 417	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 25000),
 418	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 40000),
 419	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 50000),
 420	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 100000),
 421	ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 200000),
 422};
 423
 424void __init ice_adv_lnk_speed_maps_init(void)
 425{
 426	ethtool_forced_speed_maps_init(ice_adv_lnk_speed_maps,
 427				       ARRAY_SIZE(ice_adv_lnk_speed_maps));
 428}
 429
 430static void
 431__ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo,
 432		  struct ice_vsi *vsi)
 433{
 434	struct ice_pf *pf = vsi->back;
 435	struct ice_hw *hw = &pf->hw;
 436	struct ice_orom_info *orom;
 437	struct ice_nvm_info *nvm;
 438
 439	nvm = &hw->flash.nvm;
 440	orom = &hw->flash.orom;
 441
 442	strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
 443
 444	/* Display NVM version (from which the firmware version can be
 445	 * determined) which contains more pertinent information.
 446	 */
 447	snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
 448		 "%x.%02x 0x%x %d.%d.%d", nvm->major, nvm->minor,
 449		 nvm->eetrack, orom->major, orom->build, orom->patch);
 450
 451	strscpy(drvinfo->bus_info, pci_name(pf->pdev),
 452		sizeof(drvinfo->bus_info));
 453}
 454
 455static void
 456ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
 457{
 458	struct ice_netdev_priv *np = netdev_priv(netdev);
 459
 460	__ice_get_drvinfo(netdev, drvinfo, np->vsi);
 461	drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
 462}
 463
 464static int ice_get_regs_len(struct net_device __always_unused *netdev)
 465{
 466	return (sizeof(ice_regs_dump_list) +
 467		sizeof(struct ice_regdump_to_ethtool));
 468}
 469
 470/**
 471 * ice_ethtool_get_maxspeed - Get the max speed for given lport
 472 * @hw: pointer to the HW struct
 473 * @lport: logical port for which max speed is requested
 474 * @max_speed: return max speed for input lport
 475 *
 476 * Return: 0 on success, negative on failure.
 477 */
 478static int ice_ethtool_get_maxspeed(struct ice_hw *hw, u8 lport, u8 *max_speed)
 479{
 480	struct ice_aqc_get_port_options_elem options[ICE_AQC_PORT_OPT_MAX] = {};
 481	bool active_valid = false, pending_valid = true;
 482	u8 option_count = ICE_AQC_PORT_OPT_MAX;
 483	u8 active_idx = 0, pending_idx = 0;
 484	int status;
 485
 486	status = ice_aq_get_port_options(hw, options, &option_count, lport,
 487					 true, &active_idx, &active_valid,
 488					 &pending_idx, &pending_valid);
 489	if (status)
 490		return -EIO;
 491	if (!active_valid)
 492		return -EINVAL;
 493
 494	*max_speed = options[active_idx].max_lane_speed & ICE_AQC_PORT_OPT_MAX_LANE_M;
 495	return 0;
 496}
 497
 498/**
 499 * ice_is_serdes_muxed - returns whether serdes is muxed in hardware
 500 * @hw: pointer to the HW struct
 501 *
 502 * Return: true when serdes is muxed, false when serdes is not muxed.
 503 */
 504static bool ice_is_serdes_muxed(struct ice_hw *hw)
 505{
 506	u32 reg_value = rd32(hw, GLGEN_SWITCH_MODE_CONFIG);
 507
 508	return FIELD_GET(GLGEN_SWITCH_MODE_CONFIG_25X4_QUAD_M, reg_value);
 509}
 510
 511static int ice_map_port_topology_for_sfp(struct ice_port_topology *port_topology,
 512					 u8 lport, bool is_muxed)
 513{
 514	switch (lport) {
 515	case 0:
 516		port_topology->pcs_quad_select = 0;
 517		port_topology->pcs_port = 0;
 518		port_topology->primary_serdes_lane = 0;
 519		break;
 520	case 1:
 521		port_topology->pcs_quad_select = 1;
 522		port_topology->pcs_port = 0;
 523		if (is_muxed)
 524			port_topology->primary_serdes_lane = 2;
 525		else
 526			port_topology->primary_serdes_lane = 4;
 527		break;
 528	case 2:
 529		port_topology->pcs_quad_select = 0;
 530		port_topology->pcs_port = 1;
 531		port_topology->primary_serdes_lane = 1;
 532		break;
 533	case 3:
 534		port_topology->pcs_quad_select = 1;
 535		port_topology->pcs_port = 1;
 536		if (is_muxed)
 537			port_topology->primary_serdes_lane = 3;
 538		else
 539			port_topology->primary_serdes_lane = 5;
 540		break;
 541	case 4:
 542		port_topology->pcs_quad_select = 0;
 543		port_topology->pcs_port = 2;
 544		port_topology->primary_serdes_lane = 2;
 545		break;
 546	case 5:
 547		port_topology->pcs_quad_select = 1;
 548		port_topology->pcs_port = 2;
 549		port_topology->primary_serdes_lane = 6;
 550		break;
 551	case 6:
 552		port_topology->pcs_quad_select = 0;
 553		port_topology->pcs_port = 3;
 554		port_topology->primary_serdes_lane = 3;
 555		break;
 556	case 7:
 557		port_topology->pcs_quad_select = 1;
 558		port_topology->pcs_port = 3;
 559		port_topology->primary_serdes_lane = 7;
 560		break;
 561	default:
 562		return -EINVAL;
 563	}
 564
 565	return 0;
 566}
 567
 568static int ice_map_port_topology_for_qsfp(struct ice_port_topology *port_topology,
 569					  u8 lport, bool is_muxed)
 570{
 571	switch (lport) {
 572	case 0:
 573		port_topology->pcs_quad_select = 0;
 574		port_topology->pcs_port = 0;
 575		port_topology->primary_serdes_lane = 0;
 576		break;
 577	case 1:
 578		port_topology->pcs_quad_select = 1;
 579		port_topology->pcs_port = 0;
 580		if (is_muxed)
 581			port_topology->primary_serdes_lane = 2;
 582		else
 583			port_topology->primary_serdes_lane = 4;
 584		break;
 585	case 2:
 586		port_topology->pcs_quad_select = 0;
 587		port_topology->pcs_port = 1;
 588		port_topology->primary_serdes_lane = 1;
 589		break;
 590	case 3:
 591		port_topology->pcs_quad_select = 1;
 592		port_topology->pcs_port = 1;
 593		if (is_muxed)
 594			port_topology->primary_serdes_lane = 3;
 595		else
 596			port_topology->primary_serdes_lane = 5;
 597		break;
 598	case 4:
 599		port_topology->pcs_quad_select = 0;
 600		port_topology->pcs_port = 2;
 601		port_topology->primary_serdes_lane = 2;
 602		break;
 603	case 5:
 604		port_topology->pcs_quad_select = 1;
 605		port_topology->pcs_port = 2;
 606		port_topology->primary_serdes_lane = 6;
 607		break;
 608	case 6:
 609		port_topology->pcs_quad_select = 0;
 610		port_topology->pcs_port = 3;
 611		port_topology->primary_serdes_lane = 3;
 612		break;
 613	case 7:
 614		port_topology->pcs_quad_select = 1;
 615		port_topology->pcs_port = 3;
 616		port_topology->primary_serdes_lane = 7;
 617		break;
 618	default:
 619		return -EINVAL;
 620	}
 621
 622	return 0;
 623}
 624
 625/**
 626 * ice_get_port_topology - returns physical topology like pcsquad, pcsport,
 627 *                         serdes number
 628 * @hw: pointer to the HW struct
 629 * @lport: logical port for which physical info requested
 630 * @port_topology: buffer to hold port topology
 631 *
 632 * Return: 0 on success, negative on failure.
 633 */
 634static int ice_get_port_topology(struct ice_hw *hw, u8 lport,
 635				 struct ice_port_topology *port_topology)
 636{
 637	struct ice_aqc_get_link_topo cmd = {};
 638	u16 node_handle = 0;
 639	u8 cage_type = 0;
 640	bool is_muxed;
 641	int err;
 642	u8 ctx;
 643
 644	ctx = ICE_AQC_LINK_TOPO_NODE_TYPE_CAGE << ICE_AQC_LINK_TOPO_NODE_TYPE_S;
 645	ctx |= ICE_AQC_LINK_TOPO_NODE_CTX_PORT << ICE_AQC_LINK_TOPO_NODE_CTX_S;
 646	cmd.addr.topo_params.node_type_ctx = ctx;
 647
 648	err = ice_aq_get_netlist_node(hw, &cmd, &cage_type, &node_handle);
 649	if (err)
 650		return -EINVAL;
 651
 652	is_muxed = ice_is_serdes_muxed(hw);
 653
 654	if (cage_type == 0x11 ||	/* SFP+ */
 655	    cage_type == 0x12) {	/* SFP28 */
 656		port_topology->serdes_lane_count = 1;
 657		err = ice_map_port_topology_for_sfp(port_topology, lport, is_muxed);
 658		if (err)
 659			return err;
 660	} else if (cage_type == 0x13 ||	/* QSFP */
 661		   cage_type == 0x14) {	/* QSFP28 */
 662		u8 max_speed = 0;
 663
 664		err = ice_ethtool_get_maxspeed(hw, lport, &max_speed);
 665		if (err)
 666			return err;
 667
 668		if (max_speed == ICE_AQC_PORT_OPT_MAX_LANE_100G)
 669			port_topology->serdes_lane_count = 4;
 670		else if (max_speed == ICE_AQC_PORT_OPT_MAX_LANE_50G ||
 671			 max_speed == ICE_AQC_PORT_OPT_MAX_LANE_40G)
 672			port_topology->serdes_lane_count = 2;
 673		else
 674			port_topology->serdes_lane_count = 1;
 675
 676		err = ice_map_port_topology_for_qsfp(port_topology, lport, is_muxed);
 677		if (err)
 678			return err;
 679	} else {
 680		return -EINVAL;
 681	}
 682
 683	return 0;
 684}
 685
 686/**
 687 * ice_get_tx_rx_equa - read serdes tx rx equaliser param
 688 * @hw: pointer to the HW struct
 689 * @serdes_num: represents the serdes number
 690 * @ptr: structure to read all serdes parameter for given serdes
 691 *
 692 * Return: all serdes equalization parameter supported per serdes number
 693 */
 694static int ice_get_tx_rx_equa(struct ice_hw *hw, u8 serdes_num,
 695			      struct ice_serdes_equalization_to_ethtool *ptr)
 696{
 697	static const int tx = ICE_AQC_OP_CODE_TX_EQU;
 698	static const int rx = ICE_AQC_OP_CODE_RX_EQU;
 699	struct {
 700		int data_in;
 701		int opcode;
 702		int *out;
 703	} aq_params[] = {
 704		{ ICE_AQC_TX_EQU_PRE1, tx, &ptr->tx_equ_pre1 },
 705		{ ICE_AQC_TX_EQU_PRE3, tx, &ptr->tx_equ_pre3 },
 706		{ ICE_AQC_TX_EQU_ATTEN, tx, &ptr->tx_equ_atten },
 707		{ ICE_AQC_TX_EQU_POST1, tx, &ptr->tx_equ_post1 },
 708		{ ICE_AQC_TX_EQU_PRE2, tx, &ptr->tx_equ_pre2 },
 709		{ ICE_AQC_RX_EQU_PRE2, rx, &ptr->rx_equ_pre2 },
 710		{ ICE_AQC_RX_EQU_PRE1, rx, &ptr->rx_equ_pre1 },
 711		{ ICE_AQC_RX_EQU_POST1, rx, &ptr->rx_equ_post1 },
 712		{ ICE_AQC_RX_EQU_BFLF, rx, &ptr->rx_equ_bflf },
 713		{ ICE_AQC_RX_EQU_BFHF, rx, &ptr->rx_equ_bfhf },
 714		{ ICE_AQC_RX_EQU_CTLE_GAINHF, rx, &ptr->rx_equ_ctle_gainhf },
 715		{ ICE_AQC_RX_EQU_CTLE_GAINLF, rx, &ptr->rx_equ_ctle_gainlf },
 716		{ ICE_AQC_RX_EQU_CTLE_GAINDC, rx, &ptr->rx_equ_ctle_gaindc },
 717		{ ICE_AQC_RX_EQU_CTLE_BW, rx, &ptr->rx_equ_ctle_bw },
 718		{ ICE_AQC_RX_EQU_DFE_GAIN, rx, &ptr->rx_equ_dfe_gain },
 719		{ ICE_AQC_RX_EQU_DFE_GAIN2, rx, &ptr->rx_equ_dfe_gain_2 },
 720		{ ICE_AQC_RX_EQU_DFE_2, rx, &ptr->rx_equ_dfe_2 },
 721		{ ICE_AQC_RX_EQU_DFE_3, rx, &ptr->rx_equ_dfe_3 },
 722		{ ICE_AQC_RX_EQU_DFE_4, rx, &ptr->rx_equ_dfe_4 },
 723		{ ICE_AQC_RX_EQU_DFE_5, rx, &ptr->rx_equ_dfe_5 },
 724		{ ICE_AQC_RX_EQU_DFE_6, rx, &ptr->rx_equ_dfe_6 },
 725		{ ICE_AQC_RX_EQU_DFE_7, rx, &ptr->rx_equ_dfe_7 },
 726		{ ICE_AQC_RX_EQU_DFE_8, rx, &ptr->rx_equ_dfe_8 },
 727		{ ICE_AQC_RX_EQU_DFE_9, rx, &ptr->rx_equ_dfe_9 },
 728		{ ICE_AQC_RX_EQU_DFE_10, rx, &ptr->rx_equ_dfe_10 },
 729		{ ICE_AQC_RX_EQU_DFE_11, rx, &ptr->rx_equ_dfe_11 },
 730		{ ICE_AQC_RX_EQU_DFE_12, rx, &ptr->rx_equ_dfe_12 },
 731	};
 732	int err;
 733
 734	for (int i = 0; i < ARRAY_SIZE(aq_params); i++) {
 735		err = ice_aq_get_phy_equalization(hw, aq_params[i].data_in,
 736						  aq_params[i].opcode,
 737						  serdes_num, aq_params[i].out);
 738		if (err)
 739			break;
 740	}
 741
 742	return err;
 743}
 744
 745/**
 746 * ice_get_extended_regs - returns FEC correctable, uncorrectable stats per
 747 *                         pcsquad, pcsport
 748 * @netdev: pointer to net device structure
 749 * @p: output buffer to fill requested register dump
 750 *
 751 * Return: 0 on success, negative on failure.
 752 */
 753static int ice_get_extended_regs(struct net_device *netdev, void *p)
 754{
 755	struct ice_netdev_priv *np = netdev_priv(netdev);
 756	struct ice_regdump_to_ethtool *ice_prv_regs_buf;
 757	struct ice_port_topology port_topology = {};
 758	struct ice_port_info *pi;
 759	struct ice_pf *pf;
 760	struct ice_hw *hw;
 761	unsigned int i;
 762	int err;
 763
 764	pf = np->vsi->back;
 765	hw = &pf->hw;
 766	pi = np->vsi->port_info;
 767
 768	/* Serdes parameters are not supported if not the PF VSI */
 769	if (np->vsi->type != ICE_VSI_PF || !pi)
 770		return -EINVAL;
 771
 772	err = ice_get_port_topology(hw, pi->lport, &port_topology);
 773	if (err)
 774		return -EINVAL;
 775	if (port_topology.serdes_lane_count > 4)
 776		return -EINVAL;
 777
 778	ice_prv_regs_buf = p;
 779
 780	/* Get serdes equalization parameter for available serdes */
 781	for (i = 0; i < port_topology.serdes_lane_count; i++) {
 782		u8 serdes_num = 0;
 783
 784		serdes_num = port_topology.primary_serdes_lane + i;
 785		err = ice_get_tx_rx_equa(hw, serdes_num,
 786					 &ice_prv_regs_buf->equalization[i]);
 787		if (err)
 788			return -EINVAL;
 789	}
 790
 791	return 0;
 792}
 793
 794static void
 795ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
 796{
 797	struct ice_pf *pf = ice_netdev_to_pf(netdev);
 798	struct ice_hw *hw = &pf->hw;
 799	u32 *regs_buf = (u32 *)p;
 800	unsigned int i;
 801
 802	regs->version = 2;
 803
 804	for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
 805		regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
 806
 807	ice_get_extended_regs(netdev, (void *)&regs_buf[i]);
 808}
 809
 810static u32 ice_get_msglevel(struct net_device *netdev)
 811{
 812	struct ice_pf *pf = ice_netdev_to_pf(netdev);
 813
 814#ifndef CONFIG_DYNAMIC_DEBUG
 815	if (pf->hw.debug_mask)
 816		netdev_info(netdev, "hw debug_mask: 0x%llX\n",
 817			    pf->hw.debug_mask);
 818#endif /* !CONFIG_DYNAMIC_DEBUG */
 819
 820	return pf->msg_enable;
 821}
 822
 823static void ice_set_msglevel(struct net_device *netdev, u32 data)
 824{
 825	struct ice_pf *pf = ice_netdev_to_pf(netdev);
 826
 827#ifndef CONFIG_DYNAMIC_DEBUG
 828	if (ICE_DBG_USER & data)
 829		pf->hw.debug_mask = data;
 830	else
 831		pf->msg_enable = data;
 832#else
 833	pf->msg_enable = data;
 834#endif /* !CONFIG_DYNAMIC_DEBUG */
 835}
 836
 837static void ice_get_link_ext_stats(struct net_device *netdev,
 838				   struct ethtool_link_ext_stats *stats)
 839{
 840	struct ice_pf *pf = ice_netdev_to_pf(netdev);
 841
 842	stats->link_down_events = pf->link_down_events;
 843}
 844
 845static int ice_get_eeprom_len(struct net_device *netdev)
 846{
 847	struct ice_pf *pf = ice_netdev_to_pf(netdev);
 848
 849	return (int)pf->hw.flash.flash_size;
 850}
 851
 852static int
 853ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
 854	       u8 *bytes)
 855{
 856	struct ice_pf *pf = ice_netdev_to_pf(netdev);
 857	struct ice_hw *hw = &pf->hw;
 858	struct device *dev;
 859	int ret;
 860	u8 *buf;
 861
 862	dev = ice_pf_to_dev(pf);
 863
 864	eeprom->magic = hw->vendor_id | (hw->device_id << 16);
 865	netdev_dbg(netdev, "GEEPROM cmd 0x%08x, offset 0x%08x, len 0x%08x\n",
 866		   eeprom->cmd, eeprom->offset, eeprom->len);
 867
 868	buf = kzalloc(eeprom->len, GFP_KERNEL);
 869	if (!buf)
 870		return -ENOMEM;
 871
 872	ret = ice_acquire_nvm(hw, ICE_RES_READ);
 873	if (ret) {
 874		dev_err(dev, "ice_acquire_nvm failed, err %d aq_err %s\n",
 875			ret, libie_aq_str(hw->adminq.sq_last_status));
 876		goto out;
 877	}
 878
 879	ret = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf,
 880				false);
 881	if (ret) {
 882		dev_err(dev, "ice_read_flat_nvm failed, err %d aq_err %s\n",
 883			ret, libie_aq_str(hw->adminq.sq_last_status));
 884		goto release;
 885	}
 886
 887	memcpy(bytes, buf, eeprom->len);
 888release:
 889	ice_release_nvm(hw);
 890out:
 891	kfree(buf);
 892	return ret;
 893}
 894
 895/**
 896 * ice_active_vfs - check if there are any active VFs
 897 * @pf: board private structure
 898 *
 899 * Returns true if an active VF is found, otherwise returns false
 900 */
 901static bool ice_active_vfs(struct ice_pf *pf)
 902{
 903	bool active = false;
 904	struct ice_vf *vf;
 905	unsigned int bkt;
 906
 907	rcu_read_lock();
 908	ice_for_each_vf_rcu(pf, bkt, vf) {
 909		if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
 910			active = true;
 911			break;
 912		}
 913	}
 914	rcu_read_unlock();
 915
 916	return active;
 917}
 918
 919/**
 920 * ice_link_test - perform a link test on a given net_device
 921 * @netdev: network interface device structure
 922 *
 923 * This function performs one of the self-tests required by ethtool.
 924 * Returns 0 on success, non-zero on failure.
 925 */
 926static u64 ice_link_test(struct net_device *netdev)
 927{
 928	struct ice_netdev_priv *np = netdev_priv(netdev);
 929	bool link_up = false;
 930	int status;
 931
 932	netdev_info(netdev, "link test\n");
 933	status = ice_get_link_status(np->vsi->port_info, &link_up);
 934	if (status) {
 935		netdev_err(netdev, "link query error, status = %d\n",
 936			   status);
 937		return 1;
 938	}
 939
 940	if (!link_up)
 941		return 2;
 942
 943	return 0;
 944}
 945
 946/**
 947 * ice_eeprom_test - perform an EEPROM test on a given net_device
 948 * @netdev: network interface device structure
 949 *
 950 * This function performs one of the self-tests required by ethtool.
 951 * Returns 0 on success, non-zero on failure.
 952 */
 953static u64 ice_eeprom_test(struct net_device *netdev)
 954{
 955	struct ice_pf *pf = ice_netdev_to_pf(netdev);
 956
 957	netdev_info(netdev, "EEPROM test\n");
 958	return !!(ice_nvm_validate_checksum(&pf->hw));
 959}
 960
 961/**
 962 * ice_reg_pattern_test
 963 * @hw: pointer to the HW struct
 964 * @reg: reg to be tested
 965 * @mask: bits to be touched
 966 */
 967static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
 968{
 969	struct ice_pf *pf = (struct ice_pf *)hw->back;
 970	struct device *dev = ice_pf_to_dev(pf);
 971	static const u32 patterns[] = {
 972		0x5A5A5A5A, 0xA5A5A5A5,
 973		0x00000000, 0xFFFFFFFF
 974	};
 975	u32 val, orig_val;
 976	unsigned int i;
 977
 978	orig_val = rd32(hw, reg);
 979	for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
 980		u32 pattern = patterns[i] & mask;
 981
 982		wr32(hw, reg, pattern);
 983		val = rd32(hw, reg);
 984		if (val == pattern)
 985			continue;
 986		dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
 987			, __func__, reg, pattern, val);
 988		return 1;
 989	}
 990
 991	wr32(hw, reg, orig_val);
 992	val = rd32(hw, reg);
 993	if (val != orig_val) {
 994		dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
 995			, __func__, reg, orig_val, val);
 996		return 1;
 997	}
 998
 999	return 0;
1000}
1001
1002/**
1003 * ice_reg_test - perform a register test on a given net_device
1004 * @netdev: network interface device structure
1005 *
1006 * This function performs one of the self-tests required by ethtool.
1007 * Returns 0 on success, non-zero on failure.
1008 */
1009static u64 ice_reg_test(struct net_device *netdev)
1010{
1011	struct ice_netdev_priv *np = netdev_priv(netdev);
1012	struct ice_hw *hw = np->vsi->port_info->hw;
1013	u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
1014		hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
1015	struct ice_diag_reg_test_info {
1016		u32 address;
1017		u32 mask;
1018		u32 elem_num;
1019		u32 elem_size;
1020	} ice_reg_list[] = {
1021		{GLINT_ITR(0, 0), 0x00000fff, int_elements,
1022			GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
1023		{GLINT_ITR(1, 0), 0x00000fff, int_elements,
1024			GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
1025		{GLINT_ITR(0, 0), 0x00000fff, int_elements,
1026			GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
1027		{GLINT_CTL, 0xffff0001, 1, 0}
1028	};
1029	unsigned int i;
1030
1031	netdev_dbg(netdev, "Register test\n");
1032	for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
1033		u32 j;
1034
1035		for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
1036			u32 mask = ice_reg_list[i].mask;
1037			u32 reg = ice_reg_list[i].address +
1038				(j * ice_reg_list[i].elem_size);
1039
1040			/* bail on failure (non-zero return) */
1041			if (ice_reg_pattern_test(hw, reg, mask))
1042				return 1;
1043		}
1044	}
1045
1046	return 0;
1047}
1048
1049/**
1050 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
1051 * @vsi: pointer to the VSI structure
1052 *
1053 * Function configures rings of a VSI for loopback test without
1054 * enabling interrupts or informing the kernel about new queues.
1055 *
1056 * Returns 0 on success, negative on failure.
1057 */
1058static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
1059{
1060	int status;
1061
1062	status = ice_vsi_setup_tx_rings(vsi);
1063	if (status)
1064		goto err_setup_tx_ring;
1065
1066	status = ice_vsi_setup_rx_rings(vsi);
1067	if (status)
1068		goto err_setup_rx_ring;
1069
1070	status = ice_vsi_cfg_lan(vsi);
1071	if (status)
1072		goto err_setup_rx_ring;
1073
1074	status = ice_vsi_start_all_rx_rings(vsi);
1075	if (status)
1076		goto err_start_rx_ring;
1077
1078	return 0;
1079
1080err_start_rx_ring:
1081	ice_vsi_free_rx_rings(vsi);
1082err_setup_rx_ring:
1083	ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
1084err_setup_tx_ring:
1085	ice_vsi_free_tx_rings(vsi);
1086
1087	return status;
1088}
1089
1090/**
1091 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
1092 * @vsi: pointer to the VSI structure
1093 *
1094 * Function stops and frees VSI rings after a loopback test.
1095 * Returns 0 on success, negative on failure.
1096 */
1097static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
1098{
1099	int status;
1100
1101	status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
1102	if (status)
1103		netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
1104			   vsi->vsi_num, status);
1105
1106	status = ice_vsi_stop_all_rx_rings(vsi);
1107	if (status)
1108		netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
1109			   vsi->vsi_num, status);
1110
1111	ice_vsi_free_tx_rings(vsi);
1112	ice_vsi_free_rx_rings(vsi);
1113
1114	return status;
1115}
1116
1117/**
1118 * ice_lbtest_create_frame - create test packet
1119 * @pf: pointer to the PF structure
1120 * @ret_data: allocated frame buffer
1121 * @size: size of the packet data
1122 *
1123 * Function allocates a frame with a test pattern on specific offsets.
1124 * Returns 0 on success, non-zero on failure.
1125 */
1126static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
1127{
1128	u8 *data;
1129
1130	if (!pf)
1131		return -EINVAL;
1132
1133	data = kzalloc(size, GFP_KERNEL);
1134	if (!data)
1135		return -ENOMEM;
1136
1137	/* Since the ethernet test frame should always be at least
1138	 * 64 bytes long, fill some octets in the payload with test data.
1139	 */
1140	memset(data, 0xFF, size);
1141	data[32] = 0xDE;
1142	data[42] = 0xAD;
1143	data[44] = 0xBE;
1144	data[46] = 0xEF;
1145
1146	*ret_data = data;
1147
1148	return 0;
1149}
1150
1151/**
1152 * ice_lbtest_check_frame - verify received loopback frame
1153 * @frame: pointer to the raw packet data
1154 *
1155 * Function verifies received test frame with a pattern.
1156 * Returns true if frame matches the pattern, false otherwise.
1157 */
1158static bool ice_lbtest_check_frame(u8 *frame)
1159{
1160	/* Validate bytes of a frame under offsets chosen earlier */
1161	if (frame[32] == 0xDE &&
1162	    frame[42] == 0xAD &&
1163	    frame[44] == 0xBE &&
1164	    frame[46] == 0xEF &&
1165	    frame[48] == 0xFF)
1166		return true;
1167
1168	return false;
1169}
1170
1171/**
1172 * ice_diag_send - send test frames to the test ring
1173 * @tx_ring: pointer to the transmit ring
1174 * @data: pointer to the raw packet data
1175 * @size: size of the packet to send
1176 *
1177 * Function sends loopback packets on a test Tx ring.
1178 */
1179static int ice_diag_send(struct ice_tx_ring *tx_ring, u8 *data, u16 size)
1180{
1181	struct ice_tx_desc *tx_desc;
1182	struct ice_tx_buf *tx_buf;
1183	dma_addr_t dma;
1184	u64 td_cmd;
1185
1186	tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
1187	tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
1188
1189	dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
1190	if (dma_mapping_error(tx_ring->dev, dma))
1191		return -EINVAL;
1192
1193	tx_desc->buf_addr = cpu_to_le64(dma);
1194
1195	/* These flags are required for a descriptor to be pushed out */
1196	td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
1197	tx_desc->cmd_type_offset_bsz =
1198		cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
1199			    (td_cmd << ICE_TXD_QW1_CMD_S) |
1200			    ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
1201			    ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
1202			    ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
1203
1204	tx_buf->next_to_watch = tx_desc;
1205
1206	/* Force memory write to complete before letting h/w know
1207	 * there are new descriptors to fetch.
1208	 */
1209	wmb();
1210
1211	tx_ring->next_to_use++;
1212	if (tx_ring->next_to_use >= tx_ring->count)
1213		tx_ring->next_to_use = 0;
1214
1215	writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
1216
1217	/* Wait until the packets get transmitted to the receive queue. */
1218	usleep_range(1000, 2000);
1219	dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
1220
1221	return 0;
1222}
1223
1224#define ICE_LB_FRAME_SIZE 64
1225/**
1226 * ice_lbtest_receive_frames - receive and verify test frames
1227 * @rx_ring: pointer to the receive ring
1228 *
1229 * Function receives loopback packets and verify their correctness.
1230 * Returns number of received valid frames.
1231 */
1232static int ice_lbtest_receive_frames(struct ice_rx_ring *rx_ring)
1233{
1234	struct libeth_fqe *rx_buf;
1235	int valid_frames, i;
1236	struct page *page;
1237	u8 *received_buf;
1238
1239	valid_frames = 0;
1240
1241	for (i = 0; i < rx_ring->count; i++) {
1242		union ice_32b_rx_flex_desc *rx_desc;
1243
1244		rx_desc = ICE_RX_DESC(rx_ring, i);
1245
1246		if (!(rx_desc->wb.status_error0 &
1247		    (cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_DD_S)) |
1248		     cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_EOF_S)))))
1249			continue;
1250
1251		rx_buf = &rx_ring->rx_fqes[i];
1252		page = __netmem_to_page(rx_buf->netmem);
1253		received_buf = page_address(page) + rx_buf->offset +
1254			       page->pp->p.offset;
1255
1256		if (ice_lbtest_check_frame(received_buf))
1257			valid_frames++;
1258	}
1259
1260	return valid_frames;
1261}
1262
1263/**
1264 * ice_loopback_test - perform a loopback test on a given net_device
1265 * @netdev: network interface device structure
1266 *
1267 * This function performs one of the self-tests required by ethtool.
1268 * Returns 0 on success, non-zero on failure.
1269 */
1270static u64 ice_loopback_test(struct net_device *netdev)
1271{
1272	struct ice_pf *pf = ice_netdev_to_pf(netdev);
1273	struct ice_vsi *test_vsi;
1274	u8 *tx_frame __free(kfree) = NULL;
1275	u8 broadcast[ETH_ALEN], ret = 0;
1276	int num_frames, valid_frames;
1277	struct ice_tx_ring *tx_ring;
1278	struct ice_rx_ring *rx_ring;
1279	int i;
1280
1281	netdev_info(netdev, "loopback test\n");
1282
1283	test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
1284	if (!test_vsi) {
1285		netdev_err(netdev, "Failed to create a VSI for the loopback test\n");
1286		return 1;
1287	}
1288
1289	test_vsi->netdev = netdev;
1290	tx_ring = test_vsi->tx_rings[0];
1291	rx_ring = test_vsi->rx_rings[0];
1292	/* Dummy q_vector and napi. Fill the minimum required for
1293	 * ice_rxq_pp_create().
1294	 */
1295	rx_ring->q_vector->napi.dev = netdev;
1296
1297	if (ice_lbtest_prepare_rings(test_vsi)) {
1298		ret = 2;
1299		goto lbtest_vsi_close;
1300	}
1301
1302	if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
1303		ret = 3;
1304		goto lbtest_rings_dis;
1305	}
1306
1307	/* Enable MAC loopback in firmware */
1308	if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
1309		ret = 4;
1310		goto lbtest_mac_dis;
1311	}
1312
1313	/* Test VSI needs to receive broadcast packets */
1314	eth_broadcast_addr(broadcast);
1315	if (ice_fltr_add_mac(test_vsi, broadcast, ICE_FWD_TO_VSI)) {
1316		ret = 5;
1317		goto lbtest_mac_dis;
1318	}
1319
1320	if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
1321		ret = 7;
1322		goto remove_mac_filters;
1323	}
1324
1325	num_frames = min_t(int, tx_ring->count, 32);
1326	for (i = 0; i < num_frames; i++) {
1327		if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
1328			ret = 8;
1329			goto remove_mac_filters;
1330		}
1331	}
1332
1333	valid_frames = ice_lbtest_receive_frames(rx_ring);
1334	if (!valid_frames)
1335		ret = 9;
1336	else if (valid_frames != num_frames)
1337		ret = 10;
1338
1339remove_mac_filters:
1340	if (ice_fltr_remove_mac(test_vsi, broadcast, ICE_FWD_TO_VSI))
1341		netdev_err(netdev, "Could not remove MAC filter for the test VSI\n");
1342lbtest_mac_dis:
1343	/* Disable MAC loopback after the test is completed. */
1344	if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
1345		netdev_err(netdev, "Could not disable MAC loopback\n");
1346lbtest_rings_dis:
1347	if (ice_lbtest_disable_rings(test_vsi))
1348		netdev_err(netdev, "Could not disable test rings\n");
1349lbtest_vsi_close:
1350	test_vsi->netdev = NULL;
1351	if (ice_vsi_release(test_vsi))
1352		netdev_err(netdev, "Failed to remove the test VSI\n");
1353
1354	return ret;
1355}
1356
1357/**
1358 * ice_intr_test - perform an interrupt test on a given net_device
1359 * @netdev: network interface device structure
1360 *
1361 * This function performs one of the self-tests required by ethtool.
1362 * Returns 0 on success, non-zero on failure.
1363 */
1364static u64 ice_intr_test(struct net_device *netdev)
1365{
1366	struct ice_pf *pf = ice_netdev_to_pf(netdev);
1367	u16 swic_old = pf->sw_int_count;
1368
1369	netdev_info(netdev, "interrupt test\n");
1370
1371	wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_irq.index),
1372	     GLINT_DYN_CTL_SW_ITR_INDX_M |
1373	     GLINT_DYN_CTL_INTENA_MSK_M |
1374	     GLINT_DYN_CTL_SWINT_TRIG_M);
1375
1376	usleep_range(1000, 2000);
1377	return (swic_old == pf->sw_int_count);
1378}
1379
1380/**
1381 * ice_self_test - handler function for performing a self-test by ethtool
1382 * @netdev: network interface device structure
1383 * @eth_test: ethtool_test structure
1384 * @data: required by ethtool.self_test
1385 *
1386 * This function is called after invoking 'ethtool -t devname' command where
1387 * devname is the name of the network device on which ethtool should operate.
1388 * It performs a set of self-tests to check if a device works properly.
1389 */
1390static void
1391ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
1392	      u64 *data)
1393{
1394	struct ice_pf *pf = ice_netdev_to_pf(netdev);
1395	bool if_running = netif_running(netdev);
1396	struct device *dev;
1397
1398	dev = ice_pf_to_dev(pf);
1399
1400	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1401		netdev_info(netdev, "offline testing starting\n");
1402
1403		set_bit(ICE_TESTING, pf->state);
1404
1405		if (ice_active_vfs(pf)) {
1406			dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1407			data[ICE_ETH_TEST_REG] = 1;
1408			data[ICE_ETH_TEST_EEPROM] = 1;
1409			data[ICE_ETH_TEST_INTR] = 1;
1410			data[ICE_ETH_TEST_LOOP] = 1;
1411			data[ICE_ETH_TEST_LINK] = 1;
1412			eth_test->flags |= ETH_TEST_FL_FAILED;
1413			clear_bit(ICE_TESTING, pf->state);
1414			goto skip_ol_tests;
1415		}
1416		/* If the device is online then take it offline */
1417		if (if_running)
1418			/* indicate we're in test mode */
1419			ice_stop(netdev);
1420
1421		data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
1422		data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
1423		data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
1424		data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
1425		data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
1426
1427		if (data[ICE_ETH_TEST_LINK] ||
1428		    data[ICE_ETH_TEST_EEPROM] ||
1429		    data[ICE_ETH_TEST_LOOP] ||
1430		    data[ICE_ETH_TEST_INTR] ||
1431		    data[ICE_ETH_TEST_REG])
1432			eth_test->flags |= ETH_TEST_FL_FAILED;
1433
1434		clear_bit(ICE_TESTING, pf->state);
1435
1436		if (if_running) {
1437			int status = ice_open(netdev);
1438
1439			if (status) {
1440				dev_err(dev, "Could not open device %s, err %d\n",
1441					pf->int_name, status);
1442			}
1443		}
1444	} else {
1445		/* Online tests */
1446		netdev_info(netdev, "online testing starting\n");
1447
1448		data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
1449		if (data[ICE_ETH_TEST_LINK])
1450			eth_test->flags |= ETH_TEST_FL_FAILED;
1451
1452		/* Offline only tests, not run in online; pass by default */
1453		data[ICE_ETH_TEST_REG] = 0;
1454		data[ICE_ETH_TEST_EEPROM] = 0;
1455		data[ICE_ETH_TEST_INTR] = 0;
1456		data[ICE_ETH_TEST_LOOP] = 0;
1457	}
1458
1459skip_ol_tests:
1460	netdev_info(netdev, "testing finished\n");
1461}
1462
1463static void
1464__ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
1465		  struct ice_vsi *vsi)
1466{
1467	unsigned int i;
1468	u8 *p = data;
1469
1470	switch (stringset) {
1471	case ETH_SS_STATS:
1472		for (i = 0; i < ICE_VSI_STATS_LEN; i++)
1473			ethtool_puts(&p, ice_gstrings_vsi_stats[i].stat_string);
1474
1475		if (ice_is_port_repr_netdev(netdev))
1476			return;
1477
1478		ice_for_each_alloc_txq(vsi, i) {
1479			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
1480			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
1481		}
1482
1483		ice_for_each_alloc_rxq(vsi, i) {
1484			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
1485			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
1486		}
1487
1488		if (vsi->type != ICE_VSI_PF)
1489			return;
1490
1491		for (i = 0; i < ICE_PF_STATS_LEN; i++)
1492			ethtool_puts(&p, ice_gstrings_pf_stats[i].stat_string);
1493
1494		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
1495			ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
1496			ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
1497		}
1498		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
1499			ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
1500			ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
1501		}
1502		break;
1503	case ETH_SS_TEST:
1504		memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
1505		break;
1506	case ETH_SS_PRIV_FLAGS:
1507		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
1508			ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
1509		break;
1510	default:
1511		break;
1512	}
1513}
1514
1515static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
1516{
1517	struct ice_netdev_priv *np = netdev_priv(netdev);
1518
1519	__ice_get_strings(netdev, stringset, data, np->vsi);
1520}
1521
1522static int
1523ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
1524{
1525	struct ice_netdev_priv *np = netdev_priv(netdev);
1526	bool led_active;
1527
1528	switch (state) {
1529	case ETHTOOL_ID_ACTIVE:
1530		led_active = true;
1531		break;
1532	case ETHTOOL_ID_INACTIVE:
1533		led_active = false;
1534		break;
1535	default:
1536		return -EINVAL;
1537	}
1538
1539	if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
1540		return -EIO;
1541
1542	return 0;
1543}
1544
1545/**
1546 * ice_set_fec_cfg - Set link FEC options
1547 * @netdev: network interface device structure
1548 * @req_fec: FEC mode to configure
1549 */
1550static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
1551{
1552	struct ice_netdev_priv *np = netdev_priv(netdev);
1553	struct ice_aqc_set_phy_cfg_data config = { 0 };
1554	struct ice_vsi *vsi = np->vsi;
1555	struct ice_port_info *pi;
1556
1557	pi = vsi->port_info;
1558	if (!pi)
1559		return -EOPNOTSUPP;
1560
1561	/* Changing the FEC parameters is not supported if not the PF VSI */
1562	if (vsi->type != ICE_VSI_PF) {
1563		netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
1564		return -EOPNOTSUPP;
1565	}
1566
1567	/* Proceed only if requesting different FEC mode */
1568	if (pi->phy.curr_user_fec_req == req_fec)
1569		return 0;
1570
1571	/* Copy the current user PHY configuration. The current user PHY
1572	 * configuration is initialized during probe from PHY capabilities
1573	 * software mode, and updated on set PHY configuration.
1574	 */
1575	memcpy(&config, &pi->phy.curr_user_phy_cfg, sizeof(config));
1576
1577	ice_cfg_phy_fec(pi, &config, req_fec);
1578	config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1579
1580	if (ice_aq_set_phy_cfg(pi->hw, pi, &config, NULL))
1581		return -EAGAIN;
1582
1583	/* Save requested FEC config */
1584	pi->phy.curr_user_fec_req = req_fec;
1585
1586	return 0;
1587}
1588
1589/**
1590 * ice_set_fecparam - Set FEC link options
1591 * @netdev: network interface device structure
1592 * @fecparam: Ethtool structure to retrieve FEC parameters
1593 */
1594static int
1595ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1596{
1597	struct ice_netdev_priv *np = netdev_priv(netdev);
1598	struct ice_vsi *vsi = np->vsi;
1599	enum ice_fec_mode fec;
1600
1601	switch (fecparam->fec) {
1602	case ETHTOOL_FEC_AUTO:
1603		fec = ICE_FEC_AUTO;
1604		break;
1605	case ETHTOOL_FEC_RS:
1606		fec = ICE_FEC_RS;
1607		break;
1608	case ETHTOOL_FEC_BASER:
1609		fec = ICE_FEC_BASER;
1610		break;
1611	case ETHTOOL_FEC_OFF:
1612	case ETHTOOL_FEC_NONE:
1613		fec = ICE_FEC_NONE;
1614		break;
1615	default:
1616		dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n",
1617			 fecparam->fec);
1618		return -EINVAL;
1619	}
1620
1621	return ice_set_fec_cfg(netdev, fec);
1622}
1623
1624/**
1625 * ice_get_fecparam - Get link FEC options
1626 * @netdev: network interface device structure
1627 * @fecparam: Ethtool structure to retrieve FEC parameters
1628 */
1629static int
1630ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1631{
1632	struct ice_netdev_priv *np = netdev_priv(netdev);
1633	struct ice_aqc_get_phy_caps_data *caps;
1634	struct ice_link_status *link_info;
1635	struct ice_vsi *vsi = np->vsi;
1636	struct ice_port_info *pi;
1637	int err;
1638
1639	pi = vsi->port_info;
1640
1641	if (!pi)
1642		return -EOPNOTSUPP;
1643	link_info = &pi->phy.link_info;
1644
1645	/* Set FEC mode based on negotiated link info */
1646	switch (link_info->fec_info) {
1647	case ICE_AQ_LINK_25G_KR_FEC_EN:
1648		fecparam->active_fec = ETHTOOL_FEC_BASER;
1649		break;
1650	case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1651	case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1652		fecparam->active_fec = ETHTOOL_FEC_RS;
1653		break;
1654	default:
1655		fecparam->active_fec = ETHTOOL_FEC_OFF;
1656		break;
1657	}
1658
1659	caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1660	if (!caps)
1661		return -ENOMEM;
1662
1663	err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
1664				  caps, NULL);
1665	if (err)
1666		goto done;
1667
1668	/* Set supported/configured FEC modes based on PHY capability */
1669	if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1670		fecparam->fec |= ETHTOOL_FEC_AUTO;
1671	if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1672	    caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1673	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1674	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1675		fecparam->fec |= ETHTOOL_FEC_BASER;
1676	if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1677	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1678	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1679		fecparam->fec |= ETHTOOL_FEC_RS;
1680	if (caps->link_fec_options == 0)
1681		fecparam->fec |= ETHTOOL_FEC_OFF;
1682
1683done:
1684	kfree(caps);
1685	return err;
1686}
1687
1688/**
1689 * ice_nway_reset - restart autonegotiation
1690 * @netdev: network interface device structure
1691 */
1692static int ice_nway_reset(struct net_device *netdev)
1693{
1694	struct ice_netdev_priv *np = netdev_priv(netdev);
1695	struct ice_vsi *vsi = np->vsi;
1696	int err;
1697
1698	/* If VSI state is up, then restart autoneg with link up */
1699	if (!test_bit(ICE_DOWN, vsi->back->state))
1700		err = ice_set_link(vsi, true);
1701	else
1702		err = ice_set_link(vsi, false);
1703
1704	return err;
1705}
1706
1707/**
1708 * ice_get_priv_flags - report device private flags
1709 * @netdev: network interface device structure
1710 *
1711 * The get string set count and the string set should be matched for each
1712 * flag returned.  Add new strings for each flag to the ice_gstrings_priv_flags
1713 * array.
1714 *
1715 * Returns a u32 bitmap of flags.
1716 */
1717static u32 ice_get_priv_flags(struct net_device *netdev)
1718{
1719	struct ice_pf *pf = ice_netdev_to_pf(netdev);
1720	u32 i, ret_flags = 0;
1721
1722	for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1723		const struct ice_priv_flag *priv_flag;
1724
1725		priv_flag = &ice_gstrings_priv_flags[i];
1726
1727		if (test_bit(priv_flag->bitno, pf->flags))
1728			ret_flags |= BIT(i);
1729	}
1730
1731	return ret_flags;
1732}
1733
1734/**
1735 * ice_set_priv_flags - set private flags
1736 * @netdev: network interface device structure
1737 * @flags: bit flags to be set
1738 */
1739static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1740{
1741	struct ice_netdev_priv *np = netdev_priv(netdev);
1742	DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1743	DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1744	struct ice_vsi *vsi = np->vsi;
1745	struct ice_pf *pf = vsi->back;
1746	struct device *dev;
1747	int ret = 0;
1748	u32 i;
1749
1750	if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1751		return -EINVAL;
1752
1753	dev = ice_pf_to_dev(pf);
1754	set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1755
1756	bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1757	for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1758		const struct ice_priv_flag *priv_flag;
1759
1760		priv_flag = &ice_gstrings_priv_flags[i];
1761
1762		if (flags & BIT(i))
1763			set_bit(priv_flag->bitno, pf->flags);
1764		else
1765			clear_bit(priv_flag->bitno, pf->flags);
1766	}
1767
1768	bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1769
1770	/* Do not allow change to link-down-on-close when Total Port Shutdown
1771	 * is enabled.
1772	 */
1773	if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, change_flags) &&
1774	    test_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags)) {
1775		dev_err(dev, "Setting link-down-on-close not supported on this port\n");
1776		set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1777		ret = -EINVAL;
1778		goto ethtool_exit;
1779	}
1780
1781	if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1782		if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1783			int status;
1784
1785			/* Disable FW LLDP engine */
1786			status = ice_cfg_lldp_mib_change(&pf->hw, false);
1787
1788			/* If unregistering for LLDP events fails, this is
1789			 * not an error state, as there shouldn't be any
1790			 * events to respond to.
1791			 */
1792			if (status)
1793				dev_info(dev, "Failed to unreg for LLDP events\n");
1794
1795			/* The AQ call to stop the FW LLDP agent will generate
1796			 * an error if the agent is already stopped.
1797			 */
1798			status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1799			if (status)
1800				dev_warn(dev, "Fail to stop LLDP agent\n");
1801			/* Use case for having the FW LLDP agent stopped
1802			 * will likely not need DCB, so failure to init is
1803			 * not a concern of ethtool
1804			 */
1805			status = ice_init_pf_dcb(pf, true);
1806			if (status)
1807				dev_warn(dev, "Fail to init DCB\n");
1808
1809			pf->dcbx_cap &= ~DCB_CAP_DCBX_LLD_MANAGED;
1810			pf->dcbx_cap |= DCB_CAP_DCBX_HOST;
1811		} else {
1812			bool dcbx_agent_status;
1813			int status;
1814
1815			if (ice_get_pfc_mode(pf) == ICE_QOS_MODE_DSCP) {
1816				clear_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
1817				dev_err(dev, "QoS in L3 DSCP mode, FW Agent not allowed to start\n");
1818				ret = -EOPNOTSUPP;
1819				goto ethtool_exit;
1820			}
1821
1822			/* Remove rule to direct LLDP packets to default VSI.
1823			 * The FW LLDP engine will now be consuming them.
1824			 */
1825			ice_cfg_sw_rx_lldp(vsi->back, false);
1826
1827			/* AQ command to start FW LLDP agent will return an
1828			 * error if the agent is already started
1829			 */
1830			status = ice_aq_start_lldp(&pf->hw, true, NULL);
1831			if (status)
1832				dev_warn(dev, "Fail to start LLDP Agent\n");
1833
1834			/* AQ command to start FW DCBX agent will fail if
1835			 * the agent is already started
1836			 */
1837			status = ice_aq_start_stop_dcbx(&pf->hw, true,
1838							&dcbx_agent_status,
1839							NULL);
1840			if (status)
1841				dev_dbg(dev, "Failed to start FW DCBX\n");
1842
1843			dev_info(dev, "FW DCBX agent is %s\n",
1844				 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1845
1846			/* Failure to configure MIB change or init DCB is not
1847			 * relevant to ethtool.  Print notification that
1848			 * registration/init failed but do not return error
1849			 * state to ethtool
1850			 */
1851			status = ice_init_pf_dcb(pf, true);
1852			if (status)
1853				dev_dbg(dev, "Fail to init DCB\n");
1854
1855			/* Register for MIB change events */
1856			status = ice_cfg_lldp_mib_change(&pf->hw, true);
1857			if (status)
1858				dev_dbg(dev, "Fail to enable MIB change events\n");
1859
1860			pf->dcbx_cap &= ~DCB_CAP_DCBX_HOST;
1861			pf->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED;
1862
1863			ice_nway_reset(netdev);
1864		}
1865	}
1866	/* don't allow modification of this flag when a single VF is in
1867	 * promiscuous mode because it's not supported
1868	 */
1869	if (test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, change_flags) &&
1870	    ice_is_any_vf_in_unicast_promisc(pf)) {
1871		dev_err(dev, "Changing vf-true-promisc-support flag while VF(s) are in promiscuous mode not supported\n");
1872		/* toggle bit back to previous state */
1873		change_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags);
1874		ret = -EAGAIN;
1875	}
1876
1877	if (test_bit(ICE_FLAG_VF_VLAN_PRUNING, change_flags) &&
1878	    ice_has_vfs(pf)) {
1879		dev_err(dev, "vf-vlan-pruning: VLAN pruning cannot be changed while VFs are active.\n");
1880		/* toggle bit back to previous state */
1881		change_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags);
1882		ret = -EOPNOTSUPP;
1883	}
1884ethtool_exit:
1885	clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1886	return ret;
1887}
1888
1889static int ice_get_sset_count(struct net_device *netdev, int sset)
1890{
1891	switch (sset) {
1892	case ETH_SS_STATS:
1893		/* The number (and order) of strings reported *must* remain
1894		 * constant for a given netdevice. This function must not
1895		 * report a different number based on run time parameters
1896		 * (such as the number of queues in use, or the setting of
1897		 * a private ethtool flag). This is due to the nature of the
1898		 * ethtool stats API.
1899		 *
1900		 * Userspace programs such as ethtool must make 3 separate
1901		 * ioctl requests, one for size, one for the strings, and
1902		 * finally one for the stats. Since these cross into
1903		 * userspace, changes to the number or size could result in
1904		 * undefined memory access or incorrect string<->value
1905		 * correlations for statistics.
1906		 *
1907		 * Even if it appears to be safe, changes to the size or
1908		 * order of strings will suffer from race conditions and are
1909		 * not safe.
1910		 */
1911		return ICE_ALL_STATS_LEN(netdev);
1912	case ETH_SS_TEST:
1913		return ICE_TEST_LEN;
1914	case ETH_SS_PRIV_FLAGS:
1915		return ICE_PRIV_FLAG_ARRAY_SIZE;
1916	default:
1917		return -EOPNOTSUPP;
1918	}
1919}
1920
1921static void
1922__ice_get_ethtool_stats(struct net_device *netdev,
1923			struct ethtool_stats __always_unused *stats, u64 *data,
1924			struct ice_vsi *vsi)
1925{
1926	struct ice_pf *pf = vsi->back;
1927	struct ice_tx_ring *tx_ring;
1928	struct ice_rx_ring *rx_ring;
1929	unsigned int j;
1930	int i = 0;
1931	char *p;
1932
1933	if (ice_is_port_repr_netdev(netdev)) {
1934		ice_update_eth_stats(vsi);
1935
1936		for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1937			p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1938			data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1939				     sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1940		}
1941		return;
1942	}
1943
1944	ice_update_pf_stats(pf);
1945	ice_update_vsi_stats(vsi);
1946
1947	for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1948		p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1949		data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1950			     sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1951	}
1952
1953	/* populate per queue stats */
1954	rcu_read_lock();
1955
1956	ice_for_each_alloc_txq(vsi, j) {
1957		tx_ring = READ_ONCE(vsi->tx_rings[j]);
1958		if (tx_ring && tx_ring->ring_stats) {
1959			data[i++] = tx_ring->ring_stats->stats.pkts;
1960			data[i++] = tx_ring->ring_stats->stats.bytes;
1961		} else {
1962			data[i++] = 0;
1963			data[i++] = 0;
1964		}
1965	}
1966
1967	ice_for_each_alloc_rxq(vsi, j) {
1968		rx_ring = READ_ONCE(vsi->rx_rings[j]);
1969		if (rx_ring && rx_ring->ring_stats) {
1970			data[i++] = rx_ring->ring_stats->stats.pkts;
1971			data[i++] = rx_ring->ring_stats->stats.bytes;
1972		} else {
1973			data[i++] = 0;
1974			data[i++] = 0;
1975		}
1976	}
1977
1978	rcu_read_unlock();
1979
1980	if (vsi->type != ICE_VSI_PF)
1981		return;
1982
1983	for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1984		p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1985		data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1986			     sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1987	}
1988
1989	for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1990		data[i++] = pf->stats.priority_xon_tx[j];
1991		data[i++] = pf->stats.priority_xoff_tx[j];
1992	}
1993
1994	for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1995		data[i++] = pf->stats.priority_xon_rx[j];
1996		data[i++] = pf->stats.priority_xoff_rx[j];
1997	}
1998}
1999
2000static void
2001ice_get_ethtool_stats(struct net_device *netdev,
2002		      struct ethtool_stats __always_unused *stats, u64 *data)
2003{
2004	struct ice_netdev_priv *np = netdev_priv(netdev);
2005
2006	__ice_get_ethtool_stats(netdev, stats, data, np->vsi);
2007}
2008
2009#define ICE_PHY_TYPE_LOW_MASK_MIN_1G	(ICE_PHY_TYPE_LOW_100BASE_TX | \
2010					 ICE_PHY_TYPE_LOW_100M_SGMII)
2011
2012#define ICE_PHY_TYPE_LOW_MASK_MIN_25G	(ICE_PHY_TYPE_LOW_MASK_MIN_1G | \
2013					 ICE_PHY_TYPE_LOW_1000BASE_T | \
2014					 ICE_PHY_TYPE_LOW_1000BASE_SX | \
2015					 ICE_PHY_TYPE_LOW_1000BASE_LX | \
2016					 ICE_PHY_TYPE_LOW_1000BASE_KX | \
2017					 ICE_PHY_TYPE_LOW_1G_SGMII | \
2018					 ICE_PHY_TYPE_LOW_2500BASE_T | \
2019					 ICE_PHY_TYPE_LOW_2500BASE_X | \
2020					 ICE_PHY_TYPE_LOW_2500BASE_KX | \
2021					 ICE_PHY_TYPE_LOW_5GBASE_T | \
2022					 ICE_PHY_TYPE_LOW_5GBASE_KR | \
2023					 ICE_PHY_TYPE_LOW_10GBASE_T | \
2024					 ICE_PHY_TYPE_LOW_10G_SFI_DA | \
2025					 ICE_PHY_TYPE_LOW_10GBASE_SR | \
2026					 ICE_PHY_TYPE_LOW_10GBASE_LR | \
2027					 ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 | \
2028					 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC | \
2029					 ICE_PHY_TYPE_LOW_10G_SFI_C2C)
2030
2031#define ICE_PHY_TYPE_LOW_MASK_100G	(ICE_PHY_TYPE_LOW_100GBASE_CR4 | \
2032					 ICE_PHY_TYPE_LOW_100GBASE_SR4 | \
2033					 ICE_PHY_TYPE_LOW_100GBASE_LR4 | \
2034					 ICE_PHY_TYPE_LOW_100GBASE_KR4 | \
2035					 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC | \
2036					 ICE_PHY_TYPE_LOW_100G_CAUI4 | \
2037					 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC | \
2038					 ICE_PHY_TYPE_LOW_100G_AUI4 | \
2039					 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 | \
2040					 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 | \
2041					 ICE_PHY_TYPE_LOW_100GBASE_CP2 | \
2042					 ICE_PHY_TYPE_LOW_100GBASE_SR2 | \
2043					 ICE_PHY_TYPE_LOW_100GBASE_DR)
2044
2045#define ICE_PHY_TYPE_HIGH_MASK_100G	(ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4 | \
2046					 ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC |\
2047					 ICE_PHY_TYPE_HIGH_100G_CAUI2 | \
2048					 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC | \
2049					 ICE_PHY_TYPE_HIGH_100G_AUI2)
2050
2051#define ICE_PHY_TYPE_HIGH_MASK_200G	(ICE_PHY_TYPE_HIGH_200G_CR4_PAM4 | \
2052					 ICE_PHY_TYPE_HIGH_200G_SR4 | \
2053					 ICE_PHY_TYPE_HIGH_200G_FR4 | \
2054					 ICE_PHY_TYPE_HIGH_200G_LR4 | \
2055					 ICE_PHY_TYPE_HIGH_200G_DR4 | \
2056					 ICE_PHY_TYPE_HIGH_200G_KR4_PAM4 | \
2057					 ICE_PHY_TYPE_HIGH_200G_AUI4_AOC_ACC | \
2058					 ICE_PHY_TYPE_HIGH_200G_AUI4)
2059
2060/**
2061 * ice_mask_min_supported_speeds
2062 * @hw: pointer to the HW structure
2063 * @phy_types_high: PHY type high
2064 * @phy_types_low: PHY type low to apply minimum supported speeds mask
2065 *
2066 * Apply minimum supported speeds mask to PHY type low. These are the speeds
2067 * for ethtool supported link mode.
2068 */
2069static void
2070ice_mask_min_supported_speeds(struct ice_hw *hw,
2071			      u64 phy_types_high, u64 *phy_types_low)
2072{
2073	/* if QSFP connection with 100G speed, minimum supported speed is 25G */
2074	if ((*phy_types_low & ICE_PHY_TYPE_LOW_MASK_100G) ||
2075	    (phy_types_high & ICE_PHY_TYPE_HIGH_MASK_100G) ||
2076	    (phy_types_high & ICE_PHY_TYPE_HIGH_MASK_200G))
2077		*phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_25G;
2078	else if (!ice_is_100m_speed_supported(hw))
2079		*phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_1G;
2080}
2081
2082/**
2083 * ice_linkmode_set_bit - set link mode bit
2084 * @phy_to_ethtool: PHY type to ethtool link mode struct to set
2085 * @ks: ethtool link ksettings struct to fill out
2086 * @req_speeds: speed requested by user
2087 * @advert_phy_type: advertised PHY type
2088 * @phy_type: PHY type
2089 */
2090static void
2091ice_linkmode_set_bit(const struct ice_phy_type_to_ethtool *phy_to_ethtool,
2092		     struct ethtool_link_ksettings *ks, u32 req_speeds,
2093		     u64 advert_phy_type, u32 phy_type)
2094{
2095	linkmode_set_bit(phy_to_ethtool->link_mode, ks->link_modes.supported);
2096
2097	if (req_speeds & phy_to_ethtool->aq_link_speed ||
2098	    (!req_speeds && advert_phy_type & BIT(phy_type)))
2099		linkmode_set_bit(phy_to_ethtool->link_mode,
2100				 ks->link_modes.advertising);
2101}
2102
2103/**
2104 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
2105 * @netdev: network interface device structure
2106 * @ks: ethtool link ksettings struct to fill out
2107 */
2108static void
2109ice_phy_type_to_ethtool(struct net_device *netdev,
2110			struct ethtool_link_ksettings *ks)
2111{
2112	struct ice_netdev_priv *np = netdev_priv(netdev);
2113	struct ice_vsi *vsi = np->vsi;
2114	struct ice_pf *pf = vsi->back;
2115	u64 advert_phy_type_lo = 0;
2116	u64 advert_phy_type_hi = 0;
2117	u64 phy_types_high = 0;
2118	u64 phy_types_low = 0;
2119	u32 req_speeds;
2120	u32 i;
2121
2122	req_speeds = vsi->port_info->phy.link_info.req_speeds;
2123
2124	/* Check if lenient mode is supported and enabled, or in strict mode.
2125	 *
2126	 * In lenient mode the Supported link modes are the PHY types without
2127	 * media. The Advertising link mode is either 1. the user requested
2128	 * speed, 2. the override PHY mask, or 3. the PHY types with media.
2129	 *
2130	 * In strict mode Supported link mode are the PHY type with media,
2131	 * and Advertising link modes are the media PHY type or the speed
2132	 * requested by user.
2133	 */
2134	if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
2135		phy_types_low = le64_to_cpu(pf->nvm_phy_type_lo);
2136		phy_types_high = le64_to_cpu(pf->nvm_phy_type_hi);
2137
2138		ice_mask_min_supported_speeds(&pf->hw, phy_types_high,
2139					      &phy_types_low);
2140		/* determine advertised modes based on link override only
2141		 * if it's supported and if the FW doesn't abstract the
2142		 * driver from having to account for link overrides
2143		 */
2144		if (ice_fw_supports_link_override(&pf->hw) &&
2145		    !ice_fw_supports_report_dflt_cfg(&pf->hw)) {
2146			struct ice_link_default_override_tlv *ldo;
2147
2148			ldo = &pf->link_dflt_override;
2149			/* If override enabled and PHY mask set, then
2150			 * Advertising link mode is the intersection of the PHY
2151			 * types without media and the override PHY mask.
2152			 */
2153			if (ldo->options & ICE_LINK_OVERRIDE_EN &&
2154			    (ldo->phy_type_low || ldo->phy_type_high)) {
2155				advert_phy_type_lo =
2156					le64_to_cpu(pf->nvm_phy_type_lo) &
2157					ldo->phy_type_low;
2158				advert_phy_type_hi =
2159					le64_to_cpu(pf->nvm_phy_type_hi) &
2160					ldo->phy_type_high;
2161			}
2162		}
2163	} else {
2164		/* strict mode */
2165		phy_types_low = vsi->port_info->phy.phy_type_low;
2166		phy_types_high = vsi->port_info->phy.phy_type_high;
2167	}
2168
2169	/* If Advertising link mode PHY type is not using override PHY type,
2170	 * then use PHY type with media.
2171	 */
2172	if (!advert_phy_type_lo && !advert_phy_type_hi) {
2173		advert_phy_type_lo = vsi->port_info->phy.phy_type_low;
2174		advert_phy_type_hi = vsi->port_info->phy.phy_type_high;
2175	}
2176
2177	linkmode_zero(ks->link_modes.supported);
2178	linkmode_zero(ks->link_modes.advertising);
2179
2180	for (i = 0; i < ARRAY_SIZE(phy_type_low_lkup); i++) {
2181		if (phy_types_low & BIT_ULL(i))
2182			ice_linkmode_set_bit(&phy_type_low_lkup[i], ks,
2183					     req_speeds, advert_phy_type_lo,
2184					     i);
2185	}
2186
2187	for (i = 0; i < ARRAY_SIZE(phy_type_high_lkup); i++) {
2188		if (phy_types_high & BIT_ULL(i))
2189			ice_linkmode_set_bit(&phy_type_high_lkup[i], ks,
2190					     req_speeds, advert_phy_type_hi,
2191					     i);
2192	}
2193}
2194
2195#define TEST_SET_BITS_TIMEOUT	50
2196#define TEST_SET_BITS_SLEEP_MAX	2000
2197#define TEST_SET_BITS_SLEEP_MIN	1000
2198
2199/**
2200 * ice_get_settings_link_up - Get Link settings for when link is up
2201 * @ks: ethtool ksettings to fill in
2202 * @netdev: network interface device structure
2203 */
2204static void
2205ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
2206			 struct net_device *netdev)
2207{
2208	struct ice_netdev_priv *np = netdev_priv(netdev);
2209	struct ice_port_info *pi = np->vsi->port_info;
2210	struct ice_link_status *link_info;
2211	struct ice_vsi *vsi = np->vsi;
2212
2213	link_info = &vsi->port_info->phy.link_info;
2214
2215	/* Get supported and advertised settings from PHY ability with media */
2216	ice_phy_type_to_ethtool(netdev, ks);
2217
2218	switch (link_info->link_speed) {
2219	case ICE_AQ_LINK_SPEED_200GB:
2220		ks->base.speed = SPEED_200000;
2221		break;
2222	case ICE_AQ_LINK_SPEED_100GB:
2223		ks->base.speed = SPEED_100000;
2224		break;
2225	case ICE_AQ_LINK_SPEED_50GB:
2226		ks->base.speed = SPEED_50000;
2227		break;
2228	case ICE_AQ_LINK_SPEED_40GB:
2229		ks->base.speed = SPEED_40000;
2230		break;
2231	case ICE_AQ_LINK_SPEED_25GB:
2232		ks->base.speed = SPEED_25000;
2233		break;
2234	case ICE_AQ_LINK_SPEED_20GB:
2235		ks->base.speed = SPEED_20000;
2236		break;
2237	case ICE_AQ_LINK_SPEED_10GB:
2238		ks->base.speed = SPEED_10000;
2239		break;
2240	case ICE_AQ_LINK_SPEED_5GB:
2241		ks->base.speed = SPEED_5000;
2242		break;
2243	case ICE_AQ_LINK_SPEED_2500MB:
2244		ks->base.speed = SPEED_2500;
2245		break;
2246	case ICE_AQ_LINK_SPEED_1000MB:
2247		ks->base.speed = SPEED_1000;
2248		break;
2249	case ICE_AQ_LINK_SPEED_100MB:
2250		ks->base.speed = SPEED_100;
2251		break;
2252	default:
2253		netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n",
2254			    link_info->link_speed);
2255		break;
2256	}
2257	ks->base.duplex = DUPLEX_FULL;
2258
2259	if (link_info->an_info & ICE_AQ_AN_COMPLETED)
2260		ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2261						     Autoneg);
2262
2263	/* Set flow control negotiated Rx/Tx pause */
2264	switch (pi->fc.current_mode) {
2265	case ICE_FC_FULL:
2266		ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
2267		break;
2268	case ICE_FC_TX_PAUSE:
2269		ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
2270		ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2271						     Asym_Pause);
2272		break;
2273	case ICE_FC_RX_PAUSE:
2274		ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2275						     Asym_Pause);
2276		break;
2277	case ICE_FC_PFC:
2278	default:
2279		ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
2280		ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
2281						     Asym_Pause);
2282		break;
2283	}
2284}
2285
2286/**
2287 * ice_get_settings_link_down - Get the Link settings when link is down
2288 * @ks: ethtool ksettings to fill in
2289 * @netdev: network interface device structure
2290 *
2291 * Reports link settings that can be determined when link is down
2292 */
2293static void
2294ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
2295			   struct net_device *netdev)
2296{
2297	/* link is down and the driver needs to fall back on
2298	 * supported PHY types to figure out what info to display
2299	 */
2300	ice_phy_type_to_ethtool(netdev, ks);
2301
2302	/* With no link, speed and duplex are unknown */
2303	ks->base.speed = SPEED_UNKNOWN;
2304	ks->base.duplex = DUPLEX_UNKNOWN;
2305}
2306
2307/**
2308 * ice_get_link_ksettings - Get Link Speed and Duplex settings
2309 * @netdev: network interface device structure
2310 * @ks: ethtool ksettings
2311 *
2312 * Reports speed/duplex settings based on media_type
2313 */
2314static int
2315ice_get_link_ksettings(struct net_device *netdev,
2316		       struct ethtool_link_ksettings *ks)
2317{
2318	struct ice_netdev_priv *np = netdev_priv(netdev);
2319	struct ice_aqc_get_phy_caps_data *caps;
2320	struct ice_link_status *hw_link_info;
2321	struct ice_vsi *vsi = np->vsi;
2322	int err;
2323
2324	ethtool_link_ksettings_zero_link_mode(ks, supported);
2325	ethtool_link_ksettings_zero_link_mode(ks, advertising);
2326	ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
2327	hw_link_info = &vsi->port_info->phy.link_info;
2328
2329	/* set speed and duplex */
2330	if (hw_link_info->link_info & ICE_AQ_LINK_UP)
2331		ice_get_settings_link_up(ks, netdev);
2332	else
2333		ice_get_settings_link_down(ks, netdev);
2334
2335	/* set autoneg settings */
2336	ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
2337		AUTONEG_ENABLE : AUTONEG_DISABLE;
2338
2339	/* set media type settings */
2340	switch (vsi->port_info->phy.media_type) {
2341	case ICE_MEDIA_FIBER:
2342		ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
2343		ks->base.port = PORT_FIBRE;
2344		break;
2345	case ICE_MEDIA_BASET:
2346		ethtool_link_ksettings_add_link_mode(ks, supported, TP);
2347		ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
2348		ks->base.port = PORT_TP;
2349		break;
2350	case ICE_MEDIA_BACKPLANE:
2351		ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
2352		ethtool_link_ksettings_add_link_mode(ks, advertising,
2353						     Backplane);
2354		ks->base.port = PORT_NONE;
2355		break;
2356	case ICE_MEDIA_DA:
2357		ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
2358		ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
2359		ks->base.port = PORT_DA;
2360		break;
2361	default:
2362		ks->base.port = PORT_OTHER;
2363		break;
2364	}
2365
2366	/* flow control is symmetric and always supported */
2367	ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
2368
2369	caps = kzalloc(sizeof(*caps), GFP_KERNEL);
2370	if (!caps)
2371		return -ENOMEM;
2372
2373	err = ice_aq_get_phy_caps(vsi->port_info, false,
2374				  ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
2375	if (err)
2376		goto done;
2377
2378	/* Set the advertised flow control based on the PHY capability */
2379	if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
2380	    (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
2381		ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2382		ethtool_link_ksettings_add_link_mode(ks, advertising,
2383						     Asym_Pause);
2384	} else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
2385		ethtool_link_ksettings_add_link_mode(ks, advertising,
2386						     Asym_Pause);
2387	} else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
2388		ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2389		ethtool_link_ksettings_add_link_mode(ks, advertising,
2390						     Asym_Pause);
2391	} else {
2392		ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
2393		ethtool_link_ksettings_del_link_mode(ks, advertising,
2394						     Asym_Pause);
2395	}
2396
2397	/* Set advertised FEC modes based on PHY capability */
2398	ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
2399
2400	if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
2401	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
2402		ethtool_link_ksettings_add_link_mode(ks, advertising,
2403						     FEC_BASER);
2404	if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
2405	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
2406		ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
2407
2408	err = ice_aq_get_phy_caps(vsi->port_info, false,
2409				  ICE_AQC_REPORT_TOPO_CAP_MEDIA, caps, NULL);
2410	if (err)
2411		goto done;
2412
2413	/* Set supported FEC modes based on PHY capability */
2414	ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
2415
2416	if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
2417	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
2418		ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
2419	if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
2420		ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
2421
2422	/* Set supported and advertised autoneg */
2423	if (ice_is_phy_caps_an_enabled(caps)) {
2424		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
2425		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
2426	}
2427
2428done:
2429	kfree(caps);
2430	return err;
2431}
2432
2433/**
2434 * ice_speed_to_aq_link - Get AQ link speed by Ethtool forced speed
2435 * @speed: ethtool forced speed
2436 */
2437static u16 ice_speed_to_aq_link(int speed)
2438{
2439	int aq_speed;
2440
2441	switch (speed) {
2442	case SPEED_10:
2443		aq_speed = ICE_AQ_LINK_SPEED_10MB;
2444		break;
2445	case SPEED_100:
2446		aq_speed = ICE_AQ_LINK_SPEED_100MB;
2447		break;
2448	case SPEED_1000:
2449		aq_speed = ICE_AQ_LINK_SPEED_1000MB;
2450		break;
2451	case SPEED_2500:
2452		aq_speed = ICE_AQ_LINK_SPEED_2500MB;
2453		break;
2454	case SPEED_5000:
2455		aq_speed = ICE_AQ_LINK_SPEED_5GB;
2456		break;
2457	case SPEED_10000:
2458		aq_speed = ICE_AQ_LINK_SPEED_10GB;
2459		break;
2460	case SPEED_20000:
2461		aq_speed = ICE_AQ_LINK_SPEED_20GB;
2462		break;
2463	case SPEED_25000:
2464		aq_speed = ICE_AQ_LINK_SPEED_25GB;
2465		break;
2466	case SPEED_40000:
2467		aq_speed = ICE_AQ_LINK_SPEED_40GB;
2468		break;
2469	case SPEED_50000:
2470		aq_speed = ICE_AQ_LINK_SPEED_50GB;
2471		break;
2472	case SPEED_100000:
2473		aq_speed = ICE_AQ_LINK_SPEED_100GB;
2474		break;
2475	default:
2476		aq_speed = ICE_AQ_LINK_SPEED_UNKNOWN;
2477		break;
2478	}
2479	return aq_speed;
2480}
2481
2482/**
2483 * ice_ksettings_find_adv_link_speed - Find advertising link speed
2484 * @ks: ethtool ksettings
2485 */
2486static u16
2487ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
2488{
2489	const struct ethtool_forced_speed_map *map;
2490	u16 adv_link_speed = 0;
2491
2492	for (u32 i = 0; i < ARRAY_SIZE(ice_adv_lnk_speed_maps); i++) {
2493		map = ice_adv_lnk_speed_maps + i;
2494		if (linkmode_intersects(ks->link_modes.advertising, map->caps))
2495			adv_link_speed |= ice_speed_to_aq_link(map->speed);
2496	}
2497
2498	return adv_link_speed;
2499}
2500
2501/**
2502 * ice_setup_autoneg
2503 * @p: port info
2504 * @ks: ethtool_link_ksettings
2505 * @config: configuration that will be sent down to FW
2506 * @autoneg_enabled: autonegotiation is enabled or not
2507 * @autoneg_changed: will there a change in autonegotiation
2508 * @netdev: network interface device structure
2509 *
2510 * Setup PHY autonegotiation feature
2511 */
2512static int
2513ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2514		  struct ice_aqc_set_phy_cfg_data *config,
2515		  u8 autoneg_enabled, u8 *autoneg_changed,
2516		  struct net_device *netdev)
2517{
2518	int err = 0;
2519
2520	*autoneg_changed = 0;
2521
2522	/* Check autoneg */
2523	if (autoneg_enabled == AUTONEG_ENABLE) {
2524		/* If autoneg was not already enabled */
2525		if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2526			/* If autoneg is not supported, return error */
2527			if (!ethtool_link_ksettings_test_link_mode(ks,
2528								   supported,
2529								   Autoneg)) {
2530				netdev_info(netdev, "Autoneg not supported on this phy.\n");
2531				err = -EINVAL;
2532			} else {
2533				/* Autoneg is allowed to change */
2534				config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2535				*autoneg_changed = 1;
2536			}
2537		}
2538	} else {
2539		/* If autoneg is currently enabled */
2540		if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2541			/* If autoneg is supported 10GBASE_T is the only PHY
2542			 * that can disable it, so otherwise return error
2543			 */
2544			if (ethtool_link_ksettings_test_link_mode(ks,
2545								  supported,
2546								  Autoneg)) {
2547				netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2548				err = -EINVAL;
2549			} else {
2550				/* Autoneg is allowed to change */
2551				config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2552				*autoneg_changed = 1;
2553			}
2554		}
2555	}
2556
2557	return err;
2558}
2559
2560/**
2561 * ice_set_phy_type_from_speed - set phy_types based on speeds
2562 * and advertised modes
2563 * @ks: ethtool link ksettings struct
2564 * @phy_type_low: pointer to the lower part of phy_type
2565 * @phy_type_high: pointer to the higher part of phy_type
2566 * @adv_link_speed: targeted link speeds bitmap
2567 */
2568static void
2569ice_set_phy_type_from_speed(const struct ethtool_link_ksettings *ks,
2570			    u64 *phy_type_low, u64 *phy_type_high,
2571			    u16 adv_link_speed)
2572{
2573	/* Handle 1000M speed in a special way because ice_update_phy_type
2574	 * enables all link modes, but having mixed copper and optical
2575	 * standards is not supported.
2576	 */
2577	adv_link_speed &= ~ICE_AQ_LINK_SPEED_1000MB;
2578
2579	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2580						  1000baseT_Full))
2581		*phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_T |
2582				 ICE_PHY_TYPE_LOW_1G_SGMII;
2583
2584	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2585						  1000baseKX_Full))
2586		*phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_KX;
2587
2588	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2589						  1000baseX_Full))
2590		*phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_SX |
2591				 ICE_PHY_TYPE_LOW_1000BASE_LX;
2592
2593	ice_update_phy_type(phy_type_low, phy_type_high, adv_link_speed);
2594}
2595
2596/**
2597 * ice_set_link_ksettings - Set Speed and Duplex
2598 * @netdev: network interface device structure
2599 * @ks: ethtool ksettings
2600 *
2601 * Set speed/duplex per media_types advertised/forced
2602 */
2603static int
2604ice_set_link_ksettings(struct net_device *netdev,
2605		       const struct ethtool_link_ksettings *ks)
2606{
2607	struct ice_netdev_priv *np = netdev_priv(netdev);
2608	u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT;
2609	struct ethtool_link_ksettings copy_ks = *ks;
2610	struct ethtool_link_ksettings safe_ks = {};
2611	struct ice_aqc_get_phy_caps_data *phy_caps;
2612	struct ice_aqc_set_phy_cfg_data config;
2613	u16 adv_link_speed, curr_link_speed;
2614	struct ice_pf *pf = np->vsi->back;
2615	struct ice_port_info *pi;
2616	u8 autoneg_changed = 0;
2617	u64 phy_type_high = 0;
2618	u64 phy_type_low = 0;
2619	bool linkup;
2620	int err;
2621
2622	pi = np->vsi->port_info;
2623
2624	if (!pi)
2625		return -EIO;
2626
2627	if (pi->phy.media_type != ICE_MEDIA_BASET &&
2628	    pi->phy.media_type != ICE_MEDIA_FIBER &&
2629	    pi->phy.media_type != ICE_MEDIA_BACKPLANE &&
2630	    pi->phy.media_type != ICE_MEDIA_DA &&
2631	    pi->phy.link_info.link_info & ICE_AQ_LINK_UP)
2632		return -EOPNOTSUPP;
2633
2634	phy_caps = kzalloc(sizeof(*phy_caps), GFP_KERNEL);
2635	if (!phy_caps)
2636		return -ENOMEM;
2637
2638	/* Get the PHY capabilities based on media */
2639	if (ice_fw_supports_report_dflt_cfg(pi->hw))
2640		err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2641					  phy_caps, NULL);
2642	else
2643		err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2644					  phy_caps, NULL);
2645	if (err)
2646		goto done;
2647
2648	/* save autoneg out of ksettings */
2649	autoneg = copy_ks.base.autoneg;
2650
2651	/* Get link modes supported by hardware.*/
2652	ice_phy_type_to_ethtool(netdev, &safe_ks);
2653
2654	/* and check against modes requested by user.
2655	 * Return an error if unsupported mode was set.
2656	 */
2657	if (!bitmap_subset(copy_ks.link_modes.advertising,
2658			   safe_ks.link_modes.supported,
2659			   __ETHTOOL_LINK_MODE_MASK_NBITS)) {
2660		if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags))
2661			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");
2662		err = -EOPNOTSUPP;
2663		goto done;
2664	}
2665
2666	/* get our own copy of the bits to check against */
2667	memset(&safe_ks, 0, sizeof(safe_ks));
2668	safe_ks.base.cmd = copy_ks.base.cmd;
2669	safe_ks.base.link_mode_masks_nwords =
2670		copy_ks.base.link_mode_masks_nwords;
2671	ice_get_link_ksettings(netdev, &safe_ks);
2672
2673	/* set autoneg back to what it currently is */
2674	copy_ks.base.autoneg = safe_ks.base.autoneg;
2675	/* we don't compare the speed */
2676	copy_ks.base.speed = safe_ks.base.speed;
2677
2678	/* If copy_ks.base and safe_ks.base are not the same now, then they are
2679	 * trying to set something that we do not support.
2680	 */
2681	if (memcmp(&copy_ks.base, &safe_ks.base, sizeof(copy_ks.base))) {
2682		err = -EOPNOTSUPP;
2683		goto done;
2684	}
2685
2686	while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
2687		timeout--;
2688		if (!timeout) {
2689			err = -EBUSY;
2690			goto done;
2691		}
2692		usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2693	}
2694
2695	/* Copy the current user PHY configuration. The current user PHY
2696	 * configuration is initialized during probe from PHY capabilities
2697	 * software mode, and updated on set PHY configuration.
2698	 */
2699	config = pi->phy.curr_user_phy_cfg;
2700
2701	config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2702
2703	/* Check autoneg */
2704	err = ice_setup_autoneg(pi, &safe_ks, &config, autoneg, &autoneg_changed,
2705				netdev);
2706
2707	if (err)
2708		goto done;
2709
2710	/* Call to get the current link speed */
2711	pi->phy.get_link_info = true;
2712	err = ice_get_link_status(pi, &linkup);
2713	if (err)
2714		goto done;
2715
2716	curr_link_speed = pi->phy.curr_user_speed_req;
2717	adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2718
2719	/* If speed didn't get set, set it to what it currently is.
2720	 * This is needed because if advertise is 0 (as it is when autoneg
2721	 * is disabled) then speed won't get set.
2722	 */
2723	if (!adv_link_speed)
2724		adv_link_speed = curr_link_speed;
2725
2726	/* Convert the advertise link speeds to their corresponded PHY_TYPE */
2727	ice_set_phy_type_from_speed(ks, &phy_type_low, &phy_type_high,
2728				    adv_link_speed);
2729
2730	if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2731		netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2732		goto done;
2733	}
2734
2735	/* save the requested speeds */
2736	pi->phy.link_info.req_speeds = adv_link_speed;
2737
2738	/* set link and auto negotiation so changes take effect */
2739	config.caps |= ICE_AQ_PHY_ENA_LINK;
2740
2741	/* check if there is a PHY type for the requested advertised speed */
2742	if (!(phy_type_low || phy_type_high)) {
2743		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");
2744		err = -EOPNOTSUPP;
2745		goto done;
2746	}
2747
2748	/* intersect requested advertised speed PHY types with media PHY types
2749	 * for set PHY configuration
2750	 */
2751	config.phy_type_high = cpu_to_le64(phy_type_high) &
2752			phy_caps->phy_type_high;
2753	config.phy_type_low = cpu_to_le64(phy_type_low) &
2754			phy_caps->phy_type_low;
2755
2756	if (!(config.phy_type_high || config.phy_type_low)) {
2757		/* If there is no intersection and lenient mode is enabled, then
2758		 * intersect the requested advertised speed with NVM media type
2759		 * PHY types.
2760		 */
2761		if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
2762			config.phy_type_high = cpu_to_le64(phy_type_high) &
2763					       pf->nvm_phy_type_hi;
2764			config.phy_type_low = cpu_to_le64(phy_type_low) &
2765					      pf->nvm_phy_type_lo;
2766		} else {
2767			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");
2768			err = -EOPNOTSUPP;
2769			goto done;
2770		}
2771	}
2772
2773	/* If link is up put link down */
2774	if (pi->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2775		/* Tell the OS link is going down, the link will go
2776		 * back up when fw says it is ready asynchronously
2777		 */
2778		ice_print_link_msg(np->vsi, false);
2779		netif_carrier_off(netdev);
2780		netif_tx_stop_all_queues(netdev);
2781	}
2782
2783	/* make the aq call */
2784	err = ice_aq_set_phy_cfg(&pf->hw, pi, &config, NULL);
2785	if (err) {
2786		netdev_info(netdev, "Set phy config failed,\n");
2787		goto done;
2788	}
2789
2790	/* Save speed request */
2791	pi->phy.curr_user_speed_req = adv_link_speed;
2792done:
2793	kfree(phy_caps);
2794	clear_bit(ICE_CFG_BUSY, pf->state);
2795
2796	return err;
2797}
2798
2799static u32 ice_parse_hdrs(const struct ethtool_rxfh_fields *nfc)
2800{
2801	u32 hdrs = ICE_FLOW_SEG_HDR_NONE;
2802
2803	switch (nfc->flow_type) {
2804	case TCP_V4_FLOW:
2805		hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4;
2806		break;
2807	case UDP_V4_FLOW:
2808		hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4;
2809		break;
2810	case SCTP_V4_FLOW:
2811		hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4;
2812		break;
2813	case GTPU_V4_FLOW:
2814		hdrs |= ICE_FLOW_SEG_HDR_GTPU_IP | ICE_FLOW_SEG_HDR_IPV4;
2815		break;
2816	case GTPC_V4_FLOW:
2817		hdrs |= ICE_FLOW_SEG_HDR_GTPC | ICE_FLOW_SEG_HDR_IPV4;
2818		break;
2819	case GTPC_TEID_V4_FLOW:
2820		hdrs |= ICE_FLOW_SEG_HDR_GTPC_TEID | ICE_FLOW_SEG_HDR_IPV4;
2821		break;
2822	case GTPU_EH_V4_FLOW:
2823		hdrs |= ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV4;
2824		break;
2825	case GTPU_UL_V4_FLOW:
2826		hdrs |= ICE_FLOW_SEG_HDR_GTPU_UP | ICE_FLOW_SEG_HDR_IPV4;
2827		break;
2828	case GTPU_DL_V4_FLOW:
2829		hdrs |= ICE_FLOW_SEG_HDR_GTPU_DWN | ICE_FLOW_SEG_HDR_IPV4;
2830		break;
2831	case TCP_V6_FLOW:
2832		hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6;
2833		break;
2834	case UDP_V6_FLOW:
2835		hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6;
2836		break;
2837	case SCTP_V6_FLOW:
2838		hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6;
2839		break;
2840	case GTPU_V6_FLOW:
2841		hdrs |= ICE_FLOW_SEG_HDR_GTPU_IP | ICE_FLOW_SEG_HDR_IPV6;
2842		break;
2843	case GTPC_V6_FLOW:
2844		hdrs |= ICE_FLOW_SEG_HDR_GTPC | ICE_FLOW_SEG_HDR_IPV6;
2845		break;
2846	case GTPC_TEID_V6_FLOW:
2847		hdrs |= ICE_FLOW_SEG_HDR_GTPC_TEID | ICE_FLOW_SEG_HDR_IPV6;
2848		break;
2849	case GTPU_EH_V6_FLOW:
2850		hdrs |= ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV6;
2851		break;
2852	case GTPU_UL_V6_FLOW:
2853		hdrs |= ICE_FLOW_SEG_HDR_GTPU_UP | ICE_FLOW_SEG_HDR_IPV6;
2854		break;
2855	case GTPU_DL_V6_FLOW:
2856		hdrs |= ICE_FLOW_SEG_HDR_GTPU_DWN | ICE_FLOW_SEG_HDR_IPV6;
2857		break;
2858	default:
2859		break;
2860	}
2861	return hdrs;
2862}
2863
2864static u64 ice_parse_hash_flds(const struct ethtool_rxfh_fields *nfc, bool symm)
2865{
2866	u64 hfld = ICE_HASH_INVALID;
2867
2868	if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) {
2869		switch (nfc->flow_type) {
2870		case TCP_V4_FLOW:
2871		case UDP_V4_FLOW:
2872		case SCTP_V4_FLOW:
2873		case GTPU_V4_FLOW:
2874		case GTPC_V4_FLOW:
2875		case GTPC_TEID_V4_FLOW:
2876		case GTPU_EH_V4_FLOW:
2877		case GTPU_UL_V4_FLOW:
2878		case GTPU_DL_V4_FLOW:
2879			if (nfc->data & RXH_IP_SRC)
2880				hfld |= ICE_FLOW_HASH_FLD_IPV4_SA;
2881			if (nfc->data & RXH_IP_DST)
2882				hfld |= ICE_FLOW_HASH_FLD_IPV4_DA;
2883			break;
2884		case TCP_V6_FLOW:
2885		case UDP_V6_FLOW:
2886		case SCTP_V6_FLOW:
2887		case GTPU_V6_FLOW:
2888		case GTPC_V6_FLOW:
2889		case GTPC_TEID_V6_FLOW:
2890		case GTPU_EH_V6_FLOW:
2891		case GTPU_UL_V6_FLOW:
2892		case GTPU_DL_V6_FLOW:
2893			if (nfc->data & RXH_IP_SRC)
2894				hfld |= ICE_FLOW_HASH_FLD_IPV6_SA;
2895			if (nfc->data & RXH_IP_DST)
2896				hfld |= ICE_FLOW_HASH_FLD_IPV6_DA;
2897			break;
2898		default:
2899			break;
2900		}
2901	}
2902
2903	if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) {
2904		switch (nfc->flow_type) {
2905		case TCP_V4_FLOW:
2906		case TCP_V6_FLOW:
2907			if (nfc->data & RXH_L4_B_0_1)
2908				hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT;
2909			if (nfc->data & RXH_L4_B_2_3)
2910				hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT;
2911			break;
2912		case UDP_V4_FLOW:
2913		case UDP_V6_FLOW:
2914			if (nfc->data & RXH_L4_B_0_1)
2915				hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT;
2916			if (nfc->data & RXH_L4_B_2_3)
2917				hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT;
2918			break;
2919		case SCTP_V4_FLOW:
2920		case SCTP_V6_FLOW:
2921			if (nfc->data & RXH_L4_B_0_1)
2922				hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT;
2923			if (nfc->data & RXH_L4_B_2_3)
2924				hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT;
2925			break;
2926		default:
2927			break;
2928		}
2929	}
2930
2931	if (nfc->data & RXH_GTP_TEID) {
2932		switch (nfc->flow_type) {
2933		case GTPC_TEID_V4_FLOW:
2934		case GTPC_TEID_V6_FLOW:
2935			hfld |= ICE_FLOW_HASH_FLD_GTPC_TEID;
2936			break;
2937		case GTPU_V4_FLOW:
2938		case GTPU_V6_FLOW:
2939			hfld |= ICE_FLOW_HASH_FLD_GTPU_IP_TEID;
2940			break;
2941		case GTPU_EH_V4_FLOW:
2942		case GTPU_EH_V6_FLOW:
2943			hfld |= ICE_FLOW_HASH_FLD_GTPU_EH_TEID;
2944			break;
2945		case GTPU_UL_V4_FLOW:
2946		case GTPU_UL_V6_FLOW:
2947			hfld |= ICE_FLOW_HASH_FLD_GTPU_UP_TEID;
2948			break;
2949		case GTPU_DL_V4_FLOW:
2950		case GTPU_DL_V6_FLOW:
2951			hfld |= ICE_FLOW_HASH_FLD_GTPU_DWN_TEID;
2952			break;
2953		default:
2954			break;
2955		}
2956	}
2957
2958	return hfld;
2959}
2960
2961static int
2962ice_set_rxfh_fields(struct net_device *netdev,
2963		    const struct ethtool_rxfh_fields *nfc,
2964		    struct netlink_ext_ack *extack)
2965{
2966	struct ice_netdev_priv *np = netdev_priv(netdev);
2967	struct ice_vsi *vsi = np->vsi;
2968	struct ice_pf *pf = vsi->back;
2969	struct ice_rss_hash_cfg cfg;
2970	struct device *dev;
2971	u64 hashed_flds;
2972	int status;
2973	bool symm;
2974	u32 hdrs;
2975
2976	dev = ice_pf_to_dev(pf);
2977	if (ice_is_safe_mode(pf)) {
2978		dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2979			vsi->vsi_num);
2980		return -EINVAL;
2981	}
2982
2983	symm = !!(vsi->rss_hfunc == ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ);
2984	hashed_flds = ice_parse_hash_flds(nfc, symm);
2985	if (hashed_flds == ICE_HASH_INVALID) {
2986		dev_dbg(dev, "Invalid hash fields, vsi num = %d\n",
2987			vsi->vsi_num);
2988		return -EINVAL;
2989	}
2990
2991	hdrs = ice_parse_hdrs(nfc);
2992	if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2993		dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2994			vsi->vsi_num);
2995		return -EINVAL;
2996	}
2997
2998	cfg.hash_flds = hashed_flds;
2999	cfg.addl_hdrs = hdrs;
3000	cfg.hdr_type = ICE_RSS_ANY_HEADERS;
3001	cfg.symm = symm;
3002
3003	status = ice_add_rss_cfg(&pf->hw, vsi, &cfg);
3004	if (status) {
3005		dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %d\n",
3006			vsi->vsi_num, status);
3007		return status;
3008	}
3009
3010	return 0;
3011}
3012
3013static int
3014ice_get_rxfh_fields(struct net_device *netdev, struct ethtool_rxfh_fields *nfc)
3015{
3016	struct ice_netdev_priv *np = netdev_priv(netdev);
3017	struct ice_vsi *vsi = np->vsi;
3018	struct ice_pf *pf = vsi->back;
3019	struct device *dev;
3020	u64 hash_flds;
3021	bool symm;
3022	u32 hdrs;
3023
3024	dev = ice_pf_to_dev(pf);
3025
3026	nfc->data = 0;
3027	if (ice_is_safe_mode(pf)) {
3028		dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
3029			vsi->vsi_num);
3030		return 0;
3031	}
3032
3033	hdrs = ice_parse_hdrs(nfc);
3034	if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
3035		dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
3036			vsi->vsi_num);
3037		return 0;
3038	}
3039
3040	hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs, &symm);
3041	if (hash_flds == ICE_HASH_INVALID) {
3042		dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n",
3043			vsi->vsi_num);
3044		return 0;
3045	}
3046
3047	if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA ||
3048	    hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA)
3049		nfc->data |= (u64)RXH_IP_SRC;
3050
3051	if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA ||
3052	    hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA)
3053		nfc->data |= (u64)RXH_IP_DST;
3054
3055	if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT ||
3056	    hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT ||
3057	    hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT)
3058		nfc->data |= (u64)RXH_L4_B_0_1;
3059
3060	if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT ||
3061	    hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT ||
3062	    hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)
3063		nfc->data |= (u64)RXH_L4_B_2_3;
3064
3065	if (hash_flds & ICE_FLOW_HASH_FLD_GTPC_TEID ||
3066	    hash_flds & ICE_FLOW_HASH_FLD_GTPU_IP_TEID ||
3067	    hash_flds & ICE_FLOW_HASH_FLD_GTPU_EH_TEID ||
3068	    hash_flds & ICE_FLOW_HASH_FLD_GTPU_UP_TEID ||
3069	    hash_flds & ICE_FLOW_HASH_FLD_GTPU_DWN_TEID)
3070		nfc->data |= (u64)RXH_GTP_TEID;
3071
3072	return 0;
3073}
3074
3075/**
3076 * ice_set_rxnfc - command to set Rx flow rules.
3077 * @netdev: network interface device structure
3078 * @cmd: ethtool rxnfc command
3079 *
3080 * Returns 0 for success and negative values for errors
3081 */
3082static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3083{
3084	struct ice_netdev_priv *np = netdev_priv(netdev);
3085	struct ice_vsi *vsi = np->vsi;
3086
3087	switch (cmd->cmd) {
3088	case ETHTOOL_SRXCLSRLINS:
3089		return ice_add_fdir_ethtool(vsi, cmd);
3090	case ETHTOOL_SRXCLSRLDEL:
3091		return ice_del_fdir_ethtool(vsi, cmd);
3092	default:
3093		break;
3094	}
3095	return -EOPNOTSUPP;
3096}
3097
3098/**
3099 * ice_get_rx_ring_count - get RX ring count
3100 * @netdev: network interface device structure
3101 *
3102 * Return: number of RX rings.
3103 */
3104static u32 ice_get_rx_ring_count(struct net_device *netdev)
3105{
3106	struct ice_netdev_priv *np = netdev_priv(netdev);
3107	struct ice_vsi *vsi = np->vsi;
3108
3109	return vsi->rss_size;
3110}
3111
3112/**
3113 * ice_get_rxnfc - command to get Rx flow classification rules
3114 * @netdev: network interface device structure
3115 * @cmd: ethtool rxnfc command
3116 * @rule_locs: buffer to rturn Rx flow classification rules
3117 *
3118 * Returns Success if the command is supported.
3119 */
3120static int
3121ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
3122	      u32 __always_unused *rule_locs)
3123{
3124	struct ice_netdev_priv *np = netdev_priv(netdev);
3125	struct ice_vsi *vsi = np->vsi;
3126	int ret = -EOPNOTSUPP;
3127	struct ice_hw *hw;
3128
3129	hw = &vsi->back->hw;
3130
3131	switch (cmd->cmd) {
3132	case ETHTOOL_GRXCLSRLCNT:
3133		cmd->rule_cnt = hw->fdir_active_fltr;
3134		/* report total rule count */
3135		cmd->data = ice_get_fdir_cnt_all(hw);
3136		ret = 0;
3137		break;
3138	case ETHTOOL_GRXCLSRULE:
3139		ret = ice_get_ethtool_fdir_entry(hw, cmd);
3140		break;
3141	case ETHTOOL_GRXCLSRLALL:
3142		ret = ice_get_fdir_fltr_ids(hw, cmd, (u32 *)rule_locs);
3143		break;
3144	default:
3145		break;
3146	}
3147
3148	return ret;
3149}
3150
3151static void
3152ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
3153		  struct kernel_ethtool_ringparam *kernel_ring,
3154		  struct netlink_ext_ack *extack)
3155{
3156	struct ice_netdev_priv *np = netdev_priv(netdev);
3157	struct ice_vsi *vsi = np->vsi;
3158	struct ice_hw *hw;
3159
3160	hw = &vsi->back->hw;
3161	ring->rx_max_pending = ICE_MAX_NUM_DESC_BY_MAC(hw);
3162	ring->tx_max_pending = ICE_MAX_NUM_DESC_BY_MAC(hw);
3163	if (vsi->tx_rings && vsi->rx_rings) {
3164		ring->rx_pending = vsi->rx_rings[0]->count;
3165		ring->tx_pending = vsi->tx_rings[0]->count;
3166	} else {
3167		ring->rx_pending = 0;
3168		ring->tx_pending = 0;
3169	}
3170
3171	/* Rx mini and jumbo rings are not supported */
3172	ring->rx_mini_max_pending = 0;
3173	ring->rx_jumbo_max_pending = 0;
3174	ring->rx_mini_pending = 0;
3175	ring->rx_jumbo_pending = 0;
3176
3177	kernel_ring->tcp_data_split = vsi->hsplit ?
3178				      ETHTOOL_TCP_DATA_SPLIT_ENABLED :
3179				      ETHTOOL_TCP_DATA_SPLIT_DISABLED;
3180}
3181
3182static int
3183ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
3184		  struct kernel_ethtool_ringparam *kernel_ring,
3185		  struct netlink_ext_ack *extack)
3186{
3187	struct ice_netdev_priv *np = netdev_priv(netdev);
3188	struct ice_tx_ring *xdp_rings = NULL;
3189	struct ice_tx_ring *tx_rings = NULL;
3190	struct ice_rx_ring *rx_rings = NULL;
3191	struct ice_vsi *vsi = np->vsi;
3192	struct ice_pf *pf = vsi->back;
3193	int i, timeout = 50, err = 0;
3194	struct ice_hw *hw = &pf->hw;
3195	u16 new_rx_cnt, new_tx_cnt;
3196	bool hsplit;
3197
3198	if (ring->tx_pending > ICE_MAX_NUM_DESC_BY_MAC(hw) ||
3199	    ring->tx_pending < ICE_MIN_NUM_DESC ||
3200	    ring->rx_pending > ICE_MAX_NUM_DESC_BY_MAC(hw) ||
3201	    ring->rx_pending < ICE_MIN_NUM_DESC) {
3202		netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
3203			   ring->tx_pending, ring->rx_pending,
3204			   ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC_BY_MAC(hw),
3205			   ICE_REQ_DESC_MULTIPLE);
3206		return -EINVAL;
3207	}
3208
3209	/* Return if there is no rings (device is reloading) */
3210	if (!vsi->tx_rings || !vsi->rx_rings)
3211		return -EBUSY;
3212
3213	new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
3214	if (new_tx_cnt != ring->tx_pending)
3215		netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n",
3216			    new_tx_cnt);
3217	new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
3218	if (new_rx_cnt != ring->rx_pending)
3219		netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n",
3220			    new_rx_cnt);
3221
3222	hsplit = kernel_ring->tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_ENABLED;
3223
3224	/* if nothing to do return success */
3225	if (new_tx_cnt == vsi->tx_rings[0]->count &&
3226	    new_rx_cnt == vsi->rx_rings[0]->count &&
3227	    hsplit == vsi->hsplit) {
3228		netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
3229		return 0;
3230	}
3231
3232	/* If there is a AF_XDP UMEM attached to any of Rx rings,
3233	 * disallow changing the number of descriptors -- regardless
3234	 * if the netdev is running or not.
3235	 */
3236	if (ice_xsk_any_rx_ring_ena(vsi))
3237		return -EBUSY;
3238
3239	while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
3240		timeout--;
3241		if (!timeout)
3242			return -EBUSY;
3243		usleep_range(1000, 2000);
3244	}
3245
3246	/* set for the next time the netdev is started */
3247	if (!netif_running(vsi->netdev)) {
3248		ice_for_each_alloc_txq(vsi, i)
3249			vsi->tx_rings[i]->count = new_tx_cnt;
3250		ice_for_each_alloc_rxq(vsi, i)
3251			vsi->rx_rings[i]->count = new_rx_cnt;
3252		if (ice_is_xdp_ena_vsi(vsi))
3253			ice_for_each_xdp_txq(vsi, i)
3254				vsi->xdp_rings[i]->count = new_tx_cnt;
3255		vsi->num_tx_desc = (u16)new_tx_cnt;
3256		vsi->num_rx_desc = (u16)new_rx_cnt;
3257		vsi->hsplit = hsplit;
3258
3259		netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
3260		goto done;
3261	}
3262
3263	if (new_tx_cnt == vsi->tx_rings[0]->count)
3264		goto process_rx;
3265
3266	/* alloc updated Tx resources */
3267	netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
3268		    vsi->tx_rings[0]->count, new_tx_cnt);
3269
3270	tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
3271	if (!tx_rings) {
3272		err = -ENOMEM;
3273		goto done;
3274	}
3275
3276	ice_for_each_txq(vsi, i) {
3277		/* clone ring and setup updated count */
3278		tx_rings[i] = *vsi->tx_rings[i];
3279		tx_rings[i].count = new_tx_cnt;
3280		tx_rings[i].desc = NULL;
3281		tx_rings[i].tx_buf = NULL;
3282		tx_rings[i].tstamp_ring = NULL;
3283		tx_rings[i].tx_tstamps = &pf->ptp.port.tx;
3284		err = ice_setup_tx_ring(&tx_rings[i]);
3285		if (err) {
3286			while (i--)
3287				ice_clean_tx_ring(&tx_rings[i]);
3288			kfree(tx_rings);
3289			goto done;
3290		}
3291	}
3292
3293	if (!ice_is_xdp_ena_vsi(vsi))
3294		goto process_rx;
3295
3296	/* alloc updated XDP resources */
3297	netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
3298		    vsi->xdp_rings[0]->count, new_tx_cnt);
3299
3300	xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
3301	if (!xdp_rings) {
3302		err = -ENOMEM;
3303		goto free_tx;
3304	}
3305
3306	ice_for_each_xdp_txq(vsi, i) {
3307		/* clone ring and setup updated count */
3308		xdp_rings[i] = *vsi->xdp_rings[i];
3309		xdp_rings[i].count = new_tx_cnt;
3310		xdp_rings[i].desc = NULL;
3311		xdp_rings[i].tx_buf = NULL;
3312		err = ice_setup_tx_ring(&xdp_rings[i]);
3313		if (err) {
3314			while (i--)
3315				ice_clean_tx_ring(&xdp_rings[i]);
3316			kfree(xdp_rings);
3317			goto free_tx;
3318		}
3319		ice_set_ring_xdp(&xdp_rings[i]);
3320	}
3321
3322process_rx:
3323	if (new_rx_cnt == vsi->rx_rings[0]->count)
3324		goto process_link;
3325
3326	/* alloc updated Rx resources */
3327	netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
3328		    vsi->rx_rings[0]->count, new_rx_cnt);
3329
3330	rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
3331	if (!rx_rings) {
3332		err = -ENOMEM;
3333		goto free_xdp;
3334	}
3335
3336	ice_for_each_rxq(vsi, i) {
3337		/* clone ring and setup updated count */
3338		rx_rings[i] = *vsi->rx_rings[i];
3339		rx_rings[i].count = new_rx_cnt;
3340		rx_rings[i].cached_phctime = pf->ptp.cached_phc_time;
3341		rx_rings[i].desc = NULL;
3342		rx_rings[i].xdp_buf = NULL;
3343		rx_rings[i].xdp_rxq = (struct xdp_rxq_info){ };
3344
3345		/* this is to allow wr32 to have something to write to
3346		 * during early allocation of Rx buffers
3347		 */
3348		rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
3349
3350		err = ice_setup_rx_ring(&rx_rings[i]);
3351		if (err)
3352			goto rx_unwind;
3353rx_unwind:
3354		if (err) {
3355			while (i) {
3356				i--;
3357				ice_free_rx_ring(&rx_rings[i]);
3358			}
3359			kfree(rx_rings);
3360			err = -ENOMEM;
3361			goto free_xdp;
3362		}
3363	}
3364
3365process_link:
3366	vsi->hsplit = hsplit;
3367
3368	/* Bring interface down, copy in the new ring info, then restore the
3369	 * interface. if VSI is up, bring it down and then back up
3370	 */
3371	if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
3372		ice_down(vsi);
3373
3374		if (tx_rings) {
3375			ice_for_each_txq(vsi, i) {
3376				ice_free_tx_ring(vsi->tx_rings[i]);
3377				*vsi->tx_rings[i] = tx_rings[i];
3378			}
3379			kfree(tx_rings);
3380		}
3381
3382		if (rx_rings) {
3383			ice_for_each_rxq(vsi, i) {
3384				ice_free_rx_ring(vsi->rx_rings[i]);
3385				/* copy the real tail offset */
3386				rx_rings[i].tail = vsi->rx_rings[i]->tail;
3387				/* this is to fake out the allocation routine
3388				 * into thinking it has to realloc everything
3389				 * but the recycling logic will let us re-use
3390				 * the buffers allocated above
3391				 */
3392				rx_rings[i].next_to_use = 0;
3393				rx_rings[i].next_to_clean = 0;
3394				rx_rings[i].next_to_alloc = 0;
3395				*vsi->rx_rings[i] = rx_rings[i];
3396			}
3397			kfree(rx_rings);
3398		}
3399
3400		if (xdp_rings) {
3401			ice_for_each_xdp_txq(vsi, i) {
3402				ice_free_tx_ring(vsi->xdp_rings[i]);
3403				*vsi->xdp_rings[i] = xdp_rings[i];
3404			}
3405			kfree(xdp_rings);
3406		}
3407
3408		vsi->num_tx_desc = new_tx_cnt;
3409		vsi->num_rx_desc = new_rx_cnt;
3410		ice_up(vsi);
3411	}
3412	goto done;
3413
3414free_xdp:
3415	if (xdp_rings) {
3416		ice_for_each_xdp_txq(vsi, i)
3417			ice_free_tx_ring(&xdp_rings[i]);
3418		kfree(xdp_rings);
3419	}
3420
3421free_tx:
3422	/* error cleanup if the Rx allocations failed after getting Tx */
3423	if (tx_rings) {
3424		ice_for_each_txq(vsi, i)
3425			ice_free_tx_ring(&tx_rings[i]);
3426		kfree(tx_rings);
3427	}
3428
3429done:
3430	clear_bit(ICE_CFG_BUSY, pf->state);
3431	return err;
3432}
3433
3434/**
3435 * ice_get_pauseparam - Get Flow Control status
3436 * @netdev: network interface device structure
3437 * @pause: ethernet pause (flow control) parameters
3438 *
3439 * Get requested flow control status from PHY capability.
3440 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
3441 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
3442 * the negotiated Rx/Tx pause via lp_advertising.
3443 */
3444static void
3445ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
3446{
3447	struct ice_netdev_priv *np = netdev_priv(netdev);
3448	struct ice_port_info *pi = np->vsi->port_info;
3449	struct ice_aqc_get_phy_caps_data *pcaps;
3450	struct ice_dcbx_cfg *dcbx_cfg;
3451	int status;
3452
3453	/* Initialize pause params */
3454	pause->rx_pause = 0;
3455	pause->tx_pause = 0;
3456
3457	dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
3458
3459	pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
3460	if (!pcaps)
3461		return;
3462
3463	/* Get current PHY config */
3464	status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
3465				     NULL);
3466	if (status)
3467		goto out;
3468
3469	pause->autoneg = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
3470							     AUTONEG_DISABLE;
3471
3472	if (dcbx_cfg->pfc.pfcena)
3473		/* PFC enabled so report LFC as off */
3474		goto out;
3475
3476	if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
3477		pause->tx_pause = 1;
3478	if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
3479		pause->rx_pause = 1;
3480
3481out:
3482	kfree(pcaps);
3483}
3484
3485/**
3486 * ice_set_pauseparam - Set Flow Control parameter
3487 * @netdev: network interface device structure
3488 * @pause: return Tx/Rx flow control status
3489 */
3490static int
3491ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
3492{
3493	struct ice_netdev_priv *np = netdev_priv(netdev);
3494	struct ice_aqc_get_phy_caps_data *pcaps;
3495	struct ice_link_status *hw_link_info;
3496	struct ice_pf *pf = np->vsi->back;
3497	struct ice_dcbx_cfg *dcbx_cfg;
3498	struct ice_vsi *vsi = np->vsi;
3499	struct ice_hw *hw = &pf->hw;
3500	struct ice_port_info *pi;
3501	u8 aq_failures;
3502	bool link_up;
3503	u32 is_an;
3504	int err;
3505
3506	pi = vsi->port_info;
3507	hw_link_info = &pi->phy.link_info;
3508	dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
3509	link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
3510
3511	/* Changing the port's flow control is not supported if this isn't the
3512	 * PF VSI
3513	 */
3514	if (vsi->type != ICE_VSI_PF) {
3515		netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
3516		return -EOPNOTSUPP;
3517	}
3518
3519	/* Get pause param reports configured and negotiated flow control pause
3520	 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
3521	 * defined get pause param pause->autoneg reports SW configured setting,
3522	 * so compare pause->autoneg with SW configured to prevent the user from
3523	 * using set pause param to chance autoneg.
3524	 */
3525	pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
3526	if (!pcaps)
3527		return -ENOMEM;
3528
3529	/* Get current PHY config */
3530	err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
3531				  NULL);
3532	if (err) {
3533		kfree(pcaps);
3534		return err;
3535	}
3536
3537	is_an = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
3538						    AUTONEG_DISABLE;
3539
3540	kfree(pcaps);
3541
3542	if (pause->autoneg != is_an) {
3543		netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
3544		return -EOPNOTSUPP;
3545	}
3546
3547	/* If we have link and don't have autoneg */
3548	if (!test_bit(ICE_DOWN, pf->state) &&
3549	    !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
3550		/* Send message that it might not necessarily work*/
3551		netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
3552	}
3553
3554	if (dcbx_cfg->pfc.pfcena) {
3555		netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
3556		return -EOPNOTSUPP;
3557	}
3558	if (pause->rx_pause && pause->tx_pause)
3559		pi->fc.req_mode = ICE_FC_FULL;
3560	else if (pause->rx_pause && !pause->tx_pause)
3561		pi->fc.req_mode = ICE_FC_RX_PAUSE;
3562	else if (!pause->rx_pause && pause->tx_pause)
3563		pi->fc.req_mode = ICE_FC_TX_PAUSE;
3564	else if (!pause->rx_pause && !pause->tx_pause)
3565		pi->fc.req_mode = ICE_FC_NONE;
3566	else
3567		return -EINVAL;
3568
3569	/* Set the FC mode and only restart AN if link is up */
3570	err = ice_set_fc(pi, &aq_failures, link_up);
3571
3572	if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
3573		netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %s\n",
3574			    err, libie_aq_str(hw->adminq.sq_last_status));
3575		err = -EAGAIN;
3576	} else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
3577		netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %s\n",
3578			    err, libie_aq_str(hw->adminq.sq_last_status));
3579		err = -EAGAIN;
3580	} else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
3581		netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %s\n",
3582			    err, libie_aq_str(hw->adminq.sq_last_status));
3583		err = -EAGAIN;
3584	}
3585
3586	return err;
3587}
3588
3589/**
3590 * ice_get_rxfh_key_size - get the RSS hash key size
3591 * @netdev: network interface device structure
3592 *
3593 * Returns the table size.
3594 */
3595static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
3596{
3597	return ICE_VSIQF_HKEY_ARRAY_SIZE;
3598}
3599
3600/**
3601 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
3602 * @netdev: network interface device structure
3603 *
3604 * Returns the table size.
3605 */
3606static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
3607{
3608	struct ice_netdev_priv *np = netdev_priv(netdev);
3609
3610	return np->vsi->rss_table_size;
3611}
3612
3613/**
3614 * ice_get_rxfh - get the Rx flow hash indirection table
3615 * @netdev: network interface device structure
3616 * @rxfh: pointer to param struct (indir, key, hfunc)
3617 *
3618 * Reads the indirection table directly from the hardware.
3619 */
3620static int
3621ice_get_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh)
3622{
3623	struct ice_netdev_priv *np = netdev_priv(netdev);
3624	struct ice_vsi *vsi = np->vsi;
3625	struct ice_pf *pf = vsi->back;
3626	u16 qcount, offset;
3627	int err, i;
3628	u8 *lut;
3629
3630	if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3631		netdev_warn(netdev, "RSS is not supported on this VSI!\n");
3632		return -EOPNOTSUPP;
3633	}
3634
3635	qcount = vsi->mqprio_qopt.qopt.count[0];
3636	offset = vsi->mqprio_qopt.qopt.offset[0];
3637
3638	rxfh->hfunc = ETH_RSS_HASH_TOP;
3639	if (vsi->rss_hfunc == ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ)
3640		rxfh->input_xfrm |= RXH_XFRM_SYM_XOR;
3641
3642	if (!rxfh->indir)
3643		return 0;
3644
3645	lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3646	if (!lut)
3647		return -ENOMEM;
3648
3649	err = ice_get_rss(vsi, rxfh->key, lut, vsi->rss_table_size);
3650	if (err)
3651		goto out;
3652
3653	if (ice_is_adq_active(pf)) {
3654		for (i = 0; i < vsi->rss_table_size; i++)
3655			rxfh->indir[i] = offset + lut[i] % qcount;
3656		goto out;
3657	}
3658
3659	for (i = 0; i < vsi->rss_table_size; i++)
3660		rxfh->indir[i] = lut[i];
3661
3662out:
3663	kfree(lut);
3664	return err;
3665}
3666
3667/**
3668 * ice_set_rxfh - set the Rx flow hash indirection table
3669 * @netdev: network interface device structure
3670 * @rxfh: pointer to param struct (indir, key, hfunc)
3671 * @extack: extended ACK from the Netlink message
3672 *
3673 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3674 * returns 0 after programming the table.
3675 */
3676static int
3677ice_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh,
3678	     struct netlink_ext_ack *extack)
3679{
3680	struct ice_netdev_priv *np = netdev_priv(netdev);
3681	u8 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
3682	struct ice_vsi *vsi = np->vsi;
3683	struct ice_pf *pf = vsi->back;
3684	struct device *dev;
3685	int err;
3686
3687	dev = ice_pf_to_dev(pf);
3688	if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
3689	    rxfh->hfunc != ETH_RSS_HASH_TOP)
3690		return -EOPNOTSUPP;
3691
3692	if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3693		/* RSS not supported return error here */
3694		netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3695		return -EIO;
3696	}
3697
3698	if (ice_is_adq_active(pf)) {
3699		netdev_err(netdev, "Cannot change RSS params with ADQ configured.\n");
3700		return -EOPNOTSUPP;
3701	}
3702
3703	/* Update the VSI's hash function */
3704	if (rxfh->input_xfrm & RXH_XFRM_SYM_XOR)
3705		hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ;
3706
3707	err = ice_set_rss_hfunc(vsi, hfunc);
3708	if (err)
3709		return err;
3710
3711	if (rxfh->key) {
3712		if (!vsi->rss_hkey_user) {
3713			vsi->rss_hkey_user =
3714				devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE,
3715					     GFP_KERNEL);
3716			if (!vsi->rss_hkey_user)
3717				return -ENOMEM;
3718		}
3719		memcpy(vsi->rss_hkey_user, rxfh->key,
3720		       ICE_VSIQF_HKEY_ARRAY_SIZE);
3721
3722		err = ice_set_rss_key(vsi, vsi->rss_hkey_user);
3723		if (err)
3724			return err;
3725	}
3726
3727	if (!vsi->rss_lut_user) {
3728		vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size,
3729						 GFP_KERNEL);
3730		if (!vsi->rss_lut_user)
3731			return -ENOMEM;
3732	}
3733
3734	/* Each 32 bits pointed by 'indir' is stored with a lut entry */
3735	if (rxfh->indir) {
3736		int i;
3737
3738		for (i = 0; i < vsi->rss_table_size; i++)
3739			vsi->rss_lut_user[i] = (u8)(rxfh->indir[i]);
3740	} else {
3741		ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3742				 vsi->rss_size);
3743	}
3744
3745	err = ice_set_rss_lut(vsi, vsi->rss_lut_user, vsi->rss_table_size);
3746	if (err)
3747		return err;
3748
3749	return 0;
3750}
3751
3752static int
3753ice_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info)
3754{
3755	struct ice_pf *pf = ice_netdev_to_pf(dev);
3756
3757	/* only report timestamping if PTP is enabled */
3758	if (pf->ptp.state != ICE_PTP_READY)
3759		return ethtool_op_get_ts_info(dev, info);
3760
3761	info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
3762				SOF_TIMESTAMPING_TX_HARDWARE |
3763				SOF_TIMESTAMPING_RX_HARDWARE |
3764				SOF_TIMESTAMPING_RAW_HARDWARE;
3765
3766	info->phc_index = ice_ptp_clock_index(pf);
3767
3768	info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
3769
3770	info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL);
3771
3772	return 0;
3773}
3774
3775/**
3776 * ice_get_max_txq - return the maximum number of Tx queues for in a PF
3777 * @pf: PF structure
3778 */
3779static int ice_get_max_txq(struct ice_pf *pf)
3780{
3781	return min(num_online_cpus(), pf->hw.func_caps.common_cap.num_txq);
3782}
3783
3784/**
3785 * ice_get_max_rxq - return the maximum number of Rx queues for in a PF
3786 * @pf: PF structure
3787 */
3788static int ice_get_max_rxq(struct ice_pf *pf)
3789{
3790	return min(num_online_cpus(), pf->hw.func_caps.common_cap.num_rxq);
3791}
3792
3793/**
3794 * ice_get_combined_cnt - return the current number of combined channels
3795 * @vsi: PF VSI pointer
3796 *
3797 * Go through all queue vectors and count ones that have both Rx and Tx ring
3798 * attached
3799 */
3800static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
3801{
3802	u32 combined = 0;
3803	int q_idx;
3804
3805	ice_for_each_q_vector(vsi, q_idx) {
3806		struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3807
3808		combined += min(q_vector->num_ring_tx, q_vector->num_ring_rx);
3809	}
3810
3811	return combined;
3812}
3813
3814/**
3815 * ice_get_channels - get the current and max supported channels
3816 * @dev: network interface device structure
3817 * @ch: ethtool channel data structure
3818 */
3819static void
3820ice_get_channels(struct net_device *dev, struct ethtool_channels *ch)
3821{
3822	struct ice_netdev_priv *np = netdev_priv(dev);
3823	struct ice_vsi *vsi = np->vsi;
3824	struct ice_pf *pf = vsi->back;
3825
3826	/* report maximum channels */
3827	ch->max_rx = ice_get_max_rxq(pf);
3828	ch->max_tx = ice_get_max_txq(pf);
3829	ch->max_combined = min_t(int, ch->max_rx, ch->max_tx);
3830
3831	/* report current channels */
3832	ch->combined_count = ice_get_combined_cnt(vsi);
3833	ch->rx_count = vsi->num_rxq - ch->combined_count;
3834	ch->tx_count = vsi->num_txq - ch->combined_count;
3835
3836	/* report other queues */
3837	ch->other_count = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
3838	ch->max_other = ch->other_count;
3839}
3840
3841/**
3842 * ice_get_valid_rss_size - return valid number of RSS queues
3843 * @hw: pointer to the HW structure
3844 * @new_size: requested RSS queues
3845 */
3846static int ice_get_valid_rss_size(struct ice_hw *hw, int new_size)
3847{
3848	struct ice_hw_common_caps *caps = &hw->func_caps.common_cap;
3849
3850	return min_t(int, new_size, BIT(caps->rss_table_entry_width));
3851}
3852
3853/**
3854 * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size
3855 * @vsi: VSI to reconfigure RSS LUT on
3856 * @req_rss_size: requested range of queue numbers for hashing
3857 *
3858 * Set the VSI's RSS parameters, configure the RSS LUT based on these.
3859 */
3860static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size)
3861{
3862	struct ice_pf *pf = vsi->back;
3863	struct device *dev;
3864	struct ice_hw *hw;
3865	int err;
3866	u8 *lut;
3867
3868	dev = ice_pf_to_dev(pf);
3869	hw = &pf->hw;
3870
3871	if (!req_rss_size)
3872		return -EINVAL;
3873
3874	lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3875	if (!lut)
3876		return -ENOMEM;
3877
3878	/* set RSS LUT parameters */
3879	if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
3880		vsi->rss_size = 1;
3881	else
3882		vsi->rss_size = ice_get_valid_rss_size(hw, req_rss_size);
3883
3884	/* create/set RSS LUT */
3885	ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
3886	err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size);
3887	if (err)
3888		dev_err(dev, "Cannot set RSS lut, err %d aq_err %s\n", err,
3889			libie_aq_str(hw->adminq.sq_last_status));
3890
3891	kfree(lut);
3892	return err;
3893}
3894
3895/**
3896 * ice_set_channels - set the number channels
3897 * @dev: network interface device structure
3898 * @ch: ethtool channel data structure
3899 */
3900static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
3901{
3902	struct ice_netdev_priv *np = netdev_priv(dev);
3903	struct ice_vsi *vsi = np->vsi;
3904	struct ice_pf *pf = vsi->back;
3905	int new_rx = 0, new_tx = 0;
3906	bool locked = false;
3907	int ret = 0;
3908
3909	/* do not support changing channels in Safe Mode */
3910	if (ice_is_safe_mode(pf)) {
3911		netdev_err(dev, "Changing channel in Safe Mode is not supported\n");
3912		return -EOPNOTSUPP;
3913	}
3914	/* do not support changing other_count */
3915	if (ch->other_count != (test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1U : 0U))
3916		return -EINVAL;
3917
3918	if (ice_is_adq_active(pf)) {
3919		netdev_err(dev, "Cannot set channels with ADQ configured.\n");
3920		return -EOPNOTSUPP;
3921	}
3922
3923	if (test_bit(ICE_FLAG_FD_ENA, pf->flags) && pf->hw.fdir_active_fltr) {
3924		netdev_err(dev, "Cannot set channels when Flow Director filters are active\n");
3925		return -EOPNOTSUPP;
3926	}
3927
3928	if (ch->rx_count && ch->tx_count) {
3929		netdev_err(dev, "Dedicated RX or TX channels cannot be used simultaneously\n");
3930		return -EINVAL;
3931	}
3932
3933	new_rx = ch->combined_count + ch->rx_count;
3934	new_tx = ch->combined_count + ch->tx_count;
3935
3936	if (new_rx < vsi->tc_cfg.numtc) {
3937		netdev_err(dev, "Cannot set less Rx channels, than Traffic Classes you have (%u)\n",
3938			   vsi->tc_cfg.numtc);
3939		return -EINVAL;
3940	}
3941	if (new_tx < vsi->tc_cfg.numtc) {
3942		netdev_err(dev, "Cannot set less Tx channels, than Traffic Classes you have (%u)\n",
3943			   vsi->tc_cfg.numtc);
3944		return -EINVAL;
3945	}
3946	if (new_rx > ice_get_max_rxq(pf)) {
3947		netdev_err(dev, "Maximum allowed Rx channels is %d\n",
3948			   ice_get_max_rxq(pf));
3949		return -EINVAL;
3950	}
3951	if (new_tx > ice_get_max_txq(pf)) {
3952		netdev_err(dev, "Maximum allowed Tx channels is %d\n",
3953			   ice_get_max_txq(pf));
3954		return -EINVAL;
3955	}
3956
3957	if (pf->cdev_info && pf->cdev_info->adev) {
3958		mutex_lock(&pf->adev_mutex);
3959		device_lock(&pf->cdev_info->adev->dev);
3960		locked = true;
3961		if (pf->cdev_info->adev->dev.driver) {
3962			netdev_err(dev, "Cannot change channels when RDMA is active\n");
3963			ret = -EBUSY;
3964			goto adev_unlock;
3965		}
3966	}
3967
3968	ice_vsi_recfg_qs(vsi, new_rx, new_tx, locked);
3969
3970	if (!netif_is_rxfh_configured(dev)) {
3971		ret = ice_vsi_set_dflt_rss_lut(vsi, new_rx);
3972		goto adev_unlock;
3973	}
3974
3975	/* Update rss_size due to change in Rx queues */
3976	vsi->rss_size = ice_get_valid_rss_size(&pf->hw, new_rx);
3977
3978adev_unlock:
3979	if (locked) {
3980		device_unlock(&pf->cdev_info->adev->dev);
3981		mutex_unlock(&pf->adev_mutex);
3982	}
3983	return ret;
3984}
3985
3986/**
3987 * ice_get_wol - get current Wake on LAN configuration
3988 * @netdev: network interface device structure
3989 * @wol: Ethtool structure to retrieve WoL settings
3990 */
3991static void ice_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3992{
3993	struct ice_netdev_priv *np = netdev_priv(netdev);
3994	struct ice_pf *pf = np->vsi->back;
3995
3996	if (np->vsi->type != ICE_VSI_PF)
3997		netdev_warn(netdev, "Wake on LAN is not supported on this interface!\n");
3998
3999	/* Get WoL settings based on the HW capability */
4000	if (ice_is_wol_supported(&pf->hw)) {
4001		wol->supported = WAKE_MAGIC;
4002		wol->wolopts = pf->wol_ena ? WAKE_MAGIC : 0;
4003	} else {
4004		wol->supported = 0;
4005		wol->wolopts = 0;
4006	}
4007}
4008
4009/**
4010 * ice_set_wol - set Wake on LAN on supported device
4011 * @netdev: network interface device structure
4012 * @wol: Ethtool structure to set WoL
4013 */
4014static int ice_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
4015{
4016	struct ice_netdev_priv *np = netdev_priv(netdev);
4017	struct ice_vsi *vsi = np->vsi;
4018	struct ice_pf *pf = vsi->back;
4019
4020	if (vsi->type != ICE_VSI_PF || !ice_is_wol_supported(&pf->hw))
4021		return -EOPNOTSUPP;
4022
4023	/* only magic packet is supported */
4024	if (wol->wolopts && wol->wolopts != WAKE_MAGIC)
4025		return -EOPNOTSUPP;
4026
4027	/* Set WoL only if there is a new value */
4028	if (pf->wol_ena != !!wol->wolopts) {
4029		pf->wol_ena = !!wol->wolopts;
4030		device_set_wakeup_enable(ice_pf_to_dev(pf), pf->wol_ena);
4031		netdev_dbg(netdev, "WoL magic packet %sabled\n",
4032			   pf->wol_ena ? "en" : "dis");
4033	}
4034
4035	return 0;
4036}
4037
4038/**
4039 * ice_get_rc_coalesce - get ITR values for specific ring container
4040 * @ec: ethtool structure to fill with driver's coalesce settings
4041 * @rc: ring container that the ITR values will come from
4042 *
4043 * Query the device for ice_ring_container specific ITR values. This is
4044 * done per ice_ring_container because each q_vector can have 1 or more rings
4045 * and all of said ring(s) will have the same ITR values.
4046 *
4047 * Returns 0 on success, negative otherwise.
4048 */
4049static int
4050ice_get_rc_coalesce(struct ethtool_coalesce *ec, struct ice_ring_container *rc)
4051{
4052	if (!rc->rx_ring)
4053		return -EINVAL;
4054
4055	switch (rc->type) {
4056	case ICE_RX_CONTAINER:
4057		ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc);
4058		ec->rx_coalesce_usecs = rc->itr_setting;
4059		ec->rx_coalesce_usecs_high = rc->rx_ring->q_vector->intrl;
4060		break;
4061	case ICE_TX_CONTAINER:
4062		ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc);
4063		ec->tx_coalesce_usecs = rc->itr_setting;
4064		break;
4065	default:
4066		dev_dbg(ice_pf_to_dev(rc->rx_ring->vsi->back), "Invalid c_type %d\n", rc->type);
4067		return -EINVAL;
4068	}
4069
4070	return 0;
4071}
4072
4073/**
4074 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
4075 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
4076 * @ec: coalesce settings to program the device with
4077 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
4078 *
4079 * Return 0 on success, and negative under the following conditions:
4080 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
4081 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
4082 */
4083static int
4084ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
4085{
4086	if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
4087		if (ice_get_rc_coalesce(ec,
4088					&vsi->rx_rings[q_num]->q_vector->rx))
4089			return -EINVAL;
4090		if (ice_get_rc_coalesce(ec,
4091					&vsi->tx_rings[q_num]->q_vector->tx))
4092			return -EINVAL;
4093	} else if (q_num < vsi->num_rxq) {
4094		if (ice_get_rc_coalesce(ec,
4095					&vsi->rx_rings[q_num]->q_vector->rx))
4096			return -EINVAL;
4097	} else if (q_num < vsi->num_txq) {
4098		if (ice_get_rc_coalesce(ec,
4099					&vsi->tx_rings[q_num]->q_vector->tx))
4100			return -EINVAL;
4101	} else {
4102		return -EINVAL;
4103	}
4104
4105	return 0;
4106}
4107
4108/**
4109 * __ice_get_coalesce - get ITR/INTRL values for the device
4110 * @netdev: pointer to the netdev associated with this query
4111 * @ec: ethtool structure to fill with driver's coalesce settings
4112 * @q_num: queue number to get the coalesce settings for
4113 *
4114 * If the caller passes in a negative q_num then we return coalesce settings
4115 * based on queue number 0, else use the actual q_num passed in.
4116 */
4117static int
4118__ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
4119		   int q_num)
4120{
4121	struct ice_netdev_priv *np = netdev_priv(netdev);
4122	struct ice_vsi *vsi = np->vsi;
4123
4124	if (q_num < 0)
4125		q_num = 0;
4126
4127	if (ice_get_q_coalesce(vsi, ec, q_num))
4128		return -EINVAL;
4129
4130	return 0;
4131}
4132
4133static int ice_get_coalesce(struct net_device *netdev,
4134			    struct ethtool_coalesce *ec,
4135			    struct kernel_ethtool_coalesce *kernel_coal,
4136			    struct netlink_ext_ack *extack)
4137{
4138	return __ice_get_coalesce(netdev, ec, -1);
4139}
4140
4141static int
4142ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
4143		       struct ethtool_coalesce *ec)
4144{
4145	return __ice_get_coalesce(netdev, ec, q_num);
4146}
4147
4148/**
4149 * ice_set_rc_coalesce - set ITR values for specific ring container
4150 * @ec: ethtool structure from user to update ITR settings
4151 * @rc: ring container that the ITR values will come from
4152 * @vsi: VSI associated to the ring container
4153 *
4154 * Set specific ITR values. This is done per ice_ring_container because each
4155 * q_vector can have 1 or more rings and all of said ring(s) will have the same
4156 * ITR values.
4157 *
4158 * Returns 0 on success, negative otherwise.
4159 */
4160static int
4161ice_set_rc_coalesce(struct ethtool_coalesce *ec,
4162		    struct ice_ring_container *rc, struct ice_vsi *vsi)
4163{
4164	const char *c_type_str = (rc->type == ICE_RX_CONTAINER) ? "rx" : "tx";
4165	u32 use_adaptive_coalesce, coalesce_usecs;
4166	struct ice_pf *pf = vsi->back;
4167	u16 itr_setting;
4168
4169	if (!rc->rx_ring)
4170		return -EINVAL;
4171
4172	switch (rc->type) {
4173	case ICE_RX_CONTAINER:
4174	{
4175		struct ice_q_vector *q_vector = rc->rx_ring->q_vector;
4176
4177		if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
4178		    (ec->rx_coalesce_usecs_high &&
4179		     ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
4180			netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
4181				    c_type_str, pf->hw.intrl_gran,
4182				    ICE_MAX_INTRL);
4183			return -EINVAL;
4184		}
4185		if (ec->rx_coalesce_usecs_high != q_vector->intrl &&
4186		    (ec->use_adaptive_rx_coalesce || ec->use_adaptive_tx_coalesce)) {
4187			netdev_info(vsi->netdev, "Invalid value, %s-usecs-high cannot be changed if adaptive-tx or adaptive-rx is enabled\n",
4188				    c_type_str);
4189			return -EINVAL;
4190		}
4191		if (ec->rx_coalesce_usecs_high != q_vector->intrl)
4192			q_vector->intrl = ec->rx_coalesce_usecs_high;
4193
4194		use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
4195		coalesce_usecs = ec->rx_coalesce_usecs;
4196
4197		break;
4198	}
4199	case ICE_TX_CONTAINER:
4200		use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
4201		coalesce_usecs = ec->tx_coalesce_usecs;
4202
4203		break;
4204	default:
4205		dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n",
4206			rc->type);
4207		return -EINVAL;
4208	}
4209
4210	itr_setting = rc->itr_setting;
4211	if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
4212		netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
4213			    c_type_str, c_type_str);
4214		return -EINVAL;
4215	}
4216
4217	if (coalesce_usecs > ICE_ITR_MAX) {
4218		netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n",
4219			    c_type_str, ICE_ITR_MAX);
4220		return -EINVAL;
4221	}
4222
4223	if (use_adaptive_coalesce) {
4224		rc->itr_mode = ITR_DYNAMIC;
4225	} else {
4226		rc->itr_mode = ITR_STATIC;
4227		/* store user facing value how it was set */
4228		rc->itr_setting = coalesce_usecs;
4229		/* write the change to the register */
4230		ice_write_itr(rc, coalesce_usecs);
4231		/* force writes to take effect immediately, the flush shouldn't
4232		 * be done in the functions above because the intent is for
4233		 * them to do lazy writes.
4234		 */
4235		ice_flush(&pf->hw);
4236	}
4237
4238	return 0;
4239}
4240
4241/**
4242 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
4243 * @vsi: VSI associated to the queue that need updating
4244 * @ec: coalesce settings to program the device with
4245 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
4246 *
4247 * Return 0 on success, and negative under the following conditions:
4248 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
4249 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
4250 */
4251static int
4252ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
4253{
4254	if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
4255		if (ice_set_rc_coalesce(ec,
4256					&vsi->rx_rings[q_num]->q_vector->rx,
4257					vsi))
4258			return -EINVAL;
4259
4260		if (ice_set_rc_coalesce(ec,
4261					&vsi->tx_rings[q_num]->q_vector->tx,
4262					vsi))
4263			return -EINVAL;
4264	} else if (q_num < vsi->num_rxq) {
4265		if (ice_set_rc_coalesce(ec,
4266					&vsi->rx_rings[q_num]->q_vector->rx,
4267					vsi))
4268			return -EINVAL;
4269	} else if (q_num < vsi->num_txq) {
4270		if (ice_set_rc_coalesce(ec,
4271					&vsi->tx_rings[q_num]->q_vector->tx,
4272					vsi))
4273			return -EINVAL;
4274	} else {
4275		return -EINVAL;
4276	}
4277
4278	return 0;
4279}
4280
4281/**
4282 * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs
4283 * @netdev: netdev used for print
4284 * @itr_setting: previous user setting
4285 * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled
4286 * @coalesce_usecs: requested value of [tx|rx]-usecs
4287 * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs
4288 */
4289static void
4290ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting,
4291		       u32 use_adaptive_coalesce, u32 coalesce_usecs,
4292		       const char *c_type_str)
4293{
4294	if (use_adaptive_coalesce)
4295		return;
4296
4297	if (itr_setting != coalesce_usecs && (coalesce_usecs % 2))
4298		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",
4299			    c_type_str, coalesce_usecs, c_type_str,
4300			    ITR_REG_ALIGN(coalesce_usecs));
4301}
4302
4303/**
4304 * __ice_set_coalesce - set ITR/INTRL values for the device
4305 * @netdev: pointer to the netdev associated with this query
4306 * @ec: ethtool structure to fill with driver's coalesce settings
4307 * @q_num: queue number to get the coalesce settings for
4308 *
4309 * If the caller passes in a negative q_num then we set the coalesce settings
4310 * for all Tx/Rx queues, else use the actual q_num passed in.
4311 */
4312static int
4313__ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
4314		   int q_num)
4315{
4316	struct ice_netdev_priv *np = netdev_priv(netdev);
4317	struct ice_vsi *vsi = np->vsi;
4318
4319	if (q_num < 0) {
4320		struct ice_q_vector *q_vector = vsi->q_vectors[0];
4321		int v_idx;
4322
4323		if (q_vector) {
4324			ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting,
4325					       ec->use_adaptive_rx_coalesce,
4326					       ec->rx_coalesce_usecs, "rx");
4327
4328			ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting,
4329					       ec->use_adaptive_tx_coalesce,
4330					       ec->tx_coalesce_usecs, "tx");
4331		}
4332
4333		ice_for_each_q_vector(vsi, v_idx) {
4334			/* In some cases if DCB is configured the num_[rx|tx]q
4335			 * can be less than vsi->num_q_vectors. This check
4336			 * accounts for that so we don't report a false failure
4337			 */
4338			if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq)
4339				goto set_complete;
4340
4341			if (ice_set_q_coalesce(vsi, ec, v_idx))
4342				return -EINVAL;
4343
4344			ice_set_q_vector_intrl(vsi->q_vectors[v_idx]);
4345		}
4346		goto set_complete;
4347	}
4348
4349	if (ice_set_q_coalesce(vsi, ec, q_num))
4350		return -EINVAL;
4351
4352	ice_set_q_vector_intrl(vsi->q_vectors[q_num]);
4353
4354set_complete:
4355	return 0;
4356}
4357
4358static int ice_set_coalesce(struct net_device *netdev,
4359			    struct ethtool_coalesce *ec,
4360			    struct kernel_ethtool_coalesce *kernel_coal,
4361			    struct netlink_ext_ack *extack)
4362{
4363	return __ice_set_coalesce(netdev, ec, -1);
4364}
4365
4366static int
4367ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
4368		       struct ethtool_coalesce *ec)
4369{
4370	return __ice_set_coalesce(netdev, ec, q_num);
4371}
4372
4373static void
4374ice_repr_get_drvinfo(struct net_device *netdev,
4375		     struct ethtool_drvinfo *drvinfo)
4376{
4377	struct ice_repr *repr = ice_netdev_to_repr(netdev);
4378
4379	if (repr->ops.ready(repr))
4380		return;
4381
4382	__ice_get_drvinfo(netdev, drvinfo, repr->src_vsi);
4383}
4384
4385static void
4386ice_repr_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
4387{
4388	struct ice_repr *repr = ice_netdev_to_repr(netdev);
4389
4390	/* for port representors only ETH_SS_STATS is supported */
4391	if (repr->ops.ready(repr) || stringset != ETH_SS_STATS)
4392		return;
4393
4394	__ice_get_strings(netdev, stringset, data, repr->src_vsi);
4395}
4396
4397static void
4398ice_repr_get_ethtool_stats(struct net_device *netdev,
4399			   struct ethtool_stats __always_unused *stats,
4400			   u64 *data)
4401{
4402	struct ice_repr *repr = ice_netdev_to_repr(netdev);
4403
4404	if (repr->ops.ready(repr))
4405		return;
4406
4407	__ice_get_ethtool_stats(netdev, stats, data, repr->src_vsi);
4408}
4409
4410static int ice_repr_get_sset_count(struct net_device *netdev, int sset)
4411{
4412	switch (sset) {
4413	case ETH_SS_STATS:
4414		return ICE_VSI_STATS_LEN;
4415	default:
4416		return -EOPNOTSUPP;
4417	}
4418}
4419
4420#define ICE_I2C_EEPROM_DEV_ADDR		0xA0
4421#define ICE_I2C_EEPROM_DEV_ADDR2	0xA2
4422#define ICE_MODULE_TYPE_SFP		0x03
4423#define ICE_MODULE_TYPE_QSFP_PLUS	0x0D
4424#define ICE_MODULE_TYPE_QSFP28		0x11
4425#define ICE_MODULE_SFF_ADDR_MODE	0x04
4426#define ICE_MODULE_SFF_DIAG_CAPAB	0x40
4427#define ICE_MODULE_REVISION_ADDR	0x01
4428#define ICE_MODULE_SFF_8472_COMP	0x5E
4429#define ICE_MODULE_SFF_8472_SWAP	0x5C
4430#define ICE_MODULE_QSFP_MAX_LEN		640
4431
4432/**
4433 * ice_get_module_info - get SFF module type and revision information
4434 * @netdev: network interface device structure
4435 * @modinfo: module EEPROM size and layout information structure
4436 */
4437static int
4438ice_get_module_info(struct net_device *netdev,
4439		    struct ethtool_modinfo *modinfo)
4440{
4441	struct ice_pf *pf = ice_netdev_to_pf(netdev);
4442	struct ice_hw *hw = &pf->hw;
4443	u8 sff8472_comp = 0;
4444	u8 sff8472_swap = 0;
4445	u8 sff8636_rev = 0;
4446	u8 value = 0;
4447	int status;
4448
4449	status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
4450				   0, &value, 1, 0, NULL);
4451	if (status)
4452		return status;
4453
4454	switch (value) {
4455	case ICE_MODULE_TYPE_SFP:
4456		status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4457					   ICE_MODULE_SFF_8472_COMP, 0x00, 0,
4458					   &sff8472_comp, 1, 0, NULL);
4459		if (status)
4460			return status;
4461		status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4462					   ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
4463					   &sff8472_swap, 1, 0, NULL);
4464		if (status)
4465			return status;
4466
4467		if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
4468			modinfo->type = ETH_MODULE_SFF_8079;
4469			modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4470		} else if (sff8472_comp &&
4471			   (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
4472			modinfo->type = ETH_MODULE_SFF_8472;
4473			modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4474		} else {
4475			modinfo->type = ETH_MODULE_SFF_8079;
4476			modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4477		}
4478		break;
4479	case ICE_MODULE_TYPE_QSFP_PLUS:
4480	case ICE_MODULE_TYPE_QSFP28:
4481		status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4482					   ICE_MODULE_REVISION_ADDR, 0x00, 0,
4483					   &sff8636_rev, 1, 0, NULL);
4484		if (status)
4485			return status;
4486		/* Check revision compliance */
4487		if (sff8636_rev > 0x02) {
4488			/* Module is SFF-8636 compliant */
4489			modinfo->type = ETH_MODULE_SFF_8636;
4490			modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
4491		} else {
4492			modinfo->type = ETH_MODULE_SFF_8436;
4493			modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
4494		}
4495		break;
4496	default:
4497		netdev_warn(netdev, "SFF Module Type not recognized.\n");
4498		return -EINVAL;
4499	}
4500	return 0;
4501}
4502
4503/**
4504 * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
4505 * @netdev: network interface device structure
4506 * @ee: EEPROM dump request structure
4507 * @data: buffer to be filled with EEPROM contents
4508 */
4509static int
4510ice_get_module_eeprom(struct net_device *netdev,
4511		      struct ethtool_eeprom *ee, u8 *data)
4512{
4513	struct ice_pf *pf = ice_netdev_to_pf(netdev);
4514#define SFF_READ_BLOCK_SIZE 8
4515	u8 value[SFF_READ_BLOCK_SIZE] = { 0 };
4516	u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
4517	struct ice_hw *hw = &pf->hw;
4518	bool is_sfp = false;
4519	unsigned int i;
4520	u16 offset = 0;
4521	u8 page = 0;
4522	int status;
4523
4524	if (!ee || !ee->len || !data)
4525		return -EINVAL;
4526
4527	status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0, value, 1, 0,
4528				   NULL);
4529	if (status)
4530		return status;
4531
4532	if (value[0] == ICE_MODULE_TYPE_SFP)
4533		is_sfp = true;
4534
4535	memset(data, 0, ee->len);
4536	for (i = 0; i < ee->len; i += SFF_READ_BLOCK_SIZE) {
4537		offset = i + ee->offset;
4538		page = 0;
4539
4540		/* Check if we need to access the other memory page */
4541		if (is_sfp) {
4542			if (offset >= ETH_MODULE_SFF_8079_LEN) {
4543				offset -= ETH_MODULE_SFF_8079_LEN;
4544				addr = ICE_I2C_EEPROM_DEV_ADDR2;
4545			}
4546		} else {
4547			while (offset >= ETH_MODULE_SFF_8436_LEN) {
4548				/* Compute memory page number and offset. */
4549				offset -= ETH_MODULE_SFF_8436_LEN / 2;
4550				page++;
4551			}
4552		}
4553
4554		/* Bit 2 of EEPROM address 0x02 declares upper
4555		 * pages are disabled on QSFP modules.
4556		 * SFP modules only ever use page 0.
4557		 */
4558		if (page == 0 || !(data[0x2] & 0x4)) {
4559			u32 copy_len;
4560
4561			status = ice_aq_sff_eeprom(hw, 0, addr, offset, page,
4562						   !is_sfp, value,
4563						   SFF_READ_BLOCK_SIZE,
4564						   0, NULL);
4565			netdev_dbg(netdev, "SFF %02X %02X %02X %X = %02X%02X%02X%02X.%02X%02X%02X%02X (%pe)\n",
4566				   addr, offset, page, is_sfp,
4567				   value[0], value[1], value[2], value[3],
4568				   value[4], value[5], value[6], value[7],
4569				   ERR_PTR(status));
4570			if (status) {
4571				netdev_err(netdev, "%s: error reading module EEPROM: status %pe\n",
4572					   __func__, ERR_PTR(status));
4573				return status;
4574			}
4575
4576			/* Make sure we have enough room for the new block */
4577			copy_len = min_t(u32, SFF_READ_BLOCK_SIZE, ee->len - i);
4578			memcpy(data + i, value, copy_len);
4579		}
4580	}
4581	return 0;
4582}
4583
4584/**
4585 * ice_get_port_fec_stats - returns FEC correctable, uncorrectable stats per
4586 *                          pcsquad, pcsport
4587 * @hw: pointer to the HW struct
4588 * @pcs_quad: pcsquad for input port
4589 * @pcs_port: pcsport for input port
4590 * @fec_stats: buffer to hold FEC statistics for given port
4591 *
4592 * Return: 0 on success, negative on failure.
4593 */
4594static int ice_get_port_fec_stats(struct ice_hw *hw, u16 pcs_quad, u16 pcs_port,
4595				  struct ethtool_fec_stats *fec_stats)
4596{
4597	u32 fec_uncorr_low_val = 0, fec_uncorr_high_val = 0;
4598	u32 fec_corr_low_val = 0, fec_corr_high_val = 0;
4599	int err;
4600
4601	if (pcs_quad > 1 || pcs_port > 3)
4602		return -EINVAL;
4603
4604	err = ice_aq_get_fec_stats(hw, pcs_quad, pcs_port, ICE_FEC_CORR_LOW,
4605				   &fec_corr_low_val);
4606	if (err)
4607		return err;
4608
4609	err = ice_aq_get_fec_stats(hw, pcs_quad, pcs_port, ICE_FEC_CORR_HIGH,
4610				   &fec_corr_high_val);
4611	if (err)
4612		return err;
4613
4614	err = ice_aq_get_fec_stats(hw, pcs_quad, pcs_port,
4615				   ICE_FEC_UNCORR_LOW,
4616				   &fec_uncorr_low_val);
4617	if (err)
4618		return err;
4619
4620	err = ice_aq_get_fec_stats(hw, pcs_quad, pcs_port,
4621				   ICE_FEC_UNCORR_HIGH,
4622				   &fec_uncorr_high_val);
4623	if (err)
4624		return err;
4625
4626	fec_stats->corrected_blocks.total = (fec_corr_high_val << 16) +
4627					     fec_corr_low_val;
4628	fec_stats->uncorrectable_blocks.total = (fec_uncorr_high_val << 16) +
4629						 fec_uncorr_low_val;
4630	return 0;
4631}
4632
4633/**
4634 * ice_get_fec_stats - returns FEC correctable, uncorrectable stats per netdev
4635 * @netdev: network interface device structure
4636 * @fec_stats: buffer to hold FEC statistics for given port
4637 * @hist: buffer to put FEC histogram statistics for given port
4638 *
4639 */
4640static void ice_get_fec_stats(struct net_device *netdev,
4641			      struct ethtool_fec_stats *fec_stats,
4642			      struct ethtool_fec_hist *hist)
4643{
4644	struct ice_netdev_priv *np = netdev_priv(netdev);
4645	struct ice_port_topology port_topology;
4646	struct ice_port_info *pi;
4647	struct ice_pf *pf;
4648	struct ice_hw *hw;
4649	int err;
4650
4651	pf = np->vsi->back;
4652	hw = &pf->hw;
4653	pi = np->vsi->port_info;
4654
4655	/* Serdes parameters are not supported if not the PF VSI */
4656	if (np->vsi->type != ICE_VSI_PF || !pi)
4657		return;
4658
4659	err = ice_get_port_topology(hw, pi->lport, &port_topology);
4660	if (err) {
4661		netdev_info(netdev, "Extended register dump failed Lport %d\n",
4662			    pi->lport);
4663		return;
4664	}
4665
4666	/* Get FEC correctable, uncorrectable counter */
4667	err = ice_get_port_fec_stats(hw, port_topology.pcs_quad_select,
4668				     port_topology.pcs_port, fec_stats);
4669	if (err)
4670		netdev_info(netdev, "FEC stats get failed Lport %d Err %d\n",
4671			    pi->lport, err);
4672}
4673
4674static void ice_get_eth_mac_stats(struct net_device *netdev,
4675				  struct ethtool_eth_mac_stats *mac_stats)
4676{
4677	struct ice_pf *pf = ice_netdev_to_pf(netdev);
4678	struct ice_hw_port_stats *ps = &pf->stats;
4679
4680	mac_stats->FramesTransmittedOK = ps->eth.tx_unicast +
4681					 ps->eth.tx_multicast +
4682					 ps->eth.tx_broadcast;
4683	mac_stats->FramesReceivedOK = ps->eth.rx_unicast +
4684				      ps->eth.rx_multicast +
4685				      ps->eth.rx_broadcast;
4686	mac_stats->FrameCheckSequenceErrors = ps->crc_errors;
4687	mac_stats->OctetsTransmittedOK = ps->eth.tx_bytes;
4688	mac_stats->OctetsReceivedOK = ps->eth.rx_bytes;
4689	mac_stats->MulticastFramesXmittedOK = ps->eth.tx_multicast;
4690	mac_stats->BroadcastFramesXmittedOK = ps->eth.tx_broadcast;
4691	mac_stats->MulticastFramesReceivedOK = ps->eth.rx_multicast;
4692	mac_stats->BroadcastFramesReceivedOK = ps->eth.rx_broadcast;
4693	mac_stats->InRangeLengthErrors = ps->rx_len_errors;
4694	mac_stats->FrameTooLongErrors = ps->rx_oversize;
4695}
4696
4697static void ice_get_pause_stats(struct net_device *netdev,
4698				struct ethtool_pause_stats *pause_stats)
4699{
4700	struct ice_pf *pf = ice_netdev_to_pf(netdev);
4701	struct ice_hw_port_stats *ps = &pf->stats;
4702
4703	pause_stats->tx_pause_frames = ps->link_xon_tx + ps->link_xoff_tx;
4704	pause_stats->rx_pause_frames = ps->link_xon_rx + ps->link_xoff_rx;
4705}
4706
4707static const struct ethtool_rmon_hist_range ice_rmon_ranges[] = {
4708	{    0,    64 },
4709	{   65,   127 },
4710	{  128,   255 },
4711	{  256,   511 },
4712	{  512,  1023 },
4713	{ 1024,  1522 },
4714	{ 1523,  9522 },
4715	{}
4716};
4717
4718static void ice_get_rmon_stats(struct net_device *netdev,
4719			       struct ethtool_rmon_stats *rmon,
4720			       const struct ethtool_rmon_hist_range **ranges)
4721{
4722	struct ice_pf *pf = ice_netdev_to_pf(netdev);
4723	struct ice_hw_port_stats *ps = &pf->stats;
4724
4725	rmon->undersize_pkts	= ps->rx_undersize;
4726	rmon->oversize_pkts	= ps->rx_oversize;
4727	rmon->fragments		= ps->rx_fragments;
4728	rmon->jabbers		= ps->rx_jabber;
4729
4730	rmon->hist[0]		= ps->rx_size_64;
4731	rmon->hist[1]		= ps->rx_size_127;
4732	rmon->hist[2]		= ps->rx_size_255;
4733	rmon->hist[3]		= ps->rx_size_511;
4734	rmon->hist[4]		= ps->rx_size_1023;
4735	rmon->hist[5]		= ps->rx_size_1522;
4736	rmon->hist[6]		= ps->rx_size_big;
4737
4738	rmon->hist_tx[0]	= ps->tx_size_64;
4739	rmon->hist_tx[1]	= ps->tx_size_127;
4740	rmon->hist_tx[2]	= ps->tx_size_255;
4741	rmon->hist_tx[3]	= ps->tx_size_511;
4742	rmon->hist_tx[4]	= ps->tx_size_1023;
4743	rmon->hist_tx[5]	= ps->tx_size_1522;
4744	rmon->hist_tx[6]	= ps->tx_size_big;
4745
4746	*ranges = ice_rmon_ranges;
4747}
4748
4749/* ice_get_ts_stats - provide timestamping stats
4750 * @netdev: the netdevice pointer from ethtool
4751 * @ts_stats: the ethtool data structure to fill in
4752 */
4753static void ice_get_ts_stats(struct net_device *netdev,
4754			     struct ethtool_ts_stats *ts_stats)
4755{
4756	struct ice_pf *pf = ice_netdev_to_pf(netdev);
4757	struct ice_ptp *ptp = &pf->ptp;
4758
4759	ts_stats->pkts = ptp->tx_hwtstamp_good;
4760	ts_stats->err = ptp->tx_hwtstamp_skipped +
4761			ptp->tx_hwtstamp_flushed +
4762			ptp->tx_hwtstamp_discarded;
4763	ts_stats->lost = ptp->tx_hwtstamp_timeouts;
4764}
4765
4766#define ICE_ETHTOOL_PFR (ETH_RESET_IRQ | ETH_RESET_DMA | \
4767	ETH_RESET_FILTER | ETH_RESET_OFFLOAD)
4768
4769#define ICE_ETHTOOL_CORER ((ICE_ETHTOOL_PFR | ETH_RESET_RAM) << \
4770	ETH_RESET_SHARED_SHIFT)
4771
4772#define ICE_ETHTOOL_GLOBR (ICE_ETHTOOL_CORER | \
4773	(ETH_RESET_MAC << ETH_RESET_SHARED_SHIFT) | \
4774	(ETH_RESET_PHY << ETH_RESET_SHARED_SHIFT))
4775
4776#define ICE_ETHTOOL_VFR ICE_ETHTOOL_PFR
4777
4778/**
4779 * ice_ethtool_reset - triggers a given type of reset
4780 * @dev: network interface device structure
4781 * @flags: set of reset flags
4782 *
4783 * Return: 0 on success, -EOPNOTSUPP when using unsupported set of flags.
4784 */
4785static int ice_ethtool_reset(struct net_device *dev, u32 *flags)
4786{
4787	struct ice_pf *pf = ice_netdev_to_pf(dev);
4788	enum ice_reset_req reset;
4789
4790	switch (*flags) {
4791	case ICE_ETHTOOL_CORER:
4792		reset = ICE_RESET_CORER;
4793		break;
4794	case ICE_ETHTOOL_GLOBR:
4795		reset = ICE_RESET_GLOBR;
4796		break;
4797	case ICE_ETHTOOL_PFR:
4798		reset = ICE_RESET_PFR;
4799		break;
4800	default:
4801		netdev_info(dev, "Unsupported set of ethtool flags");
4802		return -EOPNOTSUPP;
4803	}
4804
4805	ice_schedule_reset(pf, reset);
4806
4807	*flags = 0;
4808
4809	return 0;
4810}
4811
4812/**
4813 * ice_repr_ethtool_reset - triggers a VF reset
4814 * @dev: network interface device structure
4815 * @flags: set of reset flags
4816 *
4817 * Return: 0 on success,
4818 * -EOPNOTSUPP when using unsupported set of flags
4819 * -EBUSY when VF is not ready for reset.
4820 */
4821static int ice_repr_ethtool_reset(struct net_device *dev, u32 *flags)
4822{
4823	struct ice_repr *repr = ice_netdev_to_repr(dev);
4824	struct ice_vf *vf;
4825
4826	if (repr->type != ICE_REPR_TYPE_VF ||
4827	    *flags != ICE_ETHTOOL_VFR)
4828		return -EOPNOTSUPP;
4829
4830	vf = repr->vf;
4831
4832	if (ice_check_vf_ready_for_cfg(vf))
4833		return -EBUSY;
4834
4835	*flags = 0;
4836
4837	return ice_reset_vf(vf, ICE_VF_RESET_VFLR | ICE_VF_RESET_LOCK);
4838}
4839
4840static const struct ethtool_ops ice_ethtool_ops = {
4841	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
4842				     ETHTOOL_COALESCE_USE_ADAPTIVE |
4843				     ETHTOOL_COALESCE_RX_USECS_HIGH,
4844	.supported_input_xfrm	= RXH_XFRM_SYM_XOR,
4845	.supported_ring_params	= ETHTOOL_RING_USE_TCP_DATA_SPLIT,
4846	.get_link_ksettings	= ice_get_link_ksettings,
4847	.set_link_ksettings	= ice_set_link_ksettings,
4848	.get_fec_stats		= ice_get_fec_stats,
4849	.get_eth_mac_stats	= ice_get_eth_mac_stats,
4850	.get_pause_stats	= ice_get_pause_stats,
4851	.get_rmon_stats		= ice_get_rmon_stats,
4852	.get_ts_stats		= ice_get_ts_stats,
4853	.get_drvinfo		= ice_get_drvinfo,
4854	.get_regs_len		= ice_get_regs_len,
4855	.get_regs		= ice_get_regs,
4856	.get_wol		= ice_get_wol,
4857	.set_wol		= ice_set_wol,
4858	.get_msglevel		= ice_get_msglevel,
4859	.set_msglevel		= ice_set_msglevel,
4860	.self_test		= ice_self_test,
4861	.get_link		= ethtool_op_get_link,
4862	.get_link_ext_stats	= ice_get_link_ext_stats,
4863	.get_eeprom_len		= ice_get_eeprom_len,
4864	.get_eeprom		= ice_get_eeprom,
4865	.get_coalesce		= ice_get_coalesce,
4866	.set_coalesce		= ice_set_coalesce,
4867	.get_strings		= ice_get_strings,
4868	.set_phys_id		= ice_set_phys_id,
4869	.get_ethtool_stats      = ice_get_ethtool_stats,
4870	.get_priv_flags		= ice_get_priv_flags,
4871	.set_priv_flags		= ice_set_priv_flags,
4872	.get_sset_count		= ice_get_sset_count,
4873	.get_rxnfc		= ice_get_rxnfc,
4874	.set_rxnfc		= ice_set_rxnfc,
4875	.get_rx_ring_count	= ice_get_rx_ring_count,
4876	.get_ringparam		= ice_get_ringparam,
4877	.set_ringparam		= ice_set_ringparam,
4878	.nway_reset		= ice_nway_reset,
4879	.get_pauseparam		= ice_get_pauseparam,
4880	.set_pauseparam		= ice_set_pauseparam,
4881	.reset			= ice_ethtool_reset,
4882	.get_rxfh_key_size	= ice_get_rxfh_key_size,
4883	.get_rxfh_indir_size	= ice_get_rxfh_indir_size,
4884	.get_rxfh		= ice_get_rxfh,
4885	.set_rxfh		= ice_set_rxfh,
4886	.get_rxfh_fields	= ice_get_rxfh_fields,
4887	.set_rxfh_fields	= ice_set_rxfh_fields,
4888	.get_channels		= ice_get_channels,
4889	.set_channels		= ice_set_channels,
4890	.get_ts_info		= ice_get_ts_info,
4891	.get_per_queue_coalesce	= ice_get_per_q_coalesce,
4892	.set_per_queue_coalesce	= ice_set_per_q_coalesce,
4893	.get_fecparam		= ice_get_fecparam,
4894	.set_fecparam		= ice_set_fecparam,
4895	.get_module_info	= ice_get_module_info,
4896	.get_module_eeprom	= ice_get_module_eeprom,
4897};
4898
4899static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
4900	.get_link_ksettings	= ice_get_link_ksettings,
4901	.set_link_ksettings	= ice_set_link_ksettings,
4902	.get_drvinfo		= ice_get_drvinfo,
4903	.get_regs_len		= ice_get_regs_len,
4904	.get_regs		= ice_get_regs,
4905	.get_wol		= ice_get_wol,
4906	.set_wol		= ice_set_wol,
4907	.get_msglevel		= ice_get_msglevel,
4908	.set_msglevel		= ice_set_msglevel,
4909	.get_link		= ethtool_op_get_link,
4910	.get_eeprom_len		= ice_get_eeprom_len,
4911	.get_eeprom		= ice_get_eeprom,
4912	.get_strings		= ice_get_strings,
4913	.get_ethtool_stats	= ice_get_ethtool_stats,
4914	.get_sset_count		= ice_get_sset_count,
4915	.get_ringparam		= ice_get_ringparam,
4916	.set_ringparam		= ice_set_ringparam,
4917	.nway_reset		= ice_nway_reset,
4918	.get_channels		= ice_get_channels,
4919};
4920
4921/**
4922 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
4923 * @netdev: network interface device structure
4924 */
4925void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
4926{
4927	netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
4928}
4929
4930static const struct ethtool_ops ice_ethtool_repr_ops = {
4931	.get_drvinfo		= ice_repr_get_drvinfo,
4932	.get_link		= ethtool_op_get_link,
4933	.get_strings		= ice_repr_get_strings,
4934	.get_ethtool_stats      = ice_repr_get_ethtool_stats,
4935	.get_sset_count		= ice_repr_get_sset_count,
4936	.reset			= ice_repr_ethtool_reset,
4937};
4938
4939/**
4940 * ice_set_ethtool_repr_ops - setup VF's port representor ethtool ops
4941 * @netdev: network interface device structure
4942 */
4943void ice_set_ethtool_repr_ops(struct net_device *netdev)
4944{
4945	netdev->ethtool_ops = &ice_ethtool_repr_ops;
4946}
4947
4948/**
4949 * ice_set_ethtool_ops - setup netdev ethtool ops
4950 * @netdev: network interface device structure
4951 *
4952 * setup netdev ethtool ops with ice specific ops
4953 */
4954void ice_set_ethtool_ops(struct net_device *netdev)
4955{
4956	netdev->ethtool_ops = &ice_ethtool_ops;
4957}
~/ Read-only file preview.