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