gianfar_ethtool.c 17.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8
/*
 *  drivers/net/gianfar_ethtool.c
 *
 *  Gianfar Ethernet Driver
 *  Ethtool support for Gianfar Enet
 *  Based on e1000 ethtool support
 *
 *  Author: Andy Fleming
9
 *  Maintainer: Kumar Gala
10
 *  Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
L
Linus Torvalds 已提交
11
 *
12
 *  Copyright 2003-2006, 2008-2009 Freescale Semiconductor, Inc.
L
Linus Torvalds 已提交
13
 *
14 15
 *  This software may be used and distributed according to
 *  the terms of the GNU Public License, Version 2, incorporated herein
L
Linus Torvalds 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *  by reference.
 */

#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/spinlock.h>
#include <linux/mm.h>

#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <linux/module.h>
#include <linux/crc32.h>
#include <asm/types.h>
#include <linux/ethtool.h>
39 40
#include <linux/mii.h>
#include <linux/phy.h>
L
Linus Torvalds 已提交
41 42 43

#include "gianfar.h"

44
extern void gfar_start(struct net_device *dev);
45
extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit);
L
Linus Torvalds 已提交
46

47 48
#define GFAR_MAX_COAL_USECS 0xffff
#define GFAR_MAX_COAL_FRAMES 0xff
49
static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
L
Linus Torvalds 已提交
50
		     u64 * buf);
51 52 53 54 55 56
static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo);
L
Linus Torvalds 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

static char stat_gstrings[][ETH_GSTRING_LEN] = {
	"rx-dropped-by-kernel",
	"rx-large-frame-errors",
	"rx-short-frame-errors",
	"rx-non-octet-errors",
	"rx-crc-errors",
	"rx-overrun-errors",
	"rx-busy-errors",
	"rx-babbling-errors",
	"rx-truncated-frames",
	"ethernet-bus-error",
	"tx-babbling-errors",
	"tx-underrun-errors",
	"rx-skb-missing-errors",
	"tx-timeout-errors",
	"tx-rx-64-frames",
	"tx-rx-65-127-frames",
	"tx-rx-128-255-frames",
	"tx-rx-256-511-frames",
	"tx-rx-512-1023-frames",
	"tx-rx-1024-1518-frames",
	"tx-rx-1519-1522-good-vlan",
	"rx-bytes",
	"rx-packets",
	"rx-fcs-errors",
	"receive-multicast-packet",
	"receive-broadcast-packet",
	"rx-control-frame-packets",
	"rx-pause-frame-packets",
	"rx-unknown-op-code",
	"rx-alignment-error",
	"rx-frame-length-error",
	"rx-code-error",
	"rx-carrier-sense-error",
	"rx-undersize-packets",
	"rx-oversize-packets",
	"rx-fragmented-frames",
	"rx-jabber-frames",
	"rx-dropped-frames",
	"tx-byte-counter",
	"tx-packets",
	"tx-multicast-packets",
	"tx-broadcast-packets",
	"tx-pause-control-frames",
	"tx-deferral-packets",
	"tx-excessive-deferral-packets",
	"tx-single-collision-packets",
	"tx-multiple-collision-packets",
	"tx-late-collision-packets",
	"tx-excessive-collision-packets",
	"tx-total-collision",
	"reserved",
	"tx-dropped-frames",
	"tx-jabber-frames",
	"tx-fcs-errors",
	"tx-control-frames",
	"tx-oversize-frames",
	"tx-undersize-frames",
	"tx-fragmented-frames",
};

119 120 121 122 123
/* Fill in a buffer with the strings which correspond to the
 * stats */
