linux/drivers/net/ethernet/freescale/gianfar_ethtool.c
<<
>>
Prefs
   1/*
   2 *  drivers/net/ethernet/freescale/gianfar_ethtool.c
   3 *
   4 *  Gianfar Ethernet Driver
   5 *  Ethtool support for Gianfar Enet
   6 *  Based on e1000 ethtool support
   7 *
   8 *  Author: Andy Fleming
   9 *  Maintainer: Kumar Gala
  10 *  Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
  11 *
  12 *  Copyright 2003-2006, 2008-2009, 2011 Freescale Semiconductor, Inc.
  13 *
  14 *  This software may be used and distributed according to
  15 *  the terms of the GNU Public License, Version 2, incorporated herein
  16 *  by reference.
  17 */
  18
  19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20
  21#include <linux/kernel.h>
  22#include <linux/string.h>
  23#include <linux/errno.h>
  24#include <linux/interrupt.h>
  25#include <linux/init.h>
  26#include <linux/delay.h>
  27#include <linux/netdevice.h>
  28#include <linux/etherdevice.h>
  29#include <linux/net_tstamp.h>
  30#include <linux/skbuff.h>
  31#include <linux/spinlock.h>
  32#include <linux/mm.h>
  33
  34#include <asm/io.h>
  35#include <asm/irq.h>
  36#include <asm/uaccess.h>
  37#include <linux/module.h>
  38#include <linux/crc32.h>
  39#include <asm/types.h>
  40#include <linux/ethtool.h>
  41#include <linux/mii.h>
  42#include <linux/phy.h>
  43#include <linux/sort.h>
  44#include <linux/if_vlan.h>
  45
  46#include "gianfar.h"
  47
  48extern void gfar_start(struct net_device *dev);
  49extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue,
  50                              int rx_work_limit);
  51
  52#define GFAR_MAX_COAL_USECS 0xffff
  53#define GFAR_MAX_COAL_FRAMES 0xff
  54static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
  55                            u64 *buf);
  56static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
  57static int gfar_gcoalesce(struct net_device *dev,
  58                          struct ethtool_coalesce *cvals);
  59static int gfar_scoalesce(struct net_device *dev,
  60                          struct ethtool_coalesce *cvals);
  61static void gfar_gringparam(struct net_device *dev,
  62                            struct ethtool_ringparam *rvals);
  63static int gfar_sringparam(struct net_device *dev,
  64                           struct ethtool_ringparam *rvals);
  65static void gfar_gdrvinfo(struct net_device *dev,
  66                          struct ethtool_drvinfo *drvinfo);
  67
  68static const char stat_gstrings[][ETH_GSTRING_LEN] = {
  69        "rx-large-frame-errors",
  70        "rx-short-frame-errors",
  71        "rx-non-octet-errors",
  72        "rx-crc-errors",
  73        "rx-overrun-errors",
  74        "rx-busy-errors",
  75        "rx-babbling-errors",
  76        "rx-truncated-frames",
  77        "ethernet-bus-error",
  78        "tx-babbling-errors",
  79        "tx-underrun-errors",
  80        "rx-skb-missing-errors",
  81        "tx-timeout-errors",
  82        "tx-rx-64-frames",
  83        "tx-rx-65-127-frames",
  84        "tx-rx-128-255-frames",
  85        "tx-rx-256-511-frames",
  86        "tx-rx-512-1023-frames",
  87        "tx-rx-1024-1518-frames",
  88        "tx-rx-1519-1522-good-vlan",
  89        "rx-bytes",
  90        "rx-packets",
  91        "rx-fcs-errors",
  92        "receive-multicast-packet",
  93        "receive-broadcast-packet",
  94        "rx-control-frame-packets",
  95        "rx-pause-frame-packets",
  96        "rx-unknown-op-code",
  97        "rx-alignment-error",
  98        "rx-frame-length-error",
  99        "rx-code-error",
 100        "rx-carrier-sense-error",
 101        "rx-undersize-packets",
 102        "rx-oversize-packets",
 103        "rx-fragmented-frames",
 104        "rx-jabber-frames",
 105        "rx-dropped-frames",
 106        "tx-byte-counter",
 107        "tx-packets",
 108        "tx-multicast-packets",
 109        "tx-broadcast-packets",
 110        "tx-pause-control-frames",
 111        "tx-deferral-packets",
 112        "tx-excessive-deferral-packets",
 113        "tx-single-collision-packets",
 114        "tx-multiple-collision-packets",
 115        "tx-late-collision-packets",
 116        "tx-excessive-collision-packets",
 117        "tx-total-collision",
 118        "reserved",
 119        "tx-dropped-frames",
 120        "tx-jabber-frames",
 121        "tx-fcs-errors",
 122        "tx-control-frames",
 123        "tx-oversize-frames",
 124        "tx-undersize-frames",
 125        "tx-fragmented-frames",
 126};
 127
 128/* Fill in a buffer with the strings which correspond to the
 129 * stats */
 130static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
 131{
 132        struct gfar_private *priv = netdev_priv(dev);
 133
 134        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
 135                memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
 136        else
 137                memcpy(buf, stat_gstrings,
 138                       GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
 139}
 140
 141/* Fill in an array of 64-bit statistics from various sources.
 142 * This array will be appended to the end of the ethtool_stats
 143 * structure, and returned to user space
 144 */
 145static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
 146                            u64 *buf)
 147{
 148        int i;
 149        struct gfar_private *priv = netdev_priv(dev);
 150        struct gfar __iomem *regs = priv->gfargrp[0].regs;
 151        atomic64_t *extra = (atomic64_t *)&priv->extra_stats;
 152
 153        for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
 154                buf[i] = atomic64_read(&extra[i]);
 155
 156        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
 157                u32 __iomem *rmon = (u32 __iomem *) &regs->rmon;
 158
 159                for (; i < GFAR_STATS_LEN; i++, rmon++)
 160                        buf[i] = (u64) gfar_read(rmon);
 161        }
 162}
 163
 164static int gfar_sset_count(struct net_device *dev, int sset)
 165{
 166        struct gfar_private *priv = netdev_priv(dev);
 167
 168        switch (sset) {
 169        case ETH_SS_STATS:
 170                if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
 171                        return GFAR_STATS_LEN;
 172                else
 173                        return GFAR_EXTRA_STATS_LEN;
 174        default:
 175                return -EOPNOTSUPP;
 176        }
 177}
 178
 179/* Fills in the drvinfo structure with some basic info */
 180static void gfar_gdrvinfo(struct net_device *dev,
 181                          struct ethtool_drvinfo *drvinfo)
 182{
 183        strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
 184        strlcpy(drvinfo->version, gfar_driver_version,
 185                sizeof(drvinfo->version));
 186        strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
 187        strlcpy(drvinfo->bus_info, "N/A", sizeof(drvinfo->bus_info));
 188}
 189
 190
 191static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
 192{
 193        struct gfar_private *priv = netdev_priv(dev);
 194        struct phy_device *phydev = priv->phydev;
 195
 196        if (NULL == phydev)
 197                return -ENODEV;
 198
 199        return phy_ethtool_sset(phydev, cmd);
 200}
 201
 202
 203/* Return the current settings in the ethtool_cmd structure */
 204static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
 205{
 206        struct gfar_private *priv = netdev_priv(dev);
 207        struct phy_device *phydev = priv->phydev;
 208        struct gfar_priv_rx_q *rx_queue = NULL;
 209        struct gfar_priv_tx_q *tx_queue = NULL;
 210
 211        if (NULL == phydev)
 212                return -ENODEV;
 213        tx_queue = priv->tx_queue[0];
 214        rx_queue = priv->rx_queue[0];
 215
 216        /* etsec-1.7 and older versions have only one txic
 217         * and rxic regs although they support multiple queues */
 218        cmd->maxtxpkt = get_icft_value(tx_queue->txic);
 219        cmd->maxrxpkt = get_icft_value(rx_queue->rxic);
 220
 221        return phy_ethtool_gset(phydev, cmd);
 222}
 223
 224/* Return the length of the register structure */
 225static int gfar_reglen(struct net_device *dev)
 226{
 227        return sizeof (struct gfar);
 228}
 229
 230/* Return a dump of the GFAR register space */
 231static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs,
 232                          void *regbuf)
 233{
 234        int i;
 235        struct gfar_private *priv = netdev_priv(dev);
 236        u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp[0].regs;
 237        u32 *buf = (u32 *) regbuf;
 238
 239        for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)
 240                buf[i] = gfar_read(&theregs[i]);
 241}
 242
 243/* Convert microseconds to ethernet clock ticks, which changes
 244 * depending on what speed the controller is running at */
 245static unsigned int gfar_usecs2ticks(struct gfar_private *priv,
 246                                     unsigned int usecs)
 247{
 248        unsigned int count;
 249
 250        /* The timer is different, depending on the interface speed */
 251        switch (priv->phydev->speed) {
 252        case SPEED_1000:
 253                count = GFAR_GBIT_TIME;
 254                break;
 255        case SPEED_100:
 256                count = GFAR_100_TIME;
 257                break;
 258        case SPEED_10:
 259        default:
 260                count = GFAR_10_TIME;
 261                break;
 262        }
 263
 264        /* Make sure we return a number greater than 0
 265         * if usecs > 0 */
 266        return (usecs * 1000 + count - 1) / count;
 267}
 268
 269/* Convert ethernet clock ticks to microseconds */
 270static unsigned int gfar_ticks2usecs(struct gfar_private *priv,
 271                                     unsigned int ticks)
 272{
 273        unsigned int count;
 274
 275        /* The timer is different, depending on the interface speed */
 276        switch (priv->phydev->speed) {
 277        case SPEED_1000:
 278                count = GFAR_GBIT_TIME;
 279                break;
 280        case SPEED_100:
 281                count = GFAR_100_TIME;
 282                break;
 283        case SPEED_10:
 284        default:
 285                count = GFAR_10_TIME;
 286                break;
 287        }
 288
 289        /* Make sure we return a number greater than 0 */
 290        /* if ticks is > 0 */
 291        return (ticks * count) / 1000;
 292}
 293
 294/* Get the coalescing parameters, and put them in the cvals
 295 * structure.  */
 296static int gfar_gcoalesce(struct net_device *dev,
 297                          struct ethtool_coalesce *cvals)
 298{
 299        struct gfar_private *priv = netdev_priv(dev);
 300        struct gfar_priv_rx_q *rx_queue = NULL;
 301        struct gfar_priv_tx_q *tx_queue = NULL;
 302        unsigned long rxtime;
 303        unsigned long rxcount;
 304        unsigned long txtime;
 305        unsigned long txcount;
 306
 307        if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
 308                return -EOPNOTSUPP;
 309
 310        if (NULL == priv->phydev)
 311                return -ENODEV;
 312
 313        rx_queue = priv->rx_queue[0];
 314        tx_queue = priv->tx_queue[0];
 315
 316        rxtime  = get_ictt_value(rx_queue->rxic);
 317        rxcount = get_icft_value(rx_queue->rxic);
 318        txtime  = get_ictt_value(tx_queue->txic);
 319        txcount = get_icft_value(tx_queue->txic);
 320        cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime);
 321        cvals->rx_max_coalesced_frames = rxcount;
 322
 323        cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime);
 324        cvals->tx_max_coalesced_frames = txcount;
 325
 326        cvals->use_adaptive_rx_coalesce = 0;
 327        cvals->use_adaptive_tx_coalesce = 0;
 328
 329        cvals->pkt_rate_low = 0;
 330        cvals->rx_coalesce_usecs_low = 0;
 331        cvals->rx_max_coalesced_frames_low = 0;
 332        cvals->tx_coalesce_usecs_low = 0;
 333        cvals->tx_max_coalesced_frames_low = 0;
 334
 335        /* When the packet rate is below pkt_rate_high but above
 336         * pkt_rate_low (both measured in packets per second) the
 337         * normal {rx,tx}_* coalescing parameters are used.
 338         */
 339
 340        /* When the packet rate is (measured in packets per second)
 341         * is above pkt_rate_high, the {rx,tx}_*_high parameters are
 342         * used.
 343         */
 344        cvals->pkt_rate_high = 0;
 345        cvals->rx_coalesce_usecs_high = 0;
 346        cvals->rx_max_coalesced_frames_high = 0;
 347        cvals->tx_coalesce_usecs_high = 0;
 348        cvals->tx_max_coalesced_frames_high = 0;
 349
 350        /* How often to do adaptive coalescing packet rate sampling,
 351         * measured in seconds.  Must not be zero.
 352         */
 353        cvals->rate_sample_interval = 0;
 354
 355        return 0;
 356}
 357
 358/* Change the coalescing values.
 359 * Both cvals->*_usecs and cvals->*_frames have to be > 0
 360 * in order for coalescing to be active
 361 */
 362static int gfar_scoalesce(struct net_device *dev,
 363                          struct ethtool_coalesce *cvals)
 364{
 365        struct gfar_private *priv = netdev_priv(dev);
 366        int i = 0;
 367
 368        if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
 369                return -EOPNOTSUPP;
 370
 371        /* Set up rx coalescing */
 372        /* As of now, we will enable/disable coalescing for all
 373         * queues together in case of eTSEC2, this will be modified
 374         * along with the ethtool interface
 375         */
 376        if ((cvals->rx_coalesce_usecs == 0) ||
 377            (cvals->rx_max_coalesced_frames == 0)) {
 378                for (i = 0; i < priv->num_rx_queues; i++)
 379                        priv->rx_queue[i]->rxcoalescing = 0;
 380        } else {
 381                for (i = 0; i < priv->num_rx_queues; i++)
 382                        priv->rx_queue[i]->rxcoalescing = 1;
 383        }
 384
 385        if (NULL == priv->phydev)
 386                return -ENODEV;
 387
 388        /* Check the bounds of the values */
 389        if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
 390                netdev_info(dev, "Coalescing is limited to %d microseconds\n",
 391                            GFAR_MAX_COAL_USECS);
 392                return -EINVAL;
 393        }
 394
 395        if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
 396                netdev_info(dev, "Coalescing is limited to %d frames\n",
 397                            GFAR_MAX_COAL_FRAMES);
 398                return -EINVAL;
 399        }
 400
 401        for (i = 0; i < priv->num_rx_queues; i++) {
 402                priv->rx_queue[i]->rxic = mk_ic_value(
 403                        cvals->rx_max_coalesced_frames,
 404                        gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs));
 405        }
 406
 407        /* Set up tx coalescing */
 408        if ((cvals->tx_coalesce_usecs == 0) ||
 409            (cvals->tx_max_coalesced_frames == 0)) {
 410                for (i = 0; i < priv->num_tx_queues; i++)
 411                        priv->tx_queue[i]->txcoalescing = 0;
 412        } else {
 413                for (i = 0; i < priv->num_tx_queues; i++)
 414                        priv->tx_queue[i]->txcoalescing = 1;
 415        }
 416
 417        /* Check the bounds of the values */
 418        if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
 419                netdev_info(dev, "Coalescing is limited to %d microseconds\n",
 420                            GFAR_MAX_COAL_USECS);
 421                return -EINVAL;
 422        }
 423
 424        if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
 425                netdev_info(dev, "Coalescing is limited to %d frames\n",
 426                            GFAR_MAX_COAL_FRAMES);
 427                return -EINVAL;
 428        }
 429
 430        for (i = 0; i < priv->num_tx_queues; i++) {
 431                priv->tx_queue[i]->txic = mk_ic_value(
 432                        cvals->tx_max_coalesced_frames,
 433                        gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs));
 434        }
 435
 436        gfar_configure_coalescing_all(priv);
 437
 438        return 0;
 439}
 440
 441/* Fills in rvals with the current ring parameters.  Currently,
 442 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
 443 * jumbo are ignored by the driver */
 444static void gfar_gringparam(struct net_device *dev,
 445                            struct ethtool_ringparam *rvals)
 446{
 447        struct gfar_private *priv = netdev_priv(dev);
 448        struct gfar_priv_tx_q *tx_queue = NULL;
 449        struct gfar_priv_rx_q *rx_queue = NULL;
 450
 451        tx_queue = priv->tx_queue[0];
 452        rx_queue = priv->rx_queue[0];
 453
 454        rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE;
 455        rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE;
 456        rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE;
 457        rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE;
 458
 459        /* Values changeable by the user.  The valid values are
 460         * in the range 1 to the "*_max_pending" counterpart above.
 461         */
 462        rvals->rx_pending = rx_queue->rx_ring_size;
 463        rvals->rx_mini_pending = rx_queue->rx_ring_size;
 464        rvals->rx_jumbo_pending = rx_queue->rx_ring_size;
 465        rvals->tx_pending = tx_queue->tx_ring_size;
 466}
 467
 468/* Change the current ring parameters, stopping the controller if
 469 * necessary so that we don't mess things up while we're in
 470 * motion.  We wait for the ring to be clean before reallocating
 471 * the rings.
 472 */
 473static int gfar_sringparam(struct net_device *dev,
 474                           struct ethtool_ringparam *rvals)
 475{
 476        struct gfar_private *priv = netdev_priv(dev);
 477        int err = 0, i = 0;
 478
 479        if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE)
 480                return -EINVAL;
 481
 482        if (!is_power_of_2(rvals->rx_pending)) {
 483                netdev_err(dev, "Ring sizes must be a power of 2\n");
 484                return -EINVAL;
 485        }
 486
 487        if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE)
 488                return -EINVAL;
 489
 490        if (!is_power_of_2(rvals->tx_pending)) {
 491                netdev_err(dev, "Ring sizes must be a power of 2\n");
 492                return -EINVAL;
 493        }
 494
 495
 496        if (dev->flags & IFF_UP) {
 497                unsigned long flags;
 498
 499                /* Halt TX and RX, and process the frames which
 500                 * have already been received
 501                 */
 502                local_irq_save(flags);
 503                lock_tx_qs(priv);
 504                lock_rx_qs(priv);
 505
 506                gfar_halt(dev);
 507
 508                unlock_rx_qs(priv);
 509                unlock_tx_qs(priv);
 510                local_irq_restore(flags);
 511
 512                for (i = 0; i < priv->num_rx_queues; i++)
 513                        gfar_clean_rx_ring(priv->rx_queue[i],
 514                                           priv->rx_queue[i]->rx_ring_size);
 515
 516                /* Now we take down the rings to rebuild them */
 517                stop_gfar(dev);
 518        }
 519
 520        /* Change the size */
 521        for (i = 0; i < priv->num_rx_queues; i++) {
 522                priv->rx_queue[i]->rx_ring_size = rvals->rx_pending;
 523                priv->tx_queue[i]->tx_ring_size = rvals->tx_pending;
 524                priv->tx_queue[i]->num_txbdfree =
 525                        priv->tx_queue[i]->tx_ring_size;
 526        }
 527
 528        /* Rebuild the rings with the new size */
 529        if (dev->flags & IFF_UP) {
 530                err = startup_gfar(dev);
 531                netif_tx_wake_all_queues(dev);
 532        }
 533        return err;
 534}
 535
 536int gfar_set_features(struct net_device *dev, netdev_features_t features)
 537{
 538        struct gfar_private *priv = netdev_priv(dev);
 539        unsigned long flags;
 540        int err = 0, i = 0;
 541        netdev_features_t changed = dev->features ^ features;
 542
 543        if (changed & (NETIF_F_HW_VLAN_CTAG_TX|NETIF_F_HW_VLAN_CTAG_RX))
 544                gfar_vlan_mode(dev, features);
 545
 546        if (!(changed & NETIF_F_RXCSUM))
 547                return 0;
 548
 549        if (dev->flags & IFF_UP) {
 550                /* Halt TX and RX, and process the frames which
 551                 * have already been received
 552                 */
 553                local_irq_save(flags);
 554                lock_tx_qs(priv);
 555                lock_rx_qs(priv);
 556
 557                gfar_halt(dev);
 558
 559                unlock_tx_qs(priv);
 560                unlock_rx_qs(priv);
 561                local_irq_restore(flags);
 562
 563                for (i = 0; i < priv->num_rx_queues; i++)
 564                        gfar_clean_rx_ring(priv->rx_queue[i],
 565                                           priv->rx_queue[i]->rx_ring_size);
 566
 567                /* Now we take down the rings to rebuild them */
 568                stop_gfar(dev);
 569
 570                dev->features = features;
 571
 572                err = startup_gfar(dev);
 573                netif_tx_wake_all_queues(dev);
 574        }
 575        return err;
 576}
 577
 578static uint32_t gfar_get_msglevel(struct net_device *dev)
 579{
 580        struct gfar_private *priv = netdev_priv(dev);
 581
 582        return priv->msg_enable;
 583}
 584
 585static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
 586{
 587        struct gfar_private *priv = netdev_priv(dev);
 588
 589        priv->msg_enable = data;
 590}
 591
 592#ifdef CONFIG_PM
 593static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 594{
 595        struct gfar_private *priv = netdev_priv(dev);
 596
 597        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
 598                wol->supported = WAKE_MAGIC;
 599                wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
 600        } else {
 601                wol->supported = wol->wolopts = 0;
 602        }
 603}
 604
 605static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
 606{
 607        struct gfar_private *priv = netdev_priv(dev);
 608        unsigned long flags;
 609
 610        if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
 611            wol->wolopts != 0)
 612                return -EINVAL;
 613
 614        if (wol->wolopts & ~WAKE_MAGIC)
 615                return -EINVAL;
 616
 617        device_set_wakeup_enable(&dev->dev, wol->wolopts & WAKE_MAGIC);
 618
 619        spin_lock_irqsave(&priv->bflock, flags);
 620        priv->wol_en =  !!device_may_wakeup(&dev->dev);
 621        spin_unlock_irqrestore(&priv->bflock, flags);
 622
 623        return 0;
 624}
 625#endif
 626
 627static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow)
 628{
 629        u32 fcr = 0x0, fpr = FPR_FILER_MASK;
 630
 631        if (ethflow & RXH_L2DA) {
 632                fcr = RQFCR_PID_DAH |RQFCR_CMP_NOMATCH |
 633                      RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
 634                priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
 635                priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
 636                gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
 637                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 638
 639                fcr = RQFCR_PID_DAL | RQFCR_AND | RQFCR_CMP_NOMATCH |
 640                      RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
 641                priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
 642                priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
 643                gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
 644                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 645        }
 646
 647        if (ethflow & RXH_VLAN) {
 648                fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH |
 649                      RQFCR_AND | RQFCR_HASHTBL_0;
 650                gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
 651                priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
 652                priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
 653                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 654        }
 655
 656        if (ethflow & RXH_IP_SRC) {
 657                fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
 658                      RQFCR_AND | RQFCR_HASHTBL_0;
 659                priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
 660                priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
 661                gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
 662                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 663        }
 664
 665        if (ethflow & (RXH_IP_DST)) {
 666                fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
 667                      RQFCR_AND | RQFCR_HASHTBL_0;
 668                priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
 669                priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
 670                gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
 671                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 672        }
 673
 674        if (ethflow & RXH_L3_PROTO) {
 675                fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH |
 676                      RQFCR_AND | RQFCR_HASHTBL_0;
 677                priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
 678                priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
 679                gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
 680                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 681        }
 682
 683        if (ethflow & RXH_L4_B_0_1) {
 684                fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
 685                      RQFCR_AND | RQFCR_HASHTBL_0;
 686                priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
 687                priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
 688                gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
 689                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 690        }
 691
 692        if (ethflow & RXH_L4_B_2_3) {
 693                fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
 694                      RQFCR_AND | RQFCR_HASHTBL_0;
 695                priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
 696                priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
 697                gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
 698                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 699        }
 700}
 701
 702static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,
 703                                       u64 class)
 704{
 705        unsigned int last_rule_idx = priv->cur_filer_idx;
 706        unsigned int cmp_rqfpr;
 707        unsigned int *local_rqfpr;
 708        unsigned int *local_rqfcr;
 709        int i = 0x0, k = 0x0;
 710        int j = MAX_FILER_IDX, l = 0x0;
 711        int ret = 1;
 712
 713        local_rqfpr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int),
 714                                    GFP_KERNEL);
 715        local_rqfcr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int),
 716                                    GFP_KERNEL);
 717        if (!local_rqfpr || !local_rqfcr) {
 718                ret = 0;
 719                goto err;
 720        }
 721
 722        switch (class) {
 723        case TCP_V4_FLOW:
 724                cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP;
 725                break;
 726        case UDP_V4_FLOW:
 727                cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP;
 728                break;
 729        case TCP_V6_FLOW:
 730                cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP;
 731                break;
 732        case UDP_V6_FLOW:
 733                cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP;
 734                break;
 735        default:
 736                netdev_err(priv->ndev,
 737                           "Right now this class is not supported\n");
 738                ret = 0;
 739                goto err;
 740        }
 741
 742        for (i = 0; i < MAX_FILER_IDX + 1; i++) {
 743                local_rqfpr[j] = priv->ftp_rqfpr[i];
 744                local_rqfcr[j] = priv->ftp_rqfcr[i];
 745                j--;
 746                if ((priv->ftp_rqfcr[i] ==
 747                     (RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND)) &&
 748                    (priv->ftp_rqfpr[i] == cmp_rqfpr))
 749                        break;
 750        }
 751
 752        if (i == MAX_FILER_IDX + 1) {
 753                netdev_err(priv->ndev,
 754                           "No parse rule found, can't create hash rules\n");
 755                ret = 0;
 756                goto err;
 757        }
 758
 759        /* If a match was found, then it begins the starting of a cluster rule
 760         * if it was already programmed, we need to overwrite these rules
 761         */
 762        for (l = i+1; l < MAX_FILER_IDX; l++) {
 763                if ((priv->ftp_rqfcr[l] & RQFCR_CLE) &&
 764                    !(priv->ftp_rqfcr[l] & RQFCR_AND)) {
 765                        priv->ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT |
 766                                             RQFCR_HASHTBL_0 | RQFCR_PID_MASK;
 767                        priv->ftp_rqfpr[l] = FPR_FILER_MASK;
 768                        gfar_write_filer(priv, l, priv->ftp_rqfcr[l],
 769                                         priv->ftp_rqfpr[l]);
 770                        break;
 771                }
 772
 773                if (!(priv->ftp_rqfcr[l] & RQFCR_CLE) &&
 774                        (priv->ftp_rqfcr[l] & RQFCR_AND))
 775                        continue;
 776                else {
 777                        local_rqfpr[j] = priv->ftp_rqfpr[l];
 778                        local_rqfcr[j] = priv->ftp_rqfcr[l];
 779                        j--;
 780                }
 781        }
 782
 783        priv->cur_filer_idx = l - 1;
 784        last_rule_idx = l;
 785
 786        /* hash rules */
 787        ethflow_to_filer_rules(priv, ethflow);
 788
 789        /* Write back the popped out rules again */
 790        for (k = j+1; k < MAX_FILER_IDX; k++) {
 791                priv->ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k];
 792                priv->ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k];
 793                gfar_write_filer(priv, priv->cur_filer_idx,
 794                                 local_rqfcr[k], local_rqfpr[k]);
 795                if (!priv->cur_filer_idx)
 796                        break;
 797                priv->cur_filer_idx = priv->cur_filer_idx - 1;
 798        }
 799
 800err:
 801        kfree(local_rqfcr);
 802        kfree(local_rqfpr);
 803        return ret;
 804}
 805
 806static int gfar_set_hash_opts(struct gfar_private *priv,
 807                              struct ethtool_rxnfc *cmd)
 808{
 809        /* write the filer rules here */
 810        if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type))
 811                return -EINVAL;
 812
 813        return 0;
 814}
 815
 816static int gfar_check_filer_hardware(struct gfar_private *priv)
 817{
 818        struct gfar __iomem *regs = NULL;
 819        u32 i;
 820
 821        regs = priv->gfargrp[0].regs;
 822
 823        /* Check if we are in FIFO mode */
 824        i = gfar_read(&regs->ecntrl);
 825        i &= ECNTRL_FIFM;
 826        if (i == ECNTRL_FIFM) {
 827                netdev_notice(priv->ndev, "Interface in FIFO mode\n");
 828                i = gfar_read(&regs->rctrl);
 829                i &= RCTRL_PRSDEP_MASK | RCTRL_PRSFM;
 830                if (i == (RCTRL_PRSDEP_MASK | RCTRL_PRSFM)) {
 831                        netdev_info(priv->ndev,
 832                                    "Receive Queue Filtering enabled\n");
 833                } else {
 834                        netdev_warn(priv->ndev,
 835                                    "Receive Queue Filtering disabled\n");
 836                        return -EOPNOTSUPP;
 837                }
 838        }
 839        /* Or in standard mode */
 840        else {
 841                i = gfar_read(&regs->rctrl);
 842                i &= RCTRL_PRSDEP_MASK;
 843                if (i == RCTRL_PRSDEP_MASK) {
 844                        netdev_info(priv->ndev,
 845                                    "Receive Queue Filtering enabled\n");
 846                } else {
 847                        netdev_warn(priv->ndev,
 848                                    "Receive Queue Filtering disabled\n");
 849                        return -EOPNOTSUPP;
 850                }
 851        }
 852
 853        /* Sets the properties for arbitrary filer rule
 854         * to the first 4 Layer 4 Bytes
 855         */
 856        regs->rbifx = 0xC0C1C2C3;
 857        return 0;
 858}
 859
 860static int gfar_comp_asc(const void *a, const void *b)
 861{
 862        return memcmp(a, b, 4);
 863}
 864
 865static int gfar_comp_desc(const void *a, const void *b)
 866{
 867        return -memcmp(a, b, 4);
 868}
 869
 870static void gfar_swap(void *a, void *b, int size)
 871{
 872        u32 *_a = a;
 873        u32 *_b = b;
 874
 875        swap(_a[0], _b[0]);
 876        swap(_a[1], _b[1]);
 877        swap(_a[2], _b[2]);
 878        swap(_a[3], _b[3]);
 879}
 880
 881/* Write a mask to filer cache */
 882static void gfar_set_mask(u32 mask, struct filer_table *tab)
 883{
 884        tab->fe[tab->index].ctrl = RQFCR_AND | RQFCR_PID_MASK | RQFCR_CMP_EXACT;
 885        tab->fe[tab->index].prop = mask;
 886        tab->index++;
 887}
 888
 889/* Sets parse bits (e.g. IP or TCP) */
 890static void gfar_set_parse_bits(u32 value, u32 mask, struct filer_table *tab)
 891{
 892        gfar_set_mask(mask, tab);
 893        tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_PID_PARSE |
 894                                   RQFCR_AND;
 895        tab->fe[tab->index].prop = value;
 896        tab->index++;
 897}
 898
 899static void gfar_set_general_attribute(u32 value, u32 mask, u32 flag,
 900                                       struct filer_table *tab)
 901{
 902        gfar_set_mask(mask, tab);
 903        tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_AND | flag;
 904        tab->fe[tab->index].prop = value;
 905        tab->index++;
 906}
 907
 908/* For setting a tuple of value and mask of type flag
 909 * Example:
 910 * IP-Src = 10.0.0.0/255.0.0.0
 911 * value: 0x0A000000 mask: FF000000 flag: RQFPR_IPV4
 912 *
 913 * Ethtool gives us a value=0 and mask=~0 for don't care a tuple
 914 * For a don't care mask it gives us a 0
 915 *
 916 * The check if don't care and the mask adjustment if mask=0 is done for VLAN
 917 * and MAC stuff on an upper level (due to missing information on this level).
 918 * For these guys we can discard them if they are value=0 and mask=0.
 919 *
 920 * Further the all masks are one-padded for better hardware efficiency.
 921 */
 922static void gfar_set_attribute(u32 value, u32 mask, u32 flag,
 923                               struct filer_table *tab)
 924{
 925        switch (flag) {
 926                /* 3bit */
 927        case RQFCR_PID_PRI:
 928                if (!(value | mask))
 929                        return;
 930                mask |= RQFCR_PID_PRI_MASK;
 931                break;
 932                /* 8bit */
 933        case RQFCR_PID_L4P:
 934        case RQFCR_PID_TOS:
 935                if (!~(mask | RQFCR_PID_L4P_MASK))
 936                        return;
 937                if (!mask)
 938                        mask = ~0;
 939                else
 940                        mask |= RQFCR_PID_L4P_MASK;
 941                break;
 942                /* 12bit */
 943        case RQFCR_PID_VID:
 944                if (!(value | mask))
 945                        return;
 946                mask |= RQFCR_PID_VID_MASK;
 947                break;
 948                /* 16bit */
 949        case RQFCR_PID_DPT:
 950        case RQFCR_PID_SPT:
 951        case RQFCR_PID_ETY:
 952                if (!~(mask | RQFCR_PID_PORT_MASK))
 953                        return;
 954                if (!mask)
 955                        mask = ~0;
 956                else
 957                        mask |= RQFCR_PID_PORT_MASK;
 958                break;
 959                /* 24bit */
 960        case RQFCR_PID_DAH:
 961        case RQFCR_PID_DAL:
 962        case RQFCR_PID_SAH:
 963        case RQFCR_PID_SAL:
 964                if (!(value | mask))
 965                        return;
 966                mask |= RQFCR_PID_MAC_MASK;
 967                break;
 968                /* for all real 32bit masks */
 969        default:
 970                if (!~mask)
 971                        return;
 972                if (!mask)
 973                        mask = ~0;
 974                break;
 975        }
 976        gfar_set_general_attribute(value, mask, flag, tab);
 977}
 978
 979/* Translates value and mask for UDP, TCP or SCTP */
 980static void gfar_set_basic_ip(struct ethtool_tcpip4_spec *value,
 981                              struct ethtool_tcpip4_spec *mask,
 982                              struct filer_table *tab)
 983{
 984        gfar_set_attribute(value->ip4src, mask->ip4src, RQFCR_PID_SIA, tab);
 985        gfar_set_attribute(value->ip4dst, mask->ip4dst, RQFCR_PID_DIA, tab);
 986        gfar_set_attribute(value->pdst, mask->pdst, RQFCR_PID_DPT, tab);
 987        gfar_set_attribute(value->psrc, mask->psrc, RQFCR_PID_SPT, tab);
 988        gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab);
 989}
 990
 991/* Translates value and mask for RAW-IP4 */
 992static void gfar_set_user_ip(struct ethtool_usrip4_spec *value,
 993                             struct ethtool_usrip4_spec *mask,
 994                             struct filer_table *tab)
 995{
 996        gfar_set_attribute(value->ip4src, mask->ip4src, RQFCR_PID_SIA, tab);
 997        gfar_set_attribute(value->ip4dst, mask->ip4dst, RQFCR_PID_DIA, tab);
 998        gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab);
 999        gfar_set_attribute(value->proto, mask->proto, RQFCR_PID_L4P, tab);
