1 /****************************************************************************
 
   2  * Driver for Solarflare Solarstorm network controllers and boards
 
   3  * Copyright 2005-2006 Fen Systems Ltd.
 
   4  * Copyright 2006-2008 Solarflare Communications Inc.
 
   6  * This program is free software; you can redistribute it and/or modify it
 
   7  * under the terms of the GNU General Public License version 2 as published
 
   8  * by the Free Software Foundation, incorporated herein by reference.
 
  11 #include <linux/netdevice.h>
 
  12 #include <linux/ethtool.h>
 
  13 #include <linux/rtnetlink.h>
 
  14 #include "net_driver.h"
 
  15 #include "workarounds.h"
 
  23 const char *efx_loopback_mode_names[] = {
 
  24         [LOOPBACK_NONE]         = "NONE",
 
  25         [LOOPBACK_GMAC]         = "GMAC",
 
  26         [LOOPBACK_XGMII]        = "XGMII",
 
  27         [LOOPBACK_XGXS]         = "XGXS",
 
  28         [LOOPBACK_XAUI]         = "XAUI",
 
  29         [LOOPBACK_GPHY]         = "GPHY",
 
  30         [LOOPBACK_PHYXS]        = "PHYXS",
 
  31         [LOOPBACK_PCS]          = "PCS",
 
  32         [LOOPBACK_PMAPMD]       = "PMA/PMD",
 
  33         [LOOPBACK_NETWORK]      = "NETWORK",
 
  36 struct ethtool_string {
 
  37         char name[ETH_GSTRING_LEN];
 
  40 struct efx_ethtool_stat {
 
  43                 EFX_ETHTOOL_STAT_SOURCE_mac_stats,
 
  44                 EFX_ETHTOOL_STAT_SOURCE_nic,
 
  45                 EFX_ETHTOOL_STAT_SOURCE_channel
 
  48         u64(*get_stat) (void *field); /* Reader function */
 
  51 /* Initialiser for a struct #efx_ethtool_stat with type-checking */
 
  52 #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
 
  53                                 get_stat_function) {                    \
 
  55         .source = EFX_ETHTOOL_STAT_SOURCE_##source_name,                \
 
  56         .offset = ((((field_type *) 0) ==                               \
 
  57                       &((struct efx_##source_name *)0)->field) ?        \
 
  58                     offsetof(struct efx_##source_name, field) :         \
 
  59                     offsetof(struct efx_##source_name, field)),         \
 
  60         .get_stat = get_stat_function,                                  \
 
  63 static u64 efx_get_uint_stat(void *field)
 
  65         return *(unsigned int *)field;
 
  68 static u64 efx_get_ulong_stat(void *field)
 
  70         return *(unsigned long *)field;
 
  73 static u64 efx_get_u64_stat(void *field)
 
  75         return *(u64 *) field;
 
  78 static u64 efx_get_atomic_stat(void *field)
 
  80         return atomic_read((atomic_t *) field);
 
  83 #define EFX_ETHTOOL_ULONG_MAC_STAT(field)                       \
 
  84         EFX_ETHTOOL_STAT(field, mac_stats, field,               \
 
  85                           unsigned long, efx_get_ulong_stat)
 
  87 #define EFX_ETHTOOL_U64_MAC_STAT(field)                         \
 
  88         EFX_ETHTOOL_STAT(field, mac_stats, field,               \
 
  89                           u64, efx_get_u64_stat)
 
  91 #define EFX_ETHTOOL_UINT_NIC_STAT(name)                         \
 
  92         EFX_ETHTOOL_STAT(name, nic, n_##name,                   \
 
  93                          unsigned int, efx_get_uint_stat)
 
  95 #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field)                \
 
  96         EFX_ETHTOOL_STAT(field, nic, field,                     \
 
  97                          atomic_t, efx_get_atomic_stat)
 
  99 #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field)                    \
 
 100         EFX_ETHTOOL_STAT(field, channel, n_##field,             \
 
 101                          unsigned int, efx_get_uint_stat)
 
 103 static struct efx_ethtool_stat efx_ethtool_stats[] = {
 
 104         EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
 
 105         EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
 
 106         EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
 
 107         EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
 
 108         EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
 
 109         EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
 
 110         EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
 
 111         EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
 
 112         EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
 
 113         EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
 
 114         EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
 
 115         EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
 
 116         EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
 
 117         EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
 
 118         EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
 
 119         EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
 
 120         EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
 
 121         EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
 
 122         EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
 
 123         EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
 
 124         EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
 
 125         EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
 
 126         EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
 
 127         EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
 
 128         EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
 
 129         EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
 
 130         EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
 
 131         EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
 
 132         EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
 
 133         EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
 
 134         EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
 
 135         EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
 
 136         EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
 
 137         EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
 
 138         EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
 
 139         EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
 
 140         EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
 
 141         EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
 
 142         EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
 
 143         EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
 
 144         EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
 
 145         EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
 
 146         EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
 
 147         EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
 
 148         EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
 
 149         EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
 
 150         EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
 
 151         EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
 
 152         EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
 
 153         EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
 
 154         EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
 
 155         EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
 
 156         EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
 
 157         EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
 
 158         EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
 
 159         EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
 
 160         EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
 
 161         EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
 
 162         EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
 
 163         EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
 
 164         EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
 
 165         EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
 
 166         EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
 
 167         EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
 
 168         EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
 
 169         EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
 
 172 /* Number of ethtool statistics */
 
 173 #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
 
 175 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
 
 177 /**************************************************************************
 
 181  **************************************************************************
 
 184 /* Identify device by flashing LEDs */
 
 185 static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count)
 
 187         struct efx_nic *efx = netdev_priv(net_dev);
 
 189         efx->board_info.blink(efx, 1);
 
 190         set_current_state(TASK_INTERRUPTIBLE);
 
 192                 schedule_timeout(count * HZ);
 
 195         efx->board_info.blink(efx, 0);
 
 199 /* This must be called with rtnl_lock held. */
 
 200 int efx_ethtool_get_settings(struct net_device *net_dev,
 
 201                              struct ethtool_cmd *ecmd)
 
 203         struct efx_nic *efx = netdev_priv(net_dev);
 
 205         mutex_lock(&efx->mac_lock);
 
 206         efx->phy_op->get_settings(efx, ecmd);
 
 207         mutex_unlock(&efx->mac_lock);
 
 209         /* Falcon GMAC does not support 1000Mbps HD */
 
 210         ecmd->supported &= ~SUPPORTED_1000baseT_Half;
 
 215 /* This must be called with rtnl_lock held. */
 
 216 int efx_ethtool_set_settings(struct net_device *net_dev,
 
 217                              struct ethtool_cmd *ecmd)
 
 219         struct efx_nic *efx = netdev_priv(net_dev);
 
 222         if (EFX_WORKAROUND_13963(efx) && !ecmd->autoneg)
 
 225         /* Falcon GMAC does not support 1000Mbps HD */
 
 226         if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) {
 
 227                 EFX_LOG(efx, "rejecting unsupported 1000Mbps HD"
 
 232         mutex_lock(&efx->mac_lock);
 
 233         rc = efx->phy_op->set_settings(efx, ecmd);
 
 234         mutex_unlock(&efx->mac_lock);
 
 236                 efx_reconfigure_port(efx);
 
 241 static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
 
 242                                     struct ethtool_drvinfo *info)
 
 244         struct efx_nic *efx = netdev_priv(net_dev);
 
 246         strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver));
 
 247         strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
 
 248         strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
 
 252  * efx_fill_test - fill in an individual self-test entry
 
 253  * @test_index:         Index of the test
 
 254  * @strings:            Ethtool strings, or %NULL
 
 255  * @data:               Ethtool test results, or %NULL
 
 256  * @test:               Pointer to test result (used only if data != %NULL)
 
 257  * @unit_format:        Unit name format (e.g. "chan\%d")
 
 258  * @unit_id:            Unit id (e.g. 0 for "chan0")
 
 259  * @test_format:        Test name format (e.g. "loopback.\%s.tx.sent")
 
 260  * @test_id:            Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
 
 262  * Fill in an individual self-test entry.
 
 264 static void efx_fill_test(unsigned int test_index,
 
 265                           struct ethtool_string *strings, u64 *data,
 
 266                           int *test, const char *unit_format, int unit_id,
 
 267                           const char *test_format, const char *test_id)
 
 269         struct ethtool_string unit_str, test_str;
 
 271         /* Fill data value, if applicable */
 
 273                 data[test_index] = *test;
 
 275         /* Fill string, if applicable */
 
 277                 if (strchr(unit_format, '%'))
 
 278                         snprintf(unit_str.name, sizeof(unit_str.name),
 
 279                                  unit_format, unit_id);
 
 281                         strcpy(unit_str.name, unit_format);
 
 282                 snprintf(test_str.name, sizeof(test_str.name),
 
 283                          test_format, test_id);
 
 284                 snprintf(strings[test_index].name,
 
 285                          sizeof(strings[test_index].name),
 
 286                          "%-6s %-24s", unit_str.name, test_str.name);
 
 290 #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
 
 291 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
 
 292 #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
 
 293 #define EFX_LOOPBACK_NAME(_mode, _counter)                      \
 
 294         "loopback.%s." _counter, LOOPBACK_MODE_NAME(mode)
 
 297  * efx_fill_loopback_test - fill in a block of loopback self-test entries
 
 299  * @lb_tests:           Efx loopback self-test results structure
 
 300  * @mode:               Loopback test mode
 
 301  * @test_index:         Starting index of the test
 
 302  * @strings:            Ethtool strings, or %NULL
 
 303  * @data:               Ethtool test results, or %NULL
 
 305 static int efx_fill_loopback_test(struct efx_nic *efx,
 
 306                                   struct efx_loopback_self_tests *lb_tests,
 
 307                                   enum efx_loopback_mode mode,
 
 308                                   unsigned int test_index,
 
 309                                   struct ethtool_string *strings, u64 *data)
 
 311         struct efx_tx_queue *tx_queue;
 
 313         efx_for_each_tx_queue(tx_queue, efx) {
 
 314                 efx_fill_test(test_index++, strings, data,
 
 315                               &lb_tests->tx_sent[tx_queue->queue],
 
 316                               EFX_TX_QUEUE_NAME(tx_queue),
 
 317                               EFX_LOOPBACK_NAME(mode, "tx_sent"));
 
 318                 efx_fill_test(test_index++, strings, data,
 
 319                               &lb_tests->tx_done[tx_queue->queue],
 
 320                               EFX_TX_QUEUE_NAME(tx_queue),
 
 321                               EFX_LOOPBACK_NAME(mode, "tx_done"));
 
 323         efx_fill_test(test_index++, strings, data,
 
 326                       EFX_LOOPBACK_NAME(mode, "rx_good"));
 
 327         efx_fill_test(test_index++, strings, data,
 
 330                       EFX_LOOPBACK_NAME(mode, "rx_bad"));
 
 336  * efx_ethtool_fill_self_tests - get self-test details
 
 338  * @tests:              Efx self-test results structure, or %NULL
 
 339  * @strings:            Ethtool strings, or %NULL
 
 340  * @data:               Ethtool test results, or %NULL
 
 342 static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
 
 343                                        struct efx_self_tests *tests,
 
 344                                        struct ethtool_string *strings,
 
 347         struct efx_channel *channel;
 
 348         unsigned int n = 0, i;
 
 349         enum efx_loopback_mode mode;
 
 351         efx_fill_test(n++, strings, data, &tests->mii,
 
 352                       "core", 0, "mii", NULL);
 
 353         efx_fill_test(n++, strings, data, &tests->nvram,
 
 354                       "core", 0, "nvram", NULL);
 
 355         efx_fill_test(n++, strings, data, &tests->interrupt,
 
 356                       "core", 0, "interrupt", NULL);
 
 359         efx_for_each_channel(channel, efx) {
 
 360                 efx_fill_test(n++, strings, data,
 
 361                               &tests->eventq_dma[channel->channel],
 
 362                               EFX_CHANNEL_NAME(channel),
 
 364                 efx_fill_test(n++, strings, data,
 
 365                               &tests->eventq_int[channel->channel],
 
 366                               EFX_CHANNEL_NAME(channel),
 
 368                 efx_fill_test(n++, strings, data,
 
 369                               &tests->eventq_poll[channel->channel],
 
 370                               EFX_CHANNEL_NAME(channel),
 
 371                               "eventq.poll", NULL);
 
 374         efx_fill_test(n++, strings, data, &tests->registers,
 
 375                       "core", 0, "registers", NULL);
 
 377         for (i = 0; i < efx->phy_op->num_tests; i++)
 
 378                 efx_fill_test(n++, strings, data, &tests->phy[i],
 
 379                               "phy", 0, efx->phy_op->test_names[i], NULL);
 
 382         for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
 
 383                 if (!(efx->loopback_modes & (1 << mode)))
 
 385                 n = efx_fill_loopback_test(efx,
 
 386                                            &tests->loopback[mode], mode, n,
 
 393 static int efx_ethtool_get_sset_count(struct net_device *net_dev,
 
 396         switch (string_set) {
 
 398                 return EFX_ETHTOOL_NUM_STATS;
 
 400                 return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
 
 407 static void efx_ethtool_get_strings(struct net_device *net_dev,
 
 408                                     u32 string_set, u8 *strings)
 
 410         struct efx_nic *efx = netdev_priv(net_dev);
 
 411         struct ethtool_string *ethtool_strings =
 
 412                 (struct ethtool_string *)strings;
 
 415         switch (string_set) {
 
 417                 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
 
 418                         strncpy(ethtool_strings[i].name,
 
 419                                 efx_ethtool_stats[i].name,
 
 420                                 sizeof(ethtool_strings[i].name));
 
 423                 efx_ethtool_fill_self_tests(efx, NULL,
 
 424                                             ethtool_strings, NULL);
 
 427                 /* No other string sets */
 
 432 static void efx_ethtool_get_stats(struct net_device *net_dev,
 
 433                                   struct ethtool_stats *stats,
 
 436         struct efx_nic *efx = netdev_priv(net_dev);
 
 437         struct efx_mac_stats *mac_stats = &efx->mac_stats;
 
 438         struct efx_ethtool_stat *stat;
 
 439         struct efx_channel *channel;
 
 442         EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
 
 444         /* Update MAC and NIC statistics */
 
 445         dev_get_stats(net_dev);
 
 447         /* Fill detailed statistics buffer */
 
 448         for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
 
 449                 stat = &efx_ethtool_stats[i];
 
 450                 switch (stat->source) {
 
 451                 case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
 
 452                         data[i] = stat->get_stat((void *)mac_stats +
 
 455                 case EFX_ETHTOOL_STAT_SOURCE_nic:
 
 456                         data[i] = stat->get_stat((void *)efx + stat->offset);
 
 458                 case EFX_ETHTOOL_STAT_SOURCE_channel:
 
 460                         efx_for_each_channel(channel, efx)
 
 461                                 data[i] += stat->get_stat((void *)channel +
 
 468 static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
 
 470         struct efx_nic *efx = netdev_priv(net_dev);
 
 472         /* No way to stop the hardware doing the checks; we just
 
 475         efx->rx_checksum_enabled = !!enable;
 
 480 static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
 
 482         struct efx_nic *efx = netdev_priv(net_dev);
 
 484         return efx->rx_checksum_enabled;
 
 487 static void efx_ethtool_self_test(struct net_device *net_dev,
 
 488                                   struct ethtool_test *test, u64 *data)
 
 490         struct efx_nic *efx = netdev_priv(net_dev);
 
 491         struct efx_self_tests efx_tests;
 
 496         if (efx->state != STATE_RUNNING) {
 
 501         /* We need rx buffers and interrupts. */
 
 502         already_up = (efx->net_dev->flags & IFF_UP);
 
 504                 rc = dev_open(efx->net_dev);
 
 506                         EFX_ERR(efx, "failed opening device.\n");
 
 511         memset(&efx_tests, 0, sizeof(efx_tests));
 
 513         rc = efx_selftest(efx, &efx_tests, test->flags);
 
 516                 dev_close(efx->net_dev);
 
 518         EFX_LOG(efx, "%s %sline self-tests\n",
 
 519                 rc == 0 ? "passed" : "failed",
 
 520                 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
 
 524         /* Fill ethtool results structures */
 
 525         efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
 
 527                 test->flags |= ETH_TEST_FL_FAILED;
 
 530 /* Restart autonegotiation */
 
 531 static int efx_ethtool_nway_reset(struct net_device *net_dev)
 
 533         struct efx_nic *efx = netdev_priv(net_dev);
 
 535         return mii_nway_restart(&efx->mii);
 
 538 static u32 efx_ethtool_get_link(struct net_device *net_dev)
 
 540         struct efx_nic *efx = netdev_priv(net_dev);
 
 545 static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
 
 547         struct efx_nic *efx = netdev_priv(net_dev);
 
 548         struct efx_spi_device *spi = efx->spi_eeprom;
 
 552         return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
 
 553                 min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
 
 556 static int efx_ethtool_get_eeprom(struct net_device *net_dev,
 
 557                                   struct ethtool_eeprom *eeprom, u8 *buf)
 
 559         struct efx_nic *efx = netdev_priv(net_dev);
 
 560         struct efx_spi_device *spi = efx->spi_eeprom;
 
 564         rc = mutex_lock_interruptible(&efx->spi_lock);
 
 567         rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
 
 568                              eeprom->len, &len, buf);
 
 569         mutex_unlock(&efx->spi_lock);
 
 571         eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
 
 576 static int efx_ethtool_set_eeprom(struct net_device *net_dev,
 
 577                                   struct ethtool_eeprom *eeprom, u8 *buf)
 
 579         struct efx_nic *efx = netdev_priv(net_dev);
 
 580         struct efx_spi_device *spi = efx->spi_eeprom;
 
 584         if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
 
 587         rc = mutex_lock_interruptible(&efx->spi_lock);
 
 590         rc = falcon_spi_write(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
 
 591                               eeprom->len, &len, buf);
 
 592         mutex_unlock(&efx->spi_lock);
 
 598 static int efx_ethtool_get_coalesce(struct net_device *net_dev,
 
 599                                     struct ethtool_coalesce *coalesce)
 
 601         struct efx_nic *efx = netdev_priv(net_dev);
 
 602         struct efx_tx_queue *tx_queue;
 
 603         struct efx_rx_queue *rx_queue;
 
 604         struct efx_channel *channel;
 
 606         memset(coalesce, 0, sizeof(*coalesce));
 
 608         /* Find lowest IRQ moderation across all used TX queues */
 
 609         coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
 
 610         efx_for_each_tx_queue(tx_queue, efx) {
 
 611                 channel = tx_queue->channel;
 
 612                 if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
 
 613                         if (channel->used_flags != EFX_USED_BY_RX_TX)
 
 614                                 coalesce->tx_coalesce_usecs_irq =
 
 615                                         channel->irq_moderation;
 
 617                                 coalesce->tx_coalesce_usecs_irq = 0;
 
 621         /* Find lowest IRQ moderation across all used RX queues */
 
 622         coalesce->rx_coalesce_usecs_irq = ~((u32) 0);
 
 623         efx_for_each_rx_queue(rx_queue, efx) {
 
 624                 channel = rx_queue->channel;
 
 625                 if (channel->irq_moderation < coalesce->rx_coalesce_usecs_irq)
 
 626                         coalesce->rx_coalesce_usecs_irq =
 
 627                                 channel->irq_moderation;
 
 633 /* Set coalescing parameters
 
 634  * The difficulties occur for shared channels
 
 636 static int efx_ethtool_set_coalesce(struct net_device *net_dev,
 
 637                                     struct ethtool_coalesce *coalesce)
 
 639         struct efx_nic *efx = netdev_priv(net_dev);
 
 640         struct efx_channel *channel;
 
 641         struct efx_tx_queue *tx_queue;
 
 642         unsigned tx_usecs, rx_usecs;
 
 644         if (coalesce->use_adaptive_rx_coalesce ||
 
 645             coalesce->use_adaptive_tx_coalesce)
 
 648         if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
 
 649                 EFX_ERR(efx, "invalid coalescing setting. "
 
 650                         "Only rx/tx_coalesce_usecs_irq are supported\n");
 
 654         rx_usecs = coalesce->rx_coalesce_usecs_irq;
 
 655         tx_usecs = coalesce->tx_coalesce_usecs_irq;
 
 657         /* If the channel is shared only allow RX parameters to be set */
 
 658         efx_for_each_tx_queue(tx_queue, efx) {
 
 659                 if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) &&
 
 661                         EFX_ERR(efx, "Channel is shared. "
 
 662                                 "Only RX coalescing may be set\n");
 
 667         efx_init_irq_moderation(efx, tx_usecs, rx_usecs);
 
 669         /* Reset channel to pick up new moderation value.  Note that
 
 670          * this may change the value of the irq_moderation field
 
 671          * (e.g. to allow for hardware timer granularity).
 
 673         efx_for_each_channel(channel, efx)
 
 674                 falcon_set_int_moderation(channel);
 
 679 static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
 
 680                                       struct ethtool_pauseparam *pause)
 
 682         struct efx_nic *efx = netdev_priv(net_dev);
 
 683         enum efx_fc_type wanted_fc;
 
 686         wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
 
 687                      (pause->tx_pause ? EFX_FC_TX : 0) |
 
 688                      (pause->autoneg ? EFX_FC_AUTO : 0));
 
 690         if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
 
 691                 EFX_LOG(efx, "Flow control unsupported: tx ON rx OFF\n");
 
 695         if (!(efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)) &&
 
 696             (wanted_fc & EFX_FC_AUTO)) {
 
 697                 EFX_LOG(efx, "PHY does not support flow control "
 
 698                         "autonegotiation\n");
 
 702         /* TX flow control may automatically turn itself off if the
 
 703          * link partner (intermittently) stops responding to pause
 
 704          * frames. There isn't any indication that this has happened,
 
 705          * so the best we do is leave it up to the user to spot this
 
 706          * and fix it be cycling transmit flow control on this end. */
 
 707         reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
 
 708         if (EFX_WORKAROUND_11482(efx) && reset) {
 
 709                 if (falcon_rev(efx) >= FALCON_REV_B0) {
 
 710                         /* Recover by resetting the EM block */
 
 712                                 falcon_drain_tx_fifo(efx);
 
 714                         /* Schedule a reset to recover */
 
 715                         efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
 
 719         /* Try to push the pause parameters */
 
 720         mutex_lock(&efx->mac_lock);
 
 722         efx->wanted_fc = wanted_fc;
 
 723         mdio_clause45_set_pause(efx);
 
 724         __efx_reconfigure_port(efx);
 
 726         mutex_unlock(&efx->mac_lock);
 
 731 static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
 
 732                                        struct ethtool_pauseparam *pause)
 
 734         struct efx_nic *efx = netdev_priv(net_dev);
 
 736         pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
 
 737         pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
 
 738         pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
 
 742 struct ethtool_ops efx_ethtool_ops = {
 
 743         .get_settings           = efx_ethtool_get_settings,
 
 744         .set_settings           = efx_ethtool_set_settings,
 
 745         .get_drvinfo            = efx_ethtool_get_drvinfo,
 
 746         .nway_reset             = efx_ethtool_nway_reset,
 
 747         .get_link               = efx_ethtool_get_link,
 
 748         .get_eeprom_len         = efx_ethtool_get_eeprom_len,
 
 749         .get_eeprom             = efx_ethtool_get_eeprom,
 
 750         .set_eeprom             = efx_ethtool_set_eeprom,
 
 751         .get_coalesce           = efx_ethtool_get_coalesce,
 
 752         .set_coalesce           = efx_ethtool_set_coalesce,
 
 753         .get_pauseparam         = efx_ethtool_get_pauseparam,
 
 754         .set_pauseparam         = efx_ethtool_set_pauseparam,
 
 755         .get_rx_csum            = efx_ethtool_get_rx_csum,
 
 756         .set_rx_csum            = efx_ethtool_set_rx_csum,
 
 757         .get_tx_csum            = ethtool_op_get_tx_csum,
 
 758         .set_tx_csum            = ethtool_op_set_tx_csum,
 
 759         .get_sg                 = ethtool_op_get_sg,
 
 760         .set_sg                 = ethtool_op_set_sg,
 
 761         .get_tso                = ethtool_op_get_tso,
 
 762         .set_tso                = ethtool_op_set_tso,
 
 763         .get_flags              = ethtool_op_get_flags,
 
 764         .set_flags              = ethtool_op_set_flags,
 
 765         .get_sset_count         = efx_ethtool_get_sset_count,
 
 766         .self_test              = efx_ethtool_self_test,
 
 767         .get_strings            = efx_ethtool_get_strings,
 
 768         .phys_id                = efx_ethtool_phys_id,
 
 769         .get_ethtool_stats      = efx_ethtool_get_stats,