static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
{
	struct gfar_private *priv = netdev_priv(dev);
124

125
	if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
126 127 128 129 130 131
		memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
	else
		memcpy(buf, stat_gstrings,
				GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
}

L
Linus Torvalds 已提交
132 133 134 135
/* Fill in an array of 64-bit statistics from various sources.
 * This array will be appended to the end of the ethtool_stats
 * structure, and returned to user space
 */
136
static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf)
L
Linus Torvalds 已提交
137 138 139
{
	int i;
	struct gfar_private *priv = netdev_priv(dev);
140
	struct gfar __iomem *regs = priv->gfargrp.regs;
L
Linus Torvalds 已提交
141 142
	u64 *extra = (u64 *) & priv->extra_stats;

143
	if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
144
		u32 __iomem *rmon = (u32 __iomem *) &regs->rmon;
145
		struct gfar_stats *stats = (struct gfar_stats *) buf;
L
Linus Torvalds 已提交
146

147
		for (i = 0; i < GFAR_RMON_LEN; i++)
148
			stats->rmon[i] = (u64) gfar_read(&rmon[i]);
L
Linus Torvalds 已提交
149

150 151 152 153 154
		for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
			stats->extra[i] = extra[i];
	} else
		for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
			buf[i] = extra[i];
L
Linus Torvalds 已提交
155 156
}

157
static int gfar_sset_count(struct net_device *dev, int sset)
L
Linus Torvalds 已提交
158 159 160
{
	struct gfar_private *priv = netdev_priv(dev);

161 162
	switch (sset) {
	case ETH_SS_STATS:
163
		if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
164 165 166 167 168 169
			return GFAR_STATS_LEN;
		else
			return GFAR_EXTRA_STATS_LEN;
	default:
		return -EOPNOTSUPP;
	}
L
Linus Torvalds 已提交
170 171 172
}

/* Fills in the drvinfo structure with some basic info */
173
static void gfar_gdrvinfo(struct net_device *dev, struct
L
Linus Torvalds 已提交
174 175 176 177 178 179 180 181 182 183
	      ethtool_drvinfo *drvinfo)
{
	strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN);
	strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN);
	strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN);
	strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN);
	drvinfo->regdump_len = 0;
	drvinfo->eedump_len = 0;
}

184 185 186 187 188 189 190 191 192 193 194 195 196

static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
{
	struct gfar_private *priv = netdev_priv(dev);
	struct phy_device *phydev = priv->phydev;

	if (NULL == phydev)
		return -ENODEV;

	return phy_ethtool_sset(phydev, cmd);
}


L
Linus Torvalds 已提交
197
/* Return the current settings in the ethtool_cmd structure */
198
static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
L
Linus Torvalds 已提交
199 200
{
	struct gfar_private *priv = netdev_priv(dev);
201
	struct phy_device *phydev = priv->phydev;
202 203
	struct gfar_priv_rx_q *rx_queue = NULL;
	struct gfar_priv_tx_q *tx_queue = NULL;
204 205 206

	if (NULL == phydev)
		return -ENODEV;
207 208
	tx_queue = priv->tx_queue;
	rx_queue = priv->rx_queue;
209

210 211
	cmd->maxtxpkt = get_icft_value(tx_queue->txic);
	cmd->maxrxpkt = get_icft_value(rx_queue->rxic);
L
Linus Torvalds 已提交
212

213
	return phy_ethtool_gset(phydev, cmd);
L
Linus Torvalds 已提交
214 215 216
}

/* Return the length of the register structure */
217
static int gfar_reglen(struct net_device *dev)
L
Linus Torvalds 已提交
218 219 220 221 222
{
	return sizeof (struct gfar);
}

/* Return a dump of the GFAR register space */
223
static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
L
Linus Torvalds 已提交
224 225 226
{
	int i;
	struct gfar_private *priv = netdev_priv(dev);
227
	u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp.regs;
L
Linus Torvalds 已提交
228 229 230
	u32 *buf = (u32 *) regbuf;

	for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)
231
		buf[i] = gfar_read(&theregs[i]);
L
Linus Torvalds 已提交
232 233 234 235 236 237 238 239 240
}

/* Convert microseconds to ethernet clock ticks, which changes
 * depending on what speed the controller is running at */