1000        gfar_set_attribute(value->l4_4_bytes, mask->l4_4_bytes, RQFCR_PID_ARB,
1001                           tab);
1002
1003}
1004
1005/* Translates value and mask for ETHER spec */
1006static void gfar_set_ether(struct ethhdr *value, struct ethhdr *mask,
1007                           struct filer_table *tab)
1008{
1009        u32 upper_temp_mask = 0;
1010        u32 lower_temp_mask = 0;
1011
1012        /* Source address */
1013        if (!is_broadcast_ether_addr(mask->h_source)) {
1014                if (is_zero_ether_addr(mask->h_source)) {
1015                        upper_temp_mask = 0xFFFFFFFF;
1016                        lower_temp_mask = 0xFFFFFFFF;
1017                } else {
1018                        upper_temp_mask = mask->h_source[0] << 16 |
1019                                          mask->h_source[1] << 8  |
1020                                          mask->h_source[2];
1021                        lower_temp_mask = mask->h_source[3] << 16 |
1022                                          mask->h_source[4] << 8  |
1023                                          mask->h_source[5];
1024                }
1025                /* Upper 24bit */
1026                gfar_set_attribute(value->h_source[0] << 16 |
1027                                   value->h_source[1] << 8  |
1028                                   value->h_source[2],
1029                                   upper_temp_mask, RQFCR_PID_SAH, tab);
1030                /* And the same for the lower part */
1031                gfar_set_attribute(value->h_source[3] << 16 |
1032                                   value->h_source[4] << 8  |
1033                                   value->h_source[5],
1034                                   lower_temp_mask, RQFCR_PID_SAL, tab);
1035        }
1036        /* Destination address */
1037        if (!is_broadcast_ether_addr(mask->h_dest)) {
1038                /* Special for destination is limited broadcast */
1039                if ((is_broadcast_ether_addr(value->h_dest) &&
1040                    is_zero_ether_addr(mask->h_dest))) {
1041                        gfar_set_parse_bits(RQFPR_EBC, RQFPR_EBC, tab);
1042                } else {
1043                        if (is_zero_ether_addr(mask->h_dest)) {
1044                                upper_temp_mask = 0xFFFFFFFF;
1045                                lower_temp_mask = 0xFFFFFFFF;
1046                        } else {
1047                                upper_temp_mask = mask->h_dest[0] << 16 |
1048                                                  mask->h_dest[1] << 8  |
1049                                                  mask->h_dest[2];
1050                                lower_temp_mask = mask->h_dest[3] << 16 |
1051                                                  mask->h_dest[4] << 8  |
1052                                                  mask->h_dest[5];
1053                        }
1054
1055                        /* Upper 24bit */
1056                        gfar_set_attribute(value->h_dest[0] << 16 |
1057                                           value->h_dest[1] << 8  |
1058                                           value->h_dest[2],
1059                                           upper_temp_mask, RQFCR_PID_DAH, tab);
1060                        /* And the same for the lower part */
1061                        gfar_set_attribute(value->h_dest[3] << 16 |
1062                                           value->h_dest[4] << 8  |
1063                                           value->h_dest[5],
1064                                           lower_temp_mask, RQFCR_PID_DAL, tab);
1065                }
1066        }
1067
1068        gfar_set_attribute(value->h_proto, mask->h_proto, RQFCR_PID_ETY, tab);
1069}
1070
1071/* Convert a rule to binary filter format of gianfar */
1072static int gfar_convert_to_filer(struct ethtool_rx_flow_spec *rule,
1073                                 struct filer_table *tab)
1074{
1075        u32 vlan = 0, vlan_mask = 0;
1076        u32 id = 0, id_mask = 0;
1077        u32 cfi = 0, cfi_mask = 0;
1078        u32 prio = 0, prio_mask = 0;
1079        u32 old_index = tab->index;
1080
1081        /* Check if vlan is wanted */
1082        if ((rule->flow_type & FLOW_EXT) && (rule->m_ext.vlan_tci != 0xFFFF)) {
1083                if (!rule->m_ext.vlan_tci)
1084                        rule->m_ext.vlan_tci = 0xFFFF;
1085
1086                vlan = RQFPR_VLN;
1087                vlan_mask = RQFPR_VLN;
1088
1089                /* Separate the fields */
1090                id = rule->h_ext.vlan_tci & VLAN_VID_MASK;
1091                id_mask = rule->m_ext.vlan_tci & VLAN_VID_MASK;
1092                cfi = rule->h_ext.vlan_tci & VLAN_CFI_MASK;
1093                cfi_mask = rule->m_ext.vlan_tci & VLAN_CFI_MASK;
1094                prio = (rule->h_ext.vlan_tci & VLAN_PRIO_MASK) >>
1095                       VLAN_PRIO_SHIFT;
1096                prio_mask = (rule->m_ext.vlan_tci & VLAN_PRIO_MASK) >>
1097                            VLAN_PRIO_SHIFT;
1098
1099                if (cfi == VLAN_TAG_PRESENT && cfi_mask == VLAN_TAG_PRESENT) {
1100                        vlan |= RQFPR_CFI;
1101                        vlan_mask |= RQFPR_CFI;
1102                } else if (cfi != VLAN_TAG_PRESENT &&
1103                           cfi_mask == VLAN_TAG_PRESENT) {
1104                        vlan_mask |= RQFPR_CFI;
1105                }
1106        }
1107
1108        switch (rule->flow_type & ~FLOW_EXT) {
1109        case TCP_V4_FLOW:
1110                gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_TCP | vlan,
1111                                    RQFPR_IPV4 | RQFPR_TCP | vlan_mask, tab);
1112                gfar_set_basic_ip(&rule->h_u.tcp_ip4_spec,
1113                                  &rule->m_u.tcp_ip4_spec, tab);
1114                break;
1115        case UDP_V4_FLOW:
1116                gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_UDP | vlan,
1117                                    RQFPR_IPV4 | RQFPR_UDP | vlan_mask, tab);
1118                gfar_set_basic_ip(&rule->h_u.udp_ip4_spec,
1119                                  &rule->m_u.udp_ip4_spec, tab);
1120                break;
1121        case SCTP_V4_FLOW:
1122                gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask,
1123                                    tab);
1124                gfar_set_attribute(132, 0, RQFCR_PID_L4P, tab);
1125                gfar_set_basic_ip((struct ethtool_tcpip4_spec *)&rule->h_u,
1126                                  (struct ethtool_tcpip4_spec *)&rule->m_u,
1127                                  tab);
1128                break;
1129        case IP_USER_FLOW:
1130                gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask,
1131                                    tab);
1132                gfar_set_user_ip((struct ethtool_usrip4_spec *) &rule->h_u,
1133                                 (struct ethtool_usrip4_spec *) &rule->m_u,
1134                                 tab);
1135                break;
1136        case ETHER_FLOW:
1137                if (vlan)
1138                        gfar_set_parse_bits(vlan, vlan_mask, tab);
1139                gfar_set_ether((struct ethhdr *) &rule->h_u,
1140                               (struct ethhdr *) &rule->m_u, tab);
1141                break;
1142        default:
1143                return -1;
1144        }
1145
1146        /* Set the vlan attributes in the end */
1147        if (vlan) {
1148                gfar_set_attribute(id, id_mask, RQFCR_PID_VID, tab);
1149                gfar_set_attribute(prio, prio_mask, RQFCR_PID_PRI, tab);
1150        }
1151
1152        /* If there has been nothing written till now, it must be a default */
1153        if (tab->index == old_index) {
1154                gfar_set_mask(0xFFFFFFFF, tab);
1155                tab->fe[tab->index].ctrl = 0x20;
1156                tab->fe[tab->index].prop = 0x0;
1157                tab->index++;
1158        }
1159
1160        /* Remove last AND */
1161        tab->fe[tab->index - 1].ctrl &= (~RQFCR_AND);
1162
1163        /* Specify which queue to use or to drop */
1164        if (rule->ring_cookie == RX_CLS_FLOW_DISC)
1165                tab->fe[tab->index - 1].ctrl |= RQFCR_RJE;
1166        else
1167                tab->fe[tab->index - 1].ctrl |= (rule->ring_cookie << 10);
1168
1169        /* Only big enough entries can be clustered */
1170        if (tab->index > (old_index + 2)) {
1171                tab->fe[old_index + 1].ctrl |= RQFCR_CLE;
1172                tab->fe[tab->index - 1].ctrl |= RQFCR_CLE;
1173        }
1174
1175        /* In rare cases the cache can be full while there is
1176         * free space in hw
1177         */
1178        if (tab->index > MAX_FILER_CACHE_IDX - 1)
1179                return -EBUSY;
1180
1181        return 0;
1182}
1183
1184/* Copy size filer entries */
1185static void gfar_copy_filer_entries(struct gfar_filer_entry dst[0],
1186                                    struct gfar_filer_entry src[0], s32 size)
1187{
1188        while (size > 0) {
1189                size--;
1190                dst[size].ctrl = src[size].ctrl;
1191                dst[size].prop = src[size].prop;
1192        }
1193}
1194
1195/* Delete the contents of the filer-table between start and end
1196 * and collapse them
1197 */
1198static int gfar_trim_filer_entries(u32 begin, u32 end, struct filer_table *tab)
1199{
1200        int length;
1201
1202        if (end > MAX_FILER_CACHE_IDX || end < begin)
1203                return -EINVAL;
1204
1205        end++;
1206        length = end - begin;
1207
1208        /* Copy */
1209        while (end < tab->index) {
1210                tab->fe[begin].ctrl = tab->fe[end].ctrl;
1211                tab->fe[begin++].prop = tab->fe[end++].prop;
1212
1213        }
1214        /* Fill up with don't cares */
1215        while (begin < tab->index) {
1216                tab->fe[begin].ctrl = 0x60;
1217                tab->fe[begin].prop = 0xFFFFFFFF;
1218                begin++;
1219        }
1220
1221        tab->index -= length;
1222        return 0;
1223}
1224
1225/* Make space on the wanted location */
1226static int gfar_expand_filer_entries(u32 begin, u32 length,
1227                                     struct filer_table *tab)
1228{
1229        if (length == 0 || length + tab->index > MAX_FILER_CACHE_IDX ||
1230            begin > MAX_FILER_CACHE_IDX)
1231                return -EINVAL;
1232
1233        gfar_copy_filer_entries(&(tab->fe[begin + length]), &(tab->fe[begin]),
1234                                tab->index - length + 1);
1235
1236        tab->index += length;
1237        return 0;
1238}
1239
1240static int gfar_get_next_cluster_start(int start, struct filer_table *tab)
1241{
1242        for (; (start < tab->index) && (start < MAX_FILER_CACHE_IDX - 1);
1243             start++) {
1244                if ((tab->fe[start].ctrl & (RQFCR_AND | RQFCR_CLE)) ==
1245                    (RQFCR_AND | RQFCR_CLE))
1246                        return start;
1247        }
1248        return -1;
1249}
1250
1251static int gfar_get_next_cluster_end(int start, struct filer_table *tab)
1252{
1253        for (; (start < tab->index) && (start < MAX_FILER_CACHE_IDX - 1);
1254             start++) {
1255                if ((tab->fe[start].ctrl & (RQFCR_AND | RQFCR_CLE)) ==
1256                    (RQFCR_CLE))
1257                        return start;
1258        }
1259        return -1;
1260}
1261
1262/* Uses hardwares clustering option to reduce
1263 * the number of filer table entries
1264 */
1265static void gfar_cluster_filer(struct filer_table *tab)
1266{
1267        s32 i = -1, j, iend, jend;
1268
1269        while ((i = gfar_get_next_cluster_start(++i, tab)) != -1) {
1270                j = i;
1271                while ((j = gfar_get_next_cluster_start(++j, tab)) != -1) {
1272                        /* The cluster entries self and the previous one
1273                         * (a mask) must be identical!
1274                         */
1275                        if (tab->fe[i].ctrl != tab->fe[j].ctrl)
1276                                break;
1277                        if (tab->fe[i].prop != tab->fe[j].prop)
1278                                break;
1279                        if (tab->fe[i - 1].ctrl != tab->fe[j - 1].ctrl)
1280                                break;
1281                        if (tab->fe[i - 1].prop != tab->fe[j - 1].prop)
1282                                break;
1283                        iend = gfar_get_next_cluster_end(i, tab);
1284                        jend = gfar_get_next_cluster_end(j, tab);
1285                        if (jend == -1 || iend == -1)
1286                                break;
1287
1288                        /* First we make some free space, where our cluster
1289                         * element should be. Then we copy it there and finally
1290                         * delete in from its old location.
1291                         */
1292                        if (gfar_expand_filer_entries(iend, (jend - j), tab) ==
1293                            -EINVAL)
1294                                break;
1295
1296                        gfar_copy_filer_entries(&(tab->fe[iend + 1]),
1297                                                &(tab->fe[jend + 1]), jend - j);
1298
1299                        if (gfar_trim_filer_entries(jend - 1,
1300                                                    jend + (jend - j),
1301                                                    tab) == -EINVAL)
1302                                return;
1303
1304                        /* Mask out cluster bit */
1305                        tab->fe[iend].ctrl &= ~(RQFCR_CLE);
1306                }
1307        }
1308}
1309
1310/* Swaps the masked bits of a1<>a2 and b1<>b2 */
1311static void gfar_swap_bits(struct gfar_filer_entry *a1,
1312                           struct gfar_filer_entry *a2,
1313                           struct gfar_filer_entry *b1,
1314                           struct gfar_filer_entry *b2, u32 mask)
1315{
1316        u32 temp[4];
1317        temp[0] = a1->ctrl & mask;
1318        temp[1] = a2->ctrl & mask;
1319        temp[2] = b1->ctrl & mask;
1320        temp[3] = b2->ctrl & mask;
1321
1322        a1->ctrl &= ~mask;
1323        a2->ctrl &= ~mask;
1324        b1->ctrl &= ~mask;
1325        b2->ctrl &= ~mask;
1326
1327        a1->ctrl |= temp[1];
1328        a2->ctrl |= temp[0];
1329        b1->ctrl |= temp[3];
1330        b2->ctrl |= temp[2];
1331}
1332
1333/* Generate a list consisting of masks values with their start and
1334 * end of validity and block as indicator for parts belonging
1335 * together (glued by ANDs) in mask_table
1336 */
1337static u32 gfar_generate_mask_table(struct gfar_mask_entry *mask_table,
1338                                    struct filer_table *tab)
1339{
1340        u32 i, and_index = 0, block_index = 1;
1341
1342        for (i = 0; i < tab->index; i++) {
1343
1344                /* LSByte of control = 0 sets a mask */
1345                if (!(tab->fe[i].ctrl & 0xF)) {
1346                        mask_table[and_index].mask = tab->fe[i].prop;
1347                        mask_table[and_index].start = i;
1348                        mask_table[and_index].block = block_index;
1349                        if (and_index >= 1)
1350                                mask_table[and_index - 1].end = i - 1;
1351                        and_index++;
1352                }
1353                /* cluster starts and ends will be separated because they should
1354                 * hold their position
1355                 */
1356                if (tab->fe[i].ctrl & RQFCR_CLE)
1357                        block_index++;
1358                /* A not set AND indicates the end of a depended block */
1359                if (!(tab->fe[i].ctrl & RQFCR_AND))
1360                        block_index++;
1361        }
1362
1363        mask_table[and_index - 1].end = i - 1;
1364
1365        return and_index;
1366}
1367
1368/* Sorts the entries of mask_table by the values of the masks.
1369 * Important: The 0xFF80 flags of the first and last entry of a
1370 * block must hold their position (which queue, CLusterEnable, ReJEct,
1371 * AND)
1372 */
1373static void gfar_sort_mask_table(struct gfar_mask_entry *mask_table,
1374                                 struct filer_table *temp_table, u32 and_index)
1375{
1376        /* Pointer to compare function (_asc or _desc) */
1377        int (*gfar_comp)(const void *, const void *);
1378
1379        u32 i, size = 0, start = 0, prev = 1;
1380        u32 old_first, old_last, new_first, new_last;
1381
1382        gfar_comp = &gfar_comp_desc;
1383
1384        for (i = 0; i < and_index; i++) {
1385                if (prev != mask_table[i].block) {
1386                        old_first = mask_table[start].start + 1;
1387                        old_last = mask_table[i - 1].end;
1388                        sort(mask_table + start, size,
1389                             sizeof(struct gfar_mask_entry),
1390                             gfar_comp, &gfar_swap);
1391
1392                        /* Toggle order for every block. This makes the
1393                         * thing more efficient!
1394                         */
1395                        if (gfar_comp == gfar_comp_desc)
1396                                gfar_comp = &gfar_comp_asc;
1397                        else
1398                                gfar_comp = &gfar_comp_desc;
1399
1400                        new_first = mask_table[start].start + 1;
1401                        new_last = mask_table[i - 1].end;
1402
1403                        gfar_swap_bits(&temp_table->fe[new_first],
1404                                       &temp_table->fe[old_first],
1405                                       &temp_table->fe[new_last],
1406                                       &temp_table->fe[old_last],
1407                                       RQFCR_QUEUE | RQFCR_CLE |
1408                                       RQFCR_RJE | RQFCR_AND);
1409
1410                        start = i;
1411                        size = 0;
1412                }
1413                size++;
1414                prev = mask_table[i].block;
1415        }
1416}
1417
1418/* Reduces the number of masks needed in the filer table to save entries
1419 * This is done by sorting the masks of a depended block. A depended block is
1420 * identified by gluing ANDs or CLE. The sorting order toggles after every
1421 * block. Of course entries in scope of a mask must change their location with
1422 * it.
1423 */
1424static int gfar_optimize_filer_masks(struct filer_table *tab)
1425{
1426        struct filer_table *temp_table;
1427        struct gfar_mask_entry *mask_table;
1428
1429        u32 and_index = 0, previous_mask = 0, i = 0, j = 0, size = 0;
1430        s32 ret = 0;
1431
1432        /* We need a copy of the filer table because
1433         * we want to change its order
1434         */
1435        temp_table = kmemdup(tab, sizeof(*temp_table), GFP_KERNEL);
1436        if (temp_table == NULL)
1437                return -ENOMEM;
1438
1439        mask_table = kcalloc(MAX_FILER_CACHE_IDX / 2 + 1,
1440                             sizeof(struct gfar_mask_entry), GFP_KERNEL);
1441
1442        if (mask_table == NULL) {
1443                ret = -ENOMEM;
1444                goto end;
1445        }
1446
1447        and_index = gfar_generate_mask_table(mask_table, tab);
1448
1449        gfar_sort_mask_table(mask_table, temp_table, and_index);
1450
1451        /* Now we can copy the data from our duplicated filer table to
1452         * the real one in the order the mask table says
1453         */
1454        for (i = 0; i < and_index; i++) {
1455                size = mask_table[i].end - mask_table[i].start + 1;
1456                gfar_copy_filer_entries(&(tab->fe[j]),
1457                                &(temp_table->fe[mask_table[i].start]), size);
1458                j += size;
1459        }
1460
1461        /* And finally we just have to check for duplicated masks and drop the
1462         * second ones
1463         */
1464        for (i = 0; i < tab->index && i < MAX_FILER_CACHE_IDX; i++) {
1465                if (tab->fe[i].ctrl == 0x80) {
1466                        previous_mask = i++;
1467                        break;
1468                }
1469        }
1470        for (; i < tab->index && i < MAX_FILER_CACHE_IDX; i++) {
1471                if (tab->fe[i].ctrl == 0x80) {
1472                        if (tab->fe[i].prop == tab->fe[previous_mask].prop) {
1473                                /* Two identical ones found!
1474                                 * So drop the second one!
1475                                 */
1476                                gfar_trim_filer_entries(i, i, tab);
1477                        } else
1478                                /* Not identical! */
1479                                previous_mask = i;
1480                }
1481        }
1482
1483        kfree(mask_table);
1484end:    kfree(temp_table);
1485        return ret;
1486}
1487
1488/* Write the bit-pattern from software's buffer to hardware registers */
1489static int gfar_write_filer_table(struct gfar_private *priv,
1490                                  struct filer_table *tab)
1491{
1492        u32 i = 0;
1493        if (tab->index > MAX_FILER_IDX - 1)
1494                return -EBUSY;
1495
1496        /* Avoid inconsistent filer table to be processed */
1497        lock_rx_qs(priv);
1498
1499        /* Fill regular entries */
1500        for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].ctrl);
1501             i++)
1502                gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop);
1503        /* Fill the rest with fall-troughs */
1504        for (; i < MAX_FILER_IDX - 1; i++)
1505                gfar_write_filer(priv, i, 0x60, 0xFFFFFFFF);
1506        /* Last entry must be default accept
1507         * because that's what people expect
1508         */
1509        gfar_write_filer(priv, i, 0x20, 0x0);
1510
1511        unlock_rx_qs(priv);
1512
1513        return 0;
1514}
1515
1516static int gfar_check_capability(struct ethtool_rx_flow_spec *flow,
1517                                 struct gfar_private *priv)
1518{
1519
1520        if (flow->flow_type & FLOW_EXT) {
1521                if (~flow->m_ext.data[0] || ~flow->m_ext.data[1])
1522                        netdev_warn(priv->ndev,
1523                                    "User-specific data not supported!\n");
1524                if (~flow->m_ext.vlan_etype)
1525                        netdev_warn(priv->ndev,
1526                                    "VLAN-etype not supported!\n");
1527        }
1528        if (flow->flow_type == IP_USER_FLOW)
1529                if (flow->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4)
1530                        netdev_warn(priv->ndev,
1531                                    "IP-Version differing from IPv4 not supported!\n");
1532
1533        return 0;
1534}
1535
1536static int gfar_process_filer_changes(struct gfar_private *priv)
1537{
1538        struct ethtool_flow_spec_container *j;
1539        struct filer_table *tab;
1540        s32 i = 0;
1541        s32 ret = 0;
1542
1543        /* So index is set to zero, too! */
1544        tab = kzalloc(sizeof(*tab), GFP_KERNEL);
1545        if (tab == NULL)
1546                return -ENOMEM;
1547
1548        /* Now convert the existing filer data from flow_spec into
1549         * filer tables binary format
1550         */
1551        list_for_each_entry(j, &priv->rx_list.list, list) {
1552                ret = gfar_convert_to_filer(&j->fs, tab);
1553                if (ret == -EBUSY) {
1554                        netdev_err(priv->ndev,
1555                                   "Rule not added: No free space!\n");
1556                        goto end;
1557                }
1558                if (ret == -1) {
1559                        netdev_err(priv->ndev,
1560                                   "Rule not added: Unsupported Flow-type!\n");
1561                        goto end;
1562                }
1563        }
1564
1565        i = tab->index;
1566
1567        /* Optimizations to save entries */
1568        gfar_cluster_filer(tab);
1569        gfar_optimize_filer_masks(tab);
1570
1571        pr_debug("\tSummary:\n"
1572                 "\tData on hardware: %d\n"
1573                 "\tCompression rate: %d%%\n",
1574                 tab->index, 100 - (100 * tab->index) / i);
1575
1576        /* Write everything to hardware */
1577        ret = gfar_write_filer_table(priv, tab);
1578        if (ret == -EBUSY) {
1579                netdev_err(priv->ndev, "Rule not added: No free space!\n");
1580                goto end;
1581        }
1582
1583end:
1584        kfree(tab);
1585        return ret;
1586}
1587
1588static void gfar_invert_masks(struct ethtool_rx_flow_spec *flow)
1589{
1590        u32 i = 0;
1591
1592        for (i = 0; i < sizeof(flow->m_u); i++)
1593                flow->m_u.hdata[i] ^= 0xFF;
1594
1595        flow->m_ext.vlan_etype ^= 0xFFFF;
1596        flow->m_ext.vlan_tci ^= 0xFFFF;
1597        flow->m_ext.data[0] ^= ~0;
1598        flow->m_ext.data[1] ^= ~0;
1599}
1600
1601static int gfar_add_cls(struct gfar_private *priv,
1602                        struct ethtool_rx_flow_spec *flow)
1603{
1604        struct ethtool_flow_spec_container *temp, *comp;
1605        int ret = 0;
1606
1607        temp = kmalloc(sizeof(*temp), GFP_KERNEL);
1608        if (temp == NULL)
1609                return -ENOMEM;
1610        memcpy(&temp->fs, flow, sizeof(temp->fs));
1611
1612        gfar_invert_masks(&temp->fs);
1613        ret = gfar_check_capability(&temp->fs, priv);
1614        if (ret)
1615                goto clean_mem;
1616        /* Link in the new element at the right @location */
1617        if (list_empty(&priv->rx_list.list)) {
1618                ret = gfar_check_filer_hardware(priv);
1619                if (ret != 0)
1620                        goto clean_mem;
1621                list_add(&temp->list, &priv->rx_list.list);
1622                goto process;
1623        } else {
1624                list_for_each_entry(comp, &priv->rx_list.list, list) {
1625                        if (comp->fs.location > flow->location) {
1626                                list_add_tail(&temp->list, &comp->list);
1627                                goto process;
1628                        }
1629                        if (comp->fs.location == flow->location) {
1630                                netdev_err(priv->ndev,
1631                                           "Rule not added: ID %d not free!\n",
1632                                           flow->location);
1633                                ret = -EBUSY;
1634                                goto clean_mem;
1635                        }
1636                }
1637                list_add_tail(&temp->list, &priv->rx_list.list);
1638        }
1639
1640process:
1641        ret = gfar_process_filer_changes(priv);
1642        if (ret)
1643                goto clean_list;
1644        priv->rx_list.count++;
1645        return ret;
1646
1647clean_list:
1648        list_del(&temp->list);
1649clean_mem:
1650        kfree(temp);
1651        return ret;
1652}
1653
1654static int gfar_del_cls(struct gfar_private *priv, u32 loc)
1655{
1656        struct ethtool_flow_spec_container *comp;
1657        u32 ret = -EINVAL;
1658
1659        if (list_empty(&priv->rx_list.list))
1660                return ret;
1661
1662        list_for_each_entry(comp, &priv->rx_list.list, list) {
1663                if (comp->fs.location == loc) {
1664                        list_del(&comp->list);
1665                        kfree(comp);
1666                        priv->rx_list.count--;
1667                        gfar_process_filer_changes(priv);
1668                        ret = 0;
1669                        break;
1670                }
1671        }
1672
1673        return ret;
1674}
1675
1676static int gfar_get_cls(struct gfar_private *priv, struct ethtool_rxnfc *cmd)
1677{
1678        struct ethtool_flow_spec_container *comp;
1679        u32 ret = -EINVAL;
1680
1681        list_for_each_entry(comp, &priv->rx_list.list, list) {
1682                if (comp->fs.location == cmd->fs.location) {
1683                        memcpy(&cmd->fs, &comp->fs, sizeof(cmd->fs));
1684                        gfar_invert_masks(&cmd->fs);
1685                        ret = 0;
1686                        break;
1687                }
1688        }
1689
1690        return ret;
1691}
1692
1693static int gfar_get_cls_all(struct gfar_private *priv,
1694                            struct ethtool_rxnfc *cmd, u32 *rule_locs)
1695{
1696        struct ethtool_flow_spec_container *comp;
1697        u32 i = 0;
1698
1699        list_for_each_entry(comp, &priv->rx_list.list, list) {
1700                if (i == cmd->rule_cnt)
1701                        return -EMSGSIZE;
1702                rule_locs[i] = comp->fs.location;
1703                i++;
1704        }
1705
1706        cmd->data = MAX_FILER_IDX;
1707        cmd->rule_cnt = i;
1708
1709        return 0;
1710}
1711
1712static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
1713{
1714        struct gfar_private *priv = netdev_priv(dev);
1715        int ret = 0;
1716
1717        mutex_lock(&priv->rx_queue_access);
1718
1719        switch (cmd->cmd) {
1720        case ETHTOOL_SRXFH:
1721                ret = gfar_set_hash_opts(priv, cmd);
1722                break;
1723        case ETHTOOL_SRXCLSRLINS:
1724                if ((cmd->fs.ring_cookie != RX_CLS_FLOW_DISC &&
1725                     cmd->fs.ring_cookie >= priv->num_rx_queues) ||
1726                    cmd->fs.location >= MAX_FILER_IDX) {
1727                        ret = -EINVAL;
1728                        break;
1729                }
1730                ret = gfar_add_cls(priv, &cmd->fs);
1731                break;
1732        case ETHTOOL_SRXCLSRLDEL:
1733                ret = gfar_del_cls(priv, cmd->fs.location);
1734                break;
1735        default:
1736                ret = -EINVAL;
1737        }
1738
1739        mutex_unlock(&priv->rx_queue_access);
1740
1741        return ret;
1742}
1743
1744static int gfar_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
1745                        u32 *rule_locs)
1746{
1747        struct gfar_private *priv = netdev_priv(dev);
1748        int ret = 0;
1749
1750        switch (cmd->cmd) {
1751        case ETHTOOL_GRXRINGS:
1752                cmd->data = priv->num_rx_queues;
1753                break;
1754        case ETHTOOL_GRXCLSRLCNT:
1755                cmd->rule_cnt = priv->rx_list.count;
1756                break;
1757        case ETHTOOL_GRXCLSRULE:
1758                ret = gfar_get_cls(priv, cmd);
1759                break;
1760        case ETHTOOL_GRXCLSRLALL:
1761                ret = gfar_get_cls_all(priv, cmd, rule_locs);
1762                break;
1763        default:
1764                ret = -EINVAL;
1765                break;
1766        }
1767
1768        return ret;
1769}
1770
1771int gfar_phc_index = -1;
1772EXPORT_SYMBOL(gfar_phc_index);
1773
1774static int gfar_get_ts_info(struct net_device *dev,
1775                            struct ethtool_ts_info *info)
1776{
1777        struct gfar_private *priv = netdev_priv(dev);
1778
1779        if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)) {
1780                info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
1781                                        SOF_TIMESTAMPING_SOFTWARE;
1782                info->phc_index = -1;
1783                return 0;
1784        }
1785        info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
1786                                SOF_TIMESTAMPING_RX_HARDWARE |
1787                                SOF_TIMESTAMPING_RAW_HARDWARE;
1788        info->phc_index = gfar_phc_index;
1789        info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1790                         (1 << HWTSTAMP_TX_ON);
1791        info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1792                           (1 << HWTSTAMP_FILTER_ALL);
1793        return 0;
1794}
1795
1796const struct ethtool_ops gfar_ethtool_ops = {
1797        .get_settings = gfar_gsettings,
1798        .set_settings = gfar_ssettings,
1799        .get_drvinfo = gfar_gdrvinfo,
1800        .get_regs_len = gfar_reglen,
1801        .get_regs = gfar_get_regs,
1802        .get_link = ethtool_op_get_link,
1803        .get_coalesce = gfar_gcoalesce,
1804        .set_coalesce = gfar_scoalesce,
1805        .get_ringparam = gfar_gringparam,
1806        .set_ringparam = gfar_sringparam,
1807        .get_strings = gfar_gstrings,
1808        .get_sset_count = gfar_sset_count,
1809        .get_ethtool_stats = gfar_fill_stats,
1810        .get_msglevel = gfar_get_msglevel,
1811        .set_msglevel = gfar_set_msglevel,
1812#ifdef CONFIG_PM
1813        .get_wol = gfar_get_wol,
1814        .set_wol = gfar_set_wol,
1815#endif
1816        .set_rxnfc = gfar_set_nfc,
1817        .get_rxnfc = gfar_get_nfc,
1818        .get_ts_info = gfar_get_ts_info,
1819};
1820