blob: f7d72d7a870469ab1eb8f3c37cce537ad7deef74 [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>
37
38#include "mlx4_en.h"
39#include "en_port.h"
40
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070041
42static void mlx4_en_update_lro_stats(struct mlx4_en_priv *priv)
43{
44 int i;
45
46 priv->port_stats.lro_aggregated = 0;
47 priv->port_stats.lro_flushed = 0;
48 priv->port_stats.lro_no_desc = 0;
49
50 for (i = 0; i < priv->rx_ring_num; i++) {
51 priv->port_stats.lro_aggregated += priv->rx_ring[i].lro.stats.aggregated;
52 priv->port_stats.lro_flushed += priv->rx_ring[i].lro.stats.flushed;
53 priv->port_stats.lro_no_desc += priv->rx_ring[i].lro.stats.no_desc;
54 }
55}
56
57static void
58mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
59{
60 struct mlx4_en_priv *priv = netdev_priv(dev);
61 struct mlx4_en_dev *mdev = priv->mdev;
62
63 sprintf(drvinfo->driver, DRV_NAME " (%s)", mdev->dev->board_id);
64 strncpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", 32);
65 sprintf(drvinfo->fw_version, "%d.%d.%d",
66 (u16) (mdev->dev->caps.fw_ver >> 32),
67 (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
68 (u16) (mdev->dev->caps.fw_ver & 0xffff));
69 strncpy(drvinfo->bus_info, pci_name(mdev->dev->pdev), 32);
70 drvinfo->n_stats = 0;
71 drvinfo->regdump_len = 0;
72 drvinfo->eedump_len = 0;
73}
74
75static u32 mlx4_en_get_tso(struct net_device *dev)
76{
77 return (dev->features & NETIF_F_TSO) != 0;
78}
79
80static int mlx4_en_set_tso(struct net_device *dev, u32 data)
81{
82 struct mlx4_en_priv *priv = netdev_priv(dev);
83
84 if (data) {
85 if (!priv->mdev->LSO_support)
86 return -EPERM;
87 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
88 } else
89 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
90 return 0;
91}
92
93static u32 mlx4_en_get_rx_csum(struct net_device *dev)
94{
95 struct mlx4_en_priv *priv = netdev_priv(dev);
96 return priv->rx_csum;
97}
98
99static int mlx4_en_set_rx_csum(struct net_device *dev, u32 data)
100{
101 struct mlx4_en_priv *priv = netdev_priv(dev);
102 priv->rx_csum = (data != 0);
103 return 0;
104}
105
106static const char main_strings[][ETH_GSTRING_LEN] = {
107 "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
108 "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
109 "rx_length_errors", "rx_over_errors", "rx_crc_errors",
110 "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
111 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
112 "tx_heartbeat_errors", "tx_window_errors",
113
114 /* port statistics */
115 "lro_aggregated", "lro_flushed", "lro_no_desc", "tso_packets",
116 "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
117 "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
118
119 /* packet statistics */
120 "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
121 "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
122 "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
123 "tx_prio_6", "tx_prio_7",
124};
125#define NUM_MAIN_STATS 21
126#define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
127
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000128static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= {
129 "Interupt Test",
130 "Link Test",
131 "Speed Test",
132 "Register Test",
133 "Loopback Test",
134};
135
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700136static u32 mlx4_en_get_msglevel(struct net_device *dev)
137{
138 return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
139}
140
141static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
142{
143 ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
144}
145
146static void mlx4_en_get_wol(struct net_device *netdev,
147 struct ethtool_wolinfo *wol)
148{
149 wol->supported = 0;
150 wol->wolopts = 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700151}
152
153static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
154{
155 struct mlx4_en_priv *priv = netdev_priv(dev);
156
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000157 switch (sset) {
158 case ETH_SS_STATS:
159 return NUM_ALL_STATS +
160 (priv->tx_ring_num + priv->rx_ring_num) * 2;
161 case ETH_SS_TEST:
162 return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.loopback_support) * 2;
163 default:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700164 return -EOPNOTSUPP;
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000165 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700166}
167
168static void mlx4_en_get_ethtool_stats(struct net_device *dev,
169 struct ethtool_stats *stats, uint64_t *data)
170{
171 struct mlx4_en_priv *priv = netdev_priv(dev);
172 int index = 0;
173 int i;
174
175 spin_lock_bh(&priv->stats_lock);
176
177 mlx4_en_update_lro_stats(priv);
178
179 for (i = 0; i < NUM_MAIN_STATS; i++)
180 data[index++] = ((unsigned long *) &priv->stats)[i];
181 for (i = 0; i < NUM_PORT_STATS; i++)
182 data[index++] = ((unsigned long *) &priv->port_stats)[i];
183 for (i = 0; i < priv->tx_ring_num; i++) {
184 data[index++] = priv->tx_ring[i].packets;
185 data[index++] = priv->tx_ring[i].bytes;
186 }
187 for (i = 0; i < priv->rx_ring_num; i++) {
188 data[index++] = priv->rx_ring[i].packets;
189 data[index++] = priv->rx_ring[i].bytes;
190 }
191 for (i = 0; i < NUM_PKT_STATS; i++)
192 data[index++] = ((unsigned long *) &priv->pkstats)[i];
193 spin_unlock_bh(&priv->stats_lock);
194
195}
196
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000197static void mlx4_en_self_test(struct net_device *dev,
198 struct ethtool_test *etest, u64 *buf)
199{
200 mlx4_en_ex_selftest(dev, &etest->flags, buf);
201}
202
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700203static void mlx4_en_get_strings(struct net_device *dev,
204 uint32_t stringset, uint8_t *data)
205{
206 struct mlx4_en_priv *priv = netdev_priv(dev);
207 int index = 0;
208 int i;
209
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000210 switch (stringset) {
211 case ETH_SS_TEST:
212 for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++)
213 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
214 if (priv->mdev->dev->caps.loopback_support)
215 for (; i < MLX4_EN_NUM_SELF_TEST; i++)
216 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
217 break;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700218
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000219 case ETH_SS_STATS:
220 /* Add main counters */
221 for (i = 0; i < NUM_MAIN_STATS; i++)
222 strcpy(data + (index++) * ETH_GSTRING_LEN, main_strings[i]);
223 for (i = 0; i< NUM_PORT_STATS; i++)
224 strcpy(data + (index++) * ETH_GSTRING_LEN,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700225 main_strings[i + NUM_MAIN_STATS]);
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000226 for (i = 0; i < priv->tx_ring_num; i++) {
227 sprintf(data + (index++) * ETH_GSTRING_LEN,
228 "tx%d_packets", i);
229 sprintf(data + (index++) * ETH_GSTRING_LEN,
230 "tx%d_bytes", i);
231 }
232 for (i = 0; i < priv->rx_ring_num; i++) {
233 sprintf(data + (index++) * ETH_GSTRING_LEN,
234 "rx%d_packets", i);
235 sprintf(data + (index++) * ETH_GSTRING_LEN,
236 "rx%d_bytes", i);
237 }
238 for (i = 0; i< NUM_PKT_STATS; i++)
239 strcpy(data + (index++) * ETH_GSTRING_LEN,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700240 main_strings[i + NUM_MAIN_STATS + NUM_PORT_STATS]);
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000241 break;
242 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700243}
244
245static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
246{
247 cmd->autoneg = AUTONEG_DISABLE;
248 cmd->supported = SUPPORTED_10000baseT_Full;
Julia Lawall86669532009-07-19 06:09:25 +0000249 cmd->advertising = ADVERTISED_1000baseT_Full;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700250 if (netif_carrier_ok(dev)) {
251 cmd->speed = SPEED_10000;
252 cmd->duplex = DUPLEX_FULL;
253 } else {
254 cmd->speed = -1;
255 cmd->duplex = -1;
256 }
257 return 0;
258}
259
260static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
261{
262 if ((cmd->autoneg == AUTONEG_ENABLE) ||
263 (cmd->speed != SPEED_10000) || (cmd->duplex != DUPLEX_FULL))
264 return -EINVAL;
265
266 /* Nothing to change */
267 return 0;
268}
269
270static int mlx4_en_get_coalesce(struct net_device *dev,
271 struct ethtool_coalesce *coal)
272{
273 struct mlx4_en_priv *priv = netdev_priv(dev);
274
275 coal->tx_coalesce_usecs = 0;
276 coal->tx_max_coalesced_frames = 0;
277 coal->rx_coalesce_usecs = priv->rx_usecs;
278 coal->rx_max_coalesced_frames = priv->rx_frames;
279
280 coal->pkt_rate_low = priv->pkt_rate_low;
281 coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
282 coal->pkt_rate_high = priv->pkt_rate_high;
283 coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
284 coal->rate_sample_interval = priv->sample_interval;
285 coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
286 return 0;
287}
288
289static int mlx4_en_set_coalesce(struct net_device *dev,
290 struct ethtool_coalesce *coal)
291{
292 struct mlx4_en_priv *priv = netdev_priv(dev);
293 int err, i;
294
295 priv->rx_frames = (coal->rx_max_coalesced_frames ==
296 MLX4_EN_AUTO_CONF) ?
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +0000297 MLX4_EN_RX_COAL_TARGET :
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700298 coal->rx_max_coalesced_frames;
299 priv->rx_usecs = (coal->rx_coalesce_usecs ==
300 MLX4_EN_AUTO_CONF) ?
301 MLX4_EN_RX_COAL_TIME :
302 coal->rx_coalesce_usecs;
303
304 /* Set adaptive coalescing params */
305 priv->pkt_rate_low = coal->pkt_rate_low;
306 priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
307 priv->pkt_rate_high = coal->pkt_rate_high;
308 priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
309 priv->sample_interval = coal->rate_sample_interval;
310 priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
311 priv->last_moder_time = MLX4_EN_AUTO_CONF;
312 if (priv->adaptive_rx_coal)
313 return 0;
314
315 for (i = 0; i < priv->rx_ring_num; i++) {
316 priv->rx_cq[i].moder_cnt = priv->rx_frames;
317 priv->rx_cq[i].moder_time = priv->rx_usecs;
318 err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
319 if (err)
320 return err;
321 }
322 return 0;
323}
324
325static int mlx4_en_set_pauseparam(struct net_device *dev,
326 struct ethtool_pauseparam *pause)
327{
328 struct mlx4_en_priv *priv = netdev_priv(dev);
329 struct mlx4_en_dev *mdev = priv->mdev;
330 int err;
331
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000332 priv->prof->tx_pause = pause->tx_pause != 0;
333 priv->prof->rx_pause = pause->rx_pause != 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700334 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
335 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000336 priv->prof->tx_pause,
337 priv->prof->tx_ppp,
338 priv->prof->rx_pause,
339 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700340 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000341 en_err(priv, "Failed setting pause params\n");
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700342
343 return err;
344}
345
346static void mlx4_en_get_pauseparam(struct net_device *dev,
347 struct ethtool_pauseparam *pause)
348{
349 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700350
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000351 pause->tx_pause = priv->prof->tx_pause;
352 pause->rx_pause = priv->prof->rx_pause;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700353}
354
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800355static int mlx4_en_set_ringparam(struct net_device *dev,
356 struct ethtool_ringparam *param)
357{
358 struct mlx4_en_priv *priv = netdev_priv(dev);
359 struct mlx4_en_dev *mdev = priv->mdev;
360 u32 rx_size, tx_size;
361 int port_up = 0;
362 int err = 0;
363
364 if (param->rx_jumbo_pending || param->rx_mini_pending)
365 return -EINVAL;
366
367 rx_size = roundup_pow_of_two(param->rx_pending);
368 rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800369 rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800370 tx_size = roundup_pow_of_two(param->tx_pending);
371 tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800372 tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800373
374 if (rx_size == priv->prof->rx_ring_size &&
375 tx_size == priv->prof->tx_ring_size)
376 return 0;
377
378 mutex_lock(&mdev->state_lock);
379 if (priv->port_up) {
380 port_up = 1;
381 mlx4_en_stop_port(dev);
382 }
383
384 mlx4_en_free_resources(priv);
385
386 priv->prof->tx_ring_size = tx_size;
387 priv->prof->rx_ring_size = rx_size;
388
389 err = mlx4_en_alloc_resources(priv);
390 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000391 en_err(priv, "Failed reallocating port resources\n");
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800392 goto out;
393 }
394 if (port_up) {
395 err = mlx4_en_start_port(dev);
396 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +0000397 en_err(priv, "Failed starting port\n");
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800398 }
399
400out:
401 mutex_unlock(&mdev->state_lock);
402 return err;
403}
404
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700405static void mlx4_en_get_ringparam(struct net_device *dev,
406 struct ethtool_ringparam *param)
407{
408 struct mlx4_en_priv *priv = netdev_priv(dev);
409 struct mlx4_en_dev *mdev = priv->mdev;
410
411 memset(param, 0, sizeof(*param));
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800412 param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
413 param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700414 param->rx_pending = mdev->profile.prof[priv->port].rx_ring_size;
415 param->tx_pending = mdev->profile.prof[priv->port].tx_ring_size;
416}
417
Amerigo Wangd2ef8592010-06-21 22:50:17 +0000418static int mlx4_ethtool_op_set_flags(struct net_device *dev, u32 data)
419{
420 struct mlx4_en_priv *priv = netdev_priv(dev);
421 struct mlx4_en_dev *mdev = priv->mdev;
422 int rc = 0;
423 int changed = 0;
424
425 if (data & ~ETH_FLAG_LRO)
426 return -EOPNOTSUPP;
427
428 if (data & ETH_FLAG_LRO) {
Amerigo Wangd2ef8592010-06-21 22:50:17 +0000429 if (!(dev->features & NETIF_F_LRO))
430 changed = 1;
431 } else if (dev->features & NETIF_F_LRO) {
432 changed = 1;
433 }
434
435 if (changed) {
436 if (netif_running(dev)) {
437 mutex_lock(&mdev->state_lock);
438 mlx4_en_stop_port(dev);
439 }
440 dev->features ^= NETIF_F_LRO;
441 if (netif_running(dev)) {
442 rc = mlx4_en_start_port(dev);
443 if (rc)
444 en_err(priv, "Failed to restart port\n");
445 mutex_unlock(&mdev->state_lock);
446 }
447 }
448
449 return rc;
450}
451
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700452const struct ethtool_ops mlx4_en_ethtool_ops = {
453 .get_drvinfo = mlx4_en_get_drvinfo,
454 .get_settings = mlx4_en_get_settings,
455 .set_settings = mlx4_en_set_settings,
456#ifdef NETIF_F_TSO
457 .get_tso = mlx4_en_get_tso,
458 .set_tso = mlx4_en_set_tso,
459#endif
460 .get_sg = ethtool_op_get_sg,
461 .set_sg = ethtool_op_set_sg,
462 .get_link = ethtool_op_get_link,
463 .get_rx_csum = mlx4_en_get_rx_csum,
464 .set_rx_csum = mlx4_en_set_rx_csum,
465 .get_tx_csum = ethtool_op_get_tx_csum,
466 .set_tx_csum = ethtool_op_set_tx_ipv6_csum,
467 .get_strings = mlx4_en_get_strings,
468 .get_sset_count = mlx4_en_get_sset_count,
469 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000470 .self_test = mlx4_en_self_test,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700471 .get_wol = mlx4_en_get_wol,
472 .get_msglevel = mlx4_en_get_msglevel,
473 .set_msglevel = mlx4_en_set_msglevel,
474 .get_coalesce = mlx4_en_get_coalesce,
475 .set_coalesce = mlx4_en_set_coalesce,
476 .get_pauseparam = mlx4_en_get_pauseparam,
477 .set_pauseparam = mlx4_en_set_pauseparam,
478 .get_ringparam = mlx4_en_get_ringparam,
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800479 .set_ringparam = mlx4_en_set_ringparam,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700480 .get_flags = ethtool_op_get_flags,
Amerigo Wangd2ef8592010-06-21 22:50:17 +0000481 .set_flags = mlx4_ethtool_op_set_flags,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700482};
483
484
485
486
487