| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Gala | 4c8d3d9 | 2005-11-13 16:06:30 -0800 | [diff] [blame] | 9 |  *  Maintainer: Kumar Gala | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 |  * | 
 | 11 |  *  Copyright (c) 2003,2004 Freescale Semiconductor, Inc. | 
 | 12 |  * | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 13 |  *  This software may be used and distributed according to | 
 | 14 |  *  the terms of the GNU Public License, Version 2, incorporated herein | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 |  *  by reference. | 
 | 16 |  */ | 
 | 17 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/kernel.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/crc32.h> | 
 | 36 | #include <asm/types.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/ethtool.h> | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 38 | #include <linux/mii.h> | 
 | 39 | #include <linux/phy.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 |  | 
 | 41 | #include "gianfar.h" | 
 | 42 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 43 | extern void gfar_start(struct net_device *dev); | 
 | 44 | extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 46 | #define GFAR_MAX_COAL_USECS 0xffff | 
 | 47 | #define GFAR_MAX_COAL_FRAMES 0xff | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 48 | static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | 		     u64 * buf); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 50 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf); | 
 | 51 | static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); | 
 | 52 | static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); | 
 | 53 | static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals); | 
 | 54 | static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals); | 
 | 55 | static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 |  | 
 | 57 | static 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 Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 118 | /* Fill in a buffer with the strings which correspond to the | 
 | 119 |  * stats */ | 
 | 120 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf) | 
 | 121 | { | 
 | 122 | 	struct gfar_private *priv = netdev_priv(dev); | 
| Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 123 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 124 | 	if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /* 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 Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 135 | static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { | 
 | 137 | 	int i; | 
 | 138 | 	struct gfar_private *priv = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | 	u64 *extra = (u64 *) & priv->extra_stats; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 141 | 	if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { | 
| Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 142 | 		u32 __iomem *rmon = (u32 __iomem *) & priv->regs->rmon; | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 143 | 		struct gfar_stats *stats = (struct gfar_stats *) buf; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 145 | 		for (i = 0; i < GFAR_RMON_LEN; i++) | 
| Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 146 | 			stats->rmon[i] = (u64) gfar_read(&rmon[i]); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 147 |  | 
 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } | 
 | 154 |  | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 155 | static int gfar_sset_count(struct net_device *dev, int sset) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | 	struct gfar_private *priv = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 |  | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 159 | 	switch (sset) { | 
 | 160 | 	case ETH_SS_STATS: | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 161 | 		if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 162 | 			return GFAR_STATS_LEN; | 
 | 163 | 		else | 
 | 164 | 			return GFAR_EXTRA_STATS_LEN; | 
 | 165 | 	default: | 
 | 166 | 		return -EOPNOTSUPP; | 
 | 167 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } | 
 | 169 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | /* Fills in the drvinfo structure with some basic info */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 171 | static void gfar_gdrvinfo(struct net_device *dev, struct | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | 	      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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | 	drvinfo->regdump_len = 0; | 
 | 179 | 	drvinfo->eedump_len = 0; | 
 | 180 | } | 
 | 181 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 182 |  | 
 | 183 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | /* Return the current settings in the ethtool_cmd structure */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 196 | static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { | 
 | 198 | 	struct gfar_private *priv = netdev_priv(dev); | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 199 | 	struct phy_device *phydev = priv->phydev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 201 | 	if (NULL == phydev) | 
 | 202 | 		return -ENODEV; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 203 |  | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 204 | 	cmd->maxtxpkt = get_icft_value(priv->txic); | 
 | 205 | 	cmd->maxrxpkt = get_icft_value(priv->rxic); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 207 | 	return phy_ethtool_gset(phydev, cmd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } | 
 | 209 |  | 
 | 210 | /* Return the length of the register structure */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 211 | static int gfar_reglen(struct net_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { | 
 | 213 | 	return sizeof (struct gfar); | 
 | 214 | } | 
 | 215 |  | 
 | 216 | /* Return a dump of the GFAR register space */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 217 | static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { | 
 | 219 | 	int i; | 
 | 220 | 	struct gfar_private *priv = netdev_priv(dev); | 
| Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 221 | 	u32 __iomem *theregs = (u32 __iomem *) priv->regs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | 	u32 *buf = (u32 *) regbuf; | 
 | 223 |  | 
 | 224 | 	for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++) | 
| Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 225 | 		buf[i] = gfar_read(&theregs[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } | 
 | 227 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* Convert microseconds to ethernet clock ticks, which changes | 
 | 229 |  * depending on what speed the controller is running at */ | 
 | 230 | static 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 Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 235 | 	switch (priv->phydev->speed) { | 
 | 236 | 	case SPEED_1000: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | 		count = GFAR_GBIT_TIME; | 
 | 238 | 		break; | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 239 | 	case SPEED_100: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | 		count = GFAR_100_TIME; | 
 | 241 | 		break; | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 242 | 	case SPEED_10: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | 	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 */ | 
 | 254 | static 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 Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 259 | 	switch (priv->phydev->speed) { | 
 | 260 | 	case SPEED_1000: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | 		count = GFAR_GBIT_TIME; | 
 | 262 | 		break; | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 263 | 	case SPEED_100: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | 		count = GFAR_100_TIME; | 
 | 265 | 		break; | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 266 | 	case SPEED_10: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | 	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 Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 279 | static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { | 
 | 281 | 	struct gfar_private *priv = netdev_priv(dev); | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 282 | 	unsigned long rxtime; | 
 | 283 | 	unsigned long rxcount; | 
 | 284 | 	unsigned long txtime; | 
 | 285 | 	unsigned long txcount; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 286 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 287 | 	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 288 | 		return -EOPNOTSUPP; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 290 | 	if (NULL == priv->phydev) | 
 | 291 | 		return -ENODEV; | 
 | 292 |  | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 293 | 	rxtime  = get_ictt_value(priv->rxic); | 
 | 294 | 	rxcount = get_icft_value(priv->rxic); | 
 | 295 | 	txtime  = get_ictt_value(priv->txic); | 
| Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 296 | 	txcount = get_icft_value(priv->txic); | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 297 | 	cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime); | 
 | 298 | 	cvals->rx_max_coalesced_frames = rxcount; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 |  | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 300 | 	cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime); | 
 | 301 | 	cvals->tx_max_coalesced_frames = txcount; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 |  | 
 | 303 | 	cvals->use_adaptive_rx_coalesce = 0; | 
 | 304 | 	cvals->use_adaptive_tx_coalesce = 0; | 
 | 305 |  | 
 | 306 | 	cvals->pkt_rate_low = 0; | 
 | 307 | 	cvals->rx_coalesce_usecs_low = 0; | 
 | 308 | 	cvals->rx_max_coalesced_frames_low = 0; | 
 | 309 | 	cvals->tx_coalesce_usecs_low = 0; | 
 | 310 | 	cvals->tx_max_coalesced_frames_low = 0; | 
 | 311 |  | 
 | 312 | 	/* When the packet rate is below pkt_rate_high but above | 
 | 313 | 	 * pkt_rate_low (both measured in packets per second) the | 
 | 314 | 	 * normal {rx,tx}_* coalescing parameters are used. | 
 | 315 | 	 */ | 
 | 316 |  | 
 | 317 | 	/* When the packet rate is (measured in packets per second) | 
 | 318 | 	 * is above pkt_rate_high, the {rx,tx}_*_high parameters are | 
 | 319 | 	 * used. | 
 | 320 | 	 */ | 
 | 321 | 	cvals->pkt_rate_high = 0; | 
 | 322 | 	cvals->rx_coalesce_usecs_high = 0; | 
 | 323 | 	cvals->rx_max_coalesced_frames_high = 0; | 
 | 324 | 	cvals->tx_coalesce_usecs_high = 0; | 
 | 325 | 	cvals->tx_max_coalesced_frames_high = 0; | 
 | 326 |  | 
 | 327 | 	/* How often to do adaptive coalescing packet rate sampling, | 
 | 328 | 	 * measured in seconds.  Must not be zero. | 
 | 329 | 	 */ | 
 | 330 | 	cvals->rate_sample_interval = 0; | 
 | 331 |  | 
 | 332 | 	return 0; | 
 | 333 | } | 
 | 334 |  | 
 | 335 | /* Change the coalescing values. | 
 | 336 |  * Both cvals->*_usecs and cvals->*_frames have to be > 0 | 
 | 337 |  * in order for coalescing to be active | 
 | 338 |  */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 339 | static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { | 
 | 341 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 342 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 343 | 	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 344 | 		return -EOPNOTSUPP; | 
 | 345 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | 	/* Set up rx coalescing */ | 
 | 347 | 	if ((cvals->rx_coalesce_usecs == 0) || | 
 | 348 | 	    (cvals->rx_max_coalesced_frames == 0)) | 
 | 349 | 		priv->rxcoalescing = 0; | 
 | 350 | 	else | 
 | 351 | 		priv->rxcoalescing = 1; | 
 | 352 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 353 | 	if (NULL == priv->phydev) | 
 | 354 | 		return -ENODEV; | 
 | 355 |  | 
 | 356 | 	/* Check the bounds of the values */ | 
 | 357 | 	if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) { | 
 | 358 | 		pr_info("Coalescing is limited to %d microseconds\n", | 
 | 359 | 				GFAR_MAX_COAL_USECS); | 
 | 360 | 		return -EINVAL; | 
 | 361 | 	} | 
 | 362 |  | 
 | 363 | 	if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { | 
 | 364 | 		pr_info("Coalescing is limited to %d frames\n", | 
 | 365 | 				GFAR_MAX_COAL_FRAMES); | 
 | 366 | 		return -EINVAL; | 
 | 367 | 	} | 
 | 368 |  | 
| Jiajun Wu | accff95 | 2009-07-30 14:20:42 -0700 | [diff] [blame] | 369 | 	priv->rxic = mk_ic_value(cvals->rx_max_coalesced_frames, | 
 | 370 | 		gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 |  | 
 | 372 | 	/* Set up tx coalescing */ | 
 | 373 | 	if ((cvals->tx_coalesce_usecs == 0) || | 
 | 374 | 	    (cvals->tx_max_coalesced_frames == 0)) | 
 | 375 | 		priv->txcoalescing = 0; | 
 | 376 | 	else | 
 | 377 | 		priv->txcoalescing = 1; | 
 | 378 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 379 | 	/* Check the bounds of the values */ | 
 | 380 | 	if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) { | 
 | 381 | 		pr_info("Coalescing is limited to %d microseconds\n", | 
 | 382 | 				GFAR_MAX_COAL_USECS); | 
 | 383 | 		return -EINVAL; | 
 | 384 | 	} | 
 | 385 |  | 
 | 386 | 	if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { | 
 | 387 | 		pr_info("Coalescing is limited to %d frames\n", | 
 | 388 | 				GFAR_MAX_COAL_FRAMES); | 
 | 389 | 		return -EINVAL; | 
 | 390 | 	} | 
 | 391 |  | 
| Jiajun Wu | accff95 | 2009-07-30 14:20:42 -0700 | [diff] [blame] | 392 | 	priv->txic = mk_ic_value(cvals->tx_max_coalesced_frames, | 
 | 393 | 		gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 |  | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 395 | 	gfar_write(&priv->regs->rxic, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | 	if (priv->rxcoalescing) | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 397 | 		gfar_write(&priv->regs->rxic, priv->rxic); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 |  | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 399 | 	gfar_write(&priv->regs->txic, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | 	if (priv->txcoalescing) | 
| Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 401 | 		gfar_write(&priv->regs->txic, priv->txic); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 |  | 
 | 403 | 	return 0; | 
 | 404 | } | 
 | 405 |  | 
 | 406 | /* Fills in rvals with the current ring parameters.  Currently, | 
 | 407 |  * rx, rx_mini, and rx_jumbo rings are the same size, as mini and | 
 | 408 |  * jumbo are ignored by the driver */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 409 | static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { | 
 | 411 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 412 |  | 
 | 413 | 	rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE; | 
 | 414 | 	rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE; | 
 | 415 | 	rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE; | 
 | 416 | 	rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE; | 
 | 417 |  | 
 | 418 | 	/* Values changeable by the user.  The valid values are | 
 | 419 | 	 * in the range 1 to the "*_max_pending" counterpart above. | 
 | 420 | 	 */ | 
 | 421 | 	rvals->rx_pending = priv->rx_ring_size; | 
 | 422 | 	rvals->rx_mini_pending = priv->rx_ring_size; | 
 | 423 | 	rvals->rx_jumbo_pending = priv->rx_ring_size; | 
 | 424 | 	rvals->tx_pending = priv->tx_ring_size; | 
 | 425 | } | 
 | 426 |  | 
 | 427 | /* Change the current ring parameters, stopping the controller if | 
 | 428 |  * necessary so that we don't mess things up while we're in | 
 | 429 |  * motion.  We wait for the ring to be clean before reallocating | 
 | 430 |  * the rings. */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 431 | static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 434 | 	int err = 0; | 
 | 435 |  | 
 | 436 | 	if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) | 
 | 437 | 		return -EINVAL; | 
 | 438 |  | 
 | 439 | 	if (!is_power_of_2(rvals->rx_pending)) { | 
 | 440 | 		printk("%s: Ring sizes must be a power of 2\n", | 
 | 441 | 				dev->name); | 
 | 442 | 		return -EINVAL; | 
 | 443 | 	} | 
 | 444 |  | 
 | 445 | 	if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE) | 
 | 446 | 		return -EINVAL; | 
 | 447 |  | 
 | 448 | 	if (!is_power_of_2(rvals->tx_pending)) { | 
 | 449 | 		printk("%s: Ring sizes must be a power of 2\n", | 
 | 450 | 				dev->name); | 
 | 451 | 		return -EINVAL; | 
 | 452 | 	} | 
 | 453 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | 	if (dev->flags & IFF_UP) { | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 455 | 		unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 457 | 		/* Halt TX and RX, and process the frames which | 
 | 458 | 		 * have already been received */ | 
| Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 459 | 		spin_lock_irqsave(&priv->txlock, flags); | 
 | 460 | 		spin_lock(&priv->rxlock); | 
 | 461 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 462 | 		gfar_halt(dev); | 
| Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 463 |  | 
 | 464 | 		spin_unlock(&priv->rxlock); | 
 | 465 | 		spin_unlock_irqrestore(&priv->txlock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 |  | 
| Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 467 | 		gfar_clean_rx_ring(dev, priv->rx_ring_size); | 
 | 468 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 469 | 		/* Now we take down the rings to rebuild them */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | 		stop_gfar(dev); | 
 | 471 | 	} | 
 | 472 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 473 | 	/* Change the size */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | 	priv->rx_ring_size = rvals->rx_pending; | 
 | 475 | 	priv->tx_ring_size = rvals->tx_pending; | 
| Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 476 | 	priv->num_txbdfree = priv->tx_ring_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 478 | 	/* Rebuild the rings with the new size */ | 
| Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 479 | 	if (dev->flags & IFF_UP) { | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 480 | 		err = startup_gfar(dev); | 
| Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 481 | 		netif_wake_queue(dev); | 
 | 482 | 	} | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 483 | 	return err; | 
 | 484 | } | 
 | 485 |  | 
 | 486 | static int gfar_set_rx_csum(struct net_device *dev, uint32_t data) | 
 | 487 | { | 
 | 488 | 	struct gfar_private *priv = netdev_priv(dev); | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 489 | 	unsigned long flags; | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 490 | 	int err = 0; | 
 | 491 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 492 | 	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 493 | 		return -EOPNOTSUPP; | 
 | 494 |  | 
 | 495 | 	if (dev->flags & IFF_UP) { | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 496 | 		/* Halt TX and RX, and process the frames which | 
 | 497 | 		 * have already been received */ | 
| Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 498 | 		spin_lock_irqsave(&priv->txlock, flags); | 
 | 499 | 		spin_lock(&priv->rxlock); | 
 | 500 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 501 | 		gfar_halt(dev); | 
| Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 502 |  | 
 | 503 | 		spin_unlock(&priv->rxlock); | 
 | 504 | 		spin_unlock_irqrestore(&priv->txlock, flags); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 505 |  | 
| Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 506 | 		gfar_clean_rx_ring(dev, priv->rx_ring_size); | 
 | 507 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 508 | 		/* Now we take down the rings to rebuild them */ | 
 | 509 | 		stop_gfar(dev); | 
 | 510 | 	} | 
 | 511 |  | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 512 | 	spin_lock_irqsave(&priv->bflock, flags); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 513 | 	priv->rx_csum_enable = data; | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 514 | 	spin_unlock_irqrestore(&priv->bflock, flags); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 515 |  | 
| Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 516 | 	if (dev->flags & IFF_UP) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | 		err = startup_gfar(dev); | 
| Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 518 | 		netif_wake_queue(dev); | 
 | 519 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | 	return err; | 
 | 521 | } | 
 | 522 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 523 | static uint32_t gfar_get_rx_csum(struct net_device *dev) | 
 | 524 | { | 
 | 525 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 526 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 527 | 	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 528 | 		return 0; | 
 | 529 |  | 
 | 530 | 	return priv->rx_csum_enable; | 
 | 531 | } | 
 | 532 |  | 
 | 533 | static int gfar_set_tx_csum(struct net_device *dev, uint32_t data) | 
 | 534 | { | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 535 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 536 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 537 | 	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 538 | 		return -EOPNOTSUPP; | 
 | 539 |  | 
| Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 540 | 	netif_tx_lock_bh(dev); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 541 |  | 
 | 542 | 	if (data) | 
 | 543 | 		dev->features |= NETIF_F_IP_CSUM; | 
 | 544 | 	else | 
 | 545 | 		dev->features &= ~NETIF_F_IP_CSUM; | 
 | 546 |  | 
| Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 547 | 	netif_tx_unlock_bh(dev); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 548 |  | 
 | 549 | 	return 0; | 
 | 550 | } | 
 | 551 |  | 
 | 552 | static uint32_t gfar_get_tx_csum(struct net_device *dev) | 
 | 553 | { | 
 | 554 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 555 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 556 | 	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 557 | 		return 0; | 
 | 558 |  | 
 | 559 | 	return (dev->features & NETIF_F_IP_CSUM) != 0; | 
 | 560 | } | 
 | 561 |  | 
 | 562 | static uint32_t gfar_get_msglevel(struct net_device *dev) | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 563 | { | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 564 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 565 | 	return priv->msg_enable; | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 566 | } | 
 | 567 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 568 | static void gfar_set_msglevel(struct net_device *dev, uint32_t data) | 
| Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 569 | { | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 570 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 571 | 	priv->msg_enable = data; | 
 | 572 | } | 
 | 573 |  | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 574 | #ifdef CONFIG_PM | 
 | 575 | static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | 
 | 576 | { | 
 | 577 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 578 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 579 | 	if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) { | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 580 | 		wol->supported = WAKE_MAGIC; | 
 | 581 | 		wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0; | 
 | 582 | 	} else { | 
 | 583 | 		wol->supported = wol->wolopts = 0; | 
 | 584 | 	} | 
 | 585 | } | 
 | 586 |  | 
 | 587 | static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | 
 | 588 | { | 
 | 589 | 	struct gfar_private *priv = netdev_priv(dev); | 
 | 590 | 	unsigned long flags; | 
 | 591 |  | 
| Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 592 | 	if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) && | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 593 | 	    wol->wolopts != 0) | 
 | 594 | 		return -EINVAL; | 
 | 595 |  | 
 | 596 | 	if (wol->wolopts & ~WAKE_MAGIC) | 
 | 597 | 		return -EINVAL; | 
 | 598 |  | 
 | 599 | 	spin_lock_irqsave(&priv->bflock, flags); | 
 | 600 | 	priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0; | 
| Anton Vorontsov | 2884e5c | 2009-02-01 00:52:34 -0800 | [diff] [blame] | 601 | 	device_set_wakeup_enable(&dev->dev, priv->wol_en); | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 602 | 	spin_unlock_irqrestore(&priv->bflock, flags); | 
 | 603 |  | 
 | 604 | 	return 0; | 
 | 605 | } | 
 | 606 | #endif | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 607 |  | 
| Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 608 | const struct ethtool_ops gfar_ethtool_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | 	.get_settings = gfar_gsettings, | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 610 | 	.set_settings = gfar_ssettings, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | 	.get_drvinfo = gfar_gdrvinfo, | 
 | 612 | 	.get_regs_len = gfar_reglen, | 
 | 613 | 	.get_regs = gfar_get_regs, | 
 | 614 | 	.get_link = ethtool_op_get_link, | 
 | 615 | 	.get_coalesce = gfar_gcoalesce, | 
 | 616 | 	.set_coalesce = gfar_scoalesce, | 
 | 617 | 	.get_ringparam = gfar_gringparam, | 
 | 618 | 	.set_ringparam = gfar_sringparam, | 
 | 619 | 	.get_strings = gfar_gstrings, | 
| Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 620 | 	.get_sset_count = gfar_sset_count, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | 	.get_ethtool_stats = gfar_fill_stats, | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 622 | 	.get_rx_csum = gfar_get_rx_csum, | 
 | 623 | 	.get_tx_csum = gfar_get_tx_csum, | 
 | 624 | 	.set_rx_csum = gfar_set_rx_csum, | 
 | 625 | 	.set_tx_csum = gfar_set_tx_csum, | 
| Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 626 | 	.set_sg = ethtool_op_set_sg, | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 627 | 	.get_msglevel = gfar_get_msglevel, | 
 | 628 | 	.set_msglevel = gfar_set_msglevel, | 
| Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 629 | #ifdef CONFIG_PM | 
 | 630 | 	.get_wol = gfar_get_wol, | 
 | 631 | 	.set_wol = gfar_set_wol, | 
 | 632 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | }; |