| 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 | * | 
|  | 13 | *  This software may be used and distributed according to | 
|  | 14 | *  the terms of the GNU Public License, Version 2, incorporated herein | 
|  | 15 | *  by reference. | 
|  | 16 | */ | 
|  | 17 |  | 
|  | 18 | #include <linux/config.h> | 
|  | 19 | #include <linux/kernel.h> | 
|  | 20 | #include <linux/sched.h> | 
|  | 21 | #include <linux/string.h> | 
|  | 22 | #include <linux/errno.h> | 
|  | 23 | #include <linux/slab.h> | 
|  | 24 | #include <linux/interrupt.h> | 
|  | 25 | #include <linux/init.h> | 
|  | 26 | #include <linux/delay.h> | 
|  | 27 | #include <linux/netdevice.h> | 
|  | 28 | #include <linux/etherdevice.h> | 
|  | 29 | #include <linux/skbuff.h> | 
|  | 30 | #include <linux/spinlock.h> | 
|  | 31 | #include <linux/mm.h> | 
|  | 32 |  | 
|  | 33 | #include <asm/io.h> | 
|  | 34 | #include <asm/irq.h> | 
|  | 35 | #include <asm/uaccess.h> | 
|  | 36 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/crc32.h> | 
|  | 38 | #include <asm/types.h> | 
|  | 39 | #include <asm/uaccess.h> | 
|  | 40 | #include <linux/ethtool.h> | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 41 | #include <linux/mii.h> | 
|  | 42 | #include <linux/phy.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 |  | 
|  | 44 | #include "gianfar.h" | 
|  | 45 |  | 
|  | 46 | #define is_power_of_2(x)        ((x) != 0 && (((x) & ((x) - 1)) == 0)) | 
|  | 47 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 48 | extern void gfar_start(struct net_device *dev); | 
|  | 49 | 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] | 50 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 51 | #define GFAR_MAX_COAL_USECS 0xffff | 
|  | 52 | #define GFAR_MAX_COAL_FRAMES 0xff | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 53 | 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] | 54 | u64 * buf); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 55 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf); | 
|  | 56 | static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); | 
|  | 57 | static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); | 
|  | 58 | static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals); | 
|  | 59 | static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals); | 
|  | 60 | static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 |  | 
|  | 62 | static char stat_gstrings[][ETH_GSTRING_LEN] = { | 
|  | 63 | "rx-dropped-by-kernel", | 
|  | 64 | "rx-large-frame-errors", | 
|  | 65 | "rx-short-frame-errors", | 
|  | 66 | "rx-non-octet-errors", | 
|  | 67 | "rx-crc-errors", | 
|  | 68 | "rx-overrun-errors", | 
|  | 69 | "rx-busy-errors", | 
|  | 70 | "rx-babbling-errors", | 
|  | 71 | "rx-truncated-frames", | 
|  | 72 | "ethernet-bus-error", | 
|  | 73 | "tx-babbling-errors", | 
|  | 74 | "tx-underrun-errors", | 
|  | 75 | "rx-skb-missing-errors", | 
|  | 76 | "tx-timeout-errors", | 
|  | 77 | "tx-rx-64-frames", | 
|  | 78 | "tx-rx-65-127-frames", | 
|  | 79 | "tx-rx-128-255-frames", | 
|  | 80 | "tx-rx-256-511-frames", | 
|  | 81 | "tx-rx-512-1023-frames", | 
|  | 82 | "tx-rx-1024-1518-frames", | 
|  | 83 | "tx-rx-1519-1522-good-vlan", | 
|  | 84 | "rx-bytes", | 
|  | 85 | "rx-packets", | 
|  | 86 | "rx-fcs-errors", | 
|  | 87 | "receive-multicast-packet", | 
|  | 88 | "receive-broadcast-packet", | 
|  | 89 | "rx-control-frame-packets", | 
|  | 90 | "rx-pause-frame-packets", | 
|  | 91 | "rx-unknown-op-code", | 
|  | 92 | "rx-alignment-error", | 
|  | 93 | "rx-frame-length-error", | 
|  | 94 | "rx-code-error", | 
|  | 95 | "rx-carrier-sense-error", | 
|  | 96 | "rx-undersize-packets", | 
|  | 97 | "rx-oversize-packets", | 
|  | 98 | "rx-fragmented-frames", | 
|  | 99 | "rx-jabber-frames", | 
|  | 100 | "rx-dropped-frames", | 
|  | 101 | "tx-byte-counter", | 
|  | 102 | "tx-packets", | 
|  | 103 | "tx-multicast-packets", | 
|  | 104 | "tx-broadcast-packets", | 
|  | 105 | "tx-pause-control-frames", | 
|  | 106 | "tx-deferral-packets", | 
|  | 107 | "tx-excessive-deferral-packets", | 
|  | 108 | "tx-single-collision-packets", | 
|  | 109 | "tx-multiple-collision-packets", | 
|  | 110 | "tx-late-collision-packets", | 
|  | 111 | "tx-excessive-collision-packets", | 
|  | 112 | "tx-total-collision", | 
|  | 113 | "reserved", | 
|  | 114 | "tx-dropped-frames", | 
|  | 115 | "tx-jabber-frames", | 
|  | 116 | "tx-fcs-errors", | 
|  | 117 | "tx-control-frames", | 
|  | 118 | "tx-oversize-frames", | 
|  | 119 | "tx-undersize-frames", | 
|  | 120 | "tx-fragmented-frames", | 
|  | 121 | }; | 
|  | 122 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 123 | /* Fill in a buffer with the strings which correspond to the | 
|  | 124 | * stats */ | 
|  | 125 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf) | 
|  | 126 | { | 
|  | 127 | struct gfar_private *priv = netdev_priv(dev); | 
| Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 128 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 129 | if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) | 
|  | 130 | memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN); | 
|  | 131 | else | 
|  | 132 | memcpy(buf, stat_gstrings, | 
|  | 133 | GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN); | 
|  | 134 | } | 
|  | 135 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* Fill in an array of 64-bit statistics from various sources. | 
|  | 137 | * This array will be appended to the end of the ethtool_stats | 
|  | 138 | * structure, and returned to user space | 
|  | 139 | */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 140 | 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] | 141 | { | 
|  | 142 | int i; | 
|  | 143 | struct gfar_private *priv = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | u64 *extra = (u64 *) & priv->extra_stats; | 
| 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 | if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { | 
|  | 147 | u32 *rmon = (u32 *) & priv->regs->rmon; | 
|  | 148 | struct gfar_stats *stats = (struct gfar_stats *) buf; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 150 | for (i = 0; i < GFAR_RMON_LEN; i++) | 
|  | 151 | stats->rmon[i] = (u64) (rmon[i]); | 
|  | 152 |  | 
|  | 153 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) | 
|  | 154 | stats->extra[i] = extra[i]; | 
|  | 155 | } else | 
|  | 156 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) | 
|  | 157 | buf[i] = extra[i]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } | 
|  | 159 |  | 
|  | 160 | /* Returns the number of stats (and their corresponding strings) */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 161 | static int gfar_stats_count(struct net_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | struct gfar_private *priv = netdev_priv(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 165 | if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) | 
|  | 166 | return GFAR_STATS_LEN; | 
|  | 167 | else | 
|  | 168 | return GFAR_EXTRA_STATS_LEN; | 
| 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); | 
|  | 179 | drvinfo->n_stats = GFAR_STATS_LEN; | 
|  | 180 | drvinfo->testinfo_len = 0; | 
|  | 181 | drvinfo->regdump_len = 0; | 
|  | 182 | drvinfo->eedump_len = 0; | 
|  | 183 | } | 
|  | 184 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 185 |  | 
|  | 186 | static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd) | 
|  | 187 | { | 
|  | 188 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 189 | struct phy_device *phydev = priv->phydev; | 
|  | 190 |  | 
|  | 191 | if (NULL == phydev) | 
|  | 192 | return -ENODEV; | 
|  | 193 |  | 
|  | 194 | return phy_ethtool_sset(phydev, cmd); | 
|  | 195 | } | 
|  | 196 |  | 
|  | 197 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /* Return the current settings in the ethtool_cmd structure */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 199 | static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { | 
|  | 201 | struct gfar_private *priv = netdev_priv(dev); | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 202 | struct phy_device *phydev = priv->phydev; | 
| 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; | 
|  | 206 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | cmd->maxtxpkt = priv->txcount; | 
|  | 208 | cmd->maxrxpkt = priv->rxcount; | 
|  | 209 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 210 | return phy_ethtool_gset(phydev, cmd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } | 
|  | 212 |  | 
|  | 213 | /* Return the length of the register structure */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 214 | static int gfar_reglen(struct net_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { | 
|  | 216 | return sizeof (struct gfar); | 
|  | 217 | } | 
|  | 218 |  | 
|  | 219 | /* Return a dump of the GFAR register space */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 220 | 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] | 221 | { | 
|  | 222 | int i; | 
|  | 223 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 224 | u32 *theregs = (u32 *) priv->regs; | 
|  | 225 | u32 *buf = (u32 *) regbuf; | 
|  | 226 |  | 
|  | 227 | for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++) | 
|  | 228 | buf[i] = theregs[i]; | 
|  | 229 | } | 
|  | 230 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | /* Convert microseconds to ethernet clock ticks, which changes | 
|  | 232 | * depending on what speed the controller is running at */ | 
|  | 233 | static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs) | 
|  | 234 | { | 
|  | 235 | unsigned int count; | 
|  | 236 |  | 
|  | 237 | /* The timer is different, depending on the interface speed */ | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 238 | switch (priv->phydev->speed) { | 
|  | 239 | case SPEED_1000: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | count = GFAR_GBIT_TIME; | 
|  | 241 | break; | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 242 | case SPEED_100: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | count = GFAR_100_TIME; | 
|  | 244 | break; | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 245 | case SPEED_10: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | default: | 
|  | 247 | count = GFAR_10_TIME; | 
|  | 248 | break; | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | /* Make sure we return a number greater than 0 | 
|  | 252 | * if usecs > 0 */ | 
|  | 253 | return ((usecs * 1000 + count - 1) / count); | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 | /* Convert ethernet clock ticks to microseconds */ | 
|  | 257 | static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks) | 
|  | 258 | { | 
|  | 259 | unsigned int count; | 
|  | 260 |  | 
|  | 261 | /* The timer is different, depending on the interface speed */ | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 262 | switch (priv->phydev->speed) { | 
|  | 263 | case SPEED_1000: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | count = GFAR_GBIT_TIME; | 
|  | 265 | break; | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 266 | case SPEED_100: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | count = GFAR_100_TIME; | 
|  | 268 | break; | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 269 | case SPEED_10: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | default: | 
|  | 271 | count = GFAR_10_TIME; | 
|  | 272 | break; | 
|  | 273 | } | 
|  | 274 |  | 
|  | 275 | /* Make sure we return a number greater than 0 */ | 
|  | 276 | /* if ticks is > 0 */ | 
|  | 277 | return ((ticks * count) / 1000); | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | /* Get the coalescing parameters, and put them in the cvals | 
|  | 281 | * structure.  */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 282 | static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { | 
|  | 284 | struct gfar_private *priv = netdev_priv(dev); | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 285 |  | 
|  | 286 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) | 
|  | 287 | return -EOPNOTSUPP; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 289 | if (NULL == priv->phydev) | 
|  | 290 | return -ENODEV; | 
|  | 291 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime); | 
|  | 293 | cvals->rx_max_coalesced_frames = priv->rxcount; | 
|  | 294 |  | 
|  | 295 | cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, priv->txtime); | 
|  | 296 | cvals->tx_max_coalesced_frames = priv->txcount; | 
|  | 297 |  | 
|  | 298 | cvals->use_adaptive_rx_coalesce = 0; | 
|  | 299 | cvals->use_adaptive_tx_coalesce = 0; | 
|  | 300 |  | 
|  | 301 | cvals->pkt_rate_low = 0; | 
|  | 302 | cvals->rx_coalesce_usecs_low = 0; | 
|  | 303 | cvals->rx_max_coalesced_frames_low = 0; | 
|  | 304 | cvals->tx_coalesce_usecs_low = 0; | 
|  | 305 | cvals->tx_max_coalesced_frames_low = 0; | 
|  | 306 |  | 
|  | 307 | /* When the packet rate is below pkt_rate_high but above | 
|  | 308 | * pkt_rate_low (both measured in packets per second) the | 
|  | 309 | * normal {rx,tx}_* coalescing parameters are used. | 
|  | 310 | */ | 
|  | 311 |  | 
|  | 312 | /* When the packet rate is (measured in packets per second) | 
|  | 313 | * is above pkt_rate_high, the {rx,tx}_*_high parameters are | 
|  | 314 | * used. | 
|  | 315 | */ | 
|  | 316 | cvals->pkt_rate_high = 0; | 
|  | 317 | cvals->rx_coalesce_usecs_high = 0; | 
|  | 318 | cvals->rx_max_coalesced_frames_high = 0; | 
|  | 319 | cvals->tx_coalesce_usecs_high = 0; | 
|  | 320 | cvals->tx_max_coalesced_frames_high = 0; | 
|  | 321 |  | 
|  | 322 | /* How often to do adaptive coalescing packet rate sampling, | 
|  | 323 | * measured in seconds.  Must not be zero. | 
|  | 324 | */ | 
|  | 325 | cvals->rate_sample_interval = 0; | 
|  | 326 |  | 
|  | 327 | return 0; | 
|  | 328 | } | 
|  | 329 |  | 
|  | 330 | /* Change the coalescing values. | 
|  | 331 | * Both cvals->*_usecs and cvals->*_frames have to be > 0 | 
|  | 332 | * in order for coalescing to be active | 
|  | 333 | */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 334 | static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { | 
|  | 336 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 337 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 338 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) | 
|  | 339 | return -EOPNOTSUPP; | 
|  | 340 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | /* Set up rx coalescing */ | 
|  | 342 | if ((cvals->rx_coalesce_usecs == 0) || | 
|  | 343 | (cvals->rx_max_coalesced_frames == 0)) | 
|  | 344 | priv->rxcoalescing = 0; | 
|  | 345 | else | 
|  | 346 | priv->rxcoalescing = 1; | 
|  | 347 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 348 | if (NULL == priv->phydev) | 
|  | 349 | return -ENODEV; | 
|  | 350 |  | 
|  | 351 | /* Check the bounds of the values */ | 
|  | 352 | if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) { | 
|  | 353 | pr_info("Coalescing is limited to %d microseconds\n", | 
|  | 354 | GFAR_MAX_COAL_USECS); | 
|  | 355 | return -EINVAL; | 
|  | 356 | } | 
|  | 357 |  | 
|  | 358 | if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { | 
|  | 359 | pr_info("Coalescing is limited to %d frames\n", | 
|  | 360 | GFAR_MAX_COAL_FRAMES); | 
|  | 361 | return -EINVAL; | 
|  | 362 | } | 
|  | 363 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | priv->rxtime = gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs); | 
|  | 365 | priv->rxcount = cvals->rx_max_coalesced_frames; | 
|  | 366 |  | 
|  | 367 | /* Set up tx coalescing */ | 
|  | 368 | if ((cvals->tx_coalesce_usecs == 0) || | 
|  | 369 | (cvals->tx_max_coalesced_frames == 0)) | 
|  | 370 | priv->txcoalescing = 0; | 
|  | 371 | else | 
|  | 372 | priv->txcoalescing = 1; | 
|  | 373 |  | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 374 | /* Check the bounds of the values */ | 
|  | 375 | if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) { | 
|  | 376 | pr_info("Coalescing is limited to %d microseconds\n", | 
|  | 377 | GFAR_MAX_COAL_USECS); | 
|  | 378 | return -EINVAL; | 
|  | 379 | } | 
|  | 380 |  | 
|  | 381 | if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { | 
|  | 382 | pr_info("Coalescing is limited to %d frames\n", | 
|  | 383 | GFAR_MAX_COAL_FRAMES); | 
|  | 384 | return -EINVAL; | 
|  | 385 | } | 
|  | 386 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | priv->txtime = gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs); | 
|  | 388 | priv->txcount = cvals->tx_max_coalesced_frames; | 
|  | 389 |  | 
|  | 390 | if (priv->rxcoalescing) | 
|  | 391 | gfar_write(&priv->regs->rxic, | 
|  | 392 | mk_ic_value(priv->rxcount, priv->rxtime)); | 
|  | 393 | else | 
|  | 394 | gfar_write(&priv->regs->rxic, 0); | 
|  | 395 |  | 
|  | 396 | if (priv->txcoalescing) | 
|  | 397 | gfar_write(&priv->regs->txic, | 
|  | 398 | mk_ic_value(priv->txcount, priv->txtime)); | 
|  | 399 | else | 
|  | 400 | gfar_write(&priv->regs->txic, 0); | 
|  | 401 |  | 
|  | 402 | return 0; | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | /* Fills in rvals with the current ring parameters.  Currently, | 
|  | 406 | * rx, rx_mini, and rx_jumbo rings are the same size, as mini and | 
|  | 407 | * jumbo are ignored by the driver */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 408 | static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { | 
|  | 410 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 411 |  | 
|  | 412 | rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE; | 
|  | 413 | rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE; | 
|  | 414 | rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE; | 
|  | 415 | rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE; | 
|  | 416 |  | 
|  | 417 | /* Values changeable by the user.  The valid values are | 
|  | 418 | * in the range 1 to the "*_max_pending" counterpart above. | 
|  | 419 | */ | 
|  | 420 | rvals->rx_pending = priv->rx_ring_size; | 
|  | 421 | rvals->rx_mini_pending = priv->rx_ring_size; | 
|  | 422 | rvals->rx_jumbo_pending = priv->rx_ring_size; | 
|  | 423 | rvals->tx_pending = priv->tx_ring_size; | 
|  | 424 | } | 
|  | 425 |  | 
|  | 426 | /* Change the current ring parameters, stopping the controller if | 
|  | 427 | * necessary so that we don't mess things up while we're in | 
|  | 428 | * motion.  We wait for the ring to be clean before reallocating | 
|  | 429 | * the rings. */ | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 430 | static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 433 | int err = 0; | 
|  | 434 |  | 
|  | 435 | if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) | 
|  | 436 | return -EINVAL; | 
|  | 437 |  | 
|  | 438 | if (!is_power_of_2(rvals->rx_pending)) { | 
|  | 439 | printk("%s: Ring sizes must be a power of 2\n", | 
|  | 440 | dev->name); | 
|  | 441 | return -EINVAL; | 
|  | 442 | } | 
|  | 443 |  | 
|  | 444 | if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE) | 
|  | 445 | return -EINVAL; | 
|  | 446 |  | 
|  | 447 | if (!is_power_of_2(rvals->tx_pending)) { | 
|  | 448 | printk("%s: Ring sizes must be a power of 2\n", | 
|  | 449 | dev->name); | 
|  | 450 | return -EINVAL; | 
|  | 451 | } | 
|  | 452 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (dev->flags & IFF_UP) { | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 454 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 456 | /* Halt TX and RX, and process the frames which | 
|  | 457 | * have already been received */ | 
|  | 458 | spin_lock_irqsave(&priv->lock, flags); | 
|  | 459 | gfar_halt(dev); | 
|  | 460 | gfar_clean_rx_ring(dev, priv->rx_ring_size); | 
|  | 461 | spin_unlock_irqrestore(&priv->lock, 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 */ | 
|  | 491 | spin_lock_irqsave(&priv->lock, flags); | 
|  | 492 | gfar_halt(dev); | 
|  | 493 | gfar_clean_rx_ring(dev, priv->rx_ring_size); | 
|  | 494 | spin_unlock_irqrestore(&priv->lock, flags); | 
|  | 495 |  | 
|  | 496 | /* Now we take down the rings to rebuild them */ | 
|  | 497 | stop_gfar(dev); | 
|  | 498 | } | 
|  | 499 |  | 
|  | 500 | priv->rx_csum_enable = data; | 
|  | 501 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | if (dev->flags & IFF_UP) | 
|  | 503 | err = startup_gfar(dev); | 
|  | 504 |  | 
|  | 505 | return err; | 
|  | 506 | } | 
|  | 507 |  | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 508 | static uint32_t gfar_get_rx_csum(struct net_device *dev) | 
|  | 509 | { | 
|  | 510 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 511 |  | 
|  | 512 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) | 
|  | 513 | return 0; | 
|  | 514 |  | 
|  | 515 | return priv->rx_csum_enable; | 
|  | 516 | } | 
|  | 517 |  | 
|  | 518 | static int gfar_set_tx_csum(struct net_device *dev, uint32_t data) | 
|  | 519 | { | 
|  | 520 | unsigned long flags; | 
|  | 521 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 522 |  | 
|  | 523 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) | 
|  | 524 | return -EOPNOTSUPP; | 
|  | 525 |  | 
|  | 526 | spin_lock_irqsave(&priv->lock, flags); | 
|  | 527 | gfar_halt(dev); | 
|  | 528 |  | 
|  | 529 | if (data) | 
|  | 530 | dev->features |= NETIF_F_IP_CSUM; | 
|  | 531 | else | 
|  | 532 | dev->features &= ~NETIF_F_IP_CSUM; | 
|  | 533 |  | 
|  | 534 | gfar_start(dev); | 
|  | 535 | spin_unlock_irqrestore(&priv->lock, flags); | 
|  | 536 |  | 
|  | 537 | return 0; | 
|  | 538 | } | 
|  | 539 |  | 
|  | 540 | static uint32_t gfar_get_tx_csum(struct net_device *dev) | 
|  | 541 | { | 
|  | 542 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 543 |  | 
|  | 544 | if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) | 
|  | 545 | return 0; | 
|  | 546 |  | 
|  | 547 | return (dev->features & NETIF_F_IP_CSUM) != 0; | 
|  | 548 | } | 
|  | 549 |  | 
|  | 550 | static uint32_t gfar_get_msglevel(struct net_device *dev) | 
|  | 551 | { | 
|  | 552 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 553 | return priv->msg_enable; | 
|  | 554 | } | 
|  | 555 |  | 
|  | 556 | static void gfar_set_msglevel(struct net_device *dev, uint32_t data) | 
|  | 557 | { | 
|  | 558 | struct gfar_private *priv = netdev_priv(dev); | 
|  | 559 | priv->msg_enable = data; | 
|  | 560 | } | 
|  | 561 |  | 
|  | 562 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | struct ethtool_ops gfar_ethtool_ops = { | 
|  | 564 | .get_settings = gfar_gsettings, | 
| Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 565 | .set_settings = gfar_ssettings, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | .get_drvinfo = gfar_gdrvinfo, | 
|  | 567 | .get_regs_len = gfar_reglen, | 
|  | 568 | .get_regs = gfar_get_regs, | 
|  | 569 | .get_link = ethtool_op_get_link, | 
|  | 570 | .get_coalesce = gfar_gcoalesce, | 
|  | 571 | .set_coalesce = gfar_scoalesce, | 
|  | 572 | .get_ringparam = gfar_gringparam, | 
|  | 573 | .set_ringparam = gfar_sringparam, | 
|  | 574 | .get_strings = gfar_gstrings, | 
|  | 575 | .get_stats_count = gfar_stats_count, | 
|  | 576 | .get_ethtool_stats = gfar_fill_stats, | 
| Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 577 | .get_rx_csum = gfar_get_rx_csum, | 
|  | 578 | .get_tx_csum = gfar_get_tx_csum, | 
|  | 579 | .set_rx_csum = gfar_set_rx_csum, | 
|  | 580 | .set_tx_csum = gfar_set_tx_csum, | 
|  | 581 | .get_msglevel = gfar_get_msglevel, | 
|  | 582 | .set_msglevel = gfar_set_msglevel, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | }; |