1 /* 2 * AMD 10Gb Ethernet driver 3 * 4 * This file is available to you under your choice of the following two 5 * licenses: 6 * 7 * License 1: GPLv2 8 * 9 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 10 * 11 * This file is free software; you may copy, redistribute and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation, either version 2 of the License, or (at 14 * your option) any later version. 15 * 16 * This file is distributed in the hope that it will be useful, but 17 * WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program. If not, see <http://www.gnu.org/licenses/>. 23 * 24 * This file incorporates work covered by the following copyright and 25 * permission notice: 26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation 27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 28 * Inc. unless otherwise expressly agreed to in writing between Synopsys 29 * and you. 30 * 31 * The Software IS NOT an item of Licensed Software or Licensed Product 32 * under any End User Software License Agreement or Agreement for Licensed 33 * Product with Synopsys or any supplement thereto. Permission is hereby 34 * granted, free of charge, to any person obtaining a copy of this software 35 * annotated with this license and the Software, to deal in the Software 36 * without restriction, including without limitation the rights to use, 37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 38 * of the Software, and to permit persons to whom the Software is furnished 39 * to do so, subject to the following conditions: 40 * 41 * The above copyright notice and this permission notice shall be included 42 * in all copies or substantial portions of the Software. 43 * 44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 54 * THE POSSIBILITY OF SUCH DAMAGE. 55 * 56 * 57 * License 2: Modified BSD 58 * 59 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 60 * All rights reserved. 61 * 62 * Redistribution and use in source and binary forms, with or without 63 * modification, are permitted provided that the following conditions are met: 64 * * Redistributions of source code must retain the above copyright 65 * notice, this list of conditions and the following disclaimer. 66 * * Redistributions in binary form must reproduce the above copyright 67 * notice, this list of conditions and the following disclaimer in the 68 * documentation and/or other materials provided with the distribution. 69 * * Neither the name of Advanced Micro Devices, Inc. nor the 70 * names of its contributors may be used to endorse or promote products 71 * derived from this software without specific prior written permission. 72 * 73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 76 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 77 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 79 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 80 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 81 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 82 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 83 * 84 * This file incorporates work covered by the following copyright and 85 * permission notice: 86 * The Synopsys DWC ETHER XGMAC Software Driver and documentation 87 * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 88 * Inc. unless otherwise expressly agreed to in writing between Synopsys 89 * and you. 90 * 91 * The Software IS NOT an item of Licensed Software or Licensed Product 92 * under any End User Software License Agreement or Agreement for Licensed 93 * Product with Synopsys or any supplement thereto. Permission is hereby 94 * granted, free of charge, to any person obtaining a copy of this software 95 * annotated with this license and the Software, to deal in the Software 96 * without restriction, including without limitation the rights to use, 97 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 98 * of the Software, and to permit persons to whom the Software is furnished 99 * to do so, subject to the following conditions: 100 * 101 * The above copyright notice and this permission notice shall be included 102 * in all copies or substantial portions of the Software. 103 * 104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 114 * THE POSSIBILITY OF SUCH DAMAGE. 115 */ 116 117 #include <linux/spinlock.h> 118 #include <linux/phy.h> 119 #include <linux/net_tstamp.h> 120 121 #include "xgbe.h" 122 #include "xgbe-common.h" 123 124 struct xgbe_stats { 125 char stat_string[ETH_GSTRING_LEN]; 126 int stat_size; 127 int stat_offset; 128 }; 129 130 #define XGMAC_MMC_STAT(_string, _var) \ 131 { _string, \ 132 FIELD_SIZEOF(struct xgbe_mmc_stats, _var), \ 133 offsetof(struct xgbe_prv_data, mmc_stats._var), \ 134 } 135 136 #define XGMAC_EXT_STAT(_string, _var) \ 137 { _string, \ 138 FIELD_SIZEOF(struct xgbe_ext_stats, _var), \ 139 offsetof(struct xgbe_prv_data, ext_stats._var), \ 140 } 141 142 static const struct xgbe_stats xgbe_gstring_stats[] = { 143 XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb), 144 XGMAC_MMC_STAT("tx_packets", txframecount_gb), 145 XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb), 146 XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb), 147 XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb), 148 XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g), 149 XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets), 150 XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb), 151 XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb), 152 XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb), 153 XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb), 154 XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb), 155 XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb), 156 XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror), 157 XGMAC_MMC_STAT("tx_pause_frames", txpauseframes), 158 159 XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb), 160 XGMAC_MMC_STAT("rx_packets", rxframecount_gb), 161 XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g), 162 XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g), 163 XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g), 164 XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb), 165 XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb), 166 XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb), 167 XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb), 168 XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb), 169 XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb), 170 XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb), 171 XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g), 172 XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g), 173 XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror), 174 XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror), 175 XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror), 176 XGMAC_MMC_STAT("rx_length_errors", rxlengtherror), 177 XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype), 178 XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow), 179 XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror), 180 XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes), 181 XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets), 182 XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable), 183 }; 184 185 #define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats) 186 187 static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data) 188 { 189 int i; 190 191 switch (stringset) { 192 case ETH_SS_STATS: 193 for (i = 0; i < XGBE_STATS_COUNT; i++) { 194 memcpy(data, xgbe_gstring_stats[i].stat_string, 195 ETH_GSTRING_LEN); 196 data += ETH_GSTRING_LEN; 197 } 198 break; 199 } 200 } 201 202 static void xgbe_get_ethtool_stats(struct net_device *netdev, 203 struct ethtool_stats *stats, u64 *data) 204 { 205 struct xgbe_prv_data *pdata = netdev_priv(netdev); 206 u8 *stat; 207 int i; 208 209 pdata->hw_if.read_mmc_stats(pdata); 210 for (i = 0; i < XGBE_STATS_COUNT; i++) { 211 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset; 212 *data++ = *(u64 *)stat; 213 } 214 } 215 216 static int xgbe_get_sset_count(struct net_device *netdev, int stringset) 217 { 218 int ret; 219 220 switch (stringset) { 221 case ETH_SS_STATS: 222 ret = XGBE_STATS_COUNT; 223 break; 224 225 default: 226 ret = -EOPNOTSUPP; 227 } 228 229 return ret; 230 } 231 232 static void xgbe_get_pauseparam(struct net_device *netdev, 233 struct ethtool_pauseparam *pause) 234 { 235 struct xgbe_prv_data *pdata = netdev_priv(netdev); 236 237 pause->autoneg = pdata->phy.pause_autoneg; 238 pause->tx_pause = pdata->phy.tx_pause; 239 pause->rx_pause = pdata->phy.rx_pause; 240 } 241 242 static int xgbe_set_pauseparam(struct net_device *netdev, 243 struct ethtool_pauseparam *pause) 244 { 245 struct xgbe_prv_data *pdata = netdev_priv(netdev); 246 int ret = 0; 247 248 if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) { 249 netdev_err(netdev, 250 "autoneg disabled, pause autoneg not avialable\n"); 251 return -EINVAL; 252 } 253 254 pdata->phy.pause_autoneg = pause->autoneg; 255 pdata->phy.tx_pause = pause->tx_pause; 256 pdata->phy.rx_pause = pause->rx_pause; 257 258 pdata->phy.advertising &= ~ADVERTISED_Pause; 259 pdata->phy.advertising &= ~ADVERTISED_Asym_Pause; 260 261 if (pause->rx_pause) { 262 pdata->phy.advertising |= ADVERTISED_Pause; 263 pdata->phy.advertising |= ADVERTISED_Asym_Pause; 264 } 265 266 if (pause->tx_pause) 267 pdata->phy.advertising ^= ADVERTISED_Asym_Pause; 268 269 if (netif_running(netdev)) 270 ret = pdata->phy_if.phy_config_aneg(pdata); 271 272 return ret; 273 } 274 275 static int xgbe_get_link_ksettings(struct net_device *netdev, 276 struct ethtool_link_ksettings *cmd) 277 { 278 struct xgbe_prv_data *pdata = netdev_priv(netdev); 279 280 cmd->base.phy_address = pdata->phy.address; 281 282 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, 283 pdata->phy.supported); 284 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, 285 pdata->phy.advertising); 286 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.lp_advertising, 287 pdata->phy.lp_advertising); 288 289 cmd->base.autoneg = pdata->phy.autoneg; 290 cmd->base.speed = pdata->phy.speed; 291 cmd->base.duplex = pdata->phy.duplex; 292 293 cmd->base.port = PORT_NONE; 294 295 return 0; 296 } 297 298 static int xgbe_set_link_ksettings(struct net_device *netdev, 299 const struct ethtool_link_ksettings *cmd) 300 { 301 struct xgbe_prv_data *pdata = netdev_priv(netdev); 302 u32 advertising; 303 u32 speed; 304 int ret; 305 306 speed = cmd->base.speed; 307 308 if (cmd->base.phy_address != pdata->phy.address) { 309 netdev_err(netdev, "invalid phy address %hhu\n", 310 cmd->base.phy_address); 311 return -EINVAL; 312 } 313 314 if ((cmd->base.autoneg != AUTONEG_ENABLE) && 315 (cmd->base.autoneg != AUTONEG_DISABLE)) { 316 netdev_err(netdev, "unsupported autoneg %hhu\n", 317 cmd->base.autoneg); 318 return -EINVAL; 319 } 320 321 if (cmd->base.autoneg == AUTONEG_DISABLE) { 322 if (!pdata->phy_if.phy_valid_speed(pdata, speed)) { 323 netdev_err(netdev, "unsupported speed %u\n", speed); 324 return -EINVAL; 325 } 326 327 if (cmd->base.duplex != DUPLEX_FULL) { 328 netdev_err(netdev, "unsupported duplex %hhu\n", 329 cmd->base.duplex); 330 return -EINVAL; 331 } 332 } 333 334 ethtool_convert_link_mode_to_legacy_u32(&advertising, 335 cmd->link_modes.advertising); 336 337 netif_dbg(pdata, link, netdev, 338 "requested advertisement %#x, phy supported %#x\n", 339 advertising, pdata->phy.supported); 340 341 advertising &= pdata->phy.supported; 342 if ((cmd->base.autoneg == AUTONEG_ENABLE) && !advertising) { 343 netdev_err(netdev, 344 "unsupported requested advertisement\n"); 345 return -EINVAL; 346 } 347 348 ret = 0; 349 pdata->phy.autoneg = cmd->base.autoneg; 350 pdata->phy.speed = speed; 351 pdata->phy.duplex = cmd->base.duplex; 352 pdata->phy.advertising = advertising; 353 354 if (cmd->base.autoneg == AUTONEG_ENABLE) 355 pdata->phy.advertising |= ADVERTISED_Autoneg; 356 else 357 pdata->phy.advertising &= ~ADVERTISED_Autoneg; 358 359 if (netif_running(netdev)) 360 ret = pdata->phy_if.phy_config_aneg(pdata); 361 362 return ret; 363 } 364 365 static void xgbe_get_drvinfo(struct net_device *netdev, 366 struct ethtool_drvinfo *drvinfo) 367 { 368 struct xgbe_prv_data *pdata = netdev_priv(netdev); 369 struct xgbe_hw_features *hw_feat = &pdata->hw_feat; 370 371 strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver)); 372 strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version)); 373 strlcpy(drvinfo->bus_info, dev_name(pdata->dev), 374 sizeof(drvinfo->bus_info)); 375 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d", 376 XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER), 377 XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID), 378 XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER)); 379 } 380 381 static u32 xgbe_get_msglevel(struct net_device *netdev) 382 { 383 struct xgbe_prv_data *pdata = netdev_priv(netdev); 384 385 return pdata->msg_enable; 386 } 387 388 static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel) 389 { 390 struct xgbe_prv_data *pdata = netdev_priv(netdev); 391 392 pdata->msg_enable = msglevel; 393 } 394 395 static int xgbe_get_coalesce(struct net_device *netdev, 396 struct ethtool_coalesce *ec) 397 { 398 struct xgbe_prv_data *pdata = netdev_priv(netdev); 399 400 memset(ec, 0, sizeof(struct ethtool_coalesce)); 401 402 ec->rx_coalesce_usecs = pdata->rx_usecs; 403 ec->rx_max_coalesced_frames = pdata->rx_frames; 404 405 ec->tx_max_coalesced_frames = pdata->tx_frames; 406 407 return 0; 408 } 409 410 static int xgbe_set_coalesce(struct net_device *netdev, 411 struct ethtool_coalesce *ec) 412 { 413 struct xgbe_prv_data *pdata = netdev_priv(netdev); 414 struct xgbe_hw_if *hw_if = &pdata->hw_if; 415 unsigned int rx_frames, rx_riwt, rx_usecs; 416 unsigned int tx_frames; 417 418 /* Check for not supported parameters */ 419 if ((ec->rx_coalesce_usecs_irq) || 420 (ec->rx_max_coalesced_frames_irq) || 421 (ec->tx_coalesce_usecs) || 422 (ec->tx_coalesce_usecs_irq) || 423 (ec->tx_max_coalesced_frames_irq) || 424 (ec->stats_block_coalesce_usecs) || 425 (ec->use_adaptive_rx_coalesce) || 426 (ec->use_adaptive_tx_coalesce) || 427 (ec->pkt_rate_low) || 428 (ec->rx_coalesce_usecs_low) || 429 (ec->rx_max_coalesced_frames_low) || 430 (ec->tx_coalesce_usecs_low) || 431 (ec->tx_max_coalesced_frames_low) || 432 (ec->pkt_rate_high) || 433 (ec->rx_coalesce_usecs_high) || 434 (ec->rx_max_coalesced_frames_high) || 435 (ec->tx_coalesce_usecs_high) || 436 (ec->tx_max_coalesced_frames_high) || 437 (ec->rate_sample_interval)) { 438 netdev_err(netdev, "unsupported coalescing parameter\n"); 439 return -EOPNOTSUPP; 440 } 441 442 rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs); 443 rx_usecs = ec->rx_coalesce_usecs; 444 rx_frames = ec->rx_max_coalesced_frames; 445 446 /* Use smallest possible value if conversion resulted in zero */ 447 if (rx_usecs && !rx_riwt) 448 rx_riwt = 1; 449 450 /* Check the bounds of values for Rx */ 451 if (rx_riwt > XGMAC_MAX_DMA_RIWT) { 452 netdev_err(netdev, "rx-usec is limited to %d usecs\n", 453 hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT)); 454 return -EINVAL; 455 } 456 if (rx_frames > pdata->rx_desc_count) { 457 netdev_err(netdev, "rx-frames is limited to %d frames\n", 458 pdata->rx_desc_count); 459 return -EINVAL; 460 } 461 462 tx_frames = ec->tx_max_coalesced_frames; 463 464 /* Check the bounds of values for Tx */ 465 if (tx_frames > pdata->tx_desc_count) { 466 netdev_err(netdev, "tx-frames is limited to %d frames\n", 467 pdata->tx_desc_count); 468 return -EINVAL; 469 } 470 471 pdata->rx_riwt = rx_riwt; 472 pdata->rx_usecs = rx_usecs; 473 pdata->rx_frames = rx_frames; 474 hw_if->config_rx_coalesce(pdata); 475 476 pdata->tx_frames = tx_frames; 477 hw_if->config_tx_coalesce(pdata); 478 479 return 0; 480 } 481 482 static int xgbe_get_rxnfc(struct net_device *netdev, 483 struct ethtool_rxnfc *rxnfc, u32 *rule_locs) 484 { 485 struct xgbe_prv_data *pdata = netdev_priv(netdev); 486 487 switch (rxnfc->cmd) { 488 case ETHTOOL_GRXRINGS: 489 rxnfc->data = pdata->rx_ring_count; 490 break; 491 default: 492 return -EOPNOTSUPP; 493 } 494 495 return 0; 496 } 497 498 static u32 xgbe_get_rxfh_key_size(struct net_device *netdev) 499 { 500 struct xgbe_prv_data *pdata = netdev_priv(netdev); 501 502 return sizeof(pdata->rss_key); 503 } 504 505 static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev) 506 { 507 struct xgbe_prv_data *pdata = netdev_priv(netdev); 508 509 return ARRAY_SIZE(pdata->rss_table); 510 } 511 512 static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, 513 u8 *hfunc) 514 { 515 struct xgbe_prv_data *pdata = netdev_priv(netdev); 516 unsigned int i; 517 518 if (indir) { 519 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++) 520 indir[i] = XGMAC_GET_BITS(pdata->rss_table[i], 521 MAC_RSSDR, DMCH); 522 } 523 524 if (key) 525 memcpy(key, pdata->rss_key, sizeof(pdata->rss_key)); 526 527 if (hfunc) 528 *hfunc = ETH_RSS_HASH_TOP; 529 530 return 0; 531 } 532 533 static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir, 534 const u8 *key, const u8 hfunc) 535 { 536 struct xgbe_prv_data *pdata = netdev_priv(netdev); 537 struct xgbe_hw_if *hw_if = &pdata->hw_if; 538 unsigned int ret; 539 540 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) { 541 netdev_err(netdev, "unsupported hash function\n"); 542 return -EOPNOTSUPP; 543 } 544 545 if (indir) { 546 ret = hw_if->set_rss_lookup_table(pdata, indir); 547 if (ret) 548 return ret; 549 } 550 551 if (key) { 552 ret = hw_if->set_rss_hash_key(pdata, key); 553 if (ret) 554 return ret; 555 } 556 557 return 0; 558 } 559 560 static int xgbe_get_ts_info(struct net_device *netdev, 561 struct ethtool_ts_info *ts_info) 562 { 563 struct xgbe_prv_data *pdata = netdev_priv(netdev); 564 565 ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | 566 SOF_TIMESTAMPING_RX_SOFTWARE | 567 SOF_TIMESTAMPING_SOFTWARE | 568 SOF_TIMESTAMPING_TX_HARDWARE | 569 SOF_TIMESTAMPING_RX_HARDWARE | 570 SOF_TIMESTAMPING_RAW_HARDWARE; 571 572 if (pdata->ptp_clock) 573 ts_info->phc_index = ptp_clock_index(pdata->ptp_clock); 574 else 575 ts_info->phc_index = -1; 576 577 ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); 578 ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | 579 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | 580 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | 581 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | 582 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | 583 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | 584 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) | 585 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) | 586 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) | 587 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | 588 (1 << HWTSTAMP_FILTER_ALL); 589 590 return 0; 591 } 592 593 static const struct ethtool_ops xgbe_ethtool_ops = { 594 .get_drvinfo = xgbe_get_drvinfo, 595 .get_msglevel = xgbe_get_msglevel, 596 .set_msglevel = xgbe_set_msglevel, 597 .get_link = ethtool_op_get_link, 598 .get_coalesce = xgbe_get_coalesce, 599 .set_coalesce = xgbe_set_coalesce, 600 .get_pauseparam = xgbe_get_pauseparam, 601 .set_pauseparam = xgbe_set_pauseparam, 602 .get_strings = xgbe_get_strings, 603 .get_ethtool_stats = xgbe_get_ethtool_stats, 604 .get_sset_count = xgbe_get_sset_count, 605 .get_rxnfc = xgbe_get_rxnfc, 606 .get_rxfh_key_size = xgbe_get_rxfh_key_size, 607 .get_rxfh_indir_size = xgbe_get_rxfh_indir_size, 608 .get_rxfh = xgbe_get_rxfh, 609 .set_rxfh = xgbe_set_rxfh, 610 .get_ts_info = xgbe_get_ts_info, 611 .get_link_ksettings = xgbe_get_link_ksettings, 612 .set_link_ksettings = xgbe_set_link_ksettings, 613 }; 614 615 const struct ethtool_ops *xgbe_get_ethtool_ops(void) 616 { 617 return &xgbe_ethtool_ops; 618 } 619