1 /* 2 * Copyright (C) 2005 - 2014 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(rx_crc_errors)}, 41 {DRVSTAT_INFO(rx_alignment_symbol_errors)}, 42 {DRVSTAT_INFO(rx_pause_frames)}, 43 {DRVSTAT_INFO(rx_control_frames)}, 44 /* Received packets dropped when the Ethernet length field 45 * is not equal to the actual Ethernet data length. 46 */ 47 {DRVSTAT_INFO(rx_in_range_errors)}, 48 /* Received packets dropped when their length field is >= 1501 bytes 49 * and <= 1535 bytes. 50 */ 51 {DRVSTAT_INFO(rx_out_range_errors)}, 52 /* Received packets dropped when they are longer than 9216 bytes */ 53 {DRVSTAT_INFO(rx_frame_too_long)}, 54 /* Received packets dropped when they don't pass the unicast or 55 * multicast address filtering. 56 */ 57 {DRVSTAT_INFO(rx_address_filtered)}, 58 /* Received packets dropped when IP packet length field is less than 59 * the IP header length field. 60 */ 61 {DRVSTAT_INFO(rx_dropped_too_small)}, 62 /* Received packets dropped when IP length field is greater than 63 * the actual packet length. 64 */ 65 {DRVSTAT_INFO(rx_dropped_too_short)}, 66 /* Received packets dropped when the IP header length field is less 67 * than 5. 68 */ 69 {DRVSTAT_INFO(rx_dropped_header_too_small)}, 70 /* Received packets dropped when the TCP header length field is less 71 * than 5 or the TCP header length + IP header length is more 72 * than IP packet length. 73 */ 74 {DRVSTAT_INFO(rx_dropped_tcp_length)}, 75 {DRVSTAT_INFO(rx_dropped_runt)}, 76 /* Number of received packets dropped when a fifo for descriptors going 77 * into the packet demux block overflows. In normal operation, this 78 * fifo must never overflow. 79 */ 80 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)}, 81 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)}, 82 {DRVSTAT_INFO(rx_ip_checksum_errs)}, 83 {DRVSTAT_INFO(rx_tcp_checksum_errs)}, 84 {DRVSTAT_INFO(rx_udp_checksum_errs)}, 85 {DRVSTAT_INFO(tx_pauseframes)}, 86 {DRVSTAT_INFO(tx_controlframes)}, 87 {DRVSTAT_INFO(rx_priority_pause_frames)}, 88 {DRVSTAT_INFO(tx_priority_pauseframes)}, 89 /* Received packets dropped when an internal fifo going into 90 * main packet buffer tank (PMEM) overflows. 91 */ 92 {DRVSTAT_INFO(pmem_fifo_overflow_drop)}, 93 {DRVSTAT_INFO(jabber_events)}, 94 /* Received packets dropped due to lack of available HW packet buffers 95 * used to temporarily hold the received packets. 96 */ 97 {DRVSTAT_INFO(rx_drops_no_pbuf)}, 98 /* Received packets dropped due to input receive buffer 99 * descriptor fifo overflowing. 100 */ 101 {DRVSTAT_INFO(rx_drops_no_erx_descr)}, 102 /* Packets dropped because the internal FIFO to the offloaded TCP 103 * receive processing block is full. This could happen only for 104 * offloaded iSCSI or FCoE trarffic. 105 */ 106 {DRVSTAT_INFO(rx_drops_no_tpre_descr)}, 107 /* Received packets dropped when they need more than 8 108 * receive buffers. This cannot happen as the driver configures 109 * 2048 byte receive buffers. 110 */ 111 {DRVSTAT_INFO(rx_drops_too_many_frags)}, 112 {DRVSTAT_INFO(forwarded_packets)}, 113 /* Received packets dropped when the frame length 114 * is more than 9018 bytes 115 */ 116 {DRVSTAT_INFO(rx_drops_mtu)}, 117 /* Number of packets dropped due to random early drop function */ 118 {DRVSTAT_INFO(eth_red_drops)}, 119 {DRVSTAT_INFO(be_on_die_temperature)}, 120 {DRVSTAT_INFO(rx_roce_bytes_lsd)}, 121 {DRVSTAT_INFO(rx_roce_bytes_msd)}, 122 {DRVSTAT_INFO(rx_roce_frames)}, 123 {DRVSTAT_INFO(roce_drops_payload_len)}, 124 {DRVSTAT_INFO(roce_drops_crc)} 125 }; 126 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats) 127 128 /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts 129 * are first and second members respectively. 130 */ 131 static const struct be_ethtool_stat et_rx_stats[] = { 132 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */ 133 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */ 134 {DRVSTAT_RX_INFO(rx_compl)}, 135 {DRVSTAT_RX_INFO(rx_compl_err)}, 136 {DRVSTAT_RX_INFO(rx_mcast_pkts)}, 137 /* Number of page allocation failures while posting receive buffers 138 * to HW. 139 */ 140 {DRVSTAT_RX_INFO(rx_post_fail)}, 141 /* Recevied packets dropped due to skb allocation failure */ 142 {DRVSTAT_RX_INFO(rx_drops_no_skbs)}, 143 /* Received packets dropped due to lack of available fetched buffers 144 * posted by the driver. 145 */ 146 {DRVSTAT_RX_INFO(rx_drops_no_frags)} 147 }; 148 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats)) 149 150 /* Stats related to multi TX queues: get_stats routine assumes compl is the 151 * first member 152 */ 153 static const struct be_ethtool_stat et_tx_stats[] = { 154 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */ 155 {DRVSTAT_TX_INFO(tx_bytes)}, 156 {DRVSTAT_TX_INFO(tx_pkts)}, 157 /* Number of skbs queued for trasmission by the driver */ 158 {DRVSTAT_TX_INFO(tx_reqs)}, 159 /* Number of TX work request blocks DMAed to HW */ 160 {DRVSTAT_TX_INFO(tx_wrbs)}, 161 /* Number of times the TX queue was stopped due to lack 162 * of spaces in the TXQ. 163 */ 164 {DRVSTAT_TX_INFO(tx_stops)}, 165 /* Pkts dropped in the driver's transmit path */ 166 {DRVSTAT_TX_INFO(tx_drv_drops)} 167 }; 168 #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats)) 169 170 static const char et_self_tests[][ETH_GSTRING_LEN] = { 171 "MAC Loopback test", 172 "PHY Loopback test", 173 "External Loopback test", 174 "DDR DMA test", 175 "Link test" 176 }; 177 178 #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests) 179 #define BE_MAC_LOOPBACK 0x0 180 #define BE_PHY_LOOPBACK 0x1 181 #define BE_ONE_PORT_EXT_LOOPBACK 0x2 182 #define BE_NO_LOOPBACK 0xff 183 184 static void be_get_drvinfo(struct net_device *netdev, 185 struct ethtool_drvinfo *drvinfo) 186 { 187 struct be_adapter *adapter = netdev_priv(netdev); 188 189 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); 190 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version)); 191 if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN)) 192 strlcpy(drvinfo->fw_version, adapter->fw_ver, 193 sizeof(drvinfo->fw_version)); 194 else 195 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), 196 "%s [%s]", adapter->fw_ver, adapter->fw_on_flash); 197 198 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 199 sizeof(drvinfo->bus_info)); 200 drvinfo->testinfo_len = 0; 201 drvinfo->regdump_len = 0; 202 drvinfo->eedump_len = 0; 203 } 204 205 static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name) 206 { 207 u32 data_read = 0, eof; 208 u8 addn_status; 209 struct be_dma_mem data_len_cmd; 210 int status; 211 212 memset(&data_len_cmd, 0, sizeof(data_len_cmd)); 213 /* data_offset and data_size should be 0 to get reg len */ 214 status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0, 215 file_name, &data_read, &eof, 216 &addn_status); 217 218 return data_read; 219 } 220 221 static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name, 222 u32 buf_len, void *buf) 223 { 224 struct be_dma_mem read_cmd; 225 u32 read_len = 0, total_read_len = 0, chunk_size; 226 u32 eof = 0; 227 u8 addn_status; 228 int status = 0; 229 230 read_cmd.size = LANCER_READ_FILE_CHUNK; 231 read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size, 232 &read_cmd.dma); 233 234 if (!read_cmd.va) { 235 dev_err(&adapter->pdev->dev, 236 "Memory allocation failure while reading dump\n"); 237 return -ENOMEM; 238 } 239 240 while ((total_read_len < buf_len) && !eof) { 241 chunk_size = min_t(u32, (buf_len - total_read_len), 242 LANCER_READ_FILE_CHUNK); 243 chunk_size = ALIGN(chunk_size, 4); 244 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size, 245 total_read_len, file_name, 246 &read_len, &eof, &addn_status); 247 if (!status) { 248 memcpy(buf + total_read_len, read_cmd.va, read_len); 249 total_read_len += read_len; 250 eof &= LANCER_READ_FILE_EOF_MASK; 251 } else { 252 status = -EIO; 253 break; 254 } 255 } 256 pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va, 257 read_cmd.dma); 258 259 return status; 260 } 261 262 static int be_get_reg_len(struct net_device *netdev) 263 { 264 struct be_adapter *adapter = netdev_priv(netdev); 265 u32 log_size = 0; 266 267 if (!check_privilege(adapter, MAX_PRIVILEGES)) 268 return 0; 269 270 if (be_physfn(adapter)) { 271 if (lancer_chip(adapter)) 272 log_size = lancer_cmd_get_file_len(adapter, 273 LANCER_FW_DUMP_FILE); 274 else 275 be_cmd_get_reg_len(adapter, &log_size); 276 } 277 return log_size; 278 } 279 280 static void 281 be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf) 282 { 283 struct be_adapter *adapter = netdev_priv(netdev); 284 285 if (be_physfn(adapter)) { 286 memset(buf, 0, regs->len); 287 if (lancer_chip(adapter)) 288 lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE, 289 regs->len, buf); 290 else 291 be_cmd_get_regs(adapter, regs->len, buf); 292 } 293 } 294 295 static int be_get_coalesce(struct net_device *netdev, 296 struct ethtool_coalesce *et) 297 { 298 struct be_adapter *adapter = netdev_priv(netdev); 299 struct be_aic_obj *aic = &adapter->aic_obj[0]; 300 301 302 et->rx_coalesce_usecs = aic->prev_eqd; 303 et->rx_coalesce_usecs_high = aic->max_eqd; 304 et->rx_coalesce_usecs_low = aic->min_eqd; 305 306 et->tx_coalesce_usecs = aic->prev_eqd; 307 et->tx_coalesce_usecs_high = aic->max_eqd; 308 et->tx_coalesce_usecs_low = aic->min_eqd; 309 310 et->use_adaptive_rx_coalesce = aic->enable; 311 et->use_adaptive_tx_coalesce = aic->enable; 312 313 return 0; 314 } 315 316 /* TX attributes are ignored. Only RX attributes are considered 317 * eqd cmd is issued in the worker thread. 318 */ 319 static int be_set_coalesce(struct net_device *netdev, 320 struct ethtool_coalesce *et) 321 { 322 struct be_adapter *adapter = netdev_priv(netdev); 323 struct be_aic_obj *aic = &adapter->aic_obj[0]; 324 struct be_eq_obj *eqo; 325 int i; 326 327 for_all_evt_queues(adapter, eqo, i) { 328 aic->enable = et->use_adaptive_rx_coalesce; 329 aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD); 330 aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd); 331 aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd); 332 aic->et_eqd = max(aic->et_eqd, aic->min_eqd); 333 aic++; 334 } 335 336 return 0; 337 } 338 339 static void be_get_ethtool_stats(struct net_device *netdev, 340 struct ethtool_stats *stats, uint64_t *data) 341 { 342 struct be_adapter *adapter = netdev_priv(netdev); 343 struct be_rx_obj *rxo; 344 struct be_tx_obj *txo; 345 void *p; 346 unsigned int i, j, base = 0, start; 347 348 for (i = 0; i < ETHTOOL_STATS_NUM; i++) { 349 p = (u8 *)&adapter->drv_stats + et_stats[i].offset; 350 data[i] = *(u32 *)p; 351 } 352 base += ETHTOOL_STATS_NUM; 353 354 for_all_rx_queues(adapter, rxo, j) { 355 struct be_rx_stats *stats = rx_stats(rxo); 356 357 do { 358 start = u64_stats_fetch_begin_irq(&stats->sync); 359 data[base] = stats->rx_bytes; 360 data[base + 1] = stats->rx_pkts; 361 } while (u64_stats_fetch_retry_irq(&stats->sync, start)); 362 363 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) { 364 p = (u8 *)stats + et_rx_stats[i].offset; 365 data[base + i] = *(u32 *)p; 366 } 367 base += ETHTOOL_RXSTATS_NUM; 368 } 369 370 for_all_tx_queues(adapter, txo, j) { 371 struct be_tx_stats *stats = tx_stats(txo); 372 373 do { 374 start = u64_stats_fetch_begin_irq(&stats->sync_compl); 375 data[base] = stats->tx_compl; 376 } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start)); 377 378 do { 379 start = u64_stats_fetch_begin_irq(&stats->sync); 380 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) { 381 p = (u8 *)stats + et_tx_stats[i].offset; 382 data[base + i] = 383 (et_tx_stats[i].size == sizeof(u64)) ? 384 *(u64 *)p : *(u32 *)p; 385 } 386 } while (u64_stats_fetch_retry_irq(&stats->sync, start)); 387 base += ETHTOOL_TXSTATS_NUM; 388 } 389 } 390 391 static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset, 392 uint8_t *data) 393 { 394 struct be_adapter *adapter = netdev_priv(netdev); 395 int i, j; 396 397 switch (stringset) { 398 case ETH_SS_STATS: 399 for (i = 0; i < ETHTOOL_STATS_NUM; i++) { 400 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN); 401 data += ETH_GSTRING_LEN; 402 } 403 for (i = 0; i < adapter->num_rx_qs; i++) { 404 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) { 405 sprintf(data, "rxq%d: %s", i, 406 et_rx_stats[j].desc); 407 data += ETH_GSTRING_LEN; 408 } 409 } 410 for (i = 0; i < adapter->num_tx_qs; i++) { 411 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) { 412 sprintf(data, "txq%d: %s", i, 413 et_tx_stats[j].desc); 414 data += ETH_GSTRING_LEN; 415 } 416 } 417 break; 418 case ETH_SS_TEST: 419 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) { 420 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN); 421 data += ETH_GSTRING_LEN; 422 } 423 break; 424 } 425 } 426 427 static int be_get_sset_count(struct net_device *netdev, int stringset) 428 { 429 struct be_adapter *adapter = netdev_priv(netdev); 430 431 switch (stringset) { 432 case ETH_SS_TEST: 433 return ETHTOOL_TESTS_NUM; 434 case ETH_SS_STATS: 435 return ETHTOOL_STATS_NUM + 436 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM + 437 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM; 438 default: 439 return -EINVAL; 440 } 441 } 442 443 static u32 be_get_port_type(u32 phy_type, u32 dac_cable_len) 444 { 445 u32 port; 446 447 switch (phy_type) { 448 case PHY_TYPE_BASET_1GB: 449 case PHY_TYPE_BASEX_1GB: 450 case PHY_TYPE_SGMII: 451 port = PORT_TP; 452 break; 453 case PHY_TYPE_SFP_PLUS_10GB: 454 port = dac_cable_len ? PORT_DA : PORT_FIBRE; 455 break; 456 case PHY_TYPE_XFP_10GB: 457 case PHY_TYPE_SFP_1GB: 458 port = PORT_FIBRE; 459 break; 460 case PHY_TYPE_BASET_10GB: 461 port = PORT_TP; 462 break; 463 default: 464 port = PORT_OTHER; 465 } 466 467 return port; 468 } 469 470 static u32 convert_to_et_setting(u32 if_type, u32 if_speeds) 471 { 472 u32 val = 0; 473 474 switch (if_type) { 475 case PHY_TYPE_BASET_1GB: 476 case PHY_TYPE_BASEX_1GB: 477 case PHY_TYPE_SGMII: 478 val |= SUPPORTED_TP; 479 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) 480 val |= SUPPORTED_1000baseT_Full; 481 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS) 482 val |= SUPPORTED_100baseT_Full; 483 if (if_speeds & BE_SUPPORTED_SPEED_10MBPS) 484 val |= SUPPORTED_10baseT_Full; 485 break; 486 case PHY_TYPE_KX4_10GB: 487 val |= SUPPORTED_Backplane; 488 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) 489 val |= SUPPORTED_1000baseKX_Full; 490 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) 491 val |= SUPPORTED_10000baseKX4_Full; 492 break; 493 case PHY_TYPE_KR_10GB: 494 val |= SUPPORTED_Backplane | 495 SUPPORTED_10000baseKR_Full; 496 break; 497 case PHY_TYPE_SFP_PLUS_10GB: 498 case PHY_TYPE_XFP_10GB: 499 case PHY_TYPE_SFP_1GB: 500 val |= SUPPORTED_FIBRE; 501 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) 502 val |= SUPPORTED_10000baseT_Full; 503 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) 504 val |= SUPPORTED_1000baseT_Full; 505 break; 506 case PHY_TYPE_BASET_10GB: 507 val |= SUPPORTED_TP; 508 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) 509 val |= SUPPORTED_10000baseT_Full; 510 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) 511 val |= SUPPORTED_1000baseT_Full; 512 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS) 513 val |= SUPPORTED_100baseT_Full; 514 break; 515 default: 516 val |= SUPPORTED_TP; 517 } 518 519 return val; 520 } 521 522 bool be_pause_supported(struct be_adapter *adapter) 523 { 524 return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB || 525 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ? 526 false : true; 527 } 528 529 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) 530 { 531 struct be_adapter *adapter = netdev_priv(netdev); 532 u8 link_status; 533 u16 link_speed = 0; 534 int status; 535 u32 auto_speeds; 536 u32 fixed_speeds; 537 u32 dac_cable_len; 538 u16 interface_type; 539 540 if (adapter->phy.link_speed < 0) { 541 status = be_cmd_link_status_query(adapter, &link_speed, 542 &link_status, 0); 543 if (!status) 544 be_link_status_update(adapter, link_status); 545 ethtool_cmd_speed_set(ecmd, link_speed); 546 547 status = be_cmd_get_phy_info(adapter); 548 if (!status) { 549 interface_type = adapter->phy.interface_type; 550 auto_speeds = adapter->phy.auto_speeds_supported; 551 fixed_speeds = adapter->phy.fixed_speeds_supported; 552 dac_cable_len = adapter->phy.dac_cable_len; 553 554 ecmd->supported = 555 convert_to_et_setting(interface_type, 556 auto_speeds | 557 fixed_speeds); 558 ecmd->advertising = 559 convert_to_et_setting(interface_type, 560 auto_speeds); 561 562 ecmd->port = be_get_port_type(interface_type, 563 dac_cable_len); 564 565 if (adapter->phy.auto_speeds_supported) { 566 ecmd->supported |= SUPPORTED_Autoneg; 567 ecmd->autoneg = AUTONEG_ENABLE; 568 ecmd->advertising |= ADVERTISED_Autoneg; 569 } 570 571 ecmd->supported |= SUPPORTED_Pause; 572 if (be_pause_supported(adapter)) 573 ecmd->advertising |= ADVERTISED_Pause; 574 575 switch (adapter->phy.interface_type) { 576 case PHY_TYPE_KR_10GB: 577 case PHY_TYPE_KX4_10GB: 578 ecmd->transceiver = XCVR_INTERNAL; 579 break; 580 default: 581 ecmd->transceiver = XCVR_EXTERNAL; 582 break; 583 } 584 } else { 585 ecmd->port = PORT_OTHER; 586 ecmd->autoneg = AUTONEG_DISABLE; 587 ecmd->transceiver = XCVR_DUMMY1; 588 } 589 590 /* Save for future use */ 591 adapter->phy.link_speed = ethtool_cmd_speed(ecmd); 592 adapter->phy.port_type = ecmd->port; 593 adapter->phy.transceiver = ecmd->transceiver; 594 adapter->phy.autoneg = ecmd->autoneg; 595 adapter->phy.advertising = ecmd->advertising; 596 adapter->phy.supported = ecmd->supported; 597 } else { 598 ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed); 599 ecmd->port = adapter->phy.port_type; 600 ecmd->transceiver = adapter->phy.transceiver; 601 ecmd->autoneg = adapter->phy.autoneg; 602 ecmd->advertising = adapter->phy.advertising; 603 ecmd->supported = adapter->phy.supported; 604 } 605 606 ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN; 607 ecmd->phy_address = adapter->port_num; 608 609 return 0; 610 } 611 612 static void be_get_ringparam(struct net_device *netdev, 613 struct ethtool_ringparam *ring) 614 { 615 struct be_adapter *adapter = netdev_priv(netdev); 616 617 ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len; 618 ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len; 619 } 620 621 static void 622 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) 623 { 624 struct be_adapter *adapter = netdev_priv(netdev); 625 626 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause); 627 ecmd->autoneg = adapter->phy.fc_autoneg; 628 } 629 630 static int 631 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) 632 { 633 struct be_adapter *adapter = netdev_priv(netdev); 634 int status; 635 636 if (ecmd->autoneg != adapter->phy.fc_autoneg) 637 return -EINVAL; 638 adapter->tx_fc = ecmd->tx_pause; 639 adapter->rx_fc = ecmd->rx_pause; 640 641 status = be_cmd_set_flow_control(adapter, 642 adapter->tx_fc, adapter->rx_fc); 643 if (status) 644 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n"); 645 646 return status; 647 } 648 649 static int be_set_phys_id(struct net_device *netdev, 650 enum ethtool_phys_id_state state) 651 { 652 struct be_adapter *adapter = netdev_priv(netdev); 653 654 switch (state) { 655 case ETHTOOL_ID_ACTIVE: 656 be_cmd_get_beacon_state(adapter, adapter->hba_port_num, 657 &adapter->beacon_state); 658 return 1; /* cycle on/off once per second */ 659 660 case ETHTOOL_ID_ON: 661 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, 662 BEACON_STATE_ENABLED); 663 break; 664 665 case ETHTOOL_ID_OFF: 666 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, 667 BEACON_STATE_DISABLED); 668 break; 669 670 case ETHTOOL_ID_INACTIVE: 671 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, 672 adapter->beacon_state); 673 } 674 675 return 0; 676 } 677 678 static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump) 679 { 680 struct be_adapter *adapter = netdev_priv(netdev); 681 struct device *dev = &adapter->pdev->dev; 682 int status; 683 684 if (!lancer_chip(adapter)) { 685 dev_err(dev, "FW dump not supported\n"); 686 return -EOPNOTSUPP; 687 } 688 689 if (dump_present(adapter)) { 690 dev_err(dev, "Previous dump not cleared, not forcing dump\n"); 691 return 0; 692 } 693 694 switch (dump->flag) { 695 case LANCER_INITIATE_FW_DUMP: 696 status = lancer_initiate_dump(adapter); 697 if (!status) 698 dev_info(dev, "F/w dump initiated successfully\n"); 699 break; 700 default: 701 dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag); 702 return -EINVAL; 703 } 704 return status; 705 } 706 707 static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 708 { 709 struct be_adapter *adapter = netdev_priv(netdev); 710 711 if (adapter->wol_cap & BE_WOL_CAP) { 712 wol->supported |= WAKE_MAGIC; 713 if (adapter->wol_en) 714 wol->wolopts |= WAKE_MAGIC; 715 } else { 716 wol->wolopts = 0; 717 } 718 memset(&wol->sopass, 0, sizeof(wol->sopass)); 719 } 720 721 static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 722 { 723 struct be_adapter *adapter = netdev_priv(netdev); 724 725 if (wol->wolopts & ~WAKE_MAGIC) 726 return -EOPNOTSUPP; 727 728 if (!(adapter->wol_cap & BE_WOL_CAP)) { 729 dev_warn(&adapter->pdev->dev, "WOL not supported\n"); 730 return -EOPNOTSUPP; 731 } 732 733 if (wol->wolopts & WAKE_MAGIC) 734 adapter->wol_en = true; 735 else 736 adapter->wol_en = false; 737 738 return 0; 739 } 740 741 static int be_test_ddr_dma(struct be_adapter *adapter) 742 { 743 int ret, i; 744 struct be_dma_mem ddrdma_cmd; 745 static const u64 pattern[2] = { 746 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL 747 }; 748 749 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test); 750 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size, 751 &ddrdma_cmd.dma, GFP_KERNEL); 752 if (!ddrdma_cmd.va) 753 return -ENOMEM; 754 755 for (i = 0; i < 2; i++) { 756 ret = be_cmd_ddr_dma_test(adapter, pattern[i], 757 4096, &ddrdma_cmd); 758 if (ret != 0) 759 goto err; 760 } 761 762 err: 763 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va, 764 ddrdma_cmd.dma); 765 return ret; 766 } 767 768 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type, 769 u64 *status) 770 { 771 be_cmd_set_loopback(adapter, adapter->hba_port_num, loopback_type, 1); 772 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num, 773 loopback_type, 1500, 2, 0xabc); 774 be_cmd_set_loopback(adapter, adapter->hba_port_num, BE_NO_LOOPBACK, 1); 775 return *status; 776 } 777 778 static void be_self_test(struct net_device *netdev, struct ethtool_test *test, 779 u64 *data) 780 { 781 struct be_adapter *adapter = netdev_priv(netdev); 782 int status; 783 u8 link_status = 0; 784 785 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) { 786 dev_err(&adapter->pdev->dev, "Self test not supported\n"); 787 test->flags |= ETH_TEST_FL_FAILED; 788 return; 789 } 790 791 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM); 792 793 if (test->flags & ETH_TEST_FL_OFFLINE) { 794 if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0) 795 test->flags |= ETH_TEST_FL_FAILED; 796 797 if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0) 798 test->flags |= ETH_TEST_FL_FAILED; 799 800 if (test->flags & ETH_TEST_FL_EXTERNAL_LB) { 801 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK, 802 &data[2]) != 0) 803 test->flags |= ETH_TEST_FL_FAILED; 804 test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; 805 } 806 } 807 808 if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) { 809 data[3] = 1; 810 test->flags |= ETH_TEST_FL_FAILED; 811 } 812 813 status = be_cmd_link_status_query(adapter, NULL, &link_status, 0); 814 if (status) { 815 test->flags |= ETH_TEST_FL_FAILED; 816 data[4] = -1; 817 } else if (!link_status) { 818 test->flags |= ETH_TEST_FL_FAILED; 819 data[4] = 1; 820 } 821 } 822 823 static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl) 824 { 825 struct be_adapter *adapter = netdev_priv(netdev); 826 827 return be_load_fw(adapter, efl->data); 828 } 829 830 static int be_get_eeprom_len(struct net_device *netdev) 831 { 832 struct be_adapter *adapter = netdev_priv(netdev); 833 834 if (!check_privilege(adapter, MAX_PRIVILEGES)) 835 return 0; 836 837 if (lancer_chip(adapter)) { 838 if (be_physfn(adapter)) 839 return lancer_cmd_get_file_len(adapter, 840 LANCER_VPD_PF_FILE); 841 else 842 return lancer_cmd_get_file_len(adapter, 843 LANCER_VPD_VF_FILE); 844 } else { 845 return BE_READ_SEEPROM_LEN; 846 } 847 } 848 849 static int be_read_eeprom(struct net_device *netdev, 850 struct ethtool_eeprom *eeprom, uint8_t *data) 851 { 852 struct be_adapter *adapter = netdev_priv(netdev); 853 struct be_dma_mem eeprom_cmd; 854 struct be_cmd_resp_seeprom_read *resp; 855 int status; 856 857 if (!eeprom->len) 858 return -EINVAL; 859 860 if (lancer_chip(adapter)) { 861 if (be_physfn(adapter)) 862 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE, 863 eeprom->len, data); 864 else 865 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE, 866 eeprom->len, data); 867 } 868 869 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16); 870 871 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem)); 872 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read); 873 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size, 874 &eeprom_cmd.dma, GFP_KERNEL); 875 876 if (!eeprom_cmd.va) 877 return -ENOMEM; 878 879 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd); 880 881 if (!status) { 882 resp = eeprom_cmd.va; 883 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len); 884 } 885 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va, 886 eeprom_cmd.dma); 887 888 return status; 889 } 890 891 static u32 be_get_msg_level(struct net_device *netdev) 892 { 893 struct be_adapter *adapter = netdev_priv(netdev); 894 895 return adapter->msg_enable; 896 } 897 898 static void be_set_msg_level(struct net_device *netdev, u32 level) 899 { 900 struct be_adapter *adapter = netdev_priv(netdev); 901 902 if (adapter->msg_enable == level) 903 return; 904 905 if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW)) 906 if (BEx_chip(adapter)) 907 be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ? 908 FW_LOG_LEVEL_DEFAULT : 909 FW_LOG_LEVEL_FATAL); 910 adapter->msg_enable = level; 911 912 return; 913 } 914 915 static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type) 916 { 917 u64 data = 0; 918 919 switch (flow_type) { 920 case TCP_V4_FLOW: 921 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4) 922 data |= RXH_IP_DST | RXH_IP_SRC; 923 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4) 924 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 925 break; 926 case UDP_V4_FLOW: 927 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4) 928 data |= RXH_IP_DST | RXH_IP_SRC; 929 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4) 930 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 931 break; 932 case TCP_V6_FLOW: 933 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6) 934 data |= RXH_IP_DST | RXH_IP_SRC; 935 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6) 936 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 937 break; 938 case UDP_V6_FLOW: 939 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6) 940 data |= RXH_IP_DST | RXH_IP_SRC; 941 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6) 942 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 943 break; 944 } 945 946 return data; 947 } 948 949 static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, 950 u32 *rule_locs) 951 { 952 struct be_adapter *adapter = netdev_priv(netdev); 953 954 if (!be_multi_rxq(adapter)) { 955 dev_info(&adapter->pdev->dev, 956 "ethtool::get_rxnfc: RX flow hashing is disabled\n"); 957 return -EINVAL; 958 } 959 960 switch (cmd->cmd) { 961 case ETHTOOL_GRXFH: 962 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type); 963 break; 964 case ETHTOOL_GRXRINGS: 965 cmd->data = adapter->num_rx_qs - 1; 966 break; 967 default: 968 return -EINVAL; 969 } 970 971 return 0; 972 } 973 974 static int be_set_rss_hash_opts(struct be_adapter *adapter, 975 struct ethtool_rxnfc *cmd) 976 { 977 struct be_rx_obj *rxo; 978 int status = 0, i, j; 979 u8 rsstable[128]; 980 u32 rss_flags = adapter->rss_info.rss_flags; 981 982 if (cmd->data != L3_RSS_FLAGS && 983 cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS)) 984 return -EINVAL; 985 986 switch (cmd->flow_type) { 987 case TCP_V4_FLOW: 988 if (cmd->data == L3_RSS_FLAGS) 989 rss_flags &= ~RSS_ENABLE_TCP_IPV4; 990 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) 991 rss_flags |= RSS_ENABLE_IPV4 | 992 RSS_ENABLE_TCP_IPV4; 993 break; 994 case TCP_V6_FLOW: 995 if (cmd->data == L3_RSS_FLAGS) 996 rss_flags &= ~RSS_ENABLE_TCP_IPV6; 997 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) 998 rss_flags |= RSS_ENABLE_IPV6 | 999 RSS_ENABLE_TCP_IPV6; 1000 break; 1001 case UDP_V4_FLOW: 1002 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) && 1003 BEx_chip(adapter)) 1004 return -EINVAL; 1005 1006 if (cmd->data == L3_RSS_FLAGS) 1007 rss_flags &= ~RSS_ENABLE_UDP_IPV4; 1008 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) 1009 rss_flags |= RSS_ENABLE_IPV4 | 1010 RSS_ENABLE_UDP_IPV4; 1011 break; 1012 case UDP_V6_FLOW: 1013 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) && 1014 BEx_chip(adapter)) 1015 return -EINVAL; 1016 1017 if (cmd->data == L3_RSS_FLAGS) 1018 rss_flags &= ~RSS_ENABLE_UDP_IPV6; 1019 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) 1020 rss_flags |= RSS_ENABLE_IPV6 | 1021 RSS_ENABLE_UDP_IPV6; 1022 break; 1023 default: 1024 return -EINVAL; 1025 } 1026 1027 if (rss_flags == adapter->rss_info.rss_flags) 1028 return status; 1029 1030 if (be_multi_rxq(adapter)) { 1031 for (j = 0; j < 128; j += adapter->num_rx_qs - 1) { 1032 for_all_rss_queues(adapter, rxo, i) { 1033 if ((j + i) >= 128) 1034 break; 1035 rsstable[j + i] = rxo->rss_id; 1036 } 1037 } 1038 } 1039 1040 status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable, 1041 rss_flags, 128, adapter->rss_info.rss_hkey); 1042 if (!status) 1043 adapter->rss_info.rss_flags = rss_flags; 1044 1045 return status; 1046 } 1047 1048 static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) 1049 { 1050 struct be_adapter *adapter = netdev_priv(netdev); 1051 int status = 0; 1052 1053 if (!be_multi_rxq(adapter)) { 1054 dev_err(&adapter->pdev->dev, 1055 "ethtool::set_rxnfc: RX flow hashing is disabled\n"); 1056 return -EINVAL; 1057 } 1058 1059 switch (cmd->cmd) { 1060 case ETHTOOL_SRXFH: 1061 status = be_set_rss_hash_opts(adapter, cmd); 1062 break; 1063 default: 1064 return -EINVAL; 1065 } 1066 1067 return status; 1068 } 1069 1070 static void be_get_channels(struct net_device *netdev, 1071 struct ethtool_channels *ch) 1072 { 1073 struct be_adapter *adapter = netdev_priv(netdev); 1074 1075 ch->combined_count = adapter->num_evt_qs; 1076 ch->max_combined = be_max_qs(adapter); 1077 } 1078 1079 static int be_set_channels(struct net_device *netdev, 1080 struct ethtool_channels *ch) 1081 { 1082 struct be_adapter *adapter = netdev_priv(netdev); 1083 1084 if (ch->rx_count || ch->tx_count || ch->other_count || 1085 !ch->combined_count || ch->combined_count > be_max_qs(adapter)) 1086 return -EINVAL; 1087 1088 adapter->cfg_num_qs = ch->combined_count; 1089 1090 return be_update_queues(adapter); 1091 } 1092 1093 static u32 be_get_rxfh_indir_size(struct net_device *netdev) 1094 { 1095 return RSS_INDIR_TABLE_LEN; 1096 } 1097 1098 static u32 be_get_rxfh_key_size(struct net_device *netdev) 1099 { 1100 return RSS_HASH_KEY_LEN; 1101 } 1102 1103 static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey) 1104 { 1105 struct be_adapter *adapter = netdev_priv(netdev); 1106 int i; 1107 struct rss_info *rss = &adapter->rss_info; 1108 1109 if (indir) { 1110 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) 1111 indir[i] = rss->rss_queue[i]; 1112 } 1113 1114 if (hkey) 1115 memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN); 1116 1117 return 0; 1118 } 1119 1120 static int be_set_rxfh(struct net_device *netdev, const u32 *indir, 1121 const u8 *hkey) 1122 { 1123 int rc = 0, i, j; 1124 struct be_adapter *adapter = netdev_priv(netdev); 1125 u8 rsstable[RSS_INDIR_TABLE_LEN]; 1126 1127 if (indir) { 1128 struct be_rx_obj *rxo; 1129 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) { 1130 j = indir[i]; 1131 rxo = &adapter->rx_obj[j]; 1132 rsstable[i] = rxo->rss_id; 1133 adapter->rss_info.rss_queue[i] = j; 1134 } 1135 } else { 1136 memcpy(rsstable, adapter->rss_info.rsstable, 1137 RSS_INDIR_TABLE_LEN); 1138 } 1139 1140 if (!hkey) 1141 hkey = adapter->rss_info.rss_hkey; 1142 1143 rc = be_cmd_rss_config(adapter, rsstable, 1144 adapter->rss_info.rss_flags, 1145 RSS_INDIR_TABLE_LEN, hkey); 1146 if (rc) { 1147 adapter->rss_info.rss_flags = RSS_ENABLE_NONE; 1148 return -EIO; 1149 } 1150 memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN); 1151 memcpy(adapter->rss_info.rsstable, rsstable, 1152 RSS_INDIR_TABLE_LEN); 1153 return 0; 1154 } 1155 1156 const struct ethtool_ops be_ethtool_ops = { 1157 .get_settings = be_get_settings, 1158 .get_drvinfo = be_get_drvinfo, 1159 .get_wol = be_get_wol, 1160 .set_wol = be_set_wol, 1161 .get_link = ethtool_op_get_link, 1162 .get_eeprom_len = be_get_eeprom_len, 1163 .get_eeprom = be_read_eeprom, 1164 .get_coalesce = be_get_coalesce, 1165 .set_coalesce = be_set_coalesce, 1166 .get_ringparam = be_get_ringparam, 1167 .get_pauseparam = be_get_pauseparam, 1168 .set_pauseparam = be_set_pauseparam, 1169 .get_strings = be_get_stat_strings, 1170 .set_phys_id = be_set_phys_id, 1171 .set_dump = be_set_dump, 1172 .get_msglevel = be_get_msg_level, 1173 .set_msglevel = be_set_msg_level, 1174 .get_sset_count = be_get_sset_count, 1175 .get_ethtool_stats = be_get_ethtool_stats, 1176 .get_regs_len = be_get_reg_len, 1177 .get_regs = be_get_regs, 1178 .flash_device = be_do_flash, 1179 .self_test = be_self_test, 1180 .get_rxnfc = be_get_rxnfc, 1181 .set_rxnfc = be_set_rxnfc, 1182 .get_rxfh_indir_size = be_get_rxfh_indir_size, 1183 .get_rxfh_key_size = be_get_rxfh_key_size, 1184 .get_rxfh = be_get_rxfh, 1185 .set_rxfh = be_set_rxfh, 1186 .get_channels = be_get_channels, 1187 .set_channels = be_set_channels 1188 }; 1189