2 * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
34 #include <linux/kernel.h>
35 #include <linux/ethtool.h>
36 #include <linux/netdevice.h>
42 static void mlx4_en_update_lro_stats(struct mlx4_en_priv *priv)
46 priv->port_stats.lro_aggregated = 0;
47 priv->port_stats.lro_flushed = 0;
48 priv->port_stats.lro_no_desc = 0;
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;
58 mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
60 struct mlx4_en_priv *priv = netdev_priv(dev);
61 struct mlx4_en_dev *mdev = priv->mdev;
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);
71 drvinfo->regdump_len = 0;
72 drvinfo->eedump_len = 0;
75 static u32 mlx4_en_get_tso(struct net_device *dev)
77 return (dev->features & NETIF_F_TSO) != 0;
80 static int mlx4_en_set_tso(struct net_device *dev, u32 data)
82 struct mlx4_en_priv *priv = netdev_priv(dev);
85 if (!priv->mdev->LSO_support)
87 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
89 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
93 static u32 mlx4_en_get_rx_csum(struct net_device *dev)
95 struct mlx4_en_priv *priv = netdev_priv(dev);
99 static int mlx4_en_set_rx_csum(struct net_device *dev, u32 data)
101 struct mlx4_en_priv *priv = netdev_priv(dev);
102 priv->rx_csum = (data != 0);
106 static 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",
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",
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",
125 #define NUM_MAIN_STATS 21
126 #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
128 static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= {
136 static u32 mlx4_en_get_msglevel(struct net_device *dev)
138 return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
141 static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
143 ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
146 static void mlx4_en_get_wol(struct net_device *netdev,
147 struct ethtool_wolinfo *wol)
153 static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
155 struct mlx4_en_priv *priv = netdev_priv(dev);
159 return NUM_ALL_STATS +
160 (priv->tx_ring_num + priv->rx_ring_num) * 2;
162 return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.loopback_support) * 2;
168 static void mlx4_en_get_ethtool_stats(struct net_device *dev,
169 struct ethtool_stats *stats, uint64_t *data)
171 struct mlx4_en_priv *priv = netdev_priv(dev);
175 spin_lock_bh(&priv->stats_lock);
177 mlx4_en_update_lro_stats(priv);
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;
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;
191 for (i = 0; i < NUM_PKT_STATS; i++)
192 data[index++] = ((unsigned long *) &priv->pkstats)[i];
193 spin_unlock_bh(&priv->stats_lock);
197 static void mlx4_en_self_test(struct net_device *dev,
198 struct ethtool_test *etest, u64 *buf)
200 mlx4_en_ex_selftest(dev, &etest->flags, buf);
203 static void mlx4_en_get_strings(struct net_device *dev,
204 uint32_t stringset, uint8_t *data)
206 struct mlx4_en_priv *priv = netdev_priv(dev);
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]);
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,
225 main_strings[i + NUM_MAIN_STATS]);
226 for (i = 0; i < priv->tx_ring_num; i++) {
227 sprintf(data + (index++) * ETH_GSTRING_LEN,
229 sprintf(data + (index++) * ETH_GSTRING_LEN,
232 for (i = 0; i < priv->rx_ring_num; i++) {
233 sprintf(data + (index++) * ETH_GSTRING_LEN,
235 sprintf(data + (index++) * ETH_GSTRING_LEN,
238 for (i = 0; i< NUM_PKT_STATS; i++)
239 strcpy(data + (index++) * ETH_GSTRING_LEN,
240 main_strings[i + NUM_MAIN_STATS + NUM_PORT_STATS]);
245 static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
247 struct mlx4_en_priv *priv = netdev_priv(dev);
250 cmd->autoneg = AUTONEG_DISABLE;
251 cmd->supported = SUPPORTED_10000baseT_Full;
252 cmd->advertising = ADVERTISED_10000baseT_Full;
254 if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
257 trans_type = priv->port_state.transciver;
258 if (netif_carrier_ok(dev)) {
259 cmd->speed = priv->port_state.link_speed;
260 cmd->duplex = DUPLEX_FULL;
266 if (trans_type > 0 && trans_type <= 0xC) {
267 cmd->port = PORT_FIBRE;
268 cmd->transceiver = XCVR_EXTERNAL;
269 cmd->supported |= SUPPORTED_FIBRE;
270 cmd->advertising |= ADVERTISED_FIBRE;
271 } else if (trans_type == 0x80 || trans_type == 0) {
273 cmd->transceiver = XCVR_INTERNAL;
274 cmd->supported |= SUPPORTED_TP;
275 cmd->advertising |= ADVERTISED_TP;
278 cmd->transceiver = -1;
283 static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
285 if ((cmd->autoneg == AUTONEG_ENABLE) ||
286 (cmd->speed != SPEED_10000) || (cmd->duplex != DUPLEX_FULL))
289 /* Nothing to change */
293 static int mlx4_en_get_coalesce(struct net_device *dev,
294 struct ethtool_coalesce *coal)
296 struct mlx4_en_priv *priv = netdev_priv(dev);
298 coal->tx_coalesce_usecs = 0;
299 coal->tx_max_coalesced_frames = 0;
300 coal->rx_coalesce_usecs = priv->rx_usecs;
301 coal->rx_max_coalesced_frames = priv->rx_frames;
303 coal->pkt_rate_low = priv->pkt_rate_low;
304 coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
305 coal->pkt_rate_high = priv->pkt_rate_high;
306 coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
307 coal->rate_sample_interval = priv->sample_interval;
308 coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
312 static int mlx4_en_set_coalesce(struct net_device *dev,
313 struct ethtool_coalesce *coal)
315 struct mlx4_en_priv *priv = netdev_priv(dev);
318 priv->rx_frames = (coal->rx_max_coalesced_frames ==
320 MLX4_EN_RX_COAL_TARGET :
321 coal->rx_max_coalesced_frames;
322 priv->rx_usecs = (coal->rx_coalesce_usecs ==
324 MLX4_EN_RX_COAL_TIME :
325 coal->rx_coalesce_usecs;
327 /* Set adaptive coalescing params */
328 priv->pkt_rate_low = coal->pkt_rate_low;
329 priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
330 priv->pkt_rate_high = coal->pkt_rate_high;
331 priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
332 priv->sample_interval = coal->rate_sample_interval;
333 priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
334 priv->last_moder_time = MLX4_EN_AUTO_CONF;
335 if (priv->adaptive_rx_coal)
338 for (i = 0; i < priv->rx_ring_num; i++) {
339 priv->rx_cq[i].moder_cnt = priv->rx_frames;
340 priv->rx_cq[i].moder_time = priv->rx_usecs;
341 err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
348 static int mlx4_en_set_pauseparam(struct net_device *dev,
349 struct ethtool_pauseparam *pause)
351 struct mlx4_en_priv *priv = netdev_priv(dev);
352 struct mlx4_en_dev *mdev = priv->mdev;
355 priv->prof->tx_pause = pause->tx_pause != 0;
356 priv->prof->rx_pause = pause->rx_pause != 0;
357 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
358 priv->rx_skb_size + ETH_FCS_LEN,
359 priv->prof->tx_pause,
361 priv->prof->rx_pause,
364 en_err(priv, "Failed setting pause params\n");
369 static void mlx4_en_get_pauseparam(struct net_device *dev,
370 struct ethtool_pauseparam *pause)
372 struct mlx4_en_priv *priv = netdev_priv(dev);
374 pause->tx_pause = priv->prof->tx_pause;
375 pause->rx_pause = priv->prof->rx_pause;
378 static int mlx4_en_set_ringparam(struct net_device *dev,
379 struct ethtool_ringparam *param)
381 struct mlx4_en_priv *priv = netdev_priv(dev);
382 struct mlx4_en_dev *mdev = priv->mdev;
383 u32 rx_size, tx_size;
387 if (param->rx_jumbo_pending || param->rx_mini_pending)
390 rx_size = roundup_pow_of_two(param->rx_pending);
391 rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
392 rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
393 tx_size = roundup_pow_of_two(param->tx_pending);
394 tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
395 tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
397 if (rx_size == (priv->port_up ? priv->rx_ring[0].actual_size :
398 priv->rx_ring[0].size) &&
399 tx_size == priv->tx_ring[0].size)
402 mutex_lock(&mdev->state_lock);
405 mlx4_en_stop_port(dev);
408 mlx4_en_free_resources(priv);
410 priv->prof->tx_ring_size = tx_size;
411 priv->prof->rx_ring_size = rx_size;
413 err = mlx4_en_alloc_resources(priv);
415 en_err(priv, "Failed reallocating port resources\n");
419 err = mlx4_en_start_port(dev);
421 en_err(priv, "Failed starting port\n");
425 mutex_unlock(&mdev->state_lock);
429 static void mlx4_en_get_ringparam(struct net_device *dev,
430 struct ethtool_ringparam *param)
432 struct mlx4_en_priv *priv = netdev_priv(dev);
434 memset(param, 0, sizeof(*param));
435 param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
436 param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
437 param->rx_pending = priv->port_up ?
438 priv->rx_ring[0].actual_size : priv->rx_ring[0].size;
439 param->tx_pending = priv->tx_ring[0].size;
442 static int mlx4_ethtool_op_set_flags(struct net_device *dev, u32 data)
444 struct mlx4_en_priv *priv = netdev_priv(dev);
445 struct mlx4_en_dev *mdev = priv->mdev;
449 if (data & ~ETH_FLAG_LRO)
452 if (data & ETH_FLAG_LRO) {
453 if (!(dev->features & NETIF_F_LRO))
455 } else if (dev->features & NETIF_F_LRO) {
460 if (netif_running(dev)) {
461 mutex_lock(&mdev->state_lock);
462 mlx4_en_stop_port(dev);
464 dev->features ^= NETIF_F_LRO;
465 if (netif_running(dev)) {
466 rc = mlx4_en_start_port(dev);
468 en_err(priv, "Failed to restart port\n");
469 mutex_unlock(&mdev->state_lock);
476 const struct ethtool_ops mlx4_en_ethtool_ops = {
477 .get_drvinfo = mlx4_en_get_drvinfo,
478 .get_settings = mlx4_en_get_settings,
479 .set_settings = mlx4_en_set_settings,
481 .get_tso = mlx4_en_get_tso,
482 .set_tso = mlx4_en_set_tso,
484 .get_sg = ethtool_op_get_sg,
485 .set_sg = ethtool_op_set_sg,
486 .get_link = ethtool_op_get_link,
487 .get_rx_csum = mlx4_en_get_rx_csum,
488 .set_rx_csum = mlx4_en_set_rx_csum,
489 .get_tx_csum = ethtool_op_get_tx_csum,
490 .set_tx_csum = ethtool_op_set_tx_ipv6_csum,
491 .get_strings = mlx4_en_get_strings,
492 .get_sset_count = mlx4_en_get_sset_count,
493 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
494 .self_test = mlx4_en_self_test,
495 .get_wol = mlx4_en_get_wol,
496 .get_msglevel = mlx4_en_get_msglevel,
497 .set_msglevel = mlx4_en_set_msglevel,
498 .get_coalesce = mlx4_en_get_coalesce,
499 .set_coalesce = mlx4_en_set_coalesce,
500 .get_pauseparam = mlx4_en_get_pauseparam,
501 .set_pauseparam = mlx4_en_set_pauseparam,
502 .get_ringparam = mlx4_en_get_ringparam,
503 .set_ringparam = mlx4_en_set_ringparam,
504 .get_flags = ethtool_op_get_flags,
505 .set_flags = mlx4_ethtool_op_set_flags,