blob: a28cd801a236e5a674de67009a5b872ed29e9e71 [file] [log] [blame]
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001/*
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 Vadaiaf22d9d2012-07-18 22:33:49 +000037#include <linux/mlx4/driver.h>
Hadar Hen Zionf90a3672013-01-30 23:07:04 +000038#include <linux/in.h>
39#include <net/ip.h>
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070040
41#include "mlx4_en.h"
42#include "en_port.h"
43
Hadar Hen Zion82067282012-07-05 04:03:49 +000044#define EN_ETHTOOL_QP_ATTACH (1ull << 63)
Hadar Hen Zion82067282012-07-05 04:03:49 +000045#define EN_ETHTOOL_SHORT_MASK cpu_to_be16(0xffff)
46#define EN_ETHTOOL_WORD_MASK cpu_to_be32(0xffffffff)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070047
Amir Vadai79c54b62012-12-02 03:49:22 +000048static int mlx4_en_moderation_update(struct mlx4_en_priv *priv)
49{
50 int i;
51 int err = 0;
52
53 for (i = 0; i < priv->tx_ring_num; i++) {
54 priv->tx_cq[i].moder_cnt = priv->tx_frames;
55 priv->tx_cq[i].moder_time = priv->tx_usecs;
56 err = mlx4_en_set_cq_moder(priv, &priv->tx_cq[i]);
57 if (err)
58 return err;
59 }
60
61 if (priv->adaptive_rx_coal)
62 return 0;
63
64 for (i = 0; i < priv->rx_ring_num; i++) {
65 priv->rx_cq[i].moder_cnt = priv->rx_frames;
66 priv->rx_cq[i].moder_time = priv->rx_usecs;
67 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
68 err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
69 if (err)
70 return err;
71 }
72
73 return err;
74}
75
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070076static void
77mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
78{
79 struct mlx4_en_priv *priv = netdev_priv(dev);
80 struct mlx4_en_dev *mdev = priv->mdev;
81
Rick Jones612a94d2011-11-14 08:13:25 +000082 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
83 strlcpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")",
84 sizeof(drvinfo->version));
85 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
86 "%d.%d.%d",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070087 (u16) (mdev->dev->caps.fw_ver >> 32),
88 (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
89 (u16) (mdev->dev->caps.fw_ver & 0xffff));
Rick Jones612a94d2011-11-14 08:13:25 +000090 strlcpy(drvinfo->bus_info, pci_name(mdev->dev->pdev),
91 sizeof(drvinfo->bus_info));
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070092 drvinfo->n_stats = 0;
93 drvinfo->regdump_len = 0;
94 drvinfo->eedump_len = 0;
95}
96
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070097static const char main_strings[][ETH_GSTRING_LEN] = {
98 "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
99 "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
100 "rx_length_errors", "rx_over_errors", "rx_crc_errors",
101 "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
102 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
103 "tx_heartbeat_errors", "tx_window_errors",
104
105 /* port statistics */
Yevgeny Petrilinfa37a952010-08-24 03:46:46 +0000106 "tso_packets",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700107 "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
108 "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
109
110 /* packet statistics */
111 "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
112 "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
113 "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
114 "tx_prio_6", "tx_prio_7",
115};
Yevgeny Petrilind61702f2010-09-05 22:20:24 +0000116#define NUM_MAIN_STATS 21
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700117#define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
118
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000119static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= {
Masanari Iidafd9071e2012-04-13 04:33:20 +0000120 "Interrupt Test",
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000121 "Link Test",
122 "Speed Test",
123 "Register Test",
124 "Loopback Test",
125};
126
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700127static u32 mlx4_en_get_msglevel(struct net_device *dev)
128{
129 return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
130}
131
132static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
133{
134 ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
135}
136
137static void mlx4_en_get_wol(struct net_device *netdev,
138 struct ethtool_wolinfo *wol)
139{
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000140 struct mlx4_en_priv *priv = netdev_priv(netdev);
141 int err = 0;
142 u64 config = 0;
Oren Duer559a9f12011-11-26 19:55:15 +0000143 u64 mask;
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000144
Oren Duer559a9f12011-11-26 19:55:15 +0000145 if ((priv->port < 1) || (priv->port > 2)) {
146 en_err(priv, "Failed to get WoL information\n");
147 return;
148 }
149
150 mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 :
151 MLX4_DEV_CAP_FLAG_WOL_PORT2;
152
153 if (!(priv->mdev->dev->caps.flags & mask)) {
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000154 wol->supported = 0;
155 wol->wolopts = 0;
156 return;
157 }
158
159 err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
160 if (err) {
161 en_err(priv, "Failed to get WoL information\n");
162 return;
163 }
164
165 if (config & MLX4_EN_WOL_MAGIC)
166 wol->supported = WAKE_MAGIC;
167 else
168 wol->supported = 0;
169
170 if (config & MLX4_EN_WOL_ENABLED)
171 wol->wolopts = WAKE_MAGIC;
172 else
173 wol->wolopts = 0;
174}
175
176static int mlx4_en_set_wol(struct net_device *netdev,
177 struct ethtool_wolinfo *wol)
178{
179 struct mlx4_en_priv *priv = netdev_priv(netdev);
180 u64 config = 0;
181 int err = 0;
Oren Duer559a9f12011-11-26 19:55:15 +0000182 u64 mask;
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000183
Oren Duer559a9f12011-11-26 19:55:15 +0000184 if ((priv->port < 1) || (priv->port > 2))
185 return -EOPNOTSUPP;
186
187 mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 :
188 MLX4_DEV_CAP_FLAG_WOL_PORT2;
189
190 if (!(priv->mdev->dev->caps.flags & mask))
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000191 return -EOPNOTSUPP;
192
193 if (wol->supported & ~WAKE_MAGIC)
194 return -EINVAL;
195
196 err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
197 if (err) {
198 en_err(priv, "Failed to get WoL info, unable to modify\n");
199 return err;
200 }
201
202 if (wol->wolopts & WAKE_MAGIC) {
203 config |= MLX4_EN_WOL_DO_MODIFY | MLX4_EN_WOL_ENABLED |
204 MLX4_EN_WOL_MAGIC;
205 } else {
206 config &= ~(MLX4_EN_WOL_ENABLED | MLX4_EN_WOL_MAGIC);
207 config |= MLX4_EN_WOL_DO_MODIFY;
208 }
209
210 err = mlx4_wol_write(priv->mdev->dev, config, priv->port);
211 if (err)
212 en_err(priv, "Failed to set WoL information\n");
213
214 return err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700215}
216
217static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
218{
219 struct mlx4_en_priv *priv = netdev_priv(dev);
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000220 int bit_count = hweight64(priv->stats_bitmap);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700221
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000222 switch (sset) {
223 case ETH_SS_STATS:
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000224 return (priv->stats_bitmap ? bit_count : NUM_ALL_STATS) +
Amir Vadai85018412013-06-18 16:18:28 +0300225 (priv->tx_ring_num * 2) +
Cong Wange0d10952013-08-01 11:10:25 +0800226#ifdef CONFIG_NET_RX_BUSY_POLL
Amir Vadai85018412013-06-18 16:18:28 +0300227 (priv->rx_ring_num * 5);
228#else
229 (priv->rx_ring_num * 2);
230#endif
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000231 case ETH_SS_TEST:
Or Gerlitzccf86322011-07-07 19:19:29 +0000232 return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags
233 & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2;
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000234 default:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700235 return -EOPNOTSUPP;
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000236 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700237}
238
239static void mlx4_en_get_ethtool_stats(struct net_device *dev,
240 struct ethtool_stats *stats, uint64_t *data)
241{
242 struct mlx4_en_priv *priv = netdev_priv(dev);
243 int index = 0;
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000244 int i, j = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700245
246 spin_lock_bh(&priv->stats_lock);
247
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000248 if (!(priv->stats_bitmap)) {
249 for (i = 0; i < NUM_MAIN_STATS; i++)
250 data[index++] =
251 ((unsigned long *) &priv->stats)[i];
252 for (i = 0; i < NUM_PORT_STATS; i++)
253 data[index++] =
254 ((unsigned long *) &priv->port_stats)[i];
255 for (i = 0; i < NUM_PKT_STATS; i++)
256 data[index++] =
257 ((unsigned long *) &priv->pkstats)[i];
258 } else {
259 for (i = 0; i < NUM_MAIN_STATS; i++) {
260 if ((priv->stats_bitmap >> j) & 1)
261 data[index++] =
262 ((unsigned long *) &priv->stats)[i];
263 j++;
264 }
265 for (i = 0; i < NUM_PORT_STATS; i++) {
266 if ((priv->stats_bitmap >> j) & 1)
267 data[index++] =
268 ((unsigned long *) &priv->port_stats)[i];
269 j++;
270 }
271 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700272 for (i = 0; i < priv->tx_ring_num; i++) {
273 data[index++] = priv->tx_ring[i].packets;
274 data[index++] = priv->tx_ring[i].bytes;
275 }
276 for (i = 0; i < priv->rx_ring_num; i++) {
277 data[index++] = priv->rx_ring[i].packets;
278 data[index++] = priv->rx_ring[i].bytes;
Cong Wange0d10952013-08-01 11:10:25 +0800279#ifdef CONFIG_NET_RX_BUSY_POLL
Amir Vadai85018412013-06-18 16:18:28 +0300280 data[index++] = priv->rx_ring[i].yields;
281 data[index++] = priv->rx_ring[i].misses;
282 data[index++] = priv->rx_ring[i].cleaned;
283#endif
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700284 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700285 spin_unlock_bh(&priv->stats_lock);
286
287}
288
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000289static void mlx4_en_self_test(struct net_device *dev,
290 struct ethtool_test *etest, u64 *buf)
291{
292 mlx4_en_ex_selftest(dev, &etest->flags, buf);
293}
294
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700295static void mlx4_en_get_strings(struct net_device *dev,
296 uint32_t stringset, uint8_t *data)
297{
298 struct mlx4_en_priv *priv = netdev_priv(dev);
299 int index = 0;
300 int i;
301
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000302 switch (stringset) {
303 case ETH_SS_TEST:
304 for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++)
305 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
Or Gerlitzccf86322011-07-07 19:19:29 +0000306 if (priv->mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UC_LOOPBACK)
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000307 for (; i < MLX4_EN_NUM_SELF_TEST; i++)
308 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
309 break;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700310
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000311 case ETH_SS_STATS:
312 /* Add main counters */
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000313 if (!priv->stats_bitmap) {
314 for (i = 0; i < NUM_MAIN_STATS; i++)
315 strcpy(data + (index++) * ETH_GSTRING_LEN,
316 main_strings[i]);
317 for (i = 0; i < NUM_PORT_STATS; i++)
318 strcpy(data + (index++) * ETH_GSTRING_LEN,
319 main_strings[i +
320 NUM_MAIN_STATS]);
321 for (i = 0; i < NUM_PKT_STATS; i++)
322 strcpy(data + (index++) * ETH_GSTRING_LEN,
323 main_strings[i +
324 NUM_MAIN_STATS +
325 NUM_PORT_STATS]);
326 } else
327 for (i = 0; i < NUM_MAIN_STATS + NUM_PORT_STATS; i++) {
328 if ((priv->stats_bitmap >> i) & 1) {
329 strcpy(data +
330 (index++) * ETH_GSTRING_LEN,
331 main_strings[i]);
332 }
333 if (!(priv->stats_bitmap >> i))
334 break;
335 }
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000336 for (i = 0; i < priv->tx_ring_num; i++) {
337 sprintf(data + (index++) * ETH_GSTRING_LEN,
338 "tx%d_packets", i);
339 sprintf(data + (index++) * ETH_GSTRING_LEN,
340 "tx%d_bytes", i);
341 }
342 for (i = 0; i < priv->rx_ring_num; i++) {
343 sprintf(data + (index++) * ETH_GSTRING_LEN,
344 "rx%d_packets", i);
345 sprintf(data + (index++) * ETH_GSTRING_LEN,
346 "rx%d_bytes", i);
Cong Wange0d10952013-08-01 11:10:25 +0800347#ifdef CONFIG_NET_RX_BUSY_POLL
Amir Vadai85018412013-06-18 16:18:28 +0300348 sprintf(data + (index++) * ETH_GSTRING_LEN,
349 "rx%d_napi_yield", i);
350 sprintf(data + (index++) * ETH_GSTRING_LEN,
351 "rx%d_misses", i);
352 sprintf(data + (index++) * ETH_GSTRING_LEN,
353 "rx%d_cleaned", i);
354#endif
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000355 }
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000356 break;
357 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700358}
359
360static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
361{
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000362 struct mlx4_en_priv *priv = netdev_priv(dev);
363 int trans_type;
364
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700365 cmd->autoneg = AUTONEG_DISABLE;
366 cmd->supported = SUPPORTED_10000baseT_Full;
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000367 cmd->advertising = ADVERTISED_10000baseT_Full;
368
369 if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
370 return -ENOMEM;
371
372 trans_type = priv->port_state.transciver;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700373 if (netif_carrier_ok(dev)) {
David Decotigny70739492011-04-27 18:32:40 +0000374 ethtool_cmd_speed_set(cmd, priv->port_state.link_speed);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700375 cmd->duplex = DUPLEX_FULL;
376 } else {
David Decotigny70739492011-04-27 18:32:40 +0000377 ethtool_cmd_speed_set(cmd, -1);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700378 cmd->duplex = -1;
379 }
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000380
381 if (trans_type > 0 && trans_type <= 0xC) {
382 cmd->port = PORT_FIBRE;
383 cmd->transceiver = XCVR_EXTERNAL;
384 cmd->supported |= SUPPORTED_FIBRE;
385 cmd->advertising |= ADVERTISED_FIBRE;
386 } else if (trans_type == 0x80 || trans_type == 0) {
387 cmd->port = PORT_TP;
388 cmd->transceiver = XCVR_INTERNAL;
389 cmd->supported |= SUPPORTED_TP;
390 cmd->advertising |= ADVERTISED_TP;
391 } else {
392 cmd->port = -1;
393 cmd->transceiver = -1;
394 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700395 return 0;
396}
397
398static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
399{
400 if ((cmd->autoneg == AUTONEG_ENABLE) ||
David Decotigny25db0332011-04-27 18:32:39 +0000401 (ethtool_cmd_speed(cmd) != SPEED_10000) ||
402 (cmd->duplex != DUPLEX_FULL))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700403 return -EINVAL;
404
405 /* Nothing to change */
406 return 0;
407}
408
409static int mlx4_en_get_coalesce(struct net_device *dev,
410 struct ethtool_coalesce *coal)
411{
412 struct mlx4_en_priv *priv = netdev_priv(dev);
413
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000414 coal->tx_coalesce_usecs = priv->tx_usecs;
415 coal->tx_max_coalesced_frames = priv->tx_frames;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700416 coal->rx_coalesce_usecs = priv->rx_usecs;
417 coal->rx_max_coalesced_frames = priv->rx_frames;
418
419 coal->pkt_rate_low = priv->pkt_rate_low;
420 coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
421 coal->pkt_rate_high = priv->pkt_rate_high;
422 coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
423 coal->rate_sample_interval = priv->sample_interval;
424 coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
425 return 0;
426}
427
428static int mlx4_en_set_coalesce(struct net_device *dev,
429 struct ethtool_coalesce *coal)
430{
431 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700432
433 priv->rx_frames = (coal->rx_max_coalesced_frames ==
434 MLX4_EN_AUTO_CONF) ?
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +0000435 MLX4_EN_RX_COAL_TARGET :
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700436 coal->rx_max_coalesced_frames;
437 priv->rx_usecs = (coal->rx_coalesce_usecs ==
438 MLX4_EN_AUTO_CONF) ?
439 MLX4_EN_RX_COAL_TIME :
440 coal->rx_coalesce_usecs;
441
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000442 /* Setting TX coalescing parameters */
443 if (coal->tx_coalesce_usecs != priv->tx_usecs ||
444 coal->tx_max_coalesced_frames != priv->tx_frames) {
445 priv->tx_usecs = coal->tx_coalesce_usecs;
446 priv->tx_frames = coal->tx_max_coalesced_frames;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000447 }
448
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700449 /* Set adaptive coalescing params */
450 priv->pkt_rate_low = coal->pkt_rate_low;
451 priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
452 priv->pkt_rate_high = coal->pkt_rate_high;
453 priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
454 priv->sample_interval = coal->rate_sample_interval;
455 priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700456
Amir Vadai79c54b62012-12-02 03:49:22 +0000457 return mlx4_en_moderation_update(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700458}
459
460static int mlx4_en_set_pauseparam(struct net_device *dev,
461 struct ethtool_pauseparam *pause)
462{
463 struct mlx4_en_priv *priv = netdev_priv(dev);
464 struct mlx4_en_dev *mdev = priv->mdev;
465 int err;
466
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000467 priv->prof->tx_pause = pause->tx_pause != 0;
468 priv->prof->rx_pause = pause->rx_pause != 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700469 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
470 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000471 priv->prof->tx_pause,
472 priv->prof->tx_ppp,
473 priv->prof->rx_pause,
474 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700475 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000476 en_err(priv, "Failed setting pause params\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700477
478 return err;
479}
480
481static void mlx4_en_get_pauseparam(struct net_device *dev,
482 struct ethtool_pauseparam *pause)
483{
484 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700485
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000486 pause->tx_pause = priv->prof->tx_pause;
487 pause->rx_pause = priv->prof->rx_pause;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700488}
489
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800490static int mlx4_en_set_ringparam(struct net_device *dev,
491 struct ethtool_ringparam *param)
492{
493 struct mlx4_en_priv *priv = netdev_priv(dev);
494 struct mlx4_en_dev *mdev = priv->mdev;
495 u32 rx_size, tx_size;
496 int port_up = 0;
497 int err = 0;
498
499 if (param->rx_jumbo_pending || param->rx_mini_pending)
500 return -EINVAL;
501
502 rx_size = roundup_pow_of_two(param->rx_pending);
503 rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800504 rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800505 tx_size = roundup_pow_of_two(param->tx_pending);
506 tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800507 tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800508
Yevgeny Petrilinbc081ce2010-08-24 03:46:34 +0000509 if (rx_size == (priv->port_up ? priv->rx_ring[0].actual_size :
510 priv->rx_ring[0].size) &&
511 tx_size == priv->tx_ring[0].size)
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800512 return 0;
513
514 mutex_lock(&mdev->state_lock);
515 if (priv->port_up) {
516 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +0000517 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800518 }
519
Alexander Gullerfe0af032011-10-09 05:26:46 +0000520 mlx4_en_free_resources(priv);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800521
522 priv->prof->tx_ring_size = tx_size;
523 priv->prof->rx_ring_size = rx_size;
524
525 err = mlx4_en_alloc_resources(priv);
526 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000527 en_err(priv, "Failed reallocating port resources\n");
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800528 goto out;
529 }
530 if (port_up) {
531 err = mlx4_en_start_port(dev);
532 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000533 en_err(priv, "Failed starting port\n");
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800534 }
535
Amir Vadai79c54b62012-12-02 03:49:22 +0000536 err = mlx4_en_moderation_update(priv);
Alexander Guller6b4d8d92011-10-09 05:38:23 +0000537
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800538out:
539 mutex_unlock(&mdev->state_lock);
540 return err;
541}
542
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700543static void mlx4_en_get_ringparam(struct net_device *dev,
544 struct ethtool_ringparam *param)
545{
546 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700547
548 memset(param, 0, sizeof(*param));
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800549 param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
550 param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
Yevgeny Petrilinbc081ce2010-08-24 03:46:34 +0000551 param->rx_pending = priv->port_up ?
552 priv->rx_ring[0].actual_size : priv->rx_ring[0].size;
553 param->tx_pending = priv->tx_ring[0].size;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700554}
555
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +0000556static u32 mlx4_en_get_rxfh_indir_size(struct net_device *dev)
557{
558 struct mlx4_en_priv *priv = netdev_priv(dev);
559
560 return priv->rx_ring_num;
561}
562
563static int mlx4_en_get_rxfh_indir(struct net_device *dev, u32 *ring_index)
564{
565 struct mlx4_en_priv *priv = netdev_priv(dev);
566 struct mlx4_en_rss_map *rss_map = &priv->rss_map;
567 int rss_rings;
568 size_t n = priv->rx_ring_num;
569 int err = 0;
570
571 rss_rings = priv->prof->rss_rings ?: priv->rx_ring_num;
572
573 while (n--) {
574 ring_index[n] = rss_map->qps[n % rss_rings].qpn -
575 rss_map->base_qpn;
576 }
577
578 return err;
579}
580
581static int mlx4_en_set_rxfh_indir(struct net_device *dev,
582 const u32 *ring_index)
583{
584 struct mlx4_en_priv *priv = netdev_priv(dev);
585 struct mlx4_en_dev *mdev = priv->mdev;
586 int port_up = 0;
587 int err = 0;
588 int i;
589 int rss_rings = 0;
590
591 /* Calculate RSS table size and make sure flows are spread evenly
592 * between rings
593 */
594 for (i = 0; i < priv->rx_ring_num; i++) {
595 if (i > 0 && !ring_index[i] && !rss_rings)
596 rss_rings = i;
597
598 if (ring_index[i] != (i % (rss_rings ?: priv->rx_ring_num)))
599 return -EINVAL;
600 }
601
602 if (!rss_rings)
603 rss_rings = priv->rx_ring_num;
604
605 /* RSS table size must be an order of 2 */
606 if (!is_power_of_2(rss_rings))
607 return -EINVAL;
608
609 mutex_lock(&mdev->state_lock);
610 if (priv->port_up) {
611 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +0000612 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +0000613 }
614
615 priv->prof->rss_rings = rss_rings;
616
617 if (port_up) {
618 err = mlx4_en_start_port(dev);
619 if (err)
620 en_err(priv, "Failed starting port\n");
621 }
622
623 mutex_unlock(&mdev->state_lock);
624 return err;
625}
626
Hadar Hen Zion82067282012-07-05 04:03:49 +0000627#define all_zeros_or_all_ones(field) \
628 ((field) == 0 || (field) == (__force typeof(field))-1)
629
630static int mlx4_en_validate_flow(struct net_device *dev,
631 struct ethtool_rxnfc *cmd)
632{
633 struct ethtool_usrip4_spec *l3_mask;
634 struct ethtool_tcpip4_spec *l4_mask;
635 struct ethhdr *eth_mask;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000636
637 if (cmd->fs.location >= MAX_NUM_OF_FS_RULES)
638 return -EINVAL;
639
Yan Burman520dfe32012-12-12 02:13:19 +0000640 if (cmd->fs.flow_type & FLOW_MAC_EXT) {
641 /* dest mac mask must be ff:ff:ff:ff:ff:ff */
642 if (!is_broadcast_ether_addr(cmd->fs.m_ext.h_dest))
643 return -EINVAL;
644 }
645
646 switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
Hadar Hen Zion82067282012-07-05 04:03:49 +0000647 case TCP_V4_FLOW:
648 case UDP_V4_FLOW:
649 if (cmd->fs.m_u.tcp_ip4_spec.tos)
650 return -EINVAL;
651 l4_mask = &cmd->fs.m_u.tcp_ip4_spec;
652 /* don't allow mask which isn't all 0 or 1 */
653 if (!all_zeros_or_all_ones(l4_mask->ip4src) ||
654 !all_zeros_or_all_ones(l4_mask->ip4dst) ||
655 !all_zeros_or_all_ones(l4_mask->psrc) ||
656 !all_zeros_or_all_ones(l4_mask->pdst))
657 return -EINVAL;
658 break;
659 case IP_USER_FLOW:
660 l3_mask = &cmd->fs.m_u.usr_ip4_spec;
661 if (l3_mask->l4_4_bytes || l3_mask->tos || l3_mask->proto ||
662 cmd->fs.h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 ||
663 (!l3_mask->ip4src && !l3_mask->ip4dst) ||
664 !all_zeros_or_all_ones(l3_mask->ip4src) ||
665 !all_zeros_or_all_ones(l3_mask->ip4dst))
666 return -EINVAL;
667 break;
668 case ETHER_FLOW:
669 eth_mask = &cmd->fs.m_u.ether_spec;
670 /* source mac mask must not be set */
Yan Burmanc402b942012-12-12 02:13:18 +0000671 if (!is_zero_ether_addr(eth_mask->h_source))
Hadar Hen Zion82067282012-07-05 04:03:49 +0000672 return -EINVAL;
673
674 /* dest mac mask must be ff:ff:ff:ff:ff:ff */
Yan Burmanc402b942012-12-12 02:13:18 +0000675 if (!is_broadcast_ether_addr(eth_mask->h_dest))
Hadar Hen Zion82067282012-07-05 04:03:49 +0000676 return -EINVAL;
677
678 if (!all_zeros_or_all_ones(eth_mask->h_proto))
679 return -EINVAL;
680 break;
681 default:
682 return -EINVAL;
683 }
684
685 if ((cmd->fs.flow_type & FLOW_EXT)) {
686 if (cmd->fs.m_ext.vlan_etype ||
Hadar Hen Zion8258bd22013-01-30 23:07:06 +0000687 !((cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) ==
688 0 ||
689 (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) ==
690 cpu_to_be16(VLAN_VID_MASK)))
Hadar Hen Zion82067282012-07-05 04:03:49 +0000691 return -EINVAL;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +0000692
Hadar Hen Zion69d71262013-01-30 23:07:05 +0000693 if (cmd->fs.m_ext.vlan_tci) {
694 if (be16_to_cpu(cmd->fs.h_ext.vlan_tci) >= VLAN_N_VID)
695 return -EINVAL;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +0000696
Hadar Hen Zion69d71262013-01-30 23:07:05 +0000697 }
Hadar Hen Zion82067282012-07-05 04:03:49 +0000698 }
699
700 return 0;
701}
702
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000703static int mlx4_en_ethtool_add_mac_rule(struct ethtool_rxnfc *cmd,
704 struct list_head *rule_list_h,
705 struct mlx4_spec_list *spec_l2,
706 unsigned char *mac)
Hadar Hen Zion82067282012-07-05 04:03:49 +0000707{
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000708 int err = 0;
709 __be64 mac_msk = cpu_to_be64(MLX4_MAC_MASK << 16);
710
711 spec_l2->id = MLX4_NET_TRANS_RULE_ID_ETH;
712 memcpy(spec_l2->eth.dst_mac_msk, &mac_msk, ETH_ALEN);
713 memcpy(spec_l2->eth.dst_mac, mac, ETH_ALEN);
714
Hadar Hen Zion8258bd22013-01-30 23:07:06 +0000715 if ((cmd->fs.flow_type & FLOW_EXT) &&
716 (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK))) {
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000717 spec_l2->eth.vlan_id = cmd->fs.h_ext.vlan_tci;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +0000718 spec_l2->eth.vlan_id_msk = cpu_to_be16(VLAN_VID_MASK);
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000719 }
720
721 list_add_tail(&spec_l2->list, rule_list_h);
722
723 return err;
724}
725
726static int mlx4_en_ethtool_add_mac_rule_by_ipv4(struct mlx4_en_priv *priv,
727 struct ethtool_rxnfc *cmd,
728 struct list_head *rule_list_h,
729 struct mlx4_spec_list *spec_l2,
730 __be32 ipv4_dst)
731{
Hadar Hen Zionf9d96862013-02-04 03:01:21 +0000732#ifdef CONFIG_INET
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000733 unsigned char mac[ETH_ALEN];
734
735 if (!ipv4_is_multicast(ipv4_dst)) {
Yan Burman6bbb6d92013-02-07 02:25:20 +0000736 if (cmd->fs.flow_type & FLOW_MAC_EXT)
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000737 memcpy(&mac, cmd->fs.h_ext.h_dest, ETH_ALEN);
Yan Burman6bbb6d92013-02-07 02:25:20 +0000738 else
739 memcpy(&mac, priv->dev->dev_addr, ETH_ALEN);
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000740 } else {
741 ip_eth_mc_map(ipv4_dst, mac);
742 }
743
744 return mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2, &mac[0]);
Hadar Hen Zionf9d96862013-02-04 03:01:21 +0000745#else
746 return -EINVAL;
747#endif
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000748}
749
750static int add_ip_rule(struct mlx4_en_priv *priv,
751 struct ethtool_rxnfc *cmd,
752 struct list_head *list_h)
753{
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000754 int err;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000755 struct mlx4_spec_list *spec_l2 = NULL;
756 struct mlx4_spec_list *spec_l3 = NULL;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000757 struct ethtool_usrip4_spec *l3_mask = &cmd->fs.m_u.usr_ip4_spec;
758
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000759 spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL);
760 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
761 if (!spec_l2 || !spec_l3) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000762 err = -ENOMEM;
763 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000764 }
765
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000766 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h, spec_l2,
767 cmd->fs.h_u.
768 usr_ip4_spec.ip4dst);
769 if (err)
770 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000771 spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4;
772 spec_l3->ipv4.src_ip = cmd->fs.h_u.usr_ip4_spec.ip4src;
773 if (l3_mask->ip4src)
774 spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK;
775 spec_l3->ipv4.dst_ip = cmd->fs.h_u.usr_ip4_spec.ip4dst;
776 if (l3_mask->ip4dst)
777 spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK;
778 list_add_tail(&spec_l3->list, list_h);
779
780 return 0;
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000781
782free_spec:
783 kfree(spec_l2);
784 kfree(spec_l3);
785 return err;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000786}
787
788static int add_tcp_udp_rule(struct mlx4_en_priv *priv,
789 struct ethtool_rxnfc *cmd,
790 struct list_head *list_h, int proto)
791{
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000792 int err;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000793 struct mlx4_spec_list *spec_l2 = NULL;
794 struct mlx4_spec_list *spec_l3 = NULL;
795 struct mlx4_spec_list *spec_l4 = NULL;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000796 struct ethtool_tcpip4_spec *l4_mask = &cmd->fs.m_u.tcp_ip4_spec;
797
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000798 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
799 spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL);
800 spec_l4 = kzalloc(sizeof(*spec_l4), GFP_KERNEL);
801 if (!spec_l2 || !spec_l3 || !spec_l4) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000802 err = -ENOMEM;
803 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000804 }
805
806 spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4;
807
808 if (proto == TCP_V4_FLOW) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000809 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h,
810 spec_l2,
811 cmd->fs.h_u.
812 tcp_ip4_spec.ip4dst);
813 if (err)
814 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000815 spec_l4->id = MLX4_NET_TRANS_RULE_ID_TCP;
816 spec_l3->ipv4.src_ip = cmd->fs.h_u.tcp_ip4_spec.ip4src;
817 spec_l3->ipv4.dst_ip = cmd->fs.h_u.tcp_ip4_spec.ip4dst;
818 spec_l4->tcp_udp.src_port = cmd->fs.h_u.tcp_ip4_spec.psrc;
819 spec_l4->tcp_udp.dst_port = cmd->fs.h_u.tcp_ip4_spec.pdst;
820 } else {
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000821 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h,
822 spec_l2,
823 cmd->fs.h_u.
824 udp_ip4_spec.ip4dst);
825 if (err)
826 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000827 spec_l4->id = MLX4_NET_TRANS_RULE_ID_UDP;
828 spec_l3->ipv4.src_ip = cmd->fs.h_u.udp_ip4_spec.ip4src;
829 spec_l3->ipv4.dst_ip = cmd->fs.h_u.udp_ip4_spec.ip4dst;
830 spec_l4->tcp_udp.src_port = cmd->fs.h_u.udp_ip4_spec.psrc;
831 spec_l4->tcp_udp.dst_port = cmd->fs.h_u.udp_ip4_spec.pdst;
832 }
833
834 if (l4_mask->ip4src)
835 spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK;
836 if (l4_mask->ip4dst)
837 spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK;
838
839 if (l4_mask->psrc)
840 spec_l4->tcp_udp.src_port_msk = EN_ETHTOOL_SHORT_MASK;
841 if (l4_mask->pdst)
842 spec_l4->tcp_udp.dst_port_msk = EN_ETHTOOL_SHORT_MASK;
843
844 list_add_tail(&spec_l3->list, list_h);
845 list_add_tail(&spec_l4->list, list_h);
846
847 return 0;
Hadar Hen Zion377d9732013-02-04 03:01:20 +0000848
849free_spec:
850 kfree(spec_l2);
851 kfree(spec_l3);
852 kfree(spec_l4);
853 return err;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000854}
855
856static int mlx4_en_ethtool_to_net_trans_rule(struct net_device *dev,
857 struct ethtool_rxnfc *cmd,
858 struct list_head *rule_list_h)
859{
860 int err;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000861 struct ethhdr *eth_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000862 struct mlx4_spec_list *spec_l2;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000863 struct mlx4_en_priv *priv = netdev_priv(dev);
Hadar Hen Zion82067282012-07-05 04:03:49 +0000864
865 err = mlx4_en_validate_flow(dev, cmd);
866 if (err)
867 return err;
868
Yan Burman520dfe32012-12-12 02:13:19 +0000869 switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
Hadar Hen Zion82067282012-07-05 04:03:49 +0000870 case ETHER_FLOW:
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000871 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
872 if (!spec_l2)
873 return -ENOMEM;
874
Hadar Hen Zion82067282012-07-05 04:03:49 +0000875 eth_spec = &cmd->fs.h_u.ether_spec;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +0000876 mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2,
877 &eth_spec->h_dest[0]);
Hadar Hen Zion82067282012-07-05 04:03:49 +0000878 spec_l2->eth.ether_type = eth_spec->h_proto;
879 if (eth_spec->h_proto)
880 spec_l2->eth.ether_type_enable = 1;
881 break;
882 case IP_USER_FLOW:
883 err = add_ip_rule(priv, cmd, rule_list_h);
884 break;
885 case TCP_V4_FLOW:
886 err = add_tcp_udp_rule(priv, cmd, rule_list_h, TCP_V4_FLOW);
887 break;
888 case UDP_V4_FLOW:
889 err = add_tcp_udp_rule(priv, cmd, rule_list_h, UDP_V4_FLOW);
890 break;
891 }
892
893 return err;
894}
895
896static int mlx4_en_flow_replace(struct net_device *dev,
897 struct ethtool_rxnfc *cmd)
898{
899 int err;
900 struct mlx4_en_priv *priv = netdev_priv(dev);
901 struct ethtool_flow_id *loc_rule;
902 struct mlx4_spec_list *spec, *tmp_spec;
903 u32 qpn;
904 u64 reg_id;
905
906 struct mlx4_net_trans_rule rule = {
907 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
908 .exclusive = 0,
909 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +0000910 .promisc_mode = MLX4_FS_REGULAR,
Hadar Hen Zion82067282012-07-05 04:03:49 +0000911 };
912
913 rule.port = priv->port;
914 rule.priority = MLX4_DOMAIN_ETHTOOL | cmd->fs.location;
915 INIT_LIST_HEAD(&rule.list);
916
917 /* Allow direct QP attaches if the EN_ETHTOOL_QP_ATTACH flag is set */
918 if (cmd->fs.ring_cookie == RX_CLS_FLOW_DISC)
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +0000919 qpn = priv->drop_qp.qpn;
Hadar Hen Zion82067282012-07-05 04:03:49 +0000920 else if (cmd->fs.ring_cookie & EN_ETHTOOL_QP_ATTACH) {
921 qpn = cmd->fs.ring_cookie & (EN_ETHTOOL_QP_ATTACH - 1);
922 } else {
923 if (cmd->fs.ring_cookie >= priv->rx_ring_num) {
924 en_warn(priv, "rxnfc: RX ring (%llu) doesn't exist.\n",
925 cmd->fs.ring_cookie);
926 return -EINVAL;
927 }
928 qpn = priv->rss_map.qps[cmd->fs.ring_cookie].qpn;
929 if (!qpn) {
930 en_warn(priv, "rxnfc: RX ring (%llu) is inactive.\n",
931 cmd->fs.ring_cookie);
932 return -EINVAL;
933 }
934 }
935 rule.qpn = qpn;
936 err = mlx4_en_ethtool_to_net_trans_rule(dev, cmd, &rule.list);
937 if (err)
938 goto out_free_list;
939
940 loc_rule = &priv->ethtool_rules[cmd->fs.location];
941 if (loc_rule->id) {
942 err = mlx4_flow_detach(priv->mdev->dev, loc_rule->id);
943 if (err) {
944 en_err(priv, "Fail to detach network rule at location %d. registration id = %llx\n",
945 cmd->fs.location, loc_rule->id);
946 goto out_free_list;
947 }
948 loc_rule->id = 0;
949 memset(&loc_rule->flow_spec, 0,
950 sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +0000951 list_del(&loc_rule->list);
Hadar Hen Zion82067282012-07-05 04:03:49 +0000952 }
953 err = mlx4_flow_attach(priv->mdev->dev, &rule, &reg_id);
954 if (err) {
955 en_err(priv, "Fail to attach network rule at location %d.\n",
956 cmd->fs.location);
957 goto out_free_list;
958 }
959 loc_rule->id = reg_id;
960 memcpy(&loc_rule->flow_spec, &cmd->fs,
961 sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +0000962 list_add_tail(&loc_rule->list, &priv->ethtool_list);
Hadar Hen Zion82067282012-07-05 04:03:49 +0000963
964out_free_list:
965 list_for_each_entry_safe(spec, tmp_spec, &rule.list, list) {
966 list_del(&spec->list);
967 kfree(spec);
968 }
969 return err;
970}
971
972static int mlx4_en_flow_detach(struct net_device *dev,
973 struct ethtool_rxnfc *cmd)
974{
975 int err = 0;
976 struct ethtool_flow_id *rule;
977 struct mlx4_en_priv *priv = netdev_priv(dev);
978
979 if (cmd->fs.location >= MAX_NUM_OF_FS_RULES)
980 return -EINVAL;
981
982 rule = &priv->ethtool_rules[cmd->fs.location];
983 if (!rule->id) {
984 err = -ENOENT;
985 goto out;
986 }
987
988 err = mlx4_flow_detach(priv->mdev->dev, rule->id);
989 if (err) {
990 en_err(priv, "Fail to detach network rule at location %d. registration id = 0x%llx\n",
991 cmd->fs.location, rule->id);
992 goto out;
993 }
994 rule->id = 0;
995 memset(&rule->flow_spec, 0, sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +0000996 list_del(&rule->list);
Hadar Hen Zion82067282012-07-05 04:03:49 +0000997out:
998 return err;
999
1000}
1001
1002static int mlx4_en_get_flow(struct net_device *dev, struct ethtool_rxnfc *cmd,
1003 int loc)
1004{
1005 int err = 0;
1006 struct ethtool_flow_id *rule;
1007 struct mlx4_en_priv *priv = netdev_priv(dev);
1008
1009 if (loc < 0 || loc >= MAX_NUM_OF_FS_RULES)
1010 return -EINVAL;
1011
1012 rule = &priv->ethtool_rules[loc];
1013 if (rule->id)
1014 memcpy(&cmd->fs, &rule->flow_spec,
1015 sizeof(struct ethtool_rx_flow_spec));
1016 else
1017 err = -ENOENT;
1018
1019 return err;
1020}
1021
1022static int mlx4_en_get_num_flows(struct mlx4_en_priv *priv)
1023{
1024
1025 int i, res = 0;
1026 for (i = 0; i < MAX_NUM_OF_FS_RULES; i++) {
1027 if (priv->ethtool_rules[i].id)
1028 res++;
1029 }
1030 return res;
1031
1032}
1033
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001034static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
1035 u32 *rule_locs)
1036{
1037 struct mlx4_en_priv *priv = netdev_priv(dev);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001038 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001039 int err = 0;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001040 int i = 0, priority = 0;
1041
1042 if ((cmd->cmd == ETHTOOL_GRXCLSRLCNT ||
1043 cmd->cmd == ETHTOOL_GRXCLSRULE ||
1044 cmd->cmd == ETHTOOL_GRXCLSRLALL) &&
Hadar Hen Zion280fce12013-01-30 23:07:07 +00001045 (mdev->dev->caps.steering_mode !=
1046 MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001047 return -EINVAL;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001048
1049 switch (cmd->cmd) {
1050 case ETHTOOL_GRXRINGS:
1051 cmd->data = priv->rx_ring_num;
1052 break;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001053 case ETHTOOL_GRXCLSRLCNT:
1054 cmd->rule_cnt = mlx4_en_get_num_flows(priv);
1055 break;
1056 case ETHTOOL_GRXCLSRULE:
1057 err = mlx4_en_get_flow(dev, cmd, cmd->fs.location);
1058 break;
1059 case ETHTOOL_GRXCLSRLALL:
1060 while ((!err || err == -ENOENT) && priority < cmd->rule_cnt) {
1061 err = mlx4_en_get_flow(dev, cmd, i);
1062 if (!err)
1063 rule_locs[priority++] = i;
1064 i++;
1065 }
1066 err = 0;
1067 break;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001068 default:
1069 err = -EOPNOTSUPP;
1070 break;
1071 }
1072
1073 return err;
1074}
1075
Hadar Hen Zion82067282012-07-05 04:03:49 +00001076static int mlx4_en_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
1077{
1078 int err = 0;
1079 struct mlx4_en_priv *priv = netdev_priv(dev);
1080 struct mlx4_en_dev *mdev = priv->mdev;
1081
Hadar Hen Zion280fce12013-01-30 23:07:07 +00001082 if (mdev->dev->caps.steering_mode !=
1083 MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up)
Hadar Hen Zion82067282012-07-05 04:03:49 +00001084 return -EINVAL;
1085
1086 switch (cmd->cmd) {
1087 case ETHTOOL_SRXCLSRLINS:
1088 err = mlx4_en_flow_replace(dev, cmd);
1089 break;
1090 case ETHTOOL_SRXCLSRLDEL:
1091 err = mlx4_en_flow_detach(dev, cmd);
1092 break;
1093 default:
1094 en_warn(priv, "Unsupported ethtool command. (%d)\n", cmd->cmd);
1095 return -EINVAL;
1096 }
1097
1098 return err;
1099}
1100
Amir Vadaid3179662012-12-02 03:49:23 +00001101static void mlx4_en_get_channels(struct net_device *dev,
1102 struct ethtool_channels *channel)
1103{
1104 struct mlx4_en_priv *priv = netdev_priv(dev);
1105
1106 memset(channel, 0, sizeof(*channel));
1107
1108 channel->max_rx = MAX_RX_RINGS;
1109 channel->max_tx = MLX4_EN_MAX_TX_RING_P_UP;
1110
1111 channel->rx_count = priv->rx_ring_num;
1112 channel->tx_count = priv->tx_ring_num / MLX4_EN_NUM_UP;
1113}
1114
1115static int mlx4_en_set_channels(struct net_device *dev,
1116 struct ethtool_channels *channel)
1117{
1118 struct mlx4_en_priv *priv = netdev_priv(dev);
1119 struct mlx4_en_dev *mdev = priv->mdev;
1120 int port_up;
1121 int err = 0;
1122
1123 if (channel->other_count || channel->combined_count ||
1124 channel->tx_count > MLX4_EN_MAX_TX_RING_P_UP ||
1125 channel->rx_count > MAX_RX_RINGS ||
1126 !channel->tx_count || !channel->rx_count)
1127 return -EINVAL;
1128
1129 mutex_lock(&mdev->state_lock);
1130 if (priv->port_up) {
1131 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +00001132 mlx4_en_stop_port(dev, 1);
Amir Vadaid3179662012-12-02 03:49:23 +00001133 }
1134
1135 mlx4_en_free_resources(priv);
1136
1137 priv->num_tx_rings_p_up = channel->tx_count;
1138 priv->tx_ring_num = channel->tx_count * MLX4_EN_NUM_UP;
1139 priv->rx_ring_num = channel->rx_count;
1140
1141 err = mlx4_en_alloc_resources(priv);
1142 if (err) {
1143 en_err(priv, "Failed reallocating port resources\n");
1144 goto out;
1145 }
1146
1147 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
1148 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
1149
1150 mlx4_en_setup_tc(dev, MLX4_EN_NUM_UP);
1151
1152 en_warn(priv, "Using %d TX rings\n", priv->tx_ring_num);
1153 en_warn(priv, "Using %d RX rings\n", priv->rx_ring_num);
1154
1155 if (port_up) {
1156 err = mlx4_en_start_port(dev);
1157 if (err)
1158 en_err(priv, "Failed starting port\n");
1159 }
1160
1161 err = mlx4_en_moderation_update(priv);
1162
1163out:
1164 mutex_unlock(&mdev->state_lock);
1165 return err;
1166}
1167
Amir Vadaiec693d42013-04-23 06:06:49 +00001168static int mlx4_en_get_ts_info(struct net_device *dev,
1169 struct ethtool_ts_info *info)
1170{
1171 struct mlx4_en_priv *priv = netdev_priv(dev);
1172 struct mlx4_en_dev *mdev = priv->mdev;
1173 int ret;
1174
1175 ret = ethtool_op_get_ts_info(dev, info);
1176 if (ret)
1177 return ret;
1178
1179 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) {
1180 info->so_timestamping |=
1181 SOF_TIMESTAMPING_TX_HARDWARE |
1182 SOF_TIMESTAMPING_RX_HARDWARE |
1183 SOF_TIMESTAMPING_RAW_HARDWARE;
1184
1185 info->tx_types =
1186 (1 << HWTSTAMP_TX_OFF) |
1187 (1 << HWTSTAMP_TX_ON);
1188
1189 info->rx_filters =
1190 (1 << HWTSTAMP_FILTER_NONE) |
1191 (1 << HWTSTAMP_FILTER_ALL);
1192 }
1193
1194 return ret;
1195}
1196
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001197const struct ethtool_ops mlx4_en_ethtool_ops = {
1198 .get_drvinfo = mlx4_en_get_drvinfo,
1199 .get_settings = mlx4_en_get_settings,
1200 .set_settings = mlx4_en_set_settings,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001201 .get_link = ethtool_op_get_link,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001202 .get_strings = mlx4_en_get_strings,
1203 .get_sset_count = mlx4_en_get_sset_count,
1204 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +00001205 .self_test = mlx4_en_self_test,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001206 .get_wol = mlx4_en_get_wol,
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +00001207 .set_wol = mlx4_en_set_wol,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001208 .get_msglevel = mlx4_en_get_msglevel,
1209 .set_msglevel = mlx4_en_set_msglevel,
1210 .get_coalesce = mlx4_en_get_coalesce,
1211 .set_coalesce = mlx4_en_set_coalesce,
1212 .get_pauseparam = mlx4_en_get_pauseparam,
1213 .set_pauseparam = mlx4_en_set_pauseparam,
1214 .get_ringparam = mlx4_en_get_ringparam,
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001215 .set_ringparam = mlx4_en_set_ringparam,
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001216 .get_rxnfc = mlx4_en_get_rxnfc,
Hadar Hen Zion82067282012-07-05 04:03:49 +00001217 .set_rxnfc = mlx4_en_set_rxnfc,
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001218 .get_rxfh_indir_size = mlx4_en_get_rxfh_indir_size,
1219 .get_rxfh_indir = mlx4_en_get_rxfh_indir,
1220 .set_rxfh_indir = mlx4_en_set_rxfh_indir,
Amir Vadaid3179662012-12-02 03:49:23 +00001221 .get_channels = mlx4_en_get_channels,
1222 .set_channels = mlx4_en_set_channels,
Amir Vadaiec693d42013-04-23 06:06:49 +00001223 .get_ts_info = mlx4_en_get_ts_info,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001224};
1225
1226
1227
1228
1229