Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2007 Mellanox Technologies. All rights reserved. |
| 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include <linux/kernel.h> |
| 35 | #include <linux/ethtool.h> |
| 36 | #include <linux/netdevice.h> |
Amir Vadai | af22d9d | 2012-07-18 22:33:49 +0000 | [diff] [blame] | 37 | #include <linux/mlx4/driver.h> |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 38 | |
| 39 | #include "mlx4_en.h" |
| 40 | #include "en_port.h" |
| 41 | |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 42 | #define EN_ETHTOOL_QP_ATTACH (1ull << 63) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 43 | #define EN_ETHTOOL_SHORT_MASK cpu_to_be16(0xffff) |
| 44 | #define EN_ETHTOOL_WORD_MASK cpu_to_be32(0xffffffff) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 45 | |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 46 | static int mlx4_en_moderation_update(struct mlx4_en_priv *priv) |
| 47 | { |
| 48 | int i; |
| 49 | int err = 0; |
| 50 | |
| 51 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 52 | priv->tx_cq[i].moder_cnt = priv->tx_frames; |
| 53 | priv->tx_cq[i].moder_time = priv->tx_usecs; |
| 54 | err = mlx4_en_set_cq_moder(priv, &priv->tx_cq[i]); |
| 55 | if (err) |
| 56 | return err; |
| 57 | } |
| 58 | |
| 59 | if (priv->adaptive_rx_coal) |
| 60 | return 0; |
| 61 | |
| 62 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 63 | priv->rx_cq[i].moder_cnt = priv->rx_frames; |
| 64 | priv->rx_cq[i].moder_time = priv->rx_usecs; |
| 65 | priv->last_moder_time[i] = MLX4_EN_AUTO_CONF; |
| 66 | err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]); |
| 67 | if (err) |
| 68 | return err; |
| 69 | } |
| 70 | |
| 71 | return err; |
| 72 | } |
| 73 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 74 | static void |
| 75 | mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) |
| 76 | { |
| 77 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 78 | struct mlx4_en_dev *mdev = priv->mdev; |
| 79 | |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 80 | strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
| 81 | strlcpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", |
| 82 | sizeof(drvinfo->version)); |
| 83 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), |
| 84 | "%d.%d.%d", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 85 | (u16) (mdev->dev->caps.fw_ver >> 32), |
| 86 | (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff), |
| 87 | (u16) (mdev->dev->caps.fw_ver & 0xffff)); |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 88 | strlcpy(drvinfo->bus_info, pci_name(mdev->dev->pdev), |
| 89 | sizeof(drvinfo->bus_info)); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 90 | drvinfo->n_stats = 0; |
| 91 | drvinfo->regdump_len = 0; |
| 92 | drvinfo->eedump_len = 0; |
| 93 | } |
| 94 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 95 | static const char main_strings[][ETH_GSTRING_LEN] = { |
| 96 | "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors", |
| 97 | "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions", |
| 98 | "rx_length_errors", "rx_over_errors", "rx_crc_errors", |
| 99 | "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors", |
| 100 | "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", |
| 101 | "tx_heartbeat_errors", "tx_window_errors", |
| 102 | |
| 103 | /* port statistics */ |
Yevgeny Petrilin | fa37a95 | 2010-08-24 03:46:46 +0000 | [diff] [blame] | 104 | "tso_packets", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 105 | "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed", |
| 106 | "rx_csum_good", "rx_csum_none", "tx_chksum_offload", |
| 107 | |
| 108 | /* packet statistics */ |
| 109 | "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3", |
| 110 | "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0", |
| 111 | "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5", |
| 112 | "tx_prio_6", "tx_prio_7", |
| 113 | }; |
Yevgeny Petrilin | d61702f | 2010-09-05 22:20:24 +0000 | [diff] [blame] | 114 | #define NUM_MAIN_STATS 21 |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 115 | #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS) |
| 116 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 117 | static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= { |
Masanari Iida | fd9071e | 2012-04-13 04:33:20 +0000 | [diff] [blame] | 118 | "Interrupt Test", |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 119 | "Link Test", |
| 120 | "Speed Test", |
| 121 | "Register Test", |
| 122 | "Loopback Test", |
| 123 | }; |
| 124 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 125 | static u32 mlx4_en_get_msglevel(struct net_device *dev) |
| 126 | { |
| 127 | return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable; |
| 128 | } |
| 129 | |
| 130 | static void mlx4_en_set_msglevel(struct net_device *dev, u32 val) |
| 131 | { |
| 132 | ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val; |
| 133 | } |
| 134 | |
| 135 | static void mlx4_en_get_wol(struct net_device *netdev, |
| 136 | struct ethtool_wolinfo *wol) |
| 137 | { |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 138 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
| 139 | int err = 0; |
| 140 | u64 config = 0; |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 141 | u64 mask; |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 142 | |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 143 | if ((priv->port < 1) || (priv->port > 2)) { |
| 144 | en_err(priv, "Failed to get WoL information\n"); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 : |
| 149 | MLX4_DEV_CAP_FLAG_WOL_PORT2; |
| 150 | |
| 151 | if (!(priv->mdev->dev->caps.flags & mask)) { |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 152 | wol->supported = 0; |
| 153 | wol->wolopts = 0; |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | err = mlx4_wol_read(priv->mdev->dev, &config, priv->port); |
| 158 | if (err) { |
| 159 | en_err(priv, "Failed to get WoL information\n"); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | if (config & MLX4_EN_WOL_MAGIC) |
| 164 | wol->supported = WAKE_MAGIC; |
| 165 | else |
| 166 | wol->supported = 0; |
| 167 | |
| 168 | if (config & MLX4_EN_WOL_ENABLED) |
| 169 | wol->wolopts = WAKE_MAGIC; |
| 170 | else |
| 171 | wol->wolopts = 0; |
| 172 | } |
| 173 | |
| 174 | static int mlx4_en_set_wol(struct net_device *netdev, |
| 175 | struct ethtool_wolinfo *wol) |
| 176 | { |
| 177 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
| 178 | u64 config = 0; |
| 179 | int err = 0; |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 180 | u64 mask; |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 181 | |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 182 | if ((priv->port < 1) || (priv->port > 2)) |
| 183 | return -EOPNOTSUPP; |
| 184 | |
| 185 | mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 : |
| 186 | MLX4_DEV_CAP_FLAG_WOL_PORT2; |
| 187 | |
| 188 | if (!(priv->mdev->dev->caps.flags & mask)) |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 189 | return -EOPNOTSUPP; |
| 190 | |
| 191 | if (wol->supported & ~WAKE_MAGIC) |
| 192 | return -EINVAL; |
| 193 | |
| 194 | err = mlx4_wol_read(priv->mdev->dev, &config, priv->port); |
| 195 | if (err) { |
| 196 | en_err(priv, "Failed to get WoL info, unable to modify\n"); |
| 197 | return err; |
| 198 | } |
| 199 | |
| 200 | if (wol->wolopts & WAKE_MAGIC) { |
| 201 | config |= MLX4_EN_WOL_DO_MODIFY | MLX4_EN_WOL_ENABLED | |
| 202 | MLX4_EN_WOL_MAGIC; |
| 203 | } else { |
| 204 | config &= ~(MLX4_EN_WOL_ENABLED | MLX4_EN_WOL_MAGIC); |
| 205 | config |= MLX4_EN_WOL_DO_MODIFY; |
| 206 | } |
| 207 | |
| 208 | err = mlx4_wol_write(priv->mdev->dev, config, priv->port); |
| 209 | if (err) |
| 210 | en_err(priv, "Failed to set WoL information\n"); |
| 211 | |
| 212 | return err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static int mlx4_en_get_sset_count(struct net_device *dev, int sset) |
| 216 | { |
| 217 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 218 | int bit_count = hweight64(priv->stats_bitmap); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 219 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 220 | switch (sset) { |
| 221 | case ETH_SS_STATS: |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 222 | return (priv->stats_bitmap ? bit_count : NUM_ALL_STATS) + |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 223 | (priv->tx_ring_num + priv->rx_ring_num) * 2; |
| 224 | case ETH_SS_TEST: |
Or Gerlitz | ccf8632 | 2011-07-07 19:19:29 +0000 | [diff] [blame] | 225 | return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags |
| 226 | & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2; |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 227 | default: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 228 | return -EOPNOTSUPP; |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 229 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static void mlx4_en_get_ethtool_stats(struct net_device *dev, |
| 233 | struct ethtool_stats *stats, uint64_t *data) |
| 234 | { |
| 235 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 236 | int index = 0; |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 237 | int i, j = 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 238 | |
| 239 | spin_lock_bh(&priv->stats_lock); |
| 240 | |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 241 | if (!(priv->stats_bitmap)) { |
| 242 | for (i = 0; i < NUM_MAIN_STATS; i++) |
| 243 | data[index++] = |
| 244 | ((unsigned long *) &priv->stats)[i]; |
| 245 | for (i = 0; i < NUM_PORT_STATS; i++) |
| 246 | data[index++] = |
| 247 | ((unsigned long *) &priv->port_stats)[i]; |
| 248 | for (i = 0; i < NUM_PKT_STATS; i++) |
| 249 | data[index++] = |
| 250 | ((unsigned long *) &priv->pkstats)[i]; |
| 251 | } else { |
| 252 | for (i = 0; i < NUM_MAIN_STATS; i++) { |
| 253 | if ((priv->stats_bitmap >> j) & 1) |
| 254 | data[index++] = |
| 255 | ((unsigned long *) &priv->stats)[i]; |
| 256 | j++; |
| 257 | } |
| 258 | for (i = 0; i < NUM_PORT_STATS; i++) { |
| 259 | if ((priv->stats_bitmap >> j) & 1) |
| 260 | data[index++] = |
| 261 | ((unsigned long *) &priv->port_stats)[i]; |
| 262 | j++; |
| 263 | } |
| 264 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 265 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 266 | data[index++] = priv->tx_ring[i].packets; |
| 267 | data[index++] = priv->tx_ring[i].bytes; |
| 268 | } |
| 269 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 270 | data[index++] = priv->rx_ring[i].packets; |
| 271 | data[index++] = priv->rx_ring[i].bytes; |
| 272 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 273 | spin_unlock_bh(&priv->stats_lock); |
| 274 | |
| 275 | } |
| 276 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 277 | static void mlx4_en_self_test(struct net_device *dev, |
| 278 | struct ethtool_test *etest, u64 *buf) |
| 279 | { |
| 280 | mlx4_en_ex_selftest(dev, &etest->flags, buf); |
| 281 | } |
| 282 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 283 | static void mlx4_en_get_strings(struct net_device *dev, |
| 284 | uint32_t stringset, uint8_t *data) |
| 285 | { |
| 286 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 287 | int index = 0; |
| 288 | int i; |
| 289 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 290 | switch (stringset) { |
| 291 | case ETH_SS_TEST: |
| 292 | for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++) |
| 293 | strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]); |
Or Gerlitz | ccf8632 | 2011-07-07 19:19:29 +0000 | [diff] [blame] | 294 | if (priv->mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 295 | for (; i < MLX4_EN_NUM_SELF_TEST; i++) |
| 296 | strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]); |
| 297 | break; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 298 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 299 | case ETH_SS_STATS: |
| 300 | /* Add main counters */ |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 301 | if (!priv->stats_bitmap) { |
| 302 | for (i = 0; i < NUM_MAIN_STATS; i++) |
| 303 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
| 304 | main_strings[i]); |
| 305 | for (i = 0; i < NUM_PORT_STATS; i++) |
| 306 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
| 307 | main_strings[i + |
| 308 | NUM_MAIN_STATS]); |
| 309 | for (i = 0; i < NUM_PKT_STATS; i++) |
| 310 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
| 311 | main_strings[i + |
| 312 | NUM_MAIN_STATS + |
| 313 | NUM_PORT_STATS]); |
| 314 | } else |
| 315 | for (i = 0; i < NUM_MAIN_STATS + NUM_PORT_STATS; i++) { |
| 316 | if ((priv->stats_bitmap >> i) & 1) { |
| 317 | strcpy(data + |
| 318 | (index++) * ETH_GSTRING_LEN, |
| 319 | main_strings[i]); |
| 320 | } |
| 321 | if (!(priv->stats_bitmap >> i)) |
| 322 | break; |
| 323 | } |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 324 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 325 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 326 | "tx%d_packets", i); |
| 327 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 328 | "tx%d_bytes", i); |
| 329 | } |
| 330 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 331 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 332 | "rx%d_packets", i); |
| 333 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 334 | "rx%d_bytes", i); |
| 335 | } |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 336 | break; |
| 337 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 341 | { |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 342 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 343 | int trans_type; |
| 344 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 345 | cmd->autoneg = AUTONEG_DISABLE; |
| 346 | cmd->supported = SUPPORTED_10000baseT_Full; |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 347 | cmd->advertising = ADVERTISED_10000baseT_Full; |
| 348 | |
| 349 | if (mlx4_en_QUERY_PORT(priv->mdev, priv->port)) |
| 350 | return -ENOMEM; |
| 351 | |
| 352 | trans_type = priv->port_state.transciver; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 353 | if (netif_carrier_ok(dev)) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 354 | ethtool_cmd_speed_set(cmd, priv->port_state.link_speed); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 355 | cmd->duplex = DUPLEX_FULL; |
| 356 | } else { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 357 | ethtool_cmd_speed_set(cmd, -1); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 358 | cmd->duplex = -1; |
| 359 | } |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 360 | |
| 361 | if (trans_type > 0 && trans_type <= 0xC) { |
| 362 | cmd->port = PORT_FIBRE; |
| 363 | cmd->transceiver = XCVR_EXTERNAL; |
| 364 | cmd->supported |= SUPPORTED_FIBRE; |
| 365 | cmd->advertising |= ADVERTISED_FIBRE; |
| 366 | } else if (trans_type == 0x80 || trans_type == 0) { |
| 367 | cmd->port = PORT_TP; |
| 368 | cmd->transceiver = XCVR_INTERNAL; |
| 369 | cmd->supported |= SUPPORTED_TP; |
| 370 | cmd->advertising |= ADVERTISED_TP; |
| 371 | } else { |
| 372 | cmd->port = -1; |
| 373 | cmd->transceiver = -1; |
| 374 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 379 | { |
| 380 | if ((cmd->autoneg == AUTONEG_ENABLE) || |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 381 | (ethtool_cmd_speed(cmd) != SPEED_10000) || |
| 382 | (cmd->duplex != DUPLEX_FULL)) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 383 | return -EINVAL; |
| 384 | |
| 385 | /* Nothing to change */ |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | static int mlx4_en_get_coalesce(struct net_device *dev, |
| 390 | struct ethtool_coalesce *coal) |
| 391 | { |
| 392 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 393 | |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 394 | coal->tx_coalesce_usecs = priv->tx_usecs; |
| 395 | coal->tx_max_coalesced_frames = priv->tx_frames; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 396 | coal->rx_coalesce_usecs = priv->rx_usecs; |
| 397 | coal->rx_max_coalesced_frames = priv->rx_frames; |
| 398 | |
| 399 | coal->pkt_rate_low = priv->pkt_rate_low; |
| 400 | coal->rx_coalesce_usecs_low = priv->rx_usecs_low; |
| 401 | coal->pkt_rate_high = priv->pkt_rate_high; |
| 402 | coal->rx_coalesce_usecs_high = priv->rx_usecs_high; |
| 403 | coal->rate_sample_interval = priv->sample_interval; |
| 404 | coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal; |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static int mlx4_en_set_coalesce(struct net_device *dev, |
| 409 | struct ethtool_coalesce *coal) |
| 410 | { |
| 411 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 412 | |
| 413 | priv->rx_frames = (coal->rx_max_coalesced_frames == |
| 414 | MLX4_EN_AUTO_CONF) ? |
Yevgeny Petrilin | 3db36fb | 2009-06-01 23:23:13 +0000 | [diff] [blame] | 415 | MLX4_EN_RX_COAL_TARGET : |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 416 | coal->rx_max_coalesced_frames; |
| 417 | priv->rx_usecs = (coal->rx_coalesce_usecs == |
| 418 | MLX4_EN_AUTO_CONF) ? |
| 419 | MLX4_EN_RX_COAL_TIME : |
| 420 | coal->rx_coalesce_usecs; |
| 421 | |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 422 | /* Setting TX coalescing parameters */ |
| 423 | if (coal->tx_coalesce_usecs != priv->tx_usecs || |
| 424 | coal->tx_max_coalesced_frames != priv->tx_frames) { |
| 425 | priv->tx_usecs = coal->tx_coalesce_usecs; |
| 426 | priv->tx_frames = coal->tx_max_coalesced_frames; |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 429 | /* Set adaptive coalescing params */ |
| 430 | priv->pkt_rate_low = coal->pkt_rate_low; |
| 431 | priv->rx_usecs_low = coal->rx_coalesce_usecs_low; |
| 432 | priv->pkt_rate_high = coal->pkt_rate_high; |
| 433 | priv->rx_usecs_high = coal->rx_coalesce_usecs_high; |
| 434 | priv->sample_interval = coal->rate_sample_interval; |
| 435 | priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 436 | |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 437 | return mlx4_en_moderation_update(priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static int mlx4_en_set_pauseparam(struct net_device *dev, |
| 441 | struct ethtool_pauseparam *pause) |
| 442 | { |
| 443 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 444 | struct mlx4_en_dev *mdev = priv->mdev; |
| 445 | int err; |
| 446 | |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 447 | priv->prof->tx_pause = pause->tx_pause != 0; |
| 448 | priv->prof->rx_pause = pause->rx_pause != 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 449 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
| 450 | priv->rx_skb_size + ETH_FCS_LEN, |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 451 | priv->prof->tx_pause, |
| 452 | priv->prof->tx_ppp, |
| 453 | priv->prof->rx_pause, |
| 454 | priv->prof->rx_ppp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 455 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 456 | en_err(priv, "Failed setting pause params\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 457 | |
| 458 | return err; |
| 459 | } |
| 460 | |
| 461 | static void mlx4_en_get_pauseparam(struct net_device *dev, |
| 462 | struct ethtool_pauseparam *pause) |
| 463 | { |
| 464 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 465 | |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 466 | pause->tx_pause = priv->prof->tx_pause; |
| 467 | pause->rx_pause = priv->prof->rx_pause; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 470 | static int mlx4_en_set_ringparam(struct net_device *dev, |
| 471 | struct ethtool_ringparam *param) |
| 472 | { |
| 473 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 474 | struct mlx4_en_dev *mdev = priv->mdev; |
| 475 | u32 rx_size, tx_size; |
| 476 | int port_up = 0; |
| 477 | int err = 0; |
| 478 | |
| 479 | if (param->rx_jumbo_pending || param->rx_mini_pending) |
| 480 | return -EINVAL; |
| 481 | |
| 482 | rx_size = roundup_pow_of_two(param->rx_pending); |
| 483 | rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 484 | rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 485 | tx_size = roundup_pow_of_two(param->tx_pending); |
| 486 | tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 487 | tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 488 | |
Yevgeny Petrilin | bc081ce | 2010-08-24 03:46:34 +0000 | [diff] [blame] | 489 | if (rx_size == (priv->port_up ? priv->rx_ring[0].actual_size : |
| 490 | priv->rx_ring[0].size) && |
| 491 | tx_size == priv->tx_ring[0].size) |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 492 | return 0; |
| 493 | |
| 494 | mutex_lock(&mdev->state_lock); |
| 495 | if (priv->port_up) { |
| 496 | port_up = 1; |
| 497 | mlx4_en_stop_port(dev); |
| 498 | } |
| 499 | |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 500 | mlx4_en_free_resources(priv); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 501 | |
| 502 | priv->prof->tx_ring_size = tx_size; |
| 503 | priv->prof->rx_ring_size = rx_size; |
| 504 | |
| 505 | err = mlx4_en_alloc_resources(priv); |
| 506 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 507 | en_err(priv, "Failed reallocating port resources\n"); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 508 | goto out; |
| 509 | } |
| 510 | if (port_up) { |
| 511 | err = mlx4_en_start_port(dev); |
| 512 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 513 | en_err(priv, "Failed starting port\n"); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 516 | err = mlx4_en_moderation_update(priv); |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 517 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 518 | out: |
| 519 | mutex_unlock(&mdev->state_lock); |
| 520 | return err; |
| 521 | } |
| 522 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 523 | static void mlx4_en_get_ringparam(struct net_device *dev, |
| 524 | struct ethtool_ringparam *param) |
| 525 | { |
| 526 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 527 | |
| 528 | memset(param, 0, sizeof(*param)); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 529 | param->rx_max_pending = MLX4_EN_MAX_RX_SIZE; |
| 530 | param->tx_max_pending = MLX4_EN_MAX_TX_SIZE; |
Yevgeny Petrilin | bc081ce | 2010-08-24 03:46:34 +0000 | [diff] [blame] | 531 | param->rx_pending = priv->port_up ? |
| 532 | priv->rx_ring[0].actual_size : priv->rx_ring[0].size; |
| 533 | param->tx_pending = priv->tx_ring[0].size; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 536 | static u32 mlx4_en_get_rxfh_indir_size(struct net_device *dev) |
| 537 | { |
| 538 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 539 | |
| 540 | return priv->rx_ring_num; |
| 541 | } |
| 542 | |
| 543 | static int mlx4_en_get_rxfh_indir(struct net_device *dev, u32 *ring_index) |
| 544 | { |
| 545 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 546 | struct mlx4_en_rss_map *rss_map = &priv->rss_map; |
| 547 | int rss_rings; |
| 548 | size_t n = priv->rx_ring_num; |
| 549 | int err = 0; |
| 550 | |
| 551 | rss_rings = priv->prof->rss_rings ?: priv->rx_ring_num; |
| 552 | |
| 553 | while (n--) { |
| 554 | ring_index[n] = rss_map->qps[n % rss_rings].qpn - |
| 555 | rss_map->base_qpn; |
| 556 | } |
| 557 | |
| 558 | return err; |
| 559 | } |
| 560 | |
| 561 | static int mlx4_en_set_rxfh_indir(struct net_device *dev, |
| 562 | const u32 *ring_index) |
| 563 | { |
| 564 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 565 | struct mlx4_en_dev *mdev = priv->mdev; |
| 566 | int port_up = 0; |
| 567 | int err = 0; |
| 568 | int i; |
| 569 | int rss_rings = 0; |
| 570 | |
| 571 | /* Calculate RSS table size and make sure flows are spread evenly |
| 572 | * between rings |
| 573 | */ |
| 574 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 575 | if (i > 0 && !ring_index[i] && !rss_rings) |
| 576 | rss_rings = i; |
| 577 | |
| 578 | if (ring_index[i] != (i % (rss_rings ?: priv->rx_ring_num))) |
| 579 | return -EINVAL; |
| 580 | } |
| 581 | |
| 582 | if (!rss_rings) |
| 583 | rss_rings = priv->rx_ring_num; |
| 584 | |
| 585 | /* RSS table size must be an order of 2 */ |
| 586 | if (!is_power_of_2(rss_rings)) |
| 587 | return -EINVAL; |
| 588 | |
| 589 | mutex_lock(&mdev->state_lock); |
| 590 | if (priv->port_up) { |
| 591 | port_up = 1; |
| 592 | mlx4_en_stop_port(dev); |
| 593 | } |
| 594 | |
| 595 | priv->prof->rss_rings = rss_rings; |
| 596 | |
| 597 | if (port_up) { |
| 598 | err = mlx4_en_start_port(dev); |
| 599 | if (err) |
| 600 | en_err(priv, "Failed starting port\n"); |
| 601 | } |
| 602 | |
| 603 | mutex_unlock(&mdev->state_lock); |
| 604 | return err; |
| 605 | } |
| 606 | |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 607 | #define all_zeros_or_all_ones(field) \ |
| 608 | ((field) == 0 || (field) == (__force typeof(field))-1) |
| 609 | |
| 610 | static int mlx4_en_validate_flow(struct net_device *dev, |
| 611 | struct ethtool_rxnfc *cmd) |
| 612 | { |
| 613 | struct ethtool_usrip4_spec *l3_mask; |
| 614 | struct ethtool_tcpip4_spec *l4_mask; |
| 615 | struct ethhdr *eth_mask; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 616 | |
| 617 | if (cmd->fs.location >= MAX_NUM_OF_FS_RULES) |
| 618 | return -EINVAL; |
| 619 | |
| 620 | switch (cmd->fs.flow_type & ~FLOW_EXT) { |
| 621 | case TCP_V4_FLOW: |
| 622 | case UDP_V4_FLOW: |
| 623 | if (cmd->fs.m_u.tcp_ip4_spec.tos) |
| 624 | return -EINVAL; |
| 625 | l4_mask = &cmd->fs.m_u.tcp_ip4_spec; |
| 626 | /* don't allow mask which isn't all 0 or 1 */ |
| 627 | if (!all_zeros_or_all_ones(l4_mask->ip4src) || |
| 628 | !all_zeros_or_all_ones(l4_mask->ip4dst) || |
| 629 | !all_zeros_or_all_ones(l4_mask->psrc) || |
| 630 | !all_zeros_or_all_ones(l4_mask->pdst)) |
| 631 | return -EINVAL; |
| 632 | break; |
| 633 | case IP_USER_FLOW: |
| 634 | l3_mask = &cmd->fs.m_u.usr_ip4_spec; |
| 635 | if (l3_mask->l4_4_bytes || l3_mask->tos || l3_mask->proto || |
| 636 | cmd->fs.h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 || |
| 637 | (!l3_mask->ip4src && !l3_mask->ip4dst) || |
| 638 | !all_zeros_or_all_ones(l3_mask->ip4src) || |
| 639 | !all_zeros_or_all_ones(l3_mask->ip4dst)) |
| 640 | return -EINVAL; |
| 641 | break; |
| 642 | case ETHER_FLOW: |
| 643 | eth_mask = &cmd->fs.m_u.ether_spec; |
| 644 | /* source mac mask must not be set */ |
Yan Burman | c402b94 | 2012-12-12 02:13:18 +0000 | [diff] [blame^] | 645 | if (!is_zero_ether_addr(eth_mask->h_source)) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 646 | return -EINVAL; |
| 647 | |
| 648 | /* dest mac mask must be ff:ff:ff:ff:ff:ff */ |
Yan Burman | c402b94 | 2012-12-12 02:13:18 +0000 | [diff] [blame^] | 649 | if (!is_broadcast_ether_addr(eth_mask->h_dest)) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 650 | return -EINVAL; |
| 651 | |
| 652 | if (!all_zeros_or_all_ones(eth_mask->h_proto)) |
| 653 | return -EINVAL; |
| 654 | break; |
| 655 | default: |
| 656 | return -EINVAL; |
| 657 | } |
| 658 | |
| 659 | if ((cmd->fs.flow_type & FLOW_EXT)) { |
| 660 | if (cmd->fs.m_ext.vlan_etype || |
| 661 | !(cmd->fs.m_ext.vlan_tci == 0 || |
| 662 | cmd->fs.m_ext.vlan_tci == cpu_to_be16(0xfff))) |
| 663 | return -EINVAL; |
| 664 | } |
| 665 | |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | static int add_ip_rule(struct mlx4_en_priv *priv, |
| 670 | struct ethtool_rxnfc *cmd, |
| 671 | struct list_head *list_h) |
| 672 | { |
| 673 | struct mlx4_spec_list *spec_l3; |
| 674 | struct ethtool_usrip4_spec *l3_mask = &cmd->fs.m_u.usr_ip4_spec; |
| 675 | |
| 676 | spec_l3 = kzalloc(sizeof *spec_l3, GFP_KERNEL); |
| 677 | if (!spec_l3) { |
| 678 | en_err(priv, "Fail to alloc ethtool rule.\n"); |
| 679 | return -ENOMEM; |
| 680 | } |
| 681 | |
| 682 | spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4; |
| 683 | spec_l3->ipv4.src_ip = cmd->fs.h_u.usr_ip4_spec.ip4src; |
| 684 | if (l3_mask->ip4src) |
| 685 | spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK; |
| 686 | spec_l3->ipv4.dst_ip = cmd->fs.h_u.usr_ip4_spec.ip4dst; |
| 687 | if (l3_mask->ip4dst) |
| 688 | spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK; |
| 689 | list_add_tail(&spec_l3->list, list_h); |
| 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | static int add_tcp_udp_rule(struct mlx4_en_priv *priv, |
| 695 | struct ethtool_rxnfc *cmd, |
| 696 | struct list_head *list_h, int proto) |
| 697 | { |
| 698 | struct mlx4_spec_list *spec_l3; |
| 699 | struct mlx4_spec_list *spec_l4; |
| 700 | struct ethtool_tcpip4_spec *l4_mask = &cmd->fs.m_u.tcp_ip4_spec; |
| 701 | |
| 702 | spec_l3 = kzalloc(sizeof *spec_l3, GFP_KERNEL); |
| 703 | spec_l4 = kzalloc(sizeof *spec_l4, GFP_KERNEL); |
| 704 | if (!spec_l4 || !spec_l3) { |
| 705 | en_err(priv, "Fail to alloc ethtool rule.\n"); |
| 706 | kfree(spec_l3); |
| 707 | kfree(spec_l4); |
| 708 | return -ENOMEM; |
| 709 | } |
| 710 | |
| 711 | spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4; |
| 712 | |
| 713 | if (proto == TCP_V4_FLOW) { |
| 714 | spec_l4->id = MLX4_NET_TRANS_RULE_ID_TCP; |
| 715 | spec_l3->ipv4.src_ip = cmd->fs.h_u.tcp_ip4_spec.ip4src; |
| 716 | spec_l3->ipv4.dst_ip = cmd->fs.h_u.tcp_ip4_spec.ip4dst; |
| 717 | spec_l4->tcp_udp.src_port = cmd->fs.h_u.tcp_ip4_spec.psrc; |
| 718 | spec_l4->tcp_udp.dst_port = cmd->fs.h_u.tcp_ip4_spec.pdst; |
| 719 | } else { |
| 720 | spec_l4->id = MLX4_NET_TRANS_RULE_ID_UDP; |
| 721 | spec_l3->ipv4.src_ip = cmd->fs.h_u.udp_ip4_spec.ip4src; |
| 722 | spec_l3->ipv4.dst_ip = cmd->fs.h_u.udp_ip4_spec.ip4dst; |
| 723 | spec_l4->tcp_udp.src_port = cmd->fs.h_u.udp_ip4_spec.psrc; |
| 724 | spec_l4->tcp_udp.dst_port = cmd->fs.h_u.udp_ip4_spec.pdst; |
| 725 | } |
| 726 | |
| 727 | if (l4_mask->ip4src) |
| 728 | spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK; |
| 729 | if (l4_mask->ip4dst) |
| 730 | spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK; |
| 731 | |
| 732 | if (l4_mask->psrc) |
| 733 | spec_l4->tcp_udp.src_port_msk = EN_ETHTOOL_SHORT_MASK; |
| 734 | if (l4_mask->pdst) |
| 735 | spec_l4->tcp_udp.dst_port_msk = EN_ETHTOOL_SHORT_MASK; |
| 736 | |
| 737 | list_add_tail(&spec_l3->list, list_h); |
| 738 | list_add_tail(&spec_l4->list, list_h); |
| 739 | |
| 740 | return 0; |
| 741 | } |
| 742 | |
| 743 | static int mlx4_en_ethtool_to_net_trans_rule(struct net_device *dev, |
| 744 | struct ethtool_rxnfc *cmd, |
| 745 | struct list_head *rule_list_h) |
| 746 | { |
| 747 | int err; |
| 748 | u64 mac; |
| 749 | __be64 be_mac; |
| 750 | struct ethhdr *eth_spec; |
| 751 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 752 | struct mlx4_spec_list *spec_l2; |
Amir Vadai | af22d9d | 2012-07-18 22:33:49 +0000 | [diff] [blame] | 753 | __be64 mac_msk = cpu_to_be64(MLX4_MAC_MASK << 16); |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 754 | |
| 755 | err = mlx4_en_validate_flow(dev, cmd); |
| 756 | if (err) |
| 757 | return err; |
| 758 | |
| 759 | spec_l2 = kzalloc(sizeof *spec_l2, GFP_KERNEL); |
| 760 | if (!spec_l2) |
| 761 | return -ENOMEM; |
| 762 | |
Amir Vadai | af22d9d | 2012-07-18 22:33:49 +0000 | [diff] [blame] | 763 | mac = priv->mac & MLX4_MAC_MASK; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 764 | be_mac = cpu_to_be64(mac << 16); |
| 765 | |
| 766 | spec_l2->id = MLX4_NET_TRANS_RULE_ID_ETH; |
| 767 | memcpy(spec_l2->eth.dst_mac_msk, &mac_msk, ETH_ALEN); |
| 768 | if ((cmd->fs.flow_type & ~FLOW_EXT) != ETHER_FLOW) |
| 769 | memcpy(spec_l2->eth.dst_mac, &be_mac, ETH_ALEN); |
| 770 | |
| 771 | if ((cmd->fs.flow_type & FLOW_EXT) && cmd->fs.m_ext.vlan_tci) { |
| 772 | spec_l2->eth.vlan_id = cmd->fs.h_ext.vlan_tci; |
| 773 | spec_l2->eth.vlan_id_msk = cpu_to_be16(0xfff); |
| 774 | } |
| 775 | |
| 776 | list_add_tail(&spec_l2->list, rule_list_h); |
| 777 | |
| 778 | switch (cmd->fs.flow_type & ~FLOW_EXT) { |
| 779 | case ETHER_FLOW: |
| 780 | eth_spec = &cmd->fs.h_u.ether_spec; |
| 781 | memcpy(&spec_l2->eth.dst_mac, eth_spec->h_dest, ETH_ALEN); |
| 782 | spec_l2->eth.ether_type = eth_spec->h_proto; |
| 783 | if (eth_spec->h_proto) |
| 784 | spec_l2->eth.ether_type_enable = 1; |
| 785 | break; |
| 786 | case IP_USER_FLOW: |
| 787 | err = add_ip_rule(priv, cmd, rule_list_h); |
| 788 | break; |
| 789 | case TCP_V4_FLOW: |
| 790 | err = add_tcp_udp_rule(priv, cmd, rule_list_h, TCP_V4_FLOW); |
| 791 | break; |
| 792 | case UDP_V4_FLOW: |
| 793 | err = add_tcp_udp_rule(priv, cmd, rule_list_h, UDP_V4_FLOW); |
| 794 | break; |
| 795 | } |
| 796 | |
| 797 | return err; |
| 798 | } |
| 799 | |
| 800 | static int mlx4_en_flow_replace(struct net_device *dev, |
| 801 | struct ethtool_rxnfc *cmd) |
| 802 | { |
| 803 | int err; |
| 804 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 805 | struct ethtool_flow_id *loc_rule; |
| 806 | struct mlx4_spec_list *spec, *tmp_spec; |
| 807 | u32 qpn; |
| 808 | u64 reg_id; |
| 809 | |
| 810 | struct mlx4_net_trans_rule rule = { |
| 811 | .queue_mode = MLX4_NET_TRANS_Q_FIFO, |
| 812 | .exclusive = 0, |
| 813 | .allow_loopback = 1, |
| 814 | .promisc_mode = MLX4_FS_PROMISC_NONE, |
| 815 | }; |
| 816 | |
| 817 | rule.port = priv->port; |
| 818 | rule.priority = MLX4_DOMAIN_ETHTOOL | cmd->fs.location; |
| 819 | INIT_LIST_HEAD(&rule.list); |
| 820 | |
| 821 | /* Allow direct QP attaches if the EN_ETHTOOL_QP_ATTACH flag is set */ |
| 822 | if (cmd->fs.ring_cookie == RX_CLS_FLOW_DISC) |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 823 | qpn = priv->drop_qp.qpn; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 824 | else if (cmd->fs.ring_cookie & EN_ETHTOOL_QP_ATTACH) { |
| 825 | qpn = cmd->fs.ring_cookie & (EN_ETHTOOL_QP_ATTACH - 1); |
| 826 | } else { |
| 827 | if (cmd->fs.ring_cookie >= priv->rx_ring_num) { |
| 828 | en_warn(priv, "rxnfc: RX ring (%llu) doesn't exist.\n", |
| 829 | cmd->fs.ring_cookie); |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | qpn = priv->rss_map.qps[cmd->fs.ring_cookie].qpn; |
| 833 | if (!qpn) { |
| 834 | en_warn(priv, "rxnfc: RX ring (%llu) is inactive.\n", |
| 835 | cmd->fs.ring_cookie); |
| 836 | return -EINVAL; |
| 837 | } |
| 838 | } |
| 839 | rule.qpn = qpn; |
| 840 | err = mlx4_en_ethtool_to_net_trans_rule(dev, cmd, &rule.list); |
| 841 | if (err) |
| 842 | goto out_free_list; |
| 843 | |
| 844 | loc_rule = &priv->ethtool_rules[cmd->fs.location]; |
| 845 | if (loc_rule->id) { |
| 846 | err = mlx4_flow_detach(priv->mdev->dev, loc_rule->id); |
| 847 | if (err) { |
| 848 | en_err(priv, "Fail to detach network rule at location %d. registration id = %llx\n", |
| 849 | cmd->fs.location, loc_rule->id); |
| 850 | goto out_free_list; |
| 851 | } |
| 852 | loc_rule->id = 0; |
| 853 | memset(&loc_rule->flow_spec, 0, |
| 854 | sizeof(struct ethtool_rx_flow_spec)); |
| 855 | } |
| 856 | err = mlx4_flow_attach(priv->mdev->dev, &rule, ®_id); |
| 857 | if (err) { |
| 858 | en_err(priv, "Fail to attach network rule at location %d.\n", |
| 859 | cmd->fs.location); |
| 860 | goto out_free_list; |
| 861 | } |
| 862 | loc_rule->id = reg_id; |
| 863 | memcpy(&loc_rule->flow_spec, &cmd->fs, |
| 864 | sizeof(struct ethtool_rx_flow_spec)); |
| 865 | |
| 866 | out_free_list: |
| 867 | list_for_each_entry_safe(spec, tmp_spec, &rule.list, list) { |
| 868 | list_del(&spec->list); |
| 869 | kfree(spec); |
| 870 | } |
| 871 | return err; |
| 872 | } |
| 873 | |
| 874 | static int mlx4_en_flow_detach(struct net_device *dev, |
| 875 | struct ethtool_rxnfc *cmd) |
| 876 | { |
| 877 | int err = 0; |
| 878 | struct ethtool_flow_id *rule; |
| 879 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 880 | |
| 881 | if (cmd->fs.location >= MAX_NUM_OF_FS_RULES) |
| 882 | return -EINVAL; |
| 883 | |
| 884 | rule = &priv->ethtool_rules[cmd->fs.location]; |
| 885 | if (!rule->id) { |
| 886 | err = -ENOENT; |
| 887 | goto out; |
| 888 | } |
| 889 | |
| 890 | err = mlx4_flow_detach(priv->mdev->dev, rule->id); |
| 891 | if (err) { |
| 892 | en_err(priv, "Fail to detach network rule at location %d. registration id = 0x%llx\n", |
| 893 | cmd->fs.location, rule->id); |
| 894 | goto out; |
| 895 | } |
| 896 | rule->id = 0; |
| 897 | memset(&rule->flow_spec, 0, sizeof(struct ethtool_rx_flow_spec)); |
| 898 | out: |
| 899 | return err; |
| 900 | |
| 901 | } |
| 902 | |
| 903 | static int mlx4_en_get_flow(struct net_device *dev, struct ethtool_rxnfc *cmd, |
| 904 | int loc) |
| 905 | { |
| 906 | int err = 0; |
| 907 | struct ethtool_flow_id *rule; |
| 908 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 909 | |
| 910 | if (loc < 0 || loc >= MAX_NUM_OF_FS_RULES) |
| 911 | return -EINVAL; |
| 912 | |
| 913 | rule = &priv->ethtool_rules[loc]; |
| 914 | if (rule->id) |
| 915 | memcpy(&cmd->fs, &rule->flow_spec, |
| 916 | sizeof(struct ethtool_rx_flow_spec)); |
| 917 | else |
| 918 | err = -ENOENT; |
| 919 | |
| 920 | return err; |
| 921 | } |
| 922 | |
| 923 | static int mlx4_en_get_num_flows(struct mlx4_en_priv *priv) |
| 924 | { |
| 925 | |
| 926 | int i, res = 0; |
| 927 | for (i = 0; i < MAX_NUM_OF_FS_RULES; i++) { |
| 928 | if (priv->ethtool_rules[i].id) |
| 929 | res++; |
| 930 | } |
| 931 | return res; |
| 932 | |
| 933 | } |
| 934 | |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 935 | static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, |
| 936 | u32 *rule_locs) |
| 937 | { |
| 938 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 939 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 940 | int err = 0; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 941 | int i = 0, priority = 0; |
| 942 | |
| 943 | if ((cmd->cmd == ETHTOOL_GRXCLSRLCNT || |
| 944 | cmd->cmd == ETHTOOL_GRXCLSRULE || |
| 945 | cmd->cmd == ETHTOOL_GRXCLSRLALL) && |
| 946 | mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_DEVICE_MANAGED) |
| 947 | return -EINVAL; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 948 | |
| 949 | switch (cmd->cmd) { |
| 950 | case ETHTOOL_GRXRINGS: |
| 951 | cmd->data = priv->rx_ring_num; |
| 952 | break; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 953 | case ETHTOOL_GRXCLSRLCNT: |
| 954 | cmd->rule_cnt = mlx4_en_get_num_flows(priv); |
| 955 | break; |
| 956 | case ETHTOOL_GRXCLSRULE: |
| 957 | err = mlx4_en_get_flow(dev, cmd, cmd->fs.location); |
| 958 | break; |
| 959 | case ETHTOOL_GRXCLSRLALL: |
| 960 | while ((!err || err == -ENOENT) && priority < cmd->rule_cnt) { |
| 961 | err = mlx4_en_get_flow(dev, cmd, i); |
| 962 | if (!err) |
| 963 | rule_locs[priority++] = i; |
| 964 | i++; |
| 965 | } |
| 966 | err = 0; |
| 967 | break; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 968 | default: |
| 969 | err = -EOPNOTSUPP; |
| 970 | break; |
| 971 | } |
| 972 | |
| 973 | return err; |
| 974 | } |
| 975 | |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 976 | static int mlx4_en_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) |
| 977 | { |
| 978 | int err = 0; |
| 979 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 980 | struct mlx4_en_dev *mdev = priv->mdev; |
| 981 | |
| 982 | if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_DEVICE_MANAGED) |
| 983 | return -EINVAL; |
| 984 | |
| 985 | switch (cmd->cmd) { |
| 986 | case ETHTOOL_SRXCLSRLINS: |
| 987 | err = mlx4_en_flow_replace(dev, cmd); |
| 988 | break; |
| 989 | case ETHTOOL_SRXCLSRLDEL: |
| 990 | err = mlx4_en_flow_detach(dev, cmd); |
| 991 | break; |
| 992 | default: |
| 993 | en_warn(priv, "Unsupported ethtool command. (%d)\n", cmd->cmd); |
| 994 | return -EINVAL; |
| 995 | } |
| 996 | |
| 997 | return err; |
| 998 | } |
| 999 | |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1000 | static void mlx4_en_get_channels(struct net_device *dev, |
| 1001 | struct ethtool_channels *channel) |
| 1002 | { |
| 1003 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1004 | |
| 1005 | memset(channel, 0, sizeof(*channel)); |
| 1006 | |
| 1007 | channel->max_rx = MAX_RX_RINGS; |
| 1008 | channel->max_tx = MLX4_EN_MAX_TX_RING_P_UP; |
| 1009 | |
| 1010 | channel->rx_count = priv->rx_ring_num; |
| 1011 | channel->tx_count = priv->tx_ring_num / MLX4_EN_NUM_UP; |
| 1012 | } |
| 1013 | |
| 1014 | static int mlx4_en_set_channels(struct net_device *dev, |
| 1015 | struct ethtool_channels *channel) |
| 1016 | { |
| 1017 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1018 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1019 | int port_up; |
| 1020 | int err = 0; |
| 1021 | |
| 1022 | if (channel->other_count || channel->combined_count || |
| 1023 | channel->tx_count > MLX4_EN_MAX_TX_RING_P_UP || |
| 1024 | channel->rx_count > MAX_RX_RINGS || |
| 1025 | !channel->tx_count || !channel->rx_count) |
| 1026 | return -EINVAL; |
| 1027 | |
| 1028 | mutex_lock(&mdev->state_lock); |
| 1029 | if (priv->port_up) { |
| 1030 | port_up = 1; |
| 1031 | mlx4_en_stop_port(dev); |
| 1032 | } |
| 1033 | |
| 1034 | mlx4_en_free_resources(priv); |
| 1035 | |
| 1036 | priv->num_tx_rings_p_up = channel->tx_count; |
| 1037 | priv->tx_ring_num = channel->tx_count * MLX4_EN_NUM_UP; |
| 1038 | priv->rx_ring_num = channel->rx_count; |
| 1039 | |
| 1040 | err = mlx4_en_alloc_resources(priv); |
| 1041 | if (err) { |
| 1042 | en_err(priv, "Failed reallocating port resources\n"); |
| 1043 | goto out; |
| 1044 | } |
| 1045 | |
| 1046 | netif_set_real_num_tx_queues(dev, priv->tx_ring_num); |
| 1047 | netif_set_real_num_rx_queues(dev, priv->rx_ring_num); |
| 1048 | |
| 1049 | mlx4_en_setup_tc(dev, MLX4_EN_NUM_UP); |
| 1050 | |
| 1051 | en_warn(priv, "Using %d TX rings\n", priv->tx_ring_num); |
| 1052 | en_warn(priv, "Using %d RX rings\n", priv->rx_ring_num); |
| 1053 | |
| 1054 | if (port_up) { |
| 1055 | err = mlx4_en_start_port(dev); |
| 1056 | if (err) |
| 1057 | en_err(priv, "Failed starting port\n"); |
| 1058 | } |
| 1059 | |
| 1060 | err = mlx4_en_moderation_update(priv); |
| 1061 | |
| 1062 | out: |
| 1063 | mutex_unlock(&mdev->state_lock); |
| 1064 | return err; |
| 1065 | } |
| 1066 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1067 | const struct ethtool_ops mlx4_en_ethtool_ops = { |
| 1068 | .get_drvinfo = mlx4_en_get_drvinfo, |
| 1069 | .get_settings = mlx4_en_get_settings, |
| 1070 | .set_settings = mlx4_en_set_settings, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1071 | .get_link = ethtool_op_get_link, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1072 | .get_strings = mlx4_en_get_strings, |
| 1073 | .get_sset_count = mlx4_en_get_sset_count, |
| 1074 | .get_ethtool_stats = mlx4_en_get_ethtool_stats, |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 1075 | .self_test = mlx4_en_self_test, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1076 | .get_wol = mlx4_en_get_wol, |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 1077 | .set_wol = mlx4_en_set_wol, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1078 | .get_msglevel = mlx4_en_get_msglevel, |
| 1079 | .set_msglevel = mlx4_en_set_msglevel, |
| 1080 | .get_coalesce = mlx4_en_get_coalesce, |
| 1081 | .set_coalesce = mlx4_en_set_coalesce, |
| 1082 | .get_pauseparam = mlx4_en_get_pauseparam, |
| 1083 | .set_pauseparam = mlx4_en_set_pauseparam, |
| 1084 | .get_ringparam = mlx4_en_get_ringparam, |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1085 | .set_ringparam = mlx4_en_set_ringparam, |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1086 | .get_rxnfc = mlx4_en_get_rxnfc, |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1087 | .set_rxnfc = mlx4_en_set_rxnfc, |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1088 | .get_rxfh_indir_size = mlx4_en_get_rxfh_indir_size, |
| 1089 | .get_rxfh_indir = mlx4_en_get_rxfh_indir, |
| 1090 | .set_rxfh_indir = mlx4_en_set_rxfh_indir, |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1091 | .get_channels = mlx4_en_get_channels, |
| 1092 | .set_channels = mlx4_en_set_channels, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1093 | }; |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | |