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