igb_ethtool.c revision 373e6978f9c5c05af3b3ec4cd0295b0bfbe11644
1/******************************************************************************* 2 3 Intel(R) Gigabit Ethernet Linux driver 4 Copyright(c) 2007-2013 Intel Corporation. 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms and conditions of the GNU General Public License, 8 version 2, as published by the Free Software Foundation. 9 10 This program is distributed in the hope it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 more details. 14 15 You should have received a copy of the GNU General Public License along with 16 this program; if not, write to the Free Software Foundation, Inc., 17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18 19 The full GNU General Public License is included in this distribution in 20 the file called "COPYING". 21 22 Contact Information: 23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 25 26*******************************************************************************/ 27 28/* ethtool support for igb */ 29 30#include <linux/vmalloc.h> 31#include <linux/netdevice.h> 32#include <linux/pci.h> 33#include <linux/delay.h> 34#include <linux/interrupt.h> 35#include <linux/if_ether.h> 36#include <linux/ethtool.h> 37#include <linux/sched.h> 38#include <linux/slab.h> 39#include <linux/pm_runtime.h> 40#include <linux/highmem.h> 41#include <linux/mdio.h> 42 43#include "igb.h" 44 45struct igb_stats { 46 char stat_string[ETH_GSTRING_LEN]; 47 int sizeof_stat; 48 int stat_offset; 49}; 50 51#define IGB_STAT(_name, _stat) { \ 52 .stat_string = _name, \ 53 .sizeof_stat = FIELD_SIZEOF(struct igb_adapter, _stat), \ 54 .stat_offset = offsetof(struct igb_adapter, _stat) \ 55} 56static const struct igb_stats igb_gstrings_stats[] = { 57 IGB_STAT("rx_packets", stats.gprc), 58 IGB_STAT("tx_packets", stats.gptc), 59 IGB_STAT("rx_bytes", stats.gorc), 60 IGB_STAT("tx_bytes", stats.gotc), 61 IGB_STAT("rx_broadcast", stats.bprc), 62 IGB_STAT("tx_broadcast", stats.bptc), 63 IGB_STAT("rx_multicast", stats.mprc), 64 IGB_STAT("tx_multicast", stats.mptc), 65 IGB_STAT("multicast", stats.mprc), 66 IGB_STAT("collisions", stats.colc), 67 IGB_STAT("rx_crc_errors", stats.crcerrs), 68 IGB_STAT("rx_no_buffer_count", stats.rnbc), 69 IGB_STAT("rx_missed_errors", stats.mpc), 70 IGB_STAT("tx_aborted_errors", stats.ecol), 71 IGB_STAT("tx_carrier_errors", stats.tncrs), 72 IGB_STAT("tx_window_errors", stats.latecol), 73 IGB_STAT("tx_abort_late_coll", stats.latecol), 74 IGB_STAT("tx_deferred_ok", stats.dc), 75 IGB_STAT("tx_single_coll_ok", stats.scc), 76 IGB_STAT("tx_multi_coll_ok", stats.mcc), 77 IGB_STAT("tx_timeout_count", tx_timeout_count), 78 IGB_STAT("rx_long_length_errors", stats.roc), 79 IGB_STAT("rx_short_length_errors", stats.ruc), 80 IGB_STAT("rx_align_errors", stats.algnerrc), 81 IGB_STAT("tx_tcp_seg_good", stats.tsctc), 82 IGB_STAT("tx_tcp_seg_failed", stats.tsctfc), 83 IGB_STAT("rx_flow_control_xon", stats.xonrxc), 84 IGB_STAT("rx_flow_control_xoff", stats.xoffrxc), 85 IGB_STAT("tx_flow_control_xon", stats.xontxc), 86 IGB_STAT("tx_flow_control_xoff", stats.xofftxc), 87 IGB_STAT("rx_long_byte_count", stats.gorc), 88 IGB_STAT("tx_dma_out_of_sync", stats.doosync), 89 IGB_STAT("tx_smbus", stats.mgptc), 90 IGB_STAT("rx_smbus", stats.mgprc), 91 IGB_STAT("dropped_smbus", stats.mgpdc), 92 IGB_STAT("os2bmc_rx_by_bmc", stats.o2bgptc), 93 IGB_STAT("os2bmc_tx_by_bmc", stats.b2ospc), 94 IGB_STAT("os2bmc_tx_by_host", stats.o2bspc), 95 IGB_STAT("os2bmc_rx_by_host", stats.b2ogprc), 96 IGB_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts), 97 IGB_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared), 98}; 99 100#define IGB_NETDEV_STAT(_net_stat) { \ 101 .stat_string = __stringify(_net_stat), \ 102 .sizeof_stat = FIELD_SIZEOF(struct rtnl_link_stats64, _net_stat), \ 103 .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \ 104} 105static const struct igb_stats igb_gstrings_net_stats[] = { 106 IGB_NETDEV_STAT(rx_errors), 107 IGB_NETDEV_STAT(tx_errors), 108 IGB_NETDEV_STAT(tx_dropped), 109 IGB_NETDEV_STAT(rx_length_errors), 110 IGB_NETDEV_STAT(rx_over_errors), 111 IGB_NETDEV_STAT(rx_frame_errors), 112 IGB_NETDEV_STAT(rx_fifo_errors), 113 IGB_NETDEV_STAT(tx_fifo_errors), 114 IGB_NETDEV_STAT(tx_heartbeat_errors) 115}; 116 117#define IGB_GLOBAL_STATS_LEN \ 118 (sizeof(igb_gstrings_stats) / sizeof(struct igb_stats)) 119#define IGB_NETDEV_STATS_LEN \ 120 (sizeof(igb_gstrings_net_stats) / sizeof(struct igb_stats)) 121#define IGB_RX_QUEUE_STATS_LEN \ 122 (sizeof(struct igb_rx_queue_stats) / sizeof(u64)) 123 124#define IGB_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */ 125 126#define IGB_QUEUE_STATS_LEN \ 127 ((((struct igb_adapter *)netdev_priv(netdev))->num_rx_queues * \ 128 IGB_RX_QUEUE_STATS_LEN) + \ 129 (((struct igb_adapter *)netdev_priv(netdev))->num_tx_queues * \ 130 IGB_TX_QUEUE_STATS_LEN)) 131#define IGB_STATS_LEN \ 132 (IGB_GLOBAL_STATS_LEN + IGB_NETDEV_STATS_LEN + IGB_QUEUE_STATS_LEN) 133 134static const char igb_gstrings_test[][ETH_GSTRING_LEN] = { 135 "Register test (offline)", "Eeprom test (offline)", 136 "Interrupt test (offline)", "Loopback test (offline)", 137 "Link test (on/offline)" 138}; 139#define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN) 140 141static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) 142{ 143 struct igb_adapter *adapter = netdev_priv(netdev); 144 struct e1000_hw *hw = &adapter->hw; 145 struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575; 146 struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags; 147 u32 status; 148 149 if (hw->phy.media_type == e1000_media_type_copper) { 150 151 ecmd->supported = (SUPPORTED_10baseT_Half | 152 SUPPORTED_10baseT_Full | 153 SUPPORTED_100baseT_Half | 154 SUPPORTED_100baseT_Full | 155 SUPPORTED_1000baseT_Full| 156 SUPPORTED_Autoneg | 157 SUPPORTED_TP | 158 SUPPORTED_Pause); 159 ecmd->advertising = ADVERTISED_TP; 160 161 if (hw->mac.autoneg == 1) { 162 ecmd->advertising |= ADVERTISED_Autoneg; 163 /* the e1000 autoneg seems to match ethtool nicely */ 164 ecmd->advertising |= hw->phy.autoneg_advertised; 165 } 166 167 ecmd->port = PORT_TP; 168 ecmd->phy_address = hw->phy.addr; 169 ecmd->transceiver = XCVR_INTERNAL; 170 } else { 171 ecmd->supported = (SUPPORTED_FIBRE | 172 SUPPORTED_Autoneg | 173 SUPPORTED_Pause); 174 ecmd->advertising = ADVERTISED_FIBRE; 175 if (hw->mac.type == e1000_i354) { 176 ecmd->supported |= SUPPORTED_2500baseX_Full; 177 ecmd->advertising |= ADVERTISED_2500baseX_Full; 178 } 179 if ((eth_flags->e1000_base_lx) || (eth_flags->e1000_base_sx)) { 180 ecmd->supported |= SUPPORTED_1000baseT_Full; 181 ecmd->advertising |= ADVERTISED_1000baseT_Full; 182 } 183 if (eth_flags->e100_base_fx) { 184 ecmd->supported |= SUPPORTED_100baseT_Full; 185 ecmd->advertising |= ADVERTISED_100baseT_Full; 186 } 187 if (hw->mac.autoneg == 1) 188 ecmd->advertising |= ADVERTISED_Autoneg; 189 190 ecmd->port = PORT_FIBRE; 191 ecmd->transceiver = XCVR_EXTERNAL; 192 } 193 194 if (hw->mac.autoneg != 1) 195 ecmd->advertising &= ~(ADVERTISED_Pause | 196 ADVERTISED_Asym_Pause); 197 198 if (hw->fc.requested_mode == e1000_fc_full) 199 ecmd->advertising |= ADVERTISED_Pause; 200 else if (hw->fc.requested_mode == e1000_fc_rx_pause) 201 ecmd->advertising |= (ADVERTISED_Pause | 202 ADVERTISED_Asym_Pause); 203 else if (hw->fc.requested_mode == e1000_fc_tx_pause) 204 ecmd->advertising |= ADVERTISED_Asym_Pause; 205 else 206 ecmd->advertising &= ~(ADVERTISED_Pause | 207 ADVERTISED_Asym_Pause); 208 209 status = rd32(E1000_STATUS); 210 211 if (status & E1000_STATUS_LU) { 212 if ((hw->mac.type == e1000_i354) && 213 (status & E1000_STATUS_2P5_SKU) && 214 !(status & E1000_STATUS_2P5_SKU_OVER)) 215 ecmd->speed = SPEED_2500; 216 else if (status & E1000_STATUS_SPEED_1000) 217 ecmd->speed = SPEED_1000; 218 else if (status & E1000_STATUS_SPEED_100) 219 ecmd->speed = SPEED_100; 220 else 221 ecmd->speed = SPEED_10; 222 if ((status & E1000_STATUS_FD) || 223 hw->phy.media_type != e1000_media_type_copper) 224 ecmd->duplex = DUPLEX_FULL; 225 else 226 ecmd->duplex = DUPLEX_HALF; 227 } else { 228 ecmd->speed = -1; 229 ecmd->duplex = -1; 230 } 231 232 if ((hw->phy.media_type == e1000_media_type_fiber) || 233 hw->mac.autoneg) 234 ecmd->autoneg = AUTONEG_ENABLE; 235 else 236 ecmd->autoneg = AUTONEG_DISABLE; 237 238 /* MDI-X => 2; MDI =>1; Invalid =>0 */ 239 if (hw->phy.media_type == e1000_media_type_copper) 240 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : 241 ETH_TP_MDI; 242 else 243 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID; 244 245 if (hw->phy.mdix == AUTO_ALL_MODES) 246 ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO; 247 else 248 ecmd->eth_tp_mdix_ctrl = hw->phy.mdix; 249 250 return 0; 251} 252 253static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) 254{ 255 struct igb_adapter *adapter = netdev_priv(netdev); 256 struct e1000_hw *hw = &adapter->hw; 257 258 /* When SoL/IDER sessions are active, autoneg/speed/duplex 259 * cannot be changed 260 */ 261 if (igb_check_reset_block(hw)) { 262 dev_err(&adapter->pdev->dev, 263 "Cannot change link characteristics when SoL/IDER is active.\n"); 264 return -EINVAL; 265 } 266 267 /* MDI setting is only allowed when autoneg enabled because 268 * some hardware doesn't allow MDI setting when speed or 269 * duplex is forced. 270 */ 271 if (ecmd->eth_tp_mdix_ctrl) { 272 if (hw->phy.media_type != e1000_media_type_copper) 273 return -EOPNOTSUPP; 274 275 if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) && 276 (ecmd->autoneg != AUTONEG_ENABLE)) { 277 dev_err(&adapter->pdev->dev, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n"); 278 return -EINVAL; 279 } 280 } 281 282 while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) 283 msleep(1); 284 285 if (ecmd->autoneg == AUTONEG_ENABLE) { 286 hw->mac.autoneg = 1; 287 if (hw->phy.media_type == e1000_media_type_fiber) { 288 hw->phy.autoneg_advertised = ecmd->advertising | 289 ADVERTISED_FIBRE | 290 ADVERTISED_Autoneg; 291 switch (adapter->link_speed) { 292 case SPEED_2500: 293 hw->phy.autoneg_advertised = 294 ADVERTISED_2500baseX_Full; 295 break; 296 case SPEED_1000: 297 hw->phy.autoneg_advertised = 298 ADVERTISED_1000baseT_Full; 299 break; 300 case SPEED_100: 301 hw->phy.autoneg_advertised = 302 ADVERTISED_100baseT_Full; 303 break; 304 default: 305 break; 306 } 307 } else { 308 hw->phy.autoneg_advertised = ecmd->advertising | 309 ADVERTISED_TP | 310 ADVERTISED_Autoneg; 311 } 312 ecmd->advertising = hw->phy.autoneg_advertised; 313 if (adapter->fc_autoneg) 314 hw->fc.requested_mode = e1000_fc_default; 315 } else { 316 u32 speed = ethtool_cmd_speed(ecmd); 317 /* calling this overrides forced MDI setting */ 318 if (igb_set_spd_dplx(adapter, speed, ecmd->duplex)) { 319 clear_bit(__IGB_RESETTING, &adapter->state); 320 return -EINVAL; 321 } 322 } 323 324 /* MDI-X => 2; MDI => 1; Auto => 3 */ 325 if (ecmd->eth_tp_mdix_ctrl) { 326 /* fix up the value for auto (3 => 0) as zero is mapped 327 * internally to auto 328 */ 329 if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO) 330 hw->phy.mdix = AUTO_ALL_MODES; 331 else 332 hw->phy.mdix = ecmd->eth_tp_mdix_ctrl; 333 } 334 335 /* reset the link */ 336 if (netif_running(adapter->netdev)) { 337 igb_down(adapter); 338 igb_up(adapter); 339 } else 340 igb_reset(adapter); 341 342 clear_bit(__IGB_RESETTING, &adapter->state); 343 return 0; 344} 345 346static u32 igb_get_link(struct net_device *netdev) 347{ 348 struct igb_adapter *adapter = netdev_priv(netdev); 349 struct e1000_mac_info *mac = &adapter->hw.mac; 350 351 /* If the link is not reported up to netdev, interrupts are disabled, 352 * and so the physical link state may have changed since we last 353 * looked. Set get_link_status to make sure that the true link 354 * state is interrogated, rather than pulling a cached and possibly 355 * stale link state from the driver. 356 */ 357 if (!netif_carrier_ok(netdev)) 358 mac->get_link_status = 1; 359 360 return igb_has_link(adapter); 361} 362 363static void igb_get_pauseparam(struct net_device *netdev, 364 struct ethtool_pauseparam *pause) 365{ 366 struct igb_adapter *adapter = netdev_priv(netdev); 367 struct e1000_hw *hw = &adapter->hw; 368 369 pause->autoneg = 370 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); 371 372 if (hw->fc.current_mode == e1000_fc_rx_pause) 373 pause->rx_pause = 1; 374 else if (hw->fc.current_mode == e1000_fc_tx_pause) 375 pause->tx_pause = 1; 376 else if (hw->fc.current_mode == e1000_fc_full) { 377 pause->rx_pause = 1; 378 pause->tx_pause = 1; 379 } 380} 381 382static int igb_set_pauseparam(struct net_device *netdev, 383 struct ethtool_pauseparam *pause) 384{ 385 struct igb_adapter *adapter = netdev_priv(netdev); 386 struct e1000_hw *hw = &adapter->hw; 387 int retval = 0; 388 389 /* 100basefx does not support setting link flow control */ 390 if (hw->dev_spec._82575.eth_flags.e100_base_fx) 391 return -EINVAL; 392 393 adapter->fc_autoneg = pause->autoneg; 394 395 while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) 396 msleep(1); 397 398 if (adapter->fc_autoneg == AUTONEG_ENABLE) { 399 hw->fc.requested_mode = e1000_fc_default; 400 if (netif_running(adapter->netdev)) { 401 igb_down(adapter); 402 igb_up(adapter); 403 } else { 404 igb_reset(adapter); 405 } 406 } else { 407 if (pause->rx_pause && pause->tx_pause) 408 hw->fc.requested_mode = e1000_fc_full; 409 else if (pause->rx_pause && !pause->tx_pause) 410 hw->fc.requested_mode = e1000_fc_rx_pause; 411 else if (!pause->rx_pause && pause->tx_pause) 412 hw->fc.requested_mode = e1000_fc_tx_pause; 413 else if (!pause->rx_pause && !pause->tx_pause) 414 hw->fc.requested_mode = e1000_fc_none; 415 416 hw->fc.current_mode = hw->fc.requested_mode; 417 418 retval = ((hw->phy.media_type == e1000_media_type_copper) ? 419 igb_force_mac_fc(hw) : igb_setup_link(hw)); 420 } 421 422 clear_bit(__IGB_RESETTING, &adapter->state); 423 return retval; 424} 425 426static u32 igb_get_msglevel(struct net_device *netdev) 427{ 428 struct igb_adapter *adapter = netdev_priv(netdev); 429 return adapter->msg_enable; 430} 431 432static void igb_set_msglevel(struct net_device *netdev, u32 data) 433{ 434 struct igb_adapter *adapter = netdev_priv(netdev); 435 adapter->msg_enable = data; 436} 437 438static int igb_get_regs_len(struct net_device *netdev) 439{ 440#define IGB_REGS_LEN 739 441 return IGB_REGS_LEN * sizeof(u32); 442} 443 444static void igb_get_regs(struct net_device *netdev, 445 struct ethtool_regs *regs, void *p) 446{ 447 struct igb_adapter *adapter = netdev_priv(netdev); 448 struct e1000_hw *hw = &adapter->hw; 449 u32 *regs_buff = p; 450 u8 i; 451 452 memset(p, 0, IGB_REGS_LEN * sizeof(u32)); 453 454 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id; 455 456 /* General Registers */ 457 regs_buff[0] = rd32(E1000_CTRL); 458 regs_buff[1] = rd32(E1000_STATUS); 459 regs_buff[2] = rd32(E1000_CTRL_EXT); 460 regs_buff[3] = rd32(E1000_MDIC); 461 regs_buff[4] = rd32(E1000_SCTL); 462 regs_buff[5] = rd32(E1000_CONNSW); 463 regs_buff[6] = rd32(E1000_VET); 464 regs_buff[7] = rd32(E1000_LEDCTL); 465 regs_buff[8] = rd32(E1000_PBA); 466 regs_buff[9] = rd32(E1000_PBS); 467 regs_buff[10] = rd32(E1000_FRTIMER); 468 regs_buff[11] = rd32(E1000_TCPTIMER); 469 470 /* NVM Register */ 471 regs_buff[12] = rd32(E1000_EECD); 472 473 /* Interrupt */ 474 /* Reading EICS for EICR because they read the 475 * same but EICS does not clear on read 476 */ 477 regs_buff[13] = rd32(E1000_EICS); 478 regs_buff[14] = rd32(E1000_EICS); 479 regs_buff[15] = rd32(E1000_EIMS); 480 regs_buff[16] = rd32(E1000_EIMC); 481 regs_buff[17] = rd32(E1000_EIAC); 482 regs_buff[18] = rd32(E1000_EIAM); 483 /* Reading ICS for ICR because they read the 484 * same but ICS does not clear on read 485 */ 486 regs_buff[19] = rd32(E1000_ICS); 487 regs_buff[20] = rd32(E1000_ICS); 488 regs_buff[21] = rd32(E1000_IMS); 489 regs_buff[22] = rd32(E1000_IMC); 490 regs_buff[23] = rd32(E1000_IAC); 491 regs_buff[24] = rd32(E1000_IAM); 492 regs_buff[25] = rd32(E1000_IMIRVP); 493 494 /* Flow Control */ 495 regs_buff[26] = rd32(E1000_FCAL); 496 regs_buff[27] = rd32(E1000_FCAH); 497 regs_buff[28] = rd32(E1000_FCTTV); 498 regs_buff[29] = rd32(E1000_FCRTL); 499 regs_buff[30] = rd32(E1000_FCRTH); 500 regs_buff[31] = rd32(E1000_FCRTV); 501 502 /* Receive */ 503 regs_buff[32] = rd32(E1000_RCTL); 504 regs_buff[33] = rd32(E1000_RXCSUM); 505 regs_buff[34] = rd32(E1000_RLPML); 506 regs_buff[35] = rd32(E1000_RFCTL); 507 regs_buff[36] = rd32(E1000_MRQC); 508 regs_buff[37] = rd32(E1000_VT_CTL); 509 510 /* Transmit */ 511 regs_buff[38] = rd32(E1000_TCTL); 512 regs_buff[39] = rd32(E1000_TCTL_EXT); 513 regs_buff[40] = rd32(E1000_TIPG); 514 regs_buff[41] = rd32(E1000_DTXCTL); 515 516 /* Wake Up */ 517 regs_buff[42] = rd32(E1000_WUC); 518 regs_buff[43] = rd32(E1000_WUFC); 519 regs_buff[44] = rd32(E1000_WUS); 520 regs_buff[45] = rd32(E1000_IPAV); 521 regs_buff[46] = rd32(E1000_WUPL); 522 523 /* MAC */ 524 regs_buff[47] = rd32(E1000_PCS_CFG0); 525 regs_buff[48] = rd32(E1000_PCS_LCTL); 526 regs_buff[49] = rd32(E1000_PCS_LSTAT); 527 regs_buff[50] = rd32(E1000_PCS_ANADV); 528 regs_buff[51] = rd32(E1000_PCS_LPAB); 529 regs_buff[52] = rd32(E1000_PCS_NPTX); 530 regs_buff[53] = rd32(E1000_PCS_LPABNP); 531 532 /* Statistics */ 533 regs_buff[54] = adapter->stats.crcerrs; 534 regs_buff[55] = adapter->stats.algnerrc; 535 regs_buff[56] = adapter->stats.symerrs; 536 regs_buff[57] = adapter->stats.rxerrc; 537 regs_buff[58] = adapter->stats.mpc; 538 regs_buff[59] = adapter->stats.scc; 539 regs_buff[60] = adapter->stats.ecol; 540 regs_buff[61] = adapter->stats.mcc; 541 regs_buff[62] = adapter->stats.latecol; 542 regs_buff[63] = adapter->stats.colc; 543 regs_buff[64] = adapter->stats.dc; 544 regs_buff[65] = adapter->stats.tncrs; 545 regs_buff[66] = adapter->stats.sec; 546 regs_buff[67] = adapter->stats.htdpmc; 547 regs_buff[68] = adapter->stats.rlec; 548 regs_buff[69] = adapter->stats.xonrxc; 549 regs_buff[70] = adapter->stats.xontxc; 550 regs_buff[71] = adapter->stats.xoffrxc; 551 regs_buff[72] = adapter->stats.xofftxc; 552 regs_buff[73] = adapter->stats.fcruc; 553 regs_buff[74] = adapter->stats.prc64; 554 regs_buff[75] = adapter->stats.prc127; 555 regs_buff[76] = adapter->stats.prc255; 556 regs_buff[77] = adapter->stats.prc511; 557 regs_buff[78] = adapter->stats.prc1023; 558 regs_buff[79] = adapter->stats.prc1522; 559 regs_buff[80] = adapter->stats.gprc; 560 regs_buff[81] = adapter->stats.bprc; 561 regs_buff[82] = adapter->stats.mprc; 562 regs_buff[83] = adapter->stats.gptc; 563 regs_buff[84] = adapter->stats.gorc; 564 regs_buff[86] = adapter->stats.gotc; 565 regs_buff[88] = adapter->stats.rnbc; 566 regs_buff[89] = adapter->stats.ruc; 567 regs_buff[90] = adapter->stats.rfc; 568 regs_buff[91] = adapter->stats.roc; 569 regs_buff[92] = adapter->stats.rjc; 570 regs_buff[93] = adapter->stats.mgprc; 571 regs_buff[94] = adapter->stats.mgpdc; 572 regs_buff[95] = adapter->stats.mgptc; 573 regs_buff[96] = adapter->stats.tor; 574 regs_buff[98] = adapter->stats.tot; 575 regs_buff[100] = adapter->stats.tpr; 576 regs_buff[101] = adapter->stats.tpt; 577 regs_buff[102] = adapter->stats.ptc64; 578 regs_buff[103] = adapter->stats.ptc127; 579 regs_buff[104] = adapter->stats.ptc255; 580 regs_buff[105] = adapter->stats.ptc511; 581 regs_buff[106] = adapter->stats.ptc1023; 582 regs_buff[107] = adapter->stats.ptc1522; 583 regs_buff[108] = adapter->stats.mptc; 584 regs_buff[109] = adapter->stats.bptc; 585 regs_buff[110] = adapter->stats.tsctc; 586 regs_buff[111] = adapter->stats.iac; 587 regs_buff[112] = adapter->stats.rpthc; 588 regs_buff[113] = adapter->stats.hgptc; 589 regs_buff[114] = adapter->stats.hgorc; 590 regs_buff[116] = adapter->stats.hgotc; 591 regs_buff[118] = adapter->stats.lenerrs; 592 regs_buff[119] = adapter->stats.scvpc; 593 regs_buff[120] = adapter->stats.hrmpc; 594 595 for (i = 0; i < 4; i++) 596 regs_buff[121 + i] = rd32(E1000_SRRCTL(i)); 597 for (i = 0; i < 4; i++) 598 regs_buff[125 + i] = rd32(E1000_PSRTYPE(i)); 599 for (i = 0; i < 4; i++) 600 regs_buff[129 + i] = rd32(E1000_RDBAL(i)); 601 for (i = 0; i < 4; i++) 602 regs_buff[133 + i] = rd32(E1000_RDBAH(i)); 603 for (i = 0; i < 4; i++) 604 regs_buff[137 + i] = rd32(E1000_RDLEN(i)); 605 for (i = 0; i < 4; i++) 606 regs_buff[141 + i] = rd32(E1000_RDH(i)); 607 for (i = 0; i < 4; i++) 608 regs_buff[145 + i] = rd32(E1000_RDT(i)); 609 for (i = 0; i < 4; i++) 610 regs_buff[149 + i] = rd32(E1000_RXDCTL(i)); 611 612 for (i = 0; i < 10; i++) 613 regs_buff[153 + i] = rd32(E1000_EITR(i)); 614 for (i = 0; i < 8; i++) 615 regs_buff[163 + i] = rd32(E1000_IMIR(i)); 616 for (i = 0; i < 8; i++) 617 regs_buff[171 + i] = rd32(E1000_IMIREXT(i)); 618 for (i = 0; i < 16; i++) 619 regs_buff[179 + i] = rd32(E1000_RAL(i)); 620 for (i = 0; i < 16; i++) 621 regs_buff[195 + i] = rd32(E1000_RAH(i)); 622 623 for (i = 0; i < 4; i++) 624 regs_buff[211 + i] = rd32(E1000_TDBAL(i)); 625 for (i = 0; i < 4; i++) 626 regs_buff[215 + i] = rd32(E1000_TDBAH(i)); 627 for (i = 0; i < 4; i++) 628 regs_buff[219 + i] = rd32(E1000_TDLEN(i)); 629 for (i = 0; i < 4; i++) 630 regs_buff[223 + i] = rd32(E1000_TDH(i)); 631 for (i = 0; i < 4; i++) 632 regs_buff[227 + i] = rd32(E1000_TDT(i)); 633 for (i = 0; i < 4; i++) 634 regs_buff[231 + i] = rd32(E1000_TXDCTL(i)); 635 for (i = 0; i < 4; i++) 636 regs_buff[235 + i] = rd32(E1000_TDWBAL(i)); 637 for (i = 0; i < 4; i++) 638 regs_buff[239 + i] = rd32(E1000_TDWBAH(i)); 639 for (i = 0; i < 4; i++) 640 regs_buff[243 + i] = rd32(E1000_DCA_TXCTRL(i)); 641 642 for (i = 0; i < 4; i++) 643 regs_buff[247 + i] = rd32(E1000_IP4AT_REG(i)); 644 for (i = 0; i < 4; i++) 645 regs_buff[251 + i] = rd32(E1000_IP6AT_REG(i)); 646 for (i = 0; i < 32; i++) 647 regs_buff[255 + i] = rd32(E1000_WUPM_REG(i)); 648 for (i = 0; i < 128; i++) 649 regs_buff[287 + i] = rd32(E1000_FFMT_REG(i)); 650 for (i = 0; i < 128; i++) 651 regs_buff[415 + i] = rd32(E1000_FFVT_REG(i)); 652 for (i = 0; i < 4; i++) 653 regs_buff[543 + i] = rd32(E1000_FFLT_REG(i)); 654 655 regs_buff[547] = rd32(E1000_TDFH); 656 regs_buff[548] = rd32(E1000_TDFT); 657 regs_buff[549] = rd32(E1000_TDFHS); 658 regs_buff[550] = rd32(E1000_TDFPC); 659 660 if (hw->mac.type > e1000_82580) { 661 regs_buff[551] = adapter->stats.o2bgptc; 662 regs_buff[552] = adapter->stats.b2ospc; 663 regs_buff[553] = adapter->stats.o2bspc; 664 regs_buff[554] = adapter->stats.b2ogprc; 665 } 666 667 if (hw->mac.type != e1000_82576) 668 return; 669 for (i = 0; i < 12; i++) 670 regs_buff[555 + i] = rd32(E1000_SRRCTL(i + 4)); 671 for (i = 0; i < 4; i++) 672 regs_buff[567 + i] = rd32(E1000_PSRTYPE(i + 4)); 673 for (i = 0; i < 12; i++) 674 regs_buff[571 + i] = rd32(E1000_RDBAL(i + 4)); 675 for (i = 0; i < 12; i++) 676 regs_buff[583 + i] = rd32(E1000_RDBAH(i + 4)); 677 for (i = 0; i < 12; i++) 678 regs_buff[595 + i] = rd32(E1000_RDLEN(i + 4)); 679 for (i = 0; i < 12; i++) 680 regs_buff[607 + i] = rd32(E1000_RDH(i + 4)); 681 for (i = 0; i < 12; i++) 682 regs_buff[619 + i] = rd32(E1000_RDT(i + 4)); 683 for (i = 0; i < 12; i++) 684 regs_buff[631 + i] = rd32(E1000_RXDCTL(i + 4)); 685 686 for (i = 0; i < 12; i++) 687 regs_buff[643 + i] = rd32(E1000_TDBAL(i + 4)); 688 for (i = 0; i < 12; i++) 689 regs_buff[655 + i] = rd32(E1000_TDBAH(i + 4)); 690 for (i = 0; i < 12; i++) 691 regs_buff[667 + i] = rd32(E1000_TDLEN(i + 4)); 692 for (i = 0; i < 12; i++) 693 regs_buff[679 + i] = rd32(E1000_TDH(i + 4)); 694 for (i = 0; i < 12; i++) 695 regs_buff[691 + i] = rd32(E1000_TDT(i + 4)); 696 for (i = 0; i < 12; i++) 697 regs_buff[703 + i] = rd32(E1000_TXDCTL(i + 4)); 698 for (i = 0; i < 12; i++) 699 regs_buff[715 + i] = rd32(E1000_TDWBAL(i + 4)); 700 for (i = 0; i < 12; i++) 701 regs_buff[727 + i] = rd32(E1000_TDWBAH(i + 4)); 702} 703 704static int igb_get_eeprom_len(struct net_device *netdev) 705{ 706 struct igb_adapter *adapter = netdev_priv(netdev); 707 return adapter->hw.nvm.word_size * 2; 708} 709 710static int igb_get_eeprom(struct net_device *netdev, 711 struct ethtool_eeprom *eeprom, u8 *bytes) 712{ 713 struct igb_adapter *adapter = netdev_priv(netdev); 714 struct e1000_hw *hw = &adapter->hw; 715 u16 *eeprom_buff; 716 int first_word, last_word; 717 int ret_val = 0; 718 u16 i; 719 720 if (eeprom->len == 0) 721 return -EINVAL; 722 723 eeprom->magic = hw->vendor_id | (hw->device_id << 16); 724 725 first_word = eeprom->offset >> 1; 726 last_word = (eeprom->offset + eeprom->len - 1) >> 1; 727 728 eeprom_buff = kmalloc(sizeof(u16) * 729 (last_word - first_word + 1), GFP_KERNEL); 730 if (!eeprom_buff) 731 return -ENOMEM; 732 733 if (hw->nvm.type == e1000_nvm_eeprom_spi) 734 ret_val = hw->nvm.ops.read(hw, first_word, 735 last_word - first_word + 1, 736 eeprom_buff); 737 else { 738 for (i = 0; i < last_word - first_word + 1; i++) { 739 ret_val = hw->nvm.ops.read(hw, first_word + i, 1, 740 &eeprom_buff[i]); 741 if (ret_val) 742 break; 743 } 744 } 745 746 /* Device's eeprom is always little-endian, word addressable */ 747 for (i = 0; i < last_word - first_word + 1; i++) 748 le16_to_cpus(&eeprom_buff[i]); 749 750 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), 751 eeprom->len); 752 kfree(eeprom_buff); 753 754 return ret_val; 755} 756 757static int igb_set_eeprom(struct net_device *netdev, 758 struct ethtool_eeprom *eeprom, u8 *bytes) 759{ 760 struct igb_adapter *adapter = netdev_priv(netdev); 761 struct e1000_hw *hw = &adapter->hw; 762 u16 *eeprom_buff; 763 void *ptr; 764 int max_len, first_word, last_word, ret_val = 0; 765 u16 i; 766 767 if (eeprom->len == 0) 768 return -EOPNOTSUPP; 769 770 if (hw->mac.type == e1000_i211) 771 return -EOPNOTSUPP; 772 773 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16))) 774 return -EFAULT; 775 776 max_len = hw->nvm.word_size * 2; 777 778 first_word = eeprom->offset >> 1; 779 last_word = (eeprom->offset + eeprom->len - 1) >> 1; 780 eeprom_buff = kmalloc(max_len, GFP_KERNEL); 781 if (!eeprom_buff) 782 return -ENOMEM; 783 784 ptr = (void *)eeprom_buff; 785 786 if (eeprom->offset & 1) { 787 /* need read/modify/write of first changed EEPROM word 788 * only the second byte of the word is being modified 789 */ 790 ret_val = hw->nvm.ops.read(hw, first_word, 1, 791 &eeprom_buff[0]); 792 ptr++; 793 } 794 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) { 795 /* need read/modify/write of last changed EEPROM word 796 * only the first byte of the word is being modified 797 */ 798 ret_val = hw->nvm.ops.read(hw, last_word, 1, 799 &eeprom_buff[last_word - first_word]); 800 } 801 802 /* Device's eeprom is always little-endian, word addressable */ 803 for (i = 0; i < last_word - first_word + 1; i++) 804 le16_to_cpus(&eeprom_buff[i]); 805 806 memcpy(ptr, bytes, eeprom->len); 807 808 for (i = 0; i < last_word - first_word + 1; i++) 809 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]); 810 811 ret_val = hw->nvm.ops.write(hw, first_word, 812 last_word - first_word + 1, eeprom_buff); 813 814 /* Update the checksum over the first part of the EEPROM if needed 815 * and flush shadow RAM for 82573 controllers 816 */ 817 if ((ret_val == 0) && ((first_word <= NVM_CHECKSUM_REG))) 818 hw->nvm.ops.update(hw); 819 820 igb_set_fw_version(adapter); 821 kfree(eeprom_buff); 822 return ret_val; 823} 824 825static void igb_get_drvinfo(struct net_device *netdev, 826 struct ethtool_drvinfo *drvinfo) 827{ 828 struct igb_adapter *adapter = netdev_priv(netdev); 829 830 strlcpy(drvinfo->driver, igb_driver_name, sizeof(drvinfo->driver)); 831 strlcpy(drvinfo->version, igb_driver_version, sizeof(drvinfo->version)); 832 833 /* EEPROM image version # is reported as firmware version # for 834 * 82575 controllers 835 */ 836 strlcpy(drvinfo->fw_version, adapter->fw_version, 837 sizeof(drvinfo->fw_version)); 838 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 839 sizeof(drvinfo->bus_info)); 840 drvinfo->n_stats = IGB_STATS_LEN; 841 drvinfo->testinfo_len = IGB_TEST_LEN; 842 drvinfo->regdump_len = igb_get_regs_len(netdev); 843 drvinfo->eedump_len = igb_get_eeprom_len(netdev); 844} 845 846static void igb_get_ringparam(struct net_device *netdev, 847 struct ethtool_ringparam *ring) 848{ 849 struct igb_adapter *adapter = netdev_priv(netdev); 850 851 ring->rx_max_pending = IGB_MAX_RXD; 852 ring->tx_max_pending = IGB_MAX_TXD; 853 ring->rx_pending = adapter->rx_ring_count; 854 ring->tx_pending = adapter->tx_ring_count; 855} 856 857static int igb_set_ringparam(struct net_device *netdev, 858 struct ethtool_ringparam *ring) 859{ 860 struct igb_adapter *adapter = netdev_priv(netdev); 861 struct igb_ring *temp_ring; 862 int i, err = 0; 863 u16 new_rx_count, new_tx_count; 864 865 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 866 return -EINVAL; 867 868 new_rx_count = min_t(u32, ring->rx_pending, IGB_MAX_RXD); 869 new_rx_count = max_t(u16, new_rx_count, IGB_MIN_RXD); 870 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE); 871 872 new_tx_count = min_t(u32, ring->tx_pending, IGB_MAX_TXD); 873 new_tx_count = max_t(u16, new_tx_count, IGB_MIN_TXD); 874 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE); 875 876 if ((new_tx_count == adapter->tx_ring_count) && 877 (new_rx_count == adapter->rx_ring_count)) { 878 /* nothing to do */ 879 return 0; 880 } 881 882 while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) 883 msleep(1); 884 885 if (!netif_running(adapter->netdev)) { 886 for (i = 0; i < adapter->num_tx_queues; i++) 887 adapter->tx_ring[i]->count = new_tx_count; 888 for (i = 0; i < adapter->num_rx_queues; i++) 889 adapter->rx_ring[i]->count = new_rx_count; 890 adapter->tx_ring_count = new_tx_count; 891 adapter->rx_ring_count = new_rx_count; 892 goto clear_reset; 893 } 894 895 if (adapter->num_tx_queues > adapter->num_rx_queues) 896 temp_ring = vmalloc(adapter->num_tx_queues * 897 sizeof(struct igb_ring)); 898 else 899 temp_ring = vmalloc(adapter->num_rx_queues * 900 sizeof(struct igb_ring)); 901 902 if (!temp_ring) { 903 err = -ENOMEM; 904 goto clear_reset; 905 } 906 907 igb_down(adapter); 908 909 /* We can't just free everything and then setup again, 910 * because the ISRs in MSI-X mode get passed pointers 911 * to the Tx and Rx ring structs. 912 */ 913 if (new_tx_count != adapter->tx_ring_count) { 914 for (i = 0; i < adapter->num_tx_queues; i++) { 915 memcpy(&temp_ring[i], adapter->tx_ring[i], 916 sizeof(struct igb_ring)); 917 918 temp_ring[i].count = new_tx_count; 919 err = igb_setup_tx_resources(&temp_ring[i]); 920 if (err) { 921 while (i) { 922 i--; 923 igb_free_tx_resources(&temp_ring[i]); 924 } 925 goto err_setup; 926 } 927 } 928 929 for (i = 0; i < adapter->num_tx_queues; i++) { 930 igb_free_tx_resources(adapter->tx_ring[i]); 931 932 memcpy(adapter->tx_ring[i], &temp_ring[i], 933 sizeof(struct igb_ring)); 934 } 935 936 adapter->tx_ring_count = new_tx_count; 937 } 938 939 if (new_rx_count != adapter->rx_ring_count) { 940 for (i = 0; i < adapter->num_rx_queues; i++) { 941 memcpy(&temp_ring[i], adapter->rx_ring[i], 942 sizeof(struct igb_ring)); 943 944 temp_ring[i].count = new_rx_count; 945 err = igb_setup_rx_resources(&temp_ring[i]); 946 if (err) { 947 while (i) { 948 i--; 949 igb_free_rx_resources(&temp_ring[i]); 950 } 951 goto err_setup; 952 } 953 954 } 955 956 for (i = 0; i < adapter->num_rx_queues; i++) { 957 igb_free_rx_resources(adapter->rx_ring[i]); 958 959 memcpy(adapter->rx_ring[i], &temp_ring[i], 960 sizeof(struct igb_ring)); 961 } 962 963 adapter->rx_ring_count = new_rx_count; 964 } 965err_setup: 966 igb_up(adapter); 967 vfree(temp_ring); 968clear_reset: 969 clear_bit(__IGB_RESETTING, &adapter->state); 970 return err; 971} 972 973/* ethtool register test data */ 974struct igb_reg_test { 975 u16 reg; 976 u16 reg_offset; 977 u16 array_len; 978 u16 test_type; 979 u32 mask; 980 u32 write; 981}; 982 983/* In the hardware, registers are laid out either singly, in arrays 984 * spaced 0x100 bytes apart, or in contiguous tables. We assume 985 * most tests take place on arrays or single registers (handled 986 * as a single-element array) and special-case the tables. 987 * Table tests are always pattern tests. 988 * 989 * We also make provision for some required setup steps by specifying 990 * registers to be written without any read-back testing. 991 */ 992 993#define PATTERN_TEST 1 994#define SET_READ_TEST 2 995#define WRITE_NO_TEST 3 996#define TABLE32_TEST 4 997#define TABLE64_TEST_LO 5 998#define TABLE64_TEST_HI 6 999 1000/* i210 reg test */ 1001static struct igb_reg_test reg_test_i210[] = { 1002 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1003 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1004 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1005 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1006 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1007 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, 1008 /* RDH is read-only for i210, only test RDT. */ 1009 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1010 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 }, 1011 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1012 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF }, 1013 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1014 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1015 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, 1016 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1017 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1018 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB }, 1019 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF }, 1020 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1021 { E1000_RA, 0, 16, TABLE64_TEST_LO, 1022 0xFFFFFFFF, 0xFFFFFFFF }, 1023 { E1000_RA, 0, 16, TABLE64_TEST_HI, 1024 0x900FFFFF, 0xFFFFFFFF }, 1025 { E1000_MTA, 0, 128, TABLE32_TEST, 1026 0xFFFFFFFF, 0xFFFFFFFF }, 1027 { 0, 0, 0, 0, 0 } 1028}; 1029 1030/* i350 reg test */ 1031static struct igb_reg_test reg_test_i350[] = { 1032 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1033 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1034 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1035 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFF0000, 0xFFFF0000 }, 1036 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1037 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1038 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, 1039 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1040 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1041 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, 1042 /* RDH is read-only for i350, only test RDT. */ 1043 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1044 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1045 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 }, 1046 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1047 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF }, 1048 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1049 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1050 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, 1051 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1052 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1053 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, 1054 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1055 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1056 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1057 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB }, 1058 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF }, 1059 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1060 { E1000_RA, 0, 16, TABLE64_TEST_LO, 1061 0xFFFFFFFF, 0xFFFFFFFF }, 1062 { E1000_RA, 0, 16, TABLE64_TEST_HI, 1063 0xC3FFFFFF, 0xFFFFFFFF }, 1064 { E1000_RA2, 0, 16, TABLE64_TEST_LO, 1065 0xFFFFFFFF, 0xFFFFFFFF }, 1066 { E1000_RA2, 0, 16, TABLE64_TEST_HI, 1067 0xC3FFFFFF, 0xFFFFFFFF }, 1068 { E1000_MTA, 0, 128, TABLE32_TEST, 1069 0xFFFFFFFF, 0xFFFFFFFF }, 1070 { 0, 0, 0, 0 } 1071}; 1072 1073/* 82580 reg test */ 1074static struct igb_reg_test reg_test_82580[] = { 1075 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1076 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1077 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1078 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1079 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1080 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1081 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF }, 1082 { E1000_RDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1083 { E1000_RDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1084 { E1000_RDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF }, 1085 /* RDH is read-only for 82580, only test RDT. */ 1086 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1087 { E1000_RDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1088 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 }, 1089 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1090 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF }, 1091 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1092 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1093 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF }, 1094 { E1000_TDBAL(4), 0x40, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1095 { E1000_TDBAH(4), 0x40, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1096 { E1000_TDLEN(4), 0x40, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF }, 1097 { E1000_TDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1098 { E1000_TDT(4), 0x40, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1099 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1100 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB }, 1101 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF }, 1102 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1103 { E1000_RA, 0, 16, TABLE64_TEST_LO, 1104 0xFFFFFFFF, 0xFFFFFFFF }, 1105 { E1000_RA, 0, 16, TABLE64_TEST_HI, 1106 0x83FFFFFF, 0xFFFFFFFF }, 1107 { E1000_RA2, 0, 8, TABLE64_TEST_LO, 1108 0xFFFFFFFF, 0xFFFFFFFF }, 1109 { E1000_RA2, 0, 8, TABLE64_TEST_HI, 1110 0x83FFFFFF, 0xFFFFFFFF }, 1111 { E1000_MTA, 0, 128, TABLE32_TEST, 1112 0xFFFFFFFF, 0xFFFFFFFF }, 1113 { 0, 0, 0, 0 } 1114}; 1115 1116/* 82576 reg test */ 1117static struct igb_reg_test reg_test_82576[] = { 1118 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1119 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1120 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1121 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1122 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1123 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1124 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF }, 1125 { E1000_RDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1126 { E1000_RDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1127 { E1000_RDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF }, 1128 /* Enable all RX queues before testing. */ 1129 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE }, 1130 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE }, 1131 /* RDH is read-only for 82576, only test RDT. */ 1132 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1133 { E1000_RDT(4), 0x40, 12, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1134 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 }, 1135 { E1000_RXDCTL(4), 0x40, 12, WRITE_NO_TEST, 0, 0 }, 1136 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 }, 1137 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1138 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF }, 1139 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1140 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1141 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF }, 1142 { E1000_TDBAL(4), 0x40, 12, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1143 { E1000_TDBAH(4), 0x40, 12, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1144 { E1000_TDLEN(4), 0x40, 12, PATTERN_TEST, 0x000FFFF0, 0x000FFFFF }, 1145 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1146 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0x003FFFFB }, 1147 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB0FE, 0xFFFFFFFF }, 1148 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1149 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF }, 1150 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF }, 1151 { E1000_RA2, 0, 8, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF }, 1152 { E1000_RA2, 0, 8, TABLE64_TEST_HI, 0x83FFFFFF, 0xFFFFFFFF }, 1153 { E1000_MTA, 0, 128,TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1154 { 0, 0, 0, 0 } 1155}; 1156 1157/* 82575 register test */ 1158static struct igb_reg_test reg_test_82575[] = { 1159 { E1000_FCAL, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1160 { E1000_FCAH, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1161 { E1000_FCT, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0xFFFFFFFF }, 1162 { E1000_VET, 0x100, 1, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1163 { E1000_RDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1164 { E1000_RDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1165 { E1000_RDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, 1166 /* Enable all four RX queues before testing. */ 1167 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, E1000_RXDCTL_QUEUE_ENABLE }, 1168 /* RDH is read-only for 82575, only test RDT. */ 1169 { E1000_RDT(0), 0x100, 4, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1170 { E1000_RXDCTL(0), 0x100, 4, WRITE_NO_TEST, 0, 0 }, 1171 { E1000_FCRTH, 0x100, 1, PATTERN_TEST, 0x0000FFF0, 0x0000FFF0 }, 1172 { E1000_FCTTV, 0x100, 1, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF }, 1173 { E1000_TIPG, 0x100, 1, PATTERN_TEST, 0x3FFFFFFF, 0x3FFFFFFF }, 1174 { E1000_TDBAL(0), 0x100, 4, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF }, 1175 { E1000_TDBAH(0), 0x100, 4, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1176 { E1000_TDLEN(0), 0x100, 4, PATTERN_TEST, 0x000FFF80, 0x000FFFFF }, 1177 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1178 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0x003FFFFB }, 1179 { E1000_RCTL, 0x100, 1, SET_READ_TEST, 0x04CFB3FE, 0xFFFFFFFF }, 1180 { E1000_TCTL, 0x100, 1, SET_READ_TEST, 0xFFFFFFFF, 0x00000000 }, 1181 { E1000_TXCW, 0x100, 1, PATTERN_TEST, 0xC000FFFF, 0x0000FFFF }, 1182 { E1000_RA, 0, 16, TABLE64_TEST_LO, 0xFFFFFFFF, 0xFFFFFFFF }, 1183 { E1000_RA, 0, 16, TABLE64_TEST_HI, 0x800FFFFF, 0xFFFFFFFF }, 1184 { E1000_MTA, 0, 128, TABLE32_TEST, 0xFFFFFFFF, 0xFFFFFFFF }, 1185 { 0, 0, 0, 0 } 1186}; 1187 1188static bool reg_pattern_test(struct igb_adapter *adapter, u64 *data, 1189 int reg, u32 mask, u32 write) 1190{ 1191 struct e1000_hw *hw = &adapter->hw; 1192 u32 pat, val; 1193 static const u32 _test[] = 1194 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; 1195 for (pat = 0; pat < ARRAY_SIZE(_test); pat++) { 1196 wr32(reg, (_test[pat] & write)); 1197 val = rd32(reg) & mask; 1198 if (val != (_test[pat] & write & mask)) { 1199 dev_err(&adapter->pdev->dev, 1200 "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n", 1201 reg, val, (_test[pat] & write & mask)); 1202 *data = reg; 1203 return 1; 1204 } 1205 } 1206 1207 return 0; 1208} 1209 1210static bool reg_set_and_check(struct igb_adapter *adapter, u64 *data, 1211 int reg, u32 mask, u32 write) 1212{ 1213 struct e1000_hw *hw = &adapter->hw; 1214 u32 val; 1215 wr32(reg, write & mask); 1216 val = rd32(reg); 1217 if ((write & mask) != (val & mask)) { 1218 dev_err(&adapter->pdev->dev, 1219 "set/check reg %04X test failed: got 0x%08X expected 0x%08X\n", reg, 1220 (val & mask), (write & mask)); 1221 *data = reg; 1222 return 1; 1223 } 1224 1225 return 0; 1226} 1227 1228#define REG_PATTERN_TEST(reg, mask, write) \ 1229 do { \ 1230 if (reg_pattern_test(adapter, data, reg, mask, write)) \ 1231 return 1; \ 1232 } while (0) 1233 1234#define REG_SET_AND_CHECK(reg, mask, write) \ 1235 do { \ 1236 if (reg_set_and_check(adapter, data, reg, mask, write)) \ 1237 return 1; \ 1238 } while (0) 1239 1240static int igb_reg_test(struct igb_adapter *adapter, u64 *data) 1241{ 1242 struct e1000_hw *hw = &adapter->hw; 1243 struct igb_reg_test *test; 1244 u32 value, before, after; 1245 u32 i, toggle; 1246 1247 switch (adapter->hw.mac.type) { 1248 case e1000_i350: 1249 case e1000_i354: 1250 test = reg_test_i350; 1251 toggle = 0x7FEFF3FF; 1252 break; 1253 case e1000_i210: 1254 case e1000_i211: 1255 test = reg_test_i210; 1256 toggle = 0x7FEFF3FF; 1257 break; 1258 case e1000_82580: 1259 test = reg_test_82580; 1260 toggle = 0x7FEFF3FF; 1261 break; 1262 case e1000_82576: 1263 test = reg_test_82576; 1264 toggle = 0x7FFFF3FF; 1265 break; 1266 default: 1267 test = reg_test_82575; 1268 toggle = 0x7FFFF3FF; 1269 break; 1270 } 1271 1272 /* Because the status register is such a special case, 1273 * we handle it separately from the rest of the register 1274 * tests. Some bits are read-only, some toggle, and some 1275 * are writable on newer MACs. 1276 */ 1277 before = rd32(E1000_STATUS); 1278 value = (rd32(E1000_STATUS) & toggle); 1279 wr32(E1000_STATUS, toggle); 1280 after = rd32(E1000_STATUS) & toggle; 1281 if (value != after) { 1282 dev_err(&adapter->pdev->dev, 1283 "failed STATUS register test got: 0x%08X expected: 0x%08X\n", 1284 after, value); 1285 *data = 1; 1286 return 1; 1287 } 1288 /* restore previous status */ 1289 wr32(E1000_STATUS, before); 1290 1291 /* Perform the remainder of the register test, looping through 1292 * the test table until we either fail or reach the null entry. 1293 */ 1294 while (test->reg) { 1295 for (i = 0; i < test->array_len; i++) { 1296 switch (test->test_type) { 1297 case PATTERN_TEST: 1298 REG_PATTERN_TEST(test->reg + 1299 (i * test->reg_offset), 1300 test->mask, 1301 test->write); 1302 break; 1303 case SET_READ_TEST: 1304 REG_SET_AND_CHECK(test->reg + 1305 (i * test->reg_offset), 1306 test->mask, 1307 test->write); 1308 break; 1309 case WRITE_NO_TEST: 1310 writel(test->write, 1311 (adapter->hw.hw_addr + test->reg) 1312 + (i * test->reg_offset)); 1313 break; 1314 case TABLE32_TEST: 1315 REG_PATTERN_TEST(test->reg + (i * 4), 1316 test->mask, 1317 test->write); 1318 break; 1319 case TABLE64_TEST_LO: 1320 REG_PATTERN_TEST(test->reg + (i * 8), 1321 test->mask, 1322 test->write); 1323 break; 1324 case TABLE64_TEST_HI: 1325 REG_PATTERN_TEST((test->reg + 4) + (i * 8), 1326 test->mask, 1327 test->write); 1328 break; 1329 } 1330 } 1331 test++; 1332 } 1333 1334 *data = 0; 1335 return 0; 1336} 1337 1338static int igb_eeprom_test(struct igb_adapter *adapter, u64 *data) 1339{ 1340 *data = 0; 1341 1342 /* Validate eeprom on all parts but i211 */ 1343 if (adapter->hw.mac.type != e1000_i211) { 1344 if (adapter->hw.nvm.ops.validate(&adapter->hw) < 0) 1345 *data = 2; 1346 } 1347 1348 return *data; 1349} 1350 1351static irqreturn_t igb_test_intr(int irq, void *data) 1352{ 1353 struct igb_adapter *adapter = (struct igb_adapter *) data; 1354 struct e1000_hw *hw = &adapter->hw; 1355 1356 adapter->test_icr |= rd32(E1000_ICR); 1357 1358 return IRQ_HANDLED; 1359} 1360 1361static int igb_intr_test(struct igb_adapter *adapter, u64 *data) 1362{ 1363 struct e1000_hw *hw = &adapter->hw; 1364 struct net_device *netdev = adapter->netdev; 1365 u32 mask, ics_mask, i = 0, shared_int = true; 1366 u32 irq = adapter->pdev->irq; 1367 1368 *data = 0; 1369 1370 /* Hook up test interrupt handler just for this test */ 1371 if (adapter->msix_entries) { 1372 if (request_irq(adapter->msix_entries[0].vector, 1373 igb_test_intr, 0, netdev->name, adapter)) { 1374 *data = 1; 1375 return -1; 1376 } 1377 } else if (adapter->flags & IGB_FLAG_HAS_MSI) { 1378 shared_int = false; 1379 if (request_irq(irq, 1380 igb_test_intr, 0, netdev->name, adapter)) { 1381 *data = 1; 1382 return -1; 1383 } 1384 } else if (!request_irq(irq, igb_test_intr, IRQF_PROBE_SHARED, 1385 netdev->name, adapter)) { 1386 shared_int = false; 1387 } else if (request_irq(irq, igb_test_intr, IRQF_SHARED, 1388 netdev->name, adapter)) { 1389 *data = 1; 1390 return -1; 1391 } 1392 dev_info(&adapter->pdev->dev, "testing %s interrupt\n", 1393 (shared_int ? "shared" : "unshared")); 1394 1395 /* Disable all the interrupts */ 1396 wr32(E1000_IMC, ~0); 1397 wrfl(); 1398 msleep(10); 1399 1400 /* Define all writable bits for ICS */ 1401 switch (hw->mac.type) { 1402 case e1000_82575: 1403 ics_mask = 0x37F47EDD; 1404 break; 1405 case e1000_82576: 1406 ics_mask = 0x77D4FBFD; 1407 break; 1408 case e1000_82580: 1409 ics_mask = 0x77DCFED5; 1410 break; 1411 case e1000_i350: 1412 case e1000_i354: 1413 case e1000_i210: 1414 case e1000_i211: 1415 ics_mask = 0x77DCFED5; 1416 break; 1417 default: 1418 ics_mask = 0x7FFFFFFF; 1419 break; 1420 } 1421 1422 /* Test each interrupt */ 1423 for (; i < 31; i++) { 1424 /* Interrupt to test */ 1425 mask = 1 << i; 1426 1427 if (!(mask & ics_mask)) 1428 continue; 1429 1430 if (!shared_int) { 1431 /* Disable the interrupt to be reported in 1432 * the cause register and then force the same 1433 * interrupt and see if one gets posted. If 1434 * an interrupt was posted to the bus, the 1435 * test failed. 1436 */ 1437 adapter->test_icr = 0; 1438 1439 /* Flush any pending interrupts */ 1440 wr32(E1000_ICR, ~0); 1441 1442 wr32(E1000_IMC, mask); 1443 wr32(E1000_ICS, mask); 1444 wrfl(); 1445 msleep(10); 1446 1447 if (adapter->test_icr & mask) { 1448 *data = 3; 1449 break; 1450 } 1451 } 1452 1453 /* Enable the interrupt to be reported in 1454 * the cause register and then force the same 1455 * interrupt and see if one gets posted. If 1456 * an interrupt was not posted to the bus, the 1457 * test failed. 1458 */ 1459 adapter->test_icr = 0; 1460 1461 /* Flush any pending interrupts */ 1462 wr32(E1000_ICR, ~0); 1463 1464 wr32(E1000_IMS, mask); 1465 wr32(E1000_ICS, mask); 1466 wrfl(); 1467 msleep(10); 1468 1469 if (!(adapter->test_icr & mask)) { 1470 *data = 4; 1471 break; 1472 } 1473 1474 if (!shared_int) { 1475 /* Disable the other interrupts to be reported in 1476 * the cause register and then force the other 1477 * interrupts and see if any get posted. If 1478 * an interrupt was posted to the bus, the 1479 * test failed. 1480 */ 1481 adapter->test_icr = 0; 1482 1483 /* Flush any pending interrupts */ 1484 wr32(E1000_ICR, ~0); 1485 1486 wr32(E1000_IMC, ~mask); 1487 wr32(E1000_ICS, ~mask); 1488 wrfl(); 1489 msleep(10); 1490 1491 if (adapter->test_icr & mask) { 1492 *data = 5; 1493 break; 1494 } 1495 } 1496 } 1497 1498 /* Disable all the interrupts */ 1499 wr32(E1000_IMC, ~0); 1500 wrfl(); 1501 msleep(10); 1502 1503 /* Unhook test interrupt handler */ 1504 if (adapter->msix_entries) 1505 free_irq(adapter->msix_entries[0].vector, adapter); 1506 else 1507 free_irq(irq, adapter); 1508 1509 return *data; 1510} 1511 1512static void igb_free_desc_rings(struct igb_adapter *adapter) 1513{ 1514 igb_free_tx_resources(&adapter->test_tx_ring); 1515 igb_free_rx_resources(&adapter->test_rx_ring); 1516} 1517 1518static int igb_setup_desc_rings(struct igb_adapter *adapter) 1519{ 1520 struct igb_ring *tx_ring = &adapter->test_tx_ring; 1521 struct igb_ring *rx_ring = &adapter->test_rx_ring; 1522 struct e1000_hw *hw = &adapter->hw; 1523 int ret_val; 1524 1525 /* Setup Tx descriptor ring and Tx buffers */ 1526 tx_ring->count = IGB_DEFAULT_TXD; 1527 tx_ring->dev = &adapter->pdev->dev; 1528 tx_ring->netdev = adapter->netdev; 1529 tx_ring->reg_idx = adapter->vfs_allocated_count; 1530 1531 if (igb_setup_tx_resources(tx_ring)) { 1532 ret_val = 1; 1533 goto err_nomem; 1534 } 1535 1536 igb_setup_tctl(adapter); 1537 igb_configure_tx_ring(adapter, tx_ring); 1538 1539 /* Setup Rx descriptor ring and Rx buffers */ 1540 rx_ring->count = IGB_DEFAULT_RXD; 1541 rx_ring->dev = &adapter->pdev->dev; 1542 rx_ring->netdev = adapter->netdev; 1543 rx_ring->reg_idx = adapter->vfs_allocated_count; 1544 1545 if (igb_setup_rx_resources(rx_ring)) { 1546 ret_val = 3; 1547 goto err_nomem; 1548 } 1549 1550 /* set the default queue to queue 0 of PF */ 1551 wr32(E1000_MRQC, adapter->vfs_allocated_count << 3); 1552 1553 /* enable receive ring */ 1554 igb_setup_rctl(adapter); 1555 igb_configure_rx_ring(adapter, rx_ring); 1556 1557 igb_alloc_rx_buffers(rx_ring, igb_desc_unused(rx_ring)); 1558 1559 return 0; 1560 1561err_nomem: 1562 igb_free_desc_rings(adapter); 1563 return ret_val; 1564} 1565 1566static void igb_phy_disable_receiver(struct igb_adapter *adapter) 1567{ 1568 struct e1000_hw *hw = &adapter->hw; 1569 1570 /* Write out to PHY registers 29 and 30 to disable the Receiver. */ 1571 igb_write_phy_reg(hw, 29, 0x001F); 1572 igb_write_phy_reg(hw, 30, 0x8FFC); 1573 igb_write_phy_reg(hw, 29, 0x001A); 1574 igb_write_phy_reg(hw, 30, 0x8FF0); 1575} 1576 1577static int igb_integrated_phy_loopback(struct igb_adapter *adapter) 1578{ 1579 struct e1000_hw *hw = &adapter->hw; 1580 u32 ctrl_reg = 0; 1581 1582 hw->mac.autoneg = false; 1583 1584 if (hw->phy.type == e1000_phy_m88) { 1585 if (hw->phy.id != I210_I_PHY_ID) { 1586 /* Auto-MDI/MDIX Off */ 1587 igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); 1588 /* reset to update Auto-MDI/MDIX */ 1589 igb_write_phy_reg(hw, PHY_CONTROL, 0x9140); 1590 /* autoneg off */ 1591 igb_write_phy_reg(hw, PHY_CONTROL, 0x8140); 1592 } else { 1593 /* force 1000, set loopback */ 1594 igb_write_phy_reg(hw, I347AT4_PAGE_SELECT, 0); 1595 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140); 1596 } 1597 } 1598 1599 /* add small delay to avoid loopback test failure */ 1600 msleep(50); 1601 1602 /* force 1000, set loopback */ 1603 igb_write_phy_reg(hw, PHY_CONTROL, 0x4140); 1604 1605 /* Now set up the MAC to the same speed/duplex as the PHY. */ 1606 ctrl_reg = rd32(E1000_CTRL); 1607 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ 1608 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ 1609 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ 1610 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */ 1611 E1000_CTRL_FD | /* Force Duplex to FULL */ 1612 E1000_CTRL_SLU); /* Set link up enable bit */ 1613 1614 if (hw->phy.type == e1000_phy_m88) 1615 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */ 1616 1617 wr32(E1000_CTRL, ctrl_reg); 1618 1619 /* Disable the receiver on the PHY so when a cable is plugged in, the 1620 * PHY does not begin to autoneg when a cable is reconnected to the NIC. 1621 */ 1622 if (hw->phy.type == e1000_phy_m88) 1623 igb_phy_disable_receiver(adapter); 1624 1625 mdelay(500); 1626 return 0; 1627} 1628 1629static int igb_set_phy_loopback(struct igb_adapter *adapter) 1630{ 1631 return igb_integrated_phy_loopback(adapter); 1632} 1633 1634static int igb_setup_loopback_test(struct igb_adapter *adapter) 1635{ 1636 struct e1000_hw *hw = &adapter->hw; 1637 u32 reg; 1638 1639 reg = rd32(E1000_CTRL_EXT); 1640 1641 /* use CTRL_EXT to identify link type as SGMII can appear as copper */ 1642 if (reg & E1000_CTRL_EXT_LINK_MODE_MASK) { 1643 if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) || 1644 (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) || 1645 (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) || 1646 (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP)) { 1647 1648 /* Enable DH89xxCC MPHY for near end loopback */ 1649 reg = rd32(E1000_MPHY_ADDR_CTL); 1650 reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) | 1651 E1000_MPHY_PCS_CLK_REG_OFFSET; 1652 wr32(E1000_MPHY_ADDR_CTL, reg); 1653 1654 reg = rd32(E1000_MPHY_DATA); 1655 reg |= E1000_MPHY_PCS_CLK_REG_DIGINELBEN; 1656 wr32(E1000_MPHY_DATA, reg); 1657 } 1658 1659 reg = rd32(E1000_RCTL); 1660 reg |= E1000_RCTL_LBM_TCVR; 1661 wr32(E1000_RCTL, reg); 1662 1663 wr32(E1000_SCTL, E1000_ENABLE_SERDES_LOOPBACK); 1664 1665 reg = rd32(E1000_CTRL); 1666 reg &= ~(E1000_CTRL_RFCE | 1667 E1000_CTRL_TFCE | 1668 E1000_CTRL_LRST); 1669 reg |= E1000_CTRL_SLU | 1670 E1000_CTRL_FD; 1671 wr32(E1000_CTRL, reg); 1672 1673 /* Unset switch control to serdes energy detect */ 1674 reg = rd32(E1000_CONNSW); 1675 reg &= ~E1000_CONNSW_ENRGSRC; 1676 wr32(E1000_CONNSW, reg); 1677 1678 /* Unset sigdetect for SERDES loopback on 1679 * 82580 and newer devices. 1680 */ 1681 if (hw->mac.type >= e1000_82580) { 1682 reg = rd32(E1000_PCS_CFG0); 1683 reg |= E1000_PCS_CFG_IGN_SD; 1684 wr32(E1000_PCS_CFG0, reg); 1685 } 1686 1687 /* Set PCS register for forced speed */ 1688 reg = rd32(E1000_PCS_LCTL); 1689 reg &= ~E1000_PCS_LCTL_AN_ENABLE; /* Disable Autoneg*/ 1690 reg |= E1000_PCS_LCTL_FLV_LINK_UP | /* Force link up */ 1691 E1000_PCS_LCTL_FSV_1000 | /* Force 1000 */ 1692 E1000_PCS_LCTL_FDV_FULL | /* SerDes Full duplex */ 1693 E1000_PCS_LCTL_FSD | /* Force Speed */ 1694 E1000_PCS_LCTL_FORCE_LINK; /* Force Link */ 1695 wr32(E1000_PCS_LCTL, reg); 1696 1697 return 0; 1698 } 1699 1700 return igb_set_phy_loopback(adapter); 1701} 1702 1703static void igb_loopback_cleanup(struct igb_adapter *adapter) 1704{ 1705 struct e1000_hw *hw = &adapter->hw; 1706 u32 rctl; 1707 u16 phy_reg; 1708 1709 if ((hw->device_id == E1000_DEV_ID_DH89XXCC_SGMII) || 1710 (hw->device_id == E1000_DEV_ID_DH89XXCC_SERDES) || 1711 (hw->device_id == E1000_DEV_ID_DH89XXCC_BACKPLANE) || 1712 (hw->device_id == E1000_DEV_ID_DH89XXCC_SFP)) { 1713 u32 reg; 1714 1715 /* Disable near end loopback on DH89xxCC */ 1716 reg = rd32(E1000_MPHY_ADDR_CTL); 1717 reg = (reg & E1000_MPHY_ADDR_CTL_OFFSET_MASK) | 1718 E1000_MPHY_PCS_CLK_REG_OFFSET; 1719 wr32(E1000_MPHY_ADDR_CTL, reg); 1720 1721 reg = rd32(E1000_MPHY_DATA); 1722 reg &= ~E1000_MPHY_PCS_CLK_REG_DIGINELBEN; 1723 wr32(E1000_MPHY_DATA, reg); 1724 } 1725 1726 rctl = rd32(E1000_RCTL); 1727 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); 1728 wr32(E1000_RCTL, rctl); 1729 1730 hw->mac.autoneg = true; 1731 igb_read_phy_reg(hw, PHY_CONTROL, &phy_reg); 1732 if (phy_reg & MII_CR_LOOPBACK) { 1733 phy_reg &= ~MII_CR_LOOPBACK; 1734 igb_write_phy_reg(hw, PHY_CONTROL, phy_reg); 1735 igb_phy_sw_reset(hw); 1736 } 1737} 1738 1739static void igb_create_lbtest_frame(struct sk_buff *skb, 1740 unsigned int frame_size) 1741{ 1742 memset(skb->data, 0xFF, frame_size); 1743 frame_size /= 2; 1744 memset(&skb->data[frame_size], 0xAA, frame_size - 1); 1745 memset(&skb->data[frame_size + 10], 0xBE, 1); 1746 memset(&skb->data[frame_size + 12], 0xAF, 1); 1747} 1748 1749static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer, 1750 unsigned int frame_size) 1751{ 1752 unsigned char *data; 1753 bool match = true; 1754 1755 frame_size >>= 1; 1756 1757 data = kmap(rx_buffer->page); 1758 1759 if (data[3] != 0xFF || 1760 data[frame_size + 10] != 0xBE || 1761 data[frame_size + 12] != 0xAF) 1762 match = false; 1763 1764 kunmap(rx_buffer->page); 1765 1766 return match; 1767} 1768 1769static int igb_clean_test_rings(struct igb_ring *rx_ring, 1770 struct igb_ring *tx_ring, 1771 unsigned int size) 1772{ 1773 union e1000_adv_rx_desc *rx_desc; 1774 struct igb_rx_buffer *rx_buffer_info; 1775 struct igb_tx_buffer *tx_buffer_info; 1776 u16 rx_ntc, tx_ntc, count = 0; 1777 1778 /* initialize next to clean and descriptor values */ 1779 rx_ntc = rx_ring->next_to_clean; 1780 tx_ntc = tx_ring->next_to_clean; 1781 rx_desc = IGB_RX_DESC(rx_ring, rx_ntc); 1782 1783 while (igb_test_staterr(rx_desc, E1000_RXD_STAT_DD)) { 1784 /* check Rx buffer */ 1785 rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc]; 1786 1787 /* sync Rx buffer for CPU read */ 1788 dma_sync_single_for_cpu(rx_ring->dev, 1789 rx_buffer_info->dma, 1790 IGB_RX_BUFSZ, 1791 DMA_FROM_DEVICE); 1792 1793 /* verify contents of skb */ 1794 if (igb_check_lbtest_frame(rx_buffer_info, size)) 1795 count++; 1796 1797 /* sync Rx buffer for device write */ 1798 dma_sync_single_for_device(rx_ring->dev, 1799 rx_buffer_info->dma, 1800 IGB_RX_BUFSZ, 1801 DMA_FROM_DEVICE); 1802 1803 /* unmap buffer on Tx side */ 1804 tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc]; 1805 igb_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); 1806 1807 /* increment Rx/Tx next to clean counters */ 1808 rx_ntc++; 1809 if (rx_ntc == rx_ring->count) 1810 rx_ntc = 0; 1811 tx_ntc++; 1812 if (tx_ntc == tx_ring->count) 1813 tx_ntc = 0; 1814 1815 /* fetch next descriptor */ 1816 rx_desc = IGB_RX_DESC(rx_ring, rx_ntc); 1817 } 1818 1819 netdev_tx_reset_queue(txring_txq(tx_ring)); 1820 1821 /* re-map buffers to ring, store next to clean values */ 1822 igb_alloc_rx_buffers(rx_ring, count); 1823 rx_ring->next_to_clean = rx_ntc; 1824 tx_ring->next_to_clean = tx_ntc; 1825 1826 return count; 1827} 1828 1829static int igb_run_loopback_test(struct igb_adapter *adapter) 1830{ 1831 struct igb_ring *tx_ring = &adapter->test_tx_ring; 1832 struct igb_ring *rx_ring = &adapter->test_rx_ring; 1833 u16 i, j, lc, good_cnt; 1834 int ret_val = 0; 1835 unsigned int size = IGB_RX_HDR_LEN; 1836 netdev_tx_t tx_ret_val; 1837 struct sk_buff *skb; 1838 1839 /* allocate test skb */ 1840 skb = alloc_skb(size, GFP_KERNEL); 1841 if (!skb) 1842 return 11; 1843 1844 /* place data into test skb */ 1845 igb_create_lbtest_frame(skb, size); 1846 skb_put(skb, size); 1847 1848 /* Calculate the loop count based on the largest descriptor ring 1849 * The idea is to wrap the largest ring a number of times using 64 1850 * send/receive pairs during each loop 1851 */ 1852 1853 if (rx_ring->count <= tx_ring->count) 1854 lc = ((tx_ring->count / 64) * 2) + 1; 1855 else 1856 lc = ((rx_ring->count / 64) * 2) + 1; 1857 1858 for (j = 0; j <= lc; j++) { /* loop count loop */ 1859 /* reset count of good packets */ 1860 good_cnt = 0; 1861 1862 /* place 64 packets on the transmit queue*/ 1863 for (i = 0; i < 64; i++) { 1864 skb_get(skb); 1865 tx_ret_val = igb_xmit_frame_ring(skb, tx_ring); 1866 if (tx_ret_val == NETDEV_TX_OK) 1867 good_cnt++; 1868 } 1869 1870 if (good_cnt != 64) { 1871 ret_val = 12; 1872 break; 1873 } 1874 1875 /* allow 200 milliseconds for packets to go from Tx to Rx */ 1876 msleep(200); 1877 1878 good_cnt = igb_clean_test_rings(rx_ring, tx_ring, size); 1879 if (good_cnt != 64) { 1880 ret_val = 13; 1881 break; 1882 } 1883 } /* end loop count loop */ 1884 1885 /* free the original skb */ 1886 kfree_skb(skb); 1887 1888 return ret_val; 1889} 1890 1891static int igb_loopback_test(struct igb_adapter *adapter, u64 *data) 1892{ 1893 /* PHY loopback cannot be performed if SoL/IDER 1894 * sessions are active 1895 */ 1896 if (igb_check_reset_block(&adapter->hw)) { 1897 dev_err(&adapter->pdev->dev, 1898 "Cannot do PHY loopback test when SoL/IDER is active.\n"); 1899 *data = 0; 1900 goto out; 1901 } 1902 1903 if (adapter->hw.mac.type == e1000_i354) { 1904 dev_info(&adapter->pdev->dev, 1905 "Loopback test not supported on i354.\n"); 1906 *data = 0; 1907 goto out; 1908 } 1909 *data = igb_setup_desc_rings(adapter); 1910 if (*data) 1911 goto out; 1912 *data = igb_setup_loopback_test(adapter); 1913 if (*data) 1914 goto err_loopback; 1915 *data = igb_run_loopback_test(adapter); 1916 igb_loopback_cleanup(adapter); 1917 1918err_loopback: 1919 igb_free_desc_rings(adapter); 1920out: 1921 return *data; 1922} 1923 1924static int igb_link_test(struct igb_adapter *adapter, u64 *data) 1925{ 1926 struct e1000_hw *hw = &adapter->hw; 1927 *data = 0; 1928 if (hw->phy.media_type == e1000_media_type_internal_serdes) { 1929 int i = 0; 1930 hw->mac.serdes_has_link = false; 1931 1932 /* On some blade server designs, link establishment 1933 * could take as long as 2-3 minutes 1934 */ 1935 do { 1936 hw->mac.ops.check_for_link(&adapter->hw); 1937 if (hw->mac.serdes_has_link) 1938 return *data; 1939 msleep(20); 1940 } while (i++ < 3750); 1941 1942 *data = 1; 1943 } else { 1944 hw->mac.ops.check_for_link(&adapter->hw); 1945 if (hw->mac.autoneg) 1946 msleep(5000); 1947 1948 if (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) 1949 *data = 1; 1950 } 1951 return *data; 1952} 1953 1954static void igb_diag_test(struct net_device *netdev, 1955 struct ethtool_test *eth_test, u64 *data) 1956{ 1957 struct igb_adapter *adapter = netdev_priv(netdev); 1958 u16 autoneg_advertised; 1959 u8 forced_speed_duplex, autoneg; 1960 bool if_running = netif_running(netdev); 1961 1962 set_bit(__IGB_TESTING, &adapter->state); 1963 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 1964 /* Offline tests */ 1965 1966 /* save speed, duplex, autoneg settings */ 1967 autoneg_advertised = adapter->hw.phy.autoneg_advertised; 1968 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex; 1969 autoneg = adapter->hw.mac.autoneg; 1970 1971 dev_info(&adapter->pdev->dev, "offline testing starting\n"); 1972 1973 /* power up link for link test */ 1974 igb_power_up_link(adapter); 1975 1976 /* Link test performed before hardware reset so autoneg doesn't 1977 * interfere with test result 1978 */ 1979 if (igb_link_test(adapter, &data[4])) 1980 eth_test->flags |= ETH_TEST_FL_FAILED; 1981 1982 if (if_running) 1983 /* indicate we're in test mode */ 1984 dev_close(netdev); 1985 else 1986 igb_reset(adapter); 1987 1988 if (igb_reg_test(adapter, &data[0])) 1989 eth_test->flags |= ETH_TEST_FL_FAILED; 1990 1991 igb_reset(adapter); 1992 if (igb_eeprom_test(adapter, &data[1])) 1993 eth_test->flags |= ETH_TEST_FL_FAILED; 1994 1995 igb_reset(adapter); 1996 if (igb_intr_test(adapter, &data[2])) 1997 eth_test->flags |= ETH_TEST_FL_FAILED; 1998 1999 igb_reset(adapter); 2000 /* power up link for loopback test */ 2001 igb_power_up_link(adapter); 2002 if (igb_loopback_test(adapter, &data[3])) 2003 eth_test->flags |= ETH_TEST_FL_FAILED; 2004 2005 /* restore speed, duplex, autoneg settings */ 2006 adapter->hw.phy.autoneg_advertised = autoneg_advertised; 2007 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex; 2008 adapter->hw.mac.autoneg = autoneg; 2009 2010 /* force this routine to wait until autoneg complete/timeout */ 2011 adapter->hw.phy.autoneg_wait_to_complete = true; 2012 igb_reset(adapter); 2013 adapter->hw.phy.autoneg_wait_to_complete = false; 2014 2015 clear_bit(__IGB_TESTING, &adapter->state); 2016 if (if_running) 2017 dev_open(netdev); 2018 } else { 2019 dev_info(&adapter->pdev->dev, "online testing starting\n"); 2020 2021 /* PHY is powered down when interface is down */ 2022 if (if_running && igb_link_test(adapter, &data[4])) 2023 eth_test->flags |= ETH_TEST_FL_FAILED; 2024 else 2025 data[4] = 0; 2026 2027 /* Online tests aren't run; pass by default */ 2028 data[0] = 0; 2029 data[1] = 0; 2030 data[2] = 0; 2031 data[3] = 0; 2032 2033 clear_bit(__IGB_TESTING, &adapter->state); 2034 } 2035 msleep_interruptible(4 * 1000); 2036} 2037 2038static void igb_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 2039{ 2040 struct igb_adapter *adapter = netdev_priv(netdev); 2041 2042 wol->supported = WAKE_UCAST | WAKE_MCAST | 2043 WAKE_BCAST | WAKE_MAGIC | 2044 WAKE_PHY; 2045 wol->wolopts = 0; 2046 2047 if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED)) 2048 return; 2049 2050 /* apply any specific unsupported masks here */ 2051 switch (adapter->hw.device_id) { 2052 default: 2053 break; 2054 } 2055 2056 if (adapter->wol & E1000_WUFC_EX) 2057 wol->wolopts |= WAKE_UCAST; 2058 if (adapter->wol & E1000_WUFC_MC) 2059 wol->wolopts |= WAKE_MCAST; 2060 if (adapter->wol & E1000_WUFC_BC) 2061 wol->wolopts |= WAKE_BCAST; 2062 if (adapter->wol & E1000_WUFC_MAG) 2063 wol->wolopts |= WAKE_MAGIC; 2064 if (adapter->wol & E1000_WUFC_LNKC) 2065 wol->wolopts |= WAKE_PHY; 2066} 2067 2068static int igb_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 2069{ 2070 struct igb_adapter *adapter = netdev_priv(netdev); 2071 2072 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE)) 2073 return -EOPNOTSUPP; 2074 2075 if (!(adapter->flags & IGB_FLAG_WOL_SUPPORTED)) 2076 return wol->wolopts ? -EOPNOTSUPP : 0; 2077 2078 /* these settings will always override what we currently have */ 2079 adapter->wol = 0; 2080 2081 if (wol->wolopts & WAKE_UCAST) 2082 adapter->wol |= E1000_WUFC_EX; 2083 if (wol->wolopts & WAKE_MCAST) 2084 adapter->wol |= E1000_WUFC_MC; 2085 if (wol->wolopts & WAKE_BCAST) 2086 adapter->wol |= E1000_WUFC_BC; 2087 if (wol->wolopts & WAKE_MAGIC) 2088 adapter->wol |= E1000_WUFC_MAG; 2089 if (wol->wolopts & WAKE_PHY) 2090 adapter->wol |= E1000_WUFC_LNKC; 2091 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); 2092 2093 return 0; 2094} 2095 2096/* bit defines for adapter->led_status */ 2097#define IGB_LED_ON 0 2098 2099static int igb_set_phys_id(struct net_device *netdev, 2100 enum ethtool_phys_id_state state) 2101{ 2102 struct igb_adapter *adapter = netdev_priv(netdev); 2103 struct e1000_hw *hw = &adapter->hw; 2104 2105 switch (state) { 2106 case ETHTOOL_ID_ACTIVE: 2107 igb_blink_led(hw); 2108 return 2; 2109 case ETHTOOL_ID_ON: 2110 igb_blink_led(hw); 2111 break; 2112 case ETHTOOL_ID_OFF: 2113 igb_led_off(hw); 2114 break; 2115 case ETHTOOL_ID_INACTIVE: 2116 igb_led_off(hw); 2117 clear_bit(IGB_LED_ON, &adapter->led_status); 2118 igb_cleanup_led(hw); 2119 break; 2120 } 2121 2122 return 0; 2123} 2124 2125static int igb_set_coalesce(struct net_device *netdev, 2126 struct ethtool_coalesce *ec) 2127{ 2128 struct igb_adapter *adapter = netdev_priv(netdev); 2129 int i; 2130 2131 if ((ec->rx_coalesce_usecs > IGB_MAX_ITR_USECS) || 2132 ((ec->rx_coalesce_usecs > 3) && 2133 (ec->rx_coalesce_usecs < IGB_MIN_ITR_USECS)) || 2134 (ec->rx_coalesce_usecs == 2)) 2135 return -EINVAL; 2136 2137 if ((ec->tx_coalesce_usecs > IGB_MAX_ITR_USECS) || 2138 ((ec->tx_coalesce_usecs > 3) && 2139 (ec->tx_coalesce_usecs < IGB_MIN_ITR_USECS)) || 2140 (ec->tx_coalesce_usecs == 2)) 2141 return -EINVAL; 2142 2143 if ((adapter->flags & IGB_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs) 2144 return -EINVAL; 2145 2146 /* If ITR is disabled, disable DMAC */ 2147 if (ec->rx_coalesce_usecs == 0) { 2148 if (adapter->flags & IGB_FLAG_DMAC) 2149 adapter->flags &= ~IGB_FLAG_DMAC; 2150 } 2151 2152 /* convert to rate of irq's per second */ 2153 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3) 2154 adapter->rx_itr_setting = ec->rx_coalesce_usecs; 2155 else 2156 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2; 2157 2158 /* convert to rate of irq's per second */ 2159 if (adapter->flags & IGB_FLAG_QUEUE_PAIRS) 2160 adapter->tx_itr_setting = adapter->rx_itr_setting; 2161 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3) 2162 adapter->tx_itr_setting = ec->tx_coalesce_usecs; 2163 else 2164 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2; 2165 2166 for (i = 0; i < adapter->num_q_vectors; i++) { 2167 struct igb_q_vector *q_vector = adapter->q_vector[i]; 2168 q_vector->tx.work_limit = adapter->tx_work_limit; 2169 if (q_vector->rx.ring) 2170 q_vector->itr_val = adapter->rx_itr_setting; 2171 else 2172 q_vector->itr_val = adapter->tx_itr_setting; 2173 if (q_vector->itr_val && q_vector->itr_val <= 3) 2174 q_vector->itr_val = IGB_START_ITR; 2175 q_vector->set_itr = 1; 2176 } 2177 2178 return 0; 2179} 2180 2181static int igb_get_coalesce(struct net_device *netdev, 2182 struct ethtool_coalesce *ec) 2183{ 2184 struct igb_adapter *adapter = netdev_priv(netdev); 2185 2186 if (adapter->rx_itr_setting <= 3) 2187 ec->rx_coalesce_usecs = adapter->rx_itr_setting; 2188 else 2189 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2; 2190 2191 if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) { 2192 if (adapter->tx_itr_setting <= 3) 2193 ec->tx_coalesce_usecs = adapter->tx_itr_setting; 2194 else 2195 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2; 2196 } 2197 2198 return 0; 2199} 2200 2201static int igb_nway_reset(struct net_device *netdev) 2202{ 2203 struct igb_adapter *adapter = netdev_priv(netdev); 2204 if (netif_running(netdev)) 2205 igb_reinit_locked(adapter); 2206 return 0; 2207} 2208 2209static int igb_get_sset_count(struct net_device *netdev, int sset) 2210{ 2211 switch (sset) { 2212 case ETH_SS_STATS: 2213 return IGB_STATS_LEN; 2214 case ETH_SS_TEST: 2215 return IGB_TEST_LEN; 2216 default: 2217 return -ENOTSUPP; 2218 } 2219} 2220 2221static void igb_get_ethtool_stats(struct net_device *netdev, 2222 struct ethtool_stats *stats, u64 *data) 2223{ 2224 struct igb_adapter *adapter = netdev_priv(netdev); 2225 struct rtnl_link_stats64 *net_stats = &adapter->stats64; 2226 unsigned int start; 2227 struct igb_ring *ring; 2228 int i, j; 2229 char *p; 2230 2231 spin_lock(&adapter->stats64_lock); 2232 igb_update_stats(adapter, net_stats); 2233 2234 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) { 2235 p = (char *)adapter + igb_gstrings_stats[i].stat_offset; 2236 data[i] = (igb_gstrings_stats[i].sizeof_stat == 2237 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 2238 } 2239 for (j = 0; j < IGB_NETDEV_STATS_LEN; j++, i++) { 2240 p = (char *)net_stats + igb_gstrings_net_stats[j].stat_offset; 2241 data[i] = (igb_gstrings_net_stats[j].sizeof_stat == 2242 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 2243 } 2244 for (j = 0; j < adapter->num_tx_queues; j++) { 2245 u64 restart2; 2246 2247 ring = adapter->tx_ring[j]; 2248 do { 2249 start = u64_stats_fetch_begin_bh(&ring->tx_syncp); 2250 data[i] = ring->tx_stats.packets; 2251 data[i+1] = ring->tx_stats.bytes; 2252 data[i+2] = ring->tx_stats.restart_queue; 2253 } while (u64_stats_fetch_retry_bh(&ring->tx_syncp, start)); 2254 do { 2255 start = u64_stats_fetch_begin_bh(&ring->tx_syncp2); 2256 restart2 = ring->tx_stats.restart_queue2; 2257 } while (u64_stats_fetch_retry_bh(&ring->tx_syncp2, start)); 2258 data[i+2] += restart2; 2259 2260 i += IGB_TX_QUEUE_STATS_LEN; 2261 } 2262 for (j = 0; j < adapter->num_rx_queues; j++) { 2263 ring = adapter->rx_ring[j]; 2264 do { 2265 start = u64_stats_fetch_begin_bh(&ring->rx_syncp); 2266 data[i] = ring->rx_stats.packets; 2267 data[i+1] = ring->rx_stats.bytes; 2268 data[i+2] = ring->rx_stats.drops; 2269 data[i+3] = ring->rx_stats.csum_err; 2270 data[i+4] = ring->rx_stats.alloc_failed; 2271 } while (u64_stats_fetch_retry_bh(&ring->rx_syncp, start)); 2272 i += IGB_RX_QUEUE_STATS_LEN; 2273 } 2274 spin_unlock(&adapter->stats64_lock); 2275} 2276 2277static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data) 2278{ 2279 struct igb_adapter *adapter = netdev_priv(netdev); 2280 u8 *p = data; 2281 int i; 2282 2283 switch (stringset) { 2284 case ETH_SS_TEST: 2285 memcpy(data, *igb_gstrings_test, 2286 IGB_TEST_LEN*ETH_GSTRING_LEN); 2287 break; 2288 case ETH_SS_STATS: 2289 for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++) { 2290 memcpy(p, igb_gstrings_stats[i].stat_string, 2291 ETH_GSTRING_LEN); 2292 p += ETH_GSTRING_LEN; 2293 } 2294 for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) { 2295 memcpy(p, igb_gstrings_net_stats[i].stat_string, 2296 ETH_GSTRING_LEN); 2297 p += ETH_GSTRING_LEN; 2298 } 2299 for (i = 0; i < adapter->num_tx_queues; i++) { 2300 sprintf(p, "tx_queue_%u_packets", i); 2301 p += ETH_GSTRING_LEN; 2302 sprintf(p, "tx_queue_%u_bytes", i); 2303 p += ETH_GSTRING_LEN; 2304 sprintf(p, "tx_queue_%u_restart", i); 2305 p += ETH_GSTRING_LEN; 2306 } 2307 for (i = 0; i < adapter->num_rx_queues; i++) { 2308 sprintf(p, "rx_queue_%u_packets", i); 2309 p += ETH_GSTRING_LEN; 2310 sprintf(p, "rx_queue_%u_bytes", i); 2311 p += ETH_GSTRING_LEN; 2312 sprintf(p, "rx_queue_%u_drops", i); 2313 p += ETH_GSTRING_LEN; 2314 sprintf(p, "rx_queue_%u_csum_err", i); 2315 p += ETH_GSTRING_LEN; 2316 sprintf(p, "rx_queue_%u_alloc_failed", i); 2317 p += ETH_GSTRING_LEN; 2318 } 2319 /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */ 2320 break; 2321 } 2322} 2323 2324static int igb_get_ts_info(struct net_device *dev, 2325 struct ethtool_ts_info *info) 2326{ 2327 struct igb_adapter *adapter = netdev_priv(dev); 2328 2329 switch (adapter->hw.mac.type) { 2330 case e1000_82575: 2331 info->so_timestamping = 2332 SOF_TIMESTAMPING_TX_SOFTWARE | 2333 SOF_TIMESTAMPING_RX_SOFTWARE | 2334 SOF_TIMESTAMPING_SOFTWARE; 2335 return 0; 2336 case e1000_82576: 2337 case e1000_82580: 2338 case e1000_i350: 2339 case e1000_i354: 2340 case e1000_i210: 2341 case e1000_i211: 2342 info->so_timestamping = 2343 SOF_TIMESTAMPING_TX_SOFTWARE | 2344 SOF_TIMESTAMPING_RX_SOFTWARE | 2345 SOF_TIMESTAMPING_SOFTWARE | 2346 SOF_TIMESTAMPING_TX_HARDWARE | 2347 SOF_TIMESTAMPING_RX_HARDWARE | 2348 SOF_TIMESTAMPING_RAW_HARDWARE; 2349 2350 if (adapter->ptp_clock) 2351 info->phc_index = ptp_clock_index(adapter->ptp_clock); 2352 else 2353 info->phc_index = -1; 2354 2355 info->tx_types = 2356 (1 << HWTSTAMP_TX_OFF) | 2357 (1 << HWTSTAMP_TX_ON); 2358 2359 info->rx_filters = 1 << HWTSTAMP_FILTER_NONE; 2360 2361 /* 82576 does not support timestamping all packets. */ 2362 if (adapter->hw.mac.type >= e1000_82580) 2363 info->rx_filters |= 1 << HWTSTAMP_FILTER_ALL; 2364 else 2365 info->rx_filters |= 2366 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | 2367 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | 2368 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | 2369 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | 2370 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) | 2371 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) | 2372 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT); 2373 2374 return 0; 2375 default: 2376 return -EOPNOTSUPP; 2377 } 2378} 2379 2380static int igb_get_rss_hash_opts(struct igb_adapter *adapter, 2381 struct ethtool_rxnfc *cmd) 2382{ 2383 cmd->data = 0; 2384 2385 /* Report default options for RSS on igb */ 2386 switch (cmd->flow_type) { 2387 case TCP_V4_FLOW: 2388 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 2389 case UDP_V4_FLOW: 2390 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV4_UDP) 2391 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 2392 case SCTP_V4_FLOW: 2393 case AH_ESP_V4_FLOW: 2394 case AH_V4_FLOW: 2395 case ESP_V4_FLOW: 2396 case IPV4_FLOW: 2397 cmd->data |= RXH_IP_SRC | RXH_IP_DST; 2398 break; 2399 case TCP_V6_FLOW: 2400 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 2401 case UDP_V6_FLOW: 2402 if (adapter->flags & IGB_FLAG_RSS_FIELD_IPV6_UDP) 2403 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 2404 case SCTP_V6_FLOW: 2405 case AH_ESP_V6_FLOW: 2406 case AH_V6_FLOW: 2407 case ESP_V6_FLOW: 2408 case IPV6_FLOW: 2409 cmd->data |= RXH_IP_SRC | RXH_IP_DST; 2410 break; 2411 default: 2412 return -EINVAL; 2413 } 2414 2415 return 0; 2416} 2417 2418static int igb_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, 2419 u32 *rule_locs) 2420{ 2421 struct igb_adapter *adapter = netdev_priv(dev); 2422 int ret = -EOPNOTSUPP; 2423 2424 switch (cmd->cmd) { 2425 case ETHTOOL_GRXRINGS: 2426 cmd->data = adapter->num_rx_queues; 2427 ret = 0; 2428 break; 2429 case ETHTOOL_GRXFH: 2430 ret = igb_get_rss_hash_opts(adapter, cmd); 2431 break; 2432 default: 2433 break; 2434 } 2435 2436 return ret; 2437} 2438 2439#define UDP_RSS_FLAGS (IGB_FLAG_RSS_FIELD_IPV4_UDP | \ 2440 IGB_FLAG_RSS_FIELD_IPV6_UDP) 2441static int igb_set_rss_hash_opt(struct igb_adapter *adapter, 2442 struct ethtool_rxnfc *nfc) 2443{ 2444 u32 flags = adapter->flags; 2445 2446 /* RSS does not support anything other than hashing 2447 * to queues on src and dst IPs and ports 2448 */ 2449 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | 2450 RXH_L4_B_0_1 | RXH_L4_B_2_3)) 2451 return -EINVAL; 2452 2453 switch (nfc->flow_type) { 2454 case TCP_V4_FLOW: 2455 case TCP_V6_FLOW: 2456 if (!(nfc->data & RXH_IP_SRC) || 2457 !(nfc->data & RXH_IP_DST) || 2458 !(nfc->data & RXH_L4_B_0_1) || 2459 !(nfc->data & RXH_L4_B_2_3)) 2460 return -EINVAL; 2461 break; 2462 case UDP_V4_FLOW: 2463 if (!(nfc->data & RXH_IP_SRC) || 2464 !(nfc->data & RXH_IP_DST)) 2465 return -EINVAL; 2466 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 2467 case 0: 2468 flags &= ~IGB_FLAG_RSS_FIELD_IPV4_UDP; 2469 break; 2470 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 2471 flags |= IGB_FLAG_RSS_FIELD_IPV4_UDP; 2472 break; 2473 default: 2474 return -EINVAL; 2475 } 2476 break; 2477 case UDP_V6_FLOW: 2478 if (!(nfc->data & RXH_IP_SRC) || 2479 !(nfc->data & RXH_IP_DST)) 2480 return -EINVAL; 2481 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 2482 case 0: 2483 flags &= ~IGB_FLAG_RSS_FIELD_IPV6_UDP; 2484 break; 2485 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 2486 flags |= IGB_FLAG_RSS_FIELD_IPV6_UDP; 2487 break; 2488 default: 2489 return -EINVAL; 2490 } 2491 break; 2492 case AH_ESP_V4_FLOW: 2493 case AH_V4_FLOW: 2494 case ESP_V4_FLOW: 2495 case SCTP_V4_FLOW: 2496 case AH_ESP_V6_FLOW: 2497 case AH_V6_FLOW: 2498 case ESP_V6_FLOW: 2499 case SCTP_V6_FLOW: 2500 if (!(nfc->data & RXH_IP_SRC) || 2501 !(nfc->data & RXH_IP_DST) || 2502 (nfc->data & RXH_L4_B_0_1) || 2503 (nfc->data & RXH_L4_B_2_3)) 2504 return -EINVAL; 2505 break; 2506 default: 2507 return -EINVAL; 2508 } 2509 2510 /* if we changed something we need to update flags */ 2511 if (flags != adapter->flags) { 2512 struct e1000_hw *hw = &adapter->hw; 2513 u32 mrqc = rd32(E1000_MRQC); 2514 2515 if ((flags & UDP_RSS_FLAGS) && 2516 !(adapter->flags & UDP_RSS_FLAGS)) 2517 dev_err(&adapter->pdev->dev, 2518 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n"); 2519 2520 adapter->flags = flags; 2521 2522 /* Perform hash on these packet types */ 2523 mrqc |= E1000_MRQC_RSS_FIELD_IPV4 | 2524 E1000_MRQC_RSS_FIELD_IPV4_TCP | 2525 E1000_MRQC_RSS_FIELD_IPV6 | 2526 E1000_MRQC_RSS_FIELD_IPV6_TCP; 2527 2528 mrqc &= ~(E1000_MRQC_RSS_FIELD_IPV4_UDP | 2529 E1000_MRQC_RSS_FIELD_IPV6_UDP); 2530 2531 if (flags & IGB_FLAG_RSS_FIELD_IPV4_UDP) 2532 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP; 2533 2534 if (flags & IGB_FLAG_RSS_FIELD_IPV6_UDP) 2535 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP; 2536 2537 wr32(E1000_MRQC, mrqc); 2538 } 2539 2540 return 0; 2541} 2542 2543static int igb_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) 2544{ 2545 struct igb_adapter *adapter = netdev_priv(dev); 2546 int ret = -EOPNOTSUPP; 2547 2548 switch (cmd->cmd) { 2549 case ETHTOOL_SRXFH: 2550 ret = igb_set_rss_hash_opt(adapter, cmd); 2551 break; 2552 default: 2553 break; 2554 } 2555 2556 return ret; 2557} 2558 2559static int igb_get_eee(struct net_device *netdev, struct ethtool_eee *edata) 2560{ 2561 struct igb_adapter *adapter = netdev_priv(netdev); 2562 struct e1000_hw *hw = &adapter->hw; 2563 u32 ipcnfg, eeer, ret_val; 2564 u16 phy_data; 2565 2566 if ((hw->mac.type < e1000_i350) || 2567 (hw->phy.media_type != e1000_media_type_copper)) 2568 return -EOPNOTSUPP; 2569 2570 edata->supported = (SUPPORTED_1000baseT_Full | 2571 SUPPORTED_100baseT_Full); 2572 2573 ipcnfg = rd32(E1000_IPCNFG); 2574 eeer = rd32(E1000_EEER); 2575 2576 /* EEE status on negotiated link */ 2577 if (ipcnfg & E1000_IPCNFG_EEE_1G_AN) 2578 edata->advertised = ADVERTISED_1000baseT_Full; 2579 2580 if (ipcnfg & E1000_IPCNFG_EEE_100M_AN) 2581 edata->advertised |= ADVERTISED_100baseT_Full; 2582 2583 /* EEE Link Partner Advertised */ 2584 switch (hw->mac.type) { 2585 case e1000_i350: 2586 ret_val = igb_read_emi_reg(hw, E1000_EEE_LP_ADV_ADDR_I350, 2587 &phy_data); 2588 if (ret_val) 2589 return -ENODATA; 2590 2591 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data); 2592 2593 break; 2594 case e1000_i210: 2595 case e1000_i211: 2596 ret_val = igb_read_xmdio_reg(hw, E1000_EEE_LP_ADV_ADDR_I210, 2597 E1000_EEE_LP_ADV_DEV_I210, 2598 &phy_data); 2599 if (ret_val) 2600 return -ENODATA; 2601 2602 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data); 2603 2604 break; 2605 default: 2606 break; 2607 } 2608 2609 if (eeer & E1000_EEER_EEE_NEG) 2610 edata->eee_active = true; 2611 2612 edata->eee_enabled = !hw->dev_spec._82575.eee_disable; 2613 2614 if (eeer & E1000_EEER_TX_LPI_EN) 2615 edata->tx_lpi_enabled = true; 2616 2617 /* Report correct negotiated EEE status for devices that 2618 * wrongly report EEE at half-duplex 2619 */ 2620 if (adapter->link_duplex == HALF_DUPLEX) { 2621 edata->eee_enabled = false; 2622 edata->eee_active = false; 2623 edata->tx_lpi_enabled = false; 2624 edata->advertised &= ~edata->advertised; 2625 } 2626 2627 return 0; 2628} 2629 2630static int igb_set_eee(struct net_device *netdev, 2631 struct ethtool_eee *edata) 2632{ 2633 struct igb_adapter *adapter = netdev_priv(netdev); 2634 struct e1000_hw *hw = &adapter->hw; 2635 struct ethtool_eee eee_curr; 2636 s32 ret_val; 2637 2638 if ((hw->mac.type < e1000_i350) || 2639 (hw->phy.media_type != e1000_media_type_copper)) 2640 return -EOPNOTSUPP; 2641 2642 ret_val = igb_get_eee(netdev, &eee_curr); 2643 if (ret_val) 2644 return ret_val; 2645 2646 if (eee_curr.eee_enabled) { 2647 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) { 2648 dev_err(&adapter->pdev->dev, 2649 "Setting EEE tx-lpi is not supported\n"); 2650 return -EINVAL; 2651 } 2652 2653 /* Tx LPI timer is not implemented currently */ 2654 if (edata->tx_lpi_timer) { 2655 dev_err(&adapter->pdev->dev, 2656 "Setting EEE Tx LPI timer is not supported\n"); 2657 return -EINVAL; 2658 } 2659 2660 if (eee_curr.advertised != edata->advertised) { 2661 dev_err(&adapter->pdev->dev, 2662 "Setting EEE Advertisement is not supported\n"); 2663 return -EINVAL; 2664 } 2665 2666 } else if (!edata->eee_enabled) { 2667 dev_err(&adapter->pdev->dev, 2668 "Setting EEE options are not supported with EEE disabled\n"); 2669 return -EINVAL; 2670 } 2671 2672 if (hw->dev_spec._82575.eee_disable != !edata->eee_enabled) { 2673 hw->dev_spec._82575.eee_disable = !edata->eee_enabled; 2674 igb_set_eee_i350(hw); 2675 2676 /* reset link */ 2677 if (!netif_running(netdev)) 2678 igb_reset(adapter); 2679 } 2680 2681 return 0; 2682} 2683 2684static int igb_get_module_info(struct net_device *netdev, 2685 struct ethtool_modinfo *modinfo) 2686{ 2687 struct igb_adapter *adapter = netdev_priv(netdev); 2688 struct e1000_hw *hw = &adapter->hw; 2689 u32 status = E1000_SUCCESS; 2690 u16 sff8472_rev, addr_mode; 2691 bool page_swap = false; 2692 2693 if ((hw->phy.media_type == e1000_media_type_copper) || 2694 (hw->phy.media_type == e1000_media_type_unknown)) 2695 return -EOPNOTSUPP; 2696 2697 /* Check whether we support SFF-8472 or not */ 2698 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev); 2699 if (status != E1000_SUCCESS) 2700 return -EIO; 2701 2702 /* addressing mode is not supported */ 2703 status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode); 2704 if (status != E1000_SUCCESS) 2705 return -EIO; 2706 2707 /* addressing mode is not supported */ 2708 if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) { 2709 hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n"); 2710 page_swap = true; 2711 } 2712 2713 if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) { 2714 /* We have an SFP, but it does not support SFF-8472 */ 2715 modinfo->type = ETH_MODULE_SFF_8079; 2716 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; 2717 } else { 2718 /* We have an SFP which supports a revision of SFF-8472 */ 2719 modinfo->type = ETH_MODULE_SFF_8472; 2720 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 2721 } 2722 2723 return 0; 2724} 2725 2726static int igb_get_module_eeprom(struct net_device *netdev, 2727 struct ethtool_eeprom *ee, u8 *data) 2728{ 2729 struct igb_adapter *adapter = netdev_priv(netdev); 2730 struct e1000_hw *hw = &adapter->hw; 2731 u32 status = E1000_SUCCESS; 2732 u16 *dataword; 2733 u16 first_word, last_word; 2734 int i = 0; 2735 2736 if (ee->len == 0) 2737 return -EINVAL; 2738 2739 first_word = ee->offset >> 1; 2740 last_word = (ee->offset + ee->len - 1) >> 1; 2741 2742 dataword = kmalloc(sizeof(u16) * (last_word - first_word + 1), 2743 GFP_KERNEL); 2744 if (!dataword) 2745 return -ENOMEM; 2746 2747 /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */ 2748 for (i = 0; i < last_word - first_word + 1; i++) { 2749 status = igb_read_phy_reg_i2c(hw, first_word + i, &dataword[i]); 2750 if (status != E1000_SUCCESS) 2751 /* Error occurred while reading module */ 2752 return -EIO; 2753 2754 be16_to_cpus(&dataword[i]); 2755 } 2756 2757 memcpy(data, (u8 *)dataword + (ee->offset & 1), ee->len); 2758 kfree(dataword); 2759 2760 return 0; 2761} 2762 2763static int igb_ethtool_begin(struct net_device *netdev) 2764{ 2765 struct igb_adapter *adapter = netdev_priv(netdev); 2766 pm_runtime_get_sync(&adapter->pdev->dev); 2767 return 0; 2768} 2769 2770static void igb_ethtool_complete(struct net_device *netdev) 2771{ 2772 struct igb_adapter *adapter = netdev_priv(netdev); 2773 pm_runtime_put(&adapter->pdev->dev); 2774} 2775 2776static const struct ethtool_ops igb_ethtool_ops = { 2777 .get_settings = igb_get_settings, 2778 .set_settings = igb_set_settings, 2779 .get_drvinfo = igb_get_drvinfo, 2780 .get_regs_len = igb_get_regs_len, 2781 .get_regs = igb_get_regs, 2782 .get_wol = igb_get_wol, 2783 .set_wol = igb_set_wol, 2784 .get_msglevel = igb_get_msglevel, 2785 .set_msglevel = igb_set_msglevel, 2786 .nway_reset = igb_nway_reset, 2787 .get_link = igb_get_link, 2788 .get_eeprom_len = igb_get_eeprom_len, 2789 .get_eeprom = igb_get_eeprom, 2790 .set_eeprom = igb_set_eeprom, 2791 .get_ringparam = igb_get_ringparam, 2792 .set_ringparam = igb_set_ringparam, 2793 .get_pauseparam = igb_get_pauseparam, 2794 .set_pauseparam = igb_set_pauseparam, 2795 .self_test = igb_diag_test, 2796 .get_strings = igb_get_strings, 2797 .set_phys_id = igb_set_phys_id, 2798 .get_sset_count = igb_get_sset_count, 2799 .get_ethtool_stats = igb_get_ethtool_stats, 2800 .get_coalesce = igb_get_coalesce, 2801 .set_coalesce = igb_set_coalesce, 2802 .get_ts_info = igb_get_ts_info, 2803 .get_rxnfc = igb_get_rxnfc, 2804 .set_rxnfc = igb_set_rxnfc, 2805 .get_eee = igb_get_eee, 2806 .set_eee = igb_set_eee, 2807 .get_module_info = igb_get_module_info, 2808 .get_module_eeprom = igb_get_module_eeprom, 2809 .begin = igb_ethtool_begin, 2810 .complete = igb_ethtool_complete, 2811}; 2812 2813void igb_set_ethtool_ops(struct net_device *netdev) 2814{ 2815 SET_ETHTOOL_OPS(netdev, &igb_ethtool_ops); 2816} 2817