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