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