1 /* 2 * Copyright (C) 2005 - 2011 Emulex 3 * All rights reserved. 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License version 2 7 * as published by the Free Software Foundation. The full GNU General 8 * Public License is included in this distribution in the file called COPYING. 9 * 10 * Contact Information: 11 * linux-drivers@emulex.com 12 * 13 * Emulex 14 * 3333 Susan Street 15 * Costa Mesa, CA 92626 16 */ 17 18 #include "be.h" 19 #include "be_cmds.h" 20 #include <linux/ethtool.h> 21 22 struct be_ethtool_stat { 23 char desc[ETH_GSTRING_LEN]; 24 int type; 25 int size; 26 int offset; 27 }; 28 29 enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT}; 30 #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \ 31 offsetof(_struct, field) 32 #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\ 33 FIELDINFO(struct be_tx_stats, field) 34 #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\ 35 FIELDINFO(struct be_rx_stats, field) 36 #define DRVSTAT_INFO(field) #field, DRVSTAT,\ 37 FIELDINFO(struct be_drv_stats, field) 38 39 static const struct be_ethtool_stat et_stats[] = { 40 {DRVSTAT_INFO(tx_events)}, 41 {DRVSTAT_INFO(rx_crc_errors)}, 42 {DRVSTAT_INFO(rx_alignment_symbol_errors)}, 43 {DRVSTAT_INFO(rx_pause_frames)}, 44 {DRVSTAT_INFO(rx_control_frames)}, 45 {DRVSTAT_INFO(rx_in_range_errors)}, 46 {DRVSTAT_INFO(rx_out_range_errors)}, 47 {DRVSTAT_INFO(rx_frame_too_long)}, 48 {DRVSTAT_INFO(rx_address_match_errors)}, 49 {DRVSTAT_INFO(rx_dropped_too_small)}, 50 {DRVSTAT_INFO(rx_dropped_too_short)}, 51 {DRVSTAT_INFO(rx_dropped_header_too_small)}, 52 {DRVSTAT_INFO(rx_dropped_tcp_length)}, 53 {DRVSTAT_INFO(rx_dropped_runt)}, 54 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)}, 55 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)}, 56 {DRVSTAT_INFO(rx_ip_checksum_errs)}, 57 {DRVSTAT_INFO(rx_tcp_checksum_errs)}, 58 {DRVSTAT_INFO(rx_udp_checksum_errs)}, 59 {DRVSTAT_INFO(tx_pauseframes)}, 60 {DRVSTAT_INFO(tx_controlframes)}, 61 {DRVSTAT_INFO(rx_priority_pause_frames)}, 62 {DRVSTAT_INFO(pmem_fifo_overflow_drop)}, 63 {DRVSTAT_INFO(jabber_events)}, 64 {DRVSTAT_INFO(rx_drops_no_pbuf)}, 65 {DRVSTAT_INFO(rx_drops_no_txpb)}, 66 {DRVSTAT_INFO(rx_drops_no_erx_descr)}, 67 {DRVSTAT_INFO(rx_drops_no_tpre_descr)}, 68 {DRVSTAT_INFO(rx_drops_too_many_frags)}, 69 {DRVSTAT_INFO(rx_drops_invalid_ring)}, 70 {DRVSTAT_INFO(forwarded_packets)}, 71 {DRVSTAT_INFO(rx_drops_mtu)}, 72 {DRVSTAT_INFO(eth_red_drops)}, 73 {DRVSTAT_INFO(be_on_die_temperature)} 74 }; 75 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats) 76 77 /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts 78 * are first and second members respectively. 79 */ 80 static const struct be_ethtool_stat et_rx_stats[] = { 81 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */ 82 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */ 83 {DRVSTAT_RX_INFO(rx_polls)}, 84 {DRVSTAT_RX_INFO(rx_events)}, 85 {DRVSTAT_RX_INFO(rx_compl)}, 86 {DRVSTAT_RX_INFO(rx_mcast_pkts)}, 87 {DRVSTAT_RX_INFO(rx_post_fail)}, 88 {DRVSTAT_RX_INFO(rx_drops_no_skbs)}, 89 {DRVSTAT_RX_INFO(rx_drops_no_frags)} 90 }; 91 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats)) 92 93 /* Stats related to multi TX queues: get_stats routine assumes compl is the 94 * first member 95 */ 96 static const struct be_ethtool_stat et_tx_stats[] = { 97 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */ 98 {DRVSTAT_TX_INFO(tx_bytes)}, 99 {DRVSTAT_TX_INFO(tx_pkts)}, 100 {DRVSTAT_TX_INFO(tx_reqs)}, 101 {DRVSTAT_TX_INFO(tx_wrbs)}, 102 {DRVSTAT_TX_INFO(tx_compl)}, 103 {DRVSTAT_TX_INFO(tx_stops)} 104 }; 105 #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats)) 106 107 static const char et_self_tests[][ETH_GSTRING_LEN] = { 108 "MAC Loopback test", 109 "PHY Loopback test", 110 "External Loopback test", 111 "DDR DMA test", 112 "Link test" 113 }; 114 115 #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests) 116 #define BE_MAC_LOOPBACK 0x0 117 #define BE_PHY_LOOPBACK 0x1 118 #define BE_ONE_PORT_EXT_LOOPBACK 0x2 119 #define BE_NO_LOOPBACK 0xff 120 121 static void be_get_drvinfo(struct net_device *netdev, 122 struct ethtool_drvinfo *drvinfo) 123 { 124 struct be_adapter *adapter = netdev_priv(netdev); 125 char fw_on_flash[FW_VER_LEN]; 126 127 memset(fw_on_flash, 0 , sizeof(fw_on_flash)); 128 be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash); 129 130 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); 131 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version)); 132 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN); 133 if (memcmp(adapter->fw_ver, fw_on_flash, FW_VER_LEN) != 0) { 134 strcat(drvinfo->fw_version, " ["); 135 strcat(drvinfo->fw_version, fw_on_flash); 136 strcat(drvinfo->fw_version, "]"); 137 } 138 139 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 140 sizeof(drvinfo->bus_info)); 141 drvinfo->testinfo_len = 0; 142 drvinfo->regdump_len = 0; 143 drvinfo->eedump_len = 0; 144 } 145 146 static u32 147 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name) 148 { 149 u32 data_read = 0, eof; 150 u8 addn_status; 151 struct be_dma_mem data_len_cmd; 152 int status; 153 154 memset(&data_len_cmd, 0, sizeof(data_len_cmd)); 155 /* data_offset and data_size should be 0 to get reg len */ 156 status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0, 157 file_name, &data_read, &eof, &addn_status); 158 159 return data_read; 160 } 161 162 static int 163 lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name, 164 u32 buf_len, void *buf) 165 { 166 struct be_dma_mem read_cmd; 167 u32 read_len = 0, total_read_len = 0, chunk_size; 168 u32 eof = 0; 169 u8 addn_status; 170 int status = 0; 171 172 read_cmd.size = LANCER_READ_FILE_CHUNK; 173 read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size, 174 &read_cmd.dma); 175 176 if (!read_cmd.va) { 177 dev_err(&adapter->pdev->dev, 178 "Memory allocation failure while reading dump\n"); 179 return -ENOMEM; 180 } 181 182 while ((total_read_len < buf_len) && !eof) { 183 chunk_size = min_t(u32, (buf_len - total_read_len), 184 LANCER_READ_FILE_CHUNK); 185 chunk_size = ALIGN(chunk_size, 4); 186 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size, 187 total_read_len, file_name, &read_len, 188 &eof, &addn_status); 189 if (!status) { 190 memcpy(buf + total_read_len, read_cmd.va, read_len); 191 total_read_len += read_len; 192 eof &= LANCER_READ_FILE_EOF_MASK; 193 } else { 194 status = -EIO; 195 break; 196 } 197 } 198 pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va, 199 read_cmd.dma); 200 201 return status; 202 } 203 204 static int 205 be_get_reg_len(struct net_device *netdev) 206 { 207 struct be_adapter *adapter = netdev_priv(netdev); 208 u32 log_size = 0; 209 210 if (be_physfn(adapter)) { 211 if (lancer_chip(adapter)) 212 log_size = lancer_cmd_get_file_len(adapter, 213 LANCER_FW_DUMP_FILE); 214 else 215 be_cmd_get_reg_len(adapter, &log_size); 216 } 217 return log_size; 218 } 219 220 static void 221 be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf) 222 { 223 struct be_adapter *adapter = netdev_priv(netdev); 224 225 if (be_physfn(adapter)) { 226 memset(buf, 0, regs->len); 227 if (lancer_chip(adapter)) 228 lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE, 229 regs->len, buf); 230 else 231 be_cmd_get_regs(adapter, regs->len, buf); 232 } 233 } 234 235 static int 236 be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) 237 { 238 struct be_adapter *adapter = netdev_priv(netdev); 239 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq; 240 struct be_eq_obj *tx_eq = &adapter->tx_eq; 241 242 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd; 243 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd; 244 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd; 245 246 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd; 247 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd; 248 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd; 249 250 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic; 251 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic; 252 253 return 0; 254 } 255 256 /* 257 * This routine is used to set interrup coalescing delay 258 */ 259 static int 260 be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) 261 { 262 struct be_adapter *adapter = netdev_priv(netdev); 263 struct be_rx_obj *rxo; 264 struct be_eq_obj *rx_eq; 265 struct be_eq_obj *tx_eq = &adapter->tx_eq; 266 u32 rx_max, rx_min, rx_cur; 267 int status = 0, i; 268 u32 tx_cur; 269 270 if (coalesce->use_adaptive_tx_coalesce == 1) 271 return -EINVAL; 272 273 for_all_rx_queues(adapter, rxo, i) { 274 rx_eq = &rxo->rx_eq; 275 276 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce) 277 rx_eq->cur_eqd = 0; 278 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce; 279 280 rx_max = coalesce->rx_coalesce_usecs_high; 281 rx_min = coalesce->rx_coalesce_usecs_low; 282 rx_cur = coalesce->rx_coalesce_usecs; 283 284 if (rx_eq->enable_aic) { 285 if (rx_max > BE_MAX_EQD) 286 rx_max = BE_MAX_EQD; 287 if (rx_min > rx_max) 288 rx_min = rx_max; 289 rx_eq->max_eqd = rx_max; 290 rx_eq->min_eqd = rx_min; 291 if (rx_eq->cur_eqd > rx_max) 292 rx_eq->cur_eqd = rx_max; 293 if (rx_eq->cur_eqd < rx_min) 294 rx_eq->cur_eqd = rx_min; 295 } else { 296 if (rx_cur > BE_MAX_EQD) 297 rx_cur = BE_MAX_EQD; 298 if (rx_eq->cur_eqd != rx_cur) { 299 status = be_cmd_modify_eqd(adapter, rx_eq->q.id, 300 rx_cur); 301 if (!status) 302 rx_eq->cur_eqd = rx_cur; 303 } 304 } 305 } 306 307 tx_cur = coalesce->tx_coalesce_usecs; 308 309 if (tx_cur > BE_MAX_EQD) 310 tx_cur = BE_MAX_EQD; 311 if (tx_eq->cur_eqd != tx_cur) { 312 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur); 313 if (!status) 314 tx_eq->cur_eqd = tx_cur; 315 } 316 317 return 0; 318 } 319 320 static void 321 be_get_ethtool_stats(struct net_device *netdev, 322 struct ethtool_stats *stats, uint64_t *data) 323 { 324 struct be_adapter *adapter = netdev_priv(netdev); 325 struct be_rx_obj *rxo; 326 struct be_tx_obj *txo; 327 void *p; 328 unsigned int i, j, base = 0, start; 329 330 for (i = 0; i < ETHTOOL_STATS_NUM; i++) { 331 p = (u8 *)&adapter->drv_stats + et_stats[i].offset; 332 data[i] = *(u32 *)p; 333 } 334 base += ETHTOOL_STATS_NUM; 335 336 for_all_rx_queues(adapter, rxo, j) { 337 struct be_rx_stats *stats = rx_stats(rxo); 338 339 do { 340 start = u64_stats_fetch_begin_bh(&stats->sync); 341 data[base] = stats->rx_bytes; 342 data[base + 1] = stats->rx_pkts; 343 } while (u64_stats_fetch_retry_bh(&stats->sync, start)); 344 345 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) { 346 p = (u8 *)stats + et_rx_stats[i].offset; 347 data[base + i] = *(u32 *)p; 348 } 349 base += ETHTOOL_RXSTATS_NUM; 350 } 351 352 for_all_tx_queues(adapter, txo, j) { 353 struct be_tx_stats *stats = tx_stats(txo); 354 355 do { 356 start = u64_stats_fetch_begin_bh(&stats->sync_compl); 357 data[base] = stats->tx_compl; 358 } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start)); 359 360 do { 361 start = u64_stats_fetch_begin_bh(&stats->sync); 362 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) { 363 p = (u8 *)stats + et_tx_stats[i].offset; 364 data[base + i] = 365 (et_tx_stats[i].size == sizeof(u64)) ? 366 *(u64 *)p : *(u32 *)p; 367 } 368 } while (u64_stats_fetch_retry_bh(&stats->sync, start)); 369 base += ETHTOOL_TXSTATS_NUM; 370 } 371 } 372 373 static void 374 be_get_stat_strings(struct net_device *netdev, uint32_t stringset, 375 uint8_t *data) 376 { 377 struct be_adapter *adapter = netdev_priv(netdev); 378 int i, j; 379 380 switch (stringset) { 381 case ETH_SS_STATS: 382 for (i = 0; i < ETHTOOL_STATS_NUM; i++) { 383 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN); 384 data += ETH_GSTRING_LEN; 385 } 386 for (i = 0; i < adapter->num_rx_qs; i++) { 387 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) { 388 sprintf(data, "rxq%d: %s", i, 389 et_rx_stats[j].desc); 390 data += ETH_GSTRING_LEN; 391 } 392 } 393 for (i = 0; i < adapter->num_tx_qs; i++) { 394 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) { 395 sprintf(data, "txq%d: %s", i, 396 et_tx_stats[j].desc); 397 data += ETH_GSTRING_LEN; 398 } 399 } 400 break; 401 case ETH_SS_TEST: 402 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) { 403 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN); 404 data += ETH_GSTRING_LEN; 405 } 406 break; 407 } 408 } 409 410 static int be_get_sset_count(struct net_device *netdev, int stringset) 411 { 412 struct be_adapter *adapter = netdev_priv(netdev); 413 414 switch (stringset) { 415 case ETH_SS_TEST: 416 return ETHTOOL_TESTS_NUM; 417 case ETH_SS_STATS: 418 return ETHTOOL_STATS_NUM + 419 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM + 420 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM; 421 default: 422 return -EINVAL; 423 } 424 } 425 426 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) 427 { 428 struct be_adapter *adapter = netdev_priv(netdev); 429 struct be_phy_info phy_info; 430 u8 mac_speed = 0; 431 u16 link_speed = 0; 432 int status; 433 434 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) { 435 status = be_cmd_link_status_query(adapter, &mac_speed, 436 &link_speed, 0); 437 438 /* link_speed is in units of 10 Mbps */ 439 if (link_speed) { 440 ethtool_cmd_speed_set(ecmd, link_speed*10); 441 } else { 442 switch (mac_speed) { 443 case PHY_LINK_SPEED_10MBPS: 444 ethtool_cmd_speed_set(ecmd, SPEED_10); 445 break; 446 case PHY_LINK_SPEED_100MBPS: 447 ethtool_cmd_speed_set(ecmd, SPEED_100); 448 break; 449 case PHY_LINK_SPEED_1GBPS: 450 ethtool_cmd_speed_set(ecmd, SPEED_1000); 451 break; 452 case PHY_LINK_SPEED_10GBPS: 453 ethtool_cmd_speed_set(ecmd, SPEED_10000); 454 break; 455 case PHY_LINK_SPEED_ZERO: 456 ethtool_cmd_speed_set(ecmd, 0); 457 break; 458 } 459 } 460 461 status = be_cmd_get_phy_info(adapter, &phy_info); 462 if (!status) { 463 switch (phy_info.interface_type) { 464 case PHY_TYPE_XFP_10GB: 465 case PHY_TYPE_SFP_1GB: 466 case PHY_TYPE_SFP_PLUS_10GB: 467 ecmd->port = PORT_FIBRE; 468 break; 469 default: 470 ecmd->port = PORT_TP; 471 break; 472 } 473 474 switch (phy_info.interface_type) { 475 case PHY_TYPE_KR_10GB: 476 case PHY_TYPE_KX4_10GB: 477 ecmd->autoneg = AUTONEG_ENABLE; 478 ecmd->transceiver = XCVR_INTERNAL; 479 break; 480 default: 481 ecmd->autoneg = AUTONEG_DISABLE; 482 ecmd->transceiver = XCVR_EXTERNAL; 483 break; 484 } 485 } 486 487 /* Save for future use */ 488 adapter->link_speed = ethtool_cmd_speed(ecmd); 489 adapter->port_type = ecmd->port; 490 adapter->transceiver = ecmd->transceiver; 491 adapter->autoneg = ecmd->autoneg; 492 } else { 493 ethtool_cmd_speed_set(ecmd, adapter->link_speed); 494 ecmd->port = adapter->port_type; 495 ecmd->transceiver = adapter->transceiver; 496 ecmd->autoneg = adapter->autoneg; 497 } 498 499 ecmd->duplex = DUPLEX_FULL; 500 ecmd->phy_address = adapter->port_num; 501 switch (ecmd->port) { 502 case PORT_FIBRE: 503 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); 504 break; 505 case PORT_TP: 506 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP); 507 break; 508 case PORT_AUI: 509 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI); 510 break; 511 } 512 513 if (ecmd->autoneg) { 514 ecmd->supported |= SUPPORTED_1000baseT_Full; 515 ecmd->supported |= SUPPORTED_Autoneg; 516 ecmd->advertising |= (ADVERTISED_10000baseT_Full | 517 ADVERTISED_1000baseT_Full); 518 } 519 520 return 0; 521 } 522 523 static void be_get_ringparam(struct net_device *netdev, 524 struct ethtool_ringparam *ring) 525 { 526 struct be_adapter *adapter = netdev_priv(netdev); 527 528 ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len; 529 ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len; 530 } 531 532 static void 533 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) 534 { 535 struct be_adapter *adapter = netdev_priv(netdev); 536 537 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause); 538 ecmd->autoneg = 0; 539 } 540 541 static int 542 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) 543 { 544 struct be_adapter *adapter = netdev_priv(netdev); 545 int status; 546 547 if (ecmd->autoneg != 0) 548 return -EINVAL; 549 adapter->tx_fc = ecmd->tx_pause; 550 adapter->rx_fc = ecmd->rx_pause; 551 552 status = be_cmd_set_flow_control(adapter, 553 adapter->tx_fc, adapter->rx_fc); 554 if (status) 555 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n"); 556 557 return status; 558 } 559 560 static int 561 be_set_phys_id(struct net_device *netdev, 562 enum ethtool_phys_id_state state) 563 { 564 struct be_adapter *adapter = netdev_priv(netdev); 565 566 switch (state) { 567 case ETHTOOL_ID_ACTIVE: 568 be_cmd_get_beacon_state(adapter, adapter->hba_port_num, 569 &adapter->beacon_state); 570 return 1; /* cycle on/off once per second */ 571 572 case ETHTOOL_ID_ON: 573 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, 574 BEACON_STATE_ENABLED); 575 break; 576 577 case ETHTOOL_ID_OFF: 578 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, 579 BEACON_STATE_DISABLED); 580 break; 581 582 case ETHTOOL_ID_INACTIVE: 583 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, 584 adapter->beacon_state); 585 } 586 587 return 0; 588 } 589 590 static bool 591 be_is_wol_supported(struct be_adapter *adapter) 592 { 593 if (!be_physfn(adapter)) 594 return false; 595 else 596 return true; 597 } 598 599 static void 600 be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 601 { 602 struct be_adapter *adapter = netdev_priv(netdev); 603 604 if (be_is_wol_supported(adapter)) 605 wol->supported = WAKE_MAGIC; 606 607 if (adapter->wol) 608 wol->wolopts = WAKE_MAGIC; 609 else 610 wol->wolopts = 0; 611 memset(&wol->sopass, 0, sizeof(wol->sopass)); 612 } 613 614 static int 615 be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 616 { 617 struct be_adapter *adapter = netdev_priv(netdev); 618 619 if (wol->wolopts & ~WAKE_MAGIC) 620 return -EINVAL; 621 622 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter)) 623 adapter->wol = true; 624 else 625 adapter->wol = false; 626 627 return 0; 628 } 629 630 static int 631 be_test_ddr_dma(struct be_adapter *adapter) 632 { 633 int ret, i; 634 struct be_dma_mem ddrdma_cmd; 635 static const u64 pattern[2] = { 636 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL 637 }; 638 639 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test); 640 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size, 641 &ddrdma_cmd.dma, GFP_KERNEL); 642 if (!ddrdma_cmd.va) { 643 dev_err(&adapter->pdev->dev, "Memory allocation failure\n"); 644 return -ENOMEM; 645 } 646 647 for (i = 0; i < 2; i++) { 648 ret = be_cmd_ddr_dma_test(adapter, pattern[i], 649 4096, &ddrdma_cmd); 650 if (ret != 0) 651 goto err; 652 } 653 654 err: 655 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va, 656 ddrdma_cmd.dma); 657 return ret; 658 } 659 660 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type, 661 u64 *status) 662 { 663 be_cmd_set_loopback(adapter, adapter->hba_port_num, 664 loopback_type, 1); 665 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num, 666 loopback_type, 1500, 667 2, 0xabc); 668 be_cmd_set_loopback(adapter, adapter->hba_port_num, 669 BE_NO_LOOPBACK, 1); 670 return *status; 671 } 672 673 static void 674 be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data) 675 { 676 struct be_adapter *adapter = netdev_priv(netdev); 677 u8 mac_speed = 0; 678 u16 qos_link_speed = 0; 679 680 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM); 681 682 if (test->flags & ETH_TEST_FL_OFFLINE) { 683 if (be_loopback_test(adapter, BE_MAC_LOOPBACK, 684 &data[0]) != 0) { 685 test->flags |= ETH_TEST_FL_FAILED; 686 } 687 if (be_loopback_test(adapter, BE_PHY_LOOPBACK, 688 &data[1]) != 0) { 689 test->flags |= ETH_TEST_FL_FAILED; 690 } 691 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK, 692 &data[2]) != 0) { 693 test->flags |= ETH_TEST_FL_FAILED; 694 } 695 } 696 697 if (be_test_ddr_dma(adapter) != 0) { 698 data[3] = 1; 699 test->flags |= ETH_TEST_FL_FAILED; 700 } 701 702 if (be_cmd_link_status_query(adapter, &mac_speed, 703 &qos_link_speed, 0) != 0) { 704 test->flags |= ETH_TEST_FL_FAILED; 705 data[4] = -1; 706 } else if (!mac_speed) { 707 test->flags |= ETH_TEST_FL_FAILED; 708 data[4] = 1; 709 } 710 } 711 712 static int 713 be_do_flash(struct net_device *netdev, struct ethtool_flash *efl) 714 { 715 struct be_adapter *adapter = netdev_priv(netdev); 716 char file_name[ETHTOOL_FLASH_MAX_FILENAME]; 717 718 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; 719 strcpy(file_name, efl->data); 720 721 return be_load_fw(adapter, file_name); 722 } 723 724 static int 725 be_get_eeprom_len(struct net_device *netdev) 726 { 727 struct be_adapter *adapter = netdev_priv(netdev); 728 if (lancer_chip(adapter)) { 729 if (be_physfn(adapter)) 730 return lancer_cmd_get_file_len(adapter, 731 LANCER_VPD_PF_FILE); 732 else 733 return lancer_cmd_get_file_len(adapter, 734 LANCER_VPD_VF_FILE); 735 } else { 736 return BE_READ_SEEPROM_LEN; 737 } 738 } 739 740 static int 741 be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, 742 uint8_t *data) 743 { 744 struct be_adapter *adapter = netdev_priv(netdev); 745 struct be_dma_mem eeprom_cmd; 746 struct be_cmd_resp_seeprom_read *resp; 747 int status; 748 749 if (!eeprom->len) 750 return -EINVAL; 751 752 if (lancer_chip(adapter)) { 753 if (be_physfn(adapter)) 754 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE, 755 eeprom->len, data); 756 else 757 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE, 758 eeprom->len, data); 759 } 760 761 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16); 762 763 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem)); 764 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read); 765 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size, 766 &eeprom_cmd.dma, GFP_KERNEL); 767 768 if (!eeprom_cmd.va) { 769 dev_err(&adapter->pdev->dev, 770 "Memory allocation failure. Could not read eeprom\n"); 771 return -ENOMEM; 772 } 773 774 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd); 775 776 if (!status) { 777 resp = eeprom_cmd.va; 778 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len); 779 } 780 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va, 781 eeprom_cmd.dma); 782 783 return status; 784 } 785 786 const struct ethtool_ops be_ethtool_ops = { 787 .get_settings = be_get_settings, 788 .get_drvinfo = be_get_drvinfo, 789 .get_wol = be_get_wol, 790 .set_wol = be_set_wol, 791 .get_link = ethtool_op_get_link, 792 .get_eeprom_len = be_get_eeprom_len, 793 .get_eeprom = be_read_eeprom, 794 .get_coalesce = be_get_coalesce, 795 .set_coalesce = be_set_coalesce, 796 .get_ringparam = be_get_ringparam, 797 .get_pauseparam = be_get_pauseparam, 798 .set_pauseparam = be_set_pauseparam, 799 .get_strings = be_get_stat_strings, 800 .set_phys_id = be_set_phys_id, 801 .get_sset_count = be_get_sset_count, 802 .get_ethtool_stats = be_get_ethtool_stats, 803 .get_regs_len = be_get_reg_len, 804 .get_regs = be_get_regs, 805 .flash_device = be_do_flash, 806 .self_test = be_self_test, 807 }; 808