blob: fb7d3ccc0fdce8eec47cef3218e39c67746d662f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/net/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
Kumar Gala4c8d3d92005-11-13 16:06:30 -08009 * Maintainer: Kumar Gala
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * Copyright (c) 2003,2004 Freescale Semiconductor, Inc.
12 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -040013 * This software may be used and distributed according to
14 * the terms of the GNU Public License, Version 2, incorporated herein
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * by reference.
16 */
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/string.h>
20#include <linux/errno.h>
21#include <linux/slab.h>
22#include <linux/interrupt.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/netdevice.h>
26#include <linux/etherdevice.h>
27#include <linux/skbuff.h>
28#include <linux/spinlock.h>
29#include <linux/mm.h>
30
31#include <asm/io.h>
32#include <asm/irq.h>
33#include <asm/uaccess.h>
34#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/crc32.h>
36#include <asm/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/ethtool.h>
Andy Flemingbb40dcb2005-09-23 22:54:21 -040038#include <linux/mii.h>
39#include <linux/phy.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#include "gianfar.h"
42
Kumar Gala0bbaf062005-06-20 10:54:21 -050043extern void gfar_start(struct net_device *dev);
44extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Andy Flemingbb40dcb2005-09-23 22:54:21 -040046#define GFAR_MAX_COAL_USECS 0xffff
47#define GFAR_MAX_COAL_FRAMES 0xff
Kumar Gala0bbaf062005-06-20 10:54:21 -050048static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 u64 * buf);
Kumar Gala0bbaf062005-06-20 10:54:21 -050050static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
51static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
52static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
53static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
54static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
55static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57static char stat_gstrings[][ETH_GSTRING_LEN] = {
58 "rx-dropped-by-kernel",
59 "rx-large-frame-errors",
60 "rx-short-frame-errors",
61 "rx-non-octet-errors",
62 "rx-crc-errors",
63 "rx-overrun-errors",
64 "rx-busy-errors",
65 "rx-babbling-errors",
66 "rx-truncated-frames",
67 "ethernet-bus-error",
68 "tx-babbling-errors",
69 "tx-underrun-errors",
70 "rx-skb-missing-errors",
71 "tx-timeout-errors",
72 "tx-rx-64-frames",
73 "tx-rx-65-127-frames",
74 "tx-rx-128-255-frames",
75 "tx-rx-256-511-frames",
76 "tx-rx-512-1023-frames",
77 "tx-rx-1024-1518-frames",
78 "tx-rx-1519-1522-good-vlan",
79 "rx-bytes",
80 "rx-packets",
81 "rx-fcs-errors",
82 "receive-multicast-packet",
83 "receive-broadcast-packet",
84 "rx-control-frame-packets",
85 "rx-pause-frame-packets",
86 "rx-unknown-op-code",
87 "rx-alignment-error",
88 "rx-frame-length-error",
89 "rx-code-error",
90 "rx-carrier-sense-error",
91 "rx-undersize-packets",
92 "rx-oversize-packets",
93 "rx-fragmented-frames",
94 "rx-jabber-frames",
95 "rx-dropped-frames",
96 "tx-byte-counter",
97 "tx-packets",
98 "tx-multicast-packets",
99 "tx-broadcast-packets",
100 "tx-pause-control-frames",
101 "tx-deferral-packets",
102 "tx-excessive-deferral-packets",
103 "tx-single-collision-packets",
104 "tx-multiple-collision-packets",
105 "tx-late-collision-packets",
106 "tx-excessive-collision-packets",
107 "tx-total-collision",
108 "reserved",
109 "tx-dropped-frames",
110 "tx-jabber-frames",
111 "tx-fcs-errors",
112 "tx-control-frames",
113 "tx-oversize-frames",
114 "tx-undersize-frames",
115 "tx-fragmented-frames",
116};
117
Kumar Gala0bbaf062005-06-20 10:54:21 -0500118/* Fill in a buffer with the strings which correspond to the
119 * stats */
120static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
121{
122 struct gfar_private *priv = netdev_priv(dev);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600123
Kumar Gala0bbaf062005-06-20 10:54:21 -0500124 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
125 memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
126 else
127 memcpy(buf, stat_gstrings,
128 GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/* Fill in an array of 64-bit statistics from various sources.
132 * This array will be appended to the end of the ethtool_stats
133 * structure, and returned to user space
134 */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500135static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
137 int i;
138 struct gfar_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 u64 *extra = (u64 *) & priv->extra_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Kumar Gala0bbaf062005-06-20 10:54:21 -0500141 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
Kumar Galacc8c6e32006-02-01 15:18:03 -0600142 u32 __iomem *rmon = (u32 __iomem *) & priv->regs->rmon;
Kumar Gala0bbaf062005-06-20 10:54:21 -0500143 struct gfar_stats *stats = (struct gfar_stats *) buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Kumar Gala0bbaf062005-06-20 10:54:21 -0500145 for (i = 0; i < GFAR_RMON_LEN; i++)
Kumar Galacc8c6e32006-02-01 15:18:03 -0600146 stats->rmon[i] = (u64) gfar_read(&rmon[i]);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500147
148 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
149 stats->extra[i] = extra[i];
150 } else
151 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
152 buf[i] = extra[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700155static int gfar_sset_count(struct net_device *dev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 struct gfar_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700159 switch (sset) {
160 case ETH_SS_STATS:
161 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
162 return GFAR_STATS_LEN;
163 else
164 return GFAR_EXTRA_STATS_LEN;
165 default:
166 return -EOPNOTSUPP;
167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/* Fills in the drvinfo structure with some basic info */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500171static void gfar_gdrvinfo(struct net_device *dev, struct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 ethtool_drvinfo *drvinfo)
173{
174 strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN);
175 strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN);
176 strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN);
177 strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 drvinfo->regdump_len = 0;
179 drvinfo->eedump_len = 0;
180}
181
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400182
183static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
184{
185 struct gfar_private *priv = netdev_priv(dev);
186 struct phy_device *phydev = priv->phydev;
187
188 if (NULL == phydev)
189 return -ENODEV;
190
191 return phy_ethtool_sset(phydev, cmd);
192}
193
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195/* Return the current settings in the ethtool_cmd structure */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500196static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198 struct gfar_private *priv = netdev_priv(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400199 struct phy_device *phydev = priv->phydev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400201 if (NULL == phydev)
202 return -ENODEV;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 cmd->maxtxpkt = priv->txcount;
205 cmd->maxrxpkt = priv->rxcount;
206
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400207 return phy_ethtool_gset(phydev, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
209
210/* Return the length of the register structure */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500211static int gfar_reglen(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
213 return sizeof (struct gfar);
214}
215
216/* Return a dump of the GFAR register space */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500217static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 int i;
220 struct gfar_private *priv = netdev_priv(dev);
Kumar Galacc8c6e32006-02-01 15:18:03 -0600221 u32 __iomem *theregs = (u32 __iomem *) priv->regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 u32 *buf = (u32 *) regbuf;
223
224 for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)
Kumar Galacc8c6e32006-02-01 15:18:03 -0600225 buf[i] = gfar_read(&theregs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228/* Convert microseconds to ethernet clock ticks, which changes
229 * depending on what speed the controller is running at */
230static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs)
231{
232 unsigned int count;
233
234 /* The timer is different, depending on the interface speed */
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400235 switch (priv->phydev->speed) {
236 case SPEED_1000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 count = GFAR_GBIT_TIME;
238 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400239 case SPEED_100:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 count = GFAR_100_TIME;
241 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400242 case SPEED_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 default:
244 count = GFAR_10_TIME;
245 break;
246 }
247
248 /* Make sure we return a number greater than 0
249 * if usecs > 0 */
250 return ((usecs * 1000 + count - 1) / count);
251}
252
253/* Convert ethernet clock ticks to microseconds */
254static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks)
255{
256 unsigned int count;
257
258 /* The timer is different, depending on the interface speed */
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400259 switch (priv->phydev->speed) {
260 case SPEED_1000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 count = GFAR_GBIT_TIME;
262 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400263 case SPEED_100:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 count = GFAR_100_TIME;
265 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400266 case SPEED_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 default:
268 count = GFAR_10_TIME;
269 break;
270 }
271
272 /* Make sure we return a number greater than 0 */
273 /* if ticks is > 0 */
274 return ((ticks * count) / 1000);
275}
276
277/* Get the coalescing parameters, and put them in the cvals
278 * structure. */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500279static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
281 struct gfar_private *priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400282
Kumar Gala0bbaf062005-06-20 10:54:21 -0500283 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
284 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400286 if (NULL == priv->phydev)
287 return -ENODEV;
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime);
290 cvals->rx_max_coalesced_frames = priv->rxcount;
291
292 cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, priv->txtime);
293 cvals->tx_max_coalesced_frames = priv->txcount;
294
295 cvals->use_adaptive_rx_coalesce = 0;
296 cvals->use_adaptive_tx_coalesce = 0;
297
298 cvals->pkt_rate_low = 0;
299 cvals->rx_coalesce_usecs_low = 0;
300 cvals->rx_max_coalesced_frames_low = 0;
301 cvals->tx_coalesce_usecs_low = 0;
302 cvals->tx_max_coalesced_frames_low = 0;
303
304 /* When the packet rate is below pkt_rate_high but above
305 * pkt_rate_low (both measured in packets per second) the
306 * normal {rx,tx}_* coalescing parameters are used.
307 */
308
309 /* When the packet rate is (measured in packets per second)
310 * is above pkt_rate_high, the {rx,tx}_*_high parameters are
311 * used.
312 */
313 cvals->pkt_rate_high = 0;
314 cvals->rx_coalesce_usecs_high = 0;
315 cvals->rx_max_coalesced_frames_high = 0;
316 cvals->tx_coalesce_usecs_high = 0;
317 cvals->tx_max_coalesced_frames_high = 0;
318
319 /* How often to do adaptive coalescing packet rate sampling,
320 * measured in seconds. Must not be zero.
321 */
322 cvals->rate_sample_interval = 0;
323
324 return 0;
325}
326
327/* Change the coalescing values.
328 * Both cvals->*_usecs and cvals->*_frames have to be > 0
329 * in order for coalescing to be active
330 */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500331static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 struct gfar_private *priv = netdev_priv(dev);
334
Kumar Gala0bbaf062005-06-20 10:54:21 -0500335 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
336 return -EOPNOTSUPP;
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 /* Set up rx coalescing */
339 if ((cvals->rx_coalesce_usecs == 0) ||
340 (cvals->rx_max_coalesced_frames == 0))
341 priv->rxcoalescing = 0;
342 else
343 priv->rxcoalescing = 1;
344
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400345 if (NULL == priv->phydev)
346 return -ENODEV;
347
348 /* Check the bounds of the values */
349 if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
350 pr_info("Coalescing is limited to %d microseconds\n",
351 GFAR_MAX_COAL_USECS);
352 return -EINVAL;
353 }
354
355 if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
356 pr_info("Coalescing is limited to %d frames\n",
357 GFAR_MAX_COAL_FRAMES);
358 return -EINVAL;
359 }
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 priv->rxtime = gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs);
362 priv->rxcount = cvals->rx_max_coalesced_frames;
363
364 /* Set up tx coalescing */
365 if ((cvals->tx_coalesce_usecs == 0) ||
366 (cvals->tx_max_coalesced_frames == 0))
367 priv->txcoalescing = 0;
368 else
369 priv->txcoalescing = 1;
370
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400371 /* Check the bounds of the values */
372 if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
373 pr_info("Coalescing is limited to %d microseconds\n",
374 GFAR_MAX_COAL_USECS);
375 return -EINVAL;
376 }
377
378 if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
379 pr_info("Coalescing is limited to %d frames\n",
380 GFAR_MAX_COAL_FRAMES);
381 return -EINVAL;
382 }
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 priv->txtime = gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs);
385 priv->txcount = cvals->tx_max_coalesced_frames;
386
387 if (priv->rxcoalescing)
388 gfar_write(&priv->regs->rxic,
389 mk_ic_value(priv->rxcount, priv->rxtime));
390 else
391 gfar_write(&priv->regs->rxic, 0);
392
393 if (priv->txcoalescing)
394 gfar_write(&priv->regs->txic,
395 mk_ic_value(priv->txcount, priv->txtime));
396 else
397 gfar_write(&priv->regs->txic, 0);
398
399 return 0;
400}
401
402/* Fills in rvals with the current ring parameters. Currently,
403 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
404 * jumbo are ignored by the driver */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500405static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
407 struct gfar_private *priv = netdev_priv(dev);
408
409 rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE;
410 rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE;
411 rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE;
412 rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE;
413
414 /* Values changeable by the user. The valid values are
415 * in the range 1 to the "*_max_pending" counterpart above.
416 */
417 rvals->rx_pending = priv->rx_ring_size;
418 rvals->rx_mini_pending = priv->rx_ring_size;
419 rvals->rx_jumbo_pending = priv->rx_ring_size;
420 rvals->tx_pending = priv->tx_ring_size;
421}
422
423/* Change the current ring parameters, stopping the controller if
424 * necessary so that we don't mess things up while we're in
425 * motion. We wait for the ring to be clean before reallocating
426 * the rings. */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500427static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 struct gfar_private *priv = netdev_priv(dev);
430 int err = 0;
431
432 if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE)
433 return -EINVAL;
434
435 if (!is_power_of_2(rvals->rx_pending)) {
436 printk("%s: Ring sizes must be a power of 2\n",
437 dev->name);
438 return -EINVAL;
439 }
440
441 if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE)
442 return -EINVAL;
443
444 if (!is_power_of_2(rvals->tx_pending)) {
445 printk("%s: Ring sizes must be a power of 2\n",
446 dev->name);
447 return -EINVAL;
448 }
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (dev->flags & IFF_UP) {
Kumar Gala0bbaf062005-06-20 10:54:21 -0500451 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Kumar Gala0bbaf062005-06-20 10:54:21 -0500453 /* Halt TX and RX, and process the frames which
454 * have already been received */
Andy Flemingfef61082006-04-20 16:44:29 -0500455 spin_lock_irqsave(&priv->txlock, flags);
456 spin_lock(&priv->rxlock);
457
Kumar Gala0bbaf062005-06-20 10:54:21 -0500458 gfar_halt(dev);
459 gfar_clean_rx_ring(dev, priv->rx_ring_size);
Andy Flemingfef61082006-04-20 16:44:29 -0500460
461 spin_unlock(&priv->rxlock);
462 spin_unlock_irqrestore(&priv->txlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Kumar Gala0bbaf062005-06-20 10:54:21 -0500464 /* Now we take down the rings to rebuild them */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 stop_gfar(dev);
466 }
467
Kumar Gala0bbaf062005-06-20 10:54:21 -0500468 /* Change the size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 priv->rx_ring_size = rvals->rx_pending;
470 priv->tx_ring_size = rvals->tx_pending;
471
Kumar Gala0bbaf062005-06-20 10:54:21 -0500472 /* Rebuild the rings with the new size */
473 if (dev->flags & IFF_UP)
474 err = startup_gfar(dev);
475
476 return err;
477}
478
479static int gfar_set_rx_csum(struct net_device *dev, uint32_t data)
480{
481 struct gfar_private *priv = netdev_priv(dev);
Scott Woodd87eb122008-07-11 18:04:45 -0500482 unsigned long flags;
Kumar Gala0bbaf062005-06-20 10:54:21 -0500483 int err = 0;
484
485 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
486 return -EOPNOTSUPP;
487
488 if (dev->flags & IFF_UP) {
Kumar Gala0bbaf062005-06-20 10:54:21 -0500489 /* Halt TX and RX, and process the frames which
490 * have already been received */
Andy Flemingfef61082006-04-20 16:44:29 -0500491 spin_lock_irqsave(&priv->txlock, flags);
492 spin_lock(&priv->rxlock);
493
Kumar Gala0bbaf062005-06-20 10:54:21 -0500494 gfar_halt(dev);
495 gfar_clean_rx_ring(dev, priv->rx_ring_size);
Andy Flemingfef61082006-04-20 16:44:29 -0500496
497 spin_unlock(&priv->rxlock);
498 spin_unlock_irqrestore(&priv->txlock, flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500499
500 /* Now we take down the rings to rebuild them */
501 stop_gfar(dev);
502 }
503
Scott Woodd87eb122008-07-11 18:04:45 -0500504 spin_lock_irqsave(&priv->bflock, flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500505 priv->rx_csum_enable = data;
Scott Woodd87eb122008-07-11 18:04:45 -0500506 spin_unlock_irqrestore(&priv->bflock, flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (dev->flags & IFF_UP)
509 err = startup_gfar(dev);
510
511 return err;
512}
513
Kumar Gala0bbaf062005-06-20 10:54:21 -0500514static uint32_t gfar_get_rx_csum(struct net_device *dev)
515{
516 struct gfar_private *priv = netdev_priv(dev);
517
518 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
519 return 0;
520
521 return priv->rx_csum_enable;
522}
523
524static int gfar_set_tx_csum(struct net_device *dev, uint32_t data)
525{
526 unsigned long flags;
527 struct gfar_private *priv = netdev_priv(dev);
528
529 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
530 return -EOPNOTSUPP;
531
Andy Flemingfef61082006-04-20 16:44:29 -0500532 spin_lock_irqsave(&priv->txlock, flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500533 gfar_halt(dev);
534
535 if (data)
536 dev->features |= NETIF_F_IP_CSUM;
537 else
538 dev->features &= ~NETIF_F_IP_CSUM;
539
540 gfar_start(dev);
Andy Flemingfef61082006-04-20 16:44:29 -0500541 spin_unlock_irqrestore(&priv->txlock, flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500542
543 return 0;
544}
545
546static uint32_t gfar_get_tx_csum(struct net_device *dev)
547{
548 struct gfar_private *priv = netdev_priv(dev);
549
550 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
551 return 0;
552
553 return (dev->features & NETIF_F_IP_CSUM) != 0;
554}
555
556static uint32_t gfar_get_msglevel(struct net_device *dev)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400557{
Kumar Gala0bbaf062005-06-20 10:54:21 -0500558 struct gfar_private *priv = netdev_priv(dev);
559 return priv->msg_enable;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400560}
561
Kumar Gala0bbaf062005-06-20 10:54:21 -0500562static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400563{
Kumar Gala0bbaf062005-06-20 10:54:21 -0500564 struct gfar_private *priv = netdev_priv(dev);
565 priv->msg_enable = data;
566}
567
Scott Woodd87eb122008-07-11 18:04:45 -0500568#ifdef CONFIG_PM
569static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
570{
571 struct gfar_private *priv = netdev_priv(dev);
572
573 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
574 wol->supported = WAKE_MAGIC;
575 wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
576 } else {
577 wol->supported = wol->wolopts = 0;
578 }
579}
580
581static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
582{
583 struct gfar_private *priv = netdev_priv(dev);
584 unsigned long flags;
585
586 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
587 wol->wolopts != 0)
588 return -EINVAL;
589
590 if (wol->wolopts & ~WAKE_MAGIC)
591 return -EINVAL;
592
593 spin_lock_irqsave(&priv->bflock, flags);
594 priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0;
595 spin_unlock_irqrestore(&priv->bflock, flags);
596
597 return 0;
598}
599#endif
Kumar Gala0bbaf062005-06-20 10:54:21 -0500600
Jeff Garzik7282d492006-09-13 14:30:00 -0400601const struct ethtool_ops gfar_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .get_settings = gfar_gsettings,
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400603 .set_settings = gfar_ssettings,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .get_drvinfo = gfar_gdrvinfo,
605 .get_regs_len = gfar_reglen,
606 .get_regs = gfar_get_regs,
607 .get_link = ethtool_op_get_link,
608 .get_coalesce = gfar_gcoalesce,
609 .set_coalesce = gfar_scoalesce,
610 .get_ringparam = gfar_gringparam,
611 .set_ringparam = gfar_sringparam,
612 .get_strings = gfar_gstrings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700613 .get_sset_count = gfar_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 .get_ethtool_stats = gfar_fill_stats,
Kumar Gala0bbaf062005-06-20 10:54:21 -0500615 .get_rx_csum = gfar_get_rx_csum,
616 .get_tx_csum = gfar_get_tx_csum,
617 .set_rx_csum = gfar_set_rx_csum,
618 .set_tx_csum = gfar_set_tx_csum,
619 .get_msglevel = gfar_get_msglevel,
620 .set_msglevel = gfar_set_msglevel,
Scott Woodd87eb122008-07-11 18:04:45 -0500621#ifdef CONFIG_PM
622 .get_wol = gfar_get_wol,
623 .set_wol = gfar_set_wol,
624#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625};