blob: c1bd040b9e05df2b7c1bfe25e23e53411743dfed [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
41#define MLX4_EN_PARM_INT(X, def_val, desc) \
42 static unsigned int X = def_val;\
43 module_param(X , uint, 0444); \
44 MODULE_PARM_DESC(X, desc);
45
46
47/*
48 * Device scope module parameters
49 */
50
51
52/* Use a XOR rathern than Toeplitz hash function for RSS */
53MLX4_EN_PARM_INT(rss_xor, 0, "Use XOR hash function for RSS");
54
55/* RSS hash type mask - default to <saddr, daddr, sport, dport> */
56MLX4_EN_PARM_INT(rss_mask, 0xf, "RSS hash type bitmask");
57
58/* Number of LRO sessions per Rx ring (rounded up to a power of two) */
59MLX4_EN_PARM_INT(num_lro, MLX4_EN_MAX_LRO_DESCRIPTORS,
60 "Number of LRO sessions per ring or disabled (0)");
61
62/* Priority pausing */
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070063MLX4_EN_PARM_INT(pfctx, 0, "Priority based Flow Control policy on TX[7:0]."
64 " Per priority bit mask");
65MLX4_EN_PARM_INT(pfcrx, 0, "Priority based Flow Control policy on RX[7:0]."
66 " Per priority bit mask");
67
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070068int mlx4_en_get_profile(struct mlx4_en_dev *mdev)
69{
70 struct mlx4_en_profile *params = &mdev->profile;
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +000071 int i;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070072
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070073 params->rss_xor = (rss_xor != 0);
74 params->rss_mask = rss_mask & 0x1f;
75 params->num_lro = min_t(int, num_lro , MLX4_EN_MAX_LRO_DESCRIPTORS);
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +000076 for (i = 1; i <= MLX4_MAX_PORTS; i++) {
Yevgeny Petrilin26c743b2008-12-25 18:20:13 -080077 params->prof[i].rx_pause = 1;
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +000078 params->prof[i].rx_ppp = pfcrx;
Yevgeny Petrilin26c743b2008-12-25 18:20:13 -080079 params->prof[i].tx_pause = 1;
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +000080 params->prof[i].tx_ppp = pfctx;
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -080081 params->prof[i].tx_ring_size = MLX4_EN_DEF_TX_RING_SIZE;
82 params->prof[i].rx_ring_size = MLX4_EN_DEF_RX_RING_SIZE;
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +000083 }
84 if (pfcrx || pfctx) {
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070085 params->prof[1].tx_ring_num = MLX4_EN_TX_RING_NUM;
86 params->prof[2].tx_ring_num = MLX4_EN_TX_RING_NUM;
87 } else {
88 params->prof[1].tx_ring_num = 1;
89 params->prof[2].tx_ring_num = 1;
90 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070091
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070092 return 0;
93}
94
95
96/*
97 * Ethtool support
98 */
99
100static void mlx4_en_update_lro_stats(struct mlx4_en_priv *priv)
101{
102 int i;
103
104 priv->port_stats.lro_aggregated = 0;
105 priv->port_stats.lro_flushed = 0;
106 priv->port_stats.lro_no_desc = 0;
107
108 for (i = 0; i < priv->rx_ring_num; i++) {
109 priv->port_stats.lro_aggregated += priv->rx_ring[i].lro.stats.aggregated;
110 priv->port_stats.lro_flushed += priv->rx_ring[i].lro.stats.flushed;
111 priv->port_stats.lro_no_desc += priv->rx_ring[i].lro.stats.no_desc;
112 }
113}
114
115static void
116mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
117{
118 struct mlx4_en_priv *priv = netdev_priv(dev);
119 struct mlx4_en_dev *mdev = priv->mdev;
120
121 sprintf(drvinfo->driver, DRV_NAME " (%s)", mdev->dev->board_id);
122 strncpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", 32);
123 sprintf(drvinfo->fw_version, "%d.%d.%d",
124 (u16) (mdev->dev->caps.fw_ver >> 32),
125 (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
126 (u16) (mdev->dev->caps.fw_ver & 0xffff));
127 strncpy(drvinfo->bus_info, pci_name(mdev->dev->pdev), 32);
128 drvinfo->n_stats = 0;
129 drvinfo->regdump_len = 0;
130 drvinfo->eedump_len = 0;
131}
132
133static u32 mlx4_en_get_tso(struct net_device *dev)
134{
135 return (dev->features & NETIF_F_TSO) != 0;
136}
137
138static int mlx4_en_set_tso(struct net_device *dev, u32 data)
139{
140 struct mlx4_en_priv *priv = netdev_priv(dev);
141
142 if (data) {
143 if (!priv->mdev->LSO_support)
144 return -EPERM;
145 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
146 } else
147 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
148 return 0;
149}
150
151static u32 mlx4_en_get_rx_csum(struct net_device *dev)
152{
153 struct mlx4_en_priv *priv = netdev_priv(dev);
154 return priv->rx_csum;
155}
156
157static int mlx4_en_set_rx_csum(struct net_device *dev, u32 data)
158{
159 struct mlx4_en_priv *priv = netdev_priv(dev);
160 priv->rx_csum = (data != 0);
161 return 0;
162}
163
164static const char main_strings[][ETH_GSTRING_LEN] = {
165 "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
166 "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
167 "rx_length_errors", "rx_over_errors", "rx_crc_errors",
168 "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
169 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
170 "tx_heartbeat_errors", "tx_window_errors",
171
172 /* port statistics */
173 "lro_aggregated", "lro_flushed", "lro_no_desc", "tso_packets",
174 "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
175 "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
176
177 /* packet statistics */
178 "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
179 "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
180 "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
181 "tx_prio_6", "tx_prio_7",
182};
183#define NUM_MAIN_STATS 21
184#define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
185
186static u32 mlx4_en_get_msglevel(struct net_device *dev)
187{
188 return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
189}
190
191static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
192{
193 ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
194}
195
196static void mlx4_en_get_wol(struct net_device *netdev,
197 struct ethtool_wolinfo *wol)
198{
199 wol->supported = 0;
200 wol->wolopts = 0;
201
202 return;
203}
204
205static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
206{
207 struct mlx4_en_priv *priv = netdev_priv(dev);
208
209 if (sset != ETH_SS_STATS)
210 return -EOPNOTSUPP;
211
212 return NUM_ALL_STATS + (priv->tx_ring_num + priv->rx_ring_num) * 2;
213}
214
215static void mlx4_en_get_ethtool_stats(struct net_device *dev,
216 struct ethtool_stats *stats, uint64_t *data)
217{
218 struct mlx4_en_priv *priv = netdev_priv(dev);
219 int index = 0;
220 int i;
221
222 spin_lock_bh(&priv->stats_lock);
223
224 mlx4_en_update_lro_stats(priv);
225
226 for (i = 0; i < NUM_MAIN_STATS; i++)
227 data[index++] = ((unsigned long *) &priv->stats)[i];
228 for (i = 0; i < NUM_PORT_STATS; i++)
229 data[index++] = ((unsigned long *) &priv->port_stats)[i];
230 for (i = 0; i < priv->tx_ring_num; i++) {
231 data[index++] = priv->tx_ring[i].packets;
232 data[index++] = priv->tx_ring[i].bytes;
233 }
234 for (i = 0; i < priv->rx_ring_num; i++) {
235 data[index++] = priv->rx_ring[i].packets;
236 data[index++] = priv->rx_ring[i].bytes;
237 }
238 for (i = 0; i < NUM_PKT_STATS; i++)
239 data[index++] = ((unsigned long *) &priv->pkstats)[i];
240 spin_unlock_bh(&priv->stats_lock);
241
242}
243
244static void mlx4_en_get_strings(struct net_device *dev,
245 uint32_t stringset, uint8_t *data)
246{
247 struct mlx4_en_priv *priv = netdev_priv(dev);
248 int index = 0;
249 int i;
250
251 if (stringset != ETH_SS_STATS)
252 return;
253
254 /* Add main counters */
255 for (i = 0; i < NUM_MAIN_STATS; i++)
256 strcpy(data + (index++) * ETH_GSTRING_LEN, main_strings[i]);
257 for (i = 0; i < NUM_PORT_STATS; i++)
258 strcpy(data + (index++) * ETH_GSTRING_LEN,
259 main_strings[i + NUM_MAIN_STATS]);
260 for (i = 0; i < priv->tx_ring_num; i++) {
261 sprintf(data + (index++) * ETH_GSTRING_LEN,
262 "tx%d_packets", i);
263 sprintf(data + (index++) * ETH_GSTRING_LEN,
264 "tx%d_bytes", i);
265 }
266 for (i = 0; i < priv->rx_ring_num; i++) {
267 sprintf(data + (index++) * ETH_GSTRING_LEN,
268 "rx%d_packets", i);
269 sprintf(data + (index++) * ETH_GSTRING_LEN,
270 "rx%d_bytes", i);
271 }
272 for (i = 0; i < NUM_PKT_STATS; i++)
273 strcpy(data + (index++) * ETH_GSTRING_LEN,
274 main_strings[i + NUM_MAIN_STATS + NUM_PORT_STATS]);
275}
276
277static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
278{
279 cmd->autoneg = AUTONEG_DISABLE;
280 cmd->supported = SUPPORTED_10000baseT_Full;
281 cmd->advertising = SUPPORTED_10000baseT_Full;
282 if (netif_carrier_ok(dev)) {
283 cmd->speed = SPEED_10000;
284 cmd->duplex = DUPLEX_FULL;
285 } else {
286 cmd->speed = -1;
287 cmd->duplex = -1;
288 }
289 return 0;
290}
291
292static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
293{
294 if ((cmd->autoneg == AUTONEG_ENABLE) ||
295 (cmd->speed != SPEED_10000) || (cmd->duplex != DUPLEX_FULL))
296 return -EINVAL;
297
298 /* Nothing to change */
299 return 0;
300}
301
302static int mlx4_en_get_coalesce(struct net_device *dev,
303 struct ethtool_coalesce *coal)
304{
305 struct mlx4_en_priv *priv = netdev_priv(dev);
306
307 coal->tx_coalesce_usecs = 0;
308 coal->tx_max_coalesced_frames = 0;
309 coal->rx_coalesce_usecs = priv->rx_usecs;
310 coal->rx_max_coalesced_frames = priv->rx_frames;
311
312 coal->pkt_rate_low = priv->pkt_rate_low;
313 coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
314 coal->pkt_rate_high = priv->pkt_rate_high;
315 coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
316 coal->rate_sample_interval = priv->sample_interval;
317 coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
318 return 0;
319}
320
321static int mlx4_en_set_coalesce(struct net_device *dev,
322 struct ethtool_coalesce *coal)
323{
324 struct mlx4_en_priv *priv = netdev_priv(dev);
325 int err, i;
326
327 priv->rx_frames = (coal->rx_max_coalesced_frames ==
328 MLX4_EN_AUTO_CONF) ?
329 MLX4_EN_RX_COAL_TARGET /
330 priv->dev->mtu + 1 :
331 coal->rx_max_coalesced_frames;
332 priv->rx_usecs = (coal->rx_coalesce_usecs ==
333 MLX4_EN_AUTO_CONF) ?
334 MLX4_EN_RX_COAL_TIME :
335 coal->rx_coalesce_usecs;
336
337 /* Set adaptive coalescing params */
338 priv->pkt_rate_low = coal->pkt_rate_low;
339 priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
340 priv->pkt_rate_high = coal->pkt_rate_high;
341 priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
342 priv->sample_interval = coal->rate_sample_interval;
343 priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
344 priv->last_moder_time = MLX4_EN_AUTO_CONF;
345 if (priv->adaptive_rx_coal)
346 return 0;
347
348 for (i = 0; i < priv->rx_ring_num; i++) {
349 priv->rx_cq[i].moder_cnt = priv->rx_frames;
350 priv->rx_cq[i].moder_time = priv->rx_usecs;
351 err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
352 if (err)
353 return err;
354 }
355 return 0;
356}
357
358static int mlx4_en_set_pauseparam(struct net_device *dev,
359 struct ethtool_pauseparam *pause)
360{
361 struct mlx4_en_priv *priv = netdev_priv(dev);
362 struct mlx4_en_dev *mdev = priv->mdev;
363 int err;
364
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000365 priv->prof->tx_pause = pause->tx_pause != 0;
366 priv->prof->rx_pause = pause->rx_pause != 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700367 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
368 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000369 priv->prof->tx_pause,
370 priv->prof->tx_ppp,
371 priv->prof->rx_pause,
372 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700373 if (err)
374 mlx4_err(mdev, "Failed setting pause params to\n");
375
376 return err;
377}
378
379static void mlx4_en_get_pauseparam(struct net_device *dev,
380 struct ethtool_pauseparam *pause)
381{
382 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700383
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +0000384 pause->tx_pause = priv->prof->tx_pause;
385 pause->rx_pause = priv->prof->rx_pause;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700386}
387
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800388static int mlx4_en_set_ringparam(struct net_device *dev,
389 struct ethtool_ringparam *param)
390{
391 struct mlx4_en_priv *priv = netdev_priv(dev);
392 struct mlx4_en_dev *mdev = priv->mdev;
393 u32 rx_size, tx_size;
394 int port_up = 0;
395 int err = 0;
396
397 if (param->rx_jumbo_pending || param->rx_mini_pending)
398 return -EINVAL;
399
400 rx_size = roundup_pow_of_two(param->rx_pending);
401 rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800402 rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800403 tx_size = roundup_pow_of_two(param->tx_pending);
404 tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800405 tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800406
407 if (rx_size == priv->prof->rx_ring_size &&
408 tx_size == priv->prof->tx_ring_size)
409 return 0;
410
411 mutex_lock(&mdev->state_lock);
412 if (priv->port_up) {
413 port_up = 1;
414 mlx4_en_stop_port(dev);
415 }
416
417 mlx4_en_free_resources(priv);
418
419 priv->prof->tx_ring_size = tx_size;
420 priv->prof->rx_ring_size = rx_size;
421
422 err = mlx4_en_alloc_resources(priv);
423 if (err) {
424 mlx4_err(mdev, "Failed reallocating port resources\n");
425 goto out;
426 }
427 if (port_up) {
428 err = mlx4_en_start_port(dev);
429 if (err)
430 mlx4_err(mdev, "Failed starting port\n");
431 }
432
433out:
434 mutex_unlock(&mdev->state_lock);
435 return err;
436}
437
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700438static void mlx4_en_get_ringparam(struct net_device *dev,
439 struct ethtool_ringparam *param)
440{
441 struct mlx4_en_priv *priv = netdev_priv(dev);
442 struct mlx4_en_dev *mdev = priv->mdev;
443
444 memset(param, 0, sizeof(*param));
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -0800445 param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
446 param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700447 param->rx_pending = mdev->profile.prof[priv->port].rx_ring_size;
448 param->tx_pending = mdev->profile.prof[priv->port].tx_ring_size;
449}
450
451const struct ethtool_ops mlx4_en_ethtool_ops = {
452 .get_drvinfo = mlx4_en_get_drvinfo,
453 .get_settings = mlx4_en_get_settings,
454 .set_settings = mlx4_en_set_settings,
455#ifdef NETIF_F_TSO
456 .get_tso = mlx4_en_get_tso,
457 .set_tso = mlx4_en_set_tso,
458#endif
459 .get_sg = ethtool_op_get_sg,
460 .set_sg = ethtool_op_set_sg,
461 .get_link = ethtool_op_get_link,
462 .get_rx_csum = mlx4_en_get_rx_csum,
463 .set_rx_csum = mlx4_en_set_rx_csum,
464 .get_tx_csum = ethtool_op_get_tx_csum,
465 .set_tx_csum = ethtool_op_set_tx_ipv6_csum,
466 .get_strings = mlx4_en_get_strings,
467 .get_sset_count = mlx4_en_get_sset_count,
468 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
469 .get_wol = mlx4_en_get_wol,
470 .get_msglevel = mlx4_en_get_msglevel,
471 .set_msglevel = mlx4_en_set_msglevel,
472 .get_coalesce = mlx4_en_get_coalesce,
473 .set_coalesce = mlx4_en_set_coalesce,
474 .get_pauseparam = mlx4_en_get_pauseparam,
475 .set_pauseparam = mlx4_en_set_pauseparam,
476 .get_ringparam = mlx4_en_get_ringparam,
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -0800477 .set_ringparam = mlx4_en_set_ringparam,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700478 .get_flags = ethtool_op_get_flags,
479 .set_flags = ethtool_op_set_flags,
480};
481
482
483
484
485