blob: 92d7ac09c87ac6e27bcd89a1cb174e7d6562a69b [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
Joe Perches59deab22011-06-14 08:57:47 +000019#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/string.h>
23#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#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/skbuff.h>
30#include <linux/spinlock.h>
31#include <linux/mm.h>
32
33#include <asm/io.h>
34#include <asm/irq.h>
35#include <asm/uaccess.h>
36#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/crc32.h>
38#include <asm/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/ethtool.h>
Andy Flemingbb40dcb2005-09-23 22:54:21 -040040#include <linux/mii.h>
41#include <linux/phy.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include "gianfar.h"
44
Kumar Gala0bbaf062005-06-20 10:54:21 -050045extern void gfar_start(struct net_device *dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000046extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Andy Flemingbb40dcb2005-09-23 22:54:21 -040048#define GFAR_MAX_COAL_USECS 0xffff
49#define GFAR_MAX_COAL_FRAMES 0xff
Kumar Gala0bbaf062005-06-20 10:54:21 -050050static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 u64 * buf);
Kumar Gala0bbaf062005-06-20 10:54:21 -050052static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
53static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
54static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
55static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
56static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
57static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59static char stat_gstrings[][ETH_GSTRING_LEN] = {
60 "rx-dropped-by-kernel",
61 "rx-large-frame-errors",
62 "rx-short-frame-errors",
63 "rx-non-octet-errors",
64 "rx-crc-errors",
65 "rx-overrun-errors",
66 "rx-busy-errors",
67 "rx-babbling-errors",
68 "rx-truncated-frames",
69 "ethernet-bus-error",
70 "tx-babbling-errors",
71 "tx-underrun-errors",
72 "rx-skb-missing-errors",
73 "tx-timeout-errors",
74 "tx-rx-64-frames",
75 "tx-rx-65-127-frames",
76 "tx-rx-128-255-frames",
77 "tx-rx-256-511-frames",
78 "tx-rx-512-1023-frames",
79 "tx-rx-1024-1518-frames",
80 "tx-rx-1519-1522-good-vlan",
81 "rx-bytes",
82 "rx-packets",
83 "rx-fcs-errors",
84 "receive-multicast-packet",
85 "receive-broadcast-packet",
86 "rx-control-frame-packets",
87 "rx-pause-frame-packets",
88 "rx-unknown-op-code",
89 "rx-alignment-error",
90 "rx-frame-length-error",
91 "rx-code-error",
92 "rx-carrier-sense-error",
93 "rx-undersize-packets",
94 "rx-oversize-packets",
95 "rx-fragmented-frames",
96 "rx-jabber-frames",
97 "rx-dropped-frames",
98 "tx-byte-counter",
99 "tx-packets",
100 "tx-multicast-packets",
101 "tx-broadcast-packets",
102 "tx-pause-control-frames",
103 "tx-deferral-packets",
104 "tx-excessive-deferral-packets",
105 "tx-single-collision-packets",
106 "tx-multiple-collision-packets",
107 "tx-late-collision-packets",
108 "tx-excessive-collision-packets",
109 "tx-total-collision",
110 "reserved",
111 "tx-dropped-frames",
112 "tx-jabber-frames",
113 "tx-fcs-errors",
114 "tx-control-frames",
115 "tx-oversize-frames",
116 "tx-undersize-frames",
117 "tx-fragmented-frames",
118};
119
Kumar Gala0bbaf062005-06-20 10:54:21 -0500120/* Fill in a buffer with the strings which correspond to the
121 * stats */
122static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
123{
124 struct gfar_private *priv = netdev_priv(dev);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600125
Andy Flemingb31a1d82008-12-16 15:29:15 -0800126 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
Kumar Gala0bbaf062005-06-20 10:54:21 -0500127 memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
128 else
129 memcpy(buf, stat_gstrings,
130 GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
131}
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/* Fill in an array of 64-bit statistics from various sources.
134 * This array will be appended to the end of the ethtool_stats
135 * structure, and returned to user space
136 */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500137static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 int i;
140 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000141 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 u64 *extra = (u64 *) & priv->extra_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Andy Flemingb31a1d82008-12-16 15:29:15 -0800144 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000145 u32 __iomem *rmon = (u32 __iomem *) &regs->rmon;
Kumar Gala0bbaf062005-06-20 10:54:21 -0500146 struct gfar_stats *stats = (struct gfar_stats *) buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Kumar Gala0bbaf062005-06-20 10:54:21 -0500148 for (i = 0; i < GFAR_RMON_LEN; i++)
Kumar Galacc8c6e32006-02-01 15:18:03 -0600149 stats->rmon[i] = (u64) gfar_read(&rmon[i]);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500150
151 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
152 stats->extra[i] = extra[i];
153 } else
154 for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
155 buf[i] = extra[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700158static int gfar_sset_count(struct net_device *dev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 struct gfar_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700162 switch (sset) {
163 case ETH_SS_STATS:
Andy Flemingb31a1d82008-12-16 15:29:15 -0800164 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700165 return GFAR_STATS_LEN;
166 else
167 return GFAR_EXTRA_STATS_LEN;
168 default:
169 return -EOPNOTSUPP;
170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/* Fills in the drvinfo structure with some basic info */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500174static void gfar_gdrvinfo(struct net_device *dev, struct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 ethtool_drvinfo *drvinfo)
176{
177 strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN);
178 strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN);
179 strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN);
180 strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 drvinfo->regdump_len = 0;
182 drvinfo->eedump_len = 0;
183}
184
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400185
186static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
187{
188 struct gfar_private *priv = netdev_priv(dev);
189 struct phy_device *phydev = priv->phydev;
190
191 if (NULL == phydev)
192 return -ENODEV;
193
194 return phy_ethtool_sset(phydev, cmd);
195}
196
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/* Return the current settings in the ethtool_cmd structure */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500199static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 struct gfar_private *priv = netdev_priv(dev);
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400202 struct phy_device *phydev = priv->phydev;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000203 struct gfar_priv_rx_q *rx_queue = NULL;
204 struct gfar_priv_tx_q *tx_queue = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400206 if (NULL == phydev)
207 return -ENODEV;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000208 tx_queue = priv->tx_queue[0];
209 rx_queue = priv->rx_queue[0];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400210
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000211 /* etsec-1.7 and older versions have only one txic
212 * and rxic regs although they support multiple queues */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000213 cmd->maxtxpkt = get_icft_value(tx_queue->txic);
214 cmd->maxrxpkt = get_icft_value(rx_queue->rxic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400216 return phy_ethtool_gset(phydev, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
219/* Return the length of the register structure */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500220static int gfar_reglen(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
222 return sizeof (struct gfar);
223}
224
225/* Return a dump of the GFAR register space */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500226static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
228 int i;
229 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000230 u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp[0].regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 u32 *buf = (u32 *) regbuf;
232
233 for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)
Kumar Galacc8c6e32006-02-01 15:18:03 -0600234 buf[i] = gfar_read(&theregs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237/* Convert microseconds to ethernet clock ticks, which changes
238 * depending on what speed the controller is running at */
239static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs)
240{
241 unsigned int count;
242
243 /* The timer is different, depending on the interface speed */
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400244 switch (priv->phydev->speed) {
245 case SPEED_1000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 count = GFAR_GBIT_TIME;
247 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400248 case SPEED_100:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 count = GFAR_100_TIME;
250 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400251 case SPEED_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 default:
253 count = GFAR_10_TIME;
254 break;
255 }
256
257 /* Make sure we return a number greater than 0
258 * if usecs > 0 */
Eric Dumazet807540b2010-09-23 05:40:09 +0000259 return (usecs * 1000 + count - 1) / count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
261
262/* Convert ethernet clock ticks to microseconds */
263static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks)
264{
265 unsigned int count;
266
267 /* The timer is different, depending on the interface speed */
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400268 switch (priv->phydev->speed) {
269 case SPEED_1000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 count = GFAR_GBIT_TIME;
271 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400272 case SPEED_100:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 count = GFAR_100_TIME;
274 break;
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400275 case SPEED_10:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 default:
277 count = GFAR_10_TIME;
278 break;
279 }
280
281 /* Make sure we return a number greater than 0 */
282 /* if ticks is > 0 */
Eric Dumazet807540b2010-09-23 05:40:09 +0000283 return (ticks * count) / 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
285
286/* Get the coalescing parameters, and put them in the cvals
287 * structure. */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500288static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000291 struct gfar_priv_rx_q *rx_queue = NULL;
292 struct gfar_priv_tx_q *tx_queue = NULL;
Dai Harukib46a8452008-12-16 15:29:52 -0800293 unsigned long rxtime;
294 unsigned long rxcount;
295 unsigned long txtime;
296 unsigned long txcount;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400297
Andy Flemingb31a1d82008-12-16 15:29:15 -0800298 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
Kumar Gala0bbaf062005-06-20 10:54:21 -0500299 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400301 if (NULL == priv->phydev)
302 return -ENODEV;
303
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000304 rx_queue = priv->rx_queue[0];
305 tx_queue = priv->tx_queue[0];
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000306
307 rxtime = get_ictt_value(rx_queue->rxic);
308 rxcount = get_icft_value(rx_queue->rxic);
309 txtime = get_ictt_value(tx_queue->txic);
310 txcount = get_icft_value(tx_queue->txic);
Dai Harukib46a8452008-12-16 15:29:52 -0800311 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime);
312 cvals->rx_max_coalesced_frames = rxcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Dai Harukib46a8452008-12-16 15:29:52 -0800314 cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime);
315 cvals->tx_max_coalesced_frames = txcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 cvals->use_adaptive_rx_coalesce = 0;
318 cvals->use_adaptive_tx_coalesce = 0;
319
320 cvals->pkt_rate_low = 0;
321 cvals->rx_coalesce_usecs_low = 0;
322 cvals->rx_max_coalesced_frames_low = 0;
323 cvals->tx_coalesce_usecs_low = 0;
324 cvals->tx_max_coalesced_frames_low = 0;
325
326 /* When the packet rate is below pkt_rate_high but above
327 * pkt_rate_low (both measured in packets per second) the
328 * normal {rx,tx}_* coalescing parameters are used.
329 */
330
331 /* When the packet rate is (measured in packets per second)
332 * is above pkt_rate_high, the {rx,tx}_*_high parameters are
333 * used.
334 */
335 cvals->pkt_rate_high = 0;
336 cvals->rx_coalesce_usecs_high = 0;
337 cvals->rx_max_coalesced_frames_high = 0;
338 cvals->tx_coalesce_usecs_high = 0;
339 cvals->tx_max_coalesced_frames_high = 0;
340
341 /* How often to do adaptive coalescing packet rate sampling,
342 * measured in seconds. Must not be zero.
343 */
344 cvals->rate_sample_interval = 0;
345
346 return 0;
347}
348
349/* Change the coalescing values.
350 * Both cvals->*_usecs and cvals->*_frames have to be > 0
351 * in order for coalescing to be active
352 */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500353static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354{
355 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000356 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Andy Flemingb31a1d82008-12-16 15:29:15 -0800358 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
Kumar Gala0bbaf062005-06-20 10:54:21 -0500359 return -EOPNOTSUPP;
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 /* Set up rx coalescing */
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000362 /* As of now, we will enable/disable coalescing for all
363 * queues together in case of eTSEC2, this will be modified
364 * along with the ethtool interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if ((cvals->rx_coalesce_usecs == 0) ||
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000366 (cvals->rx_max_coalesced_frames == 0)) {
367 for (i = 0; i < priv->num_rx_queues; i++)
368 priv->rx_queue[i]->rxcoalescing = 0;
369 } else {
370 for (i = 0; i < priv->num_rx_queues; i++)
371 priv->rx_queue[i]->rxcoalescing = 1;
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400374 if (NULL == priv->phydev)
375 return -ENODEV;
376
377 /* Check the bounds of the values */
378 if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
379 pr_info("Coalescing is limited to %d microseconds\n",
Joe Perches59deab22011-06-14 08:57:47 +0000380 GFAR_MAX_COAL_USECS);
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400381 return -EINVAL;
382 }
383
384 if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
385 pr_info("Coalescing is limited to %d frames\n",
Joe Perches59deab22011-06-14 08:57:47 +0000386 GFAR_MAX_COAL_FRAMES);
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400387 return -EINVAL;
388 }
389
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000390 for (i = 0; i < priv->num_rx_queues; i++) {
391 priv->rx_queue[i]->rxic = mk_ic_value(
392 cvals->rx_max_coalesced_frames,
393 gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs));
394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 /* Set up tx coalescing */
397 if ((cvals->tx_coalesce_usecs == 0) ||
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000398 (cvals->tx_max_coalesced_frames == 0)) {
399 for (i = 0; i < priv->num_tx_queues; i++)
400 priv->tx_queue[i]->txcoalescing = 0;
401 } else {
402 for (i = 0; i < priv->num_tx_queues; i++)
403 priv->tx_queue[i]->txcoalescing = 1;
404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400406 /* Check the bounds of the values */
407 if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
408 pr_info("Coalescing is limited to %d microseconds\n",
Joe Perches59deab22011-06-14 08:57:47 +0000409 GFAR_MAX_COAL_USECS);
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400410 return -EINVAL;
411 }
412
413 if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
414 pr_info("Coalescing is limited to %d frames\n",
Joe Perches59deab22011-06-14 08:57:47 +0000415 GFAR_MAX_COAL_FRAMES);
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400416 return -EINVAL;
417 }
418
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000419 for (i = 0; i < priv->num_tx_queues; i++) {
420 priv->tx_queue[i]->txic = mk_ic_value(
421 cvals->tx_max_coalesced_frames,
422 gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs));
423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000425 gfar_configure_coalescing(priv, 0xFF, 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 return 0;
428}
429
430/* Fills in rvals with the current ring parameters. Currently,
431 * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
432 * jumbo are ignored by the driver */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500433static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
435 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000436 struct gfar_priv_tx_q *tx_queue = NULL;
437 struct gfar_priv_rx_q *rx_queue = NULL;
438
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000439 tx_queue = priv->tx_queue[0];
440 rx_queue = priv->rx_queue[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE;
443 rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE;
444 rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE;
445 rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE;
446
447 /* Values changeable by the user. The valid values are
448 * in the range 1 to the "*_max_pending" counterpart above.
449 */
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000450 rvals->rx_pending = rx_queue->rx_ring_size;
451 rvals->rx_mini_pending = rx_queue->rx_ring_size;
452 rvals->rx_jumbo_pending = rx_queue->rx_ring_size;
453 rvals->tx_pending = tx_queue->tx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454}
455
456/* Change the current ring parameters, stopping the controller if
457 * necessary so that we don't mess things up while we're in
458 * motion. We wait for the ring to be clean before reallocating
459 * the rings. */
Kumar Gala0bbaf062005-06-20 10:54:21 -0500460static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 struct gfar_private *priv = netdev_priv(dev);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000463 int err = 0, i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE)
466 return -EINVAL;
467
468 if (!is_power_of_2(rvals->rx_pending)) {
Joe Perches59deab22011-06-14 08:57:47 +0000469 netdev_err(dev, "Ring sizes must be a power of 2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return -EINVAL;
471 }
472
473 if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE)
474 return -EINVAL;
475
476 if (!is_power_of_2(rvals->tx_pending)) {
Joe Perches59deab22011-06-14 08:57:47 +0000477 netdev_err(dev, "Ring sizes must be a power of 2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return -EINVAL;
479 }
480
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 if (dev->flags & IFF_UP) {
Kumar Gala0bbaf062005-06-20 10:54:21 -0500483 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Kumar Gala0bbaf062005-06-20 10:54:21 -0500485 /* Halt TX and RX, and process the frames which
486 * have already been received */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000487 local_irq_save(flags);
488 lock_tx_qs(priv);
489 lock_rx_qs(priv);
Andy Flemingfef61082006-04-20 16:44:29 -0500490
Kumar Gala0bbaf062005-06-20 10:54:21 -0500491 gfar_halt(dev);
Andy Flemingfef61082006-04-20 16:44:29 -0500492
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000493 unlock_rx_qs(priv);
494 unlock_tx_qs(priv);
495 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000497 for (i = 0; i < priv->num_rx_queues; i++)
498 gfar_clean_rx_ring(priv->rx_queue[i],
499 priv->rx_queue[i]->rx_ring_size);
Dai Haruki12dea572008-12-16 15:30:20 -0800500
Kumar Gala0bbaf062005-06-20 10:54:21 -0500501 /* Now we take down the rings to rebuild them */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 stop_gfar(dev);
503 }
504
Kumar Gala0bbaf062005-06-20 10:54:21 -0500505 /* Change the size */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000506 for (i = 0; i < priv->num_rx_queues; i++) {
507 priv->rx_queue[i]->rx_ring_size = rvals->rx_pending;
508 priv->tx_queue[i]->tx_ring_size = rvals->tx_pending;
509 priv->tx_queue[i]->num_txbdfree = priv->tx_queue[i]->tx_ring_size;
510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Kumar Gala0bbaf062005-06-20 10:54:21 -0500512 /* Rebuild the rings with the new size */
Dai Haruki12dea572008-12-16 15:30:20 -0800513 if (dev->flags & IFF_UP) {
Kumar Gala0bbaf062005-06-20 10:54:21 -0500514 err = startup_gfar(dev);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000515 netif_tx_wake_all_queues(dev);
Dai Haruki12dea572008-12-16 15:30:20 -0800516 }
Kumar Gala0bbaf062005-06-20 10:54:21 -0500517 return err;
518}
519
Michał Mirosław8b3afe92011-04-15 04:50:50 +0000520int gfar_set_features(struct net_device *dev, u32 features)
Kumar Gala0bbaf062005-06-20 10:54:21 -0500521{
522 struct gfar_private *priv = netdev_priv(dev);
Scott Woodd87eb122008-07-11 18:04:45 -0500523 unsigned long flags;
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000524 int err = 0, i = 0;
Michał Mirosław8b3afe92011-04-15 04:50:50 +0000525 u32 changed = dev->features ^ features;
Kumar Gala0bbaf062005-06-20 10:54:21 -0500526
Michał Mirosław8b3afe92011-04-15 04:50:50 +0000527 if (!(changed & NETIF_F_RXCSUM))
528 return 0;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000529
Kumar Gala0bbaf062005-06-20 10:54:21 -0500530 if (dev->flags & IFF_UP) {
Kumar Gala0bbaf062005-06-20 10:54:21 -0500531 /* Halt TX and RX, and process the frames which
532 * have already been received */
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000533 local_irq_save(flags);
534 lock_tx_qs(priv);
535 lock_rx_qs(priv);
Andy Flemingfef61082006-04-20 16:44:29 -0500536
Kumar Gala0bbaf062005-06-20 10:54:21 -0500537 gfar_halt(dev);
Andy Flemingfef61082006-04-20 16:44:29 -0500538
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000539 unlock_tx_qs(priv);
540 unlock_rx_qs(priv);
Dan Carpenter97564032010-10-13 09:19:55 +0000541 local_irq_restore(flags);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500542
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000543 for (i = 0; i < priv->num_rx_queues; i++)
544 gfar_clean_rx_ring(priv->rx_queue[i],
545 priv->rx_queue[i]->rx_ring_size);
Dai Haruki12dea572008-12-16 15:30:20 -0800546
Kumar Gala0bbaf062005-06-20 10:54:21 -0500547 /* Now we take down the rings to rebuild them */
548 stop_gfar(dev);
Kumar Gala0bbaf062005-06-20 10:54:21 -0500549
Michał Mirosław8b3afe92011-04-15 04:50:50 +0000550 dev->features = features;
Kumar Gala0bbaf062005-06-20 10:54:21 -0500551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 err = startup_gfar(dev);
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000553 netif_tx_wake_all_queues(dev);
Dai Haruki12dea572008-12-16 15:30:20 -0800554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return err;
556}
557
Kumar Gala0bbaf062005-06-20 10:54:21 -0500558static uint32_t gfar_get_msglevel(struct net_device *dev)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400559{
Kumar Gala0bbaf062005-06-20 10:54:21 -0500560 struct gfar_private *priv = netdev_priv(dev);
561 return priv->msg_enable;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400562}
563
Kumar Gala0bbaf062005-06-20 10:54:21 -0500564static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400565{
Kumar Gala0bbaf062005-06-20 10:54:21 -0500566 struct gfar_private *priv = netdev_priv(dev);
567 priv->msg_enable = data;
568}
569
Scott Woodd87eb122008-07-11 18:04:45 -0500570#ifdef CONFIG_PM
571static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
572{
573 struct gfar_private *priv = netdev_priv(dev);
574
Andy Flemingb31a1d82008-12-16 15:29:15 -0800575 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
Scott Woodd87eb122008-07-11 18:04:45 -0500576 wol->supported = WAKE_MAGIC;
577 wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
578 } else {
579 wol->supported = wol->wolopts = 0;
580 }
581}
582
583static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
584{
585 struct gfar_private *priv = netdev_priv(dev);
586 unsigned long flags;
587
Andy Flemingb31a1d82008-12-16 15:29:15 -0800588 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
Scott Woodd87eb122008-07-11 18:04:45 -0500589 wol->wolopts != 0)
590 return -EINVAL;
591
592 if (wol->wolopts & ~WAKE_MAGIC)
593 return -EINVAL;
594
Rafael J. Wysocki6c4f1992010-11-09 11:54:19 +0000595 device_set_wakeup_enable(&dev->dev, wol->wolopts & WAKE_MAGIC);
596
Scott Woodd87eb122008-07-11 18:04:45 -0500597 spin_lock_irqsave(&priv->bflock, flags);
Rafael J. Wysocki6c4f1992010-11-09 11:54:19 +0000598 priv->wol_en = !!device_may_wakeup(&dev->dev);
Scott Woodd87eb122008-07-11 18:04:45 -0500599 spin_unlock_irqrestore(&priv->bflock, flags);
600
601 return 0;
602}
603#endif
Kumar Gala0bbaf062005-06-20 10:54:21 -0500604
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +0000605static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow)
606{
607 u32 fcr = 0x0, fpr = FPR_FILER_MASK;
608
609 if (ethflow & RXH_L2DA) {
610 fcr = RQFCR_PID_DAH |RQFCR_CMP_NOMATCH |
611 RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
612 ftp_rqfpr[priv->cur_filer_idx] = fpr;
613 ftp_rqfcr[priv->cur_filer_idx] = fcr;
614 gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
615 priv->cur_filer_idx = priv->cur_filer_idx - 1;
616
617 fcr = RQFCR_PID_DAL | RQFCR_AND | RQFCR_CMP_NOMATCH |
618 RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
619 ftp_rqfpr[priv->cur_filer_idx] = fpr;
620 ftp_rqfcr[priv->cur_filer_idx] = fcr;
621 gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
622 priv->cur_filer_idx = priv->cur_filer_idx - 1;
623 }
624
625 if (ethflow & RXH_VLAN) {
626 fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH |
627 RQFCR_AND | RQFCR_HASHTBL_0;
628 gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
629 ftp_rqfpr[priv->cur_filer_idx] = fpr;
630 ftp_rqfcr[priv->cur_filer_idx] = fcr;
631 priv->cur_filer_idx = priv->cur_filer_idx - 1;
632 }
633
634 if (ethflow & RXH_IP_SRC) {
635 fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
636 RQFCR_AND | RQFCR_HASHTBL_0;
637 ftp_rqfpr[priv->cur_filer_idx] = fpr;
638 ftp_rqfcr[priv->cur_filer_idx] = fcr;
639 gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
640 priv->cur_filer_idx = priv->cur_filer_idx - 1;
641 }
642
643 if (ethflow & (RXH_IP_DST)) {
644 fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
645 RQFCR_AND | RQFCR_HASHTBL_0;
646 ftp_rqfpr[priv->cur_filer_idx] = fpr;
647 ftp_rqfcr[priv->cur_filer_idx] = fcr;
648 gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
649 priv->cur_filer_idx = priv->cur_filer_idx - 1;
650 }
651
652 if (ethflow & RXH_L3_PROTO) {
653 fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH |
654 RQFCR_AND | RQFCR_HASHTBL_0;
655 ftp_rqfpr[priv->cur_filer_idx] = fpr;
656 ftp_rqfcr[priv->cur_filer_idx] = fcr;
657 gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
658 priv->cur_filer_idx = priv->cur_filer_idx - 1;
659 }
660
661 if (ethflow & RXH_L4_B_0_1) {
662 fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
663 RQFCR_AND | RQFCR_HASHTBL_0;
664 ftp_rqfpr[priv->cur_filer_idx] = fpr;
665 ftp_rqfcr[priv->cur_filer_idx] = fcr;
666 gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
667 priv->cur_filer_idx = priv->cur_filer_idx - 1;
668 }
669
670 if (ethflow & RXH_L4_B_2_3) {
671 fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
672 RQFCR_AND | RQFCR_HASHTBL_0;
673 ftp_rqfpr[priv->cur_filer_idx] = fpr;
674 ftp_rqfcr[priv->cur_filer_idx] = fcr;
675 gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
676 priv->cur_filer_idx = priv->cur_filer_idx - 1;
677 }
678}
679
680static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u64 class)
681{
682 unsigned int last_rule_idx = priv->cur_filer_idx;
683 unsigned int cmp_rqfpr;
684 unsigned int local_rqfpr[MAX_FILER_IDX + 1];
685 unsigned int local_rqfcr[MAX_FILER_IDX + 1];
686 int i = 0x0, k = 0x0;
687 int j = MAX_FILER_IDX, l = 0x0;
688
689 switch (class) {
690 case TCP_V4_FLOW:
691 cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP;
692 break;
693 case UDP_V4_FLOW:
694 cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP;
695 break;
696 case TCP_V6_FLOW:
697 cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP;
698 break;
699 case UDP_V6_FLOW:
700 cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP;
701 break;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +0000702 default:
Joe Perches59deab22011-06-14 08:57:47 +0000703 pr_err("Right now this class is not supported\n");
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +0000704 return 0;
705 }
706
707 for (i = 0; i < MAX_FILER_IDX + 1; i++) {
708 local_rqfpr[j] = ftp_rqfpr[i];
709 local_rqfcr[j] = ftp_rqfcr[i];
710 j--;
711 if ((ftp_rqfcr[i] == (RQFCR_PID_PARSE |
712 RQFCR_CLE |RQFCR_AND)) &&
713 (ftp_rqfpr[i] == cmp_rqfpr))
714 break;
715 }
716
717 if (i == MAX_FILER_IDX + 1) {
Joe Perches59deab22011-06-14 08:57:47 +0000718 pr_err("No parse rule found, can't create hash rules\n");
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +0000719 return 0;
720 }
721
722 /* If a match was found, then it begins the starting of a cluster rule
723 * if it was already programmed, we need to overwrite these rules
724 */
725 for (l = i+1; l < MAX_FILER_IDX; l++) {
726 if ((ftp_rqfcr[l] & RQFCR_CLE) &&
727 !(ftp_rqfcr[l] & RQFCR_AND)) {
728 ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT |
729 RQFCR_HASHTBL_0 | RQFCR_PID_MASK;
730 ftp_rqfpr[l] = FPR_FILER_MASK;
731 gfar_write_filer(priv, l, ftp_rqfcr[l], ftp_rqfpr[l]);
732 break;
733 }
734
735 if (!(ftp_rqfcr[l] & RQFCR_CLE) && (ftp_rqfcr[l] & RQFCR_AND))
736 continue;
737 else {
738 local_rqfpr[j] = ftp_rqfpr[l];
739 local_rqfcr[j] = ftp_rqfcr[l];
740 j--;
741 }
742 }
743
744 priv->cur_filer_idx = l - 1;
745 last_rule_idx = l;
746
747 /* hash rules */
748 ethflow_to_filer_rules(priv, ethflow);
749
750 /* Write back the popped out rules again */
751 for (k = j+1; k < MAX_FILER_IDX; k++) {
752 ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k];
753 ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k];
754 gfar_write_filer(priv, priv->cur_filer_idx,
755 local_rqfcr[k], local_rqfpr[k]);
756 if (!priv->cur_filer_idx)
757 break;
758 priv->cur_filer_idx = priv->cur_filer_idx - 1;
759 }
760
761 return 1;
762}
763
764static int gfar_set_hash_opts(struct gfar_private *priv, struct ethtool_rxnfc *cmd)
765{
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +0000766 /* write the filer rules here */
767 if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type))
Ben Hutchingsbde35282011-04-08 13:45:11 +0000768 return -EINVAL;
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +0000769
770 return 0;
771}
772
773static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
774{
775 struct gfar_private *priv = netdev_priv(dev);
776 int ret = 0;
777
778 switch(cmd->cmd) {
779 case ETHTOOL_SRXFH:
780 ret = gfar_set_hash_opts(priv, cmd);
781 break;
782 default:
783 ret = -EINVAL;
784 }
785
786 return ret;
787}
788
Jeff Garzik7282d492006-09-13 14:30:00 -0400789const struct ethtool_ops gfar_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .get_settings = gfar_gsettings,
Andy Flemingbb40dcb2005-09-23 22:54:21 -0400791 .set_settings = gfar_ssettings,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .get_drvinfo = gfar_gdrvinfo,
793 .get_regs_len = gfar_reglen,
794 .get_regs = gfar_get_regs,
795 .get_link = ethtool_op_get_link,
796 .get_coalesce = gfar_gcoalesce,
797 .set_coalesce = gfar_scoalesce,
798 .get_ringparam = gfar_gringparam,
799 .set_ringparam = gfar_sringparam,
800 .get_strings = gfar_gstrings,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700801 .get_sset_count = gfar_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 .get_ethtool_stats = gfar_fill_stats,
Kumar Gala0bbaf062005-06-20 10:54:21 -0500803 .get_msglevel = gfar_get_msglevel,
804 .set_msglevel = gfar_set_msglevel,
Scott Woodd87eb122008-07-11 18:04:45 -0500805#ifdef CONFIG_PM
806 .get_wol = gfar_get_wol,
807 .set_wol = gfar_set_wol,
808#endif
Sandeep Gopalpet7a8b3372009-11-02 07:03:40 +0000809 .set_rxnfc = gfar_set_nfc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810};