Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1 | /* |
| 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 Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 41 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 42 | static void |
| 43 | mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) |
| 44 | { |
| 45 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 46 | struct mlx4_en_dev *mdev = priv->mdev; |
| 47 | |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 48 | strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
| 49 | strlcpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", |
| 50 | sizeof(drvinfo->version)); |
| 51 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), |
| 52 | "%d.%d.%d", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 53 | (u16) (mdev->dev->caps.fw_ver >> 32), |
| 54 | (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff), |
| 55 | (u16) (mdev->dev->caps.fw_ver & 0xffff)); |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 56 | strlcpy(drvinfo->bus_info, pci_name(mdev->dev->pdev), |
| 57 | sizeof(drvinfo->bus_info)); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 58 | drvinfo->n_stats = 0; |
| 59 | drvinfo->regdump_len = 0; |
| 60 | drvinfo->eedump_len = 0; |
| 61 | } |
| 62 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 63 | static const char main_strings[][ETH_GSTRING_LEN] = { |
| 64 | "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors", |
| 65 | "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions", |
| 66 | "rx_length_errors", "rx_over_errors", "rx_crc_errors", |
| 67 | "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors", |
| 68 | "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", |
| 69 | "tx_heartbeat_errors", "tx_window_errors", |
| 70 | |
| 71 | /* port statistics */ |
Yevgeny Petrilin | fa37a95 | 2010-08-24 03:46:46 +0000 | [diff] [blame] | 72 | "tso_packets", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 73 | "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed", |
| 74 | "rx_csum_good", "rx_csum_none", "tx_chksum_offload", |
| 75 | |
| 76 | /* packet statistics */ |
| 77 | "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3", |
| 78 | "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0", |
| 79 | "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5", |
| 80 | "tx_prio_6", "tx_prio_7", |
| 81 | }; |
Yevgeny Petrilin | d61702f | 2010-09-05 22:20:24 +0000 | [diff] [blame] | 82 | #define NUM_MAIN_STATS 21 |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 83 | #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS) |
| 84 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 85 | static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= { |
| 86 | "Interupt Test", |
| 87 | "Link Test", |
| 88 | "Speed Test", |
| 89 | "Register Test", |
| 90 | "Loopback Test", |
| 91 | }; |
| 92 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 93 | static u32 mlx4_en_get_msglevel(struct net_device *dev) |
| 94 | { |
| 95 | return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable; |
| 96 | } |
| 97 | |
| 98 | static void mlx4_en_set_msglevel(struct net_device *dev, u32 val) |
| 99 | { |
| 100 | ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val; |
| 101 | } |
| 102 | |
| 103 | static void mlx4_en_get_wol(struct net_device *netdev, |
| 104 | struct ethtool_wolinfo *wol) |
| 105 | { |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 106 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
| 107 | int err = 0; |
| 108 | u64 config = 0; |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 109 | u64 mask; |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 110 | |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 111 | if ((priv->port < 1) || (priv->port > 2)) { |
| 112 | en_err(priv, "Failed to get WoL information\n"); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 : |
| 117 | MLX4_DEV_CAP_FLAG_WOL_PORT2; |
| 118 | |
| 119 | if (!(priv->mdev->dev->caps.flags & mask)) { |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 120 | wol->supported = 0; |
| 121 | wol->wolopts = 0; |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | err = mlx4_wol_read(priv->mdev->dev, &config, priv->port); |
| 126 | if (err) { |
| 127 | en_err(priv, "Failed to get WoL information\n"); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | if (config & MLX4_EN_WOL_MAGIC) |
| 132 | wol->supported = WAKE_MAGIC; |
| 133 | else |
| 134 | wol->supported = 0; |
| 135 | |
| 136 | if (config & MLX4_EN_WOL_ENABLED) |
| 137 | wol->wolopts = WAKE_MAGIC; |
| 138 | else |
| 139 | wol->wolopts = 0; |
| 140 | } |
| 141 | |
| 142 | static int mlx4_en_set_wol(struct net_device *netdev, |
| 143 | struct ethtool_wolinfo *wol) |
| 144 | { |
| 145 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
| 146 | u64 config = 0; |
| 147 | int err = 0; |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 148 | u64 mask; |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 149 | |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 150 | if ((priv->port < 1) || (priv->port > 2)) |
| 151 | return -EOPNOTSUPP; |
| 152 | |
| 153 | mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 : |
| 154 | MLX4_DEV_CAP_FLAG_WOL_PORT2; |
| 155 | |
| 156 | if (!(priv->mdev->dev->caps.flags & mask)) |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 157 | return -EOPNOTSUPP; |
| 158 | |
| 159 | if (wol->supported & ~WAKE_MAGIC) |
| 160 | return -EINVAL; |
| 161 | |
| 162 | err = mlx4_wol_read(priv->mdev->dev, &config, priv->port); |
| 163 | if (err) { |
| 164 | en_err(priv, "Failed to get WoL info, unable to modify\n"); |
| 165 | return err; |
| 166 | } |
| 167 | |
| 168 | if (wol->wolopts & WAKE_MAGIC) { |
| 169 | config |= MLX4_EN_WOL_DO_MODIFY | MLX4_EN_WOL_ENABLED | |
| 170 | MLX4_EN_WOL_MAGIC; |
| 171 | } else { |
| 172 | config &= ~(MLX4_EN_WOL_ENABLED | MLX4_EN_WOL_MAGIC); |
| 173 | config |= MLX4_EN_WOL_DO_MODIFY; |
| 174 | } |
| 175 | |
| 176 | err = mlx4_wol_write(priv->mdev->dev, config, priv->port); |
| 177 | if (err) |
| 178 | en_err(priv, "Failed to set WoL information\n"); |
| 179 | |
| 180 | return err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static int mlx4_en_get_sset_count(struct net_device *dev, int sset) |
| 184 | { |
| 185 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 186 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 187 | switch (sset) { |
| 188 | case ETH_SS_STATS: |
| 189 | return NUM_ALL_STATS + |
| 190 | (priv->tx_ring_num + priv->rx_ring_num) * 2; |
| 191 | case ETH_SS_TEST: |
Or Gerlitz | ccf8632 | 2011-07-07 19:19:29 +0000 | [diff] [blame] | 192 | return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags |
| 193 | & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2; |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 194 | default: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 195 | return -EOPNOTSUPP; |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 196 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static void mlx4_en_get_ethtool_stats(struct net_device *dev, |
| 200 | struct ethtool_stats *stats, uint64_t *data) |
| 201 | { |
| 202 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 203 | int index = 0; |
| 204 | int i; |
| 205 | |
| 206 | spin_lock_bh(&priv->stats_lock); |
| 207 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 208 | for (i = 0; i < NUM_MAIN_STATS; i++) |
| 209 | data[index++] = ((unsigned long *) &priv->stats)[i]; |
| 210 | for (i = 0; i < NUM_PORT_STATS; i++) |
| 211 | data[index++] = ((unsigned long *) &priv->port_stats)[i]; |
| 212 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 213 | data[index++] = priv->tx_ring[i].packets; |
| 214 | data[index++] = priv->tx_ring[i].bytes; |
| 215 | } |
| 216 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 217 | data[index++] = priv->rx_ring[i].packets; |
| 218 | data[index++] = priv->rx_ring[i].bytes; |
| 219 | } |
| 220 | for (i = 0; i < NUM_PKT_STATS; i++) |
| 221 | data[index++] = ((unsigned long *) &priv->pkstats)[i]; |
| 222 | spin_unlock_bh(&priv->stats_lock); |
| 223 | |
| 224 | } |
| 225 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 226 | static void mlx4_en_self_test(struct net_device *dev, |
| 227 | struct ethtool_test *etest, u64 *buf) |
| 228 | { |
| 229 | mlx4_en_ex_selftest(dev, &etest->flags, buf); |
| 230 | } |
| 231 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 232 | static void mlx4_en_get_strings(struct net_device *dev, |
| 233 | uint32_t stringset, uint8_t *data) |
| 234 | { |
| 235 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 236 | int index = 0; |
| 237 | int i; |
| 238 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 239 | switch (stringset) { |
| 240 | case ETH_SS_TEST: |
| 241 | for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++) |
| 242 | strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]); |
Or Gerlitz | ccf8632 | 2011-07-07 19:19:29 +0000 | [diff] [blame] | 243 | if (priv->mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 244 | for (; i < MLX4_EN_NUM_SELF_TEST; i++) |
| 245 | strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]); |
| 246 | break; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 247 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 248 | case ETH_SS_STATS: |
| 249 | /* Add main counters */ |
| 250 | for (i = 0; i < NUM_MAIN_STATS; i++) |
| 251 | strcpy(data + (index++) * ETH_GSTRING_LEN, main_strings[i]); |
| 252 | for (i = 0; i< NUM_PORT_STATS; i++) |
| 253 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 254 | main_strings[i + NUM_MAIN_STATS]); |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 255 | for (i = 0; i < priv->tx_ring_num; i++) { |
| 256 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 257 | "tx%d_packets", i); |
| 258 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 259 | "tx%d_bytes", i); |
| 260 | } |
| 261 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 262 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 263 | "rx%d_packets", i); |
| 264 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 265 | "rx%d_bytes", i); |
| 266 | } |
| 267 | for (i = 0; i< NUM_PKT_STATS; i++) |
| 268 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 269 | main_strings[i + NUM_MAIN_STATS + NUM_PORT_STATS]); |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 270 | break; |
| 271 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 275 | { |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 276 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 277 | int trans_type; |
| 278 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 279 | cmd->autoneg = AUTONEG_DISABLE; |
| 280 | cmd->supported = SUPPORTED_10000baseT_Full; |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 281 | cmd->advertising = ADVERTISED_10000baseT_Full; |
| 282 | |
| 283 | if (mlx4_en_QUERY_PORT(priv->mdev, priv->port)) |
| 284 | return -ENOMEM; |
| 285 | |
| 286 | trans_type = priv->port_state.transciver; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 287 | if (netif_carrier_ok(dev)) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 288 | ethtool_cmd_speed_set(cmd, priv->port_state.link_speed); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 289 | cmd->duplex = DUPLEX_FULL; |
| 290 | } else { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 291 | ethtool_cmd_speed_set(cmd, -1); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 292 | cmd->duplex = -1; |
| 293 | } |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 294 | |
| 295 | if (trans_type > 0 && trans_type <= 0xC) { |
| 296 | cmd->port = PORT_FIBRE; |
| 297 | cmd->transceiver = XCVR_EXTERNAL; |
| 298 | cmd->supported |= SUPPORTED_FIBRE; |
| 299 | cmd->advertising |= ADVERTISED_FIBRE; |
| 300 | } else if (trans_type == 0x80 || trans_type == 0) { |
| 301 | cmd->port = PORT_TP; |
| 302 | cmd->transceiver = XCVR_INTERNAL; |
| 303 | cmd->supported |= SUPPORTED_TP; |
| 304 | cmd->advertising |= ADVERTISED_TP; |
| 305 | } else { |
| 306 | cmd->port = -1; |
| 307 | cmd->transceiver = -1; |
| 308 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 313 | { |
| 314 | if ((cmd->autoneg == AUTONEG_ENABLE) || |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 315 | (ethtool_cmd_speed(cmd) != SPEED_10000) || |
| 316 | (cmd->duplex != DUPLEX_FULL)) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 317 | return -EINVAL; |
| 318 | |
| 319 | /* Nothing to change */ |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static int mlx4_en_get_coalesce(struct net_device *dev, |
| 324 | struct ethtool_coalesce *coal) |
| 325 | { |
| 326 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 327 | |
| 328 | coal->tx_coalesce_usecs = 0; |
| 329 | coal->tx_max_coalesced_frames = 0; |
| 330 | coal->rx_coalesce_usecs = priv->rx_usecs; |
| 331 | coal->rx_max_coalesced_frames = priv->rx_frames; |
| 332 | |
| 333 | coal->pkt_rate_low = priv->pkt_rate_low; |
| 334 | coal->rx_coalesce_usecs_low = priv->rx_usecs_low; |
| 335 | coal->pkt_rate_high = priv->pkt_rate_high; |
| 336 | coal->rx_coalesce_usecs_high = priv->rx_usecs_high; |
| 337 | coal->rate_sample_interval = priv->sample_interval; |
| 338 | coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal; |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | static int mlx4_en_set_coalesce(struct net_device *dev, |
| 343 | struct ethtool_coalesce *coal) |
| 344 | { |
| 345 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 346 | int err, i; |
| 347 | |
| 348 | priv->rx_frames = (coal->rx_max_coalesced_frames == |
| 349 | MLX4_EN_AUTO_CONF) ? |
Yevgeny Petrilin | 3db36fb | 2009-06-01 23:23:13 +0000 | [diff] [blame] | 350 | MLX4_EN_RX_COAL_TARGET : |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 351 | coal->rx_max_coalesced_frames; |
| 352 | priv->rx_usecs = (coal->rx_coalesce_usecs == |
| 353 | MLX4_EN_AUTO_CONF) ? |
| 354 | MLX4_EN_RX_COAL_TIME : |
| 355 | coal->rx_coalesce_usecs; |
| 356 | |
| 357 | /* Set adaptive coalescing params */ |
| 358 | priv->pkt_rate_low = coal->pkt_rate_low; |
| 359 | priv->rx_usecs_low = coal->rx_coalesce_usecs_low; |
| 360 | priv->pkt_rate_high = coal->pkt_rate_high; |
| 361 | priv->rx_usecs_high = coal->rx_coalesce_usecs_high; |
| 362 | priv->sample_interval = coal->rate_sample_interval; |
| 363 | priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 364 | if (priv->adaptive_rx_coal) |
| 365 | return 0; |
| 366 | |
| 367 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 368 | priv->rx_cq[i].moder_cnt = priv->rx_frames; |
| 369 | priv->rx_cq[i].moder_time = priv->rx_usecs; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 370 | priv->last_moder_time[i] = MLX4_EN_AUTO_CONF; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 371 | err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]); |
| 372 | if (err) |
| 373 | return err; |
| 374 | } |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int mlx4_en_set_pauseparam(struct net_device *dev, |
| 379 | struct ethtool_pauseparam *pause) |
| 380 | { |
| 381 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 382 | struct mlx4_en_dev *mdev = priv->mdev; |
| 383 | int err; |
| 384 | |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 385 | priv->prof->tx_pause = pause->tx_pause != 0; |
| 386 | priv->prof->rx_pause = pause->rx_pause != 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 387 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
| 388 | priv->rx_skb_size + ETH_FCS_LEN, |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 389 | priv->prof->tx_pause, |
| 390 | priv->prof->tx_ppp, |
| 391 | priv->prof->rx_pause, |
| 392 | priv->prof->rx_ppp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 393 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 394 | en_err(priv, "Failed setting pause params\n"); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 395 | |
| 396 | return err; |
| 397 | } |
| 398 | |
| 399 | static void mlx4_en_get_pauseparam(struct net_device *dev, |
| 400 | struct ethtool_pauseparam *pause) |
| 401 | { |
| 402 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 403 | |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 404 | pause->tx_pause = priv->prof->tx_pause; |
| 405 | pause->rx_pause = priv->prof->rx_pause; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 408 | static int mlx4_en_set_ringparam(struct net_device *dev, |
| 409 | struct ethtool_ringparam *param) |
| 410 | { |
| 411 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 412 | struct mlx4_en_dev *mdev = priv->mdev; |
| 413 | u32 rx_size, tx_size; |
| 414 | int port_up = 0; |
| 415 | int err = 0; |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 416 | int i; |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 417 | |
| 418 | if (param->rx_jumbo_pending || param->rx_mini_pending) |
| 419 | return -EINVAL; |
| 420 | |
| 421 | rx_size = roundup_pow_of_two(param->rx_pending); |
| 422 | rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 423 | rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 424 | tx_size = roundup_pow_of_two(param->tx_pending); |
| 425 | tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 426 | tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 427 | |
Yevgeny Petrilin | bc081ce | 2010-08-24 03:46:34 +0000 | [diff] [blame] | 428 | if (rx_size == (priv->port_up ? priv->rx_ring[0].actual_size : |
| 429 | priv->rx_ring[0].size) && |
| 430 | tx_size == priv->tx_ring[0].size) |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 431 | return 0; |
| 432 | |
| 433 | mutex_lock(&mdev->state_lock); |
| 434 | if (priv->port_up) { |
| 435 | port_up = 1; |
| 436 | mlx4_en_stop_port(dev); |
| 437 | } |
| 438 | |
Alexander Guller | fe0af03 | 2011-10-09 05:26:46 +0000 | [diff] [blame] | 439 | mlx4_en_free_resources(priv); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 440 | |
| 441 | priv->prof->tx_ring_size = tx_size; |
| 442 | priv->prof->rx_ring_size = rx_size; |
| 443 | |
| 444 | err = mlx4_en_alloc_resources(priv); |
| 445 | if (err) { |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 446 | en_err(priv, "Failed reallocating port resources\n"); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 447 | goto out; |
| 448 | } |
| 449 | if (port_up) { |
| 450 | err = mlx4_en_start_port(dev); |
| 451 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 452 | en_err(priv, "Failed starting port\n"); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Alexander Guller | 6b4d8d9 | 2011-10-09 05:38:23 +0000 | [diff] [blame] | 455 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 456 | priv->rx_cq[i].moder_cnt = priv->rx_frames; |
| 457 | priv->rx_cq[i].moder_time = priv->rx_usecs; |
| 458 | priv->last_moder_time[i] = MLX4_EN_AUTO_CONF; |
| 459 | err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]); |
| 460 | if (err) |
| 461 | goto out; |
| 462 | } |
| 463 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 464 | out: |
| 465 | mutex_unlock(&mdev->state_lock); |
| 466 | return err; |
| 467 | } |
| 468 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 469 | static void mlx4_en_get_ringparam(struct net_device *dev, |
| 470 | struct ethtool_ringparam *param) |
| 471 | { |
| 472 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 473 | |
| 474 | memset(param, 0, sizeof(*param)); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 475 | param->rx_max_pending = MLX4_EN_MAX_RX_SIZE; |
| 476 | param->tx_max_pending = MLX4_EN_MAX_TX_SIZE; |
Yevgeny Petrilin | bc081ce | 2010-08-24 03:46:34 +0000 | [diff] [blame] | 477 | param->rx_pending = priv->port_up ? |
| 478 | priv->rx_ring[0].actual_size : priv->rx_ring[0].size; |
| 479 | param->tx_pending = priv->tx_ring[0].size; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | const struct ethtool_ops mlx4_en_ethtool_ops = { |
| 483 | .get_drvinfo = mlx4_en_get_drvinfo, |
| 484 | .get_settings = mlx4_en_get_settings, |
| 485 | .set_settings = mlx4_en_set_settings, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 486 | .get_link = ethtool_op_get_link, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 487 | .get_strings = mlx4_en_get_strings, |
| 488 | .get_sset_count = mlx4_en_get_sset_count, |
| 489 | .get_ethtool_stats = mlx4_en_get_ethtool_stats, |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 490 | .self_test = mlx4_en_self_test, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 491 | .get_wol = mlx4_en_get_wol, |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 492 | .set_wol = mlx4_en_set_wol, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 493 | .get_msglevel = mlx4_en_get_msglevel, |
| 494 | .set_msglevel = mlx4_en_set_msglevel, |
| 495 | .get_coalesce = mlx4_en_get_coalesce, |
| 496 | .set_coalesce = mlx4_en_set_coalesce, |
| 497 | .get_pauseparam = mlx4_en_get_pauseparam, |
| 498 | .set_pauseparam = mlx4_en_set_pauseparam, |
| 499 | .get_ringparam = mlx4_en_get_ringparam, |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 500 | .set_ringparam = mlx4_en_set_ringparam, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |