Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Gortmaker | 3396c78 | 2012-01-27 13:36:01 +0000 | [diff] [blame] | 2 | * drivers/net/ethernet/freescale/gianfar_ethtool.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 12 | * Copyright 2003-2006, 2008-2009, 2011 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 | |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/string.h> |
| 23 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
David S. Miller | 65a85a8 | 2012-04-06 00:35:34 -0400 | [diff] [blame] | 29 | #include <linux/net_tstamp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/skbuff.h> |
| 31 | #include <linux/spinlock.h> |
| 32 | #include <linux/mm.h> |
| 33 | |
| 34 | #include <asm/io.h> |
| 35 | #include <asm/irq.h> |
| 36 | #include <asm/uaccess.h> |
| 37 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/crc32.h> |
| 39 | #include <asm/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 43 | #include <linux/sort.h> |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 44 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #include "gianfar.h" |
| 47 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 48 | extern void gfar_start(struct net_device *dev); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 49 | extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, |
| 50 | int rx_work_limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 52 | #define GFAR_MAX_COAL_USECS 0xffff |
| 53 | #define GFAR_MAX_COAL_FRAMES 0xff |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 54 | static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 55 | u64 *buf); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 56 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 57 | static int gfar_gcoalesce(struct net_device *dev, |
| 58 | struct ethtool_coalesce *cvals); |
| 59 | static int gfar_scoalesce(struct net_device *dev, |
| 60 | struct ethtool_coalesce *cvals); |
| 61 | static void gfar_gringparam(struct net_device *dev, |
| 62 | struct ethtool_ringparam *rvals); |
| 63 | static int gfar_sringparam(struct net_device *dev, |
| 64 | struct ethtool_ringparam *rvals); |
| 65 | static void gfar_gdrvinfo(struct net_device *dev, |
| 66 | struct ethtool_drvinfo *drvinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Paul Gortmaker | 30f7e31 | 2012-01-08 13:21:57 -0500 | [diff] [blame] | 68 | static const char stat_gstrings[][ETH_GSTRING_LEN] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | "rx-dropped-by-kernel", |
| 70 | "rx-large-frame-errors", |
| 71 | "rx-short-frame-errors", |
| 72 | "rx-non-octet-errors", |
| 73 | "rx-crc-errors", |
| 74 | "rx-overrun-errors", |
| 75 | "rx-busy-errors", |
| 76 | "rx-babbling-errors", |
| 77 | "rx-truncated-frames", |
| 78 | "ethernet-bus-error", |
| 79 | "tx-babbling-errors", |
| 80 | "tx-underrun-errors", |
| 81 | "rx-skb-missing-errors", |
| 82 | "tx-timeout-errors", |
| 83 | "tx-rx-64-frames", |
| 84 | "tx-rx-65-127-frames", |
| 85 | "tx-rx-128-255-frames", |
| 86 | "tx-rx-256-511-frames", |
| 87 | "tx-rx-512-1023-frames", |
| 88 | "tx-rx-1024-1518-frames", |
| 89 | "tx-rx-1519-1522-good-vlan", |
| 90 | "rx-bytes", |
| 91 | "rx-packets", |
| 92 | "rx-fcs-errors", |
| 93 | "receive-multicast-packet", |
| 94 | "receive-broadcast-packet", |
| 95 | "rx-control-frame-packets", |
| 96 | "rx-pause-frame-packets", |
| 97 | "rx-unknown-op-code", |
| 98 | "rx-alignment-error", |
| 99 | "rx-frame-length-error", |
| 100 | "rx-code-error", |
| 101 | "rx-carrier-sense-error", |
| 102 | "rx-undersize-packets", |
| 103 | "rx-oversize-packets", |
| 104 | "rx-fragmented-frames", |
| 105 | "rx-jabber-frames", |
| 106 | "rx-dropped-frames", |
| 107 | "tx-byte-counter", |
| 108 | "tx-packets", |
| 109 | "tx-multicast-packets", |
| 110 | "tx-broadcast-packets", |
| 111 | "tx-pause-control-frames", |
| 112 | "tx-deferral-packets", |
| 113 | "tx-excessive-deferral-packets", |
| 114 | "tx-single-collision-packets", |
| 115 | "tx-multiple-collision-packets", |
| 116 | "tx-late-collision-packets", |
| 117 | "tx-excessive-collision-packets", |
| 118 | "tx-total-collision", |
| 119 | "reserved", |
| 120 | "tx-dropped-frames", |
| 121 | "tx-jabber-frames", |
| 122 | "tx-fcs-errors", |
| 123 | "tx-control-frames", |
| 124 | "tx-oversize-frames", |
| 125 | "tx-undersize-frames", |
| 126 | "tx-fragmented-frames", |
| 127 | }; |
| 128 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 129 | /* Fill in a buffer with the strings which correspond to the |
| 130 | * stats */ |
| 131 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf) |
| 132 | { |
| 133 | struct gfar_private *priv = netdev_priv(dev); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 134 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 135 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 136 | memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN); |
| 137 | else |
| 138 | memcpy(buf, stat_gstrings, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 139 | GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Fill in an array of 64-bit statistics from various sources. |
| 143 | * This array will be appended to the end of the ethtool_stats |
| 144 | * structure, and returned to user space |
| 145 | */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 146 | static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, |
| 147 | u64 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
| 149 | int i; |
| 150 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 151 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | u64 *extra = (u64 *) & priv->extra_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 154 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 155 | u32 __iomem *rmon = (u32 __iomem *) ®s->rmon; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 156 | struct gfar_stats *stats = (struct gfar_stats *) buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 158 | for (i = 0; i < GFAR_RMON_LEN; i++) |
Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 159 | stats->rmon[i] = (u64) gfar_read(&rmon[i]); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 160 | |
| 161 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) |
| 162 | stats->extra[i] = extra[i]; |
| 163 | } else |
| 164 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) |
| 165 | buf[i] = extra[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 168 | static int gfar_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | struct gfar_private *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 172 | switch (sset) { |
| 173 | case ETH_SS_STATS: |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 174 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 175 | return GFAR_STATS_LEN; |
| 176 | else |
| 177 | return GFAR_EXTRA_STATS_LEN; |
| 178 | default: |
| 179 | return -EOPNOTSUPP; |
| 180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | /* Fills in the drvinfo structure with some basic info */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 184 | static void gfar_gdrvinfo(struct net_device *dev, |
| 185 | struct ethtool_drvinfo *drvinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { |
| 187 | strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN); |
| 188 | strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN); |
| 189 | strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN); |
| 190 | strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | drvinfo->regdump_len = 0; |
| 192 | drvinfo->eedump_len = 0; |
| 193 | } |
| 194 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 195 | |
| 196 | static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 197 | { |
| 198 | struct gfar_private *priv = netdev_priv(dev); |
| 199 | struct phy_device *phydev = priv->phydev; |
| 200 | |
| 201 | if (NULL == phydev) |
| 202 | return -ENODEV; |
| 203 | |
| 204 | return phy_ethtool_sset(phydev, cmd); |
| 205 | } |
| 206 | |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* Return the current settings in the ethtool_cmd structure */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 209 | static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
| 211 | struct gfar_private *priv = netdev_priv(dev); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 212 | struct phy_device *phydev = priv->phydev; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 213 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 214 | struct gfar_priv_tx_q *tx_queue = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 216 | if (NULL == phydev) |
| 217 | return -ENODEV; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 218 | tx_queue = priv->tx_queue[0]; |
| 219 | rx_queue = priv->rx_queue[0]; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 220 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 221 | /* etsec-1.7 and older versions have only one txic |
| 222 | * and rxic regs although they support multiple queues */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 223 | cmd->maxtxpkt = get_icft_value(tx_queue->txic); |
| 224 | cmd->maxrxpkt = get_icft_value(rx_queue->rxic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 226 | return phy_ethtool_gset(phydev, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* Return the length of the register structure */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 230 | static int gfar_reglen(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
| 232 | return sizeof (struct gfar); |
| 233 | } |
| 234 | |
| 235 | /* Return a dump of the GFAR register space */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 236 | static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 237 | void *regbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | int i; |
| 240 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 241 | u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp[0].regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | u32 *buf = (u32 *) regbuf; |
| 243 | |
| 244 | for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++) |
Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 245 | buf[i] = gfar_read(&theregs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | /* Convert microseconds to ethernet clock ticks, which changes |
| 249 | * depending on what speed the controller is running at */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 250 | static unsigned int gfar_usecs2ticks(struct gfar_private *priv, |
| 251 | unsigned int usecs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
| 253 | unsigned int count; |
| 254 | |
| 255 | /* The timer is different, depending on the interface speed */ |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 256 | switch (priv->phydev->speed) { |
| 257 | case SPEED_1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | count = GFAR_GBIT_TIME; |
| 259 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 260 | case SPEED_100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | count = GFAR_100_TIME; |
| 262 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 263 | case SPEED_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | default: |
| 265 | count = GFAR_10_TIME; |
| 266 | break; |
| 267 | } |
| 268 | |
| 269 | /* Make sure we return a number greater than 0 |
| 270 | * if usecs > 0 */ |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 271 | return (usecs * 1000 + count - 1) / count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* Convert ethernet clock ticks to microseconds */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 275 | static unsigned int gfar_ticks2usecs(struct gfar_private *priv, |
| 276 | unsigned int ticks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
| 278 | unsigned int count; |
| 279 | |
| 280 | /* The timer is different, depending on the interface speed */ |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 281 | switch (priv->phydev->speed) { |
| 282 | case SPEED_1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | count = GFAR_GBIT_TIME; |
| 284 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 285 | case SPEED_100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | count = GFAR_100_TIME; |
| 287 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 288 | case SPEED_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | default: |
| 290 | count = GFAR_10_TIME; |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | /* Make sure we return a number greater than 0 */ |
| 295 | /* if ticks is > 0 */ |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 296 | return (ticks * count) / 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* Get the coalescing parameters, and put them in the cvals |
| 300 | * structure. */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 301 | static int gfar_gcoalesce(struct net_device *dev, |
| 302 | struct ethtool_coalesce *cvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
| 304 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 305 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 306 | struct gfar_priv_tx_q *tx_queue = NULL; |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 307 | unsigned long rxtime; |
| 308 | unsigned long rxcount; |
| 309 | unsigned long txtime; |
| 310 | unsigned long txcount; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 311 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 312 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 313 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 315 | if (NULL == priv->phydev) |
| 316 | return -ENODEV; |
| 317 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 318 | rx_queue = priv->rx_queue[0]; |
| 319 | tx_queue = priv->tx_queue[0]; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 320 | |
| 321 | rxtime = get_ictt_value(rx_queue->rxic); |
| 322 | rxcount = get_icft_value(rx_queue->rxic); |
| 323 | txtime = get_ictt_value(tx_queue->txic); |
| 324 | txcount = get_icft_value(tx_queue->txic); |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 325 | cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime); |
| 326 | cvals->rx_max_coalesced_frames = rxcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 328 | cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime); |
| 329 | cvals->tx_max_coalesced_frames = txcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | cvals->use_adaptive_rx_coalesce = 0; |
| 332 | cvals->use_adaptive_tx_coalesce = 0; |
| 333 | |
| 334 | cvals->pkt_rate_low = 0; |
| 335 | cvals->rx_coalesce_usecs_low = 0; |
| 336 | cvals->rx_max_coalesced_frames_low = 0; |
| 337 | cvals->tx_coalesce_usecs_low = 0; |
| 338 | cvals->tx_max_coalesced_frames_low = 0; |
| 339 | |
| 340 | /* When the packet rate is below pkt_rate_high but above |
| 341 | * pkt_rate_low (both measured in packets per second) the |
| 342 | * normal {rx,tx}_* coalescing parameters are used. |
| 343 | */ |
| 344 | |
| 345 | /* When the packet rate is (measured in packets per second) |
| 346 | * is above pkt_rate_high, the {rx,tx}_*_high parameters are |
| 347 | * used. |
| 348 | */ |
| 349 | cvals->pkt_rate_high = 0; |
| 350 | cvals->rx_coalesce_usecs_high = 0; |
| 351 | cvals->rx_max_coalesced_frames_high = 0; |
| 352 | cvals->tx_coalesce_usecs_high = 0; |
| 353 | cvals->tx_max_coalesced_frames_high = 0; |
| 354 | |
| 355 | /* How often to do adaptive coalescing packet rate sampling, |
| 356 | * measured in seconds. Must not be zero. |
| 357 | */ |
| 358 | cvals->rate_sample_interval = 0; |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | /* Change the coalescing values. |
| 364 | * Both cvals->*_usecs and cvals->*_frames have to be > 0 |
| 365 | * in order for coalescing to be active |
| 366 | */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 367 | static int gfar_scoalesce(struct net_device *dev, |
| 368 | struct ethtool_coalesce *cvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { |
| 370 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 371 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 373 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 374 | return -EOPNOTSUPP; |
| 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | /* Set up rx coalescing */ |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 377 | /* As of now, we will enable/disable coalescing for all |
| 378 | * queues together in case of eTSEC2, this will be modified |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 379 | * along with the ethtool interface |
| 380 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | if ((cvals->rx_coalesce_usecs == 0) || |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 382 | (cvals->rx_max_coalesced_frames == 0)) { |
| 383 | for (i = 0; i < priv->num_rx_queues; i++) |
| 384 | priv->rx_queue[i]->rxcoalescing = 0; |
| 385 | } else { |
| 386 | for (i = 0; i < priv->num_rx_queues; i++) |
| 387 | priv->rx_queue[i]->rxcoalescing = 1; |
| 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 390 | if (NULL == priv->phydev) |
| 391 | return -ENODEV; |
| 392 | |
| 393 | /* Check the bounds of the values */ |
| 394 | if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) { |
| 395 | pr_info("Coalescing is limited to %d microseconds\n", |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 396 | GFAR_MAX_COAL_USECS); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 397 | return -EINVAL; |
| 398 | } |
| 399 | |
| 400 | if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { |
| 401 | pr_info("Coalescing is limited to %d frames\n", |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 402 | GFAR_MAX_COAL_FRAMES); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 403 | return -EINVAL; |
| 404 | } |
| 405 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 406 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 407 | priv->rx_queue[i]->rxic = mk_ic_value( |
| 408 | cvals->rx_max_coalesced_frames, |
| 409 | gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs)); |
| 410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | /* Set up tx coalescing */ |
| 413 | if ((cvals->tx_coalesce_usecs == 0) || |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 414 | (cvals->tx_max_coalesced_frames == 0)) { |
| 415 | for (i = 0; i < priv->num_tx_queues; i++) |
| 416 | priv->tx_queue[i]->txcoalescing = 0; |
| 417 | } else { |
| 418 | for (i = 0; i < priv->num_tx_queues; i++) |
| 419 | priv->tx_queue[i]->txcoalescing = 1; |
| 420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 422 | /* Check the bounds of the values */ |
| 423 | if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) { |
| 424 | pr_info("Coalescing is limited to %d microseconds\n", |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 425 | GFAR_MAX_COAL_USECS); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 426 | return -EINVAL; |
| 427 | } |
| 428 | |
| 429 | if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { |
| 430 | pr_info("Coalescing is limited to %d frames\n", |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 431 | GFAR_MAX_COAL_FRAMES); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 432 | return -EINVAL; |
| 433 | } |
| 434 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 435 | for (i = 0; i < priv->num_tx_queues; i++) { |
| 436 | priv->tx_queue[i]->txic = mk_ic_value( |
| 437 | cvals->tx_max_coalesced_frames, |
| 438 | gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs)); |
| 439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 441 | gfar_configure_coalescing(priv, 0xFF, 0xFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | /* Fills in rvals with the current ring parameters. Currently, |
| 447 | * rx, rx_mini, and rx_jumbo rings are the same size, as mini and |
| 448 | * jumbo are ignored by the driver */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 449 | static void gfar_gringparam(struct net_device *dev, |
| 450 | struct ethtool_ringparam *rvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | { |
| 452 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 453 | struct gfar_priv_tx_q *tx_queue = NULL; |
| 454 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 455 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 456 | tx_queue = priv->tx_queue[0]; |
| 457 | rx_queue = priv->rx_queue[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 460 | rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 461 | rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 462 | rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE; |
| 463 | |
| 464 | /* Values changeable by the user. The valid values are |
| 465 | * in the range 1 to the "*_max_pending" counterpart above. |
| 466 | */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 467 | rvals->rx_pending = rx_queue->rx_ring_size; |
| 468 | rvals->rx_mini_pending = rx_queue->rx_ring_size; |
| 469 | rvals->rx_jumbo_pending = rx_queue->rx_ring_size; |
| 470 | rvals->tx_pending = tx_queue->tx_ring_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /* Change the current ring parameters, stopping the controller if |
| 474 | * necessary so that we don't mess things up while we're in |
| 475 | * motion. We wait for the ring to be clean before reallocating |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 476 | * the rings. |
| 477 | */ |
| 478 | static int gfar_sringparam(struct net_device *dev, |
| 479 | struct ethtool_ringparam *rvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 482 | int err = 0, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) |
| 485 | return -EINVAL; |
| 486 | |
| 487 | if (!is_power_of_2(rvals->rx_pending)) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 488 | netdev_err(dev, "Ring sizes must be a power of 2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | return -EINVAL; |
| 490 | } |
| 491 | |
| 492 | if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE) |
| 493 | return -EINVAL; |
| 494 | |
| 495 | if (!is_power_of_2(rvals->tx_pending)) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 496 | netdev_err(dev, "Ring sizes must be a power of 2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return -EINVAL; |
| 498 | } |
| 499 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | if (dev->flags & IFF_UP) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 502 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 504 | /* Halt TX and RX, and process the frames which |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 505 | * have already been received |
| 506 | */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 507 | local_irq_save(flags); |
| 508 | lock_tx_qs(priv); |
| 509 | lock_rx_qs(priv); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 510 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 511 | gfar_halt(dev); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 512 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 513 | unlock_rx_qs(priv); |
| 514 | unlock_tx_qs(priv); |
| 515 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 517 | for (i = 0; i < priv->num_rx_queues; i++) |
| 518 | gfar_clean_rx_ring(priv->rx_queue[i], |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 519 | priv->rx_queue[i]->rx_ring_size); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 520 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 521 | /* Now we take down the rings to rebuild them */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | stop_gfar(dev); |
| 523 | } |
| 524 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 525 | /* Change the size */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 526 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 527 | priv->rx_queue[i]->rx_ring_size = rvals->rx_pending; |
| 528 | priv->tx_queue[i]->tx_ring_size = rvals->tx_pending; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 529 | priv->tx_queue[i]->num_txbdfree = |
| 530 | priv->tx_queue[i]->tx_ring_size; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 531 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 533 | /* Rebuild the rings with the new size */ |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 534 | if (dev->flags & IFF_UP) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 535 | err = startup_gfar(dev); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 536 | netif_tx_wake_all_queues(dev); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 537 | } |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 538 | return err; |
| 539 | } |
| 540 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 541 | int gfar_set_features(struct net_device *dev, netdev_features_t features) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 542 | { |
| 543 | struct gfar_private *priv = netdev_priv(dev); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 544 | unsigned long flags; |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 545 | int err = 0, i = 0; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 546 | netdev_features_t changed = dev->features ^ features; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 547 | |
Jiri Pirko | 87c288c | 2011-07-20 04:54:19 +0000 | [diff] [blame] | 548 | if (changed & (NETIF_F_HW_VLAN_TX|NETIF_F_HW_VLAN_RX)) |
| 549 | gfar_vlan_mode(dev, features); |
| 550 | |
Michał Mirosław | 8b3afe9 | 2011-04-15 04:50:50 +0000 | [diff] [blame] | 551 | if (!(changed & NETIF_F_RXCSUM)) |
| 552 | return 0; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 553 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 554 | if (dev->flags & IFF_UP) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 555 | /* Halt TX and RX, and process the frames which |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 556 | * have already been received |
| 557 | */ |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 558 | local_irq_save(flags); |
| 559 | lock_tx_qs(priv); |
| 560 | lock_rx_qs(priv); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 561 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 562 | gfar_halt(dev); |
Andy Fleming | fef6108 | 2006-04-20 16:44:29 -0500 | [diff] [blame] | 563 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 564 | unlock_tx_qs(priv); |
| 565 | unlock_rx_qs(priv); |
Dan Carpenter | 9756403 | 2010-10-13 09:19:55 +0000 | [diff] [blame] | 566 | local_irq_restore(flags); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 567 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 568 | for (i = 0; i < priv->num_rx_queues; i++) |
| 569 | gfar_clean_rx_ring(priv->rx_queue[i], |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 570 | priv->rx_queue[i]->rx_ring_size); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 571 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 572 | /* Now we take down the rings to rebuild them */ |
| 573 | stop_gfar(dev); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 574 | |
Michał Mirosław | 8b3afe9 | 2011-04-15 04:50:50 +0000 | [diff] [blame] | 575 | dev->features = features; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | err = startup_gfar(dev); |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 578 | netif_tx_wake_all_queues(dev); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 579 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | return err; |
| 581 | } |
| 582 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 583 | static uint32_t gfar_get_msglevel(struct net_device *dev) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 584 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 585 | struct gfar_private *priv = netdev_priv(dev); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 586 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 587 | return priv->msg_enable; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 590 | static void gfar_set_msglevel(struct net_device *dev, uint32_t data) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 591 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 592 | struct gfar_private *priv = netdev_priv(dev); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 593 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 594 | priv->msg_enable = data; |
| 595 | } |
| 596 | |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 597 | #ifdef CONFIG_PM |
| 598 | static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 599 | { |
| 600 | struct gfar_private *priv = netdev_priv(dev); |
| 601 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 602 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) { |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 603 | wol->supported = WAKE_MAGIC; |
| 604 | wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0; |
| 605 | } else { |
| 606 | wol->supported = wol->wolopts = 0; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 611 | { |
| 612 | struct gfar_private *priv = netdev_priv(dev); |
| 613 | unsigned long flags; |
| 614 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 615 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) && |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 616 | wol->wolopts != 0) |
| 617 | return -EINVAL; |
| 618 | |
| 619 | if (wol->wolopts & ~WAKE_MAGIC) |
| 620 | return -EINVAL; |
| 621 | |
Rafael J. Wysocki | 6c4f199 | 2010-11-09 11:54:19 +0000 | [diff] [blame] | 622 | device_set_wakeup_enable(&dev->dev, wol->wolopts & WAKE_MAGIC); |
| 623 | |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 624 | spin_lock_irqsave(&priv->bflock, flags); |
Rafael J. Wysocki | 6c4f199 | 2010-11-09 11:54:19 +0000 | [diff] [blame] | 625 | priv->wol_en = !!device_may_wakeup(&dev->dev); |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 626 | spin_unlock_irqrestore(&priv->bflock, flags); |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | #endif |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 631 | |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 632 | static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow) |
| 633 | { |
| 634 | u32 fcr = 0x0, fpr = FPR_FILER_MASK; |
| 635 | |
| 636 | if (ethflow & RXH_L2DA) { |
| 637 | fcr = RQFCR_PID_DAH |RQFCR_CMP_NOMATCH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 638 | RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 639 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 640 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 641 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 642 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 643 | |
| 644 | fcr = RQFCR_PID_DAL | RQFCR_AND | RQFCR_CMP_NOMATCH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 645 | RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 646 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 647 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 648 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 649 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 650 | } |
| 651 | |
| 652 | if (ethflow & RXH_VLAN) { |
| 653 | fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 654 | RQFCR_AND | RQFCR_HASHTBL_0; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 655 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 656 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 657 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 658 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 659 | } |
| 660 | |
| 661 | if (ethflow & RXH_IP_SRC) { |
| 662 | fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 663 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 664 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 665 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 666 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 667 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 668 | } |
| 669 | |
| 670 | if (ethflow & (RXH_IP_DST)) { |
| 671 | fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 672 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 673 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 674 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 675 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 676 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 677 | } |
| 678 | |
| 679 | if (ethflow & RXH_L3_PROTO) { |
| 680 | fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 681 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 682 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 683 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 684 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 685 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 686 | } |
| 687 | |
| 688 | if (ethflow & RXH_L4_B_0_1) { |
| 689 | fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 690 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 691 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 692 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 693 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 694 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 695 | } |
| 696 | |
| 697 | if (ethflow & RXH_L4_B_2_3) { |
| 698 | fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 699 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 700 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 701 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 702 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 703 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 704 | } |
| 705 | } |
| 706 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 707 | static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, |
| 708 | u64 class) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 709 | { |
| 710 | unsigned int last_rule_idx = priv->cur_filer_idx; |
| 711 | unsigned int cmp_rqfpr; |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 712 | unsigned int *local_rqfpr; |
| 713 | unsigned int *local_rqfcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 714 | int i = 0x0, k = 0x0; |
| 715 | int j = MAX_FILER_IDX, l = 0x0; |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 716 | int ret = 1; |
| 717 | |
| 718 | local_rqfpr = kmalloc(sizeof(unsigned int) * (MAX_FILER_IDX + 1), |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 719 | GFP_KERNEL); |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 720 | local_rqfcr = kmalloc(sizeof(unsigned int) * (MAX_FILER_IDX + 1), |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 721 | GFP_KERNEL); |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 722 | if (!local_rqfpr || !local_rqfcr) { |
| 723 | pr_err("Out of memory\n"); |
| 724 | ret = 0; |
| 725 | goto err; |
| 726 | } |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 727 | |
| 728 | switch (class) { |
| 729 | case TCP_V4_FLOW: |
| 730 | cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP; |
| 731 | break; |
| 732 | case UDP_V4_FLOW: |
| 733 | cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP; |
| 734 | break; |
| 735 | case TCP_V6_FLOW: |
| 736 | cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP; |
| 737 | break; |
| 738 | case UDP_V6_FLOW: |
| 739 | cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP; |
| 740 | break; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 741 | default: |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 742 | pr_err("Right now this class is not supported\n"); |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 743 | ret = 0; |
| 744 | goto err; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | for (i = 0; i < MAX_FILER_IDX + 1; i++) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 748 | local_rqfpr[j] = priv->ftp_rqfpr[i]; |
| 749 | local_rqfcr[j] = priv->ftp_rqfcr[i]; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 750 | j--; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 751 | if ((priv->ftp_rqfcr[i] == |
| 752 | (RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND)) && |
| 753 | (priv->ftp_rqfpr[i] == cmp_rqfpr)) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 754 | break; |
| 755 | } |
| 756 | |
| 757 | if (i == MAX_FILER_IDX + 1) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 758 | pr_err("No parse rule found, can't create hash rules\n"); |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 759 | ret = 0; |
| 760 | goto err; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | /* If a match was found, then it begins the starting of a cluster rule |
| 764 | * if it was already programmed, we need to overwrite these rules |
| 765 | */ |
| 766 | for (l = i+1; l < MAX_FILER_IDX; l++) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 767 | if ((priv->ftp_rqfcr[l] & RQFCR_CLE) && |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 768 | !(priv->ftp_rqfcr[l] & RQFCR_AND)) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 769 | priv->ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 770 | RQFCR_HASHTBL_0 | RQFCR_PID_MASK; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 771 | priv->ftp_rqfpr[l] = FPR_FILER_MASK; |
| 772 | gfar_write_filer(priv, l, priv->ftp_rqfcr[l], |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 773 | priv->ftp_rqfpr[l]); |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 774 | break; |
| 775 | } |
| 776 | |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 777 | if (!(priv->ftp_rqfcr[l] & RQFCR_CLE) && |
| 778 | (priv->ftp_rqfcr[l] & RQFCR_AND)) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 779 | continue; |
| 780 | else { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 781 | local_rqfpr[j] = priv->ftp_rqfpr[l]; |
| 782 | local_rqfcr[j] = priv->ftp_rqfcr[l]; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 783 | j--; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | priv->cur_filer_idx = l - 1; |
| 788 | last_rule_idx = l; |
| 789 | |
| 790 | /* hash rules */ |
| 791 | ethflow_to_filer_rules(priv, ethflow); |
| 792 | |
| 793 | /* Write back the popped out rules again */ |
| 794 | for (k = j+1; k < MAX_FILER_IDX; k++) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 795 | priv->ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k]; |
| 796 | priv->ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k]; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 797 | gfar_write_filer(priv, priv->cur_filer_idx, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 798 | local_rqfcr[k], local_rqfpr[k]); |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 799 | if (!priv->cur_filer_idx) |
| 800 | break; |
| 801 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 802 | } |
| 803 | |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 804 | err: |
| 805 | kfree(local_rqfcr); |
| 806 | kfree(local_rqfpr); |
| 807 | return ret; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 810 | static int gfar_set_hash_opts(struct gfar_private *priv, |
| 811 | struct ethtool_rxnfc *cmd) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 812 | { |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 813 | /* write the filer rules here */ |
| 814 | if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type)) |
Ben Hutchings | bde3528 | 2011-04-08 13:45:11 +0000 | [diff] [blame] | 815 | return -EINVAL; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 820 | static int gfar_check_filer_hardware(struct gfar_private *priv) |
| 821 | { |
| 822 | struct gfar __iomem *regs = NULL; |
| 823 | u32 i; |
| 824 | |
| 825 | regs = priv->gfargrp[0].regs; |
| 826 | |
| 827 | /* Check if we are in FIFO mode */ |
| 828 | i = gfar_read(®s->ecntrl); |
| 829 | i &= ECNTRL_FIFM; |
| 830 | if (i == ECNTRL_FIFM) { |
| 831 | netdev_notice(priv->ndev, "Interface in FIFO mode\n"); |
| 832 | i = gfar_read(®s->rctrl); |
| 833 | i &= RCTRL_PRSDEP_MASK | RCTRL_PRSFM; |
| 834 | if (i == (RCTRL_PRSDEP_MASK | RCTRL_PRSFM)) { |
| 835 | netdev_info(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 836 | "Receive Queue Filtering enabled\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 837 | } else { |
| 838 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 839 | "Receive Queue Filtering disabled\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 840 | return -EOPNOTSUPP; |
| 841 | } |
| 842 | } |
| 843 | /* Or in standard mode */ |
| 844 | else { |
| 845 | i = gfar_read(®s->rctrl); |
| 846 | i &= RCTRL_PRSDEP_MASK; |
| 847 | if (i == RCTRL_PRSDEP_MASK) { |
| 848 | netdev_info(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 849 | "Receive Queue Filtering enabled\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 850 | } else { |
| 851 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 852 | "Receive Queue Filtering disabled\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 853 | return -EOPNOTSUPP; |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | /* Sets the properties for arbitrary filer rule |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 858 | * to the first 4 Layer 4 Bytes |
| 859 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 860 | regs->rbifx = 0xC0C1C2C3; |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | static int gfar_comp_asc(const void *a, const void *b) |
| 865 | { |
| 866 | return memcmp(a, b, 4); |
| 867 | } |
| 868 | |
| 869 | static int gfar_comp_desc(const void *a, const void *b) |
| 870 | { |
| 871 | return -memcmp(a, b, 4); |
| 872 | } |
| 873 | |
| 874 | static void gfar_swap(void *a, void *b, int size) |
| 875 | { |
| 876 | u32 *_a = a; |
| 877 | u32 *_b = b; |
| 878 | |
| 879 | swap(_a[0], _b[0]); |
| 880 | swap(_a[1], _b[1]); |
| 881 | swap(_a[2], _b[2]); |
| 882 | swap(_a[3], _b[3]); |
| 883 | } |
| 884 | |
| 885 | /* Write a mask to filer cache */ |
| 886 | static void gfar_set_mask(u32 mask, struct filer_table *tab) |
| 887 | { |
| 888 | tab->fe[tab->index].ctrl = RQFCR_AND | RQFCR_PID_MASK | RQFCR_CMP_EXACT; |
| 889 | tab->fe[tab->index].prop = mask; |
| 890 | tab->index++; |
| 891 | } |
| 892 | |
| 893 | /* Sets parse bits (e.g. IP or TCP) */ |
| 894 | static void gfar_set_parse_bits(u32 value, u32 mask, struct filer_table *tab) |
| 895 | { |
| 896 | gfar_set_mask(mask, tab); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 897 | tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_PID_PARSE | |
| 898 | RQFCR_AND; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 899 | tab->fe[tab->index].prop = value; |
| 900 | tab->index++; |
| 901 | } |
| 902 | |
| 903 | static void gfar_set_general_attribute(u32 value, u32 mask, u32 flag, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 904 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 905 | { |
| 906 | gfar_set_mask(mask, tab); |
| 907 | tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_AND | flag; |
| 908 | tab->fe[tab->index].prop = value; |
| 909 | tab->index++; |
| 910 | } |
| 911 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 912 | /* For setting a tuple of value and mask of type flag |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 913 | * Example: |
| 914 | * IP-Src = 10.0.0.0/255.0.0.0 |
| 915 | * value: 0x0A000000 mask: FF000000 flag: RQFPR_IPV4 |
| 916 | * |
| 917 | * Ethtool gives us a value=0 and mask=~0 for don't care a tuple |
| 918 | * For a don't care mask it gives us a 0 |
| 919 | * |
| 920 | * The check if don't care and the mask adjustment if mask=0 is done for VLAN |
| 921 | * and MAC stuff on an upper level (due to missing information on this level). |
| 922 | * For these guys we can discard them if they are value=0 and mask=0. |
| 923 | * |
| 924 | * Further the all masks are one-padded for better hardware efficiency. |
| 925 | */ |
| 926 | static void gfar_set_attribute(u32 value, u32 mask, u32 flag, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 927 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 928 | { |
| 929 | switch (flag) { |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 930 | /* 3bit */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 931 | case RQFCR_PID_PRI: |
| 932 | if (!(value | mask)) |
| 933 | return; |
| 934 | mask |= RQFCR_PID_PRI_MASK; |
| 935 | break; |
| 936 | /* 8bit */ |
| 937 | case RQFCR_PID_L4P: |
| 938 | case RQFCR_PID_TOS: |
| 939 | if (!~(mask | RQFCR_PID_L4P_MASK)) |
| 940 | return; |
| 941 | if (!mask) |
| 942 | mask = ~0; |
| 943 | else |
| 944 | mask |= RQFCR_PID_L4P_MASK; |
| 945 | break; |
| 946 | /* 12bit */ |
| 947 | case RQFCR_PID_VID: |
| 948 | if (!(value | mask)) |
| 949 | return; |
| 950 | mask |= RQFCR_PID_VID_MASK; |
| 951 | break; |
| 952 | /* 16bit */ |
| 953 | case RQFCR_PID_DPT: |
| 954 | case RQFCR_PID_SPT: |
| 955 | case RQFCR_PID_ETY: |
| 956 | if (!~(mask | RQFCR_PID_PORT_MASK)) |
| 957 | return; |
| 958 | if (!mask) |
| 959 | mask = ~0; |
| 960 | else |
| 961 | mask |= RQFCR_PID_PORT_MASK; |
| 962 | break; |
| 963 | /* 24bit */ |
| 964 | case RQFCR_PID_DAH: |
| 965 | case RQFCR_PID_DAL: |
| 966 | case RQFCR_PID_SAH: |
| 967 | case RQFCR_PID_SAL: |
| 968 | if (!(value | mask)) |
| 969 | return; |
| 970 | mask |= RQFCR_PID_MAC_MASK; |
| 971 | break; |
| 972 | /* for all real 32bit masks */ |
| 973 | default: |
| 974 | if (!~mask) |
| 975 | return; |
| 976 | if (!mask) |
| 977 | mask = ~0; |
| 978 | break; |
| 979 | } |
| 980 | gfar_set_general_attribute(value, mask, flag, tab); |
| 981 | } |
| 982 | |
| 983 | /* Translates value and mask for UDP, TCP or SCTP */ |
| 984 | static void gfar_set_basic_ip(struct ethtool_tcpip4_spec *value, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 985 | struct ethtool_tcpip4_spec *mask, |
| 986 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 987 | { |
| 988 | gfar_set_attribute(value->ip4src, mask->ip4src, RQFCR_PID_SIA, tab); |
| 989 | gfar_set_attribute(value->ip4dst, mask->ip4dst, RQFCR_PID_DIA, tab); |
| 990 | gfar_set_attribute(value->pdst, mask->pdst, RQFCR_PID_DPT, tab); |
| 991 | gfar_set_attribute(value->psrc, mask->psrc, RQFCR_PID_SPT, tab); |
| 992 | gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab); |
| 993 | } |
| 994 | |
| 995 | /* Translates value and mask for RAW-IP4 */ |
| 996 | static void gfar_set_user_ip(struct ethtool_usrip4_spec *value, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 997 | struct ethtool_usrip4_spec *mask, |
| 998 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 999 | { |
| 1000 | gfar_set_attribute(value->ip4src, mask->ip4src, RQFCR_PID_SIA, tab); |
| 1001 | gfar_set_attribute(value->ip4dst, mask->ip4dst, RQFCR_PID_DIA, tab); |
| 1002 | gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab); |
| 1003 | gfar_set_attribute(value->proto, mask->proto, RQFCR_PID_L4P, tab); |
| 1004 | gfar_set_attribute(value->l4_4_bytes, mask->l4_4_bytes, RQFCR_PID_ARB, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1005 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1006 | |
| 1007 | } |
| 1008 | |
| 1009 | /* Translates value and mask for ETHER spec */ |
| 1010 | static void gfar_set_ether(struct ethhdr *value, struct ethhdr *mask, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1011 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1012 | { |
| 1013 | u32 upper_temp_mask = 0; |
| 1014 | u32 lower_temp_mask = 0; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1015 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1016 | /* Source address */ |
| 1017 | if (!is_broadcast_ether_addr(mask->h_source)) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1018 | if (is_zero_ether_addr(mask->h_source)) { |
| 1019 | upper_temp_mask = 0xFFFFFFFF; |
| 1020 | lower_temp_mask = 0xFFFFFFFF; |
| 1021 | } else { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1022 | upper_temp_mask = mask->h_source[0] << 16 | |
| 1023 | mask->h_source[1] << 8 | |
| 1024 | mask->h_source[2]; |
| 1025 | lower_temp_mask = mask->h_source[3] << 16 | |
| 1026 | mask->h_source[4] << 8 | |
| 1027 | mask->h_source[5]; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1028 | } |
| 1029 | /* Upper 24bit */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1030 | gfar_set_attribute(value->h_source[0] << 16 | |
| 1031 | value->h_source[1] << 8 | |
| 1032 | value->h_source[2], |
| 1033 | upper_temp_mask, RQFCR_PID_SAH, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1034 | /* And the same for the lower part */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1035 | gfar_set_attribute(value->h_source[3] << 16 | |
| 1036 | value->h_source[4] << 8 | |
| 1037 | value->h_source[5], |
| 1038 | lower_temp_mask, RQFCR_PID_SAL, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1039 | } |
| 1040 | /* Destination address */ |
| 1041 | if (!is_broadcast_ether_addr(mask->h_dest)) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1042 | /* Special for destination is limited broadcast */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1043 | if ((is_broadcast_ether_addr(value->h_dest) && |
| 1044 | is_zero_ether_addr(mask->h_dest))) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1045 | gfar_set_parse_bits(RQFPR_EBC, RQFPR_EBC, tab); |
| 1046 | } else { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1047 | if (is_zero_ether_addr(mask->h_dest)) { |
| 1048 | upper_temp_mask = 0xFFFFFFFF; |
| 1049 | lower_temp_mask = 0xFFFFFFFF; |
| 1050 | } else { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1051 | upper_temp_mask = mask->h_dest[0] << 16 | |
| 1052 | mask->h_dest[1] << 8 | |
| 1053 | mask->h_dest[2]; |
| 1054 | lower_temp_mask = mask->h_dest[3] << 16 | |
| 1055 | mask->h_dest[4] << 8 | |
| 1056 | mask->h_dest[5]; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | /* Upper 24bit */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1060 | gfar_set_attribute(value->h_dest[0] << 16 | |
| 1061 | value->h_dest[1] << 8 | |
| 1062 | value->h_dest[2], |
| 1063 | upper_temp_mask, RQFCR_PID_DAH, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1064 | /* And the same for the lower part */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1065 | gfar_set_attribute(value->h_dest[3] << 16 | |
| 1066 | value->h_dest[4] << 8 | |
| 1067 | value->h_dest[5], |
| 1068 | lower_temp_mask, RQFCR_PID_DAL, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | gfar_set_attribute(value->h_proto, mask->h_proto, RQFCR_PID_ETY, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | /* Convert a rule to binary filter format of gianfar */ |
| 1076 | static int gfar_convert_to_filer(struct ethtool_rx_flow_spec *rule, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1077 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1078 | { |
| 1079 | u32 vlan = 0, vlan_mask = 0; |
| 1080 | u32 id = 0, id_mask = 0; |
| 1081 | u32 cfi = 0, cfi_mask = 0; |
| 1082 | u32 prio = 0, prio_mask = 0; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1083 | u32 old_index = tab->index; |
| 1084 | |
| 1085 | /* Check if vlan is wanted */ |
| 1086 | if ((rule->flow_type & FLOW_EXT) && (rule->m_ext.vlan_tci != 0xFFFF)) { |
| 1087 | if (!rule->m_ext.vlan_tci) |
| 1088 | rule->m_ext.vlan_tci = 0xFFFF; |
| 1089 | |
| 1090 | vlan = RQFPR_VLN; |
| 1091 | vlan_mask = RQFPR_VLN; |
| 1092 | |
| 1093 | /* Separate the fields */ |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 1094 | id = rule->h_ext.vlan_tci & VLAN_VID_MASK; |
| 1095 | id_mask = rule->m_ext.vlan_tci & VLAN_VID_MASK; |
| 1096 | cfi = rule->h_ext.vlan_tci & VLAN_CFI_MASK; |
| 1097 | cfi_mask = rule->m_ext.vlan_tci & VLAN_CFI_MASK; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1098 | prio = (rule->h_ext.vlan_tci & VLAN_PRIO_MASK) >> |
| 1099 | VLAN_PRIO_SHIFT; |
| 1100 | prio_mask = (rule->m_ext.vlan_tci & VLAN_PRIO_MASK) >> |
| 1101 | VLAN_PRIO_SHIFT; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1102 | |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 1103 | if (cfi == VLAN_TAG_PRESENT && cfi_mask == VLAN_TAG_PRESENT) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1104 | vlan |= RQFPR_CFI; |
| 1105 | vlan_mask |= RQFPR_CFI; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1106 | } else if (cfi != VLAN_TAG_PRESENT && |
| 1107 | cfi_mask == VLAN_TAG_PRESENT) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1108 | vlan_mask |= RQFPR_CFI; |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | switch (rule->flow_type & ~FLOW_EXT) { |
| 1113 | case TCP_V4_FLOW: |
| 1114 | gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_TCP | vlan, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1115 | RQFPR_IPV4 | RQFPR_TCP | vlan_mask, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1116 | gfar_set_basic_ip(&rule->h_u.tcp_ip4_spec, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1117 | &rule->m_u.tcp_ip4_spec, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1118 | break; |
| 1119 | case UDP_V4_FLOW: |
| 1120 | gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_UDP | vlan, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1121 | RQFPR_IPV4 | RQFPR_UDP | vlan_mask, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1122 | gfar_set_basic_ip(&rule->h_u.udp_ip4_spec, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1123 | &rule->m_u.udp_ip4_spec, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1124 | break; |
| 1125 | case SCTP_V4_FLOW: |
| 1126 | gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1127 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1128 | gfar_set_attribute(132, 0, RQFCR_PID_L4P, tab); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1129 | gfar_set_basic_ip((struct ethtool_tcpip4_spec *)&rule->h_u, |
| 1130 | (struct ethtool_tcpip4_spec *)&rule->m_u, |
| 1131 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1132 | break; |
| 1133 | case IP_USER_FLOW: |
| 1134 | gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1135 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1136 | gfar_set_user_ip((struct ethtool_usrip4_spec *) &rule->h_u, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1137 | (struct ethtool_usrip4_spec *) &rule->m_u, |
| 1138 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1139 | break; |
| 1140 | case ETHER_FLOW: |
| 1141 | if (vlan) |
| 1142 | gfar_set_parse_bits(vlan, vlan_mask, tab); |
| 1143 | gfar_set_ether((struct ethhdr *) &rule->h_u, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1144 | (struct ethhdr *) &rule->m_u, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1145 | break; |
| 1146 | default: |
| 1147 | return -1; |
| 1148 | } |
| 1149 | |
| 1150 | /* Set the vlan attributes in the end */ |
| 1151 | if (vlan) { |
| 1152 | gfar_set_attribute(id, id_mask, RQFCR_PID_VID, tab); |
| 1153 | gfar_set_attribute(prio, prio_mask, RQFCR_PID_PRI, tab); |
| 1154 | } |
| 1155 | |
| 1156 | /* If there has been nothing written till now, it must be a default */ |
| 1157 | if (tab->index == old_index) { |
| 1158 | gfar_set_mask(0xFFFFFFFF, tab); |
| 1159 | tab->fe[tab->index].ctrl = 0x20; |
| 1160 | tab->fe[tab->index].prop = 0x0; |
| 1161 | tab->index++; |
| 1162 | } |
| 1163 | |
| 1164 | /* Remove last AND */ |
| 1165 | tab->fe[tab->index - 1].ctrl &= (~RQFCR_AND); |
| 1166 | |
| 1167 | /* Specify which queue to use or to drop */ |
| 1168 | if (rule->ring_cookie == RX_CLS_FLOW_DISC) |
| 1169 | tab->fe[tab->index - 1].ctrl |= RQFCR_RJE; |
| 1170 | else |
| 1171 | tab->fe[tab->index - 1].ctrl |= (rule->ring_cookie << 10); |
| 1172 | |
| 1173 | /* Only big enough entries can be clustered */ |
| 1174 | if (tab->index > (old_index + 2)) { |
| 1175 | tab->fe[old_index + 1].ctrl |= RQFCR_CLE; |
| 1176 | tab->fe[tab->index - 1].ctrl |= RQFCR_CLE; |
| 1177 | } |
| 1178 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1179 | /* In rare cases the cache can be full while there is |
| 1180 | * free space in hw |
| 1181 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1182 | if (tab->index > MAX_FILER_CACHE_IDX - 1) |
| 1183 | return -EBUSY; |
| 1184 | |
| 1185 | return 0; |
| 1186 | } |
| 1187 | |
| 1188 | /* Copy size filer entries */ |
| 1189 | static void gfar_copy_filer_entries(struct gfar_filer_entry dst[0], |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1190 | struct gfar_filer_entry src[0], s32 size) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1191 | { |
| 1192 | while (size > 0) { |
| 1193 | size--; |
| 1194 | dst[size].ctrl = src[size].ctrl; |
| 1195 | dst[size].prop = src[size].prop; |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | /* Delete the contents of the filer-table between start and end |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1200 | * and collapse them |
| 1201 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1202 | static int gfar_trim_filer_entries(u32 begin, u32 end, struct filer_table *tab) |
| 1203 | { |
| 1204 | int length; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1205 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1206 | if (end > MAX_FILER_CACHE_IDX || end < begin) |
| 1207 | return -EINVAL; |
| 1208 | |
| 1209 | end++; |
| 1210 | length = end - begin; |
| 1211 | |
| 1212 | /* Copy */ |
| 1213 | while (end < tab->index) { |
| 1214 | tab->fe[begin].ctrl = tab->fe[end].ctrl; |
| 1215 | tab->fe[begin++].prop = tab->fe[end++].prop; |
| 1216 | |
| 1217 | } |
| 1218 | /* Fill up with don't cares */ |
| 1219 | while (begin < tab->index) { |
| 1220 | tab->fe[begin].ctrl = 0x60; |
| 1221 | tab->fe[begin].prop = 0xFFFFFFFF; |
| 1222 | begin++; |
| 1223 | } |
| 1224 | |
| 1225 | tab->index -= length; |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | /* Make space on the wanted location */ |
| 1230 | static int gfar_expand_filer_entries(u32 begin, u32 length, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1231 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1232 | { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1233 | if (length == 0 || length + tab->index > MAX_FILER_CACHE_IDX || |
| 1234 | begin > MAX_FILER_CACHE_IDX) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1235 | return -EINVAL; |
| 1236 | |
| 1237 | gfar_copy_filer_entries(&(tab->fe[begin + length]), &(tab->fe[begin]), |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1238 | tab->index - length + 1); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1239 | |
| 1240 | tab->index += length; |
| 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | static int gfar_get_next_cluster_start(int start, struct filer_table *tab) |
| 1245 | { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1246 | for (; (start < tab->index) && (start < MAX_FILER_CACHE_IDX - 1); |
| 1247 | start++) { |
| 1248 | if ((tab->fe[start].ctrl & (RQFCR_AND | RQFCR_CLE)) == |
| 1249 | (RQFCR_AND | RQFCR_CLE)) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1250 | return start; |
| 1251 | } |
| 1252 | return -1; |
| 1253 | } |
| 1254 | |
| 1255 | static int gfar_get_next_cluster_end(int start, struct filer_table *tab) |
| 1256 | { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1257 | for (; (start < tab->index) && (start < MAX_FILER_CACHE_IDX - 1); |
| 1258 | start++) { |
| 1259 | if ((tab->fe[start].ctrl & (RQFCR_AND | RQFCR_CLE)) == |
| 1260 | (RQFCR_CLE)) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1261 | return start; |
| 1262 | } |
| 1263 | return -1; |
| 1264 | } |
| 1265 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1266 | /* Uses hardwares clustering option to reduce |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1267 | * the number of filer table entries |
| 1268 | */ |
| 1269 | static void gfar_cluster_filer(struct filer_table *tab) |
| 1270 | { |
| 1271 | s32 i = -1, j, iend, jend; |
| 1272 | |
| 1273 | while ((i = gfar_get_next_cluster_start(++i, tab)) != -1) { |
| 1274 | j = i; |
| 1275 | while ((j = gfar_get_next_cluster_start(++j, tab)) != -1) { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1276 | /* The cluster entries self and the previous one |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1277 | * (a mask) must be identical! |
| 1278 | */ |
| 1279 | if (tab->fe[i].ctrl != tab->fe[j].ctrl) |
| 1280 | break; |
| 1281 | if (tab->fe[i].prop != tab->fe[j].prop) |
| 1282 | break; |
| 1283 | if (tab->fe[i - 1].ctrl != tab->fe[j - 1].ctrl) |
| 1284 | break; |
| 1285 | if (tab->fe[i - 1].prop != tab->fe[j - 1].prop) |
| 1286 | break; |
| 1287 | iend = gfar_get_next_cluster_end(i, tab); |
| 1288 | jend = gfar_get_next_cluster_end(j, tab); |
| 1289 | if (jend == -1 || iend == -1) |
| 1290 | break; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1291 | |
| 1292 | /* First we make some free space, where our cluster |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1293 | * element should be. Then we copy it there and finally |
| 1294 | * delete in from its old location. |
| 1295 | */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1296 | if (gfar_expand_filer_entries(iend, (jend - j), tab) == |
| 1297 | -EINVAL) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1298 | break; |
| 1299 | |
| 1300 | gfar_copy_filer_entries(&(tab->fe[iend + 1]), |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1301 | &(tab->fe[jend + 1]), jend - j); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1302 | |
| 1303 | if (gfar_trim_filer_entries(jend - 1, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1304 | jend + (jend - j), |
| 1305 | tab) == -EINVAL) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1306 | return; |
| 1307 | |
| 1308 | /* Mask out cluster bit */ |
| 1309 | tab->fe[iend].ctrl &= ~(RQFCR_CLE); |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 1314 | /* Swaps the masked bits of a1<>a2 and b1<>b2 */ |
| 1315 | static void gfar_swap_bits(struct gfar_filer_entry *a1, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1316 | struct gfar_filer_entry *a2, |
| 1317 | struct gfar_filer_entry *b1, |
| 1318 | struct gfar_filer_entry *b2, u32 mask) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1319 | { |
| 1320 | u32 temp[4]; |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 1321 | temp[0] = a1->ctrl & mask; |
| 1322 | temp[1] = a2->ctrl & mask; |
| 1323 | temp[2] = b1->ctrl & mask; |
| 1324 | temp[3] = b2->ctrl & mask; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1325 | |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 1326 | a1->ctrl &= ~mask; |
| 1327 | a2->ctrl &= ~mask; |
| 1328 | b1->ctrl &= ~mask; |
| 1329 | b2->ctrl &= ~mask; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1330 | |
| 1331 | a1->ctrl |= temp[1]; |
| 1332 | a2->ctrl |= temp[0]; |
| 1333 | b1->ctrl |= temp[3]; |
| 1334 | b2->ctrl |= temp[2]; |
| 1335 | } |
| 1336 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1337 | /* Generate a list consisting of masks values with their start and |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1338 | * end of validity and block as indicator for parts belonging |
| 1339 | * together (glued by ANDs) in mask_table |
| 1340 | */ |
| 1341 | static u32 gfar_generate_mask_table(struct gfar_mask_entry *mask_table, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1342 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1343 | { |
| 1344 | u32 i, and_index = 0, block_index = 1; |
| 1345 | |
| 1346 | for (i = 0; i < tab->index; i++) { |
| 1347 | |
| 1348 | /* LSByte of control = 0 sets a mask */ |
| 1349 | if (!(tab->fe[i].ctrl & 0xF)) { |
| 1350 | mask_table[and_index].mask = tab->fe[i].prop; |
| 1351 | mask_table[and_index].start = i; |
| 1352 | mask_table[and_index].block = block_index; |
| 1353 | if (and_index >= 1) |
| 1354 | mask_table[and_index - 1].end = i - 1; |
| 1355 | and_index++; |
| 1356 | } |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 1357 | /* cluster starts and ends will be separated because they should |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1358 | * hold their position |
| 1359 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1360 | if (tab->fe[i].ctrl & RQFCR_CLE) |
| 1361 | block_index++; |
| 1362 | /* A not set AND indicates the end of a depended block */ |
| 1363 | if (!(tab->fe[i].ctrl & RQFCR_AND)) |
| 1364 | block_index++; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | mask_table[and_index - 1].end = i - 1; |
| 1368 | |
| 1369 | return and_index; |
| 1370 | } |
| 1371 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1372 | /* Sorts the entries of mask_table by the values of the masks. |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1373 | * Important: The 0xFF80 flags of the first and last entry of a |
| 1374 | * block must hold their position (which queue, CLusterEnable, ReJEct, |
| 1375 | * AND) |
| 1376 | */ |
| 1377 | static void gfar_sort_mask_table(struct gfar_mask_entry *mask_table, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1378 | struct filer_table *temp_table, u32 and_index) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1379 | { |
| 1380 | /* Pointer to compare function (_asc or _desc) */ |
| 1381 | int (*gfar_comp)(const void *, const void *); |
| 1382 | |
| 1383 | u32 i, size = 0, start = 0, prev = 1; |
| 1384 | u32 old_first, old_last, new_first, new_last; |
| 1385 | |
| 1386 | gfar_comp = &gfar_comp_desc; |
| 1387 | |
| 1388 | for (i = 0; i < and_index; i++) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1389 | if (prev != mask_table[i].block) { |
| 1390 | old_first = mask_table[start].start + 1; |
| 1391 | old_last = mask_table[i - 1].end; |
| 1392 | sort(mask_table + start, size, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1393 | sizeof(struct gfar_mask_entry), |
| 1394 | gfar_comp, &gfar_swap); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1395 | |
| 1396 | /* Toggle order for every block. This makes the |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1397 | * thing more efficient! |
| 1398 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1399 | if (gfar_comp == gfar_comp_desc) |
| 1400 | gfar_comp = &gfar_comp_asc; |
| 1401 | else |
| 1402 | gfar_comp = &gfar_comp_desc; |
| 1403 | |
| 1404 | new_first = mask_table[start].start + 1; |
| 1405 | new_last = mask_table[i - 1].end; |
| 1406 | |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 1407 | gfar_swap_bits(&temp_table->fe[new_first], |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1408 | &temp_table->fe[old_first], |
| 1409 | &temp_table->fe[new_last], |
| 1410 | &temp_table->fe[old_last], |
| 1411 | RQFCR_QUEUE | RQFCR_CLE | |
| 1412 | RQFCR_RJE | RQFCR_AND); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1413 | |
| 1414 | start = i; |
| 1415 | size = 0; |
| 1416 | } |
| 1417 | size++; |
| 1418 | prev = mask_table[i].block; |
| 1419 | } |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1422 | /* Reduces the number of masks needed in the filer table to save entries |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1423 | * This is done by sorting the masks of a depended block. A depended block is |
| 1424 | * identified by gluing ANDs or CLE. The sorting order toggles after every |
| 1425 | * block. Of course entries in scope of a mask must change their location with |
| 1426 | * it. |
| 1427 | */ |
| 1428 | static int gfar_optimize_filer_masks(struct filer_table *tab) |
| 1429 | { |
| 1430 | struct filer_table *temp_table; |
| 1431 | struct gfar_mask_entry *mask_table; |
| 1432 | |
| 1433 | u32 and_index = 0, previous_mask = 0, i = 0, j = 0, size = 0; |
| 1434 | s32 ret = 0; |
| 1435 | |
| 1436 | /* We need a copy of the filer table because |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1437 | * we want to change its order |
| 1438 | */ |
Thomas Meyer | b8ffdbd | 2011-11-17 13:05:35 +0000 | [diff] [blame] | 1439 | temp_table = kmemdup(tab, sizeof(*temp_table), GFP_KERNEL); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1440 | if (temp_table == NULL) |
| 1441 | return -ENOMEM; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1442 | |
| 1443 | mask_table = kcalloc(MAX_FILER_CACHE_IDX / 2 + 1, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1444 | sizeof(struct gfar_mask_entry), GFP_KERNEL); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1445 | |
| 1446 | if (mask_table == NULL) { |
| 1447 | ret = -ENOMEM; |
| 1448 | goto end; |
| 1449 | } |
| 1450 | |
| 1451 | and_index = gfar_generate_mask_table(mask_table, tab); |
| 1452 | |
| 1453 | gfar_sort_mask_table(mask_table, temp_table, and_index); |
| 1454 | |
| 1455 | /* Now we can copy the data from our duplicated filer table to |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1456 | * the real one in the order the mask table says |
| 1457 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1458 | for (i = 0; i < and_index; i++) { |
| 1459 | size = mask_table[i].end - mask_table[i].start + 1; |
| 1460 | gfar_copy_filer_entries(&(tab->fe[j]), |
| 1461 | &(temp_table->fe[mask_table[i].start]), size); |
| 1462 | j += size; |
| 1463 | } |
| 1464 | |
| 1465 | /* And finally we just have to check for duplicated masks and drop the |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1466 | * second ones |
| 1467 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1468 | for (i = 0; i < tab->index && i < MAX_FILER_CACHE_IDX; i++) { |
| 1469 | if (tab->fe[i].ctrl == 0x80) { |
| 1470 | previous_mask = i++; |
| 1471 | break; |
| 1472 | } |
| 1473 | } |
| 1474 | for (; i < tab->index && i < MAX_FILER_CACHE_IDX; i++) { |
| 1475 | if (tab->fe[i].ctrl == 0x80) { |
| 1476 | if (tab->fe[i].prop == tab->fe[previous_mask].prop) { |
| 1477 | /* Two identical ones found! |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1478 | * So drop the second one! |
| 1479 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1480 | gfar_trim_filer_entries(i, i, tab); |
| 1481 | } else |
| 1482 | /* Not identical! */ |
| 1483 | previous_mask = i; |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | kfree(mask_table); |
| 1488 | end: kfree(temp_table); |
| 1489 | return ret; |
| 1490 | } |
| 1491 | |
| 1492 | /* Write the bit-pattern from software's buffer to hardware registers */ |
| 1493 | static int gfar_write_filer_table(struct gfar_private *priv, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1494 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1495 | { |
| 1496 | u32 i = 0; |
| 1497 | if (tab->index > MAX_FILER_IDX - 1) |
| 1498 | return -EBUSY; |
| 1499 | |
| 1500 | /* Avoid inconsistent filer table to be processed */ |
| 1501 | lock_rx_qs(priv); |
| 1502 | |
| 1503 | /* Fill regular entries */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1504 | for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].ctrl); |
| 1505 | i++) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1506 | gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop); |
| 1507 | /* Fill the rest with fall-troughs */ |
| 1508 | for (; i < MAX_FILER_IDX - 1; i++) |
| 1509 | gfar_write_filer(priv, i, 0x60, 0xFFFFFFFF); |
| 1510 | /* Last entry must be default accept |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1511 | * because that's what people expect |
| 1512 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1513 | gfar_write_filer(priv, i, 0x20, 0x0); |
| 1514 | |
| 1515 | unlock_rx_qs(priv); |
| 1516 | |
| 1517 | return 0; |
| 1518 | } |
| 1519 | |
| 1520 | static int gfar_check_capability(struct ethtool_rx_flow_spec *flow, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1521 | struct gfar_private *priv) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1522 | { |
| 1523 | |
| 1524 | if (flow->flow_type & FLOW_EXT) { |
| 1525 | if (~flow->m_ext.data[0] || ~flow->m_ext.data[1]) |
| 1526 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1527 | "User-specific data not supported!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1528 | if (~flow->m_ext.vlan_etype) |
| 1529 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1530 | "VLAN-etype not supported!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1531 | } |
| 1532 | if (flow->flow_type == IP_USER_FLOW) |
| 1533 | if (flow->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4) |
| 1534 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1535 | "IP-Version differing from IPv4 not supported!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1536 | |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
| 1540 | static int gfar_process_filer_changes(struct gfar_private *priv) |
| 1541 | { |
| 1542 | struct ethtool_flow_spec_container *j; |
| 1543 | struct filer_table *tab; |
| 1544 | s32 i = 0; |
| 1545 | s32 ret = 0; |
| 1546 | |
| 1547 | /* So index is set to zero, too! */ |
| 1548 | tab = kzalloc(sizeof(*tab), GFP_KERNEL); |
| 1549 | if (tab == NULL) |
| 1550 | return -ENOMEM; |
| 1551 | |
| 1552 | /* Now convert the existing filer data from flow_spec into |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1553 | * filer tables binary format |
| 1554 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1555 | list_for_each_entry(j, &priv->rx_list.list, list) { |
| 1556 | ret = gfar_convert_to_filer(&j->fs, tab); |
| 1557 | if (ret == -EBUSY) { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1558 | netdev_err(priv->ndev, |
| 1559 | "Rule not added: No free space!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1560 | goto end; |
| 1561 | } |
| 1562 | if (ret == -1) { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1563 | netdev_err(priv->ndev, |
| 1564 | "Rule not added: Unsupported Flow-type!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1565 | goto end; |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | i = tab->index; |
| 1570 | |
| 1571 | /* Optimizations to save entries */ |
| 1572 | gfar_cluster_filer(tab); |
| 1573 | gfar_optimize_filer_masks(tab); |
| 1574 | |
| 1575 | pr_debug("\n\tSummary:\n" |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1576 | "\tData on hardware: %d\n" |
| 1577 | "\tCompression rate: %d%%\n", |
| 1578 | tab->index, 100 - (100 * tab->index) / i); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1579 | |
| 1580 | /* Write everything to hardware */ |
| 1581 | ret = gfar_write_filer_table(priv, tab); |
| 1582 | if (ret == -EBUSY) { |
| 1583 | netdev_err(priv->ndev, "Rule not added: No free space!\n"); |
| 1584 | goto end; |
| 1585 | } |
| 1586 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1587 | end: |
| 1588 | kfree(tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1589 | return ret; |
| 1590 | } |
| 1591 | |
| 1592 | static void gfar_invert_masks(struct ethtool_rx_flow_spec *flow) |
| 1593 | { |
| 1594 | u32 i = 0; |
| 1595 | |
| 1596 | for (i = 0; i < sizeof(flow->m_u); i++) |
| 1597 | flow->m_u.hdata[i] ^= 0xFF; |
| 1598 | |
| 1599 | flow->m_ext.vlan_etype ^= 0xFFFF; |
| 1600 | flow->m_ext.vlan_tci ^= 0xFFFF; |
| 1601 | flow->m_ext.data[0] ^= ~0; |
| 1602 | flow->m_ext.data[1] ^= ~0; |
| 1603 | } |
| 1604 | |
| 1605 | static int gfar_add_cls(struct gfar_private *priv, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1606 | struct ethtool_rx_flow_spec *flow) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1607 | { |
| 1608 | struct ethtool_flow_spec_container *temp, *comp; |
| 1609 | int ret = 0; |
| 1610 | |
| 1611 | temp = kmalloc(sizeof(*temp), GFP_KERNEL); |
| 1612 | if (temp == NULL) |
| 1613 | return -ENOMEM; |
| 1614 | memcpy(&temp->fs, flow, sizeof(temp->fs)); |
| 1615 | |
| 1616 | gfar_invert_masks(&temp->fs); |
| 1617 | ret = gfar_check_capability(&temp->fs, priv); |
| 1618 | if (ret) |
| 1619 | goto clean_mem; |
| 1620 | /* Link in the new element at the right @location */ |
| 1621 | if (list_empty(&priv->rx_list.list)) { |
| 1622 | ret = gfar_check_filer_hardware(priv); |
| 1623 | if (ret != 0) |
| 1624 | goto clean_mem; |
| 1625 | list_add(&temp->list, &priv->rx_list.list); |
| 1626 | goto process; |
| 1627 | } else { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1628 | list_for_each_entry(comp, &priv->rx_list.list, list) { |
| 1629 | if (comp->fs.location > flow->location) { |
| 1630 | list_add_tail(&temp->list, &comp->list); |
| 1631 | goto process; |
| 1632 | } |
| 1633 | if (comp->fs.location == flow->location) { |
| 1634 | netdev_err(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1635 | "Rule not added: ID %d not free!\n", |
| 1636 | flow->location); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1637 | ret = -EBUSY; |
| 1638 | goto clean_mem; |
| 1639 | } |
| 1640 | } |
| 1641 | list_add_tail(&temp->list, &priv->rx_list.list); |
| 1642 | } |
| 1643 | |
| 1644 | process: |
| 1645 | ret = gfar_process_filer_changes(priv); |
| 1646 | if (ret) |
| 1647 | goto clean_list; |
| 1648 | priv->rx_list.count++; |
| 1649 | return ret; |
| 1650 | |
| 1651 | clean_list: |
| 1652 | list_del(&temp->list); |
| 1653 | clean_mem: |
| 1654 | kfree(temp); |
| 1655 | return ret; |
| 1656 | } |
| 1657 | |
| 1658 | static int gfar_del_cls(struct gfar_private *priv, u32 loc) |
| 1659 | { |
| 1660 | struct ethtool_flow_spec_container *comp; |
| 1661 | u32 ret = -EINVAL; |
| 1662 | |
| 1663 | if (list_empty(&priv->rx_list.list)) |
| 1664 | return ret; |
| 1665 | |
| 1666 | list_for_each_entry(comp, &priv->rx_list.list, list) { |
| 1667 | if (comp->fs.location == loc) { |
| 1668 | list_del(&comp->list); |
| 1669 | kfree(comp); |
| 1670 | priv->rx_list.count--; |
| 1671 | gfar_process_filer_changes(priv); |
| 1672 | ret = 0; |
| 1673 | break; |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | return ret; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | static int gfar_get_cls(struct gfar_private *priv, struct ethtool_rxnfc *cmd) |
| 1681 | { |
| 1682 | struct ethtool_flow_spec_container *comp; |
| 1683 | u32 ret = -EINVAL; |
| 1684 | |
| 1685 | list_for_each_entry(comp, &priv->rx_list.list, list) { |
| 1686 | if (comp->fs.location == cmd->fs.location) { |
| 1687 | memcpy(&cmd->fs, &comp->fs, sizeof(cmd->fs)); |
| 1688 | gfar_invert_masks(&cmd->fs); |
| 1689 | ret = 0; |
| 1690 | break; |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | return ret; |
| 1695 | } |
| 1696 | |
| 1697 | static int gfar_get_cls_all(struct gfar_private *priv, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1698 | struct ethtool_rxnfc *cmd, u32 *rule_locs) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1699 | { |
| 1700 | struct ethtool_flow_spec_container *comp; |
| 1701 | u32 i = 0; |
| 1702 | |
| 1703 | list_for_each_entry(comp, &priv->rx_list.list, list) { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 1704 | if (i == cmd->rule_cnt) |
| 1705 | return -EMSGSIZE; |
| 1706 | rule_locs[i] = comp->fs.location; |
| 1707 | i++; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | cmd->data = MAX_FILER_IDX; |
Ben Hutchings | 473e64e | 2011-09-06 13:52:47 +0000 | [diff] [blame] | 1711 | cmd->rule_cnt = i; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1712 | |
| 1713 | return 0; |
| 1714 | } |
| 1715 | |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1716 | static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd) |
| 1717 | { |
| 1718 | struct gfar_private *priv = netdev_priv(dev); |
| 1719 | int ret = 0; |
| 1720 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1721 | mutex_lock(&priv->rx_queue_access); |
| 1722 | |
| 1723 | switch (cmd->cmd) { |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1724 | case ETHTOOL_SRXFH: |
| 1725 | ret = gfar_set_hash_opts(priv, cmd); |
| 1726 | break; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1727 | case ETHTOOL_SRXCLSRLINS: |
Ben Hutchings | 3a73e49 | 2012-01-03 11:59:30 +0000 | [diff] [blame] | 1728 | if ((cmd->fs.ring_cookie != RX_CLS_FLOW_DISC && |
| 1729 | cmd->fs.ring_cookie >= priv->num_rx_queues) || |
| 1730 | cmd->fs.location >= MAX_FILER_IDX) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1731 | ret = -EINVAL; |
| 1732 | break; |
| 1733 | } |
| 1734 | ret = gfar_add_cls(priv, &cmd->fs); |
| 1735 | break; |
| 1736 | case ETHTOOL_SRXCLSRLDEL: |
| 1737 | ret = gfar_del_cls(priv, cmd->fs.location); |
| 1738 | break; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1739 | default: |
| 1740 | ret = -EINVAL; |
| 1741 | } |
| 1742 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1743 | mutex_unlock(&priv->rx_queue_access); |
| 1744 | |
| 1745 | return ret; |
| 1746 | } |
| 1747 | |
| 1748 | static int gfar_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1749 | u32 *rule_locs) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1750 | { |
| 1751 | struct gfar_private *priv = netdev_priv(dev); |
| 1752 | int ret = 0; |
| 1753 | |
| 1754 | switch (cmd->cmd) { |
| 1755 | case ETHTOOL_GRXRINGS: |
| 1756 | cmd->data = priv->num_rx_queues; |
| 1757 | break; |
| 1758 | case ETHTOOL_GRXCLSRLCNT: |
| 1759 | cmd->rule_cnt = priv->rx_list.count; |
| 1760 | break; |
| 1761 | case ETHTOOL_GRXCLSRULE: |
| 1762 | ret = gfar_get_cls(priv, cmd); |
| 1763 | break; |
| 1764 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | 815c7db | 2011-09-06 13:49:12 +0000 | [diff] [blame] | 1765 | ret = gfar_get_cls_all(priv, cmd, rule_locs); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1766 | break; |
| 1767 | default: |
| 1768 | ret = -EINVAL; |
| 1769 | break; |
| 1770 | } |
| 1771 | |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1772 | return ret; |
| 1773 | } |
| 1774 | |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1775 | int gfar_phc_index = -1; |
Richard Cochran | 28889b7 | 2012-09-20 19:11:12 +0000 | [diff] [blame] | 1776 | EXPORT_SYMBOL(gfar_phc_index); |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1777 | |
| 1778 | static int gfar_get_ts_info(struct net_device *dev, |
| 1779 | struct ethtool_ts_info *info) |
| 1780 | { |
| 1781 | struct gfar_private *priv = netdev_priv(dev); |
| 1782 | |
| 1783 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)) { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1784 | info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1785 | SOF_TIMESTAMPING_SOFTWARE; |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1786 | info->phc_index = -1; |
| 1787 | return 0; |
| 1788 | } |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1789 | info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | |
| 1790 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1791 | SOF_TIMESTAMPING_RAW_HARDWARE; |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1792 | info->phc_index = gfar_phc_index; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1793 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | |
| 1794 | (1 << HWTSTAMP_TX_ON); |
| 1795 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 1796 | (1 << HWTSTAMP_FILTER_ALL); |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1797 | return 0; |
| 1798 | } |
| 1799 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1800 | const struct ethtool_ops gfar_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | .get_settings = gfar_gsettings, |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 1802 | .set_settings = gfar_ssettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | .get_drvinfo = gfar_gdrvinfo, |
| 1804 | .get_regs_len = gfar_reglen, |
| 1805 | .get_regs = gfar_get_regs, |
| 1806 | .get_link = ethtool_op_get_link, |
| 1807 | .get_coalesce = gfar_gcoalesce, |
| 1808 | .set_coalesce = gfar_scoalesce, |
| 1809 | .get_ringparam = gfar_gringparam, |
| 1810 | .set_ringparam = gfar_sringparam, |
| 1811 | .get_strings = gfar_gstrings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1812 | .get_sset_count = gfar_sset_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | .get_ethtool_stats = gfar_fill_stats, |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1814 | .get_msglevel = gfar_get_msglevel, |
| 1815 | .set_msglevel = gfar_set_msglevel, |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1816 | #ifdef CONFIG_PM |
| 1817 | .get_wol = gfar_get_wol, |
| 1818 | .set_wol = gfar_set_wol, |
| 1819 | #endif |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1820 | .set_rxnfc = gfar_set_nfc, |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1821 | .get_rxnfc = gfar_get_nfc, |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1822 | .get_ts_info = gfar_get_ts_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | }; |