Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Gortmaker | 3396c78 | 2012-01-27 13:36:01 +0000 | [diff] [blame] | 2 | * drivers/net/ethernet/freescale/gianfar_ethtool.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Gianfar Ethernet Driver |
| 5 | * Ethtool support for Gianfar Enet |
| 6 | * Based on e1000 ethtool support |
| 7 | * |
| 8 | * Author: Andy Fleming |
Kumar Gala | 4c8d3d9 | 2005-11-13 16:06:30 -0800 | [diff] [blame] | 9 | * Maintainer: Kumar Gala |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 10 | * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 12 | * Copyright 2003-2006, 2008-2009, 2011 Freescale Semiconductor, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 14 | * This software may be used and distributed according to |
| 15 | * the terms of the GNU Public License, Version 2, incorporated herein |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * by reference. |
| 17 | */ |
| 18 | |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/string.h> |
| 23 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> |
| 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/etherdevice.h> |
David S. Miller | 65a85a8 | 2012-04-06 00:35:34 -0400 | [diff] [blame] | 28 | #include <linux/net_tstamp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/skbuff.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/mm.h> |
| 32 | |
| 33 | #include <asm/io.h> |
| 34 | #include <asm/irq.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 35 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/crc32.h> |
| 38 | #include <asm/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/ethtool.h> |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 40 | #include <linux/mii.h> |
| 41 | #include <linux/phy.h> |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 42 | #include <linux/sort.h> |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 43 | #include <linux/if_vlan.h> |
Yangbo Lu | 7349a74 | 2018-05-25 12:40:36 +0800 | [diff] [blame] | 44 | #include <linux/of_platform.h> |
| 45 | #include <linux/fsl/ptp_qoriq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | #include "gianfar.h" |
| 48 | |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 49 | #define GFAR_MAX_COAL_USECS 0xffff |
| 50 | #define GFAR_MAX_COAL_FRAMES 0xff |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 51 | 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] | 52 | u64 *buf); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 53 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 54 | static int gfar_gcoalesce(struct net_device *dev, |
| 55 | struct ethtool_coalesce *cvals); |
| 56 | static int gfar_scoalesce(struct net_device *dev, |
| 57 | struct ethtool_coalesce *cvals); |
| 58 | static void gfar_gringparam(struct net_device *dev, |
| 59 | struct ethtool_ringparam *rvals); |
| 60 | static int gfar_sringparam(struct net_device *dev, |
| 61 | struct ethtool_ringparam *rvals); |
| 62 | static void gfar_gdrvinfo(struct net_device *dev, |
| 63 | struct ethtool_drvinfo *drvinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Paul Gortmaker | 30f7e31 | 2012-01-08 13:21:57 -0500 | [diff] [blame] | 65 | static const char stat_gstrings[][ETH_GSTRING_LEN] = { |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 66 | /* extra stats */ |
| 67 | "rx-allocation-errors", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | "rx-large-frame-errors", |
| 69 | "rx-short-frame-errors", |
| 70 | "rx-non-octet-errors", |
| 71 | "rx-crc-errors", |
| 72 | "rx-overrun-errors", |
| 73 | "rx-busy-errors", |
| 74 | "rx-babbling-errors", |
| 75 | "rx-truncated-frames", |
| 76 | "ethernet-bus-error", |
| 77 | "tx-babbling-errors", |
| 78 | "tx-underrun-errors", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | "tx-timeout-errors", |
Claudiu Manoil | 76f31e8 | 2015-07-13 16:22:03 +0300 | [diff] [blame] | 80 | /* rmon stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | "tx-rx-64-frames", |
| 82 | "tx-rx-65-127-frames", |
| 83 | "tx-rx-128-255-frames", |
| 84 | "tx-rx-256-511-frames", |
| 85 | "tx-rx-512-1023-frames", |
| 86 | "tx-rx-1024-1518-frames", |
| 87 | "tx-rx-1519-1522-good-vlan", |
| 88 | "rx-bytes", |
| 89 | "rx-packets", |
| 90 | "rx-fcs-errors", |
| 91 | "receive-multicast-packet", |
| 92 | "receive-broadcast-packet", |
| 93 | "rx-control-frame-packets", |
| 94 | "rx-pause-frame-packets", |
| 95 | "rx-unknown-op-code", |
| 96 | "rx-alignment-error", |
| 97 | "rx-frame-length-error", |
| 98 | "rx-code-error", |
| 99 | "rx-carrier-sense-error", |
| 100 | "rx-undersize-packets", |
| 101 | "rx-oversize-packets", |
| 102 | "rx-fragmented-frames", |
| 103 | "rx-jabber-frames", |
| 104 | "rx-dropped-frames", |
| 105 | "tx-byte-counter", |
| 106 | "tx-packets", |
| 107 | "tx-multicast-packets", |
| 108 | "tx-broadcast-packets", |
| 109 | "tx-pause-control-frames", |
| 110 | "tx-deferral-packets", |
| 111 | "tx-excessive-deferral-packets", |
| 112 | "tx-single-collision-packets", |
| 113 | "tx-multiple-collision-packets", |
| 114 | "tx-late-collision-packets", |
| 115 | "tx-excessive-collision-packets", |
| 116 | "tx-total-collision", |
| 117 | "reserved", |
| 118 | "tx-dropped-frames", |
| 119 | "tx-jabber-frames", |
| 120 | "tx-fcs-errors", |
| 121 | "tx-control-frames", |
| 122 | "tx-oversize-frames", |
| 123 | "tx-undersize-frames", |
| 124 | "tx-fragmented-frames", |
| 125 | }; |
| 126 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 127 | /* Fill in a buffer with the strings which correspond to the |
| 128 | * stats */ |
| 129 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf) |
| 130 | { |
| 131 | struct gfar_private *priv = netdev_priv(dev); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 132 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 133 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 134 | memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN); |
| 135 | else |
| 136 | memcpy(buf, stat_gstrings, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 137 | GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN); |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 138 | } |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* Fill in an array of 64-bit statistics from various sources. |
| 141 | * This array will be appended to the end of the ethtool_stats |
| 142 | * structure, and returned to user space |
| 143 | */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 144 | static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, |
| 145 | u64 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | int i; |
| 148 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 149 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 150 | atomic64_t *extra = (atomic64_t *)&priv->extra_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Paul Gortmaker | 6871978 | 2013-02-12 15:28:35 -0500 | [diff] [blame] | 152 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) |
Paul Gortmaker | 212079d | 2013-02-12 15:38:19 -0500 | [diff] [blame] | 153 | buf[i] = atomic64_read(&extra[i]); |
Paul Gortmaker | 6871978 | 2013-02-12 15:28:35 -0500 | [diff] [blame] | 154 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 155 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 156 | u32 __iomem *rmon = (u32 __iomem *) ®s->rmon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Paul Gortmaker | 6871978 | 2013-02-12 15:28:35 -0500 | [diff] [blame] | 158 | for (; i < GFAR_STATS_LEN; i++, rmon++) |
| 159 | buf[i] = (u64) gfar_read(rmon); |
| 160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 163 | static int gfar_sset_count(struct net_device *dev, int sset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | struct gfar_private *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 167 | switch (sset) { |
| 168 | case ETH_SS_STATS: |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 169 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 170 | return GFAR_STATS_LEN; |
| 171 | else |
| 172 | return GFAR_EXTRA_STATS_LEN; |
| 173 | default: |
| 174 | return -EOPNOTSUPP; |
| 175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* Fills in the drvinfo structure with some basic info */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 179 | static void gfar_gdrvinfo(struct net_device *dev, |
| 180 | struct ethtool_drvinfo *drvinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Jiri Pirko | 7826d43 | 2013-01-06 00:44:26 +0000 | [diff] [blame] | 182 | strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
| 183 | strlcpy(drvinfo->version, gfar_driver_version, |
| 184 | sizeof(drvinfo->version)); |
| 185 | strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); |
| 186 | strlcpy(drvinfo->bus_info, "N/A", sizeof(drvinfo->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* Return the length of the register structure */ |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 190 | static int gfar_reglen(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
| 192 | return sizeof (struct gfar); |
| 193 | } |
| 194 | |
| 195 | /* Return a dump of the GFAR register space */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 196 | static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 197 | void *regbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | int i; |
| 200 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 201 | u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp[0].regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | u32 *buf = (u32 *) regbuf; |
| 203 | |
| 204 | for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++) |
Kumar Gala | cc8c6e3 | 2006-02-01 15:18:03 -0600 | [diff] [blame] | 205 | buf[i] = gfar_read(&theregs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* Convert microseconds to ethernet clock ticks, which changes |
| 209 | * depending on what speed the controller is running at */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 210 | static unsigned int gfar_usecs2ticks(struct gfar_private *priv, |
| 211 | unsigned int usecs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
Philippe Reynes | 4c4a6b0 | 2016-05-16 01:30:08 +0200 | [diff] [blame] | 213 | struct net_device *ndev = priv->ndev; |
| 214 | struct phy_device *phydev = ndev->phydev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | unsigned int count; |
| 216 | |
| 217 | /* The timer is different, depending on the interface speed */ |
Philippe Reynes | 4c4a6b0 | 2016-05-16 01:30:08 +0200 | [diff] [blame] | 218 | switch (phydev->speed) { |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 219 | case SPEED_1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | count = GFAR_GBIT_TIME; |
| 221 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 222 | case SPEED_100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | count = GFAR_100_TIME; |
| 224 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 225 | case SPEED_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | default: |
| 227 | count = GFAR_10_TIME; |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | /* Make sure we return a number greater than 0 |
| 232 | * if usecs > 0 */ |
zhong jiang | f8a1988 | 2018-09-11 21:08:15 +0800 | [diff] [blame] | 233 | return DIV_ROUND_UP(usecs * 1000, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* Convert ethernet clock ticks to microseconds */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 237 | static unsigned int gfar_ticks2usecs(struct gfar_private *priv, |
| 238 | unsigned int ticks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
Philippe Reynes | 4c4a6b0 | 2016-05-16 01:30:08 +0200 | [diff] [blame] | 240 | struct net_device *ndev = priv->ndev; |
| 241 | struct phy_device *phydev = ndev->phydev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | unsigned int count; |
| 243 | |
| 244 | /* The timer is different, depending on the interface speed */ |
Philippe Reynes | 4c4a6b0 | 2016-05-16 01:30:08 +0200 | [diff] [blame] | 245 | switch (phydev->speed) { |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 246 | case SPEED_1000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | count = GFAR_GBIT_TIME; |
| 248 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 249 | case SPEED_100: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | count = GFAR_100_TIME; |
| 251 | break; |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 252 | case SPEED_10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | default: |
| 254 | count = GFAR_10_TIME; |
| 255 | break; |
| 256 | } |
| 257 | |
| 258 | /* Make sure we return a number greater than 0 */ |
| 259 | /* if ticks is > 0 */ |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 260 | return (ticks * count) / 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* Get the coalescing parameters, and put them in the cvals |
| 264 | * structure. */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 265 | static int gfar_gcoalesce(struct net_device *dev, |
| 266 | struct ethtool_coalesce *cvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
| 268 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 269 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 270 | struct gfar_priv_tx_q *tx_queue = NULL; |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 271 | unsigned long rxtime; |
| 272 | unsigned long rxcount; |
| 273 | unsigned long txtime; |
| 274 | unsigned long txcount; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 275 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 276 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 277 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Philippe Reynes | 4c4a6b0 | 2016-05-16 01:30:08 +0200 | [diff] [blame] | 279 | if (!dev->phydev) |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 280 | return -ENODEV; |
| 281 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 282 | rx_queue = priv->rx_queue[0]; |
| 283 | tx_queue = priv->tx_queue[0]; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 284 | |
| 285 | rxtime = get_ictt_value(rx_queue->rxic); |
| 286 | rxcount = get_icft_value(rx_queue->rxic); |
| 287 | txtime = get_ictt_value(tx_queue->txic); |
| 288 | txcount = get_icft_value(tx_queue->txic); |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 289 | cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime); |
| 290 | cvals->rx_max_coalesced_frames = rxcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Dai Haruki | b46a845 | 2008-12-16 15:29:52 -0800 | [diff] [blame] | 292 | cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime); |
| 293 | cvals->tx_max_coalesced_frames = txcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | cvals->use_adaptive_rx_coalesce = 0; |
| 296 | cvals->use_adaptive_tx_coalesce = 0; |
| 297 | |
| 298 | cvals->pkt_rate_low = 0; |
| 299 | cvals->rx_coalesce_usecs_low = 0; |
| 300 | cvals->rx_max_coalesced_frames_low = 0; |
| 301 | cvals->tx_coalesce_usecs_low = 0; |
| 302 | cvals->tx_max_coalesced_frames_low = 0; |
| 303 | |
| 304 | /* When the packet rate is below pkt_rate_high but above |
| 305 | * pkt_rate_low (both measured in packets per second) the |
| 306 | * normal {rx,tx}_* coalescing parameters are used. |
| 307 | */ |
| 308 | |
| 309 | /* When the packet rate is (measured in packets per second) |
| 310 | * is above pkt_rate_high, the {rx,tx}_*_high parameters are |
| 311 | * used. |
| 312 | */ |
| 313 | cvals->pkt_rate_high = 0; |
| 314 | cvals->rx_coalesce_usecs_high = 0; |
| 315 | cvals->rx_max_coalesced_frames_high = 0; |
| 316 | cvals->tx_coalesce_usecs_high = 0; |
| 317 | cvals->tx_max_coalesced_frames_high = 0; |
| 318 | |
| 319 | /* How often to do adaptive coalescing packet rate sampling, |
| 320 | * measured in seconds. Must not be zero. |
| 321 | */ |
| 322 | cvals->rate_sample_interval = 0; |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | /* Change the coalescing values. |
| 328 | * Both cvals->*_usecs and cvals->*_frames have to be > 0 |
| 329 | * in order for coalescing to be active |
| 330 | */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 331 | static int gfar_scoalesce(struct net_device *dev, |
| 332 | struct ethtool_coalesce *cvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
| 334 | struct gfar_private *priv = netdev_priv(dev); |
Claudiu Manoil | f19015b | 2014-02-24 12:13:46 +0200 | [diff] [blame] | 335 | int i, err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Andy Fleming | b31a1d8 | 2008-12-16 15:29:15 -0800 | [diff] [blame] | 337 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 338 | return -EOPNOTSUPP; |
| 339 | |
Philippe Reynes | 4c4a6b0 | 2016-05-16 01:30:08 +0200 | [diff] [blame] | 340 | if (!dev->phydev) |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 341 | return -ENODEV; |
| 342 | |
| 343 | /* Check the bounds of the values */ |
| 344 | if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) { |
Joe Perches | 375d6a1 | 2013-04-13 19:03:18 +0000 | [diff] [blame] | 345 | netdev_info(dev, "Coalescing is limited to %d microseconds\n", |
| 346 | GFAR_MAX_COAL_USECS); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 347 | return -EINVAL; |
| 348 | } |
| 349 | |
| 350 | if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { |
Joe Perches | 375d6a1 | 2013-04-13 19:03:18 +0000 | [diff] [blame] | 351 | netdev_info(dev, "Coalescing is limited to %d frames\n", |
| 352 | GFAR_MAX_COAL_FRAMES); |
Andy Fleming | bb40dcb | 2005-09-23 22:54:21 -0400 | [diff] [blame] | 353 | return -EINVAL; |
| 354 | } |
| 355 | |
Claudiu Manoil | f19015b | 2014-02-24 12:13:46 +0200 | [diff] [blame] | 356 | /* Check the bounds of the values */ |
| 357 | if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) { |
| 358 | netdev_info(dev, "Coalescing is limited to %d microseconds\n", |
| 359 | GFAR_MAX_COAL_USECS); |
| 360 | return -EINVAL; |
| 361 | } |
| 362 | |
| 363 | if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { |
| 364 | netdev_info(dev, "Coalescing is limited to %d frames\n", |
| 365 | GFAR_MAX_COAL_FRAMES); |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | |
| 369 | while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state)) |
| 370 | cpu_relax(); |
| 371 | |
| 372 | /* Set up rx coalescing */ |
| 373 | if ((cvals->rx_coalesce_usecs == 0) || |
| 374 | (cvals->rx_max_coalesced_frames == 0)) { |
| 375 | for (i = 0; i < priv->num_rx_queues; i++) |
| 376 | priv->rx_queue[i]->rxcoalescing = 0; |
| 377 | } else { |
| 378 | for (i = 0; i < priv->num_rx_queues; i++) |
| 379 | priv->rx_queue[i]->rxcoalescing = 1; |
| 380 | } |
| 381 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 382 | for (i = 0; i < priv->num_rx_queues; i++) { |
| 383 | priv->rx_queue[i]->rxic = mk_ic_value( |
| 384 | cvals->rx_max_coalesced_frames, |
| 385 | gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs)); |
| 386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | /* Set up tx coalescing */ |
| 389 | if ((cvals->tx_coalesce_usecs == 0) || |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 390 | (cvals->tx_max_coalesced_frames == 0)) { |
| 391 | for (i = 0; i < priv->num_tx_queues; i++) |
| 392 | priv->tx_queue[i]->txcoalescing = 0; |
| 393 | } else { |
| 394 | for (i = 0; i < priv->num_tx_queues; i++) |
| 395 | priv->tx_queue[i]->txcoalescing = 1; |
| 396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 398 | for (i = 0; i < priv->num_tx_queues; i++) { |
| 399 | priv->tx_queue[i]->txic = mk_ic_value( |
| 400 | cvals->tx_max_coalesced_frames, |
| 401 | gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs)); |
| 402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Claudiu Manoil | f19015b | 2014-02-24 12:13:46 +0200 | [diff] [blame] | 404 | if (dev->flags & IFF_UP) { |
| 405 | stop_gfar(dev); |
| 406 | err = startup_gfar(dev); |
| 407 | } else { |
| 408 | gfar_mac_reset(priv); |
| 409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Claudiu Manoil | f19015b | 2014-02-24 12:13:46 +0200 | [diff] [blame] | 411 | clear_bit_unlock(GFAR_RESETTING, &priv->state); |
| 412 | |
| 413 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* Fills in rvals with the current ring parameters. Currently, |
| 417 | * rx, rx_mini, and rx_jumbo rings are the same size, as mini and |
| 418 | * jumbo are ignored by the driver */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 419 | static void gfar_gringparam(struct net_device *dev, |
| 420 | struct ethtool_ringparam *rvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | struct gfar_private *priv = netdev_priv(dev); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 423 | struct gfar_priv_tx_q *tx_queue = NULL; |
| 424 | struct gfar_priv_rx_q *rx_queue = NULL; |
| 425 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 426 | tx_queue = priv->tx_queue[0]; |
| 427 | rx_queue = priv->rx_queue[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
| 429 | rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 430 | rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 431 | rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE; |
| 432 | rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE; |
| 433 | |
| 434 | /* Values changeable by the user. The valid values are |
| 435 | * in the range 1 to the "*_max_pending" counterpart above. |
| 436 | */ |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 437 | rvals->rx_pending = rx_queue->rx_ring_size; |
| 438 | rvals->rx_mini_pending = rx_queue->rx_ring_size; |
| 439 | rvals->rx_jumbo_pending = rx_queue->rx_ring_size; |
| 440 | rvals->tx_pending = tx_queue->tx_ring_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /* Change the current ring parameters, stopping the controller if |
Claudiu Manoil | 7cca336 | 2014-02-17 12:53:19 +0200 | [diff] [blame] | 444 | * necessary so that we don't mess things up while we're in motion. |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 445 | */ |
| 446 | static int gfar_sringparam(struct net_device *dev, |
| 447 | struct ethtool_ringparam *rvals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | struct gfar_private *priv = netdev_priv(dev); |
Claudiu Manoil | 7cca336 | 2014-02-17 12:53:19 +0200 | [diff] [blame] | 450 | int err = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) |
| 453 | return -EINVAL; |
| 454 | |
| 455 | if (!is_power_of_2(rvals->rx_pending)) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 456 | netdev_err(dev, "Ring sizes must be a power of 2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return -EINVAL; |
| 458 | } |
| 459 | |
| 460 | if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE) |
| 461 | return -EINVAL; |
| 462 | |
| 463 | if (!is_power_of_2(rvals->tx_pending)) { |
Joe Perches | 59deab2 | 2011-06-14 08:57:47 +0000 | [diff] [blame] | 464 | netdev_err(dev, "Ring sizes must be a power of 2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | return -EINVAL; |
| 466 | } |
| 467 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 468 | while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state)) |
| 469 | cpu_relax(); |
| 470 | |
Claudiu Manoil | 7cca336 | 2014-02-17 12:53:19 +0200 | [diff] [blame] | 471 | if (dev->flags & IFF_UP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | stop_gfar(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Claudiu Manoil | 7cca336 | 2014-02-17 12:53:19 +0200 | [diff] [blame] | 474 | /* Change the sizes */ |
| 475 | for (i = 0; i < priv->num_rx_queues; i++) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 476 | priv->rx_queue[i]->rx_ring_size = rvals->rx_pending; |
Claudiu Manoil | 7cca336 | 2014-02-17 12:53:19 +0200 | [diff] [blame] | 477 | |
| 478 | for (i = 0; i < priv->num_tx_queues; i++) |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 479 | priv->tx_queue[i]->tx_ring_size = rvals->tx_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 481 | /* Rebuild the rings with the new size */ |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 482 | if (dev->flags & IFF_UP) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 483 | err = startup_gfar(dev); |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 484 | |
| 485 | clear_bit_unlock(GFAR_RESETTING, &priv->state); |
| 486 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 487 | return err; |
| 488 | } |
| 489 | |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 490 | static void gfar_gpauseparam(struct net_device *dev, |
| 491 | struct ethtool_pauseparam *epause) |
| 492 | { |
| 493 | struct gfar_private *priv = netdev_priv(dev); |
| 494 | |
| 495 | epause->autoneg = !!priv->pause_aneg_en; |
| 496 | epause->rx_pause = !!priv->rx_pause_en; |
| 497 | epause->tx_pause = !!priv->tx_pause_en; |
| 498 | } |
| 499 | |
| 500 | static int gfar_spauseparam(struct net_device *dev, |
| 501 | struct ethtool_pauseparam *epause) |
| 502 | { |
| 503 | struct gfar_private *priv = netdev_priv(dev); |
Philippe Reynes | 4c4a6b0 | 2016-05-16 01:30:08 +0200 | [diff] [blame] | 504 | struct phy_device *phydev = dev->phydev; |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 505 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 506 | |
Claudiu Manoil | 98a46d4 | 2014-04-23 16:38:47 +0300 | [diff] [blame] | 507 | if (!phydev) |
| 508 | return -ENODEV; |
| 509 | |
Andrew Lunn | 22b7d29 | 2018-09-12 01:53:19 +0200 | [diff] [blame] | 510 | if (!phy_validate_pause(phydev, epause)) |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 511 | return -EINVAL; |
| 512 | |
| 513 | priv->rx_pause_en = priv->tx_pause_en = 0; |
Andrew Lunn | 70814e8 | 2018-09-12 01:53:17 +0200 | [diff] [blame] | 514 | phy_set_asym_pause(phydev, epause->rx_pause, epause->tx_pause); |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 515 | if (epause->rx_pause) { |
| 516 | priv->rx_pause_en = 1; |
| 517 | |
| 518 | if (epause->tx_pause) { |
| 519 | priv->tx_pause_en = 1; |
Andrew Lunn | 70814e8 | 2018-09-12 01:53:17 +0200 | [diff] [blame] | 520 | } |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 521 | } else if (epause->tx_pause) { |
| 522 | priv->tx_pause_en = 1; |
Andrew Lunn | 70814e8 | 2018-09-12 01:53:17 +0200 | [diff] [blame] | 523 | } |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 524 | |
| 525 | if (epause->autoneg) |
| 526 | priv->pause_aneg_en = 1; |
| 527 | else |
| 528 | priv->pause_aneg_en = 0; |
| 529 | |
Andrew Lunn | 70814e8 | 2018-09-12 01:53:17 +0200 | [diff] [blame] | 530 | if (!epause->autoneg) { |
| 531 | u32 tempval = gfar_read(®s->maccfg1); |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 532 | |
Andrew Lunn | 70814e8 | 2018-09-12 01:53:17 +0200 | [diff] [blame] | 533 | tempval &= ~(MACCFG1_TX_FLOW | MACCFG1_RX_FLOW); |
Matei Pavaluca | 45b679c9 | 2014-10-27 10:42:44 +0200 | [diff] [blame] | 534 | |
Andrew Lunn | 70814e8 | 2018-09-12 01:53:17 +0200 | [diff] [blame] | 535 | priv->tx_actual_en = 0; |
| 536 | if (priv->tx_pause_en) { |
| 537 | priv->tx_actual_en = 1; |
| 538 | tempval |= MACCFG1_TX_FLOW; |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 539 | } |
Andrew Lunn | 70814e8 | 2018-09-12 01:53:17 +0200 | [diff] [blame] | 540 | |
| 541 | if (priv->rx_pause_en) |
| 542 | tempval |= MACCFG1_RX_FLOW; |
| 543 | gfar_write(®s->maccfg1, tempval); |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 549 | int gfar_set_features(struct net_device *dev, netdev_features_t features) |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 550 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 551 | netdev_features_t changed = dev->features ^ features; |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 552 | struct gfar_private *priv = netdev_priv(dev); |
Claudiu Manoil | 7cca336 | 2014-02-17 12:53:19 +0200 | [diff] [blame] | 553 | int err = 0; |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 554 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 555 | if (!(changed & (NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX | |
| 556 | NETIF_F_RXCSUM))) |
Michał Mirosław | 8b3afe9 | 2011-04-15 04:50:50 +0000 | [diff] [blame] | 557 | return 0; |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 558 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 559 | while (test_and_set_bit_lock(GFAR_RESETTING, &priv->state)) |
| 560 | cpu_relax(); |
| 561 | |
Claudiu Manoil | 8830264 | 2014-02-24 12:13:43 +0200 | [diff] [blame] | 562 | dev->features = features; |
| 563 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 564 | if (dev->flags & IFF_UP) { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 565 | /* Now we take down the rings to rebuild them */ |
| 566 | stop_gfar(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | err = startup_gfar(dev); |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 568 | } else { |
| 569 | gfar_mac_reset(priv); |
Dai Haruki | 12dea57 | 2008-12-16 15:30:20 -0800 | [diff] [blame] | 570 | } |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 571 | |
| 572 | clear_bit_unlock(GFAR_RESETTING, &priv->state); |
| 573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | return err; |
| 575 | } |
| 576 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 577 | static uint32_t gfar_get_msglevel(struct net_device *dev) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 578 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 579 | struct gfar_private *priv = netdev_priv(dev); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 580 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 581 | return priv->msg_enable; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 582 | } |
| 583 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 584 | static void gfar_set_msglevel(struct net_device *dev, uint32_t data) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 585 | { |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 586 | struct gfar_private *priv = netdev_priv(dev); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 587 | |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 588 | priv->msg_enable = data; |
| 589 | } |
| 590 | |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 591 | #ifdef CONFIG_PM |
| 592 | static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 593 | { |
| 594 | struct gfar_private *priv = netdev_priv(dev); |
| 595 | |
Claudiu Manoil | 3e905b8 | 2015-10-05 17:19:59 +0300 | [diff] [blame] | 596 | wol->supported = 0; |
| 597 | wol->wolopts = 0; |
| 598 | |
| 599 | if (priv->wol_supported & GFAR_WOL_MAGIC) |
| 600 | wol->supported |= WAKE_MAGIC; |
| 601 | |
| 602 | if (priv->wol_supported & GFAR_WOL_FILER_UCAST) |
| 603 | wol->supported |= WAKE_UCAST; |
| 604 | |
| 605 | if (priv->wol_opts & GFAR_WOL_MAGIC) |
| 606 | wol->wolopts |= WAKE_MAGIC; |
| 607 | |
| 608 | if (priv->wol_opts & GFAR_WOL_FILER_UCAST) |
| 609 | wol->wolopts |= WAKE_UCAST; |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 613 | { |
| 614 | struct gfar_private *priv = netdev_priv(dev); |
Claudiu Manoil | 3e905b8 | 2015-10-05 17:19:59 +0300 | [diff] [blame] | 615 | u16 wol_opts = 0; |
| 616 | int err; |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 617 | |
Claudiu Manoil | 3e905b8 | 2015-10-05 17:19:59 +0300 | [diff] [blame] | 618 | if (!priv->wol_supported && wol->wolopts) |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 619 | return -EINVAL; |
| 620 | |
Claudiu Manoil | 3e905b8 | 2015-10-05 17:19:59 +0300 | [diff] [blame] | 621 | if (wol->wolopts & ~(WAKE_MAGIC | WAKE_UCAST)) |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 622 | return -EINVAL; |
| 623 | |
Claudiu Manoil | 3e905b8 | 2015-10-05 17:19:59 +0300 | [diff] [blame] | 624 | if (wol->wolopts & WAKE_MAGIC) { |
| 625 | wol_opts |= GFAR_WOL_MAGIC; |
| 626 | } else { |
| 627 | if (wol->wolopts & WAKE_UCAST) |
| 628 | wol_opts |= GFAR_WOL_FILER_UCAST; |
| 629 | } |
Rafael J. Wysocki | 6c4f199 | 2010-11-09 11:54:19 +0000 | [diff] [blame] | 630 | |
Claudiu Manoil | 3e905b8 | 2015-10-05 17:19:59 +0300 | [diff] [blame] | 631 | wol_opts &= priv->wol_supported; |
| 632 | priv->wol_opts = 0; |
| 633 | |
| 634 | err = device_set_wakeup_enable(priv->dev, wol_opts); |
| 635 | if (err) |
| 636 | return err; |
| 637 | |
| 638 | priv->wol_opts = wol_opts; |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | #endif |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 643 | |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 644 | static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow) |
| 645 | { |
| 646 | u32 fcr = 0x0, fpr = FPR_FILER_MASK; |
| 647 | |
| 648 | if (ethflow & RXH_L2DA) { |
Claudiu Manoil | 5188f7e | 2015-10-23 11:41:58 +0300 | [diff] [blame] | 649 | fcr = RQFCR_PID_DAH | RQFCR_CMP_NOMATCH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 650 | RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 651 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 652 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 653 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 654 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 655 | |
Claudiu Manoil | 5188f7e | 2015-10-23 11:41:58 +0300 | [diff] [blame] | 656 | fcr = RQFCR_PID_DAL | RQFCR_CMP_NOMATCH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 657 | RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 658 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 659 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 660 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 661 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 662 | } |
| 663 | |
| 664 | if (ethflow & RXH_VLAN) { |
| 665 | fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 666 | RQFCR_AND | RQFCR_HASHTBL_0; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 667 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 668 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 669 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 670 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 671 | } |
| 672 | |
| 673 | if (ethflow & RXH_IP_SRC) { |
| 674 | fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 675 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 676 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 677 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 678 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 679 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 680 | } |
| 681 | |
| 682 | if (ethflow & (RXH_IP_DST)) { |
| 683 | fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 684 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 685 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 686 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 687 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 688 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 689 | } |
| 690 | |
| 691 | if (ethflow & RXH_L3_PROTO) { |
| 692 | fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 693 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 694 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 695 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 696 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 697 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 698 | } |
| 699 | |
| 700 | if (ethflow & RXH_L4_B_0_1) { |
| 701 | fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 702 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 703 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 704 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 705 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 706 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 707 | } |
| 708 | |
| 709 | if (ethflow & RXH_L4_B_2_3) { |
| 710 | fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 711 | RQFCR_AND | RQFCR_HASHTBL_0; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 712 | priv->ftp_rqfpr[priv->cur_filer_idx] = fpr; |
| 713 | priv->ftp_rqfcr[priv->cur_filer_idx] = fcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 714 | gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr); |
| 715 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 716 | } |
| 717 | } |
| 718 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 719 | static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, |
| 720 | u64 class) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 721 | { |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 722 | unsigned int cmp_rqfpr; |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 723 | unsigned int *local_rqfpr; |
| 724 | unsigned int *local_rqfcr; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 725 | int i = 0x0, k = 0x0; |
| 726 | int j = MAX_FILER_IDX, l = 0x0; |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 727 | int ret = 1; |
| 728 | |
Joe Perches | b2adaca | 2013-02-03 17:43:58 +0000 | [diff] [blame] | 729 | local_rqfpr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int), |
| 730 | GFP_KERNEL); |
| 731 | local_rqfcr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int), |
| 732 | GFP_KERNEL); |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 733 | if (!local_rqfpr || !local_rqfcr) { |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 734 | ret = 0; |
| 735 | goto err; |
| 736 | } |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 737 | |
| 738 | switch (class) { |
| 739 | case TCP_V4_FLOW: |
| 740 | cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP; |
| 741 | break; |
| 742 | case UDP_V4_FLOW: |
| 743 | cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP; |
| 744 | break; |
| 745 | case TCP_V6_FLOW: |
| 746 | cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP; |
| 747 | break; |
| 748 | case UDP_V6_FLOW: |
| 749 | cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP; |
| 750 | break; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 751 | default: |
Joe Perches | 375d6a1 | 2013-04-13 19:03:18 +0000 | [diff] [blame] | 752 | netdev_err(priv->ndev, |
| 753 | "Right now this class is not supported\n"); |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 754 | ret = 0; |
| 755 | goto err; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | for (i = 0; i < MAX_FILER_IDX + 1; i++) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 759 | local_rqfpr[j] = priv->ftp_rqfpr[i]; |
| 760 | local_rqfcr[j] = priv->ftp_rqfcr[i]; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 761 | j--; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 762 | if ((priv->ftp_rqfcr[i] == |
| 763 | (RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND)) && |
| 764 | (priv->ftp_rqfpr[i] == cmp_rqfpr)) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 765 | break; |
| 766 | } |
| 767 | |
| 768 | if (i == MAX_FILER_IDX + 1) { |
Joe Perches | 375d6a1 | 2013-04-13 19:03:18 +0000 | [diff] [blame] | 769 | netdev_err(priv->ndev, |
| 770 | "No parse rule found, can't create hash rules\n"); |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 771 | ret = 0; |
| 772 | goto err; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /* If a match was found, then it begins the starting of a cluster rule |
| 776 | * if it was already programmed, we need to overwrite these rules |
| 777 | */ |
| 778 | for (l = i+1; l < MAX_FILER_IDX; l++) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 779 | if ((priv->ftp_rqfcr[l] & RQFCR_CLE) && |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 780 | !(priv->ftp_rqfcr[l] & RQFCR_AND)) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 781 | priv->ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 782 | RQFCR_HASHTBL_0 | RQFCR_PID_MASK; |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 783 | priv->ftp_rqfpr[l] = FPR_FILER_MASK; |
| 784 | gfar_write_filer(priv, l, priv->ftp_rqfcr[l], |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 785 | priv->ftp_rqfpr[l]); |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 786 | break; |
| 787 | } |
| 788 | |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 789 | if (!(priv->ftp_rqfcr[l] & RQFCR_CLE) && |
| 790 | (priv->ftp_rqfcr[l] & RQFCR_AND)) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 791 | continue; |
| 792 | else { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 793 | local_rqfpr[j] = priv->ftp_rqfpr[l]; |
| 794 | local_rqfcr[j] = priv->ftp_rqfcr[l]; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 795 | j--; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | priv->cur_filer_idx = l - 1; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 800 | |
| 801 | /* hash rules */ |
| 802 | ethflow_to_filer_rules(priv, ethflow); |
| 803 | |
| 804 | /* Write back the popped out rules again */ |
| 805 | for (k = j+1; k < MAX_FILER_IDX; k++) { |
Wu Jiajun-B06378 | 6c43e04 | 2011-06-07 21:46:51 +0000 | [diff] [blame] | 806 | priv->ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k]; |
| 807 | priv->ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k]; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 808 | gfar_write_filer(priv, priv->cur_filer_idx, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 809 | local_rqfcr[k], local_rqfpr[k]); |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 810 | if (!priv->cur_filer_idx) |
| 811 | break; |
| 812 | priv->cur_filer_idx = priv->cur_filer_idx - 1; |
| 813 | } |
| 814 | |
Wang Shaoyan | 588dc91 | 2011-08-11 17:07:25 +0000 | [diff] [blame] | 815 | err: |
| 816 | kfree(local_rqfcr); |
| 817 | kfree(local_rqfpr); |
| 818 | return ret; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 821 | static int gfar_set_hash_opts(struct gfar_private *priv, |
| 822 | struct ethtool_rxnfc *cmd) |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 823 | { |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 824 | /* write the filer rules here */ |
| 825 | if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type)) |
Ben Hutchings | bde3528 | 2011-04-08 13:45:11 +0000 | [diff] [blame] | 826 | return -EINVAL; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 831 | static int gfar_check_filer_hardware(struct gfar_private *priv) |
| 832 | { |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 833 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 834 | u32 i; |
| 835 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 836 | /* Check if we are in FIFO mode */ |
| 837 | i = gfar_read(®s->ecntrl); |
| 838 | i &= ECNTRL_FIFM; |
| 839 | if (i == ECNTRL_FIFM) { |
| 840 | netdev_notice(priv->ndev, "Interface in FIFO mode\n"); |
| 841 | i = gfar_read(®s->rctrl); |
| 842 | i &= RCTRL_PRSDEP_MASK | RCTRL_PRSFM; |
| 843 | if (i == (RCTRL_PRSDEP_MASK | RCTRL_PRSFM)) { |
| 844 | netdev_info(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 845 | "Receive Queue Filtering enabled\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 846 | } else { |
| 847 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 848 | "Receive Queue Filtering disabled\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 849 | return -EOPNOTSUPP; |
| 850 | } |
| 851 | } |
| 852 | /* Or in standard mode */ |
| 853 | else { |
| 854 | i = gfar_read(®s->rctrl); |
| 855 | i &= RCTRL_PRSDEP_MASK; |
| 856 | if (i == RCTRL_PRSDEP_MASK) { |
| 857 | netdev_info(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 858 | "Receive Queue Filtering enabled\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 859 | } else { |
| 860 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 861 | "Receive Queue Filtering disabled\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 862 | return -EOPNOTSUPP; |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | /* Sets the properties for arbitrary filer rule |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 867 | * to the first 4 Layer 4 Bytes |
| 868 | */ |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 869 | gfar_write(®s->rbifx, 0xC0C1C2C3); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 870 | return 0; |
| 871 | } |
| 872 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 873 | /* Write a mask to filer cache */ |
| 874 | static void gfar_set_mask(u32 mask, struct filer_table *tab) |
| 875 | { |
| 876 | tab->fe[tab->index].ctrl = RQFCR_AND | RQFCR_PID_MASK | RQFCR_CMP_EXACT; |
| 877 | tab->fe[tab->index].prop = mask; |
| 878 | tab->index++; |
| 879 | } |
| 880 | |
| 881 | /* Sets parse bits (e.g. IP or TCP) */ |
| 882 | static void gfar_set_parse_bits(u32 value, u32 mask, struct filer_table *tab) |
| 883 | { |
| 884 | gfar_set_mask(mask, tab); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 885 | tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_PID_PARSE | |
| 886 | RQFCR_AND; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 887 | tab->fe[tab->index].prop = value; |
| 888 | tab->index++; |
| 889 | } |
| 890 | |
| 891 | static void gfar_set_general_attribute(u32 value, u32 mask, u32 flag, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 892 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 893 | { |
| 894 | gfar_set_mask(mask, tab); |
| 895 | tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_AND | flag; |
| 896 | tab->fe[tab->index].prop = value; |
| 897 | tab->index++; |
| 898 | } |
| 899 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 900 | /* For setting a tuple of value and mask of type flag |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 901 | * Example: |
| 902 | * IP-Src = 10.0.0.0/255.0.0.0 |
| 903 | * value: 0x0A000000 mask: FF000000 flag: RQFPR_IPV4 |
| 904 | * |
| 905 | * Ethtool gives us a value=0 and mask=~0 for don't care a tuple |
| 906 | * For a don't care mask it gives us a 0 |
| 907 | * |
| 908 | * The check if don't care and the mask adjustment if mask=0 is done for VLAN |
| 909 | * and MAC stuff on an upper level (due to missing information on this level). |
| 910 | * For these guys we can discard them if they are value=0 and mask=0. |
| 911 | * |
| 912 | * Further the all masks are one-padded for better hardware efficiency. |
| 913 | */ |
| 914 | static void gfar_set_attribute(u32 value, u32 mask, u32 flag, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 915 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 916 | { |
| 917 | switch (flag) { |
Sebastian Poehn | 380b153 | 2011-07-07 04:30:29 -0700 | [diff] [blame] | 918 | /* 3bit */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 919 | case RQFCR_PID_PRI: |
| 920 | if (!(value | mask)) |
| 921 | return; |
| 922 | mask |= RQFCR_PID_PRI_MASK; |
| 923 | break; |
| 924 | /* 8bit */ |
| 925 | case RQFCR_PID_L4P: |
| 926 | case RQFCR_PID_TOS: |
| 927 | if (!~(mask | RQFCR_PID_L4P_MASK)) |
| 928 | return; |
| 929 | if (!mask) |
| 930 | mask = ~0; |
| 931 | else |
| 932 | mask |= RQFCR_PID_L4P_MASK; |
| 933 | break; |
| 934 | /* 12bit */ |
| 935 | case RQFCR_PID_VID: |
| 936 | if (!(value | mask)) |
| 937 | return; |
| 938 | mask |= RQFCR_PID_VID_MASK; |
| 939 | break; |
| 940 | /* 16bit */ |
| 941 | case RQFCR_PID_DPT: |
| 942 | case RQFCR_PID_SPT: |
| 943 | case RQFCR_PID_ETY: |
| 944 | if (!~(mask | RQFCR_PID_PORT_MASK)) |
| 945 | return; |
| 946 | if (!mask) |
| 947 | mask = ~0; |
| 948 | else |
| 949 | mask |= RQFCR_PID_PORT_MASK; |
| 950 | break; |
| 951 | /* 24bit */ |
| 952 | case RQFCR_PID_DAH: |
| 953 | case RQFCR_PID_DAL: |
| 954 | case RQFCR_PID_SAH: |
| 955 | case RQFCR_PID_SAL: |
| 956 | if (!(value | mask)) |
| 957 | return; |
| 958 | mask |= RQFCR_PID_MAC_MASK; |
| 959 | break; |
| 960 | /* for all real 32bit masks */ |
| 961 | default: |
| 962 | if (!~mask) |
| 963 | return; |
| 964 | if (!mask) |
| 965 | mask = ~0; |
| 966 | break; |
| 967 | } |
| 968 | gfar_set_general_attribute(value, mask, flag, tab); |
| 969 | } |
| 970 | |
| 971 | /* Translates value and mask for UDP, TCP or SCTP */ |
| 972 | static void gfar_set_basic_ip(struct ethtool_tcpip4_spec *value, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 973 | struct ethtool_tcpip4_spec *mask, |
| 974 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 975 | { |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 976 | gfar_set_attribute(be32_to_cpu(value->ip4src), |
| 977 | be32_to_cpu(mask->ip4src), |
| 978 | RQFCR_PID_SIA, tab); |
| 979 | gfar_set_attribute(be32_to_cpu(value->ip4dst), |
| 980 | be32_to_cpu(mask->ip4dst), |
| 981 | RQFCR_PID_DIA, tab); |
| 982 | gfar_set_attribute(be16_to_cpu(value->pdst), |
| 983 | be16_to_cpu(mask->pdst), |
| 984 | RQFCR_PID_DPT, tab); |
| 985 | gfar_set_attribute(be16_to_cpu(value->psrc), |
| 986 | be16_to_cpu(mask->psrc), |
| 987 | RQFCR_PID_SPT, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 988 | gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab); |
| 989 | } |
| 990 | |
| 991 | /* Translates value and mask for RAW-IP4 */ |
| 992 | static void gfar_set_user_ip(struct ethtool_usrip4_spec *value, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 993 | struct ethtool_usrip4_spec *mask, |
| 994 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 995 | { |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 996 | gfar_set_attribute(be32_to_cpu(value->ip4src), |
| 997 | be32_to_cpu(mask->ip4src), |
| 998 | RQFCR_PID_SIA, tab); |
| 999 | gfar_set_attribute(be32_to_cpu(value->ip4dst), |
| 1000 | be32_to_cpu(mask->ip4dst), |
| 1001 | RQFCR_PID_DIA, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1002 | gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab); |
| 1003 | gfar_set_attribute(value->proto, mask->proto, RQFCR_PID_L4P, tab); |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 1004 | gfar_set_attribute(be32_to_cpu(value->l4_4_bytes), |
| 1005 | be32_to_cpu(mask->l4_4_bytes), |
| 1006 | RQFCR_PID_ARB, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1007 | |
| 1008 | } |
| 1009 | |
| 1010 | /* Translates value and mask for ETHER spec */ |
| 1011 | static void gfar_set_ether(struct ethhdr *value, struct ethhdr *mask, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1012 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1013 | { |
| 1014 | u32 upper_temp_mask = 0; |
| 1015 | u32 lower_temp_mask = 0; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1016 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1017 | /* Source address */ |
| 1018 | if (!is_broadcast_ether_addr(mask->h_source)) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1019 | if (is_zero_ether_addr(mask->h_source)) { |
| 1020 | upper_temp_mask = 0xFFFFFFFF; |
| 1021 | lower_temp_mask = 0xFFFFFFFF; |
| 1022 | } else { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1023 | upper_temp_mask = mask->h_source[0] << 16 | |
| 1024 | mask->h_source[1] << 8 | |
| 1025 | mask->h_source[2]; |
| 1026 | lower_temp_mask = mask->h_source[3] << 16 | |
| 1027 | mask->h_source[4] << 8 | |
| 1028 | mask->h_source[5]; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1029 | } |
| 1030 | /* Upper 24bit */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1031 | gfar_set_attribute(value->h_source[0] << 16 | |
| 1032 | value->h_source[1] << 8 | |
| 1033 | value->h_source[2], |
| 1034 | upper_temp_mask, RQFCR_PID_SAH, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1035 | /* And the same for the lower part */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1036 | gfar_set_attribute(value->h_source[3] << 16 | |
| 1037 | value->h_source[4] << 8 | |
| 1038 | value->h_source[5], |
| 1039 | lower_temp_mask, RQFCR_PID_SAL, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1040 | } |
| 1041 | /* Destination address */ |
| 1042 | if (!is_broadcast_ether_addr(mask->h_dest)) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1043 | /* Special for destination is limited broadcast */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1044 | if ((is_broadcast_ether_addr(value->h_dest) && |
| 1045 | is_zero_ether_addr(mask->h_dest))) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1046 | gfar_set_parse_bits(RQFPR_EBC, RQFPR_EBC, tab); |
| 1047 | } else { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1048 | if (is_zero_ether_addr(mask->h_dest)) { |
| 1049 | upper_temp_mask = 0xFFFFFFFF; |
| 1050 | lower_temp_mask = 0xFFFFFFFF; |
| 1051 | } else { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1052 | upper_temp_mask = mask->h_dest[0] << 16 | |
| 1053 | mask->h_dest[1] << 8 | |
| 1054 | mask->h_dest[2]; |
| 1055 | lower_temp_mask = mask->h_dest[3] << 16 | |
| 1056 | mask->h_dest[4] << 8 | |
| 1057 | mask->h_dest[5]; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | /* Upper 24bit */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1061 | gfar_set_attribute(value->h_dest[0] << 16 | |
| 1062 | value->h_dest[1] << 8 | |
| 1063 | value->h_dest[2], |
| 1064 | upper_temp_mask, RQFCR_PID_DAH, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1065 | /* And the same for the lower part */ |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1066 | gfar_set_attribute(value->h_dest[3] << 16 | |
| 1067 | value->h_dest[4] << 8 | |
| 1068 | value->h_dest[5], |
| 1069 | lower_temp_mask, RQFCR_PID_DAL, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 1073 | gfar_set_attribute(be16_to_cpu(value->h_proto), |
| 1074 | be16_to_cpu(mask->h_proto), |
| 1075 | RQFCR_PID_ETY, tab); |
| 1076 | } |
| 1077 | |
| 1078 | static inline u32 vlan_tci_vid(struct ethtool_rx_flow_spec *rule) |
| 1079 | { |
| 1080 | return be16_to_cpu(rule->h_ext.vlan_tci) & VLAN_VID_MASK; |
| 1081 | } |
| 1082 | |
| 1083 | static inline u32 vlan_tci_vidm(struct ethtool_rx_flow_spec *rule) |
| 1084 | { |
| 1085 | return be16_to_cpu(rule->m_ext.vlan_tci) & VLAN_VID_MASK; |
| 1086 | } |
| 1087 | |
| 1088 | static inline u32 vlan_tci_cfi(struct ethtool_rx_flow_spec *rule) |
| 1089 | { |
| 1090 | return be16_to_cpu(rule->h_ext.vlan_tci) & VLAN_CFI_MASK; |
| 1091 | } |
| 1092 | |
| 1093 | static inline u32 vlan_tci_cfim(struct ethtool_rx_flow_spec *rule) |
| 1094 | { |
| 1095 | return be16_to_cpu(rule->m_ext.vlan_tci) & VLAN_CFI_MASK; |
| 1096 | } |
| 1097 | |
| 1098 | static inline u32 vlan_tci_prio(struct ethtool_rx_flow_spec *rule) |
| 1099 | { |
| 1100 | return (be16_to_cpu(rule->h_ext.vlan_tci) & VLAN_PRIO_MASK) >> |
| 1101 | VLAN_PRIO_SHIFT; |
| 1102 | } |
| 1103 | |
| 1104 | static inline u32 vlan_tci_priom(struct ethtool_rx_flow_spec *rule) |
| 1105 | { |
| 1106 | return (be16_to_cpu(rule->m_ext.vlan_tci) & VLAN_PRIO_MASK) >> |
| 1107 | VLAN_PRIO_SHIFT; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /* Convert a rule to binary filter format of gianfar */ |
| 1111 | static int gfar_convert_to_filer(struct ethtool_rx_flow_spec *rule, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1112 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1113 | { |
| 1114 | u32 vlan = 0, vlan_mask = 0; |
| 1115 | u32 id = 0, id_mask = 0; |
| 1116 | u32 cfi = 0, cfi_mask = 0; |
| 1117 | u32 prio = 0, prio_mask = 0; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1118 | u32 old_index = tab->index; |
| 1119 | |
| 1120 | /* Check if vlan is wanted */ |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 1121 | if ((rule->flow_type & FLOW_EXT) && |
| 1122 | (rule->m_ext.vlan_tci != cpu_to_be16(0xFFFF))) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1123 | if (!rule->m_ext.vlan_tci) |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 1124 | rule->m_ext.vlan_tci = cpu_to_be16(0xFFFF); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1125 | |
| 1126 | vlan = RQFPR_VLN; |
| 1127 | vlan_mask = RQFPR_VLN; |
| 1128 | |
| 1129 | /* Separate the fields */ |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 1130 | id = vlan_tci_vid(rule); |
| 1131 | id_mask = vlan_tci_vidm(rule); |
| 1132 | cfi = vlan_tci_cfi(rule); |
| 1133 | cfi_mask = vlan_tci_cfim(rule); |
| 1134 | prio = vlan_tci_prio(rule); |
| 1135 | prio_mask = vlan_tci_priom(rule); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1136 | |
Michał Mirosław | f4f9a5e | 2018-11-08 18:44:50 +0100 | [diff] [blame] | 1137 | if (cfi_mask) { |
| 1138 | if (cfi) |
| 1139 | vlan |= RQFPR_CFI; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1140 | vlan_mask |= RQFPR_CFI; |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | switch (rule->flow_type & ~FLOW_EXT) { |
| 1145 | case TCP_V4_FLOW: |
| 1146 | gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_TCP | vlan, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1147 | RQFPR_IPV4 | RQFPR_TCP | vlan_mask, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1148 | gfar_set_basic_ip(&rule->h_u.tcp_ip4_spec, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1149 | &rule->m_u.tcp_ip4_spec, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1150 | break; |
| 1151 | case UDP_V4_FLOW: |
| 1152 | gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_UDP | vlan, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1153 | RQFPR_IPV4 | RQFPR_UDP | vlan_mask, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1154 | gfar_set_basic_ip(&rule->h_u.udp_ip4_spec, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1155 | &rule->m_u.udp_ip4_spec, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1156 | break; |
| 1157 | case SCTP_V4_FLOW: |
| 1158 | gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1159 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1160 | gfar_set_attribute(132, 0, RQFCR_PID_L4P, tab); |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1161 | gfar_set_basic_ip((struct ethtool_tcpip4_spec *)&rule->h_u, |
| 1162 | (struct ethtool_tcpip4_spec *)&rule->m_u, |
| 1163 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1164 | break; |
| 1165 | case IP_USER_FLOW: |
| 1166 | gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1167 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1168 | gfar_set_user_ip((struct ethtool_usrip4_spec *) &rule->h_u, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1169 | (struct ethtool_usrip4_spec *) &rule->m_u, |
| 1170 | tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1171 | break; |
| 1172 | case ETHER_FLOW: |
| 1173 | if (vlan) |
| 1174 | gfar_set_parse_bits(vlan, vlan_mask, tab); |
| 1175 | gfar_set_ether((struct ethhdr *) &rule->h_u, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1176 | (struct ethhdr *) &rule->m_u, tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1177 | break; |
| 1178 | default: |
| 1179 | return -1; |
| 1180 | } |
| 1181 | |
| 1182 | /* Set the vlan attributes in the end */ |
| 1183 | if (vlan) { |
| 1184 | gfar_set_attribute(id, id_mask, RQFCR_PID_VID, tab); |
| 1185 | gfar_set_attribute(prio, prio_mask, RQFCR_PID_PRI, tab); |
| 1186 | } |
| 1187 | |
| 1188 | /* If there has been nothing written till now, it must be a default */ |
| 1189 | if (tab->index == old_index) { |
| 1190 | gfar_set_mask(0xFFFFFFFF, tab); |
| 1191 | tab->fe[tab->index].ctrl = 0x20; |
| 1192 | tab->fe[tab->index].prop = 0x0; |
| 1193 | tab->index++; |
| 1194 | } |
| 1195 | |
| 1196 | /* Remove last AND */ |
| 1197 | tab->fe[tab->index - 1].ctrl &= (~RQFCR_AND); |
| 1198 | |
| 1199 | /* Specify which queue to use or to drop */ |
| 1200 | if (rule->ring_cookie == RX_CLS_FLOW_DISC) |
| 1201 | tab->fe[tab->index - 1].ctrl |= RQFCR_RJE; |
| 1202 | else |
| 1203 | tab->fe[tab->index - 1].ctrl |= (rule->ring_cookie << 10); |
| 1204 | |
| 1205 | /* Only big enough entries can be clustered */ |
| 1206 | if (tab->index > (old_index + 2)) { |
| 1207 | tab->fe[old_index + 1].ctrl |= RQFCR_CLE; |
| 1208 | tab->fe[tab->index - 1].ctrl |= RQFCR_CLE; |
| 1209 | } |
| 1210 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1211 | /* In rare cases the cache can be full while there is |
| 1212 | * free space in hw |
| 1213 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1214 | if (tab->index > MAX_FILER_CACHE_IDX - 1) |
| 1215 | return -EBUSY; |
| 1216 | |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1220 | /* Write the bit-pattern from software's buffer to hardware registers */ |
| 1221 | static int gfar_write_filer_table(struct gfar_private *priv, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1222 | struct filer_table *tab) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1223 | { |
| 1224 | u32 i = 0; |
| 1225 | if (tab->index > MAX_FILER_IDX - 1) |
| 1226 | return -EBUSY; |
| 1227 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1228 | /* Fill regular entries */ |
Jakub Kicinski | a898fe0 | 2015-08-12 02:41:55 +0200 | [diff] [blame] | 1229 | for (; i < MAX_FILER_IDX && (tab->fe[i].ctrl | tab->fe[i].prop); i++) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1230 | gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop); |
| 1231 | /* Fill the rest with fall-troughs */ |
Jakub Kicinski | a898fe0 | 2015-08-12 02:41:55 +0200 | [diff] [blame] | 1232 | for (; i < MAX_FILER_IDX; i++) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1233 | gfar_write_filer(priv, i, 0x60, 0xFFFFFFFF); |
| 1234 | /* Last entry must be default accept |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1235 | * because that's what people expect |
| 1236 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1237 | gfar_write_filer(priv, i, 0x20, 0x0); |
| 1238 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | static int gfar_check_capability(struct ethtool_rx_flow_spec *flow, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1243 | struct gfar_private *priv) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1244 | { |
| 1245 | |
| 1246 | if (flow->flow_type & FLOW_EXT) { |
| 1247 | if (~flow->m_ext.data[0] || ~flow->m_ext.data[1]) |
| 1248 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1249 | "User-specific data not supported!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1250 | if (~flow->m_ext.vlan_etype) |
| 1251 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1252 | "VLAN-etype not supported!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1253 | } |
| 1254 | if (flow->flow_type == IP_USER_FLOW) |
| 1255 | if (flow->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4) |
| 1256 | netdev_warn(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1257 | "IP-Version differing from IPv4 not supported!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1258 | |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
| 1262 | static int gfar_process_filer_changes(struct gfar_private *priv) |
| 1263 | { |
| 1264 | struct ethtool_flow_spec_container *j; |
| 1265 | struct filer_table *tab; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1266 | s32 ret = 0; |
| 1267 | |
| 1268 | /* So index is set to zero, too! */ |
| 1269 | tab = kzalloc(sizeof(*tab), GFP_KERNEL); |
| 1270 | if (tab == NULL) |
| 1271 | return -ENOMEM; |
| 1272 | |
| 1273 | /* Now convert the existing filer data from flow_spec into |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1274 | * filer tables binary format |
| 1275 | */ |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1276 | list_for_each_entry(j, &priv->rx_list.list, list) { |
| 1277 | ret = gfar_convert_to_filer(&j->fs, tab); |
| 1278 | if (ret == -EBUSY) { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1279 | netdev_err(priv->ndev, |
| 1280 | "Rule not added: No free space!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1281 | goto end; |
| 1282 | } |
| 1283 | if (ret == -1) { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1284 | netdev_err(priv->ndev, |
| 1285 | "Rule not added: Unsupported Flow-type!\n"); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1286 | goto end; |
| 1287 | } |
| 1288 | } |
| 1289 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1290 | /* Write everything to hardware */ |
| 1291 | ret = gfar_write_filer_table(priv, tab); |
| 1292 | if (ret == -EBUSY) { |
| 1293 | netdev_err(priv->ndev, "Rule not added: No free space!\n"); |
| 1294 | goto end; |
| 1295 | } |
| 1296 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1297 | end: |
| 1298 | kfree(tab); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1299 | return ret; |
| 1300 | } |
| 1301 | |
| 1302 | static void gfar_invert_masks(struct ethtool_rx_flow_spec *flow) |
| 1303 | { |
| 1304 | u32 i = 0; |
| 1305 | |
| 1306 | for (i = 0; i < sizeof(flow->m_u); i++) |
| 1307 | flow->m_u.hdata[i] ^= 0xFF; |
| 1308 | |
Claudiu Manoil | 42851e8 | 2014-01-14 15:35:00 +0200 | [diff] [blame] | 1309 | flow->m_ext.vlan_etype ^= cpu_to_be16(0xFFFF); |
| 1310 | flow->m_ext.vlan_tci ^= cpu_to_be16(0xFFFF); |
| 1311 | flow->m_ext.data[0] ^= cpu_to_be32(~0); |
| 1312 | flow->m_ext.data[1] ^= cpu_to_be32(~0); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static int gfar_add_cls(struct gfar_private *priv, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1316 | struct ethtool_rx_flow_spec *flow) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1317 | { |
| 1318 | struct ethtool_flow_spec_container *temp, *comp; |
| 1319 | int ret = 0; |
| 1320 | |
| 1321 | temp = kmalloc(sizeof(*temp), GFP_KERNEL); |
| 1322 | if (temp == NULL) |
| 1323 | return -ENOMEM; |
| 1324 | memcpy(&temp->fs, flow, sizeof(temp->fs)); |
| 1325 | |
| 1326 | gfar_invert_masks(&temp->fs); |
| 1327 | ret = gfar_check_capability(&temp->fs, priv); |
| 1328 | if (ret) |
| 1329 | goto clean_mem; |
| 1330 | /* Link in the new element at the right @location */ |
| 1331 | if (list_empty(&priv->rx_list.list)) { |
| 1332 | ret = gfar_check_filer_hardware(priv); |
| 1333 | if (ret != 0) |
| 1334 | goto clean_mem; |
| 1335 | list_add(&temp->list, &priv->rx_list.list); |
| 1336 | goto process; |
| 1337 | } else { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1338 | list_for_each_entry(comp, &priv->rx_list.list, list) { |
| 1339 | if (comp->fs.location > flow->location) { |
| 1340 | list_add_tail(&temp->list, &comp->list); |
| 1341 | goto process; |
| 1342 | } |
| 1343 | if (comp->fs.location == flow->location) { |
| 1344 | netdev_err(priv->ndev, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1345 | "Rule not added: ID %d not free!\n", |
| 1346 | flow->location); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1347 | ret = -EBUSY; |
| 1348 | goto clean_mem; |
| 1349 | } |
| 1350 | } |
| 1351 | list_add_tail(&temp->list, &priv->rx_list.list); |
| 1352 | } |
| 1353 | |
| 1354 | process: |
Jakub Kicinski | b5c8c89 | 2015-08-12 02:41:56 +0200 | [diff] [blame] | 1355 | priv->rx_list.count++; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1356 | ret = gfar_process_filer_changes(priv); |
| 1357 | if (ret) |
| 1358 | goto clean_list; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1359 | return ret; |
| 1360 | |
| 1361 | clean_list: |
Jakub Kicinski | b5c8c89 | 2015-08-12 02:41:56 +0200 | [diff] [blame] | 1362 | priv->rx_list.count--; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1363 | list_del(&temp->list); |
| 1364 | clean_mem: |
| 1365 | kfree(temp); |
| 1366 | return ret; |
| 1367 | } |
| 1368 | |
| 1369 | static int gfar_del_cls(struct gfar_private *priv, u32 loc) |
| 1370 | { |
| 1371 | struct ethtool_flow_spec_container *comp; |
| 1372 | u32 ret = -EINVAL; |
| 1373 | |
| 1374 | if (list_empty(&priv->rx_list.list)) |
| 1375 | return ret; |
| 1376 | |
| 1377 | list_for_each_entry(comp, &priv->rx_list.list, list) { |
| 1378 | if (comp->fs.location == loc) { |
| 1379 | list_del(&comp->list); |
| 1380 | kfree(comp); |
| 1381 | priv->rx_list.count--; |
| 1382 | gfar_process_filer_changes(priv); |
| 1383 | ret = 0; |
| 1384 | break; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | return ret; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | static int gfar_get_cls(struct gfar_private *priv, struct ethtool_rxnfc *cmd) |
| 1392 | { |
| 1393 | struct ethtool_flow_spec_container *comp; |
| 1394 | u32 ret = -EINVAL; |
| 1395 | |
| 1396 | list_for_each_entry(comp, &priv->rx_list.list, list) { |
| 1397 | if (comp->fs.location == cmd->fs.location) { |
| 1398 | memcpy(&cmd->fs, &comp->fs, sizeof(cmd->fs)); |
| 1399 | gfar_invert_masks(&cmd->fs); |
| 1400 | ret = 0; |
| 1401 | break; |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | return ret; |
| 1406 | } |
| 1407 | |
| 1408 | static int gfar_get_cls_all(struct gfar_private *priv, |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1409 | struct ethtool_rxnfc *cmd, u32 *rule_locs) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1410 | { |
| 1411 | struct ethtool_flow_spec_container *comp; |
| 1412 | u32 i = 0; |
| 1413 | |
| 1414 | list_for_each_entry(comp, &priv->rx_list.list, list) { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 1415 | if (i == cmd->rule_cnt) |
| 1416 | return -EMSGSIZE; |
| 1417 | rule_locs[i] = comp->fs.location; |
| 1418 | i++; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | cmd->data = MAX_FILER_IDX; |
Ben Hutchings | 473e64e | 2011-09-06 13:52:47 +0000 | [diff] [blame] | 1422 | cmd->rule_cnt = i; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1423 | |
| 1424 | return 0; |
| 1425 | } |
| 1426 | |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1427 | static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd) |
| 1428 | { |
| 1429 | struct gfar_private *priv = netdev_priv(dev); |
| 1430 | int ret = 0; |
| 1431 | |
Claudiu Manoil | 0851133 | 2014-02-24 12:13:45 +0200 | [diff] [blame] | 1432 | if (test_bit(GFAR_RESETTING, &priv->state)) |
| 1433 | return -EBUSY; |
| 1434 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1435 | mutex_lock(&priv->rx_queue_access); |
| 1436 | |
| 1437 | switch (cmd->cmd) { |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1438 | case ETHTOOL_SRXFH: |
| 1439 | ret = gfar_set_hash_opts(priv, cmd); |
| 1440 | break; |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1441 | case ETHTOOL_SRXCLSRLINS: |
Ben Hutchings | 3a73e49 | 2012-01-03 11:59:30 +0000 | [diff] [blame] | 1442 | if ((cmd->fs.ring_cookie != RX_CLS_FLOW_DISC && |
| 1443 | cmd->fs.ring_cookie >= priv->num_rx_queues) || |
| 1444 | cmd->fs.location >= MAX_FILER_IDX) { |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1445 | ret = -EINVAL; |
| 1446 | break; |
| 1447 | } |
| 1448 | ret = gfar_add_cls(priv, &cmd->fs); |
| 1449 | break; |
| 1450 | case ETHTOOL_SRXCLSRLDEL: |
| 1451 | ret = gfar_del_cls(priv, cmd->fs.location); |
| 1452 | break; |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1453 | default: |
| 1454 | ret = -EINVAL; |
| 1455 | } |
| 1456 | |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1457 | mutex_unlock(&priv->rx_queue_access); |
| 1458 | |
| 1459 | return ret; |
| 1460 | } |
| 1461 | |
| 1462 | 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] | 1463 | u32 *rule_locs) |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1464 | { |
| 1465 | struct gfar_private *priv = netdev_priv(dev); |
| 1466 | int ret = 0; |
| 1467 | |
| 1468 | switch (cmd->cmd) { |
| 1469 | case ETHTOOL_GRXRINGS: |
| 1470 | cmd->data = priv->num_rx_queues; |
| 1471 | break; |
| 1472 | case ETHTOOL_GRXCLSRLCNT: |
| 1473 | cmd->rule_cnt = priv->rx_list.count; |
| 1474 | break; |
| 1475 | case ETHTOOL_GRXCLSRULE: |
| 1476 | ret = gfar_get_cls(priv, cmd); |
| 1477 | break; |
| 1478 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | 815c7db | 2011-09-06 13:49:12 +0000 | [diff] [blame] | 1479 | ret = gfar_get_cls_all(priv, cmd, rule_locs); |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1480 | break; |
| 1481 | default: |
| 1482 | ret = -EINVAL; |
| 1483 | break; |
| 1484 | } |
| 1485 | |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1486 | return ret; |
| 1487 | } |
| 1488 | |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1489 | static int gfar_get_ts_info(struct net_device *dev, |
| 1490 | struct ethtool_ts_info *info) |
| 1491 | { |
| 1492 | struct gfar_private *priv = netdev_priv(dev); |
Yangbo Lu | 7349a74 | 2018-05-25 12:40:36 +0800 | [diff] [blame] | 1493 | struct platform_device *ptp_dev; |
| 1494 | struct device_node *ptp_node; |
| 1495 | struct qoriq_ptp *ptp = NULL; |
| 1496 | |
| 1497 | info->phc_index = -1; |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1498 | |
| 1499 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)) { |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1500 | info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1501 | SOF_TIMESTAMPING_SOFTWARE; |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1502 | return 0; |
| 1503 | } |
Yangbo Lu | 7349a74 | 2018-05-25 12:40:36 +0800 | [diff] [blame] | 1504 | |
| 1505 | ptp_node = of_find_compatible_node(NULL, NULL, "fsl,etsec-ptp"); |
| 1506 | if (ptp_node) { |
| 1507 | ptp_dev = of_find_device_by_node(ptp_node); |
| 1508 | if (ptp_dev) |
| 1509 | ptp = platform_get_drvdata(ptp_dev); |
| 1510 | } |
| 1511 | |
| 1512 | if (ptp) |
| 1513 | info->phc_index = ptp->phc_index; |
| 1514 | |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1515 | info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | |
| 1516 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1517 | SOF_TIMESTAMPING_RAW_HARDWARE; |
Jan Ceuleers | cbfc6071 | 2012-06-05 03:42:15 +0000 | [diff] [blame] | 1518 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | |
| 1519 | (1 << HWTSTAMP_TX_ON); |
| 1520 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 1521 | (1 << HWTSTAMP_FILTER_ALL); |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1522 | return 0; |
| 1523 | } |
| 1524 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1525 | const struct ethtool_ops gfar_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | .get_drvinfo = gfar_gdrvinfo, |
| 1527 | .get_regs_len = gfar_reglen, |
| 1528 | .get_regs = gfar_get_regs, |
| 1529 | .get_link = ethtool_op_get_link, |
| 1530 | .get_coalesce = gfar_gcoalesce, |
| 1531 | .set_coalesce = gfar_scoalesce, |
| 1532 | .get_ringparam = gfar_gringparam, |
| 1533 | .set_ringparam = gfar_sringparam, |
Claudiu Manoil | 23402bd | 2013-08-12 13:53:26 +0300 | [diff] [blame] | 1534 | .get_pauseparam = gfar_gpauseparam, |
| 1535 | .set_pauseparam = gfar_spauseparam, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | .get_strings = gfar_gstrings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1537 | .get_sset_count = gfar_sset_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | .get_ethtool_stats = gfar_fill_stats, |
Kumar Gala | 0bbaf06 | 2005-06-20 10:54:21 -0500 | [diff] [blame] | 1539 | .get_msglevel = gfar_get_msglevel, |
| 1540 | .set_msglevel = gfar_set_msglevel, |
Scott Wood | d87eb12 | 2008-07-11 18:04:45 -0500 | [diff] [blame] | 1541 | #ifdef CONFIG_PM |
| 1542 | .get_wol = gfar_get_wol, |
| 1543 | .set_wol = gfar_set_wol, |
| 1544 | #endif |
Sandeep Gopalpet | 7a8b337 | 2009-11-02 07:03:40 +0000 | [diff] [blame] | 1545 | .set_rxnfc = gfar_set_nfc, |
Sebastian Poehn | 4aa3a71 | 2011-06-20 13:57:59 -0700 | [diff] [blame] | 1546 | .get_rxnfc = gfar_get_nfc, |
Richard Cochran | 6663628 | 2012-04-03 22:59:19 +0000 | [diff] [blame] | 1547 | .get_ts_info = gfar_get_ts_info, |
Philippe Reynes | cd5f9bb | 2016-05-16 01:30:09 +0200 | [diff] [blame] | 1548 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 1549 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | }; |