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); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 140 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | u64 *extra = (u64 *) & priv->extra_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 143 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 144 | u32 __iomem *rmon = (u32 __iomem *) ®s->rmon; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 145 | struct gfar_stats *stats = (struct gfar_stats *) buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 147 | for (i = 0; i < GFAR_RMON_LEN; i++) |
Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 148 | stats->rmon[i] = (u64) gfar_read(&rmon[i]); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 149 | |
| 150 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) |
| 151 | stats->extra[i] = extra[i]; |
| 152 | } else |
| 153 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) |
| 154 | buf[i] = extra[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 157 | static int gfar_sset_count(struct net_device *dev, int sset) |
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 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 161 | switch (sset) { |
| 162 | case ETH_SS_STATS: |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 163 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 164 | return GFAR_STATS_LEN; |
| 165 | else |
| 166 | return GFAR_EXTRA_STATS_LEN; |
| 167 | default: |
| 168 | return -EOPNOTSUPP; |
| 169 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* Fills in the drvinfo structure with some basic info */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 173 | static void gfar_gdrvinfo(struct net_device *dev, struct |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | ethtool_drvinfo *drvinfo) |
| 175 | { |
| 176 | strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN); |
| 177 | strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN); |
| 178 | strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN); |
| 179 | strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | drvinfo->regdump_len = 0; |
| 181 | drvinfo->eedump_len = 0; |
| 182 | } |
| 183 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 184 | |
| 185 | static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 186 | { |
| 187 | struct gfar_private *priv = netdev_priv(dev); |
| 188 | struct phy_device *phydev = priv->phydev; |
| 189 | |
| 190 | if (NULL == phydev) |
| 191 | return -ENODEV; |
| 192 | |
| 193 | return phy_ethtool_sset(phydev, cmd); |
| 194 | } |
| 195 | |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | /* Return the current settings in the ethtool_cmd structure */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 198 | static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
| 200 | struct gfar_private *priv = netdev_priv(dev); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 201 | struct phy_device *phydev = priv->phydev; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 202 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 203 | struct gfar_priv_tx_q *tx_queue = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 205 | if (NULL == phydev) |
| 206 | return -ENODEV; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 207 | tx_queue = priv->tx_queue[0]; |
| 208 | rx_queue = priv->rx_queue[0]; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 209 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 210 | /* etsec-1.7 and older versions have only one txic |
| 211 | * and rxic regs although they support multiple queues */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 212 | cmd->maxtxpkt = get_icft_value(tx_queue->txic); |
| 213 | cmd->maxrxpkt = get_icft_value(rx_queue->rxic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 215 | return phy_ethtool_gset(phydev, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* Return the length of the register structure */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 219 | static int gfar_reglen(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
| 221 | return sizeof (struct gfar); |
| 222 | } |
| 223 | |
| 224 | /* Return a dump of the GFAR register space */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 225 | 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] | 226 | { |
| 227 | int i; |
| 228 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 229 | u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp[0].regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | u32 *buf = (u32 *) regbuf; |
| 231 | |
| 232 | for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++) |
Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 233 | buf[i] = gfar_read(&theregs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | /* Convert microseconds to ethernet clock ticks, which changes |
| 237 | * depending on what speed the controller is running at */ |
| 238 | static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs) |
| 239 | { |
| 240 | unsigned int count; |
| 241 | |
| 242 | /* The timer is different, depending on the interface speed */ |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 243 | switch (priv->phydev->speed) { |
| 244 | case SPEED_1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | count = GFAR_GBIT_TIME; |
| 246 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 247 | case SPEED_100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | count = GFAR_100_TIME; |
| 249 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 250 | case SPEED_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | default: |
| 252 | count = GFAR_10_TIME; |
| 253 | break; |
| 254 | } |
| 255 | |
| 256 | /* Make sure we return a number greater than 0 |
| 257 | * if usecs > 0 */ |
| 258 | return ((usecs * 1000 + count - 1) / count); |
| 259 | } |
| 260 | |
| 261 | /* Convert ethernet clock ticks to microseconds */ |
| 262 | static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks) |
| 263 | { |
| 264 | unsigned int count; |
| 265 | |
| 266 | /* The timer is different, depending on the interface speed */ |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 267 | switch (priv->phydev->speed) { |
| 268 | case SPEED_1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | count = GFAR_GBIT_TIME; |
| 270 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 271 | case SPEED_100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | count = GFAR_100_TIME; |
| 273 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 274 | case SPEED_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | default: |
| 276 | count = GFAR_10_TIME; |
| 277 | break; |
| 278 | } |
| 279 | |
| 280 | /* Make sure we return a number greater than 0 */ |
| 281 | /* if ticks is > 0 */ |
| 282 | return ((ticks * count) / 1000); |
| 283 | } |
| 284 | |
| 285 | /* Get the coalescing parameters, and put them in the cvals |
| 286 | * structure. */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 287 | static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
| 289 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 290 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 291 | struct gfar_priv_tx_q *tx_queue = NULL; |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 292 | unsigned long rxtime; |
| 293 | unsigned long rxcount; |
| 294 | unsigned long txtime; |
| 295 | unsigned long txcount; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 296 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 297 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 298 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 300 | if (NULL == priv->phydev) |
| 301 | return -ENODEV; |
| 302 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 303 | rx_queue = priv->rx_queue[0]; |
| 304 | tx_queue = priv->tx_queue[0]; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 305 | |
| 306 | rxtime = get_ictt_value(rx_queue->rxic); |
| 307 | rxcount = get_icft_value(rx_queue->rxic); |
| 308 | txtime = get_ictt_value(tx_queue->txic); |
| 309 | txcount = get_icft_value(tx_queue->txic); |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 310 | cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime); |
| 311 | cvals->rx_max_coalesced_frames = rxcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 313 | cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime); |
| 314 | cvals->tx_max_coalesced_frames = txcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | cvals->use_adaptive_rx_coalesce = 0; |
| 317 | cvals->use_adaptive_tx_coalesce = 0; |
| 318 | |
| 319 | cvals->pkt_rate_low = 0; |
| 320 | cvals->rx_coalesce_usecs_low = 0; |
| 321 | cvals->rx_max_coalesced_frames_low = 0; |
| 322 | cvals->tx_coalesce_usecs_low = 0; |
| 323 | cvals->tx_max_coalesced_frames_low = 0; |
| 324 | |
| 325 | /* When the packet rate is below pkt_rate_high but above |
| 326 | * pkt_rate_low (both measured in packets per second) the |
| 327 | * normal {rx,tx}_* coalescing parameters are used. |
| 328 | */ |
| 329 | |
| 330 | /* When the packet rate is (measured in packets per second) |
| 331 | * is above pkt_rate_high, the {rx,tx}_*_high parameters are |
| 332 | * used. |
| 333 | */ |
| 334 | cvals->pkt_rate_high = 0; |
| 335 | cvals->rx_coalesce_usecs_high = 0; |
| 336 | cvals->rx_max_coalesced_frames_high = 0; |
| 337 | cvals->tx_coalesce_usecs_high = 0; |
| 338 | cvals->tx_max_coalesced_frames_high = 0; |
| 339 | |
| 340 | /* How often to do adaptive coalescing packet rate sampling, |
| 341 | * measured in seconds. Must not be zero. |
| 342 | */ |
| 343 | cvals->rate_sample_interval = 0; |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /* Change the coalescing values. |
| 349 | * Both cvals->*_usecs and cvals->*_frames have to be > 0 |
| 350 | * in order for coalescing to be active |
| 351 | */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 352 | static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
| 354 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 355 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 357 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 358 | return -EOPNOTSUPP; |
| 359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | /* Set up rx coalescing */ |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 361 | /* As of now, we will enable/disable coalescing for all |
| 362 | * queues together in case of eTSEC2, this will be modified |
| 363 | * along with the ethtool interface */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | if ((cvals->rx_coalesce_usecs == 0) || |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 365 | (cvals->rx_max_coalesced_frames == 0)) { |
| 366 | for (i = 0; i < priv->num_rx_queues; i++) |
| 367 | priv->rx_queue[i]->rxcoalescing = 0; |
| 368 | } else { |
| 369 | for (i = 0; i < priv->num_rx_queues; i++) |
| 370 | priv->rx_queue[i]->rxcoalescing = 1; |
| 371 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 373 | if (NULL == priv->phydev) |
| 374 | return -ENODEV; |
| 375 | |
| 376 | /* Check the bounds of the values */ |
| 377 | if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) { |
| 378 | pr_info("Coalescing is limited to %d microseconds\n", |
| 379 | GFAR_MAX_COAL_USECS); |
| 380 | return -EINVAL; |
| 381 | } |
| 382 | |
| 383 | if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { |
| 384 | pr_info("Coalescing is limited to %d frames\n", |
| 385 | GFAR_MAX_COAL_FRAMES); |
| 386 | return -EINVAL; |
| 387 | } |
| 388 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 389 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 390 | priv->rx_queue[i]->rxic = mk_ic_value( |
| 391 | cvals->rx_max_coalesced_frames, |
| 392 | gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs)); |
| 393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | /* Set up tx coalescing */ |
| 396 | if ((cvals->tx_coalesce_usecs == 0) || |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 397 | (cvals->tx_max_coalesced_frames == 0)) { |
| 398 | for (i = 0; i < priv->num_tx_queues; i++) |
| 399 | priv->tx_queue[i]->txcoalescing = 0; |
| 400 | } else { |
| 401 | for (i = 0; i < priv->num_tx_queues; i++) |
| 402 | priv->tx_queue[i]->txcoalescing = 1; |
| 403 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 405 | /* Check the bounds of the values */ |
| 406 | if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) { |
| 407 | pr_info("Coalescing is limited to %d microseconds\n", |
| 408 | GFAR_MAX_COAL_USECS); |
| 409 | return -EINVAL; |
| 410 | } |
| 411 | |
| 412 | if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { |
| 413 | pr_info("Coalescing is limited to %d frames\n", |
| 414 | GFAR_MAX_COAL_FRAMES); |
| 415 | return -EINVAL; |
| 416 | } |
| 417 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 418 | for (i = 0; i < priv->num_tx_queues; i++) { |
| 419 | priv->tx_queue[i]->txic = mk_ic_value( |
| 420 | cvals->tx_max_coalesced_frames, |
| 421 | gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs)); |
| 422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 424 | gfar_configure_coalescing(priv, 0xFF, 0xFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | /* Fills in rvals with the current ring parameters. Currently, |
| 430 | * rx, rx_mini, and rx_jumbo rings are the same size, as mini and |
| 431 | * jumbo are ignored by the driver */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 432 | static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
| 434 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 435 | struct gfar_priv_tx_q *tx_queue = NULL; |
| 436 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 437 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 438 | tx_queue = priv->tx_queue[0]; |
| 439 | rx_queue = priv->rx_queue[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 442 | rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 443 | rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 444 | rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE; |
| 445 | |
| 446 | /* Values changeable by the user. The valid values are |
| 447 | * in the range 1 to the "*_max_pending" counterpart above. |
| 448 | */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 449 | rvals->rx_pending = rx_queue->rx_ring_size; |
| 450 | rvals->rx_mini_pending = rx_queue->rx_ring_size; |
| 451 | rvals->rx_jumbo_pending = rx_queue->rx_ring_size; |
| 452 | rvals->tx_pending = tx_queue->tx_ring_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /* Change the current ring parameters, stopping the controller if |
| 456 | * necessary so that we don't mess things up while we're in |
| 457 | * motion. We wait for the ring to be clean before reallocating |
| 458 | * the rings. */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 459 | static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 462 | int err = 0, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) |
| 465 | return -EINVAL; |
| 466 | |
| 467 | if (!is_power_of_2(rvals->rx_pending)) { |
| 468 | printk("%s: Ring sizes must be a power of 2\n", |
| 469 | dev->name); |
| 470 | return -EINVAL; |
| 471 | } |
| 472 | |
| 473 | if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE) |
| 474 | return -EINVAL; |
| 475 | |
| 476 | if (!is_power_of_2(rvals->tx_pending)) { |
| 477 | printk("%s: Ring sizes must be a power of 2\n", |
| 478 | dev->name); |
| 479 | return -EINVAL; |
| 480 | } |
| 481 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | if (dev->flags & IFF_UP) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 484 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 486 | /* Halt TX and RX, and process the frames which |
| 487 | * have already been received */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 488 | local_irq_save(flags); |
| 489 | lock_tx_qs(priv); |
| 490 | lock_rx_qs(priv); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 491 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 492 | gfar_halt(dev); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 493 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 494 | unlock_rx_qs(priv); |
| 495 | unlock_tx_qs(priv); |
| 496 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 498 | for (i = 0; i < priv->num_rx_queues; i++) |
| 499 | gfar_clean_rx_ring(priv->rx_queue[i], |
| 500 | priv->rx_queue[i]->rx_ring_size); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 501 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 502 | /* Now we take down the rings to rebuild them */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | stop_gfar(dev); |
| 504 | } |
| 505 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 506 | /* Change the size */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 507 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 508 | priv->rx_queue[i]->rx_ring_size = rvals->rx_pending; |
| 509 | priv->tx_queue[i]->tx_ring_size = rvals->tx_pending; |
| 510 | priv->tx_queue[i]->num_txbdfree = priv->tx_queue[i]->tx_ring_size; |
| 511 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 513 | /* Rebuild the rings with the new size */ |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 514 | if (dev->flags & IFF_UP) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 515 | err = startup_gfar(dev); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 516 | netif_tx_wake_all_queues(dev); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 517 | } |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 518 | return err; |
| 519 | } |
| 520 | |
| 521 | static int gfar_set_rx_csum(struct net_device *dev, uint32_t data) |
| 522 | { |
| 523 | struct gfar_private *priv = netdev_priv(dev); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 524 | unsigned long flags; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 525 | int err = 0, i = 0; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 526 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 527 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 528 | return -EOPNOTSUPP; |
| 529 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 530 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 531 | if (dev->flags & IFF_UP) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 532 | /* Halt TX and RX, and process the frames which |
| 533 | * have already been received */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 534 | local_irq_save(flags); |
| 535 | lock_tx_qs(priv); |
| 536 | lock_rx_qs(priv); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 537 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 538 | gfar_halt(dev); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 539 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 540 | unlock_tx_qs(priv); |
| 541 | unlock_rx_qs(priv); |
| 542 | local_irq_save(flags); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 543 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 544 | for (i = 0; i < priv->num_rx_queues; i++) |
| 545 | gfar_clean_rx_ring(priv->rx_queue[i], |
| 546 | priv->rx_queue[i]->rx_ring_size); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 547 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 548 | /* Now we take down the rings to rebuild them */ |
| 549 | stop_gfar(dev); |
| 550 | } |
| 551 | |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 552 | spin_lock_irqsave(&priv->bflock, flags); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 553 | priv->rx_csum_enable = data; |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 554 | spin_unlock_irqrestore(&priv->bflock, flags); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 555 | |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 556 | if (dev->flags & IFF_UP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | err = startup_gfar(dev); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 558 | netif_tx_wake_all_queues(dev); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | return err; |
| 561 | } |
| 562 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 563 | static uint32_t gfar_get_rx_csum(struct net_device *dev) |
| 564 | { |
| 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 0; |
| 569 | |
| 570 | return priv->rx_csum_enable; |
| 571 | } |
| 572 | |
| 573 | static int gfar_set_tx_csum(struct net_device *dev, uint32_t data) |
| 574 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 575 | struct gfar_private *priv = netdev_priv(dev); |
| 576 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 577 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 578 | return -EOPNOTSUPP; |
| 579 | |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 580 | netif_tx_lock_bh(dev); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 581 | |
| 582 | if (data) |
| 583 | dev->features |= NETIF_F_IP_CSUM; |
| 584 | else |
| 585 | dev->features &= ~NETIF_F_IP_CSUM; |
| 586 | |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 587 | netif_tx_unlock_bh(dev); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | static uint32_t gfar_get_tx_csum(struct net_device *dev) |
| 593 | { |
| 594 | struct gfar_private *priv = netdev_priv(dev); |
| 595 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 596 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 597 | return 0; |
| 598 | |
| 599 | return (dev->features & NETIF_F_IP_CSUM) != 0; |
| 600 | } |
| 601 | |
| 602 | static uint32_t gfar_get_msglevel(struct net_device *dev) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 603 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 604 | struct gfar_private *priv = netdev_priv(dev); |
| 605 | return priv->msg_enable; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 606 | } |
| 607 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 608 | static void gfar_set_msglevel(struct net_device *dev, uint32_t data) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 609 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 610 | struct gfar_private *priv = netdev_priv(dev); |
| 611 | priv->msg_enable = data; |
| 612 | } |
| 613 | |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 614 | #ifdef CONFIG_PM |
| 615 | static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 616 | { |
| 617 | struct gfar_private *priv = netdev_priv(dev); |
| 618 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 619 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) { |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 620 | wol->supported = WAKE_MAGIC; |
| 621 | wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0; |
| 622 | } else { |
| 623 | wol->supported = wol->wolopts = 0; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 628 | { |
| 629 | struct gfar_private *priv = netdev_priv(dev); |
| 630 | unsigned long flags; |
| 631 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 632 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) && |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 633 | wol->wolopts != 0) |
| 634 | return -EINVAL; |
| 635 | |
| 636 | if (wol->wolopts & ~WAKE_MAGIC) |
| 637 | return -EINVAL; |
| 638 | |
| 639 | spin_lock_irqsave(&priv->bflock, flags); |
| 640 | priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0; |
Anton Vorontsov | 2884e5c | 2009-02-01 00:52:34 -0800 | [diff] [blame] | 641 | device_set_wakeup_enable(&dev->dev, priv->wol_en); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 642 | spin_unlock_irqrestore(&priv->bflock, flags); |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | #endif |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 647 | |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame^] | 648 | static int gfar_ethflow_to_class(int flow_type, u64 *class) |
| 649 | { |
| 650 | switch (flow_type) { |
| 651 | case TCP_V4_FLOW: |
| 652 | *class = CLASS_CODE_TCP_IPV4; |
| 653 | break; |
| 654 | case UDP_V4_FLOW: |
| 655 | *class = CLASS_CODE_UDP_IPV4; |
| 656 | break; |
| 657 | case AH_V4_FLOW: |
| 658 | case ESP_V4_FLOW: |
| 659 | *class = CLASS_CODE_AH_ESP_IPV4; |
| 660 | break; |
| 661 | case SCTP_V4_FLOW: |
| 662 | *class = CLASS_CODE_SCTP_IPV4; |
| 663 | break; |
| 664 | case TCP_V6_FLOW: |
| 665 | *class = CLASS_CODE_TCP_IPV6; |
| 666 | break; |
| 667 | case UDP_V6_FLOW: |
| 668 | *class = CLASS_CODE_UDP_IPV6; |
| 669 | break; |
| 670 | case AH_V6_FLOW: |
| 671 | case ESP_V6_FLOW: |
| 672 | *class = CLASS_CODE_AH_ESP_IPV6; |
| 673 | break; |
| 674 | case SCTP_V6_FLOW: |
| 675 | *class = CLASS_CODE_SCTP_IPV6; |
| 676 | break; |
| 677 | default: |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | return 1; |
| 682 | } |
| 683 | |
| 684 | static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow) |
| 685 | { |
| 686 | u32 fcr = 0x0, fpr = FPR_FILER_MASK; |
| 687 | |
| 688 | if (ethflow & RXH_L2DA) { |
| 689 | fcr = RQFCR_PID_DAH |RQFCR_CMP_NOMATCH | |
| 690 | RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0; |
| 691 | ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 692 | ftp_rqfcr[priv->cur_filer_idx] = fcr; |
| 693 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 694 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 695 | |
| 696 | fcr = RQFCR_PID_DAL | RQFCR_AND | RQFCR_CMP_NOMATCH | |
| 697 | RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0; |
| 698 | ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 699 | ftp_rqfcr[priv->cur_filer_idx] = fcr; |
| 700 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 701 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 702 | } |
| 703 | |
| 704 | if (ethflow & RXH_VLAN) { |
| 705 | fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
| 706 | RQFCR_AND | RQFCR_HASHTBL_0; |
| 707 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 708 | ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 709 | ftp_rqfcr[priv->cur_filer_idx] = fcr; |
| 710 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 711 | } |
| 712 | |
| 713 | if (ethflow & RXH_IP_SRC) { |
| 714 | fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
| 715 | RQFCR_AND | RQFCR_HASHTBL_0; |
| 716 | ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 717 | ftp_rqfcr[priv->cur_filer_idx] = fcr; |
| 718 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 719 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 720 | } |
| 721 | |
| 722 | if (ethflow & (RXH_IP_DST)) { |
| 723 | fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
| 724 | RQFCR_AND | RQFCR_HASHTBL_0; |
| 725 | ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 726 | ftp_rqfcr[priv->cur_filer_idx] = fcr; |
| 727 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 728 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 729 | } |
| 730 | |
| 731 | if (ethflow & RXH_L3_PROTO) { |
| 732 | fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
| 733 | RQFCR_AND | RQFCR_HASHTBL_0; |
| 734 | ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 735 | ftp_rqfcr[priv->cur_filer_idx] = fcr; |
| 736 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 737 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 738 | } |
| 739 | |
| 740 | if (ethflow & RXH_L4_B_0_1) { |
| 741 | fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
| 742 | RQFCR_AND | RQFCR_HASHTBL_0; |
| 743 | ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 744 | ftp_rqfcr[priv->cur_filer_idx] = fcr; |
| 745 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 746 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 747 | } |
| 748 | |
| 749 | if (ethflow & RXH_L4_B_2_3) { |
| 750 | fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
| 751 | RQFCR_AND | RQFCR_HASHTBL_0; |
| 752 | ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 753 | ftp_rqfcr[priv->cur_filer_idx] = fcr; |
| 754 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 755 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u64 class) |
| 760 | { |
| 761 | unsigned int last_rule_idx = priv->cur_filer_idx; |
| 762 | unsigned int cmp_rqfpr; |
| 763 | unsigned int local_rqfpr[MAX_FILER_IDX + 1]; |
| 764 | unsigned int local_rqfcr[MAX_FILER_IDX + 1]; |
| 765 | int i = 0x0, k = 0x0; |
| 766 | int j = MAX_FILER_IDX, l = 0x0; |
| 767 | |
| 768 | switch (class) { |
| 769 | case TCP_V4_FLOW: |
| 770 | cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP; |
| 771 | break; |
| 772 | case UDP_V4_FLOW: |
| 773 | cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP; |
| 774 | break; |
| 775 | case TCP_V6_FLOW: |
| 776 | cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP; |
| 777 | break; |
| 778 | case UDP_V6_FLOW: |
| 779 | cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP; |
| 780 | break; |
| 781 | case IPV4_FLOW: |
| 782 | cmp_rqfpr = RQFPR_IPV4; |
| 783 | case IPV6_FLOW: |
| 784 | cmp_rqfpr = RQFPR_IPV6; |
| 785 | break; |
| 786 | default: |
| 787 | printk(KERN_ERR "Right now this class is not supported\n"); |
| 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | for (i = 0; i < MAX_FILER_IDX + 1; i++) { |
| 792 | local_rqfpr[j] = ftp_rqfpr[i]; |
| 793 | local_rqfcr[j] = ftp_rqfcr[i]; |
| 794 | j--; |
| 795 | if ((ftp_rqfcr[i] == (RQFCR_PID_PARSE | |
| 796 | RQFCR_CLE |RQFCR_AND)) && |
| 797 | (ftp_rqfpr[i] == cmp_rqfpr)) |
| 798 | break; |
| 799 | } |
| 800 | |
| 801 | if (i == MAX_FILER_IDX + 1) { |
| 802 | printk(KERN_ERR "No parse rule found, "); |
| 803 | printk(KERN_ERR "can't create hash rules\n"); |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | /* If a match was found, then it begins the starting of a cluster rule |
| 808 | * if it was already programmed, we need to overwrite these rules |
| 809 | */ |
| 810 | for (l = i+1; l < MAX_FILER_IDX; l++) { |
| 811 | if ((ftp_rqfcr[l] & RQFCR_CLE) && |
| 812 | !(ftp_rqfcr[l] & RQFCR_AND)) { |
| 813 | ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT | |
| 814 | RQFCR_HASHTBL_0 | RQFCR_PID_MASK; |
| 815 | ftp_rqfpr[l] = FPR_FILER_MASK; |
| 816 | gfar_write_filer(priv, l, ftp_rqfcr[l], ftp_rqfpr[l]); |
| 817 | break; |
| 818 | } |
| 819 | |
| 820 | if (!(ftp_rqfcr[l] & RQFCR_CLE) && (ftp_rqfcr[l] & RQFCR_AND)) |
| 821 | continue; |
| 822 | else { |
| 823 | local_rqfpr[j] = ftp_rqfpr[l]; |
| 824 | local_rqfcr[j] = ftp_rqfcr[l]; |
| 825 | j--; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | priv->cur_filer_idx = l - 1; |
| 830 | last_rule_idx = l; |
| 831 | |
| 832 | /* hash rules */ |
| 833 | ethflow_to_filer_rules(priv, ethflow); |
| 834 | |
| 835 | /* Write back the popped out rules again */ |
| 836 | for (k = j+1; k < MAX_FILER_IDX; k++) { |
| 837 | ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k]; |
| 838 | ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k]; |
| 839 | gfar_write_filer(priv, priv->cur_filer_idx, |
| 840 | local_rqfcr[k], local_rqfpr[k]); |
| 841 | if (!priv->cur_filer_idx) |
| 842 | break; |
| 843 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 844 | } |
| 845 | |
| 846 | return 1; |
| 847 | } |
| 848 | |
| 849 | static int gfar_set_hash_opts(struct gfar_private *priv, struct ethtool_rxnfc *cmd) |
| 850 | { |
| 851 | u64 class; |
| 852 | |
| 853 | if (!gfar_ethflow_to_class(cmd->flow_type, &class)) |
| 854 | return -EINVAL; |
| 855 | |
| 856 | if (class < CLASS_CODE_USER_PROG1 || |
| 857 | class > CLASS_CODE_SCTP_IPV6) |
| 858 | return -EINVAL; |
| 859 | |
| 860 | /* write the filer rules here */ |
| 861 | if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type)) |
| 862 | return -1; |
| 863 | |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd) |
| 868 | { |
| 869 | struct gfar_private *priv = netdev_priv(dev); |
| 870 | int ret = 0; |
| 871 | |
| 872 | switch(cmd->cmd) { |
| 873 | case ETHTOOL_SRXFH: |
| 874 | ret = gfar_set_hash_opts(priv, cmd); |
| 875 | break; |
| 876 | default: |
| 877 | ret = -EINVAL; |
| 878 | } |
| 879 | |
| 880 | return ret; |
| 881 | } |
| 882 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 883 | const struct ethtool_ops gfar_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | .get_settings = gfar_gsettings, |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 885 | .set_settings = gfar_ssettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | .get_drvinfo = gfar_gdrvinfo, |
| 887 | .get_regs_len = gfar_reglen, |
| 888 | .get_regs = gfar_get_regs, |
| 889 | .get_link = ethtool_op_get_link, |
| 890 | .get_coalesce = gfar_gcoalesce, |
| 891 | .set_coalesce = gfar_scoalesce, |
| 892 | .get_ringparam = gfar_gringparam, |
| 893 | .set_ringparam = gfar_sringparam, |
| 894 | .get_strings = gfar_gstrings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 895 | .get_sset_count = gfar_sset_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | .get_ethtool_stats = gfar_fill_stats, |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 897 | .get_rx_csum = gfar_get_rx_csum, |
| 898 | .get_tx_csum = gfar_get_tx_csum, |
| 899 | .set_rx_csum = gfar_set_rx_csum, |
| 900 | .set_tx_csum = gfar_set_tx_csum, |
Dai Haruki | 4669bc9 | 2008-12-17 16:51:04 -0800 | [diff] [blame] | 901 | .set_sg = ethtool_op_set_sg, |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 902 | .get_msglevel = gfar_get_msglevel, |
| 903 | .set_msglevel = gfar_set_msglevel, |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 904 | #ifdef CONFIG_PM |
| 905 | .get_wol = gfar_get_wol, |
| 906 | .set_wol = gfar_set_wol, |
| 907 | #endif |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame^] | 908 | .set_rxnfc = gfar_set_nfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | }; |