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>
43 mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
45 struct mlx4_en_priv *priv = netdev_priv(dev);
46 struct mlx4_en_dev *mdev = priv->mdev;
48 switch (mdev->dev->rev_id) {
50 if (dev->dev_id >= MLX4_EN_CX3_LOW_ID && dev->dev_id <= MLX4_EN_CX3_HIGH_ID)
51 sprintf(drvinfo->driver, DRV_NAME " (%s_CX-3)", mdev->dev->board_id);
53 sprintf(drvinfo->driver, DRV_NAME " (%s_CX)", mdev->dev->board_id);
56 sprintf(drvinfo->driver, DRV_NAME " (%s_CX-2)", mdev->dev->board_id);
59 sprintf(drvinfo->driver, DRV_NAME " (%s)", mdev->dev->board_id);
62 strncpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", 32);
63 sprintf(drvinfo->fw_version, "%d.%d.%d",
64 (u16) (mdev->dev->caps.fw_ver >> 32),
65 (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
66 (u16) (mdev->dev->caps.fw_ver & 0xffff));
67 strncpy(drvinfo->bus_info, pci_name(mdev->dev->pdev), 32);
69 drvinfo->regdump_len = 0;
70 drvinfo->eedump_len = 0;
73 static u32 mlx4_en_get_tso(struct net_device *dev)
75 return (dev->features & NETIF_F_TSO) != 0;
78 static int mlx4_en_set_tso(struct net_device *dev, u32 data)
80 struct mlx4_en_priv *priv = netdev_priv(dev);
83 if (!priv->mdev->LSO_support)
85 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
87 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
91 static u32 mlx4_en_get_rx_csum(struct net_device *dev)
93 struct mlx4_en_priv *priv = netdev_priv(dev);
97 static int mlx4_en_set_rx_csum(struct net_device *dev, u32 data)
99 struct mlx4_en_priv *priv = netdev_priv(dev);
100 priv->rx_csum = (data != 0);
104 static const char main_strings[][ETH_GSTRING_LEN] = {
105 "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
106 "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
107 "rx_length_errors", "rx_over_errors", "rx_crc_errors",
108 "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
109 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
110 "tx_heartbeat_errors", "tx_window_errors",
112 /* port statistics */
114 "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
115 "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
117 /* packet statistics */
118 "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
119 "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
120 "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
121 "tx_prio_6", "tx_prio_7",
123 #define NUM_MAIN_STATS 21
124 #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
126 static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= {
134 static u32 mlx4_en_get_msglevel(struct net_device *dev)
136 return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
139 static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
141 ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
144 static void mlx4_en_get_wol(struct net_device *netdev,
145 struct ethtool_wolinfo *wol)
147 struct mlx4_en_priv *priv = netdev_priv(netdev);
151 if (!priv->mdev->dev->caps.wol) {
157 err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
159 en_err(priv, "Failed to get WoL information\n");
163 if (config & MLX4_EN_WOL_MAGIC)
164 wol->supported = WAKE_MAGIC;
168 if (config & MLX4_EN_WOL_ENABLED)
169 wol->wolopts = WAKE_MAGIC;
174 static int mlx4_en_set_wol(struct net_device *netdev,
175 struct ethtool_wolinfo *wol)
177 struct mlx4_en_priv *priv = netdev_priv(netdev);
181 if (!priv->mdev->dev->caps.wol)
184 if (wol->supported & ~WAKE_MAGIC)
187 err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
189 en_err(priv, "Failed to get WoL info, unable to modify\n");
193 if (wol->wolopts & WAKE_MAGIC) {
194 config |= MLX4_EN_WOL_DO_MODIFY | MLX4_EN_WOL_ENABLED |
197 config &= ~(MLX4_EN_WOL_ENABLED | MLX4_EN_WOL_MAGIC);
198 config |= MLX4_EN_WOL_DO_MODIFY;
201 err = mlx4_wol_write(priv->mdev->dev, config, priv->port);
203 en_err(priv, "Failed to set WoL information\n");
208 static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
210 struct mlx4_en_priv *priv = netdev_priv(dev);
214 return NUM_ALL_STATS +
215 (priv->tx_ring_num + priv->rx_ring_num) * 2;
217 return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.loopback_support) * 2;
223 static void mlx4_en_get_ethtool_stats(struct net_device *dev,
224 struct ethtool_stats *stats, uint64_t *data)
226 struct mlx4_en_priv *priv = netdev_priv(dev);
230 spin_lock_bh(&priv->stats_lock);
232 for (i = 0; i < NUM_MAIN_STATS; i++)
233 data[index++] = ((unsigned long *) &priv->stats)[i];
234 for (i = 0; i < NUM_PORT_STATS; i++)
235 data[index++] = ((unsigned long *) &priv->port_stats)[i];
236 for (i = 0; i < priv->tx_ring_num; i++) {
237 data[index++] = priv->tx_ring[i].packets;
238 data[index++] = priv->tx_ring[i].bytes;
240 for (i = 0; i < priv->rx_ring_num; i++) {
241 data[index++] = priv->rx_ring[i].packets;
242 data[index++] = priv->rx_ring[i].bytes;
244 for (i = 0; i < NUM_PKT_STATS; i++)
245 data[index++] = ((unsigned long *) &priv->pkstats)[i];
246 spin_unlock_bh(&priv->stats_lock);
250 static void mlx4_en_self_test(struct net_device *dev,
251 struct ethtool_test *etest, u64 *buf)
253 mlx4_en_ex_selftest(dev, &etest->flags, buf);
256 static void mlx4_en_get_strings(struct net_device *dev,
257 uint32_t stringset, uint8_t *data)
259 struct mlx4_en_priv *priv = netdev_priv(dev);
265 for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++)
266 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
267 if (priv->mdev->dev->caps.loopback_support)
268 for (; i < MLX4_EN_NUM_SELF_TEST; i++)
269 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
273 /* Add main counters */
274 for (i = 0; i < NUM_MAIN_STATS; i++)
275 strcpy(data + (index++) * ETH_GSTRING_LEN, main_strings[i]);
276 for (i = 0; i< NUM_PORT_STATS; i++)
277 strcpy(data + (index++) * ETH_GSTRING_LEN,
278 main_strings[i + NUM_MAIN_STATS]);
279 for (i = 0; i < priv->tx_ring_num; i++) {
280 sprintf(data + (index++) * ETH_GSTRING_LEN,
282 sprintf(data + (index++) * ETH_GSTRING_LEN,
285 for (i = 0; i < priv->rx_ring_num; i++) {
286 sprintf(data + (index++) * ETH_GSTRING_LEN,
288 sprintf(data + (index++) * ETH_GSTRING_LEN,
291 for (i = 0; i< NUM_PKT_STATS; i++)
292 strcpy(data + (index++) * ETH_GSTRING_LEN,
293 main_strings[i + NUM_MAIN_STATS + NUM_PORT_STATS]);
298 static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
300 struct mlx4_en_priv *priv = netdev_priv(dev);
303 cmd->autoneg = AUTONEG_DISABLE;
304 cmd->supported = SUPPORTED_10000baseT_Full;
305 cmd->advertising = ADVERTISED_10000baseT_Full;
307 if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
310 trans_type = priv->port_state.transciver;
311 if (netif_carrier_ok(dev)) {
312 cmd->speed = priv->port_state.link_speed;
313 cmd->duplex = DUPLEX_FULL;
319 if (trans_type > 0 && trans_type <= 0xC) {
320 cmd->port = PORT_FIBRE;
321 cmd->transceiver = XCVR_EXTERNAL;
322 cmd->supported |= SUPPORTED_FIBRE;
323 cmd->advertising |= ADVERTISED_FIBRE;
324 } else if (trans_type == 0x80 || trans_type == 0) {
326 cmd->transceiver = XCVR_INTERNAL;
327 cmd->supported |= SUPPORTED_TP;
328 cmd->advertising |= ADVERTISED_TP;
331 cmd->transceiver = -1;
336 static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
338 if ((cmd->autoneg == AUTONEG_ENABLE) ||
339 (cmd->speed != SPEED_10000) || (cmd->duplex != DUPLEX_FULL))
342 /* Nothing to change */
346 static int mlx4_en_get_coalesce(struct net_device *dev,
347 struct ethtool_coalesce *coal)
349 struct mlx4_en_priv *priv = netdev_priv(dev);
351 coal->tx_coalesce_usecs = 0;
352 coal->tx_max_coalesced_frames = 0;
353 coal->rx_coalesce_usecs = priv->rx_usecs;
354 coal->rx_max_coalesced_frames = priv->rx_frames;
356 coal->pkt_rate_low = priv->pkt_rate_low;
357 coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
358 coal->pkt_rate_high = priv->pkt_rate_high;
359 coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
360 coal->rate_sample_interval = priv->sample_interval;
361 coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
365 static int mlx4_en_set_coalesce(struct net_device *dev,
366 struct ethtool_coalesce *coal)
368 struct mlx4_en_priv *priv = netdev_priv(dev);
371 priv->rx_frames = (coal->rx_max_coalesced_frames ==
373 MLX4_EN_RX_COAL_TARGET :
374 coal->rx_max_coalesced_frames;
375 priv->rx_usecs = (coal->rx_coalesce_usecs ==
377 MLX4_EN_RX_COAL_TIME :
378 coal->rx_coalesce_usecs;
380 /* Set adaptive coalescing params */
381 priv->pkt_rate_low = coal->pkt_rate_low;
382 priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
383 priv->pkt_rate_high = coal->pkt_rate_high;
384 priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
385 priv->sample_interval = coal->rate_sample_interval;
386 priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
387 priv->last_moder_time = MLX4_EN_AUTO_CONF;
388 if (priv->adaptive_rx_coal)
391 for (i = 0; i < priv->rx_ring_num; i++) {
392 priv->rx_cq[i].moder_cnt = priv->rx_frames;
393 priv->rx_cq[i].moder_time = priv->rx_usecs;
394 err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
401 static int mlx4_en_set_pauseparam(struct net_device *dev,
402 struct ethtool_pauseparam *pause)
404 struct mlx4_en_priv *priv = netdev_priv(dev);
405 struct mlx4_en_dev *mdev = priv->mdev;
408 priv->prof->tx_pause = pause->tx_pause != 0;
409 priv->prof->rx_pause = pause->rx_pause != 0;
410 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
411 priv->rx_skb_size + ETH_FCS_LEN,
412 priv->prof->tx_pause,
414 priv->prof->rx_pause,
417 en_err(priv, "Failed setting pause params\n");
422 static void mlx4_en_get_pauseparam(struct net_device *dev,
423 struct ethtool_pauseparam *pause)
425 struct mlx4_en_priv *priv = netdev_priv(dev);
427 pause->tx_pause = priv->prof->tx_pause;
428 pause->rx_pause = priv->prof->rx_pause;
431 static int mlx4_en_set_ringparam(struct net_device *dev,
432 struct ethtool_ringparam *param)
434 struct mlx4_en_priv *priv = netdev_priv(dev);
435 struct mlx4_en_dev *mdev = priv->mdev;
436 u32 rx_size, tx_size;
440 if (param->rx_jumbo_pending || param->rx_mini_pending)
443 rx_size = roundup_pow_of_two(param->rx_pending);
444 rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
445 rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
446 tx_size = roundup_pow_of_two(param->tx_pending);
447 tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
448 tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
450 if (rx_size == (priv->port_up ? priv->rx_ring[0].actual_size :
451 priv->rx_ring[0].size) &&
452 tx_size == priv->tx_ring[0].size)
455 mutex_lock(&mdev->state_lock);
458 mlx4_en_stop_port(dev);
461 mlx4_en_free_resources(priv, true);
463 priv->prof->tx_ring_size = tx_size;
464 priv->prof->rx_ring_size = rx_size;
466 err = mlx4_en_alloc_resources(priv);
468 en_err(priv, "Failed reallocating port resources\n");
472 err = mlx4_en_start_port(dev);
474 en_err(priv, "Failed starting port\n");
478 mutex_unlock(&mdev->state_lock);
482 static void mlx4_en_get_ringparam(struct net_device *dev,
483 struct ethtool_ringparam *param)
485 struct mlx4_en_priv *priv = netdev_priv(dev);
487 memset(param, 0, sizeof(*param));
488 param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
489 param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
490 param->rx_pending = priv->port_up ?
491 priv->rx_ring[0].actual_size : priv->rx_ring[0].size;
492 param->tx_pending = priv->tx_ring[0].size;
495 const struct ethtool_ops mlx4_en_ethtool_ops = {
496 .get_drvinfo = mlx4_en_get_drvinfo,
497 .get_settings = mlx4_en_get_settings,
498 .set_settings = mlx4_en_set_settings,
500 .get_tso = mlx4_en_get_tso,
501 .set_tso = mlx4_en_set_tso,
503 .get_sg = ethtool_op_get_sg,
504 .set_sg = ethtool_op_set_sg,
505 .get_link = ethtool_op_get_link,
506 .get_rx_csum = mlx4_en_get_rx_csum,
507 .set_rx_csum = mlx4_en_set_rx_csum,
508 .get_tx_csum = ethtool_op_get_tx_csum,
509 .set_tx_csum = ethtool_op_set_tx_ipv6_csum,
510 .get_strings = mlx4_en_get_strings,
511 .get_sset_count = mlx4_en_get_sset_count,
512 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
513 .self_test = mlx4_en_self_test,
514 .get_wol = mlx4_en_get_wol,
515 .set_wol = mlx4_en_set_wol,
516 .get_msglevel = mlx4_en_get_msglevel,
517 .set_msglevel = mlx4_en_set_msglevel,
518 .get_coalesce = mlx4_en_get_coalesce,
519 .set_coalesce = mlx4_en_set_coalesce,
520 .get_pauseparam = mlx4_en_get_pauseparam,
521 .set_pauseparam = mlx4_en_set_pauseparam,
522 .get_ringparam = mlx4_en_get_ringparam,
523 .set_ringparam = mlx4_en_set_ringparam,
524 .get_flags = ethtool_op_get_flags,