linux/drivers/net/ethernet/qlogic/qlge/qlge_ethtool.c
<<
>>
Prefs
   1#include <linux/kernel.h>
   2#include <linux/init.h>
   3#include <linux/types.h>
   4#include <linux/module.h>
   5#include <linux/list.h>
   6#include <linux/pci.h>
   7#include <linux/dma-mapping.h>
   8#include <linux/pagemap.h>
   9#include <linux/sched.h>
  10#include <linux/dmapool.h>
  11#include <linux/mempool.h>
  12#include <linux/spinlock.h>
  13#include <linux/kthread.h>
  14#include <linux/interrupt.h>
  15#include <linux/errno.h>
  16#include <linux/ioport.h>
  17#include <linux/in.h>
  18#include <linux/ip.h>
  19#include <linux/ipv6.h>
  20#include <net/ipv6.h>
  21#include <linux/tcp.h>
  22#include <linux/udp.h>
  23#include <linux/if_arp.h>
  24#include <linux/if_ether.h>
  25#include <linux/netdevice.h>
  26#include <linux/etherdevice.h>
  27#include <linux/ethtool.h>
  28#include <linux/skbuff.h>
  29#include <linux/rtnetlink.h>
  30#include <linux/if_vlan.h>
  31#include <linux/delay.h>
  32#include <linux/mm.h>
  33#include <linux/vmalloc.h>
  34
  35
  36#include "qlge.h"
  37
  38struct ql_stats {
  39        char stat_string[ETH_GSTRING_LEN];
  40        int sizeof_stat;
  41        int stat_offset;
  42};
  43
  44#define QL_SIZEOF(m) FIELD_SIZEOF(struct ql_adapter, m)
  45#define QL_OFF(m) offsetof(struct ql_adapter, m)
  46
  47static const struct ql_stats ql_gstrings_stats[] = {
  48        {"tx_pkts", QL_SIZEOF(nic_stats.tx_pkts), QL_OFF(nic_stats.tx_pkts)},
  49        {"tx_bytes", QL_SIZEOF(nic_stats.tx_bytes), QL_OFF(nic_stats.tx_bytes)},
  50        {"tx_mcast_pkts", QL_SIZEOF(nic_stats.tx_mcast_pkts),
  51                                        QL_OFF(nic_stats.tx_mcast_pkts)},
  52        {"tx_bcast_pkts", QL_SIZEOF(nic_stats.tx_bcast_pkts),
  53                                        QL_OFF(nic_stats.tx_bcast_pkts)},
  54        {"tx_ucast_pkts", QL_SIZEOF(nic_stats.tx_ucast_pkts),
  55                                        QL_OFF(nic_stats.tx_ucast_pkts)},
  56        {"tx_ctl_pkts", QL_SIZEOF(nic_stats.tx_ctl_pkts),
  57                                        QL_OFF(nic_stats.tx_ctl_pkts)},
  58        {"tx_pause_pkts", QL_SIZEOF(nic_stats.tx_pause_pkts),
  59                                        QL_OFF(nic_stats.tx_pause_pkts)},
  60        {"tx_64_pkts", QL_SIZEOF(nic_stats.tx_64_pkt),
  61                                        QL_OFF(nic_stats.tx_64_pkt)},
  62        {"tx_65_to_127_pkts", QL_SIZEOF(nic_stats.tx_65_to_127_pkt),
  63                                        QL_OFF(nic_stats.tx_65_to_127_pkt)},
  64        {"tx_128_to_255_pkts", QL_SIZEOF(nic_stats.tx_128_to_255_pkt),
  65                                        QL_OFF(nic_stats.tx_128_to_255_pkt)},
  66        {"tx_256_511_pkts", QL_SIZEOF(nic_stats.tx_256_511_pkt),
  67                                        QL_OFF(nic_stats.tx_256_511_pkt)},
  68        {"tx_512_to_1023_pkts", QL_SIZEOF(nic_stats.tx_512_to_1023_pkt),
  69                                        QL_OFF(nic_stats.tx_512_to_1023_pkt)},
  70        {"tx_1024_to_1518_pkts", QL_SIZEOF(nic_stats.tx_1024_to_1518_pkt),
  71                                        QL_OFF(nic_stats.tx_1024_to_1518_pkt)},
  72        {"tx_1519_to_max_pkts", QL_SIZEOF(nic_stats.tx_1519_to_max_pkt),
  73                                        QL_OFF(nic_stats.tx_1519_to_max_pkt)},
  74        {"tx_undersize_pkts", QL_SIZEOF(nic_stats.tx_undersize_pkt),
  75                                        QL_OFF(nic_stats.tx_undersize_pkt)},
  76        {"tx_oversize_pkts", QL_SIZEOF(nic_stats.tx_oversize_pkt),
  77                                        QL_OFF(nic_stats.tx_oversize_pkt)},
  78        {"rx_bytes", QL_SIZEOF(nic_stats.rx_bytes), QL_OFF(nic_stats.rx_bytes)},
  79        {"rx_bytes_ok", QL_SIZEOF(nic_stats.rx_bytes_ok),
  80                                        QL_OFF(nic_stats.rx_bytes_ok)},
  81        {"rx_pkts", QL_SIZEOF(nic_stats.rx_pkts), QL_OFF(nic_stats.rx_pkts)},
  82        {"rx_pkts_ok", QL_SIZEOF(nic_stats.rx_pkts_ok),
  83                                        QL_OFF(nic_stats.rx_pkts_ok)},
  84        {"rx_bcast_pkts", QL_SIZEOF(nic_stats.rx_bcast_pkts),
  85                                        QL_OFF(nic_stats.rx_bcast_pkts)},
  86        {"rx_mcast_pkts", QL_SIZEOF(nic_stats.rx_mcast_pkts),
  87                                        QL_OFF(nic_stats.rx_mcast_pkts)},
  88        {"rx_ucast_pkts", QL_SIZEOF(nic_stats.rx_ucast_pkts),
  89                                        QL_OFF(nic_stats.rx_ucast_pkts)},
  90        {"rx_undersize_pkts", QL_SIZEOF(nic_stats.rx_undersize_pkts),
  91                                        QL_OFF(nic_stats.rx_undersize_pkts)},
  92        {"rx_oversize_pkts", QL_SIZEOF(nic_stats.rx_oversize_pkts),
  93                                        QL_OFF(nic_stats.rx_oversize_pkts)},
  94        {"rx_jabber_pkts", QL_SIZEOF(nic_stats.rx_jabber_pkts),
  95                                        QL_OFF(nic_stats.rx_jabber_pkts)},
  96        {"rx_undersize_fcerr_pkts",
  97                QL_SIZEOF(nic_stats.rx_undersize_fcerr_pkts),
  98                                QL_OFF(nic_stats.rx_undersize_fcerr_pkts)},
  99        {"rx_drop_events", QL_SIZEOF(nic_stats.rx_drop_events),
 100                                        QL_OFF(nic_stats.rx_drop_events)},
 101        {"rx_fcerr_pkts", QL_SIZEOF(nic_stats.rx_fcerr_pkts),
 102                                        QL_OFF(nic_stats.rx_fcerr_pkts)},
 103        {"rx_align_err", QL_SIZEOF(nic_stats.rx_align_err),
 104                                        QL_OFF(nic_stats.rx_align_err)},
 105        {"rx_symbol_err", QL_SIZEOF(nic_stats.rx_symbol_err),
 106                                        QL_OFF(nic_stats.rx_symbol_err)},
 107        {"rx_mac_err", QL_SIZEOF(nic_stats.rx_mac_err),
 108                                        QL_OFF(nic_stats.rx_mac_err)},
 109        {"rx_ctl_pkts", QL_SIZEOF(nic_stats.rx_ctl_pkts),
 110                                        QL_OFF(nic_stats.rx_ctl_pkts)},
 111        {"rx_pause_pkts", QL_SIZEOF(nic_stats.rx_pause_pkts),
 112                                        QL_OFF(nic_stats.rx_pause_pkts)},
 113        {"rx_64_pkts", QL_SIZEOF(nic_stats.rx_64_pkts),
 114                                        QL_OFF(nic_stats.rx_64_pkts)},
 115        {"rx_65_to_127_pkts", QL_SIZEOF(nic_stats.rx_65_to_127_pkts),
 116                                        QL_OFF(nic_stats.rx_65_to_127_pkts)},
 117        {"rx_128_255_pkts", QL_SIZEOF(nic_stats.rx_128_255_pkts),
 118                                        QL_OFF(nic_stats.rx_128_255_pkts)},
 119        {"rx_256_511_pkts", QL_SIZEOF(nic_stats.rx_256_511_pkts),
 120                                        QL_OFF(nic_stats.rx_256_511_pkts)},
 121        {"rx_512_to_1023_pkts", QL_SIZEOF(nic_stats.rx_512_to_1023_pkts),
 122                                        QL_OFF(nic_stats.rx_512_to_1023_pkts)},
 123        {"rx_1024_to_1518_pkts", QL_SIZEOF(nic_stats.rx_1024_to_1518_pkts),
 124                                        QL_OFF(nic_stats.rx_1024_to_1518_pkts)},
 125        {"rx_1519_to_max_pkts", QL_SIZEOF(nic_stats.rx_1519_to_max_pkts),
 126                                        QL_OFF(nic_stats.rx_1519_to_max_pkts)},
 127        {"rx_len_err_pkts", QL_SIZEOF(nic_stats.rx_len_err_pkts),
 128                                        QL_OFF(nic_stats.rx_len_err_pkts)},
 129        {"rx_code_err", QL_SIZEOF(nic_stats.rx_code_err),
 130                                        QL_OFF(nic_stats.rx_code_err)},
 131        {"rx_oversize_err", QL_SIZEOF(nic_stats.rx_oversize_err),
 132                                        QL_OFF(nic_stats.rx_oversize_err)},
 133        {"rx_undersize_err", QL_SIZEOF(nic_stats.rx_undersize_err),
 134                                        QL_OFF(nic_stats.rx_undersize_err)},
 135        {"rx_preamble_err", QL_SIZEOF(nic_stats.rx_preamble_err),
 136                                        QL_OFF(nic_stats.rx_preamble_err)},
 137        {"rx_frame_len_err", QL_SIZEOF(nic_stats.rx_frame_len_err),
 138                                        QL_OFF(nic_stats.rx_frame_len_err)},
 139        {"rx_crc_err", QL_SIZEOF(nic_stats.rx_crc_err),
 140                                        QL_OFF(nic_stats.rx_crc_err)},
 141        {"rx_err_count", QL_SIZEOF(nic_stats.rx_err_count),
 142                                        QL_OFF(nic_stats.rx_err_count)},
 143        {"tx_cbfc_pause_frames0", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames0),
 144                                QL_OFF(nic_stats.tx_cbfc_pause_frames0)},
 145        {"tx_cbfc_pause_frames1", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames1),
 146                                QL_OFF(nic_stats.tx_cbfc_pause_frames1)},
 147        {"tx_cbfc_pause_frames2", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames2),
 148                                QL_OFF(nic_stats.tx_cbfc_pause_frames2)},
 149        {"tx_cbfc_pause_frames3", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames3),
 150                                QL_OFF(nic_stats.tx_cbfc_pause_frames3)},
 151        {"tx_cbfc_pause_frames4", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames4),
 152                                QL_OFF(nic_stats.tx_cbfc_pause_frames4)},
 153        {"tx_cbfc_pause_frames5", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames5),
 154                                QL_OFF(nic_stats.tx_cbfc_pause_frames5)},
 155        {"tx_cbfc_pause_frames6", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames6),
 156                                QL_OFF(nic_stats.tx_cbfc_pause_frames6)},
 157        {"tx_cbfc_pause_frames7", QL_SIZEOF(nic_stats.tx_cbfc_pause_frames7),
 158                                QL_OFF(nic_stats.tx_cbfc_pause_frames7)},
 159        {"rx_cbfc_pause_frames0", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames0),
 160                                QL_OFF(nic_stats.rx_cbfc_pause_frames0)},
 161        {"rx_cbfc_pause_frames1", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames1),
 162                                QL_OFF(nic_stats.rx_cbfc_pause_frames1)},
 163        {"rx_cbfc_pause_frames2", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames2),
 164                                QL_OFF(nic_stats.rx_cbfc_pause_frames2)},
 165        {"rx_cbfc_pause_frames3", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames3),
 166                                QL_OFF(nic_stats.rx_cbfc_pause_frames3)},
 167        {"rx_cbfc_pause_frames4", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames4),
 168                                QL_OFF(nic_stats.rx_cbfc_pause_frames4)},
 169        {"rx_cbfc_pause_frames5", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames5),
 170                                QL_OFF(nic_stats.rx_cbfc_pause_frames5)},
 171        {"rx_cbfc_pause_frames6", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames6),
 172                                QL_OFF(nic_stats.rx_cbfc_pause_frames6)},
 173        {"rx_cbfc_pause_frames7", QL_SIZEOF(nic_stats.rx_cbfc_pause_frames7),
 174                                QL_OFF(nic_stats.rx_cbfc_pause_frames7)},
 175        {"rx_nic_fifo_drop", QL_SIZEOF(nic_stats.rx_nic_fifo_drop),
 176                                        QL_OFF(nic_stats.rx_nic_fifo_drop)},
 177};
 178
 179static const char ql_gstrings_test[][ETH_GSTRING_LEN] = {
 180        "Loopback test  (offline)"
 181};
 182#define QLGE_TEST_LEN (sizeof(ql_gstrings_test) / ETH_GSTRING_LEN)
 183#define QLGE_STATS_LEN ARRAY_SIZE(ql_gstrings_stats)
 184#define QLGE_RCV_MAC_ERR_STATS  7
 185
 186static int ql_update_ring_coalescing(struct ql_adapter *qdev)
 187{
 188        int i, status = 0;
 189        struct rx_ring *rx_ring;
 190        struct cqicb *cqicb;
 191
 192        if (!netif_running(qdev->ndev))
 193                return status;
 194
 195        /* Skip the default queue, and update the outbound handler
 196         * queues if they changed.
 197         */
 198        cqicb = (struct cqicb *)&qdev->rx_ring[qdev->rss_ring_count];
 199        if (le16_to_cpu(cqicb->irq_delay) != qdev->tx_coalesce_usecs ||
 200                le16_to_cpu(cqicb->pkt_delay) !=
 201                                qdev->tx_max_coalesced_frames) {
 202                for (i = qdev->rss_ring_count; i < qdev->rx_ring_count; i++) {
 203                        rx_ring = &qdev->rx_ring[i];
 204                        cqicb = (struct cqicb *)rx_ring;
 205                        cqicb->irq_delay = cpu_to_le16(qdev->tx_coalesce_usecs);
 206                        cqicb->pkt_delay =
 207                            cpu_to_le16(qdev->tx_max_coalesced_frames);
 208                        cqicb->flags = FLAGS_LI;
 209                        status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
 210                                                CFG_LCQ, rx_ring->cq_id);
 211                        if (status) {
 212                                netif_err(qdev, ifup, qdev->ndev,
 213                                          "Failed to load CQICB.\n");
 214                                goto exit;
 215                        }
 216                }
 217        }
 218
 219        /* Update the inbound (RSS) handler queues if they changed. */
 220        cqicb = (struct cqicb *)&qdev->rx_ring[0];
 221        if (le16_to_cpu(cqicb->irq_delay) != qdev->rx_coalesce_usecs ||
 222                le16_to_cpu(cqicb->pkt_delay) !=
 223                                        qdev->rx_max_coalesced_frames) {
 224                for (i = 0; i < qdev->rss_ring_count; i++, rx_ring++) {
 225                        rx_ring = &qdev->rx_ring[i];
 226                        cqicb = (struct cqicb *)rx_ring;
 227                        cqicb->irq_delay = cpu_to_le16(qdev->rx_coalesce_usecs);
 228                        cqicb->pkt_delay =
 229                            cpu_to_le16(qdev->rx_max_coalesced_frames);
 230                        cqicb->flags = FLAGS_LI;
 231                        status = ql_write_cfg(qdev, cqicb, sizeof(*cqicb),
 232                                                CFG_LCQ, rx_ring->cq_id);
 233                        if (status) {
 234                                netif_err(qdev, ifup, qdev->ndev,
 235                                          "Failed to load CQICB.\n");
 236                                goto exit;
 237                        }
 238                }
 239        }
 240exit:
 241        return status;
 242}
 243
 244static void ql_update_stats(struct ql_adapter *qdev)
 245{
 246        u32 i;
 247        u64 data;
 248        u64 *iter = &qdev->nic_stats.tx_pkts;
 249
 250        spin_lock(&qdev->stats_lock);
 251        if (ql_sem_spinlock(qdev, qdev->xg_sem_mask)) {
 252                        netif_err(qdev, drv, qdev->ndev,
 253                                  "Couldn't get xgmac sem.\n");
 254                goto quit;
 255        }
 256        /*
 257         * Get TX statistics.
 258         */
 259        for (i = 0x200; i < 0x280; i += 8) {
 260                if (ql_read_xgmac_reg64(qdev, i, &data)) {
 261                        netif_err(qdev, drv, qdev->ndev,
 262                                  "Error reading status register 0x%.04x.\n",
 263                                  i);
 264                        goto end;
 265                } else
 266                        *iter = data;
 267                iter++;
 268        }
 269
 270        /*
 271         * Get RX statistics.
 272         */
 273        for (i = 0x300; i < 0x3d0; i += 8) {
 274                if (ql_read_xgmac_reg64(qdev, i, &data)) {
 275                        netif_err(qdev, drv, qdev->ndev,
 276                                  "Error reading status register 0x%.04x.\n",
 277                                  i);
 278                        goto end;
 279                } else
 280                        *iter = data;
 281                iter++;
 282        }
 283
 284        /* Update receive mac error statistics */
 285        iter += QLGE_RCV_MAC_ERR_STATS;
 286
 287        /*
 288         * Get Per-priority TX pause frame counter statistics.
 289         */
 290        for (i = 0x500; i < 0x540; i += 8) {
 291                if (ql_read_xgmac_reg64(qdev, i, &data)) {
 292                        netif_err(qdev, drv, qdev->ndev,
 293                                  "Error reading status register 0x%.04x.\n",
 294                                  i);
 295                        goto end;
 296                } else
 297                        *iter = data;
 298                iter++;
 299        }
 300
 301        /*
 302         * Get Per-priority RX pause frame counter statistics.
 303         */
 304        for (i = 0x568; i < 0x5a8; i += 8) {
 305                if (ql_read_xgmac_reg64(qdev, i, &data)) {
 306                        netif_err(qdev, drv, qdev->ndev,
 307                                  "Error reading status register 0x%.04x.\n",
 308                                  i);
 309                        goto end;
 310                } else
 311                        *iter = data;
 312                iter++;
 313        }
 314
 315        /*
 316         * Get RX NIC FIFO DROP statistics.
 317         */
 318        if (ql_read_xgmac_reg64(qdev, 0x5b8, &data)) {
 319                netif_err(qdev, drv, qdev->ndev,
 320                          "Error reading status register 0x%.04x.\n", i);
 321                goto end;
 322        } else
 323                *iter = data;
 324end:
 325        ql_sem_unlock(qdev, qdev->xg_sem_mask);
 326quit:
 327        spin_unlock(&qdev->stats_lock);
 328
 329        QL_DUMP_STAT(qdev);
 330}
 331
 332static void ql_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
 333{
 334        int index;
 335        switch (stringset) {
 336        case ETH_SS_TEST:
 337                memcpy(buf, *ql_gstrings_test, QLGE_TEST_LEN * ETH_GSTRING_LEN);
 338                break;
 339        case ETH_SS_STATS:
 340                for (index = 0; index < QLGE_STATS_LEN; index++) {
 341                        memcpy(buf + index * ETH_GSTRING_LEN,
 342                                ql_gstrings_stats[index].stat_string,
 343                                ETH_GSTRING_LEN);
 344                }
 345                break;
 346        }
 347}
 348
 349static int ql_get_sset_count(struct net_device *dev, int sset)
 350{
 351        switch (sset) {
 352        case ETH_SS_TEST:
 353                return QLGE_TEST_LEN;
 354        case ETH_SS_STATS:
 355                return QLGE_STATS_LEN;
 356        default:
 357                return -EOPNOTSUPP;
 358        }
 359}
 360
 361static void
 362ql_get_ethtool_stats(struct net_device *ndev,
 363                     struct ethtool_stats *stats, u64 *data)
 364{
 365        struct ql_adapter *qdev = netdev_priv(ndev);
 366        int index, length;
 367
 368        length = QLGE_STATS_LEN;
 369        ql_update_stats(qdev);
 370
 371        for (index = 0; index < length; index++) {
 372                char *p = (char *)qdev +
 373                        ql_gstrings_stats[index].stat_offset;
 374                *data++ = (ql_gstrings_stats[index].sizeof_stat ==
 375                        sizeof(u64)) ? *(u64 *)p : (*(u32 *)p);
 376        }
 377}
 378
 379static int ql_get_settings(struct net_device *ndev,
 380                              struct ethtool_cmd *ecmd)
 381{
 382        struct ql_adapter *qdev = netdev_priv(ndev);
 383
 384        ecmd->supported = SUPPORTED_10000baseT_Full;
 385        ecmd->advertising = ADVERTISED_10000baseT_Full;
 386        ecmd->transceiver = XCVR_EXTERNAL;
 387        if ((qdev->link_status & STS_LINK_TYPE_MASK) ==
 388                                STS_LINK_TYPE_10GBASET) {
 389                ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
 390                ecmd->advertising |= (ADVERTISED_TP | ADVERTISED_Autoneg);
 391                ecmd->port = PORT_TP;
 392                ecmd->autoneg = AUTONEG_ENABLE;
 393        } else {
 394                ecmd->supported |= SUPPORTED_FIBRE;
 395                ecmd->advertising |= ADVERTISED_FIBRE;
 396                ecmd->port = PORT_FIBRE;
 397        }
 398
 399        ethtool_cmd_speed_set(ecmd, SPEED_10000);
 400        ecmd->duplex = DUPLEX_FULL;
 401
 402        return 0;
 403}
 404
 405static void ql_get_drvinfo(struct net_device *ndev,
 406                           struct ethtool_drvinfo *drvinfo)
 407{
 408        struct ql_adapter *qdev = netdev_priv(ndev);
 409        strlcpy(drvinfo->driver, qlge_driver_name, sizeof(drvinfo->driver));
 410        strlcpy(drvinfo->version, qlge_driver_version,
 411                sizeof(drvinfo->version));
 412        snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
 413                 "v%d.%d.%d",
 414                 (qdev->fw_rev_id & 0x00ff0000) >> 16,
 415                 (qdev->fw_rev_id & 0x0000ff00) >> 8,
 416                 (qdev->fw_rev_id & 0x000000ff));
 417        strlcpy(drvinfo->bus_info, pci_name(qdev->pdev),
 418                sizeof(drvinfo->bus_info));
 419        drvinfo->n_stats = 0;
 420        drvinfo->testinfo_len = 0;
 421        if (!test_bit(QL_FRC_COREDUMP, &qdev->flags))
 422                drvinfo->regdump_len = sizeof(struct ql_mpi_coredump);
 423        else
 424                drvinfo->regdump_len = sizeof(struct ql_reg_dump);
 425        drvinfo->eedump_len = 0;
 426}
 427
 428static void ql_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
 429{
 430        struct ql_adapter *qdev = netdev_priv(ndev);
 431        unsigned short ssys_dev = qdev->pdev->subsystem_device;
 432
 433        /* WOL is only supported for mezz card. */
 434        if (ssys_dev == QLGE_MEZZ_SSYS_ID_068 ||
 435                        ssys_dev == QLGE_MEZZ_SSYS_ID_180) {
 436                wol->supported = WAKE_MAGIC;
 437                wol->wolopts = qdev->wol;
 438        }
 439}
 440
 441static int ql_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
 442{
 443        struct ql_adapter *qdev = netdev_priv(ndev);
 444        unsigned short ssys_dev = qdev->pdev->subsystem_device;
 445
 446        /* WOL is only supported for mezz card. */
 447        if (ssys_dev != QLGE_MEZZ_SSYS_ID_068 &&
 448                        ssys_dev != QLGE_MEZZ_SSYS_ID_180) {
 449                netif_info(qdev, drv, qdev->ndev,
 450                                "WOL is only supported for mezz card\n");
 451                return -EOPNOTSUPP;
 452        }
 453        if (wol->wolopts & ~WAKE_MAGIC)
 454                return -EINVAL;
 455        qdev->wol = wol->wolopts;
 456
 457        netif_info(qdev, drv, qdev->ndev, "Set wol option 0x%x\n", qdev->wol);
 458        return 0;
 459}
 460
 461static int ql_set_phys_id(struct net_device *ndev,
 462                          enum ethtool_phys_id_state state)
 463
 464{
 465        struct ql_adapter *qdev = netdev_priv(ndev);
 466
 467        switch (state) {
 468        case ETHTOOL_ID_ACTIVE:
 469                /* Save the current LED settings */
 470                if (ql_mb_get_led_cfg(qdev))
 471                        return -EIO;
 472
 473                /* Start blinking */
 474                ql_mb_set_led_cfg(qdev, QL_LED_BLINK);
 475                return 0;
 476
 477        case ETHTOOL_ID_INACTIVE:
 478                /* Restore LED settings */
 479                if (ql_mb_set_led_cfg(qdev, qdev->led_config))
 480                        return -EIO;
 481                return 0;
 482
 483        default:
 484                return -EINVAL;
 485        }
 486}
 487
 488static int ql_start_loopback(struct ql_adapter *qdev)
 489{
 490        if (netif_carrier_ok(qdev->ndev)) {
 491                set_bit(QL_LB_LINK_UP, &qdev->flags);
 492                netif_carrier_off(qdev->ndev);
 493        } else
 494                clear_bit(QL_LB_LINK_UP, &qdev->flags);
 495        qdev->link_config |= CFG_LOOPBACK_PCS;
 496        return ql_mb_set_port_cfg(qdev);
 497}
 498
 499static void ql_stop_loopback(struct ql_adapter *qdev)
 500{
 501        qdev->link_config &= ~CFG_LOOPBACK_PCS;
 502        ql_mb_set_port_cfg(qdev);
 503        if (test_bit(QL_LB_LINK_UP, &qdev->flags)) {
 504                netif_carrier_on(qdev->ndev);
 505                clear_bit(QL_LB_LINK_UP, &qdev->flags);
 506        }
 507}
 508
 509static void ql_create_lb_frame(struct sk_buff *skb,
 510                                        unsigned int frame_size)
 511{
 512        memset(skb->data, 0xFF, frame_size);
 513        frame_size &= ~1;
 514        memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
 515        memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
 516        memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
 517}
 518
 519void ql_check_lb_frame(struct ql_adapter *qdev,
 520                                        struct sk_buff *skb)
 521{
 522        unsigned int frame_size = skb->len;
 523
 524        if ((*(skb->data + 3) == 0xFF) &&
 525                (*(skb->data + frame_size / 2 + 10) == 0xBE) &&
 526                (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
 527                        atomic_dec(&qdev->lb_count);
 528                        return;
 529        }
 530}
 531
 532static int ql_run_loopback_test(struct ql_adapter *qdev)
 533{
 534        int i;
 535        netdev_tx_t rc;
 536        struct sk_buff *skb;
 537        unsigned int size = SMALL_BUF_MAP_SIZE;
 538
 539        for (i = 0; i < 64; i++) {
 540                skb = netdev_alloc_skb(qdev->ndev, size);
 541                if (!skb)
 542                        return -ENOMEM;
 543
 544                skb->queue_mapping = 0;
 545                skb_put(skb, size);
 546                ql_create_lb_frame(skb, size);
 547                rc = ql_lb_send(skb, qdev->ndev);
 548                if (rc != NETDEV_TX_OK)
 549                        return -EPIPE;
 550                atomic_inc(&qdev->lb_count);
 551        }
 552        /* Give queue time to settle before testing results. */
 553        msleep(2);
 554        ql_clean_lb_rx_ring(&qdev->rx_ring[0], 128);
 555        return atomic_read(&qdev->lb_count) ? -EIO : 0;
 556}
 557
 558static int ql_loopback_test(struct ql_adapter *qdev, u64 *data)
 559{
 560        *data = ql_start_loopback(qdev);
 561        if (*data)
 562                goto out;
 563        *data = ql_run_loopback_test(qdev);
 564out:
 565        ql_stop_loopback(qdev);
 566        return *data;
 567}
 568
 569static void ql_self_test(struct net_device *ndev,
 570                                struct ethtool_test *eth_test, u64 *data)
 571{
 572        struct ql_adapter *qdev = netdev_priv(ndev);
 573
 574        memset(data, 0, sizeof(u64) * QLGE_TEST_LEN);
 575
 576        if (netif_running(ndev)) {
 577                set_bit(QL_SELFTEST, &qdev->flags);
 578                if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
 579                        /* Offline tests */
 580                        if (ql_loopback_test(qdev, &data[0]))
 581                                eth_test->flags |= ETH_TEST_FL_FAILED;
 582
 583                } else {
 584                        /* Online tests */
 585                        data[0] = 0;
 586                }
 587                clear_bit(QL_SELFTEST, &qdev->flags);
 588                /* Give link time to come up after
 589                 * port configuration changes.
 590                 */
 591                msleep_interruptible(4 * 1000);
 592        } else {
 593                netif_err(qdev, drv, qdev->ndev,
 594                          "is down, Loopback test will fail.\n");
 595                eth_test->flags |= ETH_TEST_FL_FAILED;
 596        }
 597}
 598
 599static int ql_get_regs_len(struct net_device *ndev)
 600{
 601        struct ql_adapter *qdev = netdev_priv(ndev);
 602
 603        if (!test_bit(QL_FRC_COREDUMP, &qdev->flags))
 604                return sizeof(struct ql_mpi_coredump);
 605        else
 606                return sizeof(struct ql_reg_dump);
 607}
 608
 609static void ql_get_regs(struct net_device *ndev,
 610                        struct ethtool_regs *regs, void *p)
 611{
 612        struct ql_adapter *qdev = netdev_priv(ndev);
 613
 614        ql_get_dump(qdev, p);
 615        qdev->core_is_dumped = 0;
 616        if (!test_bit(QL_FRC_COREDUMP, &qdev->flags))
 617                regs->len = sizeof(struct ql_mpi_coredump);
 618        else
 619                regs->len = sizeof(struct ql_reg_dump);
 620}
 621
 622static int ql_get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
 623{
 624        struct ql_adapter *qdev = netdev_priv(dev);
 625
 626        c->rx_coalesce_usecs = qdev->rx_coalesce_usecs;
 627        c->tx_coalesce_usecs = qdev->tx_coalesce_usecs;
 628
 629        /* This chip coalesces as follows:
 630         * If a packet arrives, hold off interrupts until
 631         * cqicb->int_delay expires, but if no other packets arrive don't
 632         * wait longer than cqicb->pkt_int_delay. But ethtool doesn't use a
 633         * timer to coalesce on a frame basis.  So, we have to take ethtool's
 634         * max_coalesced_frames value and convert it to a delay in microseconds.
 635         * We do this by using a basic thoughput of 1,000,000 frames per
 636         * second @ (1024 bytes).  This means one frame per usec. So it's a
 637         * simple one to one ratio.
 638         */
 639        c->rx_max_coalesced_frames = qdev->rx_max_coalesced_frames;
 640        c->tx_max_coalesced_frames = qdev->tx_max_coalesced_frames;
 641
 642        return 0;
 643}
 644
 645static int ql_set_coalesce(struct net_device *ndev, struct ethtool_coalesce *c)
 646{
 647        struct ql_adapter *qdev = netdev_priv(ndev);
 648
 649        /* Validate user parameters. */
 650        if (c->rx_coalesce_usecs > qdev->rx_ring_size / 2)
 651                return -EINVAL;
 652       /* Don't wait more than 10 usec. */
 653        if (c->rx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
 654                return -EINVAL;
 655        if (c->tx_coalesce_usecs > qdev->tx_ring_size / 2)
 656                return -EINVAL;
 657        if (c->tx_max_coalesced_frames > MAX_INTER_FRAME_WAIT)
 658                return -EINVAL;
 659
 660        /* Verify a change took place before updating the hardware. */
 661        if (qdev->rx_coalesce_usecs == c->rx_coalesce_usecs &&
 662            qdev->tx_coalesce_usecs == c->tx_coalesce_usecs &&
 663            qdev->rx_max_coalesced_frames == c->rx_max_coalesced_frames &&
 664            qdev->tx_max_coalesced_frames == c->tx_max_coalesced_frames)
 665                return 0;
 666
 667        qdev->rx_coalesce_usecs = c->rx_coalesce_usecs;
 668        qdev->tx_coalesce_usecs = c->tx_coalesce_usecs;
 669        qdev->rx_max_coalesced_frames = c->rx_max_coalesced_frames;
 670        qdev->tx_max_coalesced_frames = c->tx_max_coalesced_frames;
 671
 672        return ql_update_ring_coalescing(qdev);
 673}
 674
 675static void ql_get_pauseparam(struct net_device *netdev,
 676                        struct ethtool_pauseparam *pause)
 677{
 678        struct ql_adapter *qdev = netdev_priv(netdev);
 679
 680        ql_mb_get_port_cfg(qdev);
 681        if (qdev->link_config & CFG_PAUSE_STD) {
 682                pause->rx_pause = 1;
 683                pause->tx_pause = 1;
 684        }
 685}
 686
 687static int ql_set_pauseparam(struct net_device *netdev,
 688                        struct ethtool_pauseparam *pause)
 689{
 690        struct ql_adapter *qdev = netdev_priv(netdev);
 691        int status = 0;
 692
 693        if ((pause->rx_pause) && (pause->tx_pause))
 694                qdev->link_config |= CFG_PAUSE_STD;
 695        else if (!pause->rx_pause && !pause->tx_pause)
 696                qdev->link_config &= ~CFG_PAUSE_STD;
 697        else
 698                return -EINVAL;
 699
 700        status = ql_mb_set_port_cfg(qdev);
 701        return status;
 702}
 703
 704static u32 ql_get_msglevel(struct net_device *ndev)
 705{
 706        struct ql_adapter *qdev = netdev_priv(ndev);
 707        return qdev->msg_enable;
 708}
 709
 710static void ql_set_msglevel(struct net_device *ndev, u32 value)
 711{
 712        struct ql_adapter *qdev = netdev_priv(ndev);
 713        qdev->msg_enable = value;
 714}
 715
 716const struct ethtool_ops qlge_ethtool_ops = {
 717        .get_settings = ql_get_settings,
 718        .get_drvinfo = ql_get_drvinfo,
 719        .get_wol = ql_get_wol,
 720        .set_wol = ql_set_wol,
 721        .get_regs_len   = ql_get_regs_len,
 722        .get_regs = ql_get_regs,
 723        .get_msglevel = ql_get_msglevel,
 724        .set_msglevel = ql_set_msglevel,
 725        .get_link = ethtool_op_get_link,
 726        .set_phys_id             = ql_set_phys_id,
 727        .self_test               = ql_self_test,
 728        .get_pauseparam          = ql_get_pauseparam,
 729        .set_pauseparam          = ql_set_pauseparam,
 730        .get_coalesce = ql_get_coalesce,
 731        .set_coalesce = ql_set_coalesce,
 732        .get_sset_count = ql_get_sset_count,
 733        .get_strings = ql_get_strings,
 734        .get_ethtool_stats = ql_get_ethtool_stats,
 735};
 736
 737