static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs)
{
	unsigned int count;

	/* The timer is different, depending on the interface speed */
241 242
	switch (priv->phydev->speed) {
	case SPEED_1000:
L
Linus Torvalds 已提交
243 244
		count = GFAR_GBIT_TIME;
		break;
245
	case SPEED_100:
L
Linus Torvalds 已提交
246 247
		count = GFAR_100_TIME;
		break;
248
	case SPEED_10:
L
Linus Torvalds 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
	default:
		count = GFAR_10_TIME;
		break;
	}

	/* Make sure we return a number greater than 0
	 * if usecs > 0 */
	return ((usecs * 1000 + count - 1) / count);
}

/* Convert ethernet clock ticks to microseconds */
static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks)
{
	unsigned int count;

	/* The timer is different, depending on the interface speed */
265 266
	switch (priv->phydev->speed) {
	case SPEED_1000:
L
Linus Torvalds 已提交
267 268
		count = GFAR_GBIT_TIME;
		break;
269
	case SPEED_100:
L
Linus Torvalds 已提交
270 271
		count = GFAR_100_TIME;
		break;
272
	case SPEED_10:
L
Linus Torvalds 已提交
273 274 275 276 277 278 279 280 281 282 283 284
	default:
		count = GFAR_10_TIME;
		break;
	}

	/* Make sure we return a number greater than 0 */
	/* if ticks is > 0 */
	return ((ticks * count) / 1000);
}

/* Get the coalescing parameters, and put them in the cvals
 * structure.  */
285
static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
L
Linus Torvalds 已提交
286 287
{
	struct gfar_private *priv = netdev_priv(dev);
288 289
	struct gfar_priv_rx_q *rx_queue = NULL;
	struct gfar_priv_tx_q *tx_queue = NULL;
290 291 292 293
	unsigned long rxtime;
	unsigned long rxcount;
	unsigned long txtime;
	unsigned long txcount;
294

295
	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
296
		return -EOPNOTSUPP;
L
Linus Torvalds 已提交
297

298 299 300
	if (NULL == priv->phydev)
		return -ENODEV;

301 302 303 304 305 306 307
	rx_queue = priv->rx_queue;
	tx_queue = priv->tx_queue;

	rxtime  = get_ictt_value(rx_queue->rxic);
	rxcount = get_icft_value(rx_queue->rxic);
	txtime  = get_ictt_value(tx_queue->txic);
	txcount = get_icft_value(tx_queue->txic);
308 309
	cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime);
	cvals->rx_max_coalesced_frames = rxcount;
L
Linus Torvalds 已提交
310

311 312
	cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime);
	cvals->tx_max_coalesced_frames = txcount;
L
Linus Torvalds 已提交
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349

	cvals->use_adaptive_rx_coalesce = 0;
	cvals->use_adaptive_tx_coalesce = 0;

	cvals->pkt_rate_low = 0;
	cvals->rx_coalesce_usecs_low = 0;
	cvals->rx_max_coalesced_frames_low = 0;
	cvals->tx_coalesce_usecs_low = 0;
	cvals->tx_max_coalesced_frames_low = 0;

	/* When the packet rate is below pkt_rate_high but above
	 * pkt_rate_low (both measured in packets per second) the
	 * normal {rx,tx}_* coalescing parameters are used.
	 */

	/* When the packet rate is (measured in packets per second)
	 * is above pkt_rate_high, the {rx,tx}_*_high parameters are
	 * used.
	 */
	cvals->pkt_rate_high = 0;
	cvals->rx_coalesce_usecs_high = 0;
	cvals->rx_max_coalesced_frames_high = 0;
	cvals->tx_coalesce_usecs_high = 0;
	cvals->tx_max_coalesced_frames_high = 0;

	/* How often to do adaptive coalescing packet rate sampling,
	 * measured in seconds.  Must not be zero.
	 */
	cvals->rate_sample_interval = 0;

	return 0;
}

/* Change the coalescing values.
 * Both cvals->*_usecs and cvals->*_frames have to be > 0
 * in order for coalescing to be active
 */
