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> |
Amir Vadai | af22d9d | 2012-07-18 22:33:49 +0000 | [diff] [blame] | 37 | #include <linux/mlx4/driver.h> |
Saeed Mahameed | 7202da8 | 2014-10-27 11:37:36 +0200 | [diff] [blame] | 38 | #include <linux/mlx4/device.h> |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 39 | #include <linux/in.h> |
| 40 | #include <net/ip.h> |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 41 | #include <linux/bitmap.h> |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 42 | |
| 43 | #include "mlx4_en.h" |
| 44 | #include "en_port.h" |
| 45 | |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 46 | #define EN_ETHTOOL_QP_ATTACH (1ull << 63) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 47 | #define EN_ETHTOOL_SHORT_MASK cpu_to_be16(0xffff) |
| 48 | #define EN_ETHTOOL_WORD_MASK cpu_to_be32(0xffffffff) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 49 | |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 50 | static int mlx4_en_moderation_update(struct mlx4_en_priv *priv) |
| 51 | { |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 52 | int i, t; |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 53 | int err = 0; |
| 54 | |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 55 | for (t = 0 ; t < MLX4_EN_NUM_TX_TYPES; t++) { |
| 56 | for (i = 0; i < priv->tx_ring_num[t]; i++) { |
| 57 | priv->tx_cq[t][i]->moder_cnt = priv->tx_frames; |
| 58 | priv->tx_cq[t][i]->moder_time = priv->tx_usecs; |
| 59 | if (priv->port_up) { |
| 60 | err = mlx4_en_set_cq_moder(priv, |
| 61 | priv->tx_cq[t][i]); |
| 62 | if (err) |
| 63 | return err; |
| 64 | } |
Eugenia Emantayev | 38463e2 | 2013-09-12 18:11:20 +0300 | [diff] [blame] | 65 | } |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | if (priv->adaptive_rx_coal) |
| 69 | return 0; |
| 70 | |
| 71 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 72 | priv->rx_cq[i]->moder_cnt = priv->rx_frames; |
| 73 | priv->rx_cq[i]->moder_time = priv->rx_usecs; |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 74 | priv->last_moder_time[i] = MLX4_EN_AUTO_CONF; |
Eugenia Emantayev | 38463e2 | 2013-09-12 18:11:20 +0300 | [diff] [blame] | 75 | if (priv->port_up) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 76 | err = mlx4_en_set_cq_moder(priv, priv->rx_cq[i]); |
Eugenia Emantayev | 38463e2 | 2013-09-12 18:11:20 +0300 | [diff] [blame] | 77 | if (err) |
| 78 | return err; |
| 79 | } |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | return err; |
| 83 | } |
| 84 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 85 | static void |
| 86 | mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) |
| 87 | { |
| 88 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 89 | struct mlx4_en_dev *mdev = priv->mdev; |
| 90 | |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 91 | strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
| 92 | strlcpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", |
| 93 | sizeof(drvinfo->version)); |
| 94 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), |
| 95 | "%d.%d.%d", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 96 | (u16) (mdev->dev->caps.fw_ver >> 32), |
| 97 | (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff), |
| 98 | (u16) (mdev->dev->caps.fw_ver & 0xffff)); |
Yishai Hadas | 872bf2f | 2015-01-25 16:59:35 +0200 | [diff] [blame] | 99 | strlcpy(drvinfo->bus_info, pci_name(mdev->dev->persist->pdev), |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 100 | sizeof(drvinfo->bus_info)); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 103 | static const char mlx4_en_priv_flags[][ETH_GSTRING_LEN] = { |
| 104 | "blueflame", |
Hadar Hen Zion | e38af4f | 2015-07-27 14:46:34 +0300 | [diff] [blame] | 105 | "phv-bit" |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 106 | }; |
| 107 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 108 | static const char main_strings[][ETH_GSTRING_LEN] = { |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 109 | /* main statistics */ |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 110 | "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors", |
| 111 | "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions", |
| 112 | "rx_length_errors", "rx_over_errors", "rx_crc_errors", |
| 113 | "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors", |
| 114 | "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors", |
| 115 | "tx_heartbeat_errors", "tx_window_errors", |
| 116 | |
| 117 | /* port statistics */ |
Yevgeny Petrilin | fa37a95 | 2010-08-24 03:46:46 +0000 | [diff] [blame] | 118 | "tso_packets", |
Eric Dumazet | 9fab426 | 2014-10-02 08:24:21 -0700 | [diff] [blame] | 119 | "xmit_more", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 120 | "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed", |
Shani Michaeli | f8c6455 | 2014-11-09 13:51:53 +0200 | [diff] [blame] | 121 | "rx_csum_good", "rx_csum_none", "rx_csum_complete", "tx_chksum_offload", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 122 | |
Eran Ben Elisha | b42de4d | 2015-06-15 17:59:06 +0300 | [diff] [blame] | 123 | /* pf statistics */ |
| 124 | "pf_rx_packets", |
| 125 | "pf_rx_bytes", |
| 126 | "pf_tx_packets", |
| 127 | "pf_tx_bytes", |
| 128 | |
Matan Barak | 0b13156 | 2015-03-30 17:45:25 +0300 | [diff] [blame] | 129 | /* priority flow control statistics rx */ |
| 130 | "rx_pause_prio_0", "rx_pause_duration_prio_0", |
| 131 | "rx_pause_transition_prio_0", |
| 132 | "rx_pause_prio_1", "rx_pause_duration_prio_1", |
| 133 | "rx_pause_transition_prio_1", |
| 134 | "rx_pause_prio_2", "rx_pause_duration_prio_2", |
| 135 | "rx_pause_transition_prio_2", |
| 136 | "rx_pause_prio_3", "rx_pause_duration_prio_3", |
| 137 | "rx_pause_transition_prio_3", |
| 138 | "rx_pause_prio_4", "rx_pause_duration_prio_4", |
| 139 | "rx_pause_transition_prio_4", |
| 140 | "rx_pause_prio_5", "rx_pause_duration_prio_5", |
| 141 | "rx_pause_transition_prio_5", |
| 142 | "rx_pause_prio_6", "rx_pause_duration_prio_6", |
| 143 | "rx_pause_transition_prio_6", |
| 144 | "rx_pause_prio_7", "rx_pause_duration_prio_7", |
| 145 | "rx_pause_transition_prio_7", |
| 146 | |
| 147 | /* flow control statistics rx */ |
| 148 | "rx_pause", "rx_pause_duration", "rx_pause_transition", |
| 149 | |
| 150 | /* priority flow control statistics tx */ |
| 151 | "tx_pause_prio_0", "tx_pause_duration_prio_0", |
| 152 | "tx_pause_transition_prio_0", |
| 153 | "tx_pause_prio_1", "tx_pause_duration_prio_1", |
| 154 | "tx_pause_transition_prio_1", |
| 155 | "tx_pause_prio_2", "tx_pause_duration_prio_2", |
| 156 | "tx_pause_transition_prio_2", |
| 157 | "tx_pause_prio_3", "tx_pause_duration_prio_3", |
| 158 | "tx_pause_transition_prio_3", |
| 159 | "tx_pause_prio_4", "tx_pause_duration_prio_4", |
| 160 | "tx_pause_transition_prio_4", |
| 161 | "tx_pause_prio_5", "tx_pause_duration_prio_5", |
| 162 | "tx_pause_transition_prio_5", |
| 163 | "tx_pause_prio_6", "tx_pause_duration_prio_6", |
| 164 | "tx_pause_transition_prio_6", |
| 165 | "tx_pause_prio_7", "tx_pause_duration_prio_7", |
| 166 | "tx_pause_transition_prio_7", |
| 167 | |
| 168 | /* flow control statistics tx */ |
| 169 | "tx_pause", "tx_pause_duration", "tx_pause_transition", |
| 170 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 171 | /* packet statistics */ |
Eran Ben Elisha | a3333b3 | 2015-03-30 17:45:26 +0300 | [diff] [blame] | 172 | "rx_multicast_packets", |
| 173 | "rx_broadcast_packets", |
| 174 | "rx_jabbers", |
| 175 | "rx_in_range_length_error", |
| 176 | "rx_out_range_length_error", |
| 177 | "tx_multicast_packets", |
| 178 | "tx_broadcast_packets", |
| 179 | "rx_prio_0_packets", "rx_prio_0_bytes", |
| 180 | "rx_prio_1_packets", "rx_prio_1_bytes", |
| 181 | "rx_prio_2_packets", "rx_prio_2_bytes", |
| 182 | "rx_prio_3_packets", "rx_prio_3_bytes", |
| 183 | "rx_prio_4_packets", "rx_prio_4_bytes", |
| 184 | "rx_prio_5_packets", "rx_prio_5_bytes", |
| 185 | "rx_prio_6_packets", "rx_prio_6_bytes", |
| 186 | "rx_prio_7_packets", "rx_prio_7_bytes", |
| 187 | "rx_novlan_packets", "rx_novlan_bytes", |
| 188 | "tx_prio_0_packets", "tx_prio_0_bytes", |
| 189 | "tx_prio_1_packets", "tx_prio_1_bytes", |
| 190 | "tx_prio_2_packets", "tx_prio_2_bytes", |
| 191 | "tx_prio_3_packets", "tx_prio_3_bytes", |
| 192 | "tx_prio_4_packets", "tx_prio_4_bytes", |
| 193 | "tx_prio_5_packets", "tx_prio_5_bytes", |
| 194 | "tx_prio_6_packets", "tx_prio_6_bytes", |
| 195 | "tx_prio_7_packets", "tx_prio_7_bytes", |
| 196 | "tx_novlan_packets", "tx_novlan_bytes", |
| 197 | |
Tariq Toukan | 15fca2c | 2016-11-02 17:12:25 +0200 | [diff] [blame] | 198 | /* xdp statistics */ |
| 199 | "rx_xdp_drop", |
| 200 | "rx_xdp_tx", |
| 201 | "rx_xdp_tx_full", |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 202 | }; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 203 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 204 | static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= { |
Masanari Iida | fd9071e | 2012-04-13 04:33:20 +0000 | [diff] [blame] | 205 | "Interrupt Test", |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 206 | "Link Test", |
| 207 | "Speed Test", |
| 208 | "Register Test", |
| 209 | "Loopback Test", |
| 210 | }; |
| 211 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 212 | static u32 mlx4_en_get_msglevel(struct net_device *dev) |
| 213 | { |
| 214 | return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable; |
| 215 | } |
| 216 | |
| 217 | static void mlx4_en_set_msglevel(struct net_device *dev, u32 val) |
| 218 | { |
| 219 | ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val; |
| 220 | } |
| 221 | |
| 222 | static void mlx4_en_get_wol(struct net_device *netdev, |
| 223 | struct ethtool_wolinfo *wol) |
| 224 | { |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 225 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
| 226 | int err = 0; |
| 227 | u64 config = 0; |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 228 | u64 mask; |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 229 | |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 230 | if ((priv->port < 1) || (priv->port > 2)) { |
| 231 | en_err(priv, "Failed to get WoL information\n"); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 : |
| 236 | MLX4_DEV_CAP_FLAG_WOL_PORT2; |
| 237 | |
| 238 | if (!(priv->mdev->dev->caps.flags & mask)) { |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 239 | wol->supported = 0; |
| 240 | wol->wolopts = 0; |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | err = mlx4_wol_read(priv->mdev->dev, &config, priv->port); |
| 245 | if (err) { |
| 246 | en_err(priv, "Failed to get WoL information\n"); |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | if (config & MLX4_EN_WOL_MAGIC) |
| 251 | wol->supported = WAKE_MAGIC; |
| 252 | else |
| 253 | wol->supported = 0; |
| 254 | |
| 255 | if (config & MLX4_EN_WOL_ENABLED) |
| 256 | wol->wolopts = WAKE_MAGIC; |
| 257 | else |
| 258 | wol->wolopts = 0; |
| 259 | } |
| 260 | |
| 261 | static int mlx4_en_set_wol(struct net_device *netdev, |
| 262 | struct ethtool_wolinfo *wol) |
| 263 | { |
| 264 | struct mlx4_en_priv *priv = netdev_priv(netdev); |
| 265 | u64 config = 0; |
| 266 | int err = 0; |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 267 | u64 mask; |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 268 | |
Oren Duer | 559a9f1 | 2011-11-26 19:55:15 +0000 | [diff] [blame] | 269 | if ((priv->port < 1) || (priv->port > 2)) |
| 270 | return -EOPNOTSUPP; |
| 271 | |
| 272 | mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 : |
| 273 | MLX4_DEV_CAP_FLAG_WOL_PORT2; |
| 274 | |
| 275 | if (!(priv->mdev->dev->caps.flags & mask)) |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 276 | return -EOPNOTSUPP; |
| 277 | |
| 278 | if (wol->supported & ~WAKE_MAGIC) |
| 279 | return -EINVAL; |
| 280 | |
| 281 | err = mlx4_wol_read(priv->mdev->dev, &config, priv->port); |
| 282 | if (err) { |
| 283 | en_err(priv, "Failed to get WoL info, unable to modify\n"); |
| 284 | return err; |
| 285 | } |
| 286 | |
| 287 | if (wol->wolopts & WAKE_MAGIC) { |
| 288 | config |= MLX4_EN_WOL_DO_MODIFY | MLX4_EN_WOL_ENABLED | |
| 289 | MLX4_EN_WOL_MAGIC; |
| 290 | } else { |
| 291 | config &= ~(MLX4_EN_WOL_ENABLED | MLX4_EN_WOL_MAGIC); |
| 292 | config |= MLX4_EN_WOL_DO_MODIFY; |
| 293 | } |
| 294 | |
| 295 | err = mlx4_wol_write(priv->mdev->dev, config, priv->port); |
| 296 | if (err) |
| 297 | en_err(priv, "Failed to set WoL information\n"); |
| 298 | |
| 299 | return err; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 302 | struct bitmap_iterator { |
| 303 | unsigned long *stats_bitmap; |
| 304 | unsigned int count; |
| 305 | unsigned int iterator; |
| 306 | bool advance_array; /* if set, force no increments */ |
| 307 | }; |
| 308 | |
| 309 | static inline void bitmap_iterator_init(struct bitmap_iterator *h, |
| 310 | unsigned long *stats_bitmap, |
| 311 | int count) |
| 312 | { |
| 313 | h->iterator = 0; |
| 314 | h->advance_array = !bitmap_empty(stats_bitmap, count); |
| 315 | h->count = h->advance_array ? bitmap_weight(stats_bitmap, count) |
| 316 | : count; |
| 317 | h->stats_bitmap = stats_bitmap; |
| 318 | } |
| 319 | |
| 320 | static inline int bitmap_iterator_test(struct bitmap_iterator *h) |
| 321 | { |
| 322 | return !h->advance_array ? 1 : test_bit(h->iterator, h->stats_bitmap); |
| 323 | } |
| 324 | |
| 325 | static inline int bitmap_iterator_inc(struct bitmap_iterator *h) |
| 326 | { |
| 327 | return h->iterator++; |
| 328 | } |
| 329 | |
| 330 | static inline unsigned int |
| 331 | bitmap_iterator_count(struct bitmap_iterator *h) |
| 332 | { |
| 333 | return h->count; |
| 334 | } |
| 335 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 336 | static int mlx4_en_get_sset_count(struct net_device *dev, int sset) |
| 337 | { |
| 338 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 339 | struct bitmap_iterator it; |
| 340 | |
Eran Ben Elisha | 3da8a36 | 2015-03-30 17:45:24 +0300 | [diff] [blame] | 341 | bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 342 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 343 | switch (sset) { |
| 344 | case ETH_SS_STATS: |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 345 | return bitmap_iterator_count(&it) + |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 346 | (priv->tx_ring_num[TX] * 2) + |
Tariq Toukan | 15fca2c | 2016-11-02 17:12:25 +0200 | [diff] [blame] | 347 | (priv->rx_ring_num * (3 + NUM_XDP_STATS)); |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 348 | case ETH_SS_TEST: |
Or Gerlitz | ccf8632 | 2011-07-07 19:19:29 +0000 | [diff] [blame] | 349 | return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags |
| 350 | & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2; |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 351 | case ETH_SS_PRIV_FLAGS: |
| 352 | return ARRAY_SIZE(mlx4_en_priv_flags); |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 353 | default: |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 354 | return -EOPNOTSUPP; |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 355 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static void mlx4_en_get_ethtool_stats(struct net_device *dev, |
| 359 | struct ethtool_stats *stats, uint64_t *data) |
| 360 | { |
| 361 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 362 | int index = 0; |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 363 | int i; |
| 364 | struct bitmap_iterator it; |
| 365 | |
Eran Ben Elisha | 3da8a36 | 2015-03-30 17:45:24 +0300 | [diff] [blame] | 366 | bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 367 | |
| 368 | spin_lock_bh(&priv->stats_lock); |
| 369 | |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 370 | for (i = 0; i < NUM_MAIN_STATS; i++, bitmap_iterator_inc(&it)) |
| 371 | if (bitmap_iterator_test(&it)) |
Eric Dumazet | f73a6f4 | 2016-05-25 09:50:39 -0700 | [diff] [blame] | 372 | data[index++] = ((unsigned long *)&dev->stats)[i]; |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 373 | |
| 374 | for (i = 0; i < NUM_PORT_STATS; i++, bitmap_iterator_inc(&it)) |
| 375 | if (bitmap_iterator_test(&it)) |
| 376 | data[index++] = ((unsigned long *)&priv->port_stats)[i]; |
| 377 | |
Eran Ben Elisha | b42de4d | 2015-06-15 17:59:06 +0300 | [diff] [blame] | 378 | for (i = 0; i < NUM_PF_STATS; i++, bitmap_iterator_inc(&it)) |
| 379 | if (bitmap_iterator_test(&it)) |
| 380 | data[index++] = |
| 381 | ((unsigned long *)&priv->pf_stats)[i]; |
| 382 | |
Matan Barak | 0b13156 | 2015-03-30 17:45:25 +0300 | [diff] [blame] | 383 | for (i = 0; i < NUM_FLOW_PRIORITY_STATS_RX; |
| 384 | i++, bitmap_iterator_inc(&it)) |
| 385 | if (bitmap_iterator_test(&it)) |
| 386 | data[index++] = |
| 387 | ((u64 *)&priv->rx_priority_flowstats)[i]; |
| 388 | |
| 389 | for (i = 0; i < NUM_FLOW_STATS_RX; i++, bitmap_iterator_inc(&it)) |
| 390 | if (bitmap_iterator_test(&it)) |
| 391 | data[index++] = ((u64 *)&priv->rx_flowstats)[i]; |
| 392 | |
| 393 | for (i = 0; i < NUM_FLOW_PRIORITY_STATS_TX; |
| 394 | i++, bitmap_iterator_inc(&it)) |
| 395 | if (bitmap_iterator_test(&it)) |
| 396 | data[index++] = |
| 397 | ((u64 *)&priv->tx_priority_flowstats)[i]; |
| 398 | |
| 399 | for (i = 0; i < NUM_FLOW_STATS_TX; i++, bitmap_iterator_inc(&it)) |
| 400 | if (bitmap_iterator_test(&it)) |
| 401 | data[index++] = ((u64 *)&priv->tx_flowstats)[i]; |
| 402 | |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 403 | for (i = 0; i < NUM_PKT_STATS; i++, bitmap_iterator_inc(&it)) |
| 404 | if (bitmap_iterator_test(&it)) |
| 405 | data[index++] = ((unsigned long *)&priv->pkstats)[i]; |
| 406 | |
Tariq Toukan | 15fca2c | 2016-11-02 17:12:25 +0200 | [diff] [blame] | 407 | for (i = 0; i < NUM_XDP_STATS; i++, bitmap_iterator_inc(&it)) |
| 408 | if (bitmap_iterator_test(&it)) |
| 409 | data[index++] = ((unsigned long *)&priv->xdp_stats)[i]; |
| 410 | |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 411 | for (i = 0; i < priv->tx_ring_num[TX]; i++) { |
| 412 | data[index++] = priv->tx_ring[TX][i]->packets; |
| 413 | data[index++] = priv->tx_ring[TX][i]->bytes; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 414 | } |
| 415 | for (i = 0; i < priv->rx_ring_num; i++) { |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 416 | data[index++] = priv->rx_ring[i]->packets; |
| 417 | data[index++] = priv->rx_ring[i]->bytes; |
Eran Ben Elisha | d21ed3a | 2016-04-20 16:01:18 +0300 | [diff] [blame] | 418 | data[index++] = priv->rx_ring[i]->dropped; |
Tariq Toukan | 15fca2c | 2016-11-02 17:12:25 +0200 | [diff] [blame] | 419 | data[index++] = priv->rx_ring[i]->xdp_drop; |
| 420 | data[index++] = priv->rx_ring[i]->xdp_tx; |
| 421 | data[index++] = priv->rx_ring[i]->xdp_tx_full; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 422 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 423 | spin_unlock_bh(&priv->stats_lock); |
| 424 | |
| 425 | } |
| 426 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 427 | static void mlx4_en_self_test(struct net_device *dev, |
| 428 | struct ethtool_test *etest, u64 *buf) |
| 429 | { |
| 430 | mlx4_en_ex_selftest(dev, &etest->flags, buf); |
| 431 | } |
| 432 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 433 | static void mlx4_en_get_strings(struct net_device *dev, |
| 434 | uint32_t stringset, uint8_t *data) |
| 435 | { |
| 436 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 437 | int index = 0; |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 438 | int i, strings = 0; |
| 439 | struct bitmap_iterator it; |
| 440 | |
Eran Ben Elisha | 3da8a36 | 2015-03-30 17:45:24 +0300 | [diff] [blame] | 441 | bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 442 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 443 | switch (stringset) { |
| 444 | case ETH_SS_TEST: |
| 445 | for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++) |
| 446 | strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]); |
Or Gerlitz | ccf8632 | 2011-07-07 19:19:29 +0000 | [diff] [blame] | 447 | if (priv->mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 448 | for (; i < MLX4_EN_NUM_SELF_TEST; i++) |
| 449 | strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]); |
| 450 | break; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 451 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 452 | case ETH_SS_STATS: |
| 453 | /* Add main counters */ |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 454 | for (i = 0; i < NUM_MAIN_STATS; i++, strings++, |
| 455 | bitmap_iterator_inc(&it)) |
| 456 | if (bitmap_iterator_test(&it)) |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 457 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 458 | main_strings[strings]); |
| 459 | |
| 460 | for (i = 0; i < NUM_PORT_STATS; i++, strings++, |
| 461 | bitmap_iterator_inc(&it)) |
| 462 | if (bitmap_iterator_test(&it)) |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 463 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 464 | main_strings[strings]); |
| 465 | |
Eran Ben Elisha | b42de4d | 2015-06-15 17:59:06 +0300 | [diff] [blame] | 466 | for (i = 0; i < NUM_PF_STATS; i++, strings++, |
| 467 | bitmap_iterator_inc(&it)) |
| 468 | if (bitmap_iterator_test(&it)) |
| 469 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
| 470 | main_strings[strings]); |
| 471 | |
Matan Barak | 0b13156 | 2015-03-30 17:45:25 +0300 | [diff] [blame] | 472 | for (i = 0; i < NUM_FLOW_STATS; i++, strings++, |
| 473 | bitmap_iterator_inc(&it)) |
| 474 | if (bitmap_iterator_test(&it)) |
| 475 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
| 476 | main_strings[strings]); |
| 477 | |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 478 | for (i = 0; i < NUM_PKT_STATS; i++, strings++, |
| 479 | bitmap_iterator_inc(&it)) |
| 480 | if (bitmap_iterator_test(&it)) |
Eugenia Emantayev | 93ece0c | 2012-01-19 09:45:05 +0000 | [diff] [blame] | 481 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
Eran Ben Elisha | 6fcd273 | 2015-03-30 17:45:23 +0300 | [diff] [blame] | 482 | main_strings[strings]); |
| 483 | |
Tariq Toukan | 15fca2c | 2016-11-02 17:12:25 +0200 | [diff] [blame] | 484 | for (i = 0; i < NUM_XDP_STATS; i++, strings++, |
| 485 | bitmap_iterator_inc(&it)) |
| 486 | if (bitmap_iterator_test(&it)) |
| 487 | strcpy(data + (index++) * ETH_GSTRING_LEN, |
| 488 | main_strings[strings]); |
| 489 | |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 490 | for (i = 0; i < priv->tx_ring_num[TX]; i++) { |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 491 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 492 | "tx%d_packets", i); |
| 493 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 494 | "tx%d_bytes", i); |
| 495 | } |
| 496 | for (i = 0; i < priv->rx_ring_num; i++) { |
| 497 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 498 | "rx%d_packets", i); |
| 499 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 500 | "rx%d_bytes", i); |
Eran Ben Elisha | d21ed3a | 2016-04-20 16:01:18 +0300 | [diff] [blame] | 501 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 502 | "rx%d_dropped", i); |
Tariq Toukan | 15fca2c | 2016-11-02 17:12:25 +0200 | [diff] [blame] | 503 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 504 | "rx%d_xdp_drop", i); |
| 505 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 506 | "rx%d_xdp_tx", i); |
| 507 | sprintf(data + (index++) * ETH_GSTRING_LEN, |
| 508 | "rx%d_xdp_tx_full", i); |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 509 | } |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 510 | break; |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 511 | case ETH_SS_PRIV_FLAGS: |
| 512 | for (i = 0; i < ARRAY_SIZE(mlx4_en_priv_flags); i++) |
| 513 | strcpy(data + i * ETH_GSTRING_LEN, |
| 514 | mlx4_en_priv_flags[i]); |
| 515 | break; |
| 516 | |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 517 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 520 | static u32 mlx4_en_autoneg_get(struct net_device *dev) |
| 521 | { |
| 522 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 523 | struct mlx4_en_dev *mdev = priv->mdev; |
| 524 | u32 autoneg = AUTONEG_DISABLE; |
| 525 | |
| 526 | if ((mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_BACKPL_AN_REP) && |
| 527 | (priv->port_state.flags & MLX4_EN_PORT_ANE)) |
| 528 | autoneg = AUTONEG_ENABLE; |
| 529 | |
| 530 | return autoneg; |
| 531 | } |
| 532 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 533 | static void ptys2ethtool_update_supported_port(unsigned long *mask, |
| 534 | struct mlx4_ptys_reg *ptys_reg) |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 535 | { |
| 536 | u32 eth_proto = be32_to_cpu(ptys_reg->eth_proto_cap); |
| 537 | |
| 538 | if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_T) |
| 539 | | MLX4_PROT_MASK(MLX4_1000BASE_T) |
| 540 | | MLX4_PROT_MASK(MLX4_100BASE_TX))) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 541 | __set_bit(ETHTOOL_LINK_MODE_TP_BIT, mask); |
| 542 | } else if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_CR) |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 543 | | MLX4_PROT_MASK(MLX4_10GBASE_SR) |
| 544 | | MLX4_PROT_MASK(MLX4_56GBASE_SR4) |
| 545 | | MLX4_PROT_MASK(MLX4_40GBASE_CR4) |
| 546 | | MLX4_PROT_MASK(MLX4_40GBASE_SR4) |
| 547 | | MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII))) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 548 | __set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, mask); |
| 549 | } else if (eth_proto & (MLX4_PROT_MASK(MLX4_56GBASE_KR4) |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 550 | | MLX4_PROT_MASK(MLX4_40GBASE_KR4) |
| 551 | | MLX4_PROT_MASK(MLX4_20GBASE_KR2) |
| 552 | | MLX4_PROT_MASK(MLX4_10GBASE_KR) |
| 553 | | MLX4_PROT_MASK(MLX4_10GBASE_KX4) |
| 554 | | MLX4_PROT_MASK(MLX4_1000BASE_KX))) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 555 | __set_bit(ETHTOOL_LINK_MODE_Backplane_BIT, mask); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 556 | } |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static u32 ptys_get_active_port(struct mlx4_ptys_reg *ptys_reg) |
| 560 | { |
| 561 | u32 eth_proto = be32_to_cpu(ptys_reg->eth_proto_oper); |
| 562 | |
| 563 | if (!eth_proto) /* link down */ |
| 564 | eth_proto = be32_to_cpu(ptys_reg->eth_proto_cap); |
| 565 | |
| 566 | if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_T) |
| 567 | | MLX4_PROT_MASK(MLX4_1000BASE_T) |
| 568 | | MLX4_PROT_MASK(MLX4_100BASE_TX))) { |
| 569 | return PORT_TP; |
| 570 | } |
| 571 | |
| 572 | if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_SR) |
| 573 | | MLX4_PROT_MASK(MLX4_56GBASE_SR4) |
| 574 | | MLX4_PROT_MASK(MLX4_40GBASE_SR4) |
| 575 | | MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII))) { |
| 576 | return PORT_FIBRE; |
| 577 | } |
| 578 | |
| 579 | if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_CR) |
| 580 | | MLX4_PROT_MASK(MLX4_56GBASE_CR4) |
| 581 | | MLX4_PROT_MASK(MLX4_40GBASE_CR4))) { |
| 582 | return PORT_DA; |
| 583 | } |
| 584 | |
| 585 | if (eth_proto & (MLX4_PROT_MASK(MLX4_56GBASE_KR4) |
| 586 | | MLX4_PROT_MASK(MLX4_40GBASE_KR4) |
| 587 | | MLX4_PROT_MASK(MLX4_20GBASE_KR2) |
| 588 | | MLX4_PROT_MASK(MLX4_10GBASE_KR) |
| 589 | | MLX4_PROT_MASK(MLX4_10GBASE_KX4) |
| 590 | | MLX4_PROT_MASK(MLX4_1000BASE_KX))) { |
| 591 | return PORT_NONE; |
| 592 | } |
| 593 | return PORT_OTHER; |
| 594 | } |
| 595 | |
| 596 | #define MLX4_LINK_MODES_SZ \ |
| 597 | (FIELD_SIZEOF(struct mlx4_ptys_reg, eth_proto_cap) * 8) |
| 598 | |
| 599 | enum ethtool_report { |
| 600 | SUPPORTED = 0, |
| 601 | ADVERTISED = 1, |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 602 | }; |
| 603 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 604 | struct ptys2ethtool_config { |
| 605 | __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); |
| 606 | __ETHTOOL_DECLARE_LINK_MODE_MASK(advertised); |
| 607 | u32 speed; |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 608 | }; |
| 609 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 610 | static unsigned long *ptys2ethtool_link_mode(struct ptys2ethtool_config *cfg, |
| 611 | enum ethtool_report report) |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 612 | { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 613 | switch (report) { |
| 614 | case SUPPORTED: |
| 615 | return cfg->supported; |
| 616 | case ADVERTISED: |
| 617 | return cfg->advertised; |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 618 | } |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 619 | return NULL; |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 620 | } |
| 621 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 622 | #define MLX4_BUILD_PTYS2ETHTOOL_CONFIG(reg_, speed_, ...) \ |
| 623 | ({ \ |
| 624 | struct ptys2ethtool_config *cfg; \ |
| 625 | const unsigned int modes[] = { __VA_ARGS__ }; \ |
| 626 | unsigned int i; \ |
| 627 | cfg = &ptys2ethtool_map[reg_]; \ |
| 628 | cfg->speed = speed_; \ |
| 629 | bitmap_zero(cfg->supported, \ |
| 630 | __ETHTOOL_LINK_MODE_MASK_NBITS); \ |
| 631 | bitmap_zero(cfg->advertised, \ |
| 632 | __ETHTOOL_LINK_MODE_MASK_NBITS); \ |
| 633 | for (i = 0 ; i < ARRAY_SIZE(modes) ; ++i) { \ |
| 634 | __set_bit(modes[i], cfg->supported); \ |
| 635 | __set_bit(modes[i], cfg->advertised); \ |
| 636 | } \ |
| 637 | }) |
| 638 | |
| 639 | /* Translates mlx4 link mode to equivalent ethtool Link modes/speed */ |
| 640 | static struct ptys2ethtool_config ptys2ethtool_map[MLX4_LINK_MODES_SZ]; |
| 641 | |
| 642 | void __init mlx4_en_init_ptys2ethtool_map(void) |
| 643 | { |
| 644 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_100BASE_TX, SPEED_100, |
| 645 | ETHTOOL_LINK_MODE_100baseT_Full_BIT); |
| 646 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_T, SPEED_1000, |
| 647 | ETHTOOL_LINK_MODE_1000baseT_Full_BIT); |
| 648 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_CX_SGMII, SPEED_1000, |
| 649 | ETHTOOL_LINK_MODE_1000baseKX_Full_BIT); |
| 650 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_KX, SPEED_1000, |
| 651 | ETHTOOL_LINK_MODE_1000baseKX_Full_BIT); |
| 652 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_T, SPEED_10000, |
| 653 | ETHTOOL_LINK_MODE_10000baseT_Full_BIT); |
| 654 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CX4, SPEED_10000, |
| 655 | ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT); |
| 656 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KX4, SPEED_10000, |
| 657 | ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT); |
| 658 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KR, SPEED_10000, |
| 659 | ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); |
| 660 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CR, SPEED_10000, |
| 661 | ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); |
| 662 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_SR, SPEED_10000, |
| 663 | ETHTOOL_LINK_MODE_10000baseKR_Full_BIT); |
| 664 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_20GBASE_KR2, SPEED_20000, |
| 665 | ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT, |
| 666 | ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT); |
| 667 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_CR4, SPEED_40000, |
| 668 | ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT); |
| 669 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_KR4, SPEED_40000, |
| 670 | ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT); |
| 671 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_SR4, SPEED_40000, |
| 672 | ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT); |
| 673 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_KR4, SPEED_56000, |
| 674 | ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT); |
| 675 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_CR4, SPEED_56000, |
| 676 | ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT); |
| 677 | MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_SR4, SPEED_56000, |
| 678 | ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT); |
| 679 | }; |
| 680 | |
| 681 | static void ptys2ethtool_update_link_modes(unsigned long *link_modes, |
| 682 | u32 eth_proto, |
| 683 | enum ethtool_report report) |
| 684 | { |
| 685 | int i; |
| 686 | for (i = 0; i < MLX4_LINK_MODES_SZ; i++) { |
| 687 | if (eth_proto & MLX4_PROT_MASK(i)) |
| 688 | bitmap_or(link_modes, link_modes, |
| 689 | ptys2ethtool_link_mode(&ptys2ethtool_map[i], |
| 690 | report), |
| 691 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | static u32 ethtool2ptys_link_modes(const unsigned long *link_modes, |
| 696 | enum ethtool_report report) |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 697 | { |
| 698 | int i; |
| 699 | u32 ptys_modes = 0; |
| 700 | |
| 701 | for (i = 0; i < MLX4_LINK_MODES_SZ; i++) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 702 | if (bitmap_intersects( |
| 703 | ptys2ethtool_link_mode(&ptys2ethtool_map[i], |
| 704 | report), |
| 705 | link_modes, |
| 706 | __ETHTOOL_LINK_MODE_MASK_NBITS)) |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 707 | ptys_modes |= 1 << i; |
| 708 | } |
| 709 | return ptys_modes; |
| 710 | } |
| 711 | |
| 712 | /* Convert actual speed (SPEED_XXX) to ptys link modes */ |
| 713 | static u32 speed2ptys_link_modes(u32 speed) |
| 714 | { |
| 715 | int i; |
| 716 | u32 ptys_modes = 0; |
| 717 | |
| 718 | for (i = 0; i < MLX4_LINK_MODES_SZ; i++) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 719 | if (ptys2ethtool_map[i].speed == speed) |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 720 | ptys_modes |= 1 << i; |
| 721 | } |
| 722 | return ptys_modes; |
| 723 | } |
| 724 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 725 | static int |
| 726 | ethtool_get_ptys_link_ksettings(struct net_device *dev, |
| 727 | struct ethtool_link_ksettings *link_ksettings) |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 728 | { |
| 729 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 730 | struct mlx4_ptys_reg ptys_reg; |
| 731 | u32 eth_proto; |
| 732 | int ret; |
| 733 | |
| 734 | memset(&ptys_reg, 0, sizeof(ptys_reg)); |
| 735 | ptys_reg.local_port = priv->port; |
| 736 | ptys_reg.proto_mask = MLX4_PTYS_EN; |
| 737 | ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev, |
| 738 | MLX4_ACCESS_REG_QUERY, &ptys_reg); |
| 739 | if (ret) { |
| 740 | en_warn(priv, "Failed to run mlx4_ACCESS_PTYS_REG status(%x)", |
| 741 | ret); |
| 742 | return ret; |
| 743 | } |
| 744 | en_dbg(DRV, priv, "ptys_reg.proto_mask %x\n", |
| 745 | ptys_reg.proto_mask); |
| 746 | en_dbg(DRV, priv, "ptys_reg.eth_proto_cap %x\n", |
| 747 | be32_to_cpu(ptys_reg.eth_proto_cap)); |
| 748 | en_dbg(DRV, priv, "ptys_reg.eth_proto_admin %x\n", |
| 749 | be32_to_cpu(ptys_reg.eth_proto_admin)); |
| 750 | en_dbg(DRV, priv, "ptys_reg.eth_proto_oper %x\n", |
| 751 | be32_to_cpu(ptys_reg.eth_proto_oper)); |
| 752 | en_dbg(DRV, priv, "ptys_reg.eth_proto_lp_adv %x\n", |
| 753 | be32_to_cpu(ptys_reg.eth_proto_lp_adv)); |
| 754 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 755 | /* reset supported/advertising masks */ |
| 756 | ethtool_link_ksettings_zero_link_mode(link_ksettings, supported); |
| 757 | ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 758 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 759 | ptys2ethtool_update_supported_port(link_ksettings->link_modes.supported, |
| 760 | &ptys_reg); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 761 | |
| 762 | eth_proto = be32_to_cpu(ptys_reg.eth_proto_cap); |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 763 | ptys2ethtool_update_link_modes(link_ksettings->link_modes.supported, |
| 764 | eth_proto, SUPPORTED); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 765 | |
| 766 | eth_proto = be32_to_cpu(ptys_reg.eth_proto_admin); |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 767 | ptys2ethtool_update_link_modes(link_ksettings->link_modes.advertising, |
| 768 | eth_proto, ADVERTISED); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 769 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 770 | ethtool_link_ksettings_add_link_mode(link_ksettings, supported, |
| 771 | Pause); |
| 772 | ethtool_link_ksettings_add_link_mode(link_ksettings, supported, |
| 773 | Asym_Pause); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 774 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 775 | if (priv->prof->tx_pause) |
| 776 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 777 | advertising, Pause); |
| 778 | if (priv->prof->tx_pause ^ priv->prof->rx_pause) |
| 779 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 780 | advertising, Asym_Pause); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 781 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 782 | link_ksettings->base.port = ptys_get_active_port(&ptys_reg); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 783 | |
| 784 | if (mlx4_en_autoneg_get(dev)) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 785 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 786 | supported, Autoneg); |
| 787 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 788 | advertising, Autoneg); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 789 | } |
| 790 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 791 | link_ksettings->base.autoneg |
| 792 | = (priv->port_state.flags & MLX4_EN_PORT_ANC) ? |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 793 | AUTONEG_ENABLE : AUTONEG_DISABLE; |
| 794 | |
| 795 | eth_proto = be32_to_cpu(ptys_reg.eth_proto_lp_adv); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 796 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 797 | ethtool_link_ksettings_zero_link_mode(link_ksettings, lp_advertising); |
| 798 | ptys2ethtool_update_link_modes( |
| 799 | link_ksettings->link_modes.lp_advertising, |
| 800 | eth_proto, ADVERTISED); |
| 801 | if (priv->port_state.flags & MLX4_EN_PORT_ANC) |
| 802 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 803 | lp_advertising, Autoneg); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 804 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 805 | link_ksettings->base.phy_address = 0; |
| 806 | link_ksettings->base.mdio_support = 0; |
| 807 | link_ksettings->base.eth_tp_mdix = ETH_TP_MDI_INVALID; |
| 808 | link_ksettings->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO; |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 809 | |
| 810 | return ret; |
| 811 | } |
| 812 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 813 | static void |
| 814 | ethtool_get_default_link_ksettings( |
| 815 | struct net_device *dev, struct ethtool_link_ksettings *link_ksettings) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 816 | { |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 817 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 818 | int trans_type; |
| 819 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 820 | link_ksettings->base.autoneg = AUTONEG_DISABLE; |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 821 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 822 | ethtool_link_ksettings_zero_link_mode(link_ksettings, supported); |
| 823 | ethtool_link_ksettings_add_link_mode(link_ksettings, supported, |
| 824 | 10000baseT_Full); |
| 825 | |
| 826 | ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising); |
| 827 | ethtool_link_ksettings_add_link_mode(link_ksettings, advertising, |
| 828 | 10000baseT_Full); |
| 829 | |
| 830 | trans_type = priv->port_state.transceiver; |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 831 | if (trans_type > 0 && trans_type <= 0xC) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 832 | link_ksettings->base.port = PORT_FIBRE; |
| 833 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 834 | supported, FIBRE); |
| 835 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 836 | advertising, FIBRE); |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 837 | } else if (trans_type == 0x80 || trans_type == 0) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 838 | link_ksettings->base.port = PORT_TP; |
| 839 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 840 | supported, TP); |
| 841 | ethtool_link_ksettings_add_link_mode(link_ksettings, |
| 842 | advertising, TP); |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 843 | } else { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 844 | link_ksettings->base.port = -1; |
Yevgeny Petrilin | 7699517 | 2010-08-24 03:46:23 +0000 | [diff] [blame] | 845 | } |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 846 | } |
| 847 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 848 | static int |
| 849 | mlx4_en_get_link_ksettings(struct net_device *dev, |
| 850 | struct ethtool_link_ksettings *link_ksettings) |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 851 | { |
| 852 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 853 | int ret = -EINVAL; |
| 854 | |
| 855 | if (mlx4_en_QUERY_PORT(priv->mdev, priv->port)) |
| 856 | return -ENOMEM; |
| 857 | |
| 858 | en_dbg(DRV, priv, "query port state.flags ANC(%x) ANE(%x)\n", |
| 859 | priv->port_state.flags & MLX4_EN_PORT_ANC, |
| 860 | priv->port_state.flags & MLX4_EN_PORT_ANE); |
| 861 | |
| 862 | if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL) |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 863 | ret = ethtool_get_ptys_link_ksettings(dev, link_ksettings); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 864 | if (ret) /* ETH PROT CRTL is not supported or PTYS CMD failed */ |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 865 | ethtool_get_default_link_ksettings(dev, link_ksettings); |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 866 | |
| 867 | if (netif_carrier_ok(dev)) { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 868 | link_ksettings->base.speed = priv->port_state.link_speed; |
| 869 | link_ksettings->base.duplex = DUPLEX_FULL; |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 870 | } else { |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 871 | link_ksettings->base.speed = SPEED_UNKNOWN; |
| 872 | link_ksettings->base.duplex = DUPLEX_UNKNOWN; |
Saeed Mahameed | 2c76267 | 2014-10-27 11:37:40 +0200 | [diff] [blame] | 873 | } |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 874 | return 0; |
| 875 | } |
| 876 | |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 877 | /* Calculate PTYS admin according ethtool speed (SPEED_XXX) */ |
| 878 | static __be32 speed_set_ptys_admin(struct mlx4_en_priv *priv, u32 speed, |
| 879 | __be32 proto_cap) |
| 880 | { |
| 881 | __be32 proto_admin = 0; |
| 882 | |
| 883 | if (!speed) { /* Speed = 0 ==> Reset Link modes */ |
| 884 | proto_admin = proto_cap; |
| 885 | en_info(priv, "Speed was set to 0, Reset advertised Link Modes to default (%x)\n", |
| 886 | be32_to_cpu(proto_cap)); |
| 887 | } else { |
| 888 | u32 ptys_link_modes = speed2ptys_link_modes(speed); |
| 889 | |
| 890 | proto_admin = cpu_to_be32(ptys_link_modes) & proto_cap; |
| 891 | en_info(priv, "Setting Speed to %d\n", speed); |
| 892 | } |
| 893 | return proto_admin; |
| 894 | } |
| 895 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 896 | static int |
| 897 | mlx4_en_set_link_ksettings(struct net_device *dev, |
| 898 | const struct ethtool_link_ksettings *link_ksettings) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 899 | { |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 900 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 901 | struct mlx4_ptys_reg ptys_reg; |
| 902 | __be32 proto_admin; |
| 903 | int ret; |
| 904 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 905 | u32 ptys_adv = ethtool2ptys_link_modes( |
| 906 | link_ksettings->link_modes.advertising, ADVERTISED); |
| 907 | const int speed = link_ksettings->base.speed; |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 908 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 909 | en_dbg(DRV, priv, |
| 910 | "Set Speed=%d adv={%*pbl} autoneg=%d duplex=%d\n", |
| 911 | speed, __ETHTOOL_LINK_MODE_MASK_NBITS, |
| 912 | link_ksettings->link_modes.advertising, |
| 913 | link_ksettings->base.autoneg, |
| 914 | link_ksettings->base.duplex); |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 915 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 916 | if (!(priv->mdev->dev->caps.flags2 & |
| 917 | MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL) || |
| 918 | (link_ksettings->base.duplex == DUPLEX_HALF)) |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 919 | return -EINVAL; |
| 920 | |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 921 | memset(&ptys_reg, 0, sizeof(ptys_reg)); |
| 922 | ptys_reg.local_port = priv->port; |
| 923 | ptys_reg.proto_mask = MLX4_PTYS_EN; |
| 924 | ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev, |
| 925 | MLX4_ACCESS_REG_QUERY, &ptys_reg); |
| 926 | if (ret) { |
| 927 | en_warn(priv, "Failed to QUERY mlx4_ACCESS_PTYS_REG status(%x)\n", |
| 928 | ret); |
| 929 | return 0; |
| 930 | } |
| 931 | |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 932 | proto_admin = link_ksettings->base.autoneg == AUTONEG_ENABLE ? |
Saeed Mahameed | 5a228c0 | 2015-01-27 15:58:06 +0200 | [diff] [blame] | 933 | cpu_to_be32(ptys_adv) : |
| 934 | speed_set_ptys_admin(priv, speed, |
| 935 | ptys_reg.eth_proto_cap); |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 936 | |
| 937 | proto_admin &= ptys_reg.eth_proto_cap; |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 938 | if (!proto_admin) { |
| 939 | en_warn(priv, "Not supported link mode(s) requested, check supported link modes.\n"); |
| 940 | return -EINVAL; /* nothing to change due to bad input */ |
| 941 | } |
| 942 | |
Saeed Mahameed | 5a228c0 | 2015-01-27 15:58:06 +0200 | [diff] [blame] | 943 | if (proto_admin == ptys_reg.eth_proto_admin) |
| 944 | return 0; /* Nothing to change */ |
| 945 | |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 946 | en_dbg(DRV, priv, "mlx4_ACCESS_PTYS_REG SET: ptys_reg.eth_proto_admin = 0x%x\n", |
| 947 | be32_to_cpu(proto_admin)); |
| 948 | |
| 949 | ptys_reg.eth_proto_admin = proto_admin; |
| 950 | ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev, MLX4_ACCESS_REG_WRITE, |
| 951 | &ptys_reg); |
| 952 | if (ret) { |
| 953 | en_warn(priv, "Failed to write mlx4_ACCESS_PTYS_REG eth_proto_admin(0x%x) status(0x%x)", |
| 954 | be32_to_cpu(ptys_reg.eth_proto_admin), ret); |
| 955 | return ret; |
| 956 | } |
| 957 | |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 958 | mutex_lock(&priv->mdev->state_lock); |
| 959 | if (priv->port_up) { |
Saeed Mahameed | 5a228c0 | 2015-01-27 15:58:06 +0200 | [diff] [blame] | 960 | en_warn(priv, "Port link mode changed, restarting port...\n"); |
Saeed Mahameed | d48b3ab | 2014-10-27 11:37:41 +0200 | [diff] [blame] | 961 | mlx4_en_stop_port(dev, 1); |
| 962 | if (mlx4_en_start_port(dev)) |
| 963 | en_err(priv, "Failed restarting port %d\n", priv->port); |
| 964 | } |
| 965 | mutex_unlock(&priv->mdev->state_lock); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | static int mlx4_en_get_coalesce(struct net_device *dev, |
| 970 | struct ethtool_coalesce *coal) |
| 971 | { |
| 972 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 973 | |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 974 | coal->tx_coalesce_usecs = priv->tx_usecs; |
| 975 | coal->tx_max_coalesced_frames = priv->tx_frames; |
Amir Vadai | fbc6daf | 2014-07-08 11:28:12 +0300 | [diff] [blame] | 976 | coal->tx_max_coalesced_frames_irq = priv->tx_work_limit; |
| 977 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 978 | coal->rx_coalesce_usecs = priv->rx_usecs; |
| 979 | coal->rx_max_coalesced_frames = priv->rx_frames; |
| 980 | |
| 981 | coal->pkt_rate_low = priv->pkt_rate_low; |
| 982 | coal->rx_coalesce_usecs_low = priv->rx_usecs_low; |
| 983 | coal->pkt_rate_high = priv->pkt_rate_high; |
| 984 | coal->rx_coalesce_usecs_high = priv->rx_usecs_high; |
| 985 | coal->rate_sample_interval = priv->sample_interval; |
| 986 | coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal; |
Amir Vadai | fbc6daf | 2014-07-08 11:28:12 +0300 | [diff] [blame] | 987 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | static int mlx4_en_set_coalesce(struct net_device *dev, |
| 992 | struct ethtool_coalesce *coal) |
| 993 | { |
| 994 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 995 | |
Amir Vadai | fbc6daf | 2014-07-08 11:28:12 +0300 | [diff] [blame] | 996 | if (!coal->tx_max_coalesced_frames_irq) |
| 997 | return -EINVAL; |
| 998 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 999 | priv->rx_frames = (coal->rx_max_coalesced_frames == |
| 1000 | MLX4_EN_AUTO_CONF) ? |
Yevgeny Petrilin | 3db36fb | 2009-06-01 23:23:13 +0000 | [diff] [blame] | 1001 | MLX4_EN_RX_COAL_TARGET : |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1002 | coal->rx_max_coalesced_frames; |
| 1003 | priv->rx_usecs = (coal->rx_coalesce_usecs == |
| 1004 | MLX4_EN_AUTO_CONF) ? |
| 1005 | MLX4_EN_RX_COAL_TIME : |
| 1006 | coal->rx_coalesce_usecs; |
| 1007 | |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 1008 | /* Setting TX coalescing parameters */ |
| 1009 | if (coal->tx_coalesce_usecs != priv->tx_usecs || |
| 1010 | coal->tx_max_coalesced_frames != priv->tx_frames) { |
| 1011 | priv->tx_usecs = coal->tx_coalesce_usecs; |
| 1012 | priv->tx_frames = coal->tx_max_coalesced_frames; |
Yevgeny Petrilin | a19a848 | 2012-04-23 02:18:33 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1015 | /* Set adaptive coalescing params */ |
| 1016 | priv->pkt_rate_low = coal->pkt_rate_low; |
| 1017 | priv->rx_usecs_low = coal->rx_coalesce_usecs_low; |
| 1018 | priv->pkt_rate_high = coal->pkt_rate_high; |
| 1019 | priv->rx_usecs_high = coal->rx_coalesce_usecs_high; |
| 1020 | priv->sample_interval = coal->rate_sample_interval; |
| 1021 | priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce; |
Amir Vadai | fbc6daf | 2014-07-08 11:28:12 +0300 | [diff] [blame] | 1022 | priv->tx_work_limit = coal->tx_max_coalesced_frames_irq; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1023 | |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 1024 | return mlx4_en_moderation_update(priv); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | static int mlx4_en_set_pauseparam(struct net_device *dev, |
| 1028 | struct ethtool_pauseparam *pause) |
| 1029 | { |
| 1030 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1031 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1032 | int err; |
| 1033 | |
Ivan Vecera | 278d436 | 2014-09-08 18:46:53 +0200 | [diff] [blame] | 1034 | if (pause->autoneg) |
| 1035 | return -EINVAL; |
| 1036 | |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 1037 | priv->prof->tx_pause = pause->tx_pause != 0; |
| 1038 | priv->prof->rx_pause = pause->rx_pause != 0; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1039 | err = mlx4_SET_PORT_general(mdev->dev, priv->port, |
| 1040 | priv->rx_skb_size + ETH_FCS_LEN, |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 1041 | priv->prof->tx_pause, |
| 1042 | priv->prof->tx_ppp, |
| 1043 | priv->prof->rx_pause, |
| 1044 | priv->prof->rx_ppp); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1045 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1046 | en_err(priv, "Failed setting pause params\n"); |
Matan Barak | 0b13156 | 2015-03-30 17:45:25 +0300 | [diff] [blame] | 1047 | else |
| 1048 | mlx4_en_update_pfc_stats_bitmap(mdev->dev, &priv->stats_bitmap, |
| 1049 | priv->prof->rx_ppp, |
| 1050 | priv->prof->rx_pause, |
| 1051 | priv->prof->tx_ppp, |
| 1052 | priv->prof->tx_pause); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1053 | |
| 1054 | return err; |
| 1055 | } |
| 1056 | |
| 1057 | static void mlx4_en_get_pauseparam(struct net_device *dev, |
| 1058 | struct ethtool_pauseparam *pause) |
| 1059 | { |
| 1060 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1061 | |
Yevgeny Petrilin | d53b93f | 2008-11-05 04:48:36 +0000 | [diff] [blame] | 1062 | pause->tx_pause = priv->prof->tx_pause; |
| 1063 | pause->rx_pause = priv->prof->rx_pause; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1066 | static int mlx4_en_set_ringparam(struct net_device *dev, |
| 1067 | struct ethtool_ringparam *param) |
| 1068 | { |
| 1069 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1070 | struct mlx4_en_dev *mdev = priv->mdev; |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1071 | struct mlx4_en_port_profile new_prof; |
| 1072 | struct mlx4_en_priv *tmp; |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1073 | u32 rx_size, tx_size; |
| 1074 | int port_up = 0; |
| 1075 | int err = 0; |
| 1076 | |
| 1077 | if (param->rx_jumbo_pending || param->rx_mini_pending) |
| 1078 | return -EINVAL; |
| 1079 | |
| 1080 | rx_size = roundup_pow_of_two(param->rx_pending); |
| 1081 | rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 1082 | rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1083 | tx_size = roundup_pow_of_two(param->tx_pending); |
| 1084 | tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 1085 | tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1086 | |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1087 | if (rx_size == (priv->port_up ? priv->rx_ring[0]->actual_size : |
| 1088 | priv->rx_ring[0]->size) && |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1089 | tx_size == priv->tx_ring[TX][0]->size) |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1090 | return 0; |
| 1091 | |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1092 | tmp = kzalloc(sizeof(*tmp), GFP_KERNEL); |
| 1093 | if (!tmp) |
| 1094 | return -ENOMEM; |
| 1095 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1096 | mutex_lock(&mdev->state_lock); |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1097 | memcpy(&new_prof, priv->prof, sizeof(struct mlx4_en_port_profile)); |
| 1098 | new_prof.tx_ring_size = tx_size; |
| 1099 | new_prof.rx_ring_size = rx_size; |
| 1100 | err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof); |
| 1101 | if (err) |
| 1102 | goto out; |
| 1103 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1104 | if (priv->port_up) { |
| 1105 | port_up = 1; |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1106 | mlx4_en_stop_port(dev, 1); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1109 | mlx4_en_safe_replace_resources(priv, tmp); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1110 | |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1111 | if (port_up) { |
| 1112 | err = mlx4_en_start_port(dev); |
| 1113 | if (err) |
Yevgeny Petrilin | 453a608 | 2009-06-01 20:27:13 +0000 | [diff] [blame] | 1114 | en_err(priv, "Failed starting port\n"); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1115 | } |
| 1116 | |
Amir Vadai | 79c54b6 | 2012-12-02 03:49:22 +0000 | [diff] [blame] | 1117 | err = mlx4_en_moderation_update(priv); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1118 | out: |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1119 | kfree(tmp); |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 1120 | mutex_unlock(&mdev->state_lock); |
| 1121 | return err; |
| 1122 | } |
| 1123 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1124 | static void mlx4_en_get_ringparam(struct net_device *dev, |
| 1125 | struct ethtool_ringparam *param) |
| 1126 | { |
| 1127 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1128 | |
| 1129 | memset(param, 0, sizeof(*param)); |
Yevgeny Petrilin | bd531e3 | 2009-01-08 10:57:37 -0800 | [diff] [blame] | 1130 | param->rx_max_pending = MLX4_EN_MAX_RX_SIZE; |
| 1131 | param->tx_max_pending = MLX4_EN_MAX_TX_SIZE; |
Yevgeny Petrilin | bc081ce | 2010-08-24 03:46:34 +0000 | [diff] [blame] | 1132 | param->rx_pending = priv->port_up ? |
Eugenia Emantayev | 41d942d | 2013-11-07 12:19:52 +0200 | [diff] [blame] | 1133 | priv->rx_ring[0]->actual_size : priv->rx_ring[0]->size; |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1134 | param->tx_pending = priv->tx_ring[TX][0]->size; |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1137 | static u32 mlx4_en_get_rxfh_indir_size(struct net_device *dev) |
| 1138 | { |
| 1139 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1140 | |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1141 | return rounddown_pow_of_two(priv->rx_ring_num); |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Eric Dumazet | b9d1ab7 | 2014-11-16 06:23:16 -0800 | [diff] [blame] | 1144 | static u32 mlx4_en_get_rxfh_key_size(struct net_device *netdev) |
| 1145 | { |
| 1146 | return MLX4_EN_RSS_KEY_SIZE; |
| 1147 | } |
| 1148 | |
Eyal Perry | 947cbb0 | 2014-12-02 18:12:11 +0200 | [diff] [blame] | 1149 | static int mlx4_en_check_rxfh_func(struct net_device *dev, u8 hfunc) |
| 1150 | { |
| 1151 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1152 | |
| 1153 | /* check if requested function is supported by the device */ |
Amir Vadai | b370690 | 2015-04-27 13:40:56 +0300 | [diff] [blame] | 1154 | if (hfunc == ETH_RSS_HASH_TOP) { |
| 1155 | if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP)) |
| 1156 | return -EINVAL; |
| 1157 | if (!(dev->features & NETIF_F_RXHASH)) |
| 1158 | en_warn(priv, "Toeplitz hash function should be used in conjunction with RX hashing for optimal performance\n"); |
| 1159 | return 0; |
| 1160 | } else if (hfunc == ETH_RSS_HASH_XOR) { |
| 1161 | if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR)) |
| 1162 | return -EINVAL; |
| 1163 | if (dev->features & NETIF_F_RXHASH) |
| 1164 | en_warn(priv, "Enabling both XOR Hash function and RX Hashing can limit RPS functionality\n"); |
| 1165 | return 0; |
| 1166 | } |
Eyal Perry | 947cbb0 | 2014-12-02 18:12:11 +0200 | [diff] [blame] | 1167 | |
Amir Vadai | b370690 | 2015-04-27 13:40:56 +0300 | [diff] [blame] | 1168 | return -EINVAL; |
Eyal Perry | 947cbb0 | 2014-12-02 18:12:11 +0200 | [diff] [blame] | 1169 | } |
| 1170 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1171 | static int mlx4_en_get_rxfh(struct net_device *dev, u32 *ring_index, u8 *key, |
| 1172 | u8 *hfunc) |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1173 | { |
| 1174 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1175 | u32 n = mlx4_en_get_rxfh_indir_size(dev); |
| 1176 | u32 i, rss_rings; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1177 | int err = 0; |
| 1178 | |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1179 | rss_rings = priv->prof->rss_rings ?: n; |
| 1180 | rss_rings = rounddown_pow_of_two(rss_rings); |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1181 | |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1182 | for (i = 0; i < n; i++) { |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1183 | if (!ring_index) |
| 1184 | break; |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1185 | ring_index[i] = i % rss_rings; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1186 | } |
Eric Dumazet | b9d1ab7 | 2014-11-16 06:23:16 -0800 | [diff] [blame] | 1187 | if (key) |
Eric Dumazet | bd635c3 | 2014-11-22 17:24:19 -0800 | [diff] [blame] | 1188 | memcpy(key, priv->rss_key, MLX4_EN_RSS_KEY_SIZE); |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1189 | if (hfunc) |
Eyal Perry | 947cbb0 | 2014-12-02 18:12:11 +0200 | [diff] [blame] | 1190 | *hfunc = priv->rss_hash_fn; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1191 | return err; |
| 1192 | } |
| 1193 | |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 1194 | static int mlx4_en_set_rxfh(struct net_device *dev, const u32 *ring_index, |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1195 | const u8 *key, const u8 hfunc) |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1196 | { |
| 1197 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1198 | u32 n = mlx4_en_get_rxfh_indir_size(dev); |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1199 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1200 | int port_up = 0; |
| 1201 | int err = 0; |
| 1202 | int i; |
| 1203 | int rss_rings = 0; |
| 1204 | |
| 1205 | /* Calculate RSS table size and make sure flows are spread evenly |
| 1206 | * between rings |
| 1207 | */ |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1208 | for (i = 0; i < n; i++) { |
Eric Dumazet | bd635c3 | 2014-11-22 17:24:19 -0800 | [diff] [blame] | 1209 | if (!ring_index) |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1210 | break; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1211 | if (i > 0 && !ring_index[i] && !rss_rings) |
| 1212 | rss_rings = i; |
| 1213 | |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1214 | if (ring_index[i] != (i % (rss_rings ?: n))) |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1215 | return -EINVAL; |
| 1216 | } |
| 1217 | |
| 1218 | if (!rss_rings) |
Eric Dumazet | f7d3c1c | 2016-06-07 21:24:18 -0700 | [diff] [blame] | 1219 | rss_rings = n; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1220 | |
| 1221 | /* RSS table size must be an order of 2 */ |
| 1222 | if (!is_power_of_2(rss_rings)) |
| 1223 | return -EINVAL; |
| 1224 | |
Eyal Perry | 947cbb0 | 2014-12-02 18:12:11 +0200 | [diff] [blame] | 1225 | if (hfunc != ETH_RSS_HASH_NO_CHANGE) { |
| 1226 | err = mlx4_en_check_rxfh_func(dev, hfunc); |
| 1227 | if (err) |
| 1228 | return err; |
| 1229 | } |
| 1230 | |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1231 | mutex_lock(&mdev->state_lock); |
| 1232 | if (priv->port_up) { |
| 1233 | port_up = 1; |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1234 | mlx4_en_stop_port(dev, 1); |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
Eric Dumazet | bd635c3 | 2014-11-22 17:24:19 -0800 | [diff] [blame] | 1237 | if (ring_index) |
| 1238 | priv->prof->rss_rings = rss_rings; |
| 1239 | if (key) |
| 1240 | memcpy(priv->rss_key, key, MLX4_EN_RSS_KEY_SIZE); |
Amir Vadai | b370690 | 2015-04-27 13:40:56 +0300 | [diff] [blame] | 1241 | if (hfunc != ETH_RSS_HASH_NO_CHANGE) |
| 1242 | priv->rss_hash_fn = hfunc; |
Eyal Perry | 947cbb0 | 2014-12-02 18:12:11 +0200 | [diff] [blame] | 1243 | |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1244 | if (port_up) { |
| 1245 | err = mlx4_en_start_port(dev); |
| 1246 | if (err) |
| 1247 | en_err(priv, "Failed starting port\n"); |
| 1248 | } |
| 1249 | |
| 1250 | mutex_unlock(&mdev->state_lock); |
| 1251 | return err; |
| 1252 | } |
| 1253 | |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1254 | #define all_zeros_or_all_ones(field) \ |
| 1255 | ((field) == 0 || (field) == (__force typeof(field))-1) |
| 1256 | |
| 1257 | static int mlx4_en_validate_flow(struct net_device *dev, |
| 1258 | struct ethtool_rxnfc *cmd) |
| 1259 | { |
| 1260 | struct ethtool_usrip4_spec *l3_mask; |
| 1261 | struct ethtool_tcpip4_spec *l4_mask; |
| 1262 | struct ethhdr *eth_mask; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1263 | |
| 1264 | if (cmd->fs.location >= MAX_NUM_OF_FS_RULES) |
| 1265 | return -EINVAL; |
| 1266 | |
Yan Burman | 520dfe3 | 2012-12-12 02:13:19 +0000 | [diff] [blame] | 1267 | if (cmd->fs.flow_type & FLOW_MAC_EXT) { |
| 1268 | /* dest mac mask must be ff:ff:ff:ff:ff:ff */ |
| 1269 | if (!is_broadcast_ether_addr(cmd->fs.m_ext.h_dest)) |
| 1270 | return -EINVAL; |
| 1271 | } |
| 1272 | |
| 1273 | switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) { |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1274 | case TCP_V4_FLOW: |
| 1275 | case UDP_V4_FLOW: |
| 1276 | if (cmd->fs.m_u.tcp_ip4_spec.tos) |
| 1277 | return -EINVAL; |
| 1278 | l4_mask = &cmd->fs.m_u.tcp_ip4_spec; |
| 1279 | /* don't allow mask which isn't all 0 or 1 */ |
| 1280 | if (!all_zeros_or_all_ones(l4_mask->ip4src) || |
| 1281 | !all_zeros_or_all_ones(l4_mask->ip4dst) || |
| 1282 | !all_zeros_or_all_ones(l4_mask->psrc) || |
| 1283 | !all_zeros_or_all_ones(l4_mask->pdst)) |
| 1284 | return -EINVAL; |
| 1285 | break; |
| 1286 | case IP_USER_FLOW: |
| 1287 | l3_mask = &cmd->fs.m_u.usr_ip4_spec; |
| 1288 | if (l3_mask->l4_4_bytes || l3_mask->tos || l3_mask->proto || |
| 1289 | cmd->fs.h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 || |
| 1290 | (!l3_mask->ip4src && !l3_mask->ip4dst) || |
| 1291 | !all_zeros_or_all_ones(l3_mask->ip4src) || |
| 1292 | !all_zeros_or_all_ones(l3_mask->ip4dst)) |
| 1293 | return -EINVAL; |
| 1294 | break; |
| 1295 | case ETHER_FLOW: |
| 1296 | eth_mask = &cmd->fs.m_u.ether_spec; |
| 1297 | /* source mac mask must not be set */ |
Yan Burman | c402b94 | 2012-12-12 02:13:18 +0000 | [diff] [blame] | 1298 | if (!is_zero_ether_addr(eth_mask->h_source)) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1299 | return -EINVAL; |
| 1300 | |
| 1301 | /* dest mac mask must be ff:ff:ff:ff:ff:ff */ |
Yan Burman | c402b94 | 2012-12-12 02:13:18 +0000 | [diff] [blame] | 1302 | if (!is_broadcast_ether_addr(eth_mask->h_dest)) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1303 | return -EINVAL; |
| 1304 | |
| 1305 | if (!all_zeros_or_all_ones(eth_mask->h_proto)) |
| 1306 | return -EINVAL; |
| 1307 | break; |
| 1308 | default: |
| 1309 | return -EINVAL; |
| 1310 | } |
| 1311 | |
| 1312 | if ((cmd->fs.flow_type & FLOW_EXT)) { |
| 1313 | if (cmd->fs.m_ext.vlan_etype || |
Hadar Hen Zion | 8258bd2 | 2013-01-30 23:07:06 +0000 | [diff] [blame] | 1314 | !((cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) == |
| 1315 | 0 || |
| 1316 | (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) == |
| 1317 | cpu_to_be16(VLAN_VID_MASK))) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1318 | return -EINVAL; |
Hadar Hen Zion | 8258bd2 | 2013-01-30 23:07:06 +0000 | [diff] [blame] | 1319 | |
Hadar Hen Zion | 69d7126 | 2013-01-30 23:07:05 +0000 | [diff] [blame] | 1320 | if (cmd->fs.m_ext.vlan_tci) { |
| 1321 | if (be16_to_cpu(cmd->fs.h_ext.vlan_tci) >= VLAN_N_VID) |
| 1322 | return -EINVAL; |
Hadar Hen Zion | 8258bd2 | 2013-01-30 23:07:06 +0000 | [diff] [blame] | 1323 | |
Hadar Hen Zion | 69d7126 | 2013-01-30 23:07:05 +0000 | [diff] [blame] | 1324 | } |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1330 | static int mlx4_en_ethtool_add_mac_rule(struct ethtool_rxnfc *cmd, |
| 1331 | struct list_head *rule_list_h, |
| 1332 | struct mlx4_spec_list *spec_l2, |
| 1333 | unsigned char *mac) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1334 | { |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1335 | int err = 0; |
| 1336 | __be64 mac_msk = cpu_to_be64(MLX4_MAC_MASK << 16); |
| 1337 | |
| 1338 | spec_l2->id = MLX4_NET_TRANS_RULE_ID_ETH; |
| 1339 | memcpy(spec_l2->eth.dst_mac_msk, &mac_msk, ETH_ALEN); |
| 1340 | memcpy(spec_l2->eth.dst_mac, mac, ETH_ALEN); |
| 1341 | |
Hadar Hen Zion | 8258bd2 | 2013-01-30 23:07:06 +0000 | [diff] [blame] | 1342 | if ((cmd->fs.flow_type & FLOW_EXT) && |
| 1343 | (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK))) { |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1344 | spec_l2->eth.vlan_id = cmd->fs.h_ext.vlan_tci; |
Hadar Hen Zion | 8258bd2 | 2013-01-30 23:07:06 +0000 | [diff] [blame] | 1345 | spec_l2->eth.vlan_id_msk = cpu_to_be16(VLAN_VID_MASK); |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | list_add_tail(&spec_l2->list, rule_list_h); |
| 1349 | |
| 1350 | return err; |
| 1351 | } |
| 1352 | |
| 1353 | static int mlx4_en_ethtool_add_mac_rule_by_ipv4(struct mlx4_en_priv *priv, |
| 1354 | struct ethtool_rxnfc *cmd, |
| 1355 | struct list_head *rule_list_h, |
| 1356 | struct mlx4_spec_list *spec_l2, |
| 1357 | __be32 ipv4_dst) |
| 1358 | { |
Hadar Hen Zion | f9d9686 | 2013-02-04 03:01:21 +0000 | [diff] [blame] | 1359 | #ifdef CONFIG_INET |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1360 | unsigned char mac[ETH_ALEN]; |
| 1361 | |
| 1362 | if (!ipv4_is_multicast(ipv4_dst)) { |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame] | 1363 | if (cmd->fs.flow_type & FLOW_MAC_EXT) |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1364 | memcpy(&mac, cmd->fs.h_ext.h_dest, ETH_ALEN); |
Yan Burman | 6bbb6d9 | 2013-02-07 02:25:20 +0000 | [diff] [blame] | 1365 | else |
| 1366 | memcpy(&mac, priv->dev->dev_addr, ETH_ALEN); |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1367 | } else { |
| 1368 | ip_eth_mc_map(ipv4_dst, mac); |
| 1369 | } |
| 1370 | |
| 1371 | return mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2, &mac[0]); |
Hadar Hen Zion | f9d9686 | 2013-02-04 03:01:21 +0000 | [diff] [blame] | 1372 | #else |
| 1373 | return -EINVAL; |
| 1374 | #endif |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | static int add_ip_rule(struct mlx4_en_priv *priv, |
| 1378 | struct ethtool_rxnfc *cmd, |
| 1379 | struct list_head *list_h) |
| 1380 | { |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1381 | int err; |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1382 | struct mlx4_spec_list *spec_l2 = NULL; |
| 1383 | struct mlx4_spec_list *spec_l3 = NULL; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1384 | struct ethtool_usrip4_spec *l3_mask = &cmd->fs.m_u.usr_ip4_spec; |
| 1385 | |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1386 | spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL); |
| 1387 | spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL); |
| 1388 | if (!spec_l2 || !spec_l3) { |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1389 | err = -ENOMEM; |
| 1390 | goto free_spec; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1393 | err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h, spec_l2, |
| 1394 | cmd->fs.h_u. |
| 1395 | usr_ip4_spec.ip4dst); |
| 1396 | if (err) |
| 1397 | goto free_spec; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1398 | spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4; |
| 1399 | spec_l3->ipv4.src_ip = cmd->fs.h_u.usr_ip4_spec.ip4src; |
| 1400 | if (l3_mask->ip4src) |
| 1401 | spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK; |
| 1402 | spec_l3->ipv4.dst_ip = cmd->fs.h_u.usr_ip4_spec.ip4dst; |
| 1403 | if (l3_mask->ip4dst) |
| 1404 | spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK; |
| 1405 | list_add_tail(&spec_l3->list, list_h); |
| 1406 | |
| 1407 | return 0; |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1408 | |
| 1409 | free_spec: |
| 1410 | kfree(spec_l2); |
| 1411 | kfree(spec_l3); |
| 1412 | return err; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | static int add_tcp_udp_rule(struct mlx4_en_priv *priv, |
| 1416 | struct ethtool_rxnfc *cmd, |
| 1417 | struct list_head *list_h, int proto) |
| 1418 | { |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1419 | int err; |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1420 | struct mlx4_spec_list *spec_l2 = NULL; |
| 1421 | struct mlx4_spec_list *spec_l3 = NULL; |
| 1422 | struct mlx4_spec_list *spec_l4 = NULL; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1423 | struct ethtool_tcpip4_spec *l4_mask = &cmd->fs.m_u.tcp_ip4_spec; |
| 1424 | |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1425 | spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL); |
| 1426 | spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL); |
| 1427 | spec_l4 = kzalloc(sizeof(*spec_l4), GFP_KERNEL); |
| 1428 | if (!spec_l2 || !spec_l3 || !spec_l4) { |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1429 | err = -ENOMEM; |
| 1430 | goto free_spec; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4; |
| 1434 | |
| 1435 | if (proto == TCP_V4_FLOW) { |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1436 | err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h, |
| 1437 | spec_l2, |
| 1438 | cmd->fs.h_u. |
| 1439 | tcp_ip4_spec.ip4dst); |
| 1440 | if (err) |
| 1441 | goto free_spec; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1442 | spec_l4->id = MLX4_NET_TRANS_RULE_ID_TCP; |
| 1443 | spec_l3->ipv4.src_ip = cmd->fs.h_u.tcp_ip4_spec.ip4src; |
| 1444 | spec_l3->ipv4.dst_ip = cmd->fs.h_u.tcp_ip4_spec.ip4dst; |
| 1445 | spec_l4->tcp_udp.src_port = cmd->fs.h_u.tcp_ip4_spec.psrc; |
| 1446 | spec_l4->tcp_udp.dst_port = cmd->fs.h_u.tcp_ip4_spec.pdst; |
| 1447 | } else { |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1448 | err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h, |
| 1449 | spec_l2, |
| 1450 | cmd->fs.h_u. |
| 1451 | udp_ip4_spec.ip4dst); |
| 1452 | if (err) |
| 1453 | goto free_spec; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1454 | spec_l4->id = MLX4_NET_TRANS_RULE_ID_UDP; |
| 1455 | spec_l3->ipv4.src_ip = cmd->fs.h_u.udp_ip4_spec.ip4src; |
| 1456 | spec_l3->ipv4.dst_ip = cmd->fs.h_u.udp_ip4_spec.ip4dst; |
| 1457 | spec_l4->tcp_udp.src_port = cmd->fs.h_u.udp_ip4_spec.psrc; |
| 1458 | spec_l4->tcp_udp.dst_port = cmd->fs.h_u.udp_ip4_spec.pdst; |
| 1459 | } |
| 1460 | |
| 1461 | if (l4_mask->ip4src) |
| 1462 | spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK; |
| 1463 | if (l4_mask->ip4dst) |
| 1464 | spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK; |
| 1465 | |
| 1466 | if (l4_mask->psrc) |
| 1467 | spec_l4->tcp_udp.src_port_msk = EN_ETHTOOL_SHORT_MASK; |
| 1468 | if (l4_mask->pdst) |
| 1469 | spec_l4->tcp_udp.dst_port_msk = EN_ETHTOOL_SHORT_MASK; |
| 1470 | |
| 1471 | list_add_tail(&spec_l3->list, list_h); |
| 1472 | list_add_tail(&spec_l4->list, list_h); |
| 1473 | |
| 1474 | return 0; |
Hadar Hen Zion | 377d973 | 2013-02-04 03:01:20 +0000 | [diff] [blame] | 1475 | |
| 1476 | free_spec: |
| 1477 | kfree(spec_l2); |
| 1478 | kfree(spec_l3); |
| 1479 | kfree(spec_l4); |
| 1480 | return err; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | static int mlx4_en_ethtool_to_net_trans_rule(struct net_device *dev, |
| 1484 | struct ethtool_rxnfc *cmd, |
| 1485 | struct list_head *rule_list_h) |
| 1486 | { |
| 1487 | int err; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1488 | struct ethhdr *eth_spec; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1489 | struct mlx4_spec_list *spec_l2; |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1490 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1491 | |
| 1492 | err = mlx4_en_validate_flow(dev, cmd); |
| 1493 | if (err) |
| 1494 | return err; |
| 1495 | |
Yan Burman | 520dfe3 | 2012-12-12 02:13:19 +0000 | [diff] [blame] | 1496 | switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) { |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1497 | case ETHER_FLOW: |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1498 | spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL); |
| 1499 | if (!spec_l2) |
| 1500 | return -ENOMEM; |
| 1501 | |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1502 | eth_spec = &cmd->fs.h_u.ether_spec; |
Hadar Hen Zion | f90a367 | 2013-01-30 23:07:04 +0000 | [diff] [blame] | 1503 | mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2, |
| 1504 | ð_spec->h_dest[0]); |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1505 | spec_l2->eth.ether_type = eth_spec->h_proto; |
| 1506 | if (eth_spec->h_proto) |
| 1507 | spec_l2->eth.ether_type_enable = 1; |
| 1508 | break; |
| 1509 | case IP_USER_FLOW: |
| 1510 | err = add_ip_rule(priv, cmd, rule_list_h); |
| 1511 | break; |
| 1512 | case TCP_V4_FLOW: |
| 1513 | err = add_tcp_udp_rule(priv, cmd, rule_list_h, TCP_V4_FLOW); |
| 1514 | break; |
| 1515 | case UDP_V4_FLOW: |
| 1516 | err = add_tcp_udp_rule(priv, cmd, rule_list_h, UDP_V4_FLOW); |
| 1517 | break; |
| 1518 | } |
| 1519 | |
| 1520 | return err; |
| 1521 | } |
| 1522 | |
| 1523 | static int mlx4_en_flow_replace(struct net_device *dev, |
| 1524 | struct ethtool_rxnfc *cmd) |
| 1525 | { |
| 1526 | int err; |
| 1527 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1528 | struct ethtool_flow_id *loc_rule; |
| 1529 | struct mlx4_spec_list *spec, *tmp_spec; |
| 1530 | u32 qpn; |
| 1531 | u64 reg_id; |
| 1532 | |
| 1533 | struct mlx4_net_trans_rule rule = { |
| 1534 | .queue_mode = MLX4_NET_TRANS_Q_FIFO, |
| 1535 | .exclusive = 0, |
| 1536 | .allow_loopback = 1, |
Hadar Hen Zion | f916253 | 2013-04-24 13:58:45 +0000 | [diff] [blame] | 1537 | .promisc_mode = MLX4_FS_REGULAR, |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1538 | }; |
| 1539 | |
| 1540 | rule.port = priv->port; |
| 1541 | rule.priority = MLX4_DOMAIN_ETHTOOL | cmd->fs.location; |
| 1542 | INIT_LIST_HEAD(&rule.list); |
| 1543 | |
| 1544 | /* Allow direct QP attaches if the EN_ETHTOOL_QP_ATTACH flag is set */ |
| 1545 | if (cmd->fs.ring_cookie == RX_CLS_FLOW_DISC) |
Hadar Hen Zion | cabdc8ee | 2012-07-05 04:03:50 +0000 | [diff] [blame] | 1546 | qpn = priv->drop_qp.qpn; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1547 | else if (cmd->fs.ring_cookie & EN_ETHTOOL_QP_ATTACH) { |
| 1548 | qpn = cmd->fs.ring_cookie & (EN_ETHTOOL_QP_ATTACH - 1); |
| 1549 | } else { |
| 1550 | if (cmd->fs.ring_cookie >= priv->rx_ring_num) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1551 | en_warn(priv, "rxnfc: RX ring (%llu) doesn't exist\n", |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1552 | cmd->fs.ring_cookie); |
| 1553 | return -EINVAL; |
| 1554 | } |
| 1555 | qpn = priv->rss_map.qps[cmd->fs.ring_cookie].qpn; |
| 1556 | if (!qpn) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1557 | en_warn(priv, "rxnfc: RX ring (%llu) is inactive\n", |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1558 | cmd->fs.ring_cookie); |
| 1559 | return -EINVAL; |
| 1560 | } |
| 1561 | } |
| 1562 | rule.qpn = qpn; |
| 1563 | err = mlx4_en_ethtool_to_net_trans_rule(dev, cmd, &rule.list); |
| 1564 | if (err) |
| 1565 | goto out_free_list; |
| 1566 | |
| 1567 | loc_rule = &priv->ethtool_rules[cmd->fs.location]; |
| 1568 | if (loc_rule->id) { |
| 1569 | err = mlx4_flow_detach(priv->mdev->dev, loc_rule->id); |
| 1570 | if (err) { |
| 1571 | en_err(priv, "Fail to detach network rule at location %d. registration id = %llx\n", |
| 1572 | cmd->fs.location, loc_rule->id); |
| 1573 | goto out_free_list; |
| 1574 | } |
| 1575 | loc_rule->id = 0; |
| 1576 | memset(&loc_rule->flow_spec, 0, |
| 1577 | sizeof(struct ethtool_rx_flow_spec)); |
Hadar Hen Zion | 0d256c0 | 2013-01-30 23:07:08 +0000 | [diff] [blame] | 1578 | list_del(&loc_rule->list); |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1579 | } |
| 1580 | err = mlx4_flow_attach(priv->mdev->dev, &rule, ®_id); |
| 1581 | if (err) { |
Joe Perches | 1a91de2 | 2014-05-07 12:52:57 -0700 | [diff] [blame] | 1582 | en_err(priv, "Fail to attach network rule at location %d\n", |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1583 | cmd->fs.location); |
| 1584 | goto out_free_list; |
| 1585 | } |
| 1586 | loc_rule->id = reg_id; |
| 1587 | memcpy(&loc_rule->flow_spec, &cmd->fs, |
| 1588 | sizeof(struct ethtool_rx_flow_spec)); |
Hadar Hen Zion | 0d256c0 | 2013-01-30 23:07:08 +0000 | [diff] [blame] | 1589 | list_add_tail(&loc_rule->list, &priv->ethtool_list); |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1590 | |
| 1591 | out_free_list: |
| 1592 | list_for_each_entry_safe(spec, tmp_spec, &rule.list, list) { |
| 1593 | list_del(&spec->list); |
| 1594 | kfree(spec); |
| 1595 | } |
| 1596 | return err; |
| 1597 | } |
| 1598 | |
| 1599 | static int mlx4_en_flow_detach(struct net_device *dev, |
| 1600 | struct ethtool_rxnfc *cmd) |
| 1601 | { |
| 1602 | int err = 0; |
| 1603 | struct ethtool_flow_id *rule; |
| 1604 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1605 | |
| 1606 | if (cmd->fs.location >= MAX_NUM_OF_FS_RULES) |
| 1607 | return -EINVAL; |
| 1608 | |
| 1609 | rule = &priv->ethtool_rules[cmd->fs.location]; |
| 1610 | if (!rule->id) { |
| 1611 | err = -ENOENT; |
| 1612 | goto out; |
| 1613 | } |
| 1614 | |
| 1615 | err = mlx4_flow_detach(priv->mdev->dev, rule->id); |
| 1616 | if (err) { |
| 1617 | en_err(priv, "Fail to detach network rule at location %d. registration id = 0x%llx\n", |
| 1618 | cmd->fs.location, rule->id); |
| 1619 | goto out; |
| 1620 | } |
| 1621 | rule->id = 0; |
| 1622 | memset(&rule->flow_spec, 0, sizeof(struct ethtool_rx_flow_spec)); |
Hadar Hen Zion | 0d256c0 | 2013-01-30 23:07:08 +0000 | [diff] [blame] | 1623 | list_del(&rule->list); |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1624 | out: |
| 1625 | return err; |
| 1626 | |
| 1627 | } |
| 1628 | |
| 1629 | static int mlx4_en_get_flow(struct net_device *dev, struct ethtool_rxnfc *cmd, |
| 1630 | int loc) |
| 1631 | { |
| 1632 | int err = 0; |
| 1633 | struct ethtool_flow_id *rule; |
| 1634 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1635 | |
| 1636 | if (loc < 0 || loc >= MAX_NUM_OF_FS_RULES) |
| 1637 | return -EINVAL; |
| 1638 | |
| 1639 | rule = &priv->ethtool_rules[loc]; |
| 1640 | if (rule->id) |
| 1641 | memcpy(&cmd->fs, &rule->flow_spec, |
| 1642 | sizeof(struct ethtool_rx_flow_spec)); |
| 1643 | else |
| 1644 | err = -ENOENT; |
| 1645 | |
| 1646 | return err; |
| 1647 | } |
| 1648 | |
| 1649 | static int mlx4_en_get_num_flows(struct mlx4_en_priv *priv) |
| 1650 | { |
| 1651 | |
| 1652 | int i, res = 0; |
| 1653 | for (i = 0; i < MAX_NUM_OF_FS_RULES; i++) { |
| 1654 | if (priv->ethtool_rules[i].id) |
| 1655 | res++; |
| 1656 | } |
| 1657 | return res; |
| 1658 | |
| 1659 | } |
| 1660 | |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1661 | static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, |
| 1662 | u32 *rule_locs) |
| 1663 | { |
| 1664 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1665 | struct mlx4_en_dev *mdev = priv->mdev; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1666 | int err = 0; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1667 | int i = 0, priority = 0; |
| 1668 | |
| 1669 | if ((cmd->cmd == ETHTOOL_GRXCLSRLCNT || |
| 1670 | cmd->cmd == ETHTOOL_GRXCLSRULE || |
| 1671 | cmd->cmd == ETHTOOL_GRXCLSRLALL) && |
Hadar Hen Zion | 280fce1 | 2013-01-30 23:07:07 +0000 | [diff] [blame] | 1672 | (mdev->dev->caps.steering_mode != |
| 1673 | MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up)) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1674 | return -EINVAL; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1675 | |
| 1676 | switch (cmd->cmd) { |
| 1677 | case ETHTOOL_GRXRINGS: |
| 1678 | cmd->data = priv->rx_ring_num; |
| 1679 | break; |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1680 | case ETHTOOL_GRXCLSRLCNT: |
| 1681 | cmd->rule_cnt = mlx4_en_get_num_flows(priv); |
| 1682 | break; |
| 1683 | case ETHTOOL_GRXCLSRULE: |
| 1684 | err = mlx4_en_get_flow(dev, cmd, cmd->fs.location); |
| 1685 | break; |
| 1686 | case ETHTOOL_GRXCLSRLALL: |
| 1687 | while ((!err || err == -ENOENT) && priority < cmd->rule_cnt) { |
| 1688 | err = mlx4_en_get_flow(dev, cmd, i); |
| 1689 | if (!err) |
| 1690 | rule_locs[priority++] = i; |
| 1691 | i++; |
| 1692 | } |
| 1693 | err = 0; |
| 1694 | break; |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 1695 | default: |
| 1696 | err = -EOPNOTSUPP; |
| 1697 | break; |
| 1698 | } |
| 1699 | |
| 1700 | return err; |
| 1701 | } |
| 1702 | |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1703 | static int mlx4_en_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd) |
| 1704 | { |
| 1705 | int err = 0; |
| 1706 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1707 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1708 | |
Hadar Hen Zion | 280fce1 | 2013-01-30 23:07:07 +0000 | [diff] [blame] | 1709 | if (mdev->dev->caps.steering_mode != |
| 1710 | MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up) |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 1711 | return -EINVAL; |
| 1712 | |
| 1713 | switch (cmd->cmd) { |
| 1714 | case ETHTOOL_SRXCLSRLINS: |
| 1715 | err = mlx4_en_flow_replace(dev, cmd); |
| 1716 | break; |
| 1717 | case ETHTOOL_SRXCLSRLDEL: |
| 1718 | err = mlx4_en_flow_detach(dev, cmd); |
| 1719 | break; |
| 1720 | default: |
| 1721 | en_warn(priv, "Unsupported ethtool command. (%d)\n", cmd->cmd); |
| 1722 | return -EINVAL; |
| 1723 | } |
| 1724 | |
| 1725 | return err; |
| 1726 | } |
| 1727 | |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1728 | static void mlx4_en_get_channels(struct net_device *dev, |
| 1729 | struct ethtool_channels *channel) |
| 1730 | { |
| 1731 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1732 | |
| 1733 | memset(channel, 0, sizeof(*channel)); |
| 1734 | |
| 1735 | channel->max_rx = MAX_RX_RINGS; |
| 1736 | channel->max_tx = MLX4_EN_MAX_TX_RING_P_UP; |
| 1737 | |
| 1738 | channel->rx_count = priv->rx_ring_num; |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1739 | channel->tx_count = priv->tx_ring_num[TX] / MLX4_EN_NUM_UP; |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | static int mlx4_en_set_channels(struct net_device *dev, |
| 1743 | struct ethtool_channels *channel) |
| 1744 | { |
| 1745 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1746 | struct mlx4_en_dev *mdev = priv->mdev; |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1747 | struct mlx4_en_port_profile new_prof; |
| 1748 | struct mlx4_en_priv *tmp; |
Christian Engelmayer | da26a62 | 2014-05-17 23:52:03 +0200 | [diff] [blame] | 1749 | int port_up = 0; |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1750 | int xdp_count; |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1751 | int err = 0; |
| 1752 | |
| 1753 | if (channel->other_count || channel->combined_count || |
| 1754 | channel->tx_count > MLX4_EN_MAX_TX_RING_P_UP || |
| 1755 | channel->rx_count > MAX_RX_RINGS || |
| 1756 | !channel->tx_count || !channel->rx_count) |
| 1757 | return -EINVAL; |
| 1758 | |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1759 | tmp = kzalloc(sizeof(*tmp), GFP_KERNEL); |
| 1760 | if (!tmp) |
| 1761 | return -ENOMEM; |
| 1762 | |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1763 | mutex_lock(&mdev->state_lock); |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1764 | xdp_count = priv->tx_ring_num[TX_XDP] ? channel->rx_count : 0; |
| 1765 | if (channel->tx_count * MLX4_EN_NUM_UP + xdp_count > MAX_TX_RINGS) { |
| 1766 | err = -EINVAL; |
| 1767 | en_err(priv, |
| 1768 | "Total number of TX and XDP rings (%d) exceeds the maximum supported (%d)\n", |
| 1769 | channel->tx_count * MLX4_EN_NUM_UP + xdp_count, |
| 1770 | MAX_TX_RINGS); |
| 1771 | goto out; |
| 1772 | } |
| 1773 | |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1774 | memcpy(&new_prof, priv->prof, sizeof(struct mlx4_en_port_profile)); |
| 1775 | new_prof.num_tx_rings_p_up = channel->tx_count; |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1776 | new_prof.tx_ring_num[TX] = channel->tx_count * MLX4_EN_NUM_UP; |
| 1777 | new_prof.tx_ring_num[TX_XDP] = xdp_count; |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1778 | new_prof.rx_ring_num = channel->rx_count; |
| 1779 | |
| 1780 | err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof); |
| 1781 | if (err) |
| 1782 | goto out; |
| 1783 | |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1784 | if (priv->port_up) { |
| 1785 | port_up = 1; |
Amir Vadai | 3484aac | 2013-01-30 23:07:11 +0000 | [diff] [blame] | 1786 | mlx4_en_stop_port(dev, 1); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Eugenia Emantayev | ec25bc0 | 2016-07-18 18:35:12 +0300 | [diff] [blame] | 1789 | mlx4_en_safe_replace_resources(priv, tmp); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1790 | |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1791 | netif_set_real_num_tx_queues(dev, priv->tx_ring_num[TX]); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1792 | netif_set_real_num_rx_queues(dev, priv->rx_ring_num); |
| 1793 | |
Ido Shamay | f5b6345 | 2014-05-14 12:15:11 +0300 | [diff] [blame] | 1794 | if (dev->num_tc) |
| 1795 | mlx4_en_setup_tc(dev, MLX4_EN_NUM_UP); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1796 | |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1797 | en_warn(priv, "Using %d TX rings\n", priv->tx_ring_num[TX]); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1798 | en_warn(priv, "Using %d RX rings\n", priv->rx_ring_num); |
| 1799 | |
| 1800 | if (port_up) { |
| 1801 | err = mlx4_en_start_port(dev); |
| 1802 | if (err) |
| 1803 | en_err(priv, "Failed starting port\n"); |
| 1804 | } |
| 1805 | |
| 1806 | err = mlx4_en_moderation_update(priv); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1807 | out: |
| 1808 | mutex_unlock(&mdev->state_lock); |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1809 | kfree(tmp); |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 1810 | return err; |
| 1811 | } |
| 1812 | |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 1813 | static int mlx4_en_get_ts_info(struct net_device *dev, |
| 1814 | struct ethtool_ts_info *info) |
| 1815 | { |
| 1816 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1817 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1818 | int ret; |
| 1819 | |
| 1820 | ret = ethtool_op_get_ts_info(dev, info); |
| 1821 | if (ret) |
| 1822 | return ret; |
| 1823 | |
| 1824 | if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) { |
| 1825 | info->so_timestamping |= |
| 1826 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 1827 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1828 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 1829 | |
| 1830 | info->tx_types = |
| 1831 | (1 << HWTSTAMP_TX_OFF) | |
| 1832 | (1 << HWTSTAMP_TX_ON); |
| 1833 | |
| 1834 | info->rx_filters = |
| 1835 | (1 << HWTSTAMP_FILTER_NONE) | |
| 1836 | (1 << HWTSTAMP_FILTER_ALL); |
Shawn Bohrer | ad7d4ea | 2013-12-31 11:39:39 -0600 | [diff] [blame] | 1837 | |
| 1838 | if (mdev->ptp_clock) |
| 1839 | info->phc_index = ptp_clock_index(mdev->ptp_clock); |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | return ret; |
| 1843 | } |
| 1844 | |
Fengguang Wu | 3f6148e | 2014-07-24 09:11:46 +0300 | [diff] [blame] | 1845 | static int mlx4_en_set_priv_flags(struct net_device *dev, u32 flags) |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1846 | { |
| 1847 | struct mlx4_en_priv *priv = netdev_priv(dev); |
Hadar Hen Zion | e38af4f | 2015-07-27 14:46:34 +0300 | [diff] [blame] | 1848 | struct mlx4_en_dev *mdev = priv->mdev; |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1849 | bool bf_enabled_new = !!(flags & MLX4_EN_PRIV_FLAGS_BLUEFLAME); |
| 1850 | bool bf_enabled_old = !!(priv->pflags & MLX4_EN_PRIV_FLAGS_BLUEFLAME); |
Hadar Hen Zion | e38af4f | 2015-07-27 14:46:34 +0300 | [diff] [blame] | 1851 | bool phv_enabled_new = !!(flags & MLX4_EN_PRIV_FLAGS_PHV); |
| 1852 | bool phv_enabled_old = !!(priv->pflags & MLX4_EN_PRIV_FLAGS_PHV); |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1853 | int i; |
Hadar Hen Zion | e38af4f | 2015-07-27 14:46:34 +0300 | [diff] [blame] | 1854 | int ret = 0; |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1855 | |
Hadar Hen Zion | 7c509a4 | 2015-07-27 14:46:32 +0300 | [diff] [blame] | 1856 | if (bf_enabled_new != bf_enabled_old) { |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1857 | int t; |
| 1858 | |
Hadar Hen Zion | 7c509a4 | 2015-07-27 14:46:32 +0300 | [diff] [blame] | 1859 | if (bf_enabled_new) { |
| 1860 | bool bf_supported = true; |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1861 | |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1862 | for (t = 0; t < MLX4_EN_NUM_TX_TYPES; t++) |
| 1863 | for (i = 0; i < priv->tx_ring_num[t]; i++) |
| 1864 | bf_supported &= |
| 1865 | priv->tx_ring[t][i]->bf_alloced; |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1866 | |
Hadar Hen Zion | 7c509a4 | 2015-07-27 14:46:32 +0300 | [diff] [blame] | 1867 | if (!bf_supported) { |
| 1868 | en_err(priv, "BlueFlame is not supported\n"); |
| 1869 | return -EINVAL; |
| 1870 | } |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1871 | |
Hadar Hen Zion | 7c509a4 | 2015-07-27 14:46:32 +0300 | [diff] [blame] | 1872 | priv->pflags |= MLX4_EN_PRIV_FLAGS_BLUEFLAME; |
| 1873 | } else { |
| 1874 | priv->pflags &= ~MLX4_EN_PRIV_FLAGS_BLUEFLAME; |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1875 | } |
| 1876 | |
Tariq Toukan | 67f8b1d | 2016-11-02 17:12:24 +0200 | [diff] [blame] | 1877 | for (t = 0; t < MLX4_EN_NUM_TX_TYPES; t++) |
| 1878 | for (i = 0; i < priv->tx_ring_num[t]; i++) |
| 1879 | priv->tx_ring[t][i]->bf_enabled = |
| 1880 | bf_enabled_new; |
Hadar Hen Zion | 7c509a4 | 2015-07-27 14:46:32 +0300 | [diff] [blame] | 1881 | |
| 1882 | en_info(priv, "BlueFlame %s\n", |
| 1883 | bf_enabled_new ? "Enabled" : "Disabled"); |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1884 | } |
| 1885 | |
Hadar Hen Zion | e38af4f | 2015-07-27 14:46:34 +0300 | [diff] [blame] | 1886 | if (phv_enabled_new != phv_enabled_old) { |
| 1887 | ret = set_phv_bit(mdev->dev, priv->port, (int)phv_enabled_new); |
| 1888 | if (ret) |
| 1889 | return ret; |
| 1890 | else if (phv_enabled_new) |
| 1891 | priv->pflags |= MLX4_EN_PRIV_FLAGS_PHV; |
| 1892 | else |
| 1893 | priv->pflags &= ~MLX4_EN_PRIV_FLAGS_PHV; |
| 1894 | en_info(priv, "PHV bit %s\n", |
| 1895 | phv_enabled_new ? "Enabled" : "Disabled"); |
| 1896 | } |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1897 | return 0; |
| 1898 | } |
| 1899 | |
Fengguang Wu | 3f6148e | 2014-07-24 09:11:46 +0300 | [diff] [blame] | 1900 | static u32 mlx4_en_get_priv_flags(struct net_device *dev) |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 1901 | { |
| 1902 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1903 | |
| 1904 | return priv->pflags; |
| 1905 | } |
| 1906 | |
Eric Dumazet | 1556b87 | 2014-10-05 12:35:22 +0300 | [diff] [blame] | 1907 | static int mlx4_en_get_tunable(struct net_device *dev, |
| 1908 | const struct ethtool_tunable *tuna, |
| 1909 | void *data) |
| 1910 | { |
| 1911 | const struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1912 | int ret = 0; |
| 1913 | |
| 1914 | switch (tuna->id) { |
| 1915 | case ETHTOOL_TX_COPYBREAK: |
| 1916 | *(u32 *)data = priv->prof->inline_thold; |
| 1917 | break; |
| 1918 | default: |
| 1919 | ret = -EINVAL; |
| 1920 | break; |
| 1921 | } |
| 1922 | |
| 1923 | return ret; |
| 1924 | } |
| 1925 | |
| 1926 | static int mlx4_en_set_tunable(struct net_device *dev, |
| 1927 | const struct ethtool_tunable *tuna, |
| 1928 | const void *data) |
| 1929 | { |
| 1930 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1931 | int val, ret = 0; |
| 1932 | |
| 1933 | switch (tuna->id) { |
| 1934 | case ETHTOOL_TX_COPYBREAK: |
| 1935 | val = *(u32 *)data; |
| 1936 | if (val < MIN_PKT_LEN || val > MAX_INLINE) |
| 1937 | ret = -EINVAL; |
| 1938 | else |
| 1939 | priv->prof->inline_thold = val; |
| 1940 | break; |
| 1941 | default: |
| 1942 | ret = -EINVAL; |
| 1943 | break; |
| 1944 | } |
| 1945 | |
| 1946 | return ret; |
| 1947 | } |
| 1948 | |
Saeed Mahameed | 7202da8 | 2014-10-27 11:37:36 +0200 | [diff] [blame] | 1949 | static int mlx4_en_get_module_info(struct net_device *dev, |
| 1950 | struct ethtool_modinfo *modinfo) |
| 1951 | { |
| 1952 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1953 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1954 | int ret; |
| 1955 | u8 data[4]; |
| 1956 | |
| 1957 | /* Read first 2 bytes to get Module & REV ID */ |
| 1958 | ret = mlx4_get_module_info(mdev->dev, priv->port, |
| 1959 | 0/*offset*/, 2/*size*/, data); |
| 1960 | if (ret < 2) |
| 1961 | return -EIO; |
| 1962 | |
| 1963 | switch (data[0] /* identifier */) { |
| 1964 | case MLX4_MODULE_ID_QSFP: |
| 1965 | modinfo->type = ETH_MODULE_SFF_8436; |
| 1966 | modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; |
| 1967 | break; |
| 1968 | case MLX4_MODULE_ID_QSFP_PLUS: |
| 1969 | if (data[1] >= 0x3) { /* revision id */ |
| 1970 | modinfo->type = ETH_MODULE_SFF_8636; |
| 1971 | modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; |
| 1972 | } else { |
| 1973 | modinfo->type = ETH_MODULE_SFF_8436; |
| 1974 | modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; |
| 1975 | } |
| 1976 | break; |
| 1977 | case MLX4_MODULE_ID_QSFP28: |
| 1978 | modinfo->type = ETH_MODULE_SFF_8636; |
| 1979 | modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN; |
| 1980 | break; |
| 1981 | case MLX4_MODULE_ID_SFP: |
| 1982 | modinfo->type = ETH_MODULE_SFF_8472; |
| 1983 | modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; |
| 1984 | break; |
| 1985 | default: |
| 1986 | return -ENOSYS; |
| 1987 | } |
| 1988 | |
| 1989 | return 0; |
| 1990 | } |
| 1991 | |
| 1992 | static int mlx4_en_get_module_eeprom(struct net_device *dev, |
| 1993 | struct ethtool_eeprom *ee, |
| 1994 | u8 *data) |
| 1995 | { |
| 1996 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 1997 | struct mlx4_en_dev *mdev = priv->mdev; |
| 1998 | int offset = ee->offset; |
| 1999 | int i = 0, ret; |
| 2000 | |
| 2001 | if (ee->len == 0) |
| 2002 | return -EINVAL; |
| 2003 | |
| 2004 | memset(data, 0, ee->len); |
| 2005 | |
| 2006 | while (i < ee->len) { |
| 2007 | en_dbg(DRV, priv, |
| 2008 | "mlx4_get_module_info i(%d) offset(%d) len(%d)\n", |
| 2009 | i, offset, ee->len - i); |
| 2010 | |
| 2011 | ret = mlx4_get_module_info(mdev->dev, priv->port, |
| 2012 | offset, ee->len - i, data + i); |
| 2013 | |
| 2014 | if (!ret) /* Done reading */ |
| 2015 | return 0; |
| 2016 | |
| 2017 | if (ret < 0) { |
| 2018 | en_err(priv, |
| 2019 | "mlx4_get_module_info i(%d) offset(%d) bytes_to_read(%d) - FAILED (0x%x)\n", |
| 2020 | i, offset, ee->len - i, ret); |
| 2021 | return 0; |
| 2022 | } |
| 2023 | |
| 2024 | i += ret; |
| 2025 | offset += ret; |
| 2026 | } |
| 2027 | return 0; |
| 2028 | } |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 2029 | |
Ido Shamay | 51af33c | 2015-04-02 16:31:20 +0300 | [diff] [blame] | 2030 | static int mlx4_en_set_phys_id(struct net_device *dev, |
| 2031 | enum ethtool_phys_id_state state) |
| 2032 | { |
| 2033 | int err; |
| 2034 | u16 beacon_duration; |
| 2035 | struct mlx4_en_priv *priv = netdev_priv(dev); |
| 2036 | struct mlx4_en_dev *mdev = priv->mdev; |
| 2037 | |
| 2038 | if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PORT_BEACON)) |
| 2039 | return -EOPNOTSUPP; |
| 2040 | |
| 2041 | switch (state) { |
| 2042 | case ETHTOOL_ID_ACTIVE: |
| 2043 | beacon_duration = PORT_BEACON_MAX_LIMIT; |
| 2044 | break; |
| 2045 | case ETHTOOL_ID_INACTIVE: |
| 2046 | beacon_duration = 0; |
| 2047 | break; |
| 2048 | default: |
| 2049 | return -EOPNOTSUPP; |
| 2050 | } |
| 2051 | |
| 2052 | err = mlx4_SET_PORT_BEACON(mdev->dev, priv->port, beacon_duration); |
| 2053 | return err; |
| 2054 | } |
| 2055 | |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2056 | const struct ethtool_ops mlx4_en_ethtool_ops = { |
| 2057 | .get_drvinfo = mlx4_en_get_drvinfo, |
David Decotigny | 3d8f7cc | 2016-02-24 10:58:12 -0800 | [diff] [blame] | 2058 | .get_link_ksettings = mlx4_en_get_link_ksettings, |
| 2059 | .set_link_ksettings = mlx4_en_set_link_ksettings, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2060 | .get_link = ethtool_op_get_link, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2061 | .get_strings = mlx4_en_get_strings, |
| 2062 | .get_sset_count = mlx4_en_get_sset_count, |
| 2063 | .get_ethtool_stats = mlx4_en_get_ethtool_stats, |
Yevgeny Petrilin | e7c1c2c4 | 2010-08-24 03:46:18 +0000 | [diff] [blame] | 2064 | .self_test = mlx4_en_self_test, |
Ido Shamay | 51af33c | 2015-04-02 16:31:20 +0300 | [diff] [blame] | 2065 | .set_phys_id = mlx4_en_set_phys_id, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2066 | .get_wol = mlx4_en_get_wol, |
Yevgeny Petrilin | 14c07b1 | 2011-03-22 22:37:59 +0000 | [diff] [blame] | 2067 | .set_wol = mlx4_en_set_wol, |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2068 | .get_msglevel = mlx4_en_get_msglevel, |
| 2069 | .set_msglevel = mlx4_en_set_msglevel, |
| 2070 | .get_coalesce = mlx4_en_get_coalesce, |
| 2071 | .set_coalesce = mlx4_en_set_coalesce, |
| 2072 | .get_pauseparam = mlx4_en_get_pauseparam, |
| 2073 | .set_pauseparam = mlx4_en_set_pauseparam, |
| 2074 | .get_ringparam = mlx4_en_get_ringparam, |
Yevgeny Petrilin | 18cc42a | 2008-12-29 18:39:20 -0800 | [diff] [blame] | 2075 | .set_ringparam = mlx4_en_set_ringparam, |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 2076 | .get_rxnfc = mlx4_en_get_rxnfc, |
Hadar Hen Zion | 8206728 | 2012-07-05 04:03:49 +0000 | [diff] [blame] | 2077 | .set_rxnfc = mlx4_en_set_rxnfc, |
Yevgeny Petrilin | 93d3e36 | 2012-01-17 22:54:55 +0000 | [diff] [blame] | 2078 | .get_rxfh_indir_size = mlx4_en_get_rxfh_indir_size, |
Eric Dumazet | b9d1ab7 | 2014-11-16 06:23:16 -0800 | [diff] [blame] | 2079 | .get_rxfh_key_size = mlx4_en_get_rxfh_key_size, |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 2080 | .get_rxfh = mlx4_en_get_rxfh, |
| 2081 | .set_rxfh = mlx4_en_set_rxfh, |
Amir Vadai | d317966 | 2012-12-02 03:49:23 +0000 | [diff] [blame] | 2082 | .get_channels = mlx4_en_get_channels, |
| 2083 | .set_channels = mlx4_en_set_channels, |
Amir Vadai | ec693d4 | 2013-04-23 06:06:49 +0000 | [diff] [blame] | 2084 | .get_ts_info = mlx4_en_get_ts_info, |
Amir Vadai | 0fef9d0 | 2014-07-22 15:44:10 +0300 | [diff] [blame] | 2085 | .set_priv_flags = mlx4_en_set_priv_flags, |
| 2086 | .get_priv_flags = mlx4_en_get_priv_flags, |
Eric Dumazet | 1556b87 | 2014-10-05 12:35:22 +0300 | [diff] [blame] | 2087 | .get_tunable = mlx4_en_get_tunable, |
| 2088 | .set_tunable = mlx4_en_set_tunable, |
Saeed Mahameed | 7202da8 | 2014-10-27 11:37:36 +0200 | [diff] [blame] | 2089 | .get_module_info = mlx4_en_get_module_info, |
| 2090 | .get_module_eeprom = mlx4_en_get_module_eeprom |
Yevgeny Petrilin | c27a02c | 2008-10-22 15:47:49 -0700 | [diff] [blame] | 2091 | }; |
| 2092 | |
| 2093 | |
| 2094 | |
| 2095 | |
| 2096 | |