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>
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);
48 * Device scope module parameters
52 /* Use a XOR rathern than Toeplitz hash function for RSS */
53 MLX4_EN_PARM_INT(rss_xor, 0, "Use XOR hash function for RSS");
55 /* RSS hash type mask - default to <saddr, daddr, sport, dport> */
56 MLX4_EN_PARM_INT(rss_mask, 0xf, "RSS hash type bitmask");
58 /* Number of LRO sessions per Rx ring (rounded up to a power of two) */
59 MLX4_EN_PARM_INT(num_lro, MLX4_EN_MAX_LRO_DESCRIPTORS,
60 "Number of LRO sessions per ring or disabled (0)");
62 /* Priority pausing */
63 MLX4_EN_PARM_INT(pptx, MLX4_EN_DEF_TX_PAUSE,
64 "Pause policy on TX: 0 never generate pause frames "
65 "1 generate pause frames according to RX buffer threshold");
66 MLX4_EN_PARM_INT(pprx, MLX4_EN_DEF_RX_PAUSE,
67 "Pause policy on RX: 0 ignore received pause frames "
68 "1 respect received pause frames");
69 MLX4_EN_PARM_INT(pfctx, 0, "Priority based Flow Control policy on TX[7:0]."
70 " Per priority bit mask");
71 MLX4_EN_PARM_INT(pfcrx, 0, "Priority based Flow Control policy on RX[7:0]."
72 " Per priority bit mask");
74 /* Interrupt moderation tunning */
75 MLX4_EN_PARM_INT(rx_moder_cnt, MLX4_EN_AUTO_CONF,
76 "Max coalesced descriptors for Rx interrupt moderation");
77 MLX4_EN_PARM_INT(rx_moder_time, MLX4_EN_AUTO_CONF,
78 "Timeout following last packet for Rx interrupt moderation");
79 MLX4_EN_PARM_INT(auto_moder, 1, "Enable dynamic interrupt moderation");
81 MLX4_EN_PARM_INT(rx_ring_num1, 0, "Number or Rx rings for port 1 (0 = #cores)");
82 MLX4_EN_PARM_INT(rx_ring_num2, 0, "Number or Rx rings for port 2 (0 = #cores)");
84 MLX4_EN_PARM_INT(tx_ring_size1, MLX4_EN_AUTO_CONF, "Tx ring size for port 1");
85 MLX4_EN_PARM_INT(tx_ring_size2, MLX4_EN_AUTO_CONF, "Tx ring size for port 2");
86 MLX4_EN_PARM_INT(rx_ring_size1, MLX4_EN_AUTO_CONF, "Rx ring size for port 1");
87 MLX4_EN_PARM_INT(rx_ring_size2, MLX4_EN_AUTO_CONF, "Rx ring size for port 2");
90 int mlx4_en_get_profile(struct mlx4_en_dev *mdev)
92 struct mlx4_en_profile *params = &mdev->profile;
95 params->rx_moder_cnt = min_t(int, rx_moder_cnt, MLX4_EN_AUTO_CONF);
96 params->rx_moder_time = min_t(int, rx_moder_time, MLX4_EN_AUTO_CONF);
97 params->auto_moder = auto_moder;
98 params->rss_xor = (rss_xor != 0);
99 params->rss_mask = rss_mask & 0x1f;
100 params->num_lro = min_t(int, num_lro , MLX4_EN_MAX_LRO_DESCRIPTORS);
101 for (i = 1; i <= MLX4_MAX_PORTS; i++) {
102 params->prof[i].rx_pause = pprx;
103 params->prof[i].rx_ppp = pfcrx;
104 params->prof[i].tx_pause = pptx;
105 params->prof[i].tx_ppp = pfctx;
107 if (pfcrx || pfctx) {
108 params->prof[1].tx_ring_num = MLX4_EN_TX_RING_NUM;
109 params->prof[2].tx_ring_num = MLX4_EN_TX_RING_NUM;
111 params->prof[1].tx_ring_num = 1;
112 params->prof[2].tx_ring_num = 1;
114 params->prof[1].rx_ring_num = min_t(int, rx_ring_num1, MAX_RX_RINGS);
115 params->prof[2].rx_ring_num = min_t(int, rx_ring_num2, MAX_RX_RINGS);
117 if (tx_ring_size1 == MLX4_EN_AUTO_CONF)
118 tx_ring_size1 = MLX4_EN_DEF_TX_RING_SIZE;
119 params->prof[1].tx_ring_size =
120 (tx_ring_size1 < MLX4_EN_MIN_TX_SIZE) ?
121 MLX4_EN_MIN_TX_SIZE : roundup_pow_of_two(tx_ring_size1);
123 if (tx_ring_size2 == MLX4_EN_AUTO_CONF)
124 tx_ring_size2 = MLX4_EN_DEF_TX_RING_SIZE;
125 params->prof[2].tx_ring_size =
126 (tx_ring_size2 < MLX4_EN_MIN_TX_SIZE) ?
127 MLX4_EN_MIN_TX_SIZE : roundup_pow_of_two(tx_ring_size2);
129 if (rx_ring_size1 == MLX4_EN_AUTO_CONF)
130 rx_ring_size1 = MLX4_EN_DEF_RX_RING_SIZE;
131 params->prof[1].rx_ring_size =
132 (rx_ring_size1 < MLX4_EN_MIN_RX_SIZE) ?
133 MLX4_EN_MIN_RX_SIZE : roundup_pow_of_two(rx_ring_size1);
135 if (rx_ring_size2 == MLX4_EN_AUTO_CONF)
136 rx_ring_size2 = MLX4_EN_DEF_RX_RING_SIZE;
137 params->prof[2].rx_ring_size =
138 (rx_ring_size2 < MLX4_EN_MIN_RX_SIZE) ?
139 MLX4_EN_MIN_RX_SIZE : roundup_pow_of_two(rx_ring_size2);
148 static void mlx4_en_update_lro_stats(struct mlx4_en_priv *priv)
152 priv->port_stats.lro_aggregated = 0;
153 priv->port_stats.lro_flushed = 0;
154 priv->port_stats.lro_no_desc = 0;
156 for (i = 0; i < priv->rx_ring_num; i++) {
157 priv->port_stats.lro_aggregated += priv->rx_ring[i].lro.stats.aggregated;
158 priv->port_stats.lro_flushed += priv->rx_ring[i].lro.stats.flushed;
159 priv->port_stats.lro_no_desc += priv->rx_ring[i].lro.stats.no_desc;
164 mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
166 struct mlx4_en_priv *priv = netdev_priv(dev);
167 struct mlx4_en_dev *mdev = priv->mdev;
169 sprintf(drvinfo->driver, DRV_NAME " (%s)", mdev->dev->board_id);
170 strncpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", 32);
171 sprintf(drvinfo->fw_version, "%d.%d.%d",
172 (u16) (mdev->dev->caps.fw_ver >> 32),
173 (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
174 (u16) (mdev->dev->caps.fw_ver & 0xffff));
175 strncpy(drvinfo->bus_info, pci_name(mdev->dev->pdev), 32);
176 drvinfo->n_stats = 0;
177 drvinfo->regdump_len = 0;
178 drvinfo->eedump_len = 0;
181 static u32 mlx4_en_get_tso(struct net_device *dev)
183 return (dev->features & NETIF_F_TSO) != 0;
186 static int mlx4_en_set_tso(struct net_device *dev, u32 data)
188 struct mlx4_en_priv *priv = netdev_priv(dev);
191 if (!priv->mdev->LSO_support)
193 dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
195 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
199 static u32 mlx4_en_get_rx_csum(struct net_device *dev)
201 struct mlx4_en_priv *priv = netdev_priv(dev);
202 return priv->rx_csum;
205 static int mlx4_en_set_rx_csum(struct net_device *dev, u32 data)
207 struct mlx4_en_priv *priv = netdev_priv(dev);
208 priv->rx_csum = (data != 0);
212 static const char main_strings[][ETH_GSTRING_LEN] = {
213 "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
214 "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
215 "rx_length_errors", "rx_over_errors", "rx_crc_errors",
216 "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
217 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
218 "tx_heartbeat_errors", "tx_window_errors",
220 /* port statistics */
221 "lro_aggregated", "lro_flushed", "lro_no_desc", "tso_packets",
222 "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
223 "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
225 /* packet statistics */
226 "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
227 "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
228 "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
229 "tx_prio_6", "tx_prio_7",
231 #define NUM_MAIN_STATS 21
232 #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
234 static u32 mlx4_en_get_msglevel(struct net_device *dev)
236 return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
239 static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
241 ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
244 static void mlx4_en_get_wol(struct net_device *netdev,
245 struct ethtool_wolinfo *wol)
253 static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
255 struct mlx4_en_priv *priv = netdev_priv(dev);
257 if (sset != ETH_SS_STATS)
260 return NUM_ALL_STATS + (priv->tx_ring_num + priv->rx_ring_num) * 2;
263 static void mlx4_en_get_ethtool_stats(struct net_device *dev,
264 struct ethtool_stats *stats, uint64_t *data)
266 struct mlx4_en_priv *priv = netdev_priv(dev);
270 spin_lock_bh(&priv->stats_lock);
272 mlx4_en_update_lro_stats(priv);
274 for (i = 0; i < NUM_MAIN_STATS; i++)
275 data[index++] = ((unsigned long *) &priv->stats)[i];
276 for (i = 0; i < NUM_PORT_STATS; i++)
277 data[index++] = ((unsigned long *) &priv->port_stats)[i];
278 for (i = 0; i < priv->tx_ring_num; i++) {
279 data[index++] = priv->tx_ring[i].packets;
280 data[index++] = priv->tx_ring[i].bytes;
282 for (i = 0; i < priv->rx_ring_num; i++) {
283 data[index++] = priv->rx_ring[i].packets;
284 data[index++] = priv->rx_ring[i].bytes;
286 for (i = 0; i < NUM_PKT_STATS; i++)
287 data[index++] = ((unsigned long *) &priv->pkstats)[i];
288 spin_unlock_bh(&priv->stats_lock);
292 static void mlx4_en_get_strings(struct net_device *dev,
293 uint32_t stringset, uint8_t *data)
295 struct mlx4_en_priv *priv = netdev_priv(dev);
299 if (stringset != ETH_SS_STATS)
302 /* Add main counters */
303 for (i = 0; i < NUM_MAIN_STATS; i++)
304 strcpy(data + (index++) * ETH_GSTRING_LEN, main_strings[i]);
305 for (i = 0; i < NUM_PORT_STATS; i++)
306 strcpy(data + (index++) * ETH_GSTRING_LEN,
307 main_strings[i + NUM_MAIN_STATS]);
308 for (i = 0; i < priv->tx_ring_num; i++) {
309 sprintf(data + (index++) * ETH_GSTRING_LEN,
311 sprintf(data + (index++) * ETH_GSTRING_LEN,
314 for (i = 0; i < priv->rx_ring_num; i++) {
315 sprintf(data + (index++) * ETH_GSTRING_LEN,
317 sprintf(data + (index++) * ETH_GSTRING_LEN,
320 for (i = 0; i < NUM_PKT_STATS; i++)
321 strcpy(data + (index++) * ETH_GSTRING_LEN,
322 main_strings[i + NUM_MAIN_STATS + NUM_PORT_STATS]);
325 static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
327 cmd->autoneg = AUTONEG_DISABLE;
328 cmd->supported = SUPPORTED_10000baseT_Full;
329 cmd->advertising = SUPPORTED_10000baseT_Full;
330 if (netif_carrier_ok(dev)) {
331 cmd->speed = SPEED_10000;
332 cmd->duplex = DUPLEX_FULL;
340 static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
342 if ((cmd->autoneg == AUTONEG_ENABLE) ||
343 (cmd->speed != SPEED_10000) || (cmd->duplex != DUPLEX_FULL))
346 /* Nothing to change */
350 static int mlx4_en_get_coalesce(struct net_device *dev,
351 struct ethtool_coalesce *coal)
353 struct mlx4_en_priv *priv = netdev_priv(dev);
355 coal->tx_coalesce_usecs = 0;
356 coal->tx_max_coalesced_frames = 0;
357 coal->rx_coalesce_usecs = priv->rx_usecs;
358 coal->rx_max_coalesced_frames = priv->rx_frames;
360 coal->pkt_rate_low = priv->pkt_rate_low;
361 coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
362 coal->pkt_rate_high = priv->pkt_rate_high;
363 coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
364 coal->rate_sample_interval = priv->sample_interval;
365 coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
369 static int mlx4_en_set_coalesce(struct net_device *dev,
370 struct ethtool_coalesce *coal)
372 struct mlx4_en_priv *priv = netdev_priv(dev);
375 priv->rx_frames = (coal->rx_max_coalesced_frames ==
377 MLX4_EN_RX_COAL_TARGET /
379 coal->rx_max_coalesced_frames;
380 priv->rx_usecs = (coal->rx_coalesce_usecs ==
382 MLX4_EN_RX_COAL_TIME :
383 coal->rx_coalesce_usecs;
385 /* Set adaptive coalescing params */
386 priv->pkt_rate_low = coal->pkt_rate_low;
387 priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
388 priv->pkt_rate_high = coal->pkt_rate_high;
389 priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
390 priv->sample_interval = coal->rate_sample_interval;
391 priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
392 priv->last_moder_time = MLX4_EN_AUTO_CONF;
393 if (priv->adaptive_rx_coal)
396 for (i = 0; i < priv->rx_ring_num; i++) {
397 priv->rx_cq[i].moder_cnt = priv->rx_frames;
398 priv->rx_cq[i].moder_time = priv->rx_usecs;
399 err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
406 static int mlx4_en_set_pauseparam(struct net_device *dev,
407 struct ethtool_pauseparam *pause)
409 struct mlx4_en_priv *priv = netdev_priv(dev);
410 struct mlx4_en_dev *mdev = priv->mdev;
413 priv->prof->tx_pause = pause->tx_pause != 0;
414 priv->prof->rx_pause = pause->rx_pause != 0;
415 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
416 priv->rx_skb_size + ETH_FCS_LEN,
417 priv->prof->tx_pause,
419 priv->prof->rx_pause,
422 mlx4_err(mdev, "Failed setting pause params to\n");
427 static void mlx4_en_get_pauseparam(struct net_device *dev,
428 struct ethtool_pauseparam *pause)
430 struct mlx4_en_priv *priv = netdev_priv(dev);
432 pause->tx_pause = priv->prof->tx_pause;
433 pause->rx_pause = priv->prof->rx_pause;
436 static void mlx4_en_get_ringparam(struct net_device *dev,
437 struct ethtool_ringparam *param)
439 struct mlx4_en_priv *priv = netdev_priv(dev);
440 struct mlx4_en_dev *mdev = priv->mdev;
442 memset(param, 0, sizeof(*param));
443 param->rx_max_pending = mdev->dev->caps.max_rq_sg;
444 param->tx_max_pending = mdev->dev->caps.max_sq_sg;
445 param->rx_pending = mdev->profile.prof[priv->port].rx_ring_size;
446 param->tx_pending = mdev->profile.prof[priv->port].tx_ring_size;
449 const struct ethtool_ops mlx4_en_ethtool_ops = {
450 .get_drvinfo = mlx4_en_get_drvinfo,
451 .get_settings = mlx4_en_get_settings,
452 .set_settings = mlx4_en_set_settings,
454 .get_tso = mlx4_en_get_tso,
455 .set_tso = mlx4_en_set_tso,
457 .get_sg = ethtool_op_get_sg,
458 .set_sg = ethtool_op_set_sg,
459 .get_link = ethtool_op_get_link,
460 .get_rx_csum = mlx4_en_get_rx_csum,
461 .set_rx_csum = mlx4_en_set_rx_csum,
462 .get_tx_csum = ethtool_op_get_tx_csum,
463 .set_tx_csum = ethtool_op_set_tx_ipv6_csum,
464 .get_strings = mlx4_en_get_strings,
465 .get_sset_count = mlx4_en_get_sset_count,
466 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
467 .get_wol = mlx4_en_get_wol,
468 .get_msglevel = mlx4_en_get_msglevel,
469 .set_msglevel = mlx4_en_set_msglevel,
470 .get_coalesce = mlx4_en_get_coalesce,
471 .set_coalesce = mlx4_en_set_coalesce,
472 .get_pauseparam = mlx4_en_get_pauseparam,
473 .set_pauseparam = mlx4_en_set_pauseparam,
474 .get_ringparam = mlx4_en_get_ringparam,
475 .get_flags = ethtool_op_get_flags,
476 .set_flags = ethtool_op_set_flags,