blob: c681b414767a6be2ec3f647f4bb79ae10e021494 [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
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000010 * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000012 * Copyright 2003-2006, 2008-2009 Freescale Semiconductor, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -040014 * This software may be used and distributed according to
15 * the terms of the GNU Public License, Version 2, incorporated herein
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * by reference.
17 */
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/string.h>
21#include <linux/errno.h>
22#include <linux/slab.h>
23#include <linux/interrupt.h>
24#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/netdevice.h>
27#include <linux/etherdevice.h>
28#include <linux/skbuff.h>
29#include <linux/spinlock.h>
30#include <linux/mm.h>
31
32#include <asm/io.h>
33#include <asm/irq.h>
34#include <asm/uaccess.h>
35#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/crc32.h>
37#include <asm/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/ethtool.h>
Andy Flemingbb40dcb2005-09-23 22:54:21 -040039#include <linux/mii.h>
40#include <linux/phy.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#include "gianfar.h"
43
Kumar Gala0bbaf062005-06-20 10:54:21 -050044extern void gfar_start(struct net_device *dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000045extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Andy Flemingbb40dcb2005-09-23 22:54:21 -040047#define GFAR_MAX_COAL_USECS 0xffff
48#define GFAR_MAX_COAL_FRAMES 0xff
Kumar Gala0bbaf062005-06-20 10:54:21 -050049static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 u64 * buf);
Kumar Gala0bbaf062005-06-20 10:54:21 -050051static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
52static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
53static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
54static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
55static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
56static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58static char stat_gstrings[][ETH_GSTRING_LEN] = {
59 "rx-dropped-by-kernel",
60 "rx-large-frame-errors",
61 "rx-short-frame-errors",
62 "rx-non-octet-errors",
63 "rx-crc-errors",
64 "rx-overrun-errors",
65 "rx-busy-errors",
66 "rx-babbling-errors",
67 "rx-truncated-frames",
68 "ethernet-bus-error",
69 "tx-babbling-errors",
70 "tx-underrun-errors",
71 "rx-skb-missing-errors",
72 "tx-timeout-errors",
73 "tx-rx-64-frames",
74 "tx-rx-65-127-frames",
75 "tx-rx-128-255-frames",
76 "tx-rx-256-511-frames",
77 "tx-rx-512-1023-frames",
78 "tx-rx-1024-1518-frames",
79 "tx-rx-1519-1522-good-vlan",
80 "rx-bytes",
81 "rx-packets",
82 "rx-fcs-errors",
83 "receive-multicast-packet",
84 "receive-broadcast-packet",
85 "rx-control-frame-packets",
86 "rx-pause-frame-packets",
87 "rx-unknown-op-code",
88 "rx-alignment-error",
89 "rx-frame-length-error",
90 "rx-code-error",
91 "rx-carrier-sense-error",
92 "rx-undersize-packets",
93 "rx-oversize-packets",
94 "rx-fragmented-frames",
95 "rx-jabber-frames",
96 "rx-dropped-frames",
97 "tx-byte-counter",
98 "tx-packets",
99 "tx-multicast-packets",
100 "tx-broadcast-packets",
101 "tx-pause-control-frames",
102 "tx-deferral-packets",
103 "tx-excessive-deferral-packets",
104 "tx-single-collision-packets",
105 "tx-multiple-collision-packets",
106 "tx-late-collision-packets",
107 "tx-excessive-collision-packets",
108 "tx-total-collision",
109 "reserved",
110 "tx-dropped-frames",
111 "tx-jabber-frames",
112 "tx-fcs-errors",
113 "tx-control-frames",
114 "tx-oversize-frames",
115 "tx-undersize-frames",
116 "tx-fragmented-frames",
117};
118
Kumar Gala0bbaf062005-06-20 10:54:21 -0500119/* Fill in a buffer with the strings which correspond to the
120 * stats */
121static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
122{
123 struct gfar_private *priv = netdev_priv(dev);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600124
Andy Flemingb31a1d82008-12-16 15:29:15 -0800125 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
Kumar Gala0bbaf062005-06-20 10:54:21 -0500126 memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
127 else
128 memcpy(buf, stat_gstrings,
129 GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* Fill in an array of 64-bit statistics from various sources.
133 * This array will be appended to the end of the ethtool_stats
134 * structure, and returned to user space
135 */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500136static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
138 int i;
139 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000140 struct gfar __iomem *regs = priv->gfargrp.regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 u64 *extra = (u64 *) & priv->extra_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Andy Flemingb31a1d82008-12-16 15:29:15 -0800143 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000144 u32 __iomem *rmon = (u32 __iomem *) &regs->rmon;
Kumar Gala0bbaf062005-06-20 10:54:21 -0500145 struct gfar_stats *stats = (struct gfar_stats *) buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Kumar Gala0bbaf062005-06-20 10:54:21 -0500147 for (i = 0; i < GFAR_RMON_LEN; i++)
Kumar Galacc8c6e32006-02-01 15:18:03 -0600148 stats->rmon[i] = (u64) gfar_read(&rmon[i]);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500149
150 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
151 stats->extra[i] = extra[i];
152 } else
153 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
154 buf[i] = extra[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700157static int gfar_sset_count(struct net_device *dev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 struct gfar_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700161 switch (sset) {
162 case ETH_SS_STATS:
Andy Flemingb31a1d82008-12-16 15:29:15 -0800163 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700164 return GFAR_STATS_LEN;
165 else
166 return GFAR_EXTRA_STATS_LEN;
167 default:
168 return -EOPNOTSUPP;
169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/* Fills in the drvinfo structure with some basic info */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500173static void gfar_gdrvinfo(struct net_device *dev, struct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 ethtool_drvinfo *drvinfo)
175{
176 strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN);
177 strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN);
178 strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN);
179 strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 drvinfo->regdump_len = 0;
181 drvinfo->eedump_len = 0;
182}
183
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400184
185static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
186{
187 struct gfar_private *priv = netdev_priv(dev);
188 struct phy_device *phydev = priv->phydev;
189
190 if (NULL == phydev)
191 return -ENODEV;
192
193 return phy_ethtool_sset(phydev, cmd);
194}
195
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/* Return the current settings in the ethtool_cmd structure */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500198static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
200 struct gfar_private *priv = netdev_priv(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400201 struct phy_device *phydev = priv->phydev;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000202 struct gfar_priv_rx_q *rx_queue = NULL;
203 struct gfar_priv_tx_q *tx_queue = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400205 if (NULL == phydev)
206 return -ENODEV;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000207 tx_queue = priv->tx_queue;
208 rx_queue = priv->rx_queue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400209
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000210 cmd->maxtxpkt = get_icft_value(tx_queue->txic);
211 cmd->maxrxpkt = get_icft_value(rx_queue->rxic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400213 return phy_ethtool_gset(phydev, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
216/* Return the length of the register structure */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500217static int gfar_reglen(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
219 return sizeof (struct gfar);
220}
221
222/* Return a dump of the GFAR register space */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500223static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
225 int i;
226 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000227 u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp.regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 u32 *buf = (u32 *) regbuf;
229
230 for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)
Kumar Galacc8c6e32006-02-01 15:18:03 -0600231 buf[i] = gfar_read(&theregs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234/* Convert microseconds to ethernet clock ticks, which changes
235 * depending on what speed the controller is running at */
236static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs)
237{
238 unsigned int count;
239
240 /* The timer is different, depending on the interface speed */
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400241 switch (priv->phydev->speed) {
242 case SPEED_1000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 count = GFAR_GBIT_TIME;
244 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400245 case SPEED_100:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 count = GFAR_100_TIME;
247 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400248 case SPEED_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 default:
250 count = GFAR_10_TIME;
251 break;
252 }
253
254 /* Make sure we return a number greater than 0
255 * if usecs > 0 */
256 return ((usecs * 1000 + count - 1) / count);
257}
258
259/* Convert ethernet clock ticks to microseconds */
260static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks)
261{
262 unsigned int count;
263
264 /* The timer is different, depending on the interface speed */
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400265 switch (priv->phydev->speed) {
266 case SPEED_1000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 count = GFAR_GBIT_TIME;
268 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400269 case SPEED_100:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 count = GFAR_100_TIME;
271 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400272 case SPEED_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 default:
274 count = GFAR_10_TIME;
275 break;
276 }
277
278 /* Make sure we return a number greater than 0 */
279 /* if ticks is > 0 */
280 return ((ticks * count) / 1000);
281}
282
283/* Get the coalescing parameters, and put them in the cvals
284 * structure. */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500285static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000288 struct gfar_priv_rx_q *rx_queue = NULL;
289 struct gfar_priv_tx_q *tx_queue = NULL;
Dai Harukib46a8452008-12-16 15:29:52 -0800290 unsigned long rxtime;
291 unsigned long rxcount;
292 unsigned long txtime;
293 unsigned long txcount;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400294
Andy Flemingb31a1d82008-12-16 15:29:15 -0800295 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
Kumar Gala0bbaf062005-06-20 10:54:21 -0500296 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400298 if (NULL == priv->phydev)
299 return -ENODEV;
300
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000301 rx_queue = priv->rx_queue;
302 tx_queue = priv->tx_queue;
303
304 rxtime = get_ictt_value(rx_queue->rxic);
305 rxcount = get_icft_value(rx_queue->rxic);
306 txtime = get_ictt_value(tx_queue->txic);
307 txcount = get_icft_value(tx_queue->txic);
Dai Harukib46a8452008-12-16 15:29:52 -0800308 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime);
309 cvals->rx_max_coalesced_frames = rxcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Dai Harukib46a8452008-12-16 15:29:52 -0800311 cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime);
312 cvals->tx_max_coalesced_frames = txcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 cvals->use_adaptive_rx_coalesce = 0;
315 cvals->use_adaptive_tx_coalesce = 0;
316
317 cvals->pkt_rate_low = 0;
318 cvals->rx_coalesce_usecs_low = 0;
319 cvals->rx_max_coalesced_frames_low = 0;
320 cvals->tx_coalesce_usecs_low = 0;
321 cvals->tx_max_coalesced_frames_low = 0;
322
323 /* When the packet rate is below pkt_rate_high but above
324 * pkt_rate_low (both measured in packets per second) the
325 * normal {rx,tx}_* coalescing parameters are used.
326 */
327
328 /* When the packet rate is (measured in packets per second)
329 * is above pkt_rate_high, the {rx,tx}_*_high parameters are
330 * used.
331 */
332 cvals->pkt_rate_high = 0;
333 cvals->rx_coalesce_usecs_high = 0;
334 cvals->rx_max_coalesced_frames_high = 0;
335 cvals->tx_coalesce_usecs_high = 0;
336 cvals->tx_max_coalesced_frames_high = 0;
337
338 /* How often to do adaptive coalescing packet rate sampling,
339 * measured in seconds. Must not be zero.
340 */
341 cvals->rate_sample_interval = 0;
342
343 return 0;
344}
345
346/* Change the coalescing values.
347 * Both cvals->*_usecs and cvals->*_frames have to be > 0
348 * in order for coalescing to be active
349 */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500350static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
352 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000353 struct gfar __iomem *regs = priv->gfargrp.regs;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000354 struct gfar_priv_tx_q *tx_queue = NULL;
355 struct gfar_priv_rx_q *rx_queue = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Andy Flemingb31a1d82008-12-16 15:29:15 -0800357 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
Kumar Gala0bbaf062005-06-20 10:54:21 -0500358 return -EOPNOTSUPP;
359
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000360 tx_queue = priv->tx_queue;
361 rx_queue = priv->rx_queue;
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* Set up rx coalescing */
364 if ((cvals->rx_coalesce_usecs == 0) ||
365 (cvals->rx_max_coalesced_frames == 0))
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000366 rx_queue->rxcoalescing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 else
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000368 rx_queue->rxcoalescing = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400370 if (NULL == priv->phydev)
371 return -ENODEV;
372
373 /* Check the bounds of the values */
374 if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
375 pr_info("Coalescing is limited to %d microseconds\n",
376 GFAR_MAX_COAL_USECS);
377 return -EINVAL;
378 }
379
380 if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
381 pr_info("Coalescing is limited to %d frames\n",
382 GFAR_MAX_COAL_FRAMES);
383 return -EINVAL;
384 }
385
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000386 rx_queue->rxic = mk_ic_value(cvals->rx_max_coalesced_frames,
Jiajun Wuaccff952009-07-30 14:20:42 -0700387 gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 /* Set up tx coalescing */
390 if ((cvals->tx_coalesce_usecs == 0) ||
391 (cvals->tx_max_coalesced_frames == 0))
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000392 tx_queue->txcoalescing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 else
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000394 tx_queue->txcoalescing = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400396 /* Check the bounds of the values */
397 if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
398 pr_info("Coalescing is limited to %d microseconds\n",
399 GFAR_MAX_COAL_USECS);
400 return -EINVAL;
401 }
402
403 if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
404 pr_info("Coalescing is limited to %d frames\n",
405 GFAR_MAX_COAL_FRAMES);
406 return -EINVAL;
407 }
408
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000409 tx_queue->txic = mk_ic_value(cvals->tx_max_coalesced_frames,
Jiajun Wuaccff952009-07-30 14:20:42 -0700410 gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000412 gfar_write(&regs->rxic, 0);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000413 if (rx_queue->rxcoalescing)
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000414 gfar_write(&regs->rxic, rx_queue->rxic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000416 gfar_write(&regs->txic, 0);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000417 if (tx_queue->txcoalescing)
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000418 gfar_write(&regs->txic, tx_queue->txic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 return 0;
421}
422
423/* Fills in rvals with the current ring parameters. Currently,
424 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
425 * jumbo are ignored by the driver */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500426static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
428 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000429 struct gfar_priv_tx_q *tx_queue = NULL;
430 struct gfar_priv_rx_q *rx_queue = NULL;
431
432 tx_queue = priv->tx_queue;
433 rx_queue = priv->rx_queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE;
436 rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE;
437 rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE;
438 rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE;
439
440 /* Values changeable by the user. The valid values are
441 * in the range 1 to the "*_max_pending" counterpart above.
442 */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000443 rvals->rx_pending = rx_queue->rx_ring_size;
444 rvals->rx_mini_pending = rx_queue->rx_ring_size;
445 rvals->rx_jumbo_pending = rx_queue->rx_ring_size;
446 rvals->tx_pending = tx_queue->tx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447}
448
449/* Change the current ring parameters, stopping the controller if
450 * necessary so that we don't mess things up while we're in
451 * motion. We wait for the ring to be clean before reallocating
452 * the rings. */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500453static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000456 struct gfar_priv_tx_q *tx_queue = NULL;
457 struct gfar_priv_rx_q *rx_queue = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 int err = 0;
459
460 if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE)
461 return -EINVAL;
462
463 if (!is_power_of_2(rvals->rx_pending)) {
464 printk("%s: Ring sizes must be a power of 2\n",
465 dev->name);
466 return -EINVAL;
467 }
468
469 if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE)
470 return -EINVAL;
471
472 if (!is_power_of_2(rvals->tx_pending)) {
473 printk("%s: Ring sizes must be a power of 2\n",
474 dev->name);
475 return -EINVAL;
476 }
477
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000478 tx_queue = priv->tx_queue;
479 rx_queue = priv->rx_queue;
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if (dev->flags & IFF_UP) {
Kumar Gala0bbaf062005-06-20 10:54:21 -0500482 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Kumar Gala0bbaf062005-06-20 10:54:21 -0500484 /* Halt TX and RX, and process the frames which
485 * have already been received */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000486 spin_lock_irqsave(&tx_queue->txlock, flags);
487 spin_lock(&rx_queue->rxlock);
Andy Flemingfef61082006-04-20 16:44:29 -0500488
Kumar Gala0bbaf062005-06-20 10:54:21 -0500489 gfar_halt(dev);
Andy Flemingfef61082006-04-20 16:44:29 -0500490
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000491 spin_unlock(&rx_queue->rxlock);
492 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000494 gfar_clean_rx_ring(rx_queue, rx_queue->rx_ring_size);
Dai Haruki12dea572008-12-16 15:30:20 -0800495
Kumar Gala0bbaf062005-06-20 10:54:21 -0500496 /* Now we take down the rings to rebuild them */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 stop_gfar(dev);
498 }
499
Kumar Gala0bbaf062005-06-20 10:54:21 -0500500 /* Change the size */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000501 rx_queue->rx_ring_size = rvals->rx_pending;
502 tx_queue->tx_ring_size = rvals->tx_pending;
503 tx_queue->num_txbdfree = tx_queue->tx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Kumar Gala0bbaf062005-06-20 10:54:21 -0500505 /* Rebuild the rings with the new size */
Dai Haruki12dea572008-12-16 15:30:20 -0800506 if (dev->flags & IFF_UP) {
Kumar Gala0bbaf062005-06-20 10:54:21 -0500507 err = startup_gfar(dev);
Dai Haruki12dea572008-12-16 15:30:20 -0800508 netif_wake_queue(dev);
509 }
Kumar Gala0bbaf062005-06-20 10:54:21 -0500510 return err;
511}
512
513static int gfar_set_rx_csum(struct net_device *dev, uint32_t data)
514{
515 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000516 struct gfar_priv_rx_q *rx_queue = NULL;
517 struct gfar_priv_tx_q *tx_queue = NULL;
Scott Woodd87eb122008-07-11 18:04:45 -0500518 unsigned long flags;
Kumar Gala0bbaf062005-06-20 10:54:21 -0500519 int err = 0;
520
Andy Flemingb31a1d82008-12-16 15:29:15 -0800521 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
Kumar Gala0bbaf062005-06-20 10:54:21 -0500522 return -EOPNOTSUPP;
523
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000524 tx_queue = priv->tx_queue;
525 rx_queue = priv->rx_queue;
526
Kumar Gala0bbaf062005-06-20 10:54:21 -0500527 if (dev->flags & IFF_UP) {
Kumar Gala0bbaf062005-06-20 10:54:21 -0500528 /* Halt TX and RX, and process the frames which
529 * have already been received */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000530 spin_lock_irqsave(&tx_queue->txlock, flags);
531 spin_lock(&rx_queue->rxlock);
Andy Flemingfef61082006-04-20 16:44:29 -0500532
Kumar Gala0bbaf062005-06-20 10:54:21 -0500533 gfar_halt(dev);
Andy Flemingfef61082006-04-20 16:44:29 -0500534
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000535 spin_unlock(&rx_queue->rxlock);
536 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500537
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000538 gfar_clean_rx_ring(rx_queue, rx_queue->rx_ring_size);
Dai Haruki12dea572008-12-16 15:30:20 -0800539
Kumar Gala0bbaf062005-06-20 10:54:21 -0500540 /* Now we take down the rings to rebuild them */
541 stop_gfar(dev);
542 }
543
Scott Woodd87eb122008-07-11 18:04:45 -0500544 spin_lock_irqsave(&priv->bflock, flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500545 priv->rx_csum_enable = data;
Scott Woodd87eb122008-07-11 18:04:45 -0500546 spin_unlock_irqrestore(&priv->bflock, flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500547
Dai Haruki12dea572008-12-16 15:30:20 -0800548 if (dev->flags & IFF_UP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 err = startup_gfar(dev);
Dai Haruki12dea572008-12-16 15:30:20 -0800550 netif_wake_queue(dev);
551 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 return err;
553}
554
Kumar Gala0bbaf062005-06-20 10:54:21 -0500555static uint32_t gfar_get_rx_csum(struct net_device *dev)
556{
557 struct gfar_private *priv = netdev_priv(dev);
558
Andy Flemingb31a1d82008-12-16 15:29:15 -0800559 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
Kumar Gala0bbaf062005-06-20 10:54:21 -0500560 return 0;
561
562 return priv->rx_csum_enable;
563}
564
565static int gfar_set_tx_csum(struct net_device *dev, uint32_t data)
566{
Kumar Gala0bbaf062005-06-20 10:54:21 -0500567 struct gfar_private *priv = netdev_priv(dev);
568
Andy Flemingb31a1d82008-12-16 15:29:15 -0800569 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
Kumar Gala0bbaf062005-06-20 10:54:21 -0500570 return -EOPNOTSUPP;
571
Dai Haruki12dea572008-12-16 15:30:20 -0800572 netif_tx_lock_bh(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500573
574 if (data)
575 dev->features |= NETIF_F_IP_CSUM;
576 else
577 dev->features &= ~NETIF_F_IP_CSUM;
578
Dai Haruki12dea572008-12-16 15:30:20 -0800579 netif_tx_unlock_bh(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500580
581 return 0;
582}
583
584static uint32_t gfar_get_tx_csum(struct net_device *dev)
585{
586 struct gfar_private *priv = netdev_priv(dev);
587
Andy Flemingb31a1d82008-12-16 15:29:15 -0800588 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
Kumar Gala0bbaf062005-06-20 10:54:21 -0500589 return 0;
590
591 return (dev->features & NETIF_F_IP_CSUM) != 0;
592}
593
594static uint32_t gfar_get_msglevel(struct net_device *dev)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400595{
Kumar Gala0bbaf062005-06-20 10:54:21 -0500596 struct gfar_private *priv = netdev_priv(dev);
597 return priv->msg_enable;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400598}
599
Kumar Gala0bbaf062005-06-20 10:54:21 -0500600static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400601{
Kumar Gala0bbaf062005-06-20 10:54:21 -0500602 struct gfar_private *priv = netdev_priv(dev);
603 priv->msg_enable = data;
604}
605
Scott Woodd87eb122008-07-11 18:04:45 -0500606#ifdef CONFIG_PM
607static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
608{
609 struct gfar_private *priv = netdev_priv(dev);
610
Andy Flemingb31a1d82008-12-16 15:29:15 -0800611 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
Scott Woodd87eb122008-07-11 18:04:45 -0500612 wol->supported = WAKE_MAGIC;
613 wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
614 } else {
615 wol->supported = wol->wolopts = 0;
616 }
617}
618
619static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
620{
621 struct gfar_private *priv = netdev_priv(dev);
622 unsigned long flags;
623
Andy Flemingb31a1d82008-12-16 15:29:15 -0800624 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
Scott Woodd87eb122008-07-11 18:04:45 -0500625 wol->wolopts != 0)
626 return -EINVAL;
627
628 if (wol->wolopts & ~WAKE_MAGIC)
629 return -EINVAL;
630
631 spin_lock_irqsave(&priv->bflock, flags);
632 priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0;
Anton Vorontsov2884e5c2009-02-01 00:52:34 -0800633 device_set_wakeup_enable(&dev->dev, priv->wol_en);
Scott Woodd87eb122008-07-11 18:04:45 -0500634 spin_unlock_irqrestore(&priv->bflock, flags);
635
636 return 0;
637}
638#endif
Kumar Gala0bbaf062005-06-20 10:54:21 -0500639
Jeff Garzik7282d492006-09-13 14:30:00 -0400640const struct ethtool_ops gfar_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .get_settings = gfar_gsettings,
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400642 .set_settings = gfar_ssettings,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 .get_drvinfo = gfar_gdrvinfo,
644 .get_regs_len = gfar_reglen,
645 .get_regs = gfar_get_regs,
646 .get_link = ethtool_op_get_link,
647 .get_coalesce = gfar_gcoalesce,
648 .set_coalesce = gfar_scoalesce,
649 .get_ringparam = gfar_gringparam,
650 .set_ringparam = gfar_sringparam,
651 .get_strings = gfar_gstrings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700652 .get_sset_count = gfar_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 .get_ethtool_stats = gfar_fill_stats,
Kumar Gala0bbaf062005-06-20 10:54:21 -0500654 .get_rx_csum = gfar_get_rx_csum,
655 .get_tx_csum = gfar_get_tx_csum,
656 .set_rx_csum = gfar_set_rx_csum,
657 .set_tx_csum = gfar_set_tx_csum,
Dai Haruki4669bc92008-12-17 16:51:04 -0800658 .set_sg = ethtool_op_set_sg,
Kumar Gala0bbaf062005-06-20 10:54:21 -0500659 .get_msglevel = gfar_get_msglevel,
660 .set_msglevel = gfar_set_msglevel,
Scott Woodd87eb122008-07-11 18:04:45 -0500661#ifdef CONFIG_PM
662 .get_wol = gfar_get_wol,
663 .set_wol = gfar_set_wol,
664#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665};