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> |
| 37 | #include <asm/uaccess.h> |
| 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); |
| 45 | 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] | 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 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 125 | if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
| 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 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 142 | if (priv->einfo->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 | |
| 156 | /* Returns the number of stats (and their corresponding strings) */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 157 | static int gfar_stats_count(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | struct gfar_private *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 161 | if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
| 162 | return GFAR_STATS_LEN; |
| 163 | else |
| 164 | return GFAR_EXTRA_STATS_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* Fills in the drvinfo structure with some basic info */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 168 | static void gfar_gdrvinfo(struct net_device *dev, struct |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | ethtool_drvinfo *drvinfo) |
| 170 | { |
| 171 | strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN); |
| 172 | strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN); |
| 173 | strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN); |
| 174 | strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN); |
| 175 | drvinfo->n_stats = GFAR_STATS_LEN; |
| 176 | drvinfo->testinfo_len = 0; |
| 177 | drvinfo->regdump_len = 0; |
| 178 | drvinfo->eedump_len = 0; |
| 179 | } |
| 180 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 181 | |
| 182 | static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 183 | { |
| 184 | struct gfar_private *priv = netdev_priv(dev); |
| 185 | struct phy_device *phydev = priv->phydev; |
| 186 | |
| 187 | if (NULL == phydev) |
| 188 | return -ENODEV; |
| 189 | |
| 190 | return phy_ethtool_sset(phydev, cmd); |
| 191 | } |
| 192 | |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /* Return the current settings in the ethtool_cmd structure */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 195 | static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | struct gfar_private *priv = netdev_priv(dev); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 198 | struct phy_device *phydev = priv->phydev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 200 | if (NULL == phydev) |
| 201 | return -ENODEV; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | cmd->maxtxpkt = priv->txcount; |
| 204 | cmd->maxrxpkt = priv->rxcount; |
| 205 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 206 | return phy_ethtool_gset(phydev, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /* Return the length of the register structure */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 210 | static int gfar_reglen(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | return sizeof (struct gfar); |
| 213 | } |
| 214 | |
| 215 | /* Return a dump of the GFAR register space */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 216 | 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] | 217 | { |
| 218 | int i; |
| 219 | struct gfar_private *priv = netdev_priv(dev); |
Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 220 | u32 __iomem *theregs = (u32 __iomem *) priv->regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | u32 *buf = (u32 *) regbuf; |
| 222 | |
| 223 | for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++) |
Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 224 | buf[i] = gfar_read(&theregs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* Convert microseconds to ethernet clock ticks, which changes |
| 228 | * depending on what speed the controller is running at */ |
| 229 | static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs) |
| 230 | { |
| 231 | unsigned int count; |
| 232 | |
| 233 | /* The timer is different, depending on the interface speed */ |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 234 | switch (priv->phydev->speed) { |
| 235 | case SPEED_1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | count = GFAR_GBIT_TIME; |
| 237 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 238 | case SPEED_100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | count = GFAR_100_TIME; |
| 240 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 241 | case SPEED_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | default: |
| 243 | count = GFAR_10_TIME; |
| 244 | break; |
| 245 | } |
| 246 | |
| 247 | /* Make sure we return a number greater than 0 |
| 248 | * if usecs > 0 */ |
| 249 | return ((usecs * 1000 + count - 1) / count); |
| 250 | } |
| 251 | |
| 252 | /* Convert ethernet clock ticks to microseconds */ |
| 253 | static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks) |
| 254 | { |
| 255 | unsigned int count; |
| 256 | |
| 257 | /* The timer is different, depending on the interface speed */ |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 258 | switch (priv->phydev->speed) { |
| 259 | case SPEED_1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | count = GFAR_GBIT_TIME; |
| 261 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 262 | case SPEED_100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | count = GFAR_100_TIME; |
| 264 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 265 | case SPEED_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | default: |
| 267 | count = GFAR_10_TIME; |
| 268 | break; |
| 269 | } |
| 270 | |
| 271 | /* Make sure we return a number greater than 0 */ |
| 272 | /* if ticks is > 0 */ |
| 273 | return ((ticks * count) / 1000); |
| 274 | } |
| 275 | |
| 276 | /* Get the coalescing parameters, and put them in the cvals |
| 277 | * structure. */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 278 | static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
| 280 | struct gfar_private *priv = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 281 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 282 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
| 283 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 285 | if (NULL == priv->phydev) |
| 286 | return -ENODEV; |
| 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime); |
| 289 | cvals->rx_max_coalesced_frames = priv->rxcount; |
| 290 | |
| 291 | cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, priv->txtime); |
| 292 | cvals->tx_max_coalesced_frames = priv->txcount; |
| 293 | |
| 294 | cvals->use_adaptive_rx_coalesce = 0; |
| 295 | cvals->use_adaptive_tx_coalesce = 0; |
| 296 | |
| 297 | cvals->pkt_rate_low = 0; |
| 298 | cvals->rx_coalesce_usecs_low = 0; |
| 299 | cvals->rx_max_coalesced_frames_low = 0; |
| 300 | cvals->tx_coalesce_usecs_low = 0; |
| 301 | cvals->tx_max_coalesced_frames_low = 0; |
| 302 | |
| 303 | /* When the packet rate is below pkt_rate_high but above |
| 304 | * pkt_rate_low (both measured in packets per second) the |
| 305 | * normal {rx,tx}_* coalescing parameters are used. |
| 306 | */ |
| 307 | |
| 308 | /* When the packet rate is (measured in packets per second) |
| 309 | * is above pkt_rate_high, the {rx,tx}_*_high parameters are |
| 310 | * used. |
| 311 | */ |
| 312 | cvals->pkt_rate_high = 0; |
| 313 | cvals->rx_coalesce_usecs_high = 0; |
| 314 | cvals->rx_max_coalesced_frames_high = 0; |
| 315 | cvals->tx_coalesce_usecs_high = 0; |
| 316 | cvals->tx_max_coalesced_frames_high = 0; |
| 317 | |
| 318 | /* How often to do adaptive coalescing packet rate sampling, |
| 319 | * measured in seconds. Must not be zero. |
| 320 | */ |
| 321 | cvals->rate_sample_interval = 0; |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /* Change the coalescing values. |
| 327 | * Both cvals->*_usecs and cvals->*_frames have to be > 0 |
| 328 | * in order for coalescing to be active |
| 329 | */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 330 | static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | struct gfar_private *priv = netdev_priv(dev); |
| 333 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 334 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
| 335 | return -EOPNOTSUPP; |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | /* Set up rx coalescing */ |
| 338 | if ((cvals->rx_coalesce_usecs == 0) || |
| 339 | (cvals->rx_max_coalesced_frames == 0)) |
| 340 | priv->rxcoalescing = 0; |
| 341 | else |
| 342 | priv->rxcoalescing = 1; |
| 343 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 344 | if (NULL == priv->phydev) |
| 345 | return -ENODEV; |
| 346 | |
| 347 | /* Check the bounds of the values */ |
| 348 | if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) { |
| 349 | pr_info("Coalescing is limited to %d microseconds\n", |
| 350 | GFAR_MAX_COAL_USECS); |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | |
| 354 | if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { |
| 355 | pr_info("Coalescing is limited to %d frames\n", |
| 356 | GFAR_MAX_COAL_FRAMES); |
| 357 | return -EINVAL; |
| 358 | } |
| 359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | priv->rxtime = gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs); |
| 361 | priv->rxcount = cvals->rx_max_coalesced_frames; |
| 362 | |
| 363 | /* Set up tx coalescing */ |
| 364 | if ((cvals->tx_coalesce_usecs == 0) || |
| 365 | (cvals->tx_max_coalesced_frames == 0)) |
| 366 | priv->txcoalescing = 0; |
| 367 | else |
| 368 | priv->txcoalescing = 1; |
| 369 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 370 | /* Check the bounds of the values */ |
| 371 | if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) { |
| 372 | pr_info("Coalescing is limited to %d microseconds\n", |
| 373 | GFAR_MAX_COAL_USECS); |
| 374 | return -EINVAL; |
| 375 | } |
| 376 | |
| 377 | if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { |
| 378 | pr_info("Coalescing is limited to %d frames\n", |
| 379 | GFAR_MAX_COAL_FRAMES); |
| 380 | return -EINVAL; |
| 381 | } |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | priv->txtime = gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs); |
| 384 | priv->txcount = cvals->tx_max_coalesced_frames; |
| 385 | |
| 386 | if (priv->rxcoalescing) |
| 387 | gfar_write(&priv->regs->rxic, |
| 388 | mk_ic_value(priv->rxcount, priv->rxtime)); |
| 389 | else |
| 390 | gfar_write(&priv->regs->rxic, 0); |
| 391 | |
| 392 | if (priv->txcoalescing) |
| 393 | gfar_write(&priv->regs->txic, |
| 394 | mk_ic_value(priv->txcount, priv->txtime)); |
| 395 | else |
| 396 | gfar_write(&priv->regs->txic, 0); |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | /* Fills in rvals with the current ring parameters. Currently, |
| 402 | * rx, rx_mini, and rx_jumbo rings are the same size, as mini and |
| 403 | * jumbo are ignored by the driver */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 404 | static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
| 406 | struct gfar_private *priv = netdev_priv(dev); |
| 407 | |
| 408 | rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 409 | rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 410 | rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 411 | rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE; |
| 412 | |
| 413 | /* Values changeable by the user. The valid values are |
| 414 | * in the range 1 to the "*_max_pending" counterpart above. |
| 415 | */ |
| 416 | rvals->rx_pending = priv->rx_ring_size; |
| 417 | rvals->rx_mini_pending = priv->rx_ring_size; |
| 418 | rvals->rx_jumbo_pending = priv->rx_ring_size; |
| 419 | rvals->tx_pending = priv->tx_ring_size; |
| 420 | } |
| 421 | |
| 422 | /* Change the current ring parameters, stopping the controller if |
| 423 | * necessary so that we don't mess things up while we're in |
| 424 | * motion. We wait for the ring to be clean before reallocating |
| 425 | * the rings. */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 426 | static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | struct gfar_private *priv = netdev_priv(dev); |
| 429 | int err = 0; |
| 430 | |
| 431 | if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) |
| 432 | return -EINVAL; |
| 433 | |
| 434 | if (!is_power_of_2(rvals->rx_pending)) { |
| 435 | printk("%s: Ring sizes must be a power of 2\n", |
| 436 | dev->name); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | |
| 440 | if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE) |
| 441 | return -EINVAL; |
| 442 | |
| 443 | if (!is_power_of_2(rvals->tx_pending)) { |
| 444 | printk("%s: Ring sizes must be a power of 2\n", |
| 445 | dev->name); |
| 446 | return -EINVAL; |
| 447 | } |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | if (dev->flags & IFF_UP) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 450 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 452 | /* Halt TX and RX, and process the frames which |
| 453 | * have already been received */ |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 454 | spin_lock_irqsave(&priv->txlock, flags); |
| 455 | spin_lock(&priv->rxlock); |
| 456 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 457 | gfar_halt(dev); |
| 458 | gfar_clean_rx_ring(dev, priv->rx_ring_size); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 459 | |
| 460 | spin_unlock(&priv->rxlock); |
| 461 | spin_unlock_irqrestore(&priv->txlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 463 | /* Now we take down the rings to rebuild them */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | stop_gfar(dev); |
| 465 | } |
| 466 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 467 | /* Change the size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | priv->rx_ring_size = rvals->rx_pending; |
| 469 | priv->tx_ring_size = rvals->tx_pending; |
| 470 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 471 | /* Rebuild the rings with the new size */ |
| 472 | if (dev->flags & IFF_UP) |
| 473 | err = startup_gfar(dev); |
| 474 | |
| 475 | return err; |
| 476 | } |
| 477 | |
| 478 | static int gfar_set_rx_csum(struct net_device *dev, uint32_t data) |
| 479 | { |
| 480 | struct gfar_private *priv = netdev_priv(dev); |
| 481 | int err = 0; |
| 482 | |
| 483 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
| 484 | return -EOPNOTSUPP; |
| 485 | |
| 486 | if (dev->flags & IFF_UP) { |
| 487 | unsigned long flags; |
| 488 | |
| 489 | /* Halt TX and RX, and process the frames which |
| 490 | * have already been received */ |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 491 | spin_lock_irqsave(&priv->txlock, flags); |
| 492 | spin_lock(&priv->rxlock); |
| 493 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 494 | gfar_halt(dev); |
| 495 | gfar_clean_rx_ring(dev, priv->rx_ring_size); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 496 | |
| 497 | spin_unlock(&priv->rxlock); |
| 498 | spin_unlock_irqrestore(&priv->txlock, flags); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 499 | |
| 500 | /* Now we take down the rings to rebuild them */ |
| 501 | stop_gfar(dev); |
| 502 | } |
| 503 | |
| 504 | priv->rx_csum_enable = data; |
| 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | if (dev->flags & IFF_UP) |
| 507 | err = startup_gfar(dev); |
| 508 | |
| 509 | return err; |
| 510 | } |
| 511 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 512 | static uint32_t gfar_get_rx_csum(struct net_device *dev) |
| 513 | { |
| 514 | struct gfar_private *priv = netdev_priv(dev); |
| 515 | |
| 516 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
| 517 | return 0; |
| 518 | |
| 519 | return priv->rx_csum_enable; |
| 520 | } |
| 521 | |
| 522 | static int gfar_set_tx_csum(struct net_device *dev, uint32_t data) |
| 523 | { |
| 524 | unsigned long flags; |
| 525 | struct gfar_private *priv = netdev_priv(dev); |
| 526 | |
| 527 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
| 528 | return -EOPNOTSUPP; |
| 529 | |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 530 | spin_lock_irqsave(&priv->txlock, flags); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 531 | gfar_halt(dev); |
| 532 | |
| 533 | if (data) |
| 534 | dev->features |= NETIF_F_IP_CSUM; |
| 535 | else |
| 536 | dev->features &= ~NETIF_F_IP_CSUM; |
| 537 | |
| 538 | gfar_start(dev); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 539 | spin_unlock_irqrestore(&priv->txlock, flags); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | static uint32_t gfar_get_tx_csum(struct net_device *dev) |
| 545 | { |
| 546 | struct gfar_private *priv = netdev_priv(dev); |
| 547 | |
| 548 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
| 549 | return 0; |
| 550 | |
| 551 | return (dev->features & NETIF_F_IP_CSUM) != 0; |
| 552 | } |
| 553 | |
| 554 | static uint32_t gfar_get_msglevel(struct net_device *dev) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 555 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 556 | struct gfar_private *priv = netdev_priv(dev); |
| 557 | return priv->msg_enable; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 558 | } |
| 559 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 560 | static void gfar_set_msglevel(struct net_device *dev, uint32_t data) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 561 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 562 | struct gfar_private *priv = netdev_priv(dev); |
| 563 | priv->msg_enable = data; |
| 564 | } |
| 565 | |
| 566 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 567 | const struct ethtool_ops gfar_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | .get_settings = gfar_gsettings, |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 569 | .set_settings = gfar_ssettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | .get_drvinfo = gfar_gdrvinfo, |
| 571 | .get_regs_len = gfar_reglen, |
| 572 | .get_regs = gfar_get_regs, |
| 573 | .get_link = ethtool_op_get_link, |
| 574 | .get_coalesce = gfar_gcoalesce, |
| 575 | .set_coalesce = gfar_scoalesce, |
| 576 | .get_ringparam = gfar_gringparam, |
| 577 | .set_ringparam = gfar_sringparam, |
| 578 | .get_strings = gfar_gstrings, |
| 579 | .get_stats_count = gfar_stats_count, |
| 580 | .get_ethtool_stats = gfar_fill_stats, |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 581 | .get_rx_csum = gfar_get_rx_csum, |
| 582 | .get_tx_csum = gfar_get_tx_csum, |
| 583 | .set_rx_csum = gfar_set_rx_csum, |
| 584 | .set_tx_csum = gfar_set_tx_csum, |
| 585 | .get_msglevel = gfar_get_msglevel, |
| 586 | .set_msglevel = gfar_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | }; |