1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2018 Intel Corporation */ 3 4 /* ethtool support for igc */ 5 #include <linux/if_vlan.h> 6 #include <linux/pm_runtime.h> 7 #include <linux/mdio.h> 8 9 #include "igc.h" 10 #include "igc_diag.h" 11 12 /* forward declaration */ 13 struct igc_stats { 14 char stat_string[ETH_GSTRING_LEN]; 15 int sizeof_stat; 16 int stat_offset; 17 }; 18 19 #define IGC_STAT(_name, _stat) { \ 20 .stat_string = _name, \ 21 .sizeof_stat = sizeof_field(struct igc_adapter, _stat), \ 22 .stat_offset = offsetof(struct igc_adapter, _stat) \ 23 } 24 25 static const struct igc_stats igc_gstrings_stats[] = { 26 IGC_STAT("rx_packets", stats.gprc), 27 IGC_STAT("tx_packets", stats.gptc), 28 IGC_STAT("rx_bytes", stats.gorc), 29 IGC_STAT("tx_bytes", stats.gotc), 30 IGC_STAT("rx_broadcast", stats.bprc), 31 IGC_STAT("tx_broadcast", stats.bptc), 32 IGC_STAT("rx_multicast", stats.mprc), 33 IGC_STAT("tx_multicast", stats.mptc), 34 IGC_STAT("multicast", stats.mprc), 35 IGC_STAT("collisions", stats.colc), 36 IGC_STAT("rx_crc_errors", stats.crcerrs), 37 IGC_STAT("rx_no_buffer_count", stats.rnbc), 38 IGC_STAT("rx_missed_errors", stats.mpc), 39 IGC_STAT("tx_aborted_errors", stats.ecol), 40 IGC_STAT("tx_carrier_errors", stats.tncrs), 41 IGC_STAT("tx_window_errors", stats.latecol), 42 IGC_STAT("tx_abort_late_coll", stats.latecol), 43 IGC_STAT("tx_deferred_ok", stats.dc), 44 IGC_STAT("tx_single_coll_ok", stats.scc), 45 IGC_STAT("tx_multi_coll_ok", stats.mcc), 46 IGC_STAT("tx_timeout_count", tx_timeout_count), 47 IGC_STAT("rx_long_length_errors", stats.roc), 48 IGC_STAT("rx_short_length_errors", stats.ruc), 49 IGC_STAT("rx_align_errors", stats.algnerrc), 50 IGC_STAT("tx_tcp_seg_good", stats.tsctc), 51 IGC_STAT("tx_tcp_seg_failed", stats.tsctfc), 52 IGC_STAT("rx_flow_control_xon", stats.xonrxc), 53 IGC_STAT("rx_flow_control_xoff", stats.xoffrxc), 54 IGC_STAT("tx_flow_control_xon", stats.xontxc), 55 IGC_STAT("tx_flow_control_xoff", stats.xofftxc), 56 IGC_STAT("rx_long_byte_count", stats.gorc), 57 IGC_STAT("tx_dma_out_of_sync", stats.doosync), 58 IGC_STAT("tx_smbus", stats.mgptc), 59 IGC_STAT("rx_smbus", stats.mgprc), 60 IGC_STAT("dropped_smbus", stats.mgpdc), 61 IGC_STAT("os2bmc_rx_by_bmc", stats.o2bgptc), 62 IGC_STAT("os2bmc_tx_by_bmc", stats.b2ospc), 63 IGC_STAT("os2bmc_tx_by_host", stats.o2bspc), 64 IGC_STAT("os2bmc_rx_by_host", stats.b2ogprc), 65 IGC_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts), 66 IGC_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped), 67 IGC_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared), 68 }; 69 70 #define IGC_NETDEV_STAT(_net_stat) { \ 71 .stat_string = __stringify(_net_stat), \ 72 .sizeof_stat = sizeof_field(struct rtnl_link_stats64, _net_stat), \ 73 .stat_offset = offsetof(struct rtnl_link_stats64, _net_stat) \ 74 } 75 76 static const struct igc_stats igc_gstrings_net_stats[] = { 77 IGC_NETDEV_STAT(rx_errors), 78 IGC_NETDEV_STAT(tx_errors), 79 IGC_NETDEV_STAT(tx_dropped), 80 IGC_NETDEV_STAT(rx_length_errors), 81 IGC_NETDEV_STAT(rx_over_errors), 82 IGC_NETDEV_STAT(rx_frame_errors), 83 IGC_NETDEV_STAT(rx_fifo_errors), 84 IGC_NETDEV_STAT(tx_fifo_errors), 85 IGC_NETDEV_STAT(tx_heartbeat_errors) 86 }; 87 88 enum igc_diagnostics_results { 89 TEST_REG = 0, 90 TEST_EEP, 91 TEST_IRQ, 92 TEST_LOOP, 93 TEST_LINK 94 }; 95 96 static const char igc_gstrings_test[][ETH_GSTRING_LEN] = { 97 [TEST_REG] = "Register test (offline)", 98 [TEST_EEP] = "Eeprom test (offline)", 99 [TEST_IRQ] = "Interrupt test (offline)", 100 [TEST_LOOP] = "Loopback test (offline)", 101 [TEST_LINK] = "Link test (on/offline)" 102 }; 103 104 #define IGC_TEST_LEN (sizeof(igc_gstrings_test) / ETH_GSTRING_LEN) 105 106 #define IGC_GLOBAL_STATS_LEN \ 107 (sizeof(igc_gstrings_stats) / sizeof(struct igc_stats)) 108 #define IGC_NETDEV_STATS_LEN \ 109 (sizeof(igc_gstrings_net_stats) / sizeof(struct igc_stats)) 110 #define IGC_RX_QUEUE_STATS_LEN \ 111 (sizeof(struct igc_rx_queue_stats) / sizeof(u64)) 112 #define IGC_TX_QUEUE_STATS_LEN 3 /* packets, bytes, restart_queue */ 113 #define IGC_QUEUE_STATS_LEN \ 114 ((((struct igc_adapter *)netdev_priv(netdev))->num_rx_queues * \ 115 IGC_RX_QUEUE_STATS_LEN) + \ 116 (((struct igc_adapter *)netdev_priv(netdev))->num_tx_queues * \ 117 IGC_TX_QUEUE_STATS_LEN)) 118 #define IGC_STATS_LEN \ 119 (IGC_GLOBAL_STATS_LEN + IGC_NETDEV_STATS_LEN + IGC_QUEUE_STATS_LEN) 120 121 static const char igc_priv_flags_strings[][ETH_GSTRING_LEN] = { 122 #define IGC_PRIV_FLAGS_LEGACY_RX BIT(0) 123 "legacy-rx", 124 }; 125 126 #define IGC_PRIV_FLAGS_STR_LEN ARRAY_SIZE(igc_priv_flags_strings) 127 128 static void igc_ethtool_get_drvinfo(struct net_device *netdev, 129 struct ethtool_drvinfo *drvinfo) 130 { 131 struct igc_adapter *adapter = netdev_priv(netdev); 132 struct igc_hw *hw = &adapter->hw; 133 u16 nvm_version = 0; 134 u16 gphy_version; 135 136 strscpy(drvinfo->driver, igc_driver_name, sizeof(drvinfo->driver)); 137 138 /* NVM image version is reported as firmware version for i225 device */ 139 hw->nvm.ops.read(hw, IGC_NVM_DEV_STARTER, 1, &nvm_version); 140 141 /* gPHY firmware version is reported as PHY FW version */ 142 gphy_version = igc_read_phy_fw_version(hw); 143 144 scnprintf(adapter->fw_version, 145 sizeof(adapter->fw_version), 146 "%x:%x", 147 nvm_version, 148 gphy_version); 149 150 strscpy(drvinfo->fw_version, adapter->fw_version, 151 sizeof(drvinfo->fw_version)); 152 153 strscpy(drvinfo->bus_info, pci_name(adapter->pdev), 154 sizeof(drvinfo->bus_info)); 155 156 drvinfo->n_priv_flags = IGC_PRIV_FLAGS_STR_LEN; 157 } 158 159 static int igc_ethtool_get_regs_len(struct net_device *netdev) 160 { 161 return IGC_REGS_LEN * sizeof(u32); 162 } 163 164 static void igc_ethtool_get_regs(struct net_device *netdev, 165 struct ethtool_regs *regs, void *p) 166 { 167 struct igc_adapter *adapter = netdev_priv(netdev); 168 struct igc_hw *hw = &adapter->hw; 169 u32 *regs_buff = p; 170 u8 i; 171 172 memset(p, 0, IGC_REGS_LEN * sizeof(u32)); 173 174 regs->version = (2u << 24) | (hw->revision_id << 16) | hw->device_id; 175 176 /* General Registers */ 177 regs_buff[0] = rd32(IGC_CTRL); 178 regs_buff[1] = rd32(IGC_STATUS); 179 regs_buff[2] = rd32(IGC_CTRL_EXT); 180 regs_buff[3] = rd32(IGC_MDIC); 181 regs_buff[4] = rd32(IGC_CONNSW); 182 183 /* NVM Register */ 184 regs_buff[5] = rd32(IGC_EECD); 185 186 /* Interrupt */ 187 /* Reading EICS for EICR because they read the 188 * same but EICS does not clear on read 189 */ 190 regs_buff[6] = rd32(IGC_EICS); 191 regs_buff[7] = rd32(IGC_EICS); 192 regs_buff[8] = rd32(IGC_EIMS); 193 regs_buff[9] = rd32(IGC_EIMC); 194 regs_buff[10] = rd32(IGC_EIAC); 195 regs_buff[11] = rd32(IGC_EIAM); 196 /* Reading ICS for ICR because they read the 197 * same but ICS does not clear on read 198 */ 199 regs_buff[12] = rd32(IGC_ICS); 200 regs_buff[13] = rd32(IGC_ICS); 201 regs_buff[14] = rd32(IGC_IMS); 202 regs_buff[15] = rd32(IGC_IMC); 203 regs_buff[16] = rd32(IGC_IAC); 204 regs_buff[17] = rd32(IGC_IAM); 205 206 /* Flow Control */ 207 regs_buff[18] = rd32(IGC_FCAL); 208 regs_buff[19] = rd32(IGC_FCAH); 209 regs_buff[20] = rd32(IGC_FCTTV); 210 regs_buff[21] = rd32(IGC_FCRTL); 211 regs_buff[22] = rd32(IGC_FCRTH); 212 regs_buff[23] = rd32(IGC_FCRTV); 213 214 /* Receive */ 215 regs_buff[24] = rd32(IGC_RCTL); 216 regs_buff[25] = rd32(IGC_RXCSUM); 217 regs_buff[26] = rd32(IGC_RLPML); 218 regs_buff[27] = rd32(IGC_RFCTL); 219 220 /* Transmit */ 221 regs_buff[28] = rd32(IGC_TCTL); 222 regs_buff[29] = rd32(IGC_TIPG); 223 224 /* Wake Up */ 225 226 /* MAC */ 227 228 /* Statistics */ 229 regs_buff[30] = adapter->stats.crcerrs; 230 regs_buff[31] = adapter->stats.algnerrc; 231 regs_buff[32] = adapter->stats.symerrs; 232 regs_buff[33] = adapter->stats.rxerrc; 233 regs_buff[34] = adapter->stats.mpc; 234 regs_buff[35] = adapter->stats.scc; 235 regs_buff[36] = adapter->stats.ecol; 236 regs_buff[37] = adapter->stats.mcc; 237 regs_buff[38] = adapter->stats.latecol; 238 regs_buff[39] = adapter->stats.colc; 239 regs_buff[40] = adapter->stats.dc; 240 regs_buff[41] = adapter->stats.tncrs; 241 regs_buff[42] = adapter->stats.sec; 242 regs_buff[43] = adapter->stats.htdpmc; 243 regs_buff[44] = adapter->stats.rlec; 244 regs_buff[45] = adapter->stats.xonrxc; 245 regs_buff[46] = adapter->stats.xontxc; 246 regs_buff[47] = adapter->stats.xoffrxc; 247 regs_buff[48] = adapter->stats.xofftxc; 248 regs_buff[49] = adapter->stats.fcruc; 249 regs_buff[50] = adapter->stats.prc64; 250 regs_buff[51] = adapter->stats.prc127; 251 regs_buff[52] = adapter->stats.prc255; 252 regs_buff[53] = adapter->stats.prc511; 253 regs_buff[54] = adapter->stats.prc1023; 254 regs_buff[55] = adapter->stats.prc1522; 255 regs_buff[56] = adapter->stats.gprc; 256 regs_buff[57] = adapter->stats.bprc; 257 regs_buff[58] = adapter->stats.mprc; 258 regs_buff[59] = adapter->stats.gptc; 259 regs_buff[60] = adapter->stats.gorc; 260 regs_buff[61] = adapter->stats.gotc; 261 regs_buff[62] = adapter->stats.rnbc; 262 regs_buff[63] = adapter->stats.ruc; 263 regs_buff[64] = adapter->stats.rfc; 264 regs_buff[65] = adapter->stats.roc; 265 regs_buff[66] = adapter->stats.rjc; 266 regs_buff[67] = adapter->stats.mgprc; 267 regs_buff[68] = adapter->stats.mgpdc; 268 regs_buff[69] = adapter->stats.mgptc; 269 regs_buff[70] = adapter->stats.tor; 270 regs_buff[71] = adapter->stats.tot; 271 regs_buff[72] = adapter->stats.tpr; 272 regs_buff[73] = adapter->stats.tpt; 273 regs_buff[74] = adapter->stats.ptc64; 274 regs_buff[75] = adapter->stats.ptc127; 275 regs_buff[76] = adapter->stats.ptc255; 276 regs_buff[77] = adapter->stats.ptc511; 277 regs_buff[78] = adapter->stats.ptc1023; 278 regs_buff[79] = adapter->stats.ptc1522; 279 regs_buff[80] = adapter->stats.mptc; 280 regs_buff[81] = adapter->stats.bptc; 281 regs_buff[82] = adapter->stats.tsctc; 282 regs_buff[83] = adapter->stats.iac; 283 regs_buff[84] = adapter->stats.rpthc; 284 regs_buff[85] = adapter->stats.hgptc; 285 regs_buff[86] = adapter->stats.hgorc; 286 regs_buff[87] = adapter->stats.hgotc; 287 regs_buff[88] = adapter->stats.lenerrs; 288 regs_buff[89] = adapter->stats.scvpc; 289 regs_buff[90] = adapter->stats.hrmpc; 290 291 for (i = 0; i < 4; i++) 292 regs_buff[91 + i] = rd32(IGC_SRRCTL(i)); 293 for (i = 0; i < 4; i++) 294 regs_buff[95 + i] = rd32(IGC_PSRTYPE(i)); 295 for (i = 0; i < 4; i++) 296 regs_buff[99 + i] = rd32(IGC_RDBAL(i)); 297 for (i = 0; i < 4; i++) 298 regs_buff[103 + i] = rd32(IGC_RDBAH(i)); 299 for (i = 0; i < 4; i++) 300 regs_buff[107 + i] = rd32(IGC_RDLEN(i)); 301 for (i = 0; i < 4; i++) 302 regs_buff[111 + i] = rd32(IGC_RDH(i)); 303 for (i = 0; i < 4; i++) 304 regs_buff[115 + i] = rd32(IGC_RDT(i)); 305 for (i = 0; i < 4; i++) 306 regs_buff[119 + i] = rd32(IGC_RXDCTL(i)); 307 308 for (i = 0; i < 10; i++) 309 regs_buff[123 + i] = rd32(IGC_EITR(i)); 310 for (i = 0; i < 16; i++) 311 regs_buff[139 + i] = rd32(IGC_RAL(i)); 312 for (i = 0; i < 16; i++) 313 regs_buff[145 + i] = rd32(IGC_RAH(i)); 314 315 for (i = 0; i < 4; i++) 316 regs_buff[149 + i] = rd32(IGC_TDBAL(i)); 317 for (i = 0; i < 4; i++) 318 regs_buff[152 + i] = rd32(IGC_TDBAH(i)); 319 for (i = 0; i < 4; i++) 320 regs_buff[156 + i] = rd32(IGC_TDLEN(i)); 321 for (i = 0; i < 4; i++) 322 regs_buff[160 + i] = rd32(IGC_TDH(i)); 323 for (i = 0; i < 4; i++) 324 regs_buff[164 + i] = rd32(IGC_TDT(i)); 325 for (i = 0; i < 4; i++) 326 regs_buff[168 + i] = rd32(IGC_TXDCTL(i)); 327 328 /* XXX: Due to a bug few lines above, RAL and RAH registers are 329 * overwritten. To preserve the ABI, we write these registers again in 330 * regs_buff. 331 */ 332 for (i = 0; i < 16; i++) 333 regs_buff[172 + i] = rd32(IGC_RAL(i)); 334 for (i = 0; i < 16; i++) 335 regs_buff[188 + i] = rd32(IGC_RAH(i)); 336 337 regs_buff[204] = rd32(IGC_VLANPQF); 338 339 for (i = 0; i < 8; i++) 340 regs_buff[205 + i] = rd32(IGC_ETQF(i)); 341 342 regs_buff[213] = adapter->stats.tlpic; 343 regs_buff[214] = adapter->stats.rlpic; 344 } 345 346 static void igc_ethtool_get_wol(struct net_device *netdev, 347 struct ethtool_wolinfo *wol) 348 { 349 struct igc_adapter *adapter = netdev_priv(netdev); 350 351 wol->wolopts = 0; 352 353 if (!(adapter->flags & IGC_FLAG_WOL_SUPPORTED)) 354 return; 355 356 wol->supported = WAKE_UCAST | WAKE_MCAST | 357 WAKE_BCAST | WAKE_MAGIC | 358 WAKE_PHY; 359 360 /* apply any specific unsupported masks here */ 361 switch (adapter->hw.device_id) { 362 default: 363 break; 364 } 365 366 if (adapter->wol & IGC_WUFC_EX) 367 wol->wolopts |= WAKE_UCAST; 368 if (adapter->wol & IGC_WUFC_MC) 369 wol->wolopts |= WAKE_MCAST; 370 if (adapter->wol & IGC_WUFC_BC) 371 wol->wolopts |= WAKE_BCAST; 372 if (adapter->wol & IGC_WUFC_MAG) 373 wol->wolopts |= WAKE_MAGIC; 374 if (adapter->wol & IGC_WUFC_LNKC) 375 wol->wolopts |= WAKE_PHY; 376 } 377 378 static int igc_ethtool_set_wol(struct net_device *netdev, 379 struct ethtool_wolinfo *wol) 380 { 381 struct igc_adapter *adapter = netdev_priv(netdev); 382 383 if (wol->wolopts & (WAKE_ARP | WAKE_MAGICSECURE | WAKE_FILTER)) 384 return -EOPNOTSUPP; 385 386 if (!(adapter->flags & IGC_FLAG_WOL_SUPPORTED)) 387 return wol->wolopts ? -EOPNOTSUPP : 0; 388 389 /* these settings will always override what we currently have */ 390 adapter->wol = 0; 391 392 if (wol->wolopts & WAKE_UCAST) 393 adapter->wol |= IGC_WUFC_EX; 394 if (wol->wolopts & WAKE_MCAST) 395 adapter->wol |= IGC_WUFC_MC; 396 if (wol->wolopts & WAKE_BCAST) 397 adapter->wol |= IGC_WUFC_BC; 398 if (wol->wolopts & WAKE_MAGIC) 399 adapter->wol |= IGC_WUFC_MAG; 400 if (wol->wolopts & WAKE_PHY) 401 adapter->wol |= IGC_WUFC_LNKC; 402 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); 403 404 return 0; 405 } 406 407 static u32 igc_ethtool_get_msglevel(struct net_device *netdev) 408 { 409 struct igc_adapter *adapter = netdev_priv(netdev); 410 411 return adapter->msg_enable; 412 } 413 414 static void igc_ethtool_set_msglevel(struct net_device *netdev, u32 data) 415 { 416 struct igc_adapter *adapter = netdev_priv(netdev); 417 418 adapter->msg_enable = data; 419 } 420 421 static int igc_ethtool_nway_reset(struct net_device *netdev) 422 { 423 struct igc_adapter *adapter = netdev_priv(netdev); 424 425 if (netif_running(netdev)) 426 igc_reinit_locked(adapter); 427 return 0; 428 } 429 430 static u32 igc_ethtool_get_link(struct net_device *netdev) 431 { 432 struct igc_adapter *adapter = netdev_priv(netdev); 433 struct igc_mac_info *mac = &adapter->hw.mac; 434 435 /* If the link is not reported up to netdev, interrupts are disabled, 436 * and so the physical link state may have changed since we last 437 * looked. Set get_link_status to make sure that the true link 438 * state is interrogated, rather than pulling a cached and possibly 439 * stale link state from the driver. 440 */ 441 if (!netif_carrier_ok(netdev)) 442 mac->get_link_status = 1; 443 444 return igc_has_link(adapter); 445 } 446 447 static int igc_ethtool_get_eeprom_len(struct net_device *netdev) 448 { 449 struct igc_adapter *adapter = netdev_priv(netdev); 450 451 return adapter->hw.nvm.word_size * 2; 452 } 453 454 static int igc_ethtool_get_eeprom(struct net_device *netdev, 455 struct ethtool_eeprom *eeprom, u8 *bytes) 456 { 457 struct igc_adapter *adapter = netdev_priv(netdev); 458 struct igc_hw *hw = &adapter->hw; 459 int first_word, last_word; 460 u16 *eeprom_buff; 461 int ret_val = 0; 462 u16 i; 463 464 if (eeprom->len == 0) 465 return -EINVAL; 466 467 eeprom->magic = hw->vendor_id | (hw->device_id << 16); 468 469 first_word = eeprom->offset >> 1; 470 last_word = (eeprom->offset + eeprom->len - 1) >> 1; 471 472 eeprom_buff = kmalloc_array(last_word - first_word + 1, sizeof(u16), 473 GFP_KERNEL); 474 if (!eeprom_buff) 475 return -ENOMEM; 476 477 if (hw->nvm.type == igc_nvm_eeprom_spi) { 478 ret_val = hw->nvm.ops.read(hw, first_word, 479 last_word - first_word + 1, 480 eeprom_buff); 481 } else { 482 for (i = 0; i < last_word - first_word + 1; i++) { 483 ret_val = hw->nvm.ops.read(hw, first_word + i, 1, 484 &eeprom_buff[i]); 485 if (ret_val) 486 break; 487 } 488 } 489 490 /* Device's eeprom is always little-endian, word addressable */ 491 for (i = 0; i < last_word - first_word + 1; i++) 492 le16_to_cpus(&eeprom_buff[i]); 493 494 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), 495 eeprom->len); 496 kfree(eeprom_buff); 497 498 return ret_val; 499 } 500 501 static int igc_ethtool_set_eeprom(struct net_device *netdev, 502 struct ethtool_eeprom *eeprom, u8 *bytes) 503 { 504 struct igc_adapter *adapter = netdev_priv(netdev); 505 struct igc_hw *hw = &adapter->hw; 506 int max_len, first_word, last_word, ret_val = 0; 507 u16 *eeprom_buff; 508 void *ptr; 509 u16 i; 510 511 if (eeprom->len == 0) 512 return -EOPNOTSUPP; 513 514 if (hw->mac.type >= igc_i225 && 515 !igc_get_flash_presence_i225(hw)) { 516 return -EOPNOTSUPP; 517 } 518 519 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16))) 520 return -EFAULT; 521 522 max_len = hw->nvm.word_size * 2; 523 524 first_word = eeprom->offset >> 1; 525 last_word = (eeprom->offset + eeprom->len - 1) >> 1; 526 eeprom_buff = kmalloc(max_len, GFP_KERNEL); 527 if (!eeprom_buff) 528 return -ENOMEM; 529 530 ptr = (void *)eeprom_buff; 531 532 if (eeprom->offset & 1) { 533 /* need read/modify/write of first changed EEPROM word 534 * only the second byte of the word is being modified 535 */ 536 ret_val = hw->nvm.ops.read(hw, first_word, 1, 537 &eeprom_buff[0]); 538 ptr++; 539 } 540 if (((eeprom->offset + eeprom->len) & 1) && ret_val == 0) { 541 /* need read/modify/write of last changed EEPROM word 542 * only the first byte of the word is being modified 543 */ 544 ret_val = hw->nvm.ops.read(hw, last_word, 1, 545 &eeprom_buff[last_word - first_word]); 546 } 547 548 /* Device's eeprom is always little-endian, word addressable */ 549 for (i = 0; i < last_word - first_word + 1; i++) 550 le16_to_cpus(&eeprom_buff[i]); 551 552 memcpy(ptr, bytes, eeprom->len); 553 554 for (i = 0; i < last_word - first_word + 1; i++) 555 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]); 556 557 ret_val = hw->nvm.ops.write(hw, first_word, 558 last_word - first_word + 1, eeprom_buff); 559 560 /* Update the checksum if nvm write succeeded */ 561 if (ret_val == 0) 562 hw->nvm.ops.update(hw); 563 564 kfree(eeprom_buff); 565 return ret_val; 566 } 567 568 static void igc_ethtool_get_ringparam(struct net_device *netdev, 569 struct ethtool_ringparam *ring) 570 { 571 struct igc_adapter *adapter = netdev_priv(netdev); 572 573 ring->rx_max_pending = IGC_MAX_RXD; 574 ring->tx_max_pending = IGC_MAX_TXD; 575 ring->rx_pending = adapter->rx_ring_count; 576 ring->tx_pending = adapter->tx_ring_count; 577 } 578 579 static int igc_ethtool_set_ringparam(struct net_device *netdev, 580 struct ethtool_ringparam *ring) 581 { 582 struct igc_adapter *adapter = netdev_priv(netdev); 583 struct igc_ring *temp_ring; 584 u16 new_rx_count, new_tx_count; 585 int i, err = 0; 586 587 if (ring->rx_mini_pending || ring->rx_jumbo_pending) 588 return -EINVAL; 589 590 new_rx_count = min_t(u32, ring->rx_pending, IGC_MAX_RXD); 591 new_rx_count = max_t(u16, new_rx_count, IGC_MIN_RXD); 592 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE); 593 594 new_tx_count = min_t(u32, ring->tx_pending, IGC_MAX_TXD); 595 new_tx_count = max_t(u16, new_tx_count, IGC_MIN_TXD); 596 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE); 597 598 if (new_tx_count == adapter->tx_ring_count && 599 new_rx_count == adapter->rx_ring_count) { 600 /* nothing to do */ 601 return 0; 602 } 603 604 while (test_and_set_bit(__IGC_RESETTING, &adapter->state)) 605 usleep_range(1000, 2000); 606 607 if (!netif_running(adapter->netdev)) { 608 for (i = 0; i < adapter->num_tx_queues; i++) 609 adapter->tx_ring[i]->count = new_tx_count; 610 for (i = 0; i < adapter->num_rx_queues; i++) 611 adapter->rx_ring[i]->count = new_rx_count; 612 adapter->tx_ring_count = new_tx_count; 613 adapter->rx_ring_count = new_rx_count; 614 goto clear_reset; 615 } 616 617 if (adapter->num_tx_queues > adapter->num_rx_queues) 618 temp_ring = vmalloc(array_size(sizeof(struct igc_ring), 619 adapter->num_tx_queues)); 620 else 621 temp_ring = vmalloc(array_size(sizeof(struct igc_ring), 622 adapter->num_rx_queues)); 623 624 if (!temp_ring) { 625 err = -ENOMEM; 626 goto clear_reset; 627 } 628 629 igc_down(adapter); 630 631 /* We can't just free everything and then setup again, 632 * because the ISRs in MSI-X mode get passed pointers 633 * to the Tx and Rx ring structs. 634 */ 635 if (new_tx_count != adapter->tx_ring_count) { 636 for (i = 0; i < adapter->num_tx_queues; i++) { 637 memcpy(&temp_ring[i], adapter->tx_ring[i], 638 sizeof(struct igc_ring)); 639 640 temp_ring[i].count = new_tx_count; 641 err = igc_setup_tx_resources(&temp_ring[i]); 642 if (err) { 643 while (i) { 644 i--; 645 igc_free_tx_resources(&temp_ring[i]); 646 } 647 goto err_setup; 648 } 649 } 650 651 for (i = 0; i < adapter->num_tx_queues; i++) { 652 igc_free_tx_resources(adapter->tx_ring[i]); 653 654 memcpy(adapter->tx_ring[i], &temp_ring[i], 655 sizeof(struct igc_ring)); 656 } 657 658 adapter->tx_ring_count = new_tx_count; 659 } 660 661 if (new_rx_count != adapter->rx_ring_count) { 662 for (i = 0; i < adapter->num_rx_queues; i++) { 663 memcpy(&temp_ring[i], adapter->rx_ring[i], 664 sizeof(struct igc_ring)); 665 666 temp_ring[i].count = new_rx_count; 667 err = igc_setup_rx_resources(&temp_ring[i]); 668 if (err) { 669 while (i) { 670 i--; 671 igc_free_rx_resources(&temp_ring[i]); 672 } 673 goto err_setup; 674 } 675 } 676 677 for (i = 0; i < adapter->num_rx_queues; i++) { 678 igc_free_rx_resources(adapter->rx_ring[i]); 679 680 memcpy(adapter->rx_ring[i], &temp_ring[i], 681 sizeof(struct igc_ring)); 682 } 683 684 adapter->rx_ring_count = new_rx_count; 685 } 686 err_setup: 687 igc_up(adapter); 688 vfree(temp_ring); 689 clear_reset: 690 clear_bit(__IGC_RESETTING, &adapter->state); 691 return err; 692 } 693 694 static void igc_ethtool_get_pauseparam(struct net_device *netdev, 695 struct ethtool_pauseparam *pause) 696 { 697 struct igc_adapter *adapter = netdev_priv(netdev); 698 struct igc_hw *hw = &adapter->hw; 699 700 pause->autoneg = 701 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); 702 703 if (hw->fc.current_mode == igc_fc_rx_pause) { 704 pause->rx_pause = 1; 705 } else if (hw->fc.current_mode == igc_fc_tx_pause) { 706 pause->tx_pause = 1; 707 } else if (hw->fc.current_mode == igc_fc_full) { 708 pause->rx_pause = 1; 709 pause->tx_pause = 1; 710 } 711 } 712 713 static int igc_ethtool_set_pauseparam(struct net_device *netdev, 714 struct ethtool_pauseparam *pause) 715 { 716 struct igc_adapter *adapter = netdev_priv(netdev); 717 struct igc_hw *hw = &adapter->hw; 718 int retval = 0; 719 720 adapter->fc_autoneg = pause->autoneg; 721 722 while (test_and_set_bit(__IGC_RESETTING, &adapter->state)) 723 usleep_range(1000, 2000); 724 725 if (adapter->fc_autoneg == AUTONEG_ENABLE) { 726 hw->fc.requested_mode = igc_fc_default; 727 if (netif_running(adapter->netdev)) { 728 igc_down(adapter); 729 igc_up(adapter); 730 } else { 731 igc_reset(adapter); 732 } 733 } else { 734 if (pause->rx_pause && pause->tx_pause) 735 hw->fc.requested_mode = igc_fc_full; 736 else if (pause->rx_pause && !pause->tx_pause) 737 hw->fc.requested_mode = igc_fc_rx_pause; 738 else if (!pause->rx_pause && pause->tx_pause) 739 hw->fc.requested_mode = igc_fc_tx_pause; 740 else if (!pause->rx_pause && !pause->tx_pause) 741 hw->fc.requested_mode = igc_fc_none; 742 743 hw->fc.current_mode = hw->fc.requested_mode; 744 745 retval = ((hw->phy.media_type == igc_media_type_copper) ? 746 igc_force_mac_fc(hw) : igc_setup_link(hw)); 747 } 748 749 clear_bit(__IGC_RESETTING, &adapter->state); 750 return retval; 751 } 752 753 static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset, 754 u8 *data) 755 { 756 struct igc_adapter *adapter = netdev_priv(netdev); 757 u8 *p = data; 758 int i; 759 760 switch (stringset) { 761 case ETH_SS_TEST: 762 memcpy(data, *igc_gstrings_test, 763 IGC_TEST_LEN * ETH_GSTRING_LEN); 764 break; 765 case ETH_SS_STATS: 766 for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++) { 767 memcpy(p, igc_gstrings_stats[i].stat_string, 768 ETH_GSTRING_LEN); 769 p += ETH_GSTRING_LEN; 770 } 771 for (i = 0; i < IGC_NETDEV_STATS_LEN; i++) { 772 memcpy(p, igc_gstrings_net_stats[i].stat_string, 773 ETH_GSTRING_LEN); 774 p += ETH_GSTRING_LEN; 775 } 776 for (i = 0; i < adapter->num_tx_queues; i++) { 777 sprintf(p, "tx_queue_%u_packets", i); 778 p += ETH_GSTRING_LEN; 779 sprintf(p, "tx_queue_%u_bytes", i); 780 p += ETH_GSTRING_LEN; 781 sprintf(p, "tx_queue_%u_restart", i); 782 p += ETH_GSTRING_LEN; 783 } 784 for (i = 0; i < adapter->num_rx_queues; i++) { 785 sprintf(p, "rx_queue_%u_packets", i); 786 p += ETH_GSTRING_LEN; 787 sprintf(p, "rx_queue_%u_bytes", i); 788 p += ETH_GSTRING_LEN; 789 sprintf(p, "rx_queue_%u_drops", i); 790 p += ETH_GSTRING_LEN; 791 sprintf(p, "rx_queue_%u_csum_err", i); 792 p += ETH_GSTRING_LEN; 793 sprintf(p, "rx_queue_%u_alloc_failed", i); 794 p += ETH_GSTRING_LEN; 795 } 796 /* BUG_ON(p - data != IGC_STATS_LEN * ETH_GSTRING_LEN); */ 797 break; 798 case ETH_SS_PRIV_FLAGS: 799 memcpy(data, igc_priv_flags_strings, 800 IGC_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN); 801 break; 802 } 803 } 804 805 static int igc_ethtool_get_sset_count(struct net_device *netdev, int sset) 806 { 807 switch (sset) { 808 case ETH_SS_STATS: 809 return IGC_STATS_LEN; 810 case ETH_SS_TEST: 811 return IGC_TEST_LEN; 812 case ETH_SS_PRIV_FLAGS: 813 return IGC_PRIV_FLAGS_STR_LEN; 814 default: 815 return -ENOTSUPP; 816 } 817 } 818 819 static void igc_ethtool_get_stats(struct net_device *netdev, 820 struct ethtool_stats *stats, u64 *data) 821 { 822 struct igc_adapter *adapter = netdev_priv(netdev); 823 struct rtnl_link_stats64 *net_stats = &adapter->stats64; 824 unsigned int start; 825 struct igc_ring *ring; 826 int i, j; 827 char *p; 828 829 spin_lock(&adapter->stats64_lock); 830 igc_update_stats(adapter); 831 832 for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++) { 833 p = (char *)adapter + igc_gstrings_stats[i].stat_offset; 834 data[i] = (igc_gstrings_stats[i].sizeof_stat == 835 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 836 } 837 for (j = 0; j < IGC_NETDEV_STATS_LEN; j++, i++) { 838 p = (char *)net_stats + igc_gstrings_net_stats[j].stat_offset; 839 data[i] = (igc_gstrings_net_stats[j].sizeof_stat == 840 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 841 } 842 for (j = 0; j < adapter->num_tx_queues; j++) { 843 u64 restart2; 844 845 ring = adapter->tx_ring[j]; 846 do { 847 start = u64_stats_fetch_begin_irq(&ring->tx_syncp); 848 data[i] = ring->tx_stats.packets; 849 data[i + 1] = ring->tx_stats.bytes; 850 data[i + 2] = ring->tx_stats.restart_queue; 851 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp, start)); 852 do { 853 start = u64_stats_fetch_begin_irq(&ring->tx_syncp2); 854 restart2 = ring->tx_stats.restart_queue2; 855 } while (u64_stats_fetch_retry_irq(&ring->tx_syncp2, start)); 856 data[i + 2] += restart2; 857 858 i += IGC_TX_QUEUE_STATS_LEN; 859 } 860 for (j = 0; j < adapter->num_rx_queues; j++) { 861 ring = adapter->rx_ring[j]; 862 do { 863 start = u64_stats_fetch_begin_irq(&ring->rx_syncp); 864 data[i] = ring->rx_stats.packets; 865 data[i + 1] = ring->rx_stats.bytes; 866 data[i + 2] = ring->rx_stats.drops; 867 data[i + 3] = ring->rx_stats.csum_err; 868 data[i + 4] = ring->rx_stats.alloc_failed; 869 } while (u64_stats_fetch_retry_irq(&ring->rx_syncp, start)); 870 i += IGC_RX_QUEUE_STATS_LEN; 871 } 872 spin_unlock(&adapter->stats64_lock); 873 } 874 875 static int igc_ethtool_get_coalesce(struct net_device *netdev, 876 struct ethtool_coalesce *ec) 877 { 878 struct igc_adapter *adapter = netdev_priv(netdev); 879 880 if (adapter->rx_itr_setting <= 3) 881 ec->rx_coalesce_usecs = adapter->rx_itr_setting; 882 else 883 ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2; 884 885 if (!(adapter->flags & IGC_FLAG_QUEUE_PAIRS)) { 886 if (adapter->tx_itr_setting <= 3) 887 ec->tx_coalesce_usecs = adapter->tx_itr_setting; 888 else 889 ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2; 890 } 891 892 return 0; 893 } 894 895 static int igc_ethtool_set_coalesce(struct net_device *netdev, 896 struct ethtool_coalesce *ec) 897 { 898 struct igc_adapter *adapter = netdev_priv(netdev); 899 int i; 900 901 if (ec->rx_coalesce_usecs > IGC_MAX_ITR_USECS || 902 (ec->rx_coalesce_usecs > 3 && 903 ec->rx_coalesce_usecs < IGC_MIN_ITR_USECS) || 904 ec->rx_coalesce_usecs == 2) 905 return -EINVAL; 906 907 if (ec->tx_coalesce_usecs > IGC_MAX_ITR_USECS || 908 (ec->tx_coalesce_usecs > 3 && 909 ec->tx_coalesce_usecs < IGC_MIN_ITR_USECS) || 910 ec->tx_coalesce_usecs == 2) 911 return -EINVAL; 912 913 if ((adapter->flags & IGC_FLAG_QUEUE_PAIRS) && ec->tx_coalesce_usecs) 914 return -EINVAL; 915 916 /* If ITR is disabled, disable DMAC */ 917 if (ec->rx_coalesce_usecs == 0) { 918 if (adapter->flags & IGC_FLAG_DMAC) 919 adapter->flags &= ~IGC_FLAG_DMAC; 920 } 921 922 /* convert to rate of irq's per second */ 923 if (ec->rx_coalesce_usecs && ec->rx_coalesce_usecs <= 3) 924 adapter->rx_itr_setting = ec->rx_coalesce_usecs; 925 else 926 adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2; 927 928 /* convert to rate of irq's per second */ 929 if (adapter->flags & IGC_FLAG_QUEUE_PAIRS) 930 adapter->tx_itr_setting = adapter->rx_itr_setting; 931 else if (ec->tx_coalesce_usecs && ec->tx_coalesce_usecs <= 3) 932 adapter->tx_itr_setting = ec->tx_coalesce_usecs; 933 else 934 adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2; 935 936 for (i = 0; i < adapter->num_q_vectors; i++) { 937 struct igc_q_vector *q_vector = adapter->q_vector[i]; 938 939 q_vector->tx.work_limit = adapter->tx_work_limit; 940 if (q_vector->rx.ring) 941 q_vector->itr_val = adapter->rx_itr_setting; 942 else 943 q_vector->itr_val = adapter->tx_itr_setting; 944 if (q_vector->itr_val && q_vector->itr_val <= 3) 945 q_vector->itr_val = IGC_START_ITR; 946 q_vector->set_itr = 1; 947 } 948 949 return 0; 950 } 951 952 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0) 953 static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter, 954 struct ethtool_rxnfc *cmd) 955 { 956 struct ethtool_rx_flow_spec *fsp = &cmd->fs; 957 struct igc_nfc_rule *rule = NULL; 958 959 cmd->data = IGC_MAX_RXNFC_RULES; 960 961 mutex_lock(&adapter->nfc_rule_lock); 962 963 rule = igc_get_nfc_rule(adapter, fsp->location); 964 if (!rule) 965 goto out; 966 967 fsp->flow_type = ETHER_FLOW; 968 fsp->ring_cookie = rule->action; 969 970 if (rule->filter.match_flags & IGC_FILTER_FLAG_ETHER_TYPE) { 971 fsp->h_u.ether_spec.h_proto = htons(rule->filter.etype); 972 fsp->m_u.ether_spec.h_proto = ETHER_TYPE_FULL_MASK; 973 } 974 975 if (rule->filter.match_flags & IGC_FILTER_FLAG_VLAN_TCI) { 976 fsp->flow_type |= FLOW_EXT; 977 fsp->h_ext.vlan_tci = htons(rule->filter.vlan_tci); 978 fsp->m_ext.vlan_tci = htons(VLAN_PRIO_MASK); 979 } 980 981 if (rule->filter.match_flags & IGC_FILTER_FLAG_DST_MAC_ADDR) { 982 ether_addr_copy(fsp->h_u.ether_spec.h_dest, 983 rule->filter.dst_addr); 984 eth_broadcast_addr(fsp->m_u.ether_spec.h_dest); 985 } 986 987 if (rule->filter.match_flags & IGC_FILTER_FLAG_SRC_MAC_ADDR) { 988 ether_addr_copy(fsp->h_u.ether_spec.h_source, 989 rule->filter.src_addr); 990 eth_broadcast_addr(fsp->m_u.ether_spec.h_source); 991 } 992 993 mutex_unlock(&adapter->nfc_rule_lock); 994 return 0; 995 996 out: 997 mutex_unlock(&adapter->nfc_rule_lock); 998 return -EINVAL; 999 } 1000 1001 static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter, 1002 struct ethtool_rxnfc *cmd, 1003 u32 *rule_locs) 1004 { 1005 struct igc_nfc_rule *rule; 1006 int cnt = 0; 1007 1008 cmd->data = IGC_MAX_RXNFC_RULES; 1009 1010 mutex_lock(&adapter->nfc_rule_lock); 1011 1012 list_for_each_entry(rule, &adapter->nfc_rule_list, list) { 1013 if (cnt == cmd->rule_cnt) { 1014 mutex_unlock(&adapter->nfc_rule_lock); 1015 return -EMSGSIZE; 1016 } 1017 rule_locs[cnt] = rule->location; 1018 cnt++; 1019 } 1020 1021 mutex_unlock(&adapter->nfc_rule_lock); 1022 1023 cmd->rule_cnt = cnt; 1024 1025 return 0; 1026 } 1027 1028 static int igc_ethtool_get_rss_hash_opts(struct igc_adapter *adapter, 1029 struct ethtool_rxnfc *cmd) 1030 { 1031 cmd->data = 0; 1032 1033 /* Report default options for RSS on igc */ 1034 switch (cmd->flow_type) { 1035 case TCP_V4_FLOW: 1036 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1037 fallthrough; 1038 case UDP_V4_FLOW: 1039 if (adapter->flags & IGC_FLAG_RSS_FIELD_IPV4_UDP) 1040 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1041 fallthrough; 1042 case SCTP_V4_FLOW: 1043 case AH_ESP_V4_FLOW: 1044 case AH_V4_FLOW: 1045 case ESP_V4_FLOW: 1046 case IPV4_FLOW: 1047 cmd->data |= RXH_IP_SRC | RXH_IP_DST; 1048 break; 1049 case TCP_V6_FLOW: 1050 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1051 fallthrough; 1052 case UDP_V6_FLOW: 1053 if (adapter->flags & IGC_FLAG_RSS_FIELD_IPV6_UDP) 1054 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 1055 fallthrough; 1056 case SCTP_V6_FLOW: 1057 case AH_ESP_V6_FLOW: 1058 case AH_V6_FLOW: 1059 case ESP_V6_FLOW: 1060 case IPV6_FLOW: 1061 cmd->data |= RXH_IP_SRC | RXH_IP_DST; 1062 break; 1063 default: 1064 return -EINVAL; 1065 } 1066 1067 return 0; 1068 } 1069 1070 static int igc_ethtool_get_rxnfc(struct net_device *dev, 1071 struct ethtool_rxnfc *cmd, u32 *rule_locs) 1072 { 1073 struct igc_adapter *adapter = netdev_priv(dev); 1074 1075 switch (cmd->cmd) { 1076 case ETHTOOL_GRXRINGS: 1077 cmd->data = adapter->num_rx_queues; 1078 return 0; 1079 case ETHTOOL_GRXCLSRLCNT: 1080 cmd->rule_cnt = adapter->nfc_rule_count; 1081 return 0; 1082 case ETHTOOL_GRXCLSRULE: 1083 return igc_ethtool_get_nfc_rule(adapter, cmd); 1084 case ETHTOOL_GRXCLSRLALL: 1085 return igc_ethtool_get_nfc_rules(adapter, cmd, rule_locs); 1086 case ETHTOOL_GRXFH: 1087 return igc_ethtool_get_rss_hash_opts(adapter, cmd); 1088 default: 1089 return -EOPNOTSUPP; 1090 } 1091 } 1092 1093 #define UDP_RSS_FLAGS (IGC_FLAG_RSS_FIELD_IPV4_UDP | \ 1094 IGC_FLAG_RSS_FIELD_IPV6_UDP) 1095 static int igc_ethtool_set_rss_hash_opt(struct igc_adapter *adapter, 1096 struct ethtool_rxnfc *nfc) 1097 { 1098 u32 flags = adapter->flags; 1099 1100 /* RSS does not support anything other than hashing 1101 * to queues on src and dst IPs and ports 1102 */ 1103 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | 1104 RXH_L4_B_0_1 | RXH_L4_B_2_3)) 1105 return -EINVAL; 1106 1107 switch (nfc->flow_type) { 1108 case TCP_V4_FLOW: 1109 case TCP_V6_FLOW: 1110 if (!(nfc->data & RXH_IP_SRC) || 1111 !(nfc->data & RXH_IP_DST) || 1112 !(nfc->data & RXH_L4_B_0_1) || 1113 !(nfc->data & RXH_L4_B_2_3)) 1114 return -EINVAL; 1115 break; 1116 case UDP_V4_FLOW: 1117 if (!(nfc->data & RXH_IP_SRC) || 1118 !(nfc->data & RXH_IP_DST)) 1119 return -EINVAL; 1120 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 1121 case 0: 1122 flags &= ~IGC_FLAG_RSS_FIELD_IPV4_UDP; 1123 break; 1124 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 1125 flags |= IGC_FLAG_RSS_FIELD_IPV4_UDP; 1126 break; 1127 default: 1128 return -EINVAL; 1129 } 1130 break; 1131 case UDP_V6_FLOW: 1132 if (!(nfc->data & RXH_IP_SRC) || 1133 !(nfc->data & RXH_IP_DST)) 1134 return -EINVAL; 1135 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 1136 case 0: 1137 flags &= ~IGC_FLAG_RSS_FIELD_IPV6_UDP; 1138 break; 1139 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 1140 flags |= IGC_FLAG_RSS_FIELD_IPV6_UDP; 1141 break; 1142 default: 1143 return -EINVAL; 1144 } 1145 break; 1146 case AH_ESP_V4_FLOW: 1147 case AH_V4_FLOW: 1148 case ESP_V4_FLOW: 1149 case SCTP_V4_FLOW: 1150 case AH_ESP_V6_FLOW: 1151 case AH_V6_FLOW: 1152 case ESP_V6_FLOW: 1153 case SCTP_V6_FLOW: 1154 if (!(nfc->data & RXH_IP_SRC) || 1155 !(nfc->data & RXH_IP_DST) || 1156 (nfc->data & RXH_L4_B_0_1) || 1157 (nfc->data & RXH_L4_B_2_3)) 1158 return -EINVAL; 1159 break; 1160 default: 1161 return -EINVAL; 1162 } 1163 1164 /* if we changed something we need to update flags */ 1165 if (flags != adapter->flags) { 1166 struct igc_hw *hw = &adapter->hw; 1167 u32 mrqc = rd32(IGC_MRQC); 1168 1169 if ((flags & UDP_RSS_FLAGS) && 1170 !(adapter->flags & UDP_RSS_FLAGS)) 1171 netdev_err(adapter->netdev, 1172 "Enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n"); 1173 1174 adapter->flags = flags; 1175 1176 /* Perform hash on these packet types */ 1177 mrqc |= IGC_MRQC_RSS_FIELD_IPV4 | 1178 IGC_MRQC_RSS_FIELD_IPV4_TCP | 1179 IGC_MRQC_RSS_FIELD_IPV6 | 1180 IGC_MRQC_RSS_FIELD_IPV6_TCP; 1181 1182 mrqc &= ~(IGC_MRQC_RSS_FIELD_IPV4_UDP | 1183 IGC_MRQC_RSS_FIELD_IPV6_UDP); 1184 1185 if (flags & IGC_FLAG_RSS_FIELD_IPV4_UDP) 1186 mrqc |= IGC_MRQC_RSS_FIELD_IPV4_UDP; 1187 1188 if (flags & IGC_FLAG_RSS_FIELD_IPV6_UDP) 1189 mrqc |= IGC_MRQC_RSS_FIELD_IPV6_UDP; 1190 1191 wr32(IGC_MRQC, mrqc); 1192 } 1193 1194 return 0; 1195 } 1196 1197 static void igc_ethtool_init_nfc_rule(struct igc_nfc_rule *rule, 1198 const struct ethtool_rx_flow_spec *fsp) 1199 { 1200 INIT_LIST_HEAD(&rule->list); 1201 1202 rule->action = fsp->ring_cookie; 1203 rule->location = fsp->location; 1204 1205 if ((fsp->flow_type & FLOW_EXT) && fsp->m_ext.vlan_tci) { 1206 rule->filter.vlan_tci = ntohs(fsp->h_ext.vlan_tci); 1207 rule->filter.match_flags |= IGC_FILTER_FLAG_VLAN_TCI; 1208 } 1209 1210 if (fsp->m_u.ether_spec.h_proto == ETHER_TYPE_FULL_MASK) { 1211 rule->filter.etype = ntohs(fsp->h_u.ether_spec.h_proto); 1212 rule->filter.match_flags = IGC_FILTER_FLAG_ETHER_TYPE; 1213 } 1214 1215 /* Both source and destination address filters only support the full 1216 * mask. 1217 */ 1218 if (is_broadcast_ether_addr(fsp->m_u.ether_spec.h_source)) { 1219 rule->filter.match_flags |= IGC_FILTER_FLAG_SRC_MAC_ADDR; 1220 ether_addr_copy(rule->filter.src_addr, 1221 fsp->h_u.ether_spec.h_source); 1222 } 1223 1224 if (is_broadcast_ether_addr(fsp->m_u.ether_spec.h_dest)) { 1225 rule->filter.match_flags |= IGC_FILTER_FLAG_DST_MAC_ADDR; 1226 ether_addr_copy(rule->filter.dst_addr, 1227 fsp->h_u.ether_spec.h_dest); 1228 } 1229 } 1230 1231 /** 1232 * igc_ethtool_check_nfc_rule() - Check if NFC rule is valid 1233 * @adapter: Pointer to adapter 1234 * @rule: Rule under evaluation 1235 * 1236 * The driver doesn't support rules with multiple matches so if more than 1237 * one bit in filter flags is set, @rule is considered invalid. 1238 * 1239 * Also, if there is already another rule with the same filter in a different 1240 * location, @rule is considered invalid. 1241 * 1242 * Context: Expects adapter->nfc_rule_lock to be held by caller. 1243 * 1244 * Return: 0 in case of success, negative errno code otherwise. 1245 */ 1246 static int igc_ethtool_check_nfc_rule(struct igc_adapter *adapter, 1247 struct igc_nfc_rule *rule) 1248 { 1249 struct net_device *dev = adapter->netdev; 1250 u8 flags = rule->filter.match_flags; 1251 struct igc_nfc_rule *tmp; 1252 1253 if (!flags) { 1254 netdev_dbg(dev, "Rule with no match\n"); 1255 return -EINVAL; 1256 } 1257 1258 if (flags & (flags - 1)) { 1259 netdev_dbg(dev, "Rule with multiple matches not supported\n"); 1260 return -EOPNOTSUPP; 1261 } 1262 1263 list_for_each_entry(tmp, &adapter->nfc_rule_list, list) { 1264 if (!memcmp(&rule->filter, &tmp->filter, 1265 sizeof(rule->filter)) && 1266 tmp->location != rule->location) { 1267 netdev_dbg(dev, "Rule already exists\n"); 1268 return -EEXIST; 1269 } 1270 } 1271 1272 return 0; 1273 } 1274 1275 static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter, 1276 struct ethtool_rxnfc *cmd) 1277 { 1278 struct net_device *netdev = adapter->netdev; 1279 struct ethtool_rx_flow_spec *fsp = 1280 (struct ethtool_rx_flow_spec *)&cmd->fs; 1281 struct igc_nfc_rule *rule, *old_rule; 1282 int err; 1283 1284 if (!(netdev->hw_features & NETIF_F_NTUPLE)) { 1285 netdev_dbg(netdev, "N-tuple filters disabled\n"); 1286 return -EOPNOTSUPP; 1287 } 1288 1289 if ((fsp->flow_type & ~FLOW_EXT) != ETHER_FLOW) { 1290 netdev_dbg(netdev, "Only ethernet flow type is supported\n"); 1291 return -EOPNOTSUPP; 1292 } 1293 1294 if ((fsp->flow_type & FLOW_EXT) && 1295 fsp->m_ext.vlan_tci != htons(VLAN_PRIO_MASK)) { 1296 netdev_dbg(netdev, "VLAN mask not supported\n"); 1297 return -EOPNOTSUPP; 1298 } 1299 1300 if (fsp->ring_cookie >= adapter->num_rx_queues) { 1301 netdev_dbg(netdev, "Invalid action\n"); 1302 return -EINVAL; 1303 } 1304 1305 if (fsp->location >= IGC_MAX_RXNFC_RULES) { 1306 netdev_dbg(netdev, "Invalid location\n"); 1307 return -EINVAL; 1308 } 1309 1310 rule = kzalloc(sizeof(*rule), GFP_KERNEL); 1311 if (!rule) 1312 return -ENOMEM; 1313 1314 igc_ethtool_init_nfc_rule(rule, fsp); 1315 1316 mutex_lock(&adapter->nfc_rule_lock); 1317 1318 err = igc_ethtool_check_nfc_rule(adapter, rule); 1319 if (err) 1320 goto err; 1321 1322 old_rule = igc_get_nfc_rule(adapter, fsp->location); 1323 if (old_rule) 1324 igc_del_nfc_rule(adapter, old_rule); 1325 1326 err = igc_add_nfc_rule(adapter, rule); 1327 if (err) 1328 goto err; 1329 1330 mutex_unlock(&adapter->nfc_rule_lock); 1331 return 0; 1332 1333 err: 1334 mutex_unlock(&adapter->nfc_rule_lock); 1335 kfree(rule); 1336 return err; 1337 } 1338 1339 static int igc_ethtool_del_nfc_rule(struct igc_adapter *adapter, 1340 struct ethtool_rxnfc *cmd) 1341 { 1342 struct ethtool_rx_flow_spec *fsp = 1343 (struct ethtool_rx_flow_spec *)&cmd->fs; 1344 struct igc_nfc_rule *rule; 1345 1346 mutex_lock(&adapter->nfc_rule_lock); 1347 1348 rule = igc_get_nfc_rule(adapter, fsp->location); 1349 if (!rule) { 1350 mutex_unlock(&adapter->nfc_rule_lock); 1351 return -EINVAL; 1352 } 1353 1354 igc_del_nfc_rule(adapter, rule); 1355 1356 mutex_unlock(&adapter->nfc_rule_lock); 1357 return 0; 1358 } 1359 1360 static int igc_ethtool_set_rxnfc(struct net_device *dev, 1361 struct ethtool_rxnfc *cmd) 1362 { 1363 struct igc_adapter *adapter = netdev_priv(dev); 1364 1365 switch (cmd->cmd) { 1366 case ETHTOOL_SRXFH: 1367 return igc_ethtool_set_rss_hash_opt(adapter, cmd); 1368 case ETHTOOL_SRXCLSRLINS: 1369 return igc_ethtool_add_nfc_rule(adapter, cmd); 1370 case ETHTOOL_SRXCLSRLDEL: 1371 return igc_ethtool_del_nfc_rule(adapter, cmd); 1372 default: 1373 return -EOPNOTSUPP; 1374 } 1375 } 1376 1377 void igc_write_rss_indir_tbl(struct igc_adapter *adapter) 1378 { 1379 struct igc_hw *hw = &adapter->hw; 1380 u32 reg = IGC_RETA(0); 1381 u32 shift = 0; 1382 int i = 0; 1383 1384 while (i < IGC_RETA_SIZE) { 1385 u32 val = 0; 1386 int j; 1387 1388 for (j = 3; j >= 0; j--) { 1389 val <<= 8; 1390 val |= adapter->rss_indir_tbl[i + j]; 1391 } 1392 1393 wr32(reg, val << shift); 1394 reg += 4; 1395 i += 4; 1396 } 1397 } 1398 1399 static u32 igc_ethtool_get_rxfh_indir_size(struct net_device *netdev) 1400 { 1401 return IGC_RETA_SIZE; 1402 } 1403 1404 static int igc_ethtool_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, 1405 u8 *hfunc) 1406 { 1407 struct igc_adapter *adapter = netdev_priv(netdev); 1408 int i; 1409 1410 if (hfunc) 1411 *hfunc = ETH_RSS_HASH_TOP; 1412 if (!indir) 1413 return 0; 1414 for (i = 0; i < IGC_RETA_SIZE; i++) 1415 indir[i] = adapter->rss_indir_tbl[i]; 1416 1417 return 0; 1418 } 1419 1420 static int igc_ethtool_set_rxfh(struct net_device *netdev, const u32 *indir, 1421 const u8 *key, const u8 hfunc) 1422 { 1423 struct igc_adapter *adapter = netdev_priv(netdev); 1424 u32 num_queues; 1425 int i; 1426 1427 /* We do not allow change in unsupported parameters */ 1428 if (key || 1429 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)) 1430 return -EOPNOTSUPP; 1431 if (!indir) 1432 return 0; 1433 1434 num_queues = adapter->rss_queues; 1435 1436 /* Verify user input. */ 1437 for (i = 0; i < IGC_RETA_SIZE; i++) 1438 if (indir[i] >= num_queues) 1439 return -EINVAL; 1440 1441 for (i = 0; i < IGC_RETA_SIZE; i++) 1442 adapter->rss_indir_tbl[i] = indir[i]; 1443 1444 igc_write_rss_indir_tbl(adapter); 1445 1446 return 0; 1447 } 1448 1449 static void igc_ethtool_get_channels(struct net_device *netdev, 1450 struct ethtool_channels *ch) 1451 { 1452 struct igc_adapter *adapter = netdev_priv(netdev); 1453 1454 /* Report maximum channels */ 1455 ch->max_combined = igc_get_max_rss_queues(adapter); 1456 1457 /* Report info for other vector */ 1458 if (adapter->flags & IGC_FLAG_HAS_MSIX) { 1459 ch->max_other = NON_Q_VECTORS; 1460 ch->other_count = NON_Q_VECTORS; 1461 } 1462 1463 ch->combined_count = adapter->rss_queues; 1464 } 1465 1466 static int igc_ethtool_set_channels(struct net_device *netdev, 1467 struct ethtool_channels *ch) 1468 { 1469 struct igc_adapter *adapter = netdev_priv(netdev); 1470 unsigned int count = ch->combined_count; 1471 unsigned int max_combined = 0; 1472 1473 /* Verify they are not requesting separate vectors */ 1474 if (!count || ch->rx_count || ch->tx_count) 1475 return -EINVAL; 1476 1477 /* Verify other_count is valid and has not been changed */ 1478 if (ch->other_count != NON_Q_VECTORS) 1479 return -EINVAL; 1480 1481 /* Verify the number of channels doesn't exceed hw limits */ 1482 max_combined = igc_get_max_rss_queues(adapter); 1483 if (count > max_combined) 1484 return -EINVAL; 1485 1486 if (count != adapter->rss_queues) { 1487 adapter->rss_queues = count; 1488 igc_set_flag_queue_pairs(adapter, max_combined); 1489 1490 /* Hardware has to reinitialize queues and interrupts to 1491 * match the new configuration. 1492 */ 1493 return igc_reinit_queues(adapter); 1494 } 1495 1496 return 0; 1497 } 1498 1499 static int igc_ethtool_get_ts_info(struct net_device *dev, 1500 struct ethtool_ts_info *info) 1501 { 1502 struct igc_adapter *adapter = netdev_priv(dev); 1503 1504 if (adapter->ptp_clock) 1505 info->phc_index = ptp_clock_index(adapter->ptp_clock); 1506 else 1507 info->phc_index = -1; 1508 1509 switch (adapter->hw.mac.type) { 1510 case igc_i225: 1511 info->so_timestamping = 1512 SOF_TIMESTAMPING_TX_SOFTWARE | 1513 SOF_TIMESTAMPING_RX_SOFTWARE | 1514 SOF_TIMESTAMPING_SOFTWARE | 1515 SOF_TIMESTAMPING_TX_HARDWARE | 1516 SOF_TIMESTAMPING_RX_HARDWARE | 1517 SOF_TIMESTAMPING_RAW_HARDWARE; 1518 1519 info->tx_types = 1520 BIT(HWTSTAMP_TX_OFF) | 1521 BIT(HWTSTAMP_TX_ON); 1522 1523 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE); 1524 info->rx_filters |= BIT(HWTSTAMP_FILTER_ALL); 1525 1526 return 0; 1527 default: 1528 return -EOPNOTSUPP; 1529 } 1530 } 1531 1532 static u32 igc_ethtool_get_priv_flags(struct net_device *netdev) 1533 { 1534 struct igc_adapter *adapter = netdev_priv(netdev); 1535 u32 priv_flags = 0; 1536 1537 if (adapter->flags & IGC_FLAG_RX_LEGACY) 1538 priv_flags |= IGC_PRIV_FLAGS_LEGACY_RX; 1539 1540 return priv_flags; 1541 } 1542 1543 static int igc_ethtool_set_priv_flags(struct net_device *netdev, u32 priv_flags) 1544 { 1545 struct igc_adapter *adapter = netdev_priv(netdev); 1546 unsigned int flags = adapter->flags; 1547 1548 flags &= ~IGC_FLAG_RX_LEGACY; 1549 if (priv_flags & IGC_PRIV_FLAGS_LEGACY_RX) 1550 flags |= IGC_FLAG_RX_LEGACY; 1551 1552 if (flags != adapter->flags) { 1553 adapter->flags = flags; 1554 1555 /* reset interface to repopulate queues */ 1556 if (netif_running(netdev)) 1557 igc_reinit_locked(adapter); 1558 } 1559 1560 return 0; 1561 } 1562 1563 static int igc_ethtool_get_eee(struct net_device *netdev, 1564 struct ethtool_eee *edata) 1565 { 1566 struct igc_adapter *adapter = netdev_priv(netdev); 1567 struct igc_hw *hw = &adapter->hw; 1568 u32 eeer; 1569 1570 if (hw->dev_spec._base.eee_enable) 1571 edata->advertised = 1572 mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert); 1573 1574 *edata = adapter->eee; 1575 edata->supported = SUPPORTED_Autoneg; 1576 1577 eeer = rd32(IGC_EEER); 1578 1579 /* EEE status on negotiated link */ 1580 if (eeer & IGC_EEER_EEE_NEG) 1581 edata->eee_active = true; 1582 1583 if (eeer & IGC_EEER_TX_LPI_EN) 1584 edata->tx_lpi_enabled = true; 1585 1586 edata->eee_enabled = hw->dev_spec._base.eee_enable; 1587 1588 edata->advertised = SUPPORTED_Autoneg; 1589 edata->lp_advertised = SUPPORTED_Autoneg; 1590 1591 /* Report correct negotiated EEE status for devices that 1592 * wrongly report EEE at half-duplex 1593 */ 1594 if (adapter->link_duplex == HALF_DUPLEX) { 1595 edata->eee_enabled = false; 1596 edata->eee_active = false; 1597 edata->tx_lpi_enabled = false; 1598 edata->advertised &= ~edata->advertised; 1599 } 1600 1601 return 0; 1602 } 1603 1604 static int igc_ethtool_set_eee(struct net_device *netdev, 1605 struct ethtool_eee *edata) 1606 { 1607 struct igc_adapter *adapter = netdev_priv(netdev); 1608 struct igc_hw *hw = &adapter->hw; 1609 struct ethtool_eee eee_curr; 1610 s32 ret_val; 1611 1612 memset(&eee_curr, 0, sizeof(struct ethtool_eee)); 1613 1614 ret_val = igc_ethtool_get_eee(netdev, &eee_curr); 1615 if (ret_val) { 1616 netdev_err(netdev, 1617 "Problem setting EEE advertisement options\n"); 1618 return -EINVAL; 1619 } 1620 1621 if (eee_curr.eee_enabled) { 1622 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) { 1623 netdev_err(netdev, 1624 "Setting EEE tx-lpi is not supported\n"); 1625 return -EINVAL; 1626 } 1627 1628 /* Tx LPI timer is not implemented currently */ 1629 if (edata->tx_lpi_timer) { 1630 netdev_err(netdev, 1631 "Setting EEE Tx LPI timer is not supported\n"); 1632 return -EINVAL; 1633 } 1634 } else if (!edata->eee_enabled) { 1635 netdev_err(netdev, 1636 "Setting EEE options are not supported with EEE disabled\n"); 1637 return -EINVAL; 1638 } 1639 1640 adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised); 1641 if (hw->dev_spec._base.eee_enable != edata->eee_enabled) { 1642 hw->dev_spec._base.eee_enable = edata->eee_enabled; 1643 adapter->flags |= IGC_FLAG_EEE; 1644 1645 /* reset link */ 1646 if (netif_running(netdev)) 1647 igc_reinit_locked(adapter); 1648 else 1649 igc_reset(adapter); 1650 } 1651 1652 return 0; 1653 } 1654 1655 static int igc_ethtool_begin(struct net_device *netdev) 1656 { 1657 struct igc_adapter *adapter = netdev_priv(netdev); 1658 1659 pm_runtime_get_sync(&adapter->pdev->dev); 1660 return 0; 1661 } 1662 1663 static void igc_ethtool_complete(struct net_device *netdev) 1664 { 1665 struct igc_adapter *adapter = netdev_priv(netdev); 1666 1667 pm_runtime_put(&adapter->pdev->dev); 1668 } 1669 1670 static int igc_ethtool_get_link_ksettings(struct net_device *netdev, 1671 struct ethtool_link_ksettings *cmd) 1672 { 1673 struct igc_adapter *adapter = netdev_priv(netdev); 1674 struct igc_hw *hw = &adapter->hw; 1675 u32 status; 1676 u32 speed; 1677 1678 ethtool_link_ksettings_zero_link_mode(cmd, supported); 1679 ethtool_link_ksettings_zero_link_mode(cmd, advertising); 1680 1681 /* supported link modes */ 1682 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Half); 1683 ethtool_link_ksettings_add_link_mode(cmd, supported, 10baseT_Full); 1684 ethtool_link_ksettings_add_link_mode(cmd, supported, 100baseT_Half); 1685 ethtool_link_ksettings_add_link_mode(cmd, supported, 100baseT_Full); 1686 ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full); 1687 ethtool_link_ksettings_add_link_mode(cmd, supported, 2500baseT_Full); 1688 1689 /* twisted pair */ 1690 cmd->base.port = PORT_TP; 1691 cmd->base.phy_address = hw->phy.addr; 1692 1693 /* advertising link modes */ 1694 if (hw->phy.autoneg_advertised & ADVERTISE_10_HALF) 1695 ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Half); 1696 if (hw->phy.autoneg_advertised & ADVERTISE_10_FULL) 1697 ethtool_link_ksettings_add_link_mode(cmd, advertising, 10baseT_Full); 1698 if (hw->phy.autoneg_advertised & ADVERTISE_100_HALF) 1699 ethtool_link_ksettings_add_link_mode(cmd, advertising, 100baseT_Half); 1700 if (hw->phy.autoneg_advertised & ADVERTISE_100_FULL) 1701 ethtool_link_ksettings_add_link_mode(cmd, advertising, 100baseT_Full); 1702 if (hw->phy.autoneg_advertised & ADVERTISE_1000_FULL) 1703 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full); 1704 if (hw->phy.autoneg_advertised & ADVERTISE_2500_FULL) 1705 ethtool_link_ksettings_add_link_mode(cmd, advertising, 2500baseT_Full); 1706 1707 /* set autoneg settings */ 1708 if (hw->mac.autoneg == 1) { 1709 ethtool_link_ksettings_add_link_mode(cmd, supported, Autoneg); 1710 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1711 Autoneg); 1712 } 1713 1714 /* Set pause flow control settings */ 1715 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause); 1716 1717 switch (hw->fc.requested_mode) { 1718 case igc_fc_full: 1719 ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause); 1720 break; 1721 case igc_fc_rx_pause: 1722 ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause); 1723 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1724 Asym_Pause); 1725 break; 1726 case igc_fc_tx_pause: 1727 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1728 Asym_Pause); 1729 break; 1730 default: 1731 break; 1732 } 1733 1734 status = pm_runtime_suspended(&adapter->pdev->dev) ? 1735 0 : rd32(IGC_STATUS); 1736 1737 if (status & IGC_STATUS_LU) { 1738 if (status & IGC_STATUS_SPEED_1000) { 1739 /* For I225, STATUS will indicate 1G speed in both 1740 * 1 Gbps and 2.5 Gbps link modes. 1741 * An additional bit is used 1742 * to differentiate between 1 Gbps and 2.5 Gbps. 1743 */ 1744 if (hw->mac.type == igc_i225 && 1745 (status & IGC_STATUS_SPEED_2500)) { 1746 speed = SPEED_2500; 1747 } else { 1748 speed = SPEED_1000; 1749 } 1750 } else if (status & IGC_STATUS_SPEED_100) { 1751 speed = SPEED_100; 1752 } else { 1753 speed = SPEED_10; 1754 } 1755 if ((status & IGC_STATUS_FD) || 1756 hw->phy.media_type != igc_media_type_copper) 1757 cmd->base.duplex = DUPLEX_FULL; 1758 else 1759 cmd->base.duplex = DUPLEX_HALF; 1760 } else { 1761 speed = SPEED_UNKNOWN; 1762 cmd->base.duplex = DUPLEX_UNKNOWN; 1763 } 1764 cmd->base.speed = speed; 1765 if (hw->mac.autoneg) 1766 cmd->base.autoneg = AUTONEG_ENABLE; 1767 else 1768 cmd->base.autoneg = AUTONEG_DISABLE; 1769 1770 /* MDI-X => 2; MDI =>1; Invalid =>0 */ 1771 if (hw->phy.media_type == igc_media_type_copper) 1772 cmd->base.eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : 1773 ETH_TP_MDI; 1774 else 1775 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID; 1776 1777 if (hw->phy.mdix == AUTO_ALL_MODES) 1778 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO; 1779 else 1780 cmd->base.eth_tp_mdix_ctrl = hw->phy.mdix; 1781 1782 return 0; 1783 } 1784 1785 static int 1786 igc_ethtool_set_link_ksettings(struct net_device *netdev, 1787 const struct ethtool_link_ksettings *cmd) 1788 { 1789 struct igc_adapter *adapter = netdev_priv(netdev); 1790 struct net_device *dev = adapter->netdev; 1791 struct igc_hw *hw = &adapter->hw; 1792 u32 advertising; 1793 1794 /* When adapter in resetting mode, autoneg/speed/duplex 1795 * cannot be changed 1796 */ 1797 if (igc_check_reset_block(hw)) { 1798 netdev_err(dev, "Cannot change link characteristics when reset is active\n"); 1799 return -EINVAL; 1800 } 1801 1802 /* MDI setting is only allowed when autoneg enabled because 1803 * some hardware doesn't allow MDI setting when speed or 1804 * duplex is forced. 1805 */ 1806 if (cmd->base.eth_tp_mdix_ctrl) { 1807 if (cmd->base.eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO && 1808 cmd->base.autoneg != AUTONEG_ENABLE) { 1809 netdev_err(dev, "Forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n"); 1810 return -EINVAL; 1811 } 1812 } 1813 1814 while (test_and_set_bit(__IGC_RESETTING, &adapter->state)) 1815 usleep_range(1000, 2000); 1816 1817 ethtool_convert_link_mode_to_legacy_u32(&advertising, 1818 cmd->link_modes.advertising); 1819 /* Converting to legacy u32 drops ETHTOOL_LINK_MODE_2500baseT_Full_BIT. 1820 * We have to check this and convert it to ADVERTISE_2500_FULL 1821 * (aka ETHTOOL_LINK_MODE_2500baseX_Full_BIT) explicitly. 1822 */ 1823 if (ethtool_link_ksettings_test_link_mode(cmd, advertising, 2500baseT_Full)) 1824 advertising |= ADVERTISE_2500_FULL; 1825 1826 if (cmd->base.autoneg == AUTONEG_ENABLE) { 1827 hw->mac.autoneg = 1; 1828 hw->phy.autoneg_advertised = advertising; 1829 if (adapter->fc_autoneg) 1830 hw->fc.requested_mode = igc_fc_default; 1831 } else { 1832 netdev_info(dev, "Force mode currently not supported\n"); 1833 } 1834 1835 /* MDI-X => 2; MDI => 1; Auto => 3 */ 1836 if (cmd->base.eth_tp_mdix_ctrl) { 1837 /* fix up the value for auto (3 => 0) as zero is mapped 1838 * internally to auto 1839 */ 1840 if (cmd->base.eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO) 1841 hw->phy.mdix = AUTO_ALL_MODES; 1842 else 1843 hw->phy.mdix = cmd->base.eth_tp_mdix_ctrl; 1844 } 1845 1846 /* reset the link */ 1847 if (netif_running(adapter->netdev)) { 1848 igc_down(adapter); 1849 igc_up(adapter); 1850 } else { 1851 igc_reset(adapter); 1852 } 1853 1854 clear_bit(__IGC_RESETTING, &adapter->state); 1855 1856 return 0; 1857 } 1858 1859 static void igc_ethtool_diag_test(struct net_device *netdev, 1860 struct ethtool_test *eth_test, u64 *data) 1861 { 1862 struct igc_adapter *adapter = netdev_priv(netdev); 1863 bool if_running = netif_running(netdev); 1864 1865 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 1866 netdev_info(adapter->netdev, "Offline testing starting"); 1867 set_bit(__IGC_TESTING, &adapter->state); 1868 1869 /* Link test performed before hardware reset so autoneg doesn't 1870 * interfere with test result 1871 */ 1872 if (!igc_link_test(adapter, &data[TEST_LINK])) 1873 eth_test->flags |= ETH_TEST_FL_FAILED; 1874 1875 if (if_running) 1876 igc_close(netdev); 1877 else 1878 igc_reset(adapter); 1879 1880 netdev_info(adapter->netdev, "Register testing starting"); 1881 if (!igc_reg_test(adapter, &data[TEST_REG])) 1882 eth_test->flags |= ETH_TEST_FL_FAILED; 1883 1884 igc_reset(adapter); 1885 1886 netdev_info(adapter->netdev, "EEPROM testing starting"); 1887 if (!igc_eeprom_test(adapter, &data[TEST_EEP])) 1888 eth_test->flags |= ETH_TEST_FL_FAILED; 1889 1890 igc_reset(adapter); 1891 1892 /* loopback and interrupt tests 1893 * will be implemented in the future 1894 */ 1895 data[TEST_LOOP] = 0; 1896 data[TEST_IRQ] = 0; 1897 1898 clear_bit(__IGC_TESTING, &adapter->state); 1899 if (if_running) 1900 igc_open(netdev); 1901 } else { 1902 netdev_info(adapter->netdev, "Online testing starting"); 1903 1904 /* register, eeprom, intr and loopback tests not run online */ 1905 data[TEST_REG] = 0; 1906 data[TEST_EEP] = 0; 1907 data[TEST_IRQ] = 0; 1908 data[TEST_LOOP] = 0; 1909 1910 if (!igc_link_test(adapter, &data[TEST_LINK])) 1911 eth_test->flags |= ETH_TEST_FL_FAILED; 1912 } 1913 1914 msleep_interruptible(4 * 1000); 1915 } 1916 1917 static const struct ethtool_ops igc_ethtool_ops = { 1918 .supported_coalesce_params = ETHTOOL_COALESCE_USECS, 1919 .get_drvinfo = igc_ethtool_get_drvinfo, 1920 .get_regs_len = igc_ethtool_get_regs_len, 1921 .get_regs = igc_ethtool_get_regs, 1922 .get_wol = igc_ethtool_get_wol, 1923 .set_wol = igc_ethtool_set_wol, 1924 .get_msglevel = igc_ethtool_get_msglevel, 1925 .set_msglevel = igc_ethtool_set_msglevel, 1926 .nway_reset = igc_ethtool_nway_reset, 1927 .get_link = igc_ethtool_get_link, 1928 .get_eeprom_len = igc_ethtool_get_eeprom_len, 1929 .get_eeprom = igc_ethtool_get_eeprom, 1930 .set_eeprom = igc_ethtool_set_eeprom, 1931 .get_ringparam = igc_ethtool_get_ringparam, 1932 .set_ringparam = igc_ethtool_set_ringparam, 1933 .get_pauseparam = igc_ethtool_get_pauseparam, 1934 .set_pauseparam = igc_ethtool_set_pauseparam, 1935 .get_strings = igc_ethtool_get_strings, 1936 .get_sset_count = igc_ethtool_get_sset_count, 1937 .get_ethtool_stats = igc_ethtool_get_stats, 1938 .get_coalesce = igc_ethtool_get_coalesce, 1939 .set_coalesce = igc_ethtool_set_coalesce, 1940 .get_rxnfc = igc_ethtool_get_rxnfc, 1941 .set_rxnfc = igc_ethtool_set_rxnfc, 1942 .get_rxfh_indir_size = igc_ethtool_get_rxfh_indir_size, 1943 .get_rxfh = igc_ethtool_get_rxfh, 1944 .set_rxfh = igc_ethtool_set_rxfh, 1945 .get_ts_info = igc_ethtool_get_ts_info, 1946 .get_channels = igc_ethtool_get_channels, 1947 .set_channels = igc_ethtool_set_channels, 1948 .get_priv_flags = igc_ethtool_get_priv_flags, 1949 .set_priv_flags = igc_ethtool_set_priv_flags, 1950 .get_eee = igc_ethtool_get_eee, 1951 .set_eee = igc_ethtool_set_eee, 1952 .begin = igc_ethtool_begin, 1953 .complete = igc_ethtool_complete, 1954 .get_link_ksettings = igc_ethtool_get_link_ksettings, 1955 .set_link_ksettings = igc_ethtool_set_link_ksettings, 1956 .self_test = igc_ethtool_diag_test, 1957 }; 1958 1959 void igc_ethtool_set_ops(struct net_device *netdev) 1960 { 1961 netdev->ethtool_ops = &igc_ethtool_ops; 1962 } 1963