350
static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
L
Linus Torvalds 已提交
351 352
{
	struct gfar_private *priv = netdev_priv(dev);
353
	struct gfar __iomem *regs = priv->gfargrp.regs;
354 355
	struct gfar_priv_tx_q *tx_queue = NULL;
	struct gfar_priv_rx_q *rx_queue = NULL;
L
Linus Torvalds 已提交
356

357
	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
358 359
		return -EOPNOTSUPP;

360 361 362
	tx_queue = priv->tx_queue;
	rx_queue = priv->rx_queue;

L
Linus Torvalds 已提交
363 364 365
	/* Set up rx coalescing */
	if ((cvals->rx_coalesce_usecs == 0) ||
	    (cvals->rx_max_coalesced_frames == 0))
366
		rx_queue->rxcoalescing = 0;
L
Linus Torvalds 已提交
367
	else
368
		rx_queue->rxcoalescing = 1;
L
Linus Torvalds 已提交
369

370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
	if (NULL == priv->phydev)
		return -ENODEV;

	/* Check the bounds of the values */
	if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
		pr_info("Coalescing is limited to %d microseconds\n",
				GFAR_MAX_COAL_USECS);
		return -EINVAL;
	}

	if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
		pr_info("Coalescing is limited to %d frames\n",
				GFAR_MAX_COAL_FRAMES);
		return -EINVAL;
	}

386
	rx_queue->rxic = mk_ic_value(cvals->rx_max_coalesced_frames,
387
		gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs));
L
Linus Torvalds 已提交
388 389 390 391

	/* Set up tx coalescing */
	if ((cvals->tx_coalesce_usecs == 0) ||
	    (cvals->tx_max_coalesced_frames == 0))
392
		tx_queue->txcoalescing = 0;
L
Linus Torvalds 已提交
393
	else
394
		tx_queue->txcoalescing = 1;
L
Linus Torvalds 已提交
395

396 397 398 399 400 401 402 403 404 405 406 407 408
	/* Check the bounds of the values */
	if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
		pr_info("Coalescing is limited to %d microseconds\n",
				GFAR_MAX_COAL_USECS);
		return -EINVAL;
	}

	if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
		pr_info("Coalescing is limited to %d frames\n",
				GFAR_MAX_COAL_FRAMES);
		return -EINVAL;
	}

409
	tx_queue->txic = mk_ic_value(cvals->tx_max_coalesced_frames,
410
		gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs));
L
Linus Torvalds 已提交
411

412
	gfar_write(&regs->rxic, 0);
413
	if (rx_queue->rxcoalescing)
414
		gfar_write(&regs->rxic, rx_queue->rxic);
L
Linus Torvalds 已提交
415

416
	gfar_write(&regs->txic, 0);
417
	if (tx_queue->txcoalescing)
418
		gfar_write(&regs->txic, tx_queue->txic);
L
Linus Torvalds 已提交
419 420 421 422 423 424 425

	return 0;
}

/* Fills in rvals with the current ring parameters.  Currently,
 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
 * jumbo are ignored by the driver */
426
static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
L
Linus Torvalds 已提交
427 428
{
	struct gfar_private *priv = netdev_priv(dev);
429 430 431 432 433
	struct gfar_priv_tx_q *tx_queue = NULL;
	struct gfar_priv_rx_q *rx_queue = NULL;

	tx_queue = priv->tx_queue;
	rx_queue = priv->rx_queue;
L
Linus Torvalds 已提交
434 435 436 437 438 439 440 441 442

	rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE;
	rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE;
	rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE;
	rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE;

	/* Values changeable by the user.  The valid values are
	 * in the range 1 to the "*_max_pending" counterpart above.
	 */
443 444 445 446
	rvals->rx_pending = rx_queue->rx_ring_size;
	rvals->rx_mini_pending = rx_queue->rx_ring_size;
	rvals->rx_jumbo_pending = rx_queue->rx_ring_size;
	rvals->tx_pending = tx_queue->tx_ring_size;
L
Linus Torvalds 已提交
447 448 449 450 451 452
}

/* Change the current ring parameters, stopping the controller if
 * necessary so that we don't mess things up while we're in
 * motion.  We wait for the ring to be clean before reallocating
 * the rings. */
453
static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
L
Linus Torvalds 已提交
454 455
{
	struct gfar_private *priv = netdev_priv(dev);
456 457
	struct gfar_priv_tx_q *tx_queue = NULL;
	struct gfar_priv_rx_q *rx_queue = NULL;
L
Linus Torvalds 已提交
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
	int err = 0;

	if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE)
		return -EINVAL;

	if (!is_power_of_2(rvals->rx_pending)) {
		printk("%s: Ring sizes must be a power of 2\n",
				dev->name);
		return -EINVAL;
	}

	if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE)
		return -EINVAL;

	if (!is_power_of_2(rvals->tx_pending)) {
		printk("%s: Ring sizes must be a power of 2\n",
				dev->name);
		return -EINVAL;
	}

478 479 480
	tx_queue = priv->tx_queue;
	rx_queue = priv->rx_queue;

481 482
	if (dev->flags & IFF_UP) {
		unsigned long flags;
L
Linus Torvalds 已提交
483

484 485
		/* Halt TX and RX, and process the frames which
		 * have already been received */
486 487
		spin_lock_irqsave(&tx_queue->txlock, flags);
		spin_lock(&rx_queue->rxlock);
A
Andy Fleming 已提交
488

489
		gfar_halt(dev);
A
Andy Fleming 已提交
490

491 492
		spin_unlock(&rx_queue->rxlock);
		spin_unlock_irqrestore(&tx_queue->txlock, flags);
L
Linus Torvalds 已提交
493

494
		gfar_clean_rx_ring(rx_queue, rx_queue->rx_ring_size);
495

496 497 498
		/* Now we take down the rings to rebuild them */
		stop_gfar(dev);
	}
L
Linus Torvalds 已提交
499

500
	/* Change the size */
501 502 503
	rx_queue->rx_ring_size = rvals->rx_pending;
	tx_queue->tx_ring_size = rvals->tx_pending;
	tx_queue->num_txbdfree = tx_queue->tx_ring_size;
L
Linus Torvalds 已提交
504

505
	/* Rebuild the rings with the new size */
506
	if (dev->flags & IFF_UP) {
507
		err = startup_gfar(dev);
508 509
		netif_wake_queue(dev);
	}
510 511
	return err;
}
L
Linus Torvalds 已提交
512

513 514 515
static int gfar_set_rx_csum(struct net_device *dev, uint32_t data)
{
	struct gfar_private *priv = netdev_priv(dev);
516 517
	struct gfar_priv_rx_q *rx_queue = NULL;
	struct gfar_priv_tx_q *tx_queue = NULL;
518
	unsigned long flags;
519
	int err = 0;
L
Linus Torvalds 已提交
520

521
	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
522 523
		return -EOPNOTSUPP;

524 525 526
	tx_queue = priv->tx_queue;
	rx_queue = priv->rx_queue;

527 528 529
	if (dev->flags & IFF_UP) {
		/* Halt TX and RX, and process the frames which
		 * have already been received */
530 531
		spin_lock_irqsave(&tx_queue->txlock, flags);
		spin_lock(&rx_queue->rxlock);
A
Andy Fleming 已提交
532

533
		gfar_halt(dev);
A
Andy Fleming 已提交
534

535 536
		spin_unlock(&rx_queue->rxlock);
		spin_unlock_irqrestore(&tx_queue->txlock, flags);
537

538
		gfar_clean_rx_ring(rx_queue, rx_queue->rx_ring_size);
539

540
		/* Now we take down the rings to rebuild them */
L
Linus Torvalds 已提交
541 542 543
		stop_gfar(dev);
	}

544
	spin_lock_irqsave(&priv->bflock, flags);
545
	priv->rx_csum_enable = data;
546
	spin_unlock_irqrestore(&priv->bflock, flags);
L
Linus Torvalds 已提交
547

548
	if (dev->flags & IFF_UP) {
L
Linus Torvalds 已提交
549
		err = startup_gfar(dev);
550 551
		netif_wake_queue(dev);
	}
L
Linus Torvalds 已提交
552 553 554
	return err;
}

555 556 557 558
static uint32_t gfar_get_rx_csum(struct net_device *dev)
{
	struct gfar_private *priv = netdev_priv(dev);

559
	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
560 561 562 563 564 565 566 567 568
		return 0;

	return priv->rx_csum_enable;
}

static int gfar_set_tx_csum(struct net_device *dev, uint32_t data)
{
	struct gfar_private *priv = netdev_priv(dev);

569
	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
570 571
		return -EOPNOTSUPP;

572
	netif_tx_lock_bh(dev);
573 574 575 576 577 578

	if (data)
		dev->features |= NETIF_F_IP_CSUM;
	else
		dev->features &= ~NETIF_F_IP_CSUM;

579
	netif_tx_unlock_bh(dev);
580 581 582 583 584 585 586 587

	return 0;
}

static uint32_t gfar_get_tx_csum(struct net_device *dev)
{
	struct gfar_private *priv = netdev_priv(dev);

588
	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
589 590 591 592 593 594
		return 0;

	return (dev->features & NETIF_F_IP_CSUM) != 0;
}

static uint32_t gfar_get_msglevel(struct net_device *dev)
595
{
596 597
	struct gfar_private *priv = netdev_priv(dev);
	return priv->msg_enable;
598 599
}

600
static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
601
{
602 603 604 605
	struct gfar_private *priv = netdev_priv(dev);
	priv->msg_enable = data;
}

606 607 608 609 610
#ifdef CONFIG_PM
static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
	struct gfar_private *priv = netdev_priv(dev);

611
	if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
612 613 614 615 616 617 618 619 620 621 622 623
		wol->supported = WAKE_MAGIC;
		wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
	} else {
		wol->supported = wol->wolopts = 0;
	}
}

static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
	struct gfar_private *priv = netdev_priv(dev);
	unsigned long flags;

624
	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
625 626 627 628 629 630 631 632
	    wol->wolopts != 0)
		return -EINVAL;

	if (wol->wolopts & ~WAKE_MAGIC)
		return -EINVAL;

	spin_lock_irqsave(&priv->bflock, flags);
	priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0;
633
	device_set_wakeup_enable(&dev->dev, priv->wol_en);
634 635 636 637 638
	spin_unlock_irqrestore(&priv->bflock, flags);

	return 0;
}
#endif
639

640
const struct ethtool_ops gfar_ethtool_ops = {
L
Linus Torvalds 已提交
641
	.get_settings = gfar_gsettings,
642
	.set_settings = gfar_ssettings,
L
Linus Torvalds 已提交
643 644 645 646 647 648 649 650 651
	.get_drvinfo = gfar_gdrvinfo,
	.get_regs_len = gfar_reglen,
	.get_regs = gfar_get_regs,
	.get_link = ethtool_op_get_link,
	.get_coalesce = gfar_gcoalesce,
	.set_coalesce = gfar_scoalesce,
	.get_ringparam = gfar_gringparam,
	.set_ringparam = gfar_sringparam,
	.get_strings = gfar_gstrings,
652
	.get_sset_count = gfar_sset_count,
L
Linus Torvalds 已提交
653
	.get_ethtool_stats = gfar_fill_stats,
654 655 656 657
	.get_rx_csum = gfar_get_rx_csum,
	.get_tx_csum = gfar_get_tx_csum,
	.set_rx_csum = gfar_set_rx_csum,
	.set_tx_csum = gfar_set_tx_csum,
D
Dai Haruki 已提交
658
	.set_sg = ethtool_op_set_sg,
659 660
	.get_msglevel = gfar_get_msglevel,
	.set_msglevel = gfar_set_msglevel,
661 662 663 664
#ifdef CONFIG_PM
	.get_wol = gfar_get_wol,
	.set_wol = gfar_set_wol,
#endif
L
Linus Torvalds 已提交
665
};