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