1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) 2 /* Copyright 2017-2019 NXP */ 3 4 #include <linux/ethtool_netlink.h> 5 #include <linux/net_tstamp.h> 6 #include <linux/module.h> 7 #include <linux/of.h> 8 #include <linux/ptp_clock_kernel.h> 9 10 #include "enetc.h" 11 12 static const u32 enetc_si_regs[] = { 13 ENETC_SIMR, ENETC_SIPMAR0, ENETC_SIPMAR1, ENETC_SICBDRMR, 14 ENETC_SICBDRSR, ENETC_SICBDRBAR0, ENETC_SICBDRBAR1, ENETC_SICBDRPIR, 15 ENETC_SICBDRCIR, ENETC_SICBDRLENR, ENETC_SICAPR0, ENETC_SICAPR1, 16 ENETC_SIUEFDCR 17 }; 18 19 static const u32 enetc_txbdr_regs[] = { 20 ENETC_TBMR, ENETC_TBSR, ENETC_TBBAR0, ENETC_TBBAR1, 21 ENETC_TBPIR, ENETC_TBCIR, ENETC_TBLENR, ENETC_TBIER, ENETC_TBICR0, 22 ENETC_TBICR1 23 }; 24 25 static const u32 enetc_rxbdr_regs[] = { 26 ENETC_RBMR, ENETC_RBSR, ENETC_RBBSR, ENETC_RBCIR, ENETC_RBBAR0, 27 ENETC_RBBAR1, ENETC_RBPIR, ENETC_RBLENR, ENETC_RBIER, ENETC_RBICR0, 28 ENETC_RBICR1 29 }; 30 31 static const u32 enetc_port_regs[] = { 32 ENETC_PMR, ENETC_PSR, ENETC_PSIPMMR, ENETC_PSIPMAR0(0), 33 ENETC_PSIPMAR1(0), ENETC_PTXMBAR, ENETC_PCAPR0, ENETC_PCAPR1, 34 ENETC_PSICFGR0(0), ENETC_PRFSCAPR, ENETC_PTCMSDUR(0), 35 ENETC_PM0_CMD_CFG, ENETC_PM0_MAXFRM, ENETC_PM0_IF_MODE 36 }; 37 38 static const u32 enetc_port_mm_regs[] = { 39 ENETC_MMCSR, ENETC_PFPMR, ENETC_PTCFPR(0), ENETC_PTCFPR(1), 40 ENETC_PTCFPR(2), ENETC_PTCFPR(3), ENETC_PTCFPR(4), ENETC_PTCFPR(5), 41 ENETC_PTCFPR(6), ENETC_PTCFPR(7), 42 }; 43 44 static int enetc_get_reglen(struct net_device *ndev) 45 { 46 struct enetc_ndev_priv *priv = netdev_priv(ndev); 47 struct enetc_hw *hw = &priv->si->hw; 48 int len; 49 50 len = ARRAY_SIZE(enetc_si_regs); 51 len += ARRAY_SIZE(enetc_txbdr_regs) * priv->num_tx_rings; 52 len += ARRAY_SIZE(enetc_rxbdr_regs) * priv->num_rx_rings; 53 54 if (hw->port) 55 len += ARRAY_SIZE(enetc_port_regs); 56 57 if (hw->port && !!(priv->si->hw_features & ENETC_SI_F_QBU)) 58 len += ARRAY_SIZE(enetc_port_mm_regs); 59 60 len *= sizeof(u32) * 2; /* store 2 entries per reg: addr and value */ 61 62 return len; 63 } 64 65 static void enetc_get_regs(struct net_device *ndev, struct ethtool_regs *regs, 66 void *regbuf) 67 { 68 struct enetc_ndev_priv *priv = netdev_priv(ndev); 69 struct enetc_hw *hw = &priv->si->hw; 70 u32 *buf = (u32 *)regbuf; 71 int i, j; 72 u32 addr; 73 74 for (i = 0; i < ARRAY_SIZE(enetc_si_regs); i++) { 75 *buf++ = enetc_si_regs[i]; 76 *buf++ = enetc_rd(hw, enetc_si_regs[i]); 77 } 78 79 for (i = 0; i < priv->num_tx_rings; i++) { 80 for (j = 0; j < ARRAY_SIZE(enetc_txbdr_regs); j++) { 81 addr = ENETC_BDR(TX, i, enetc_txbdr_regs[j]); 82 83 *buf++ = addr; 84 *buf++ = enetc_rd(hw, addr); 85 } 86 } 87 88 for (i = 0; i < priv->num_rx_rings; i++) { 89 for (j = 0; j < ARRAY_SIZE(enetc_rxbdr_regs); j++) { 90 addr = ENETC_BDR(RX, i, enetc_rxbdr_regs[j]); 91 92 *buf++ = addr; 93 *buf++ = enetc_rd(hw, addr); 94 } 95 } 96 97 if (!hw->port) 98 return; 99 100 for (i = 0; i < ARRAY_SIZE(enetc_port_regs); i++) { 101 addr = ENETC_PORT_BASE + enetc_port_regs[i]; 102 *buf++ = addr; 103 *buf++ = enetc_rd(hw, addr); 104 } 105 106 if (priv->si->hw_features & ENETC_SI_F_QBU) { 107 for (i = 0; i < ARRAY_SIZE(enetc_port_mm_regs); i++) { 108 addr = ENETC_PORT_BASE + enetc_port_mm_regs[i]; 109 *buf++ = addr; 110 *buf++ = enetc_rd(hw, addr); 111 } 112 } 113 } 114 115 static const struct { 116 int reg; 117 char name[ETH_GSTRING_LEN]; 118 } enetc_si_counters[] = { 119 { ENETC_SIROCT, "SI rx octets" }, 120 { ENETC_SIRFRM, "SI rx frames" }, 121 { ENETC_SIRUCA, "SI rx u-cast frames" }, 122 { ENETC_SIRMCA, "SI rx m-cast frames" }, 123 { ENETC_SITOCT, "SI tx octets" }, 124 { ENETC_SITFRM, "SI tx frames" }, 125 { ENETC_SITUCA, "SI tx u-cast frames" }, 126 { ENETC_SITMCA, "SI tx m-cast frames" }, 127 }; 128 129 static const struct { 130 int reg; 131 char name[ETH_GSTRING_LEN] __nonstring; 132 } enetc_emac_counters[] = { 133 { ENETC_PM_RVLAN(0), "eMAC rx VLAN frames" }, 134 { ENETC_PM_RERR(0), "eMAC rx frame errors" }, 135 { ENETC_PM_RUCA(0), "eMAC rx unicast frames" }, 136 { ENETC_PM_RDRP(0), "eMAC rx dropped packets" }, 137 { ENETC_PM_RPKT(0), "eMAC rx packets" }, 138 { ENETC_PM_TOCT(0), "eMAC tx octets" }, 139 { ENETC_PM_TFCS(0), "eMAC tx fcs errors" }, 140 { ENETC_PM_TVLAN(0), "eMAC tx VLAN frames" }, 141 { ENETC_PM_TUCA(0), "eMAC tx unicast frames" }, 142 { ENETC_PM_TPKT(0), "eMAC tx packets" }, 143 { ENETC_PM_TUND(0), "eMAC tx undersized packets" }, 144 }; 145 146 static const struct { 147 int reg; 148 char name[ETH_GSTRING_LEN] __nonstring; 149 } enetc_pmac_counters[] = { 150 { ENETC_PM_RVLAN(1), "pMAC rx VLAN frames" }, 151 { ENETC_PM_RERR(1), "pMAC rx frame errors" }, 152 { ENETC_PM_RUCA(1), "pMAC rx unicast frames" }, 153 { ENETC_PM_RDRP(1), "pMAC rx dropped packets" }, 154 { ENETC_PM_RPKT(1), "pMAC rx packets" }, 155 { ENETC_PM_TOCT(1), "pMAC tx octets" }, 156 { ENETC_PM_TFCS(1), "pMAC tx fcs errors" }, 157 { ENETC_PM_TVLAN(1), "pMAC tx VLAN frames" }, 158 { ENETC_PM_TUCA(1), "pMAC tx unicast frames" }, 159 { ENETC_PM_TPKT(1), "pMAC tx packets" }, 160 { ENETC_PM_TUND(1), "pMAC tx undersized packets" }, 161 }; 162 163 static const struct { 164 int reg; 165 char name[ETH_GSTRING_LEN] __nonstring; 166 } enetc_port_counters[] = { 167 { ENETC_UFDMF, "SI MAC nomatch u-cast discards" }, 168 { ENETC_MFDMF, "SI MAC nomatch m-cast discards" }, 169 { ENETC_PBFDSIR, "SI MAC nomatch b-cast discards" }, 170 { ENETC_PUFDVFR, "SI VLAN nomatch u-cast discards" }, 171 { ENETC_PMFDVFR, "SI VLAN nomatch m-cast discards" }, 172 { ENETC_PBFDVFR, "SI VLAN nomatch b-cast discards" }, 173 { ENETC_PFDMSAPR, "SI pruning discarded frames" }, 174 { ENETC_PICDR(0), "ICM DR0 discarded frames" }, 175 { ENETC_PICDR(1), "ICM DR1 discarded frames" }, 176 { ENETC_PICDR(2), "ICM DR2 discarded frames" }, 177 { ENETC_PICDR(3), "ICM DR3 discarded frames" }, 178 }; 179 180 static const struct { 181 int reg; 182 char name[ETH_GSTRING_LEN] __nonstring; 183 } enetc4_emac_counters[] = { 184 { ENETC4_PM_ROCT(0), "eMAC rx octets" }, 185 { ENETC4_PM_RVLAN(0), "eMAC rx VLAN frames" }, 186 { ENETC4_PM_RERR(0), "eMAC rx frame errors" }, 187 { ENETC4_PM_RUCA(0), "eMAC rx unicast frames" }, 188 { ENETC4_PM_RDRP(0), "eMAC rx dropped packets" }, 189 { ENETC4_PM_RPKT(0), "eMAC rx packets" }, 190 { ENETC4_PM_TOCT(0), "eMAC tx octets" }, 191 { ENETC4_PM_TVLAN(0), "eMAC tx VLAN frames" }, 192 { ENETC4_PM_TFCS(0), "eMAC tx fcs errors" }, 193 { ENETC4_PM_TUCA(0), "eMAC tx unicast frames" }, 194 { ENETC4_PM_TPKT(0), "eMAC tx packets" }, 195 { ENETC4_PM_TUND(0), "eMAC tx undersized packets" }, 196 { ENETC4_PM_TIOCT(0), "eMAC tx invalid octets" }, 197 }; 198 199 static const struct { 200 int reg; 201 char name[ETH_GSTRING_LEN] __nonstring; 202 } enetc4_pmac_counters[] = { 203 { ENETC4_PM_ROCT(1), "pMAC rx octets" }, 204 { ENETC4_PM_RVLAN(1), "pMAC rx VLAN frames" }, 205 { ENETC4_PM_RERR(1), "pMAC rx frame errors" }, 206 { ENETC4_PM_RUCA(1), "pMAC rx unicast frames" }, 207 { ENETC4_PM_RDRP(1), "pMAC rx dropped packets" }, 208 { ENETC4_PM_RPKT(1), "pMAC rx packets" }, 209 { ENETC4_PM_TOCT(1), "pMAC tx octets" }, 210 { ENETC4_PM_TVLAN(1), "pMAC tx VLAN frames" }, 211 { ENETC4_PM_TFCS(1), "pMAC tx fcs errors" }, 212 { ENETC4_PM_TUCA(1), "pMAC tx unicast frames" }, 213 { ENETC4_PM_TPKT(1), "pMAC tx packets" }, 214 { ENETC4_PM_TUND(1), "pMAC tx undersized packets" }, 215 { ENETC4_PM_TIOCT(1), "pMAC tx invalid octets" }, 216 }; 217 218 static const struct { 219 int reg; 220 char name[ETH_GSTRING_LEN] __nonstring; 221 } enetc4_port_counters[] = { 222 { ENETC4_PICDRDCR(0), "ICM DR0 discarded frames" }, 223 { ENETC4_PICDRDCR(1), "ICM DR1 discarded frames" }, 224 { ENETC4_PICDRDCR(2), "ICM DR2 discarded frames" }, 225 { ENETC4_PICDRDCR(3), "ICM DR3 discarded frames" }, 226 { ENETC4_PUFDMFR, "MAC filter discarded unicast" }, 227 { ENETC4_PMFDMFR, "MAC filter discarded multicast" }, 228 { ENETC4_PBFDSIR, "MAC filter discarded broadcast" }, 229 { ENETC4_PFDMSAPR, "MAC SA pruning discarded frames" }, 230 { ENETC4_PUFDVFR, "VLAN filter discarded unicast" }, 231 { ENETC4_PMFDVFR, "VLAN filter discarded multicast" }, 232 { ENETC4_PBFDVFR, "VLAN filter discarded broadcast" }, 233 { ENETC4_PRXDCR, "MAC rx discarded frames" }, 234 { ENETC4_PRXDCRRR, "MAC rx discard read-reset" }, 235 { ENETC4_PRXDCRR0, "MAC rx discard reason 0" }, 236 { ENETC4_PRXDCRR1, "MAC rx discard reason 1" }, 237 }; 238 239 static const char rx_ring_stats[][ETH_GSTRING_LEN] = { 240 "Rx ring %2d frames", 241 "Rx ring %2d alloc errors", 242 "Rx ring %2d XDP drops", 243 "Rx ring %2d recycles", 244 "Rx ring %2d recycle failures", 245 "Rx ring %2d redirects", 246 "Rx ring %2d redirect failures", 247 "Rx ring %2d discarded frames", 248 }; 249 250 static const char tx_ring_stats[][ETH_GSTRING_LEN] = { 251 "Tx ring %2d frames", 252 "Tx ring %2d XDP frames", 253 "Tx ring %2d XDP drops", 254 "Tx window drop %2d frames", 255 }; 256 257 static int enetc_get_sset_count(struct net_device *ndev, int sset) 258 { 259 struct enetc_ndev_priv *priv = netdev_priv(ndev); 260 struct enetc_si *si = priv->si; 261 int len; 262 263 if (sset != ETH_SS_STATS) 264 return -EOPNOTSUPP; 265 266 len = ARRAY_SIZE(enetc_si_counters) + 267 ARRAY_SIZE(tx_ring_stats) * priv->num_tx_rings + 268 ARRAY_SIZE(rx_ring_stats) * priv->num_rx_rings; 269 270 if (!enetc_si_is_pf(si)) 271 return len; 272 273 if (is_enetc_rev1(si)) { 274 len += ARRAY_SIZE(enetc_port_counters); 275 len += ARRAY_SIZE(enetc_emac_counters); 276 if (si->hw_features & ENETC_SI_F_QBU) 277 len += ARRAY_SIZE(enetc_pmac_counters); 278 } else { 279 len += ARRAY_SIZE(enetc4_port_counters); 280 281 if (enetc_is_pseudo_mac(si)) 282 return len; 283 284 len += ARRAY_SIZE(enetc4_emac_counters); 285 if (si->hw_features & ENETC_SI_F_QBU) 286 len += ARRAY_SIZE(enetc4_pmac_counters); 287 } 288 289 return len; 290 } 291 292 static void enetc_get_pf_strings(struct enetc_si *si, u8 *data) 293 { 294 int i; 295 296 for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++) 297 ethtool_cpy(&data, enetc_port_counters[i].name); 298 299 for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++) 300 ethtool_cpy(&data, enetc_emac_counters[i].name); 301 302 if (!(si->hw_features & ENETC_SI_F_QBU)) 303 return; 304 305 for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++) 306 ethtool_cpy(&data, enetc_pmac_counters[i].name); 307 } 308 309 static void enetc4_get_pf_strings(struct enetc_si *si, u8 *data) 310 { 311 int i; 312 313 for (i = 0; i < ARRAY_SIZE(enetc4_port_counters); i++) 314 ethtool_cpy(&data, enetc4_port_counters[i].name); 315 316 if (enetc_is_pseudo_mac(si)) 317 return; 318 319 for (i = 0; i < ARRAY_SIZE(enetc4_emac_counters); i++) 320 ethtool_cpy(&data, enetc4_emac_counters[i].name); 321 322 if (!(si->hw_features & ENETC_SI_F_QBU)) 323 return; 324 325 for (i = 0; i < ARRAY_SIZE(enetc4_pmac_counters); i++) 326 ethtool_cpy(&data, enetc4_pmac_counters[i].name); 327 } 328 329 static void enetc_get_strings(struct net_device *ndev, u32 stringset, u8 *data) 330 { 331 struct enetc_ndev_priv *priv = netdev_priv(ndev); 332 struct enetc_si *si = priv->si; 333 int i, j; 334 335 switch (stringset) { 336 case ETH_SS_STATS: 337 for (i = 0; i < ARRAY_SIZE(enetc_si_counters); i++) 338 ethtool_puts(&data, enetc_si_counters[i].name); 339 for (i = 0; i < priv->num_tx_rings; i++) 340 for (j = 0; j < ARRAY_SIZE(tx_ring_stats); j++) 341 ethtool_sprintf(&data, tx_ring_stats[j], i); 342 for (i = 0; i < priv->num_rx_rings; i++) 343 for (j = 0; j < ARRAY_SIZE(rx_ring_stats); j++) 344 ethtool_sprintf(&data, rx_ring_stats[j], i); 345 346 if (!enetc_si_is_pf(si)) 347 break; 348 349 if (is_enetc_rev1(si)) 350 enetc_get_pf_strings(si, data); 351 else 352 enetc4_get_pf_strings(si, data); 353 354 break; 355 } 356 } 357 358 static void enetc_pf_get_ethtool_stats(struct enetc_si *si, int *o, u64 *data) 359 { 360 struct enetc_hw *hw = &si->hw; 361 int i; 362 363 for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++) 364 data[(*o)++] = enetc_port_rd(hw, enetc_port_counters[i].reg); 365 366 for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++) 367 data[(*o)++] = enetc_port_rd64(hw, enetc_emac_counters[i].reg); 368 369 if (!(si->hw_features & ENETC_SI_F_QBU)) 370 return; 371 372 for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++) 373 data[(*o)++] = enetc_port_rd64(hw, enetc_pmac_counters[i].reg); 374 } 375 376 static void enetc4_pf_get_ethtool_stats(struct enetc_si *si, int *o, u64 *data) 377 { 378 struct enetc_hw *hw = &si->hw; 379 int i; 380 381 for (i = 0; i < ARRAY_SIZE(enetc4_port_counters); i++) 382 data[(*o)++] = enetc_port_rd(hw, enetc4_port_counters[i].reg); 383 384 if (enetc_is_pseudo_mac(si)) 385 return; 386 387 for (i = 0; i < ARRAY_SIZE(enetc4_emac_counters); i++) 388 data[(*o)++] = enetc_port_rd64(hw, enetc4_emac_counters[i].reg); 389 390 if (!(si->hw_features & ENETC_SI_F_QBU)) 391 return; 392 393 for (i = 0; i < ARRAY_SIZE(enetc4_pmac_counters); i++) 394 data[(*o)++] = enetc_port_rd64(hw, enetc4_pmac_counters[i].reg); 395 } 396 397 static void enetc_get_ethtool_stats(struct net_device *ndev, 398 struct ethtool_stats *stats, u64 *data) 399 { 400 struct enetc_ndev_priv *priv = netdev_priv(ndev); 401 struct enetc_si *si = priv->si; 402 struct enetc_hw *hw = &si->hw; 403 int i, o = 0; 404 405 for (i = 0; i < ARRAY_SIZE(enetc_si_counters); i++) 406 data[o++] = enetc_rd64(hw, enetc_si_counters[i].reg); 407 408 for (i = 0; i < priv->num_tx_rings; i++) { 409 data[o++] = priv->tx_ring[i]->stats.packets; 410 data[o++] = priv->tx_ring[i]->stats.xdp_tx; 411 data[o++] = priv->tx_ring[i]->stats.xdp_tx_drops; 412 data[o++] = priv->tx_ring[i]->stats.win_drop; 413 } 414 415 for (i = 0; i < priv->num_rx_rings; i++) { 416 data[o++] = priv->rx_ring[i]->stats.packets; 417 data[o++] = priv->rx_ring[i]->stats.rx_alloc_errs; 418 data[o++] = priv->rx_ring[i]->stats.xdp_drops; 419 data[o++] = priv->rx_ring[i]->stats.recycles; 420 data[o++] = priv->rx_ring[i]->stats.recycle_failures; 421 data[o++] = priv->rx_ring[i]->stats.xdp_redirect; 422 data[o++] = priv->rx_ring[i]->stats.xdp_redirect_failures; 423 data[o++] = enetc_rd(hw, ENETC_RBDCR(i)); 424 } 425 426 if (!enetc_si_is_pf(si)) 427 return; 428 429 if (is_enetc_rev1(si)) 430 enetc_pf_get_ethtool_stats(si, &o, data); 431 else 432 enetc4_pf_get_ethtool_stats(si, &o, data); 433 } 434 435 static void enetc_pause_stats(struct enetc_si *si, int mac, 436 struct ethtool_pause_stats *pause_stats) 437 { 438 struct enetc_hw *hw = &si->hw; 439 440 switch (si->pdev->revision) { 441 case ENETC_REV1: 442 pause_stats->tx_pause_frames = enetc_port_rd64(hw, ENETC_PM_TXPF(mac)); 443 pause_stats->rx_pause_frames = enetc_port_rd64(hw, ENETC_PM_RXPF(mac)); 444 break; 445 case ENETC_REV4: 446 pause_stats->tx_pause_frames = enetc_port_rd64(hw, ENETC4_PM_TXPF(mac)); 447 pause_stats->rx_pause_frames = enetc_port_rd64(hw, ENETC4_PM_RXPF(mac)); 448 break; 449 default: 450 break; 451 } 452 } 453 454 static void enetc_get_pause_stats(struct net_device *ndev, 455 struct ethtool_pause_stats *pause_stats) 456 { 457 struct enetc_ndev_priv *priv = netdev_priv(ndev); 458 struct enetc_si *si = priv->si; 459 460 switch (pause_stats->src) { 461 case ETHTOOL_MAC_STATS_SRC_EMAC: 462 enetc_pause_stats(si, 0, pause_stats); 463 break; 464 case ETHTOOL_MAC_STATS_SRC_PMAC: 465 if (si->hw_features & ENETC_SI_F_QBU) 466 enetc_pause_stats(si, 1, pause_stats); 467 break; 468 case ETHTOOL_MAC_STATS_SRC_AGGREGATE: 469 ethtool_aggregate_pause_stats(ndev, pause_stats); 470 break; 471 } 472 } 473 474 static void enetc_mac_stats(struct enetc_hw *hw, int mac, 475 struct ethtool_eth_mac_stats *s) 476 { 477 s->FramesTransmittedOK = enetc_port_rd64(hw, ENETC_PM_TFRM(mac)); 478 s->SingleCollisionFrames = enetc_port_rd64(hw, ENETC_PM_TSCOL(mac)); 479 s->MultipleCollisionFrames = enetc_port_rd64(hw, ENETC_PM_TMCOL(mac)); 480 s->FramesReceivedOK = enetc_port_rd64(hw, ENETC_PM_RFRM(mac)); 481 s->FrameCheckSequenceErrors = enetc_port_rd64(hw, ENETC_PM_RFCS(mac)); 482 s->AlignmentErrors = enetc_port_rd64(hw, ENETC_PM_RALN(mac)); 483 s->OctetsTransmittedOK = enetc_port_rd64(hw, ENETC_PM_TEOCT(mac)); 484 s->FramesWithDeferredXmissions = enetc_port_rd64(hw, ENETC_PM_TDFR(mac)); 485 s->LateCollisions = enetc_port_rd64(hw, ENETC_PM_TLCOL(mac)); 486 s->FramesAbortedDueToXSColls = enetc_port_rd64(hw, ENETC_PM_TECOL(mac)); 487 s->FramesLostDueToIntMACXmitError = enetc_port_rd64(hw, ENETC_PM_TERR(mac)); 488 s->CarrierSenseErrors = enetc_port_rd64(hw, ENETC_PM_TCRSE(mac)); 489 s->OctetsReceivedOK = enetc_port_rd64(hw, ENETC_PM_REOCT(mac)); 490 s->FramesLostDueToIntMACRcvError = enetc_port_rd64(hw, ENETC_PM_RDRNTP(mac)); 491 s->MulticastFramesXmittedOK = enetc_port_rd64(hw, ENETC_PM_TMCA(mac)); 492 s->BroadcastFramesXmittedOK = enetc_port_rd64(hw, ENETC_PM_TBCA(mac)); 493 s->MulticastFramesReceivedOK = enetc_port_rd64(hw, ENETC_PM_RMCA(mac)); 494 s->BroadcastFramesReceivedOK = enetc_port_rd64(hw, ENETC_PM_RBCA(mac)); 495 } 496 497 static void enetc4_mac_stats(struct enetc_hw *hw, int mac, 498 struct ethtool_eth_mac_stats *s) 499 { 500 s->FramesTransmittedOK = enetc_port_rd64(hw, ENETC4_PM_TFRM(mac)); 501 s->SingleCollisionFrames = enetc_port_rd64(hw, ENETC4_PM_TSCOL(mac)); 502 s->MultipleCollisionFrames = enetc_port_rd64(hw, ENETC4_PM_TMCOL(mac)); 503 s->FramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RFRM(mac)); 504 s->FrameCheckSequenceErrors = enetc_port_rd64(hw, ENETC4_PM_RFCS(mac)); 505 s->AlignmentErrors = enetc_port_rd64(hw, ENETC4_PM_RALN(mac)); 506 s->OctetsTransmittedOK = enetc_port_rd64(hw, ENETC4_PM_TEOCT(mac)); 507 s->FramesWithDeferredXmissions = enetc_port_rd64(hw, ENETC4_PM_TDFR(mac)); 508 s->LateCollisions = enetc_port_rd64(hw, ENETC4_PM_TLCOL(mac)); 509 s->FramesAbortedDueToXSColls = enetc_port_rd64(hw, ENETC4_PM_TECOL(mac)); 510 s->FramesLostDueToIntMACXmitError = enetc_port_rd64(hw, ENETC4_PM_TERR(mac)); 511 s->OctetsReceivedOK = enetc_port_rd64(hw, ENETC4_PM_REOCT(mac)); 512 s->FramesLostDueToIntMACRcvError = enetc_port_rd64(hw, ENETC4_PM_RDRNTP(mac)); 513 s->MulticastFramesXmittedOK = enetc_port_rd64(hw, ENETC4_PM_TMCA(mac)); 514 s->BroadcastFramesXmittedOK = enetc_port_rd64(hw, ENETC4_PM_TBCA(mac)); 515 s->MulticastFramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RMCA(mac)); 516 s->BroadcastFramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RBCA(mac)); 517 } 518 519 static void enetc_ctrl_stats(struct enetc_si *si, int mac, 520 struct ethtool_eth_ctrl_stats *s) 521 { 522 struct enetc_hw *hw = &si->hw; 523 524 switch (si->pdev->revision) { 525 case ENETC_REV1: 526 s->MACControlFramesTransmitted = enetc_port_rd64(hw, ENETC_PM_TCNP(mac)); 527 s->MACControlFramesReceived = enetc_port_rd64(hw, ENETC_PM_RCNP(mac)); 528 break; 529 case ENETC_REV4: 530 s->MACControlFramesTransmitted = enetc_port_rd64(hw, ENETC4_PM_TCNP(mac)); 531 s->MACControlFramesReceived = enetc_port_rd64(hw, ENETC4_PM_RCNP(mac)); 532 break; 533 default: 534 break; 535 } 536 } 537 538 static const struct ethtool_rmon_hist_range enetc_rmon_ranges[] = { 539 { 64, 64 }, 540 { 65, 127 }, 541 { 128, 255 }, 542 { 256, 511 }, 543 { 512, 1023 }, 544 { 1024, 1522 }, 545 { 1523, ENETC_MAC_MAXFRM_SIZE }, 546 {}, 547 }; 548 549 static void enetc_rmon_stats(struct enetc_hw *hw, int mac, 550 struct ethtool_rmon_stats *s) 551 { 552 s->undersize_pkts = enetc_port_rd64(hw, ENETC_PM_RUND(mac)); 553 s->oversize_pkts = enetc_port_rd64(hw, ENETC_PM_ROVR(mac)); 554 s->fragments = enetc_port_rd64(hw, ENETC_PM_RFRG(mac)); 555 s->jabbers = enetc_port_rd64(hw, ENETC_PM_RJBR(mac)); 556 557 s->hist[0] = enetc_port_rd64(hw, ENETC_PM_R64(mac)); 558 s->hist[1] = enetc_port_rd64(hw, ENETC_PM_R127(mac)); 559 s->hist[2] = enetc_port_rd64(hw, ENETC_PM_R255(mac)); 560 s->hist[3] = enetc_port_rd64(hw, ENETC_PM_R511(mac)); 561 s->hist[4] = enetc_port_rd64(hw, ENETC_PM_R1023(mac)); 562 s->hist[5] = enetc_port_rd64(hw, ENETC_PM_R1522(mac)); 563 s->hist[6] = enetc_port_rd64(hw, ENETC_PM_R1523X(mac)); 564 565 s->hist_tx[0] = enetc_port_rd64(hw, ENETC_PM_T64(mac)); 566 s->hist_tx[1] = enetc_port_rd64(hw, ENETC_PM_T127(mac)); 567 s->hist_tx[2] = enetc_port_rd64(hw, ENETC_PM_T255(mac)); 568 s->hist_tx[3] = enetc_port_rd64(hw, ENETC_PM_T511(mac)); 569 s->hist_tx[4] = enetc_port_rd64(hw, ENETC_PM_T1023(mac)); 570 s->hist_tx[5] = enetc_port_rd64(hw, ENETC_PM_T1522(mac)); 571 s->hist_tx[6] = enetc_port_rd64(hw, ENETC_PM_T1523X(mac)); 572 } 573 574 static void enetc4_rmon_stats(struct enetc_hw *hw, int mac, 575 struct ethtool_rmon_stats *s) 576 { 577 s->undersize_pkts = enetc_port_rd64(hw, ENETC4_PM_RUND(mac)); 578 s->oversize_pkts = enetc_port_rd64(hw, ENETC4_PM_ROVR(mac)); 579 s->fragments = enetc_port_rd64(hw, ENETC4_PM_RFRG(mac)); 580 s->jabbers = enetc_port_rd64(hw, ENETC4_PM_RJBR(mac)); 581 582 s->hist[0] = enetc_port_rd64(hw, ENETC4_PM_R64(mac)); 583 s->hist[1] = enetc_port_rd64(hw, ENETC4_PM_R127(mac)); 584 s->hist[2] = enetc_port_rd64(hw, ENETC4_PM_R255(mac)); 585 s->hist[3] = enetc_port_rd64(hw, ENETC4_PM_R511(mac)); 586 s->hist[4] = enetc_port_rd64(hw, ENETC4_PM_R1023(mac)); 587 s->hist[5] = enetc_port_rd64(hw, ENETC4_PM_R1522(mac)); 588 s->hist[6] = enetc_port_rd64(hw, ENETC4_PM_R1523X(mac)); 589 590 s->hist_tx[0] = enetc_port_rd64(hw, ENETC4_PM_T64(mac)); 591 s->hist_tx[1] = enetc_port_rd64(hw, ENETC4_PM_T127(mac)); 592 s->hist_tx[2] = enetc_port_rd64(hw, ENETC4_PM_T255(mac)); 593 s->hist_tx[3] = enetc_port_rd64(hw, ENETC4_PM_T511(mac)); 594 s->hist_tx[4] = enetc_port_rd64(hw, ENETC4_PM_T1023(mac)); 595 s->hist_tx[5] = enetc_port_rd64(hw, ENETC4_PM_T1522(mac)); 596 s->hist_tx[6] = enetc_port_rd64(hw, ENETC4_PM_T1523X(mac)); 597 } 598 599 static void enetc_get_mac_stats(struct enetc_si *si, int mac, 600 struct ethtool_eth_mac_stats *mac_stats) 601 { 602 struct enetc_hw *hw = &si->hw; 603 604 switch (si->pdev->revision) { 605 case ENETC_REV1: 606 enetc_mac_stats(hw, mac, mac_stats); 607 break; 608 case ENETC_REV4: 609 enetc4_mac_stats(hw, mac, mac_stats); 610 break; 611 default: 612 break; 613 } 614 } 615 616 static void enetc_get_eth_mac_stats(struct net_device *ndev, 617 struct ethtool_eth_mac_stats *mac_stats) 618 { 619 struct enetc_ndev_priv *priv = netdev_priv(ndev); 620 struct enetc_si *si = priv->si; 621 622 switch (mac_stats->src) { 623 case ETHTOOL_MAC_STATS_SRC_EMAC: 624 enetc_get_mac_stats(si, 0, mac_stats); 625 break; 626 case ETHTOOL_MAC_STATS_SRC_PMAC: 627 if (si->hw_features & ENETC_SI_F_QBU) 628 enetc_get_mac_stats(si, 1, mac_stats); 629 break; 630 case ETHTOOL_MAC_STATS_SRC_AGGREGATE: 631 ethtool_aggregate_mac_stats(ndev, mac_stats); 632 break; 633 } 634 } 635 636 static void enetc_ppm_mac_stats(struct enetc_si *si, 637 struct ethtool_eth_mac_stats *s) 638 { 639 struct enetc_hw *hw = &si->hw; 640 u64 rufcr, rmfcr, rbfcr; 641 u64 tufcr, tmfcr, tbfcr; 642 643 rufcr = enetc_port_rd64(hw, ENETC4_PPMRUFCR); 644 rmfcr = enetc_port_rd64(hw, ENETC4_PPMRMFCR); 645 rbfcr = enetc_port_rd64(hw, ENETC4_PPMRBFCR); 646 647 tufcr = enetc_port_rd64(hw, ENETC4_PPMTUFCR); 648 tmfcr = enetc_port_rd64(hw, ENETC4_PPMTMFCR); 649 tbfcr = enetc_port_rd64(hw, ENETC4_PPMTBFCR); 650 651 s->FramesTransmittedOK = tufcr + tmfcr + tbfcr; 652 s->FramesReceivedOK = rufcr + rmfcr + rbfcr; 653 s->OctetsTransmittedOK = enetc_port_rd64(hw, ENETC4_PPMTOCR); 654 s->OctetsReceivedOK = enetc_port_rd64(hw, ENETC4_PPMROCR); 655 s->MulticastFramesXmittedOK = tmfcr; 656 s->BroadcastFramesXmittedOK = tbfcr; 657 s->MulticastFramesReceivedOK = rmfcr; 658 s->BroadcastFramesReceivedOK = rbfcr; 659 } 660 661 static void enetc_ppm_get_eth_mac_stats(struct net_device *ndev, 662 struct ethtool_eth_mac_stats *mac_stats) 663 { 664 struct enetc_ndev_priv *priv = netdev_priv(ndev); 665 666 switch (mac_stats->src) { 667 case ETHTOOL_MAC_STATS_SRC_EMAC: 668 enetc_ppm_mac_stats(priv->si, mac_stats); 669 break; 670 case ETHTOOL_MAC_STATS_SRC_PMAC: 671 break; 672 case ETHTOOL_MAC_STATS_SRC_AGGREGATE: 673 ethtool_aggregate_mac_stats(ndev, mac_stats); 674 break; 675 } 676 } 677 678 static void enetc_get_eth_ctrl_stats(struct net_device *ndev, 679 struct ethtool_eth_ctrl_stats *ctrl_stats) 680 { 681 struct enetc_ndev_priv *priv = netdev_priv(ndev); 682 struct enetc_si *si = priv->si; 683 684 switch (ctrl_stats->src) { 685 case ETHTOOL_MAC_STATS_SRC_EMAC: 686 enetc_ctrl_stats(si, 0, ctrl_stats); 687 break; 688 case ETHTOOL_MAC_STATS_SRC_PMAC: 689 if (si->hw_features & ENETC_SI_F_QBU) 690 enetc_ctrl_stats(si, 1, ctrl_stats); 691 break; 692 case ETHTOOL_MAC_STATS_SRC_AGGREGATE: 693 ethtool_aggregate_ctrl_stats(ndev, ctrl_stats); 694 break; 695 } 696 } 697 698 static void enetc_get_mac_rmon_stats(struct enetc_si *si, int mac, 699 struct ethtool_rmon_stats *rmon_stats) 700 { 701 struct enetc_hw *hw = &si->hw; 702 703 switch (si->pdev->revision) { 704 case ENETC_REV1: 705 enetc_rmon_stats(hw, mac, rmon_stats); 706 break; 707 case ENETC_REV4: 708 enetc4_rmon_stats(hw, mac, rmon_stats); 709 break; 710 default: 711 break; 712 } 713 } 714 715 static void enetc_get_rmon_stats(struct net_device *ndev, 716 struct ethtool_rmon_stats *rmon_stats, 717 const struct ethtool_rmon_hist_range **ranges) 718 { 719 struct enetc_ndev_priv *priv = netdev_priv(ndev); 720 struct enetc_si *si = priv->si; 721 722 *ranges = enetc_rmon_ranges; 723 724 switch (rmon_stats->src) { 725 case ETHTOOL_MAC_STATS_SRC_EMAC: 726 enetc_get_mac_rmon_stats(si, 0, rmon_stats); 727 break; 728 case ETHTOOL_MAC_STATS_SRC_PMAC: 729 if (si->hw_features & ENETC_SI_F_QBU) 730 enetc_get_mac_rmon_stats(si, 1, rmon_stats); 731 break; 732 case ETHTOOL_MAC_STATS_SRC_AGGREGATE: 733 ethtool_aggregate_rmon_stats(ndev, rmon_stats); 734 break; 735 } 736 } 737 738 #define ENETC_RSSHASH_L3 (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO | RXH_IP_SRC | \ 739 RXH_IP_DST) 740 #define ENETC_RSSHASH_L4 (ENETC_RSSHASH_L3 | RXH_L4_B_0_1 | RXH_L4_B_2_3) 741 static int enetc_get_rxfh_fields(struct net_device *netdev, 742 struct ethtool_rxfh_fields *rxnfc) 743 { 744 static const u32 rsshash[] = { 745 [TCP_V4_FLOW] = ENETC_RSSHASH_L4, 746 [UDP_V4_FLOW] = ENETC_RSSHASH_L4, 747 [SCTP_V4_FLOW] = ENETC_RSSHASH_L4, 748 [AH_ESP_V4_FLOW] = ENETC_RSSHASH_L3, 749 [IPV4_FLOW] = ENETC_RSSHASH_L3, 750 [TCP_V6_FLOW] = ENETC_RSSHASH_L4, 751 [UDP_V6_FLOW] = ENETC_RSSHASH_L4, 752 [SCTP_V6_FLOW] = ENETC_RSSHASH_L4, 753 [AH_ESP_V6_FLOW] = ENETC_RSSHASH_L3, 754 [IPV6_FLOW] = ENETC_RSSHASH_L3, 755 [ETHER_FLOW] = 0, 756 }; 757 758 if (rxnfc->flow_type >= ARRAY_SIZE(rsshash)) 759 return -EINVAL; 760 761 rxnfc->data = rsshash[rxnfc->flow_type]; 762 763 return 0; 764 } 765 766 /* current HW spec does byte reversal on everything including MAC addresses */ 767 static void ether_addr_copy_swap(u8 *dst, const u8 *src) 768 { 769 int i; 770 771 for (i = 0; i < ETH_ALEN; i++) 772 dst[i] = src[ETH_ALEN - i - 1]; 773 } 774 775 static int enetc_set_cls_entry(struct enetc_si *si, 776 struct ethtool_rx_flow_spec *fs, bool en) 777 { 778 struct ethtool_tcpip4_spec *l4ip4_h, *l4ip4_m; 779 struct ethtool_usrip4_spec *l3ip4_h, *l3ip4_m; 780 struct ethhdr *eth_h, *eth_m; 781 struct enetc_cmd_rfse rfse = { {0} }; 782 783 if (!en) 784 goto done; 785 786 switch (fs->flow_type & 0xff) { 787 case TCP_V4_FLOW: 788 l4ip4_h = &fs->h_u.tcp_ip4_spec; 789 l4ip4_m = &fs->m_u.tcp_ip4_spec; 790 goto l4ip4; 791 case UDP_V4_FLOW: 792 l4ip4_h = &fs->h_u.udp_ip4_spec; 793 l4ip4_m = &fs->m_u.udp_ip4_spec; 794 goto l4ip4; 795 case SCTP_V4_FLOW: 796 l4ip4_h = &fs->h_u.sctp_ip4_spec; 797 l4ip4_m = &fs->m_u.sctp_ip4_spec; 798 l4ip4: 799 rfse.sip_h[0] = l4ip4_h->ip4src; 800 rfse.sip_m[0] = l4ip4_m->ip4src; 801 rfse.dip_h[0] = l4ip4_h->ip4dst; 802 rfse.dip_m[0] = l4ip4_m->ip4dst; 803 rfse.sport_h = ntohs(l4ip4_h->psrc); 804 rfse.sport_m = ntohs(l4ip4_m->psrc); 805 rfse.dport_h = ntohs(l4ip4_h->pdst); 806 rfse.dport_m = ntohs(l4ip4_m->pdst); 807 if (l4ip4_m->tos) 808 netdev_warn(si->ndev, "ToS field is not supported and was ignored\n"); 809 rfse.ethtype_h = ETH_P_IP; /* IPv4 */ 810 rfse.ethtype_m = 0xffff; 811 break; 812 case IP_USER_FLOW: 813 l3ip4_h = &fs->h_u.usr_ip4_spec; 814 l3ip4_m = &fs->m_u.usr_ip4_spec; 815 816 rfse.sip_h[0] = l3ip4_h->ip4src; 817 rfse.sip_m[0] = l3ip4_m->ip4src; 818 rfse.dip_h[0] = l3ip4_h->ip4dst; 819 rfse.dip_m[0] = l3ip4_m->ip4dst; 820 if (l3ip4_m->tos) 821 netdev_warn(si->ndev, "ToS field is not supported and was ignored\n"); 822 rfse.ethtype_h = ETH_P_IP; /* IPv4 */ 823 rfse.ethtype_m = 0xffff; 824 break; 825 case ETHER_FLOW: 826 eth_h = &fs->h_u.ether_spec; 827 eth_m = &fs->m_u.ether_spec; 828 829 ether_addr_copy_swap(rfse.smac_h, eth_h->h_source); 830 ether_addr_copy_swap(rfse.smac_m, eth_m->h_source); 831 ether_addr_copy_swap(rfse.dmac_h, eth_h->h_dest); 832 ether_addr_copy_swap(rfse.dmac_m, eth_m->h_dest); 833 rfse.ethtype_h = ntohs(eth_h->h_proto); 834 rfse.ethtype_m = ntohs(eth_m->h_proto); 835 break; 836 default: 837 return -EOPNOTSUPP; 838 } 839 840 rfse.mode |= ENETC_RFSE_EN; 841 if (fs->ring_cookie != RX_CLS_FLOW_DISC) { 842 rfse.mode |= ENETC_RFSE_MODE_BD; 843 rfse.result = fs->ring_cookie; 844 } 845 done: 846 return enetc_set_fs_entry(si, &rfse, fs->location); 847 } 848 849 static u32 enetc_get_rx_ring_count(struct net_device *ndev) 850 { 851 struct enetc_ndev_priv *priv = netdev_priv(ndev); 852 853 return priv->num_rx_rings; 854 } 855 856 static int enetc_get_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *rxnfc, 857 u32 *rule_locs) 858 { 859 struct enetc_ndev_priv *priv = netdev_priv(ndev); 860 int i, j; 861 862 if (!is_enetc_rev1(priv->si)) 863 return -EOPNOTSUPP; 864 865 switch (rxnfc->cmd) { 866 case ETHTOOL_GRXCLSRLCNT: 867 /* total number of entries */ 868 rxnfc->data = priv->si->num_fs_entries; 869 /* number of entries in use */ 870 rxnfc->rule_cnt = 0; 871 for (i = 0; i < priv->si->num_fs_entries; i++) 872 if (priv->cls_rules[i].used) 873 rxnfc->rule_cnt++; 874 break; 875 case ETHTOOL_GRXCLSRULE: 876 if (rxnfc->fs.location >= priv->si->num_fs_entries) 877 return -EINVAL; 878 879 /* get entry x */ 880 rxnfc->fs = priv->cls_rules[rxnfc->fs.location].fs; 881 break; 882 case ETHTOOL_GRXCLSRLALL: 883 /* total number of entries */ 884 rxnfc->data = priv->si->num_fs_entries; 885 /* array of indexes of used entries */ 886 j = 0; 887 for (i = 0; i < priv->si->num_fs_entries; i++) { 888 if (!priv->cls_rules[i].used) 889 continue; 890 if (j == rxnfc->rule_cnt) 891 return -EMSGSIZE; 892 rule_locs[j++] = i; 893 } 894 /* number of entries in use */ 895 rxnfc->rule_cnt = j; 896 break; 897 default: 898 return -EOPNOTSUPP; 899 } 900 901 return 0; 902 } 903 904 static int enetc_set_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *rxnfc) 905 { 906 struct enetc_ndev_priv *priv = netdev_priv(ndev); 907 int err; 908 909 if (!is_enetc_rev1(priv->si)) 910 return -EOPNOTSUPP; 911 912 switch (rxnfc->cmd) { 913 case ETHTOOL_SRXCLSRLINS: 914 if (rxnfc->fs.location >= priv->si->num_fs_entries) 915 return -EINVAL; 916 917 if (rxnfc->fs.ring_cookie >= priv->num_rx_rings && 918 rxnfc->fs.ring_cookie != RX_CLS_FLOW_DISC) 919 return -EINVAL; 920 921 err = enetc_set_cls_entry(priv->si, &rxnfc->fs, true); 922 if (err) 923 return err; 924 priv->cls_rules[rxnfc->fs.location].fs = rxnfc->fs; 925 priv->cls_rules[rxnfc->fs.location].used = 1; 926 break; 927 case ETHTOOL_SRXCLSRLDEL: 928 if (rxnfc->fs.location >= priv->si->num_fs_entries) 929 return -EINVAL; 930 931 err = enetc_set_cls_entry(priv->si, &rxnfc->fs, false); 932 if (err) 933 return err; 934 priv->cls_rules[rxnfc->fs.location].used = 0; 935 break; 936 default: 937 return -EOPNOTSUPP; 938 } 939 940 return 0; 941 } 942 943 static u32 enetc_get_rxfh_key_size(struct net_device *ndev) 944 { 945 struct enetc_ndev_priv *priv = netdev_priv(ndev); 946 947 /* return the size of the RX flow hash key. PF only */ 948 return (priv->si->hw.port) ? ENETC_RSSHASH_KEY_SIZE : 0; 949 } 950 951 static u32 enetc_get_rxfh_indir_size(struct net_device *ndev) 952 { 953 struct enetc_ndev_priv *priv = netdev_priv(ndev); 954 955 /* return the size of the RX flow hash indirection table */ 956 return priv->si->num_rss; 957 } 958 959 static int enetc_get_rss_key_base(struct enetc_si *si) 960 { 961 if (is_enetc_rev1(si)) 962 return ENETC_PRSSK(0); 963 964 return ENETC4_PRSSKR(0); 965 } 966 967 static void enetc_get_rss_key(struct enetc_si *si, const u8 *key) 968 { 969 int base = enetc_get_rss_key_base(si); 970 struct enetc_hw *hw = &si->hw; 971 int i; 972 973 for (i = 0; i < ENETC_RSSHASH_KEY_SIZE / 4; i++) 974 ((u32 *)key)[i] = enetc_port_rd(hw, base + i * 4); 975 } 976 977 static int enetc_get_rxfh(struct net_device *ndev, 978 struct ethtool_rxfh_param *rxfh) 979 { 980 struct enetc_ndev_priv *priv = netdev_priv(ndev); 981 struct enetc_si *si = priv->si; 982 int err = 0; 983 984 /* return hash function */ 985 rxfh->hfunc = ETH_RSS_HASH_TOP; 986 987 /* return hash key */ 988 if (rxfh->key && enetc_si_is_pf(si)) 989 enetc_get_rss_key(si, rxfh->key); 990 991 /* return RSS table */ 992 if (rxfh->indir) 993 err = si->ops->get_rss_table(si, rxfh->indir, si->num_rss); 994 995 return err; 996 } 997 998 void enetc_set_rss_key(struct enetc_si *si, const u8 *bytes) 999 { 1000 int base = enetc_get_rss_key_base(si); 1001 struct enetc_hw *hw = &si->hw; 1002 int i; 1003 1004 for (i = 0; i < ENETC_RSSHASH_KEY_SIZE / 4; i++) 1005 enetc_port_wr(hw, base + i * 4, ((u32 *)bytes)[i]); 1006 } 1007 EXPORT_SYMBOL_GPL(enetc_set_rss_key); 1008 1009 static int enetc_set_rxfh(struct net_device *ndev, 1010 struct ethtool_rxfh_param *rxfh, 1011 struct netlink_ext_ack *extack) 1012 { 1013 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1014 struct enetc_si *si = priv->si; 1015 int err = 0; 1016 1017 if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && 1018 rxfh->hfunc != ETH_RSS_HASH_TOP) 1019 return -EOPNOTSUPP; 1020 1021 /* set hash key, if PF */ 1022 if (rxfh->key) { 1023 if (!enetc_si_is_pf(si)) 1024 return -EOPNOTSUPP; 1025 1026 enetc_set_rss_key(si, rxfh->key); 1027 } 1028 1029 /* set RSS table */ 1030 if (rxfh->indir) 1031 err = si->ops->set_rss_table(si, rxfh->indir, si->num_rss); 1032 1033 return err; 1034 } 1035 1036 static void enetc_get_ringparam(struct net_device *ndev, 1037 struct ethtool_ringparam *ring, 1038 struct kernel_ethtool_ringparam *kernel_ring, 1039 struct netlink_ext_ack *extack) 1040 { 1041 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1042 1043 ring->rx_max_pending = priv->rx_bd_count; 1044 ring->tx_max_pending = priv->tx_bd_count; 1045 ring->rx_pending = priv->rx_bd_count; 1046 ring->tx_pending = priv->tx_bd_count; 1047 1048 /* do some h/w sanity checks for BDR length */ 1049 if (netif_running(ndev)) { 1050 struct enetc_hw *hw = &priv->si->hw; 1051 u32 val = enetc_rxbdr_rd(hw, 0, ENETC_RBLENR); 1052 1053 if (val != priv->rx_bd_count) 1054 netif_err(priv, hw, ndev, "RxBDR[RBLENR] = %d!\n", val); 1055 1056 val = enetc_txbdr_rd(hw, 0, ENETC_TBLENR); 1057 1058 if (val != priv->tx_bd_count) 1059 netif_err(priv, hw, ndev, "TxBDR[TBLENR] = %d!\n", val); 1060 } 1061 } 1062 1063 static int enetc_get_coalesce(struct net_device *ndev, 1064 struct ethtool_coalesce *ic, 1065 struct kernel_ethtool_coalesce *kernel_coal, 1066 struct netlink_ext_ack *extack) 1067 { 1068 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1069 struct enetc_int_vector *v = priv->int_vector[0]; 1070 u64 clk_freq = priv->sysclk_freq; 1071 1072 ic->tx_coalesce_usecs = enetc_cycles_to_usecs(priv->tx_ictt, clk_freq); 1073 ic->rx_coalesce_usecs = enetc_cycles_to_usecs(v->rx_ictt, clk_freq); 1074 1075 ic->tx_max_coalesced_frames = ENETC_TXIC_PKTTHR; 1076 ic->rx_max_coalesced_frames = ENETC_RXIC_PKTTHR; 1077 1078 ic->use_adaptive_rx_coalesce = priv->ic_mode & ENETC_IC_RX_ADAPTIVE; 1079 1080 return 0; 1081 } 1082 1083 static int enetc_set_coalesce(struct net_device *ndev, 1084 struct ethtool_coalesce *ic, 1085 struct kernel_ethtool_coalesce *kernel_coal, 1086 struct netlink_ext_ack *extack) 1087 { 1088 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1089 u64 clk_freq = priv->sysclk_freq; 1090 u32 rx_ictt, tx_ictt; 1091 int i, ic_mode; 1092 bool changed; 1093 1094 tx_ictt = enetc_usecs_to_cycles(ic->tx_coalesce_usecs, clk_freq); 1095 rx_ictt = enetc_usecs_to_cycles(ic->rx_coalesce_usecs, clk_freq); 1096 1097 if (ic->rx_max_coalesced_frames != ENETC_RXIC_PKTTHR) 1098 return -EOPNOTSUPP; 1099 1100 if (ic->tx_max_coalesced_frames != ENETC_TXIC_PKTTHR) 1101 return -EOPNOTSUPP; 1102 1103 ic_mode = ENETC_IC_NONE; 1104 if (ic->use_adaptive_rx_coalesce) { 1105 ic_mode |= ENETC_IC_RX_ADAPTIVE; 1106 rx_ictt = 0x1; 1107 } else { 1108 ic_mode |= rx_ictt ? ENETC_IC_RX_MANUAL : 0; 1109 } 1110 1111 ic_mode |= tx_ictt ? ENETC_IC_TX_MANUAL : 0; 1112 1113 /* commit the settings */ 1114 changed = (ic_mode != priv->ic_mode) || (priv->tx_ictt != tx_ictt); 1115 1116 priv->ic_mode = ic_mode; 1117 priv->tx_ictt = tx_ictt; 1118 1119 for (i = 0; i < priv->bdr_int_num; i++) { 1120 struct enetc_int_vector *v = priv->int_vector[i]; 1121 1122 v->rx_ictt = rx_ictt; 1123 v->rx_dim_en = !!(ic_mode & ENETC_IC_RX_ADAPTIVE); 1124 } 1125 1126 if (netif_running(ndev) && changed) { 1127 /* reconfigure the operation mode of h/w interrupts, 1128 * traffic needs to be paused in the process 1129 */ 1130 enetc_stop(ndev); 1131 enetc_start(ndev); 1132 } 1133 1134 return 0; 1135 } 1136 1137 static int enetc_get_phc_index_by_pdev(struct enetc_si *si) 1138 { 1139 struct pci_bus *bus = si->pdev->bus; 1140 struct pci_dev *timer_pdev; 1141 unsigned int devfn; 1142 int phc_index; 1143 1144 switch (si->revision) { 1145 case ENETC_REV_1_0: 1146 devfn = PCI_DEVFN(0, 4); 1147 break; 1148 case ENETC_REV_4_1: 1149 devfn = PCI_DEVFN(24, 0); 1150 break; 1151 case ENETC_REV_4_3: 1152 devfn = PCI_DEVFN(0, 1); 1153 break; 1154 default: 1155 return -1; 1156 } 1157 1158 timer_pdev = pci_get_domain_bus_and_slot(pci_domain_nr(bus), 1159 bus->number, devfn); 1160 if (!timer_pdev) 1161 return -1; 1162 1163 phc_index = ptp_clock_index_by_dev(&timer_pdev->dev); 1164 pci_dev_put(timer_pdev); 1165 1166 return phc_index; 1167 } 1168 1169 static int enetc_get_phc_index(struct enetc_si *si) 1170 { 1171 struct device_node *np = si->pdev->dev.of_node; 1172 struct device_node *timer_np; 1173 int phc_index; 1174 1175 if (!np) 1176 return enetc_get_phc_index_by_pdev(si); 1177 1178 timer_np = of_parse_phandle(np, "ptp-timer", 0); 1179 if (!timer_np) 1180 return enetc_get_phc_index_by_pdev(si); 1181 1182 phc_index = ptp_clock_index_by_of_node(timer_np); 1183 of_node_put(timer_np); 1184 1185 return phc_index; 1186 } 1187 1188 static void enetc_get_ts_generic_info(struct net_device *ndev, 1189 struct kernel_ethtool_ts_info *info) 1190 { 1191 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1192 1193 info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | 1194 SOF_TIMESTAMPING_RX_HARDWARE | 1195 SOF_TIMESTAMPING_RAW_HARDWARE | 1196 SOF_TIMESTAMPING_TX_SOFTWARE; 1197 1198 info->tx_types = (1 << HWTSTAMP_TX_OFF) | 1199 (1 << HWTSTAMP_TX_ON); 1200 1201 if (enetc_si_is_pf(priv->si)) 1202 info->tx_types |= (1 << HWTSTAMP_TX_ONESTEP_SYNC); 1203 1204 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | 1205 (1 << HWTSTAMP_FILTER_ALL); 1206 } 1207 1208 static int enetc_get_ts_info(struct net_device *ndev, 1209 struct kernel_ethtool_ts_info *info) 1210 { 1211 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1212 struct enetc_si *si = priv->si; 1213 1214 if (!enetc_ptp_clock_is_enabled(si)) 1215 goto timestamp_tx_sw; 1216 1217 info->phc_index = enetc_get_phc_index(si); 1218 if (info->phc_index < 0) 1219 goto timestamp_tx_sw; 1220 1221 enetc_get_ts_generic_info(ndev, info); 1222 1223 return 0; 1224 1225 timestamp_tx_sw: 1226 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE; 1227 1228 return 0; 1229 } 1230 1231 static void enetc_get_wol(struct net_device *dev, 1232 struct ethtool_wolinfo *wol) 1233 { 1234 wol->supported = 0; 1235 wol->wolopts = 0; 1236 1237 if (dev->phydev) 1238 phy_ethtool_get_wol(dev->phydev, wol); 1239 } 1240 1241 static int enetc_set_wol(struct net_device *dev, 1242 struct ethtool_wolinfo *wol) 1243 { 1244 int ret; 1245 1246 if (!dev->phydev) 1247 return -EOPNOTSUPP; 1248 1249 ret = phy_ethtool_set_wol(dev->phydev, wol); 1250 if (!ret) 1251 device_set_wakeup_enable(&dev->dev, wol->wolopts); 1252 1253 return ret; 1254 } 1255 1256 static void enetc_get_pauseparam(struct net_device *dev, 1257 struct ethtool_pauseparam *pause) 1258 { 1259 struct enetc_ndev_priv *priv = netdev_priv(dev); 1260 1261 phylink_ethtool_get_pauseparam(priv->phylink, pause); 1262 } 1263 1264 static int enetc_set_pauseparam(struct net_device *dev, 1265 struct ethtool_pauseparam *pause) 1266 { 1267 struct enetc_ndev_priv *priv = netdev_priv(dev); 1268 1269 return phylink_ethtool_set_pauseparam(priv->phylink, pause); 1270 } 1271 1272 static int enetc_get_link_ksettings(struct net_device *dev, 1273 struct ethtool_link_ksettings *cmd) 1274 { 1275 struct enetc_ndev_priv *priv = netdev_priv(dev); 1276 1277 if (!priv->phylink) 1278 return -EOPNOTSUPP; 1279 1280 return phylink_ethtool_ksettings_get(priv->phylink, cmd); 1281 } 1282 1283 static int enetc_set_link_ksettings(struct net_device *dev, 1284 const struct ethtool_link_ksettings *cmd) 1285 { 1286 struct enetc_ndev_priv *priv = netdev_priv(dev); 1287 1288 if (!priv->phylink) 1289 return -EOPNOTSUPP; 1290 1291 return phylink_ethtool_ksettings_set(priv->phylink, cmd); 1292 } 1293 1294 static void enetc_get_mm_stats(struct net_device *ndev, 1295 struct ethtool_mm_stats *s) 1296 { 1297 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1298 struct enetc_hw *hw = &priv->si->hw; 1299 struct enetc_si *si = priv->si; 1300 1301 if (!(si->hw_features & ENETC_SI_F_QBU)) 1302 return; 1303 1304 s->MACMergeFrameAssErrorCount = enetc_port_rd(hw, ENETC_MMFAECR); 1305 s->MACMergeFrameSmdErrorCount = enetc_port_rd(hw, ENETC_MMFSECR); 1306 s->MACMergeFrameAssOkCount = enetc_port_rd(hw, ENETC_MMFAOCR); 1307 s->MACMergeFragCountRx = enetc_port_rd(hw, ENETC_MMFCRXR); 1308 s->MACMergeFragCountTx = enetc_port_rd(hw, ENETC_MMFCTXR); 1309 s->MACMergeHoldCount = enetc_port_rd(hw, ENETC_MMHCR); 1310 } 1311 1312 static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state) 1313 { 1314 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1315 struct enetc_si *si = priv->si; 1316 struct enetc_hw *hw = &si->hw; 1317 u32 lafs, rafs, val; 1318 1319 if (!(si->hw_features & ENETC_SI_F_QBU)) 1320 return -EOPNOTSUPP; 1321 1322 mutex_lock(&priv->mm_lock); 1323 1324 val = enetc_port_rd(hw, ENETC_PFPMR); 1325 state->pmac_enabled = !!(val & ENETC_PFPMR_PMACE); 1326 1327 val = enetc_port_rd(hw, ENETC_MMCSR); 1328 1329 switch (ENETC_MMCSR_GET_VSTS(val)) { 1330 case 0: 1331 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_DISABLED; 1332 break; 1333 case 2: 1334 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_VERIFYING; 1335 break; 1336 case 3: 1337 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED; 1338 break; 1339 case 4: 1340 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_FAILED; 1341 break; 1342 case 5: 1343 default: 1344 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_UNKNOWN; 1345 break; 1346 } 1347 1348 rafs = ENETC_MMCSR_GET_RAFS(val); 1349 state->tx_min_frag_size = ethtool_mm_frag_size_add_to_min(rafs); 1350 lafs = ENETC_MMCSR_GET_LAFS(val); 1351 state->rx_min_frag_size = ethtool_mm_frag_size_add_to_min(lafs); 1352 state->tx_enabled = !!(val & ENETC_MMCSR_LPE); /* mirror of MMCSR_ME */ 1353 state->tx_active = state->tx_enabled && 1354 (state->verify_status == ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED || 1355 state->verify_status == ETHTOOL_MM_VERIFY_STATUS_DISABLED); 1356 state->verify_enabled = !(val & ENETC_MMCSR_VDIS); 1357 state->verify_time = ENETC_MMCSR_GET_VT(val); 1358 /* A verifyTime of 128 ms would exceed the 7 bit width 1359 * of the ENETC_MMCSR_VT field 1360 */ 1361 state->max_verify_time = 127; 1362 1363 mutex_unlock(&priv->mm_lock); 1364 1365 return 0; 1366 } 1367 1368 static int enetc_mm_wait_tx_active(struct enetc_hw *hw, int verify_time) 1369 { 1370 int timeout = verify_time * USEC_PER_MSEC * ENETC_MM_VERIFY_RETRIES; 1371 u32 val; 1372 1373 /* This will time out after the standard value of 3 verification 1374 * attempts. To not sleep forever, it relies on a non-zero verify_time, 1375 * guarantee which is provided by the ethtool nlattr policy. 1376 */ 1377 return read_poll_timeout(enetc_port_rd, val, 1378 ENETC_MMCSR_GET_VSTS(val) == 3, 1379 ENETC_MM_VERIFY_SLEEP_US, timeout, 1380 true, hw, ENETC_MMCSR); 1381 } 1382 1383 static void enetc_set_ptcfpr(struct enetc_hw *hw, u8 preemptible_tcs) 1384 { 1385 u32 val; 1386 int tc; 1387 1388 for (tc = 0; tc < 8; tc++) { 1389 val = enetc_port_rd(hw, ENETC_PTCFPR(tc)); 1390 1391 if (preemptible_tcs & BIT(tc)) 1392 val |= ENETC_PTCFPR_FPE; 1393 else 1394 val &= ~ENETC_PTCFPR_FPE; 1395 1396 enetc_port_wr(hw, ENETC_PTCFPR(tc), val); 1397 } 1398 } 1399 1400 /* ENETC does not have an IRQ to notify changes to the MAC Merge TX status 1401 * (active/inactive), but the preemptible traffic classes should only be 1402 * committed to hardware once TX is active. Resort to polling. 1403 */ 1404 void enetc_mm_commit_preemptible_tcs(struct enetc_ndev_priv *priv) 1405 { 1406 struct enetc_hw *hw = &priv->si->hw; 1407 u8 preemptible_tcs = 0; 1408 u32 val; 1409 int err; 1410 1411 val = enetc_port_rd(hw, ENETC_MMCSR); 1412 if (!(val & ENETC_MMCSR_ME)) 1413 goto out; 1414 1415 if (!(val & ENETC_MMCSR_VDIS)) { 1416 err = enetc_mm_wait_tx_active(hw, ENETC_MMCSR_GET_VT(val)); 1417 if (err) 1418 goto out; 1419 } 1420 1421 preemptible_tcs = priv->preemptible_tcs; 1422 out: 1423 enetc_set_ptcfpr(hw, preemptible_tcs); 1424 } 1425 1426 /* FIXME: Workaround for the link partner's verification failing if ENETC 1427 * priorly received too much express traffic. The documentation doesn't 1428 * suggest this is needed. 1429 */ 1430 static void enetc_restart_emac_rx(struct enetc_si *si) 1431 { 1432 u32 val = enetc_port_rd(&si->hw, ENETC_PM0_CMD_CFG); 1433 1434 enetc_port_wr(&si->hw, ENETC_PM0_CMD_CFG, val & ~ENETC_PM0_RX_EN); 1435 1436 if (val & ENETC_PM0_RX_EN) 1437 enetc_port_wr(&si->hw, ENETC_PM0_CMD_CFG, val); 1438 } 1439 1440 static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg, 1441 struct netlink_ext_ack *extack) 1442 { 1443 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1444 struct enetc_hw *hw = &priv->si->hw; 1445 struct enetc_si *si = priv->si; 1446 u32 val, add_frag_size; 1447 int err; 1448 1449 if (!(si->hw_features & ENETC_SI_F_QBU)) 1450 return -EOPNOTSUPP; 1451 1452 err = ethtool_mm_frag_size_min_to_add(cfg->tx_min_frag_size, 1453 &add_frag_size, extack); 1454 if (err) 1455 return err; 1456 1457 mutex_lock(&priv->mm_lock); 1458 1459 val = enetc_port_rd(hw, ENETC_PFPMR); 1460 if (cfg->pmac_enabled) 1461 val |= ENETC_PFPMR_PMACE; 1462 else 1463 val &= ~ENETC_PFPMR_PMACE; 1464 enetc_port_wr(hw, ENETC_PFPMR, val); 1465 1466 val = enetc_port_rd(hw, ENETC_MMCSR); 1467 1468 if (cfg->verify_enabled) 1469 val &= ~ENETC_MMCSR_VDIS; 1470 else 1471 val |= ENETC_MMCSR_VDIS; 1472 1473 if (cfg->tx_enabled) 1474 priv->active_offloads |= ENETC_F_QBU; 1475 else 1476 priv->active_offloads &= ~ENETC_F_QBU; 1477 1478 /* If link is up, enable/disable MAC Merge right away */ 1479 if (!(val & ENETC_MMCSR_LINK_FAIL)) { 1480 if (!!(priv->active_offloads & ENETC_F_QBU)) 1481 val |= ENETC_MMCSR_ME; 1482 else 1483 val &= ~ENETC_MMCSR_ME; 1484 } 1485 1486 val &= ~ENETC_MMCSR_VT_MASK; 1487 val |= ENETC_MMCSR_VT(cfg->verify_time); 1488 1489 val &= ~ENETC_MMCSR_RAFS_MASK; 1490 val |= ENETC_MMCSR_RAFS(add_frag_size); 1491 1492 enetc_port_wr(hw, ENETC_MMCSR, val); 1493 1494 enetc_restart_emac_rx(priv->si); 1495 1496 enetc_mm_commit_preemptible_tcs(priv); 1497 1498 mutex_unlock(&priv->mm_lock); 1499 1500 return 0; 1501 } 1502 1503 /* When the link is lost, the verification state machine goes to the FAILED 1504 * state and doesn't restart on its own after a new link up event. 1505 * According to 802.3 Figure 99-8 - Verify state diagram, the LINK_FAIL bit 1506 * should have been sufficient to re-trigger verification, but for ENETC it 1507 * doesn't. As a workaround, we need to toggle the Merge Enable bit to 1508 * re-trigger verification when link comes up. 1509 */ 1510 void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link) 1511 { 1512 struct enetc_hw *hw = &priv->si->hw; 1513 u32 val; 1514 1515 mutex_lock(&priv->mm_lock); 1516 1517 val = enetc_port_rd(hw, ENETC_MMCSR); 1518 1519 if (link) { 1520 val &= ~ENETC_MMCSR_LINK_FAIL; 1521 if (priv->active_offloads & ENETC_F_QBU) 1522 val |= ENETC_MMCSR_ME; 1523 } else { 1524 val |= ENETC_MMCSR_LINK_FAIL; 1525 if (priv->active_offloads & ENETC_F_QBU) 1526 val &= ~ENETC_MMCSR_ME; 1527 } 1528 1529 enetc_port_wr(hw, ENETC_MMCSR, val); 1530 1531 enetc_mm_commit_preemptible_tcs(priv); 1532 1533 mutex_unlock(&priv->mm_lock); 1534 } 1535 EXPORT_SYMBOL_GPL(enetc_mm_link_state_update); 1536 1537 const struct ethtool_ops enetc_pf_ethtool_ops = { 1538 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 1539 ETHTOOL_COALESCE_MAX_FRAMES | 1540 ETHTOOL_COALESCE_USE_ADAPTIVE_RX, 1541 .get_regs_len = enetc_get_reglen, 1542 .get_regs = enetc_get_regs, 1543 .get_sset_count = enetc_get_sset_count, 1544 .get_strings = enetc_get_strings, 1545 .get_ethtool_stats = enetc_get_ethtool_stats, 1546 .get_pause_stats = enetc_get_pause_stats, 1547 .get_rmon_stats = enetc_get_rmon_stats, 1548 .get_eth_ctrl_stats = enetc_get_eth_ctrl_stats, 1549 .get_eth_mac_stats = enetc_get_eth_mac_stats, 1550 .get_rx_ring_count = enetc_get_rx_ring_count, 1551 .get_rxnfc = enetc_get_rxnfc, 1552 .set_rxnfc = enetc_set_rxnfc, 1553 .get_rxfh_key_size = enetc_get_rxfh_key_size, 1554 .get_rxfh_indir_size = enetc_get_rxfh_indir_size, 1555 .get_rxfh = enetc_get_rxfh, 1556 .set_rxfh = enetc_set_rxfh, 1557 .get_rxfh_fields = enetc_get_rxfh_fields, 1558 .get_ringparam = enetc_get_ringparam, 1559 .get_coalesce = enetc_get_coalesce, 1560 .set_coalesce = enetc_set_coalesce, 1561 .get_link_ksettings = enetc_get_link_ksettings, 1562 .set_link_ksettings = enetc_set_link_ksettings, 1563 .get_link = ethtool_op_get_link, 1564 .get_ts_info = enetc_get_ts_info, 1565 .get_wol = enetc_get_wol, 1566 .set_wol = enetc_set_wol, 1567 .get_pauseparam = enetc_get_pauseparam, 1568 .set_pauseparam = enetc_set_pauseparam, 1569 .get_mm = enetc_get_mm, 1570 .set_mm = enetc_set_mm, 1571 .get_mm_stats = enetc_get_mm_stats, 1572 }; 1573 1574 const struct ethtool_ops enetc4_ppm_ethtool_ops = { 1575 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 1576 ETHTOOL_COALESCE_MAX_FRAMES | 1577 ETHTOOL_COALESCE_USE_ADAPTIVE_RX, 1578 .get_sset_count = enetc_get_sset_count, 1579 .get_strings = enetc_get_strings, 1580 .get_ethtool_stats = enetc_get_ethtool_stats, 1581 .get_eth_mac_stats = enetc_ppm_get_eth_mac_stats, 1582 .get_rx_ring_count = enetc_get_rx_ring_count, 1583 .get_rxfh_key_size = enetc_get_rxfh_key_size, 1584 .get_rxfh_indir_size = enetc_get_rxfh_indir_size, 1585 .get_rxfh = enetc_get_rxfh, 1586 .set_rxfh = enetc_set_rxfh, 1587 .get_rxfh_fields = enetc_get_rxfh_fields, 1588 .get_ringparam = enetc_get_ringparam, 1589 .get_coalesce = enetc_get_coalesce, 1590 .set_coalesce = enetc_set_coalesce, 1591 .get_link_ksettings = enetc_get_link_ksettings, 1592 .set_link_ksettings = enetc_set_link_ksettings, 1593 .get_link = ethtool_op_get_link, 1594 }; 1595 1596 const struct ethtool_ops enetc_vf_ethtool_ops = { 1597 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 1598 ETHTOOL_COALESCE_MAX_FRAMES | 1599 ETHTOOL_COALESCE_USE_ADAPTIVE_RX, 1600 .get_regs_len = enetc_get_reglen, 1601 .get_regs = enetc_get_regs, 1602 .get_sset_count = enetc_get_sset_count, 1603 .get_strings = enetc_get_strings, 1604 .get_ethtool_stats = enetc_get_ethtool_stats, 1605 .get_rx_ring_count = enetc_get_rx_ring_count, 1606 .get_rxnfc = enetc_get_rxnfc, 1607 .set_rxnfc = enetc_set_rxnfc, 1608 .get_rxfh_indir_size = enetc_get_rxfh_indir_size, 1609 .get_rxfh = enetc_get_rxfh, 1610 .set_rxfh = enetc_set_rxfh, 1611 .get_rxfh_fields = enetc_get_rxfh_fields, 1612 .get_ringparam = enetc_get_ringparam, 1613 .get_coalesce = enetc_get_coalesce, 1614 .set_coalesce = enetc_set_coalesce, 1615 .get_link = ethtool_op_get_link, 1616 .get_ts_info = enetc_get_ts_info, 1617 }; 1618 1619 const struct ethtool_ops enetc4_pf_ethtool_ops = { 1620 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 1621 ETHTOOL_COALESCE_MAX_FRAMES | 1622 ETHTOOL_COALESCE_USE_ADAPTIVE_RX, 1623 .get_sset_count = enetc_get_sset_count, 1624 .get_strings = enetc_get_strings, 1625 .get_ethtool_stats = enetc_get_ethtool_stats, 1626 .get_pause_stats = enetc_get_pause_stats, 1627 .get_rmon_stats = enetc_get_rmon_stats, 1628 .get_eth_ctrl_stats = enetc_get_eth_ctrl_stats, 1629 .get_eth_mac_stats = enetc_get_eth_mac_stats, 1630 .get_ringparam = enetc_get_ringparam, 1631 .get_coalesce = enetc_get_coalesce, 1632 .set_coalesce = enetc_set_coalesce, 1633 .get_link_ksettings = enetc_get_link_ksettings, 1634 .set_link_ksettings = enetc_set_link_ksettings, 1635 .get_link = ethtool_op_get_link, 1636 .get_wol = enetc_get_wol, 1637 .set_wol = enetc_set_wol, 1638 .get_pauseparam = enetc_get_pauseparam, 1639 .set_pauseparam = enetc_set_pauseparam, 1640 .get_rx_ring_count = enetc_get_rx_ring_count, 1641 .get_rxfh_key_size = enetc_get_rxfh_key_size, 1642 .get_rxfh_indir_size = enetc_get_rxfh_indir_size, 1643 .get_rxfh = enetc_get_rxfh, 1644 .set_rxfh = enetc_set_rxfh, 1645 .get_rxfh_fields = enetc_get_rxfh_fields, 1646 .get_ts_info = enetc_get_ts_info, 1647 }; 1648 1649 void enetc_set_ethtool_ops(struct net_device *ndev) 1650 { 1651 struct enetc_ndev_priv *priv = netdev_priv(ndev); 1652 1653 ndev->ethtool_ops = priv->si->drvdata->eth_ops; 1654 } 1655 EXPORT_SYMBOL_GPL(enetc_set_ethtool_ops); 1656