blob: f69584a9b47fbef008a1ec138feba9f10504d997 [file] [log] [blame]
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001/*
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 Vadaiaf22d9d2012-07-18 22:33:49 +000037#include <linux/mlx4/driver.h>
Saeed Mahameed7202da82014-10-27 11:37:36 +020038#include <linux/mlx4/device.h>
Hadar Hen Zionf90a3672013-01-30 23:07:04 +000039#include <linux/in.h>
40#include <net/ip.h>
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +030041#include <linux/bitmap.h>
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070042
43#include "mlx4_en.h"
44#include "en_port.h"
45
Hadar Hen Zion82067282012-07-05 04:03:49 +000046#define EN_ETHTOOL_QP_ATTACH (1ull << 63)
Hadar Hen Zion82067282012-07-05 04:03:49 +000047#define EN_ETHTOOL_SHORT_MASK cpu_to_be16(0xffff)
48#define EN_ETHTOOL_WORD_MASK cpu_to_be32(0xffffffff)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070049
Amir Vadai79c54b62012-12-02 03:49:22 +000050static int mlx4_en_moderation_update(struct mlx4_en_priv *priv)
51{
52 int i;
53 int err = 0;
54
55 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +020056 priv->tx_cq[i]->moder_cnt = priv->tx_frames;
57 priv->tx_cq[i]->moder_time = priv->tx_usecs;
Eugenia Emantayev38463e22013-09-12 18:11:20 +030058 if (priv->port_up) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +020059 err = mlx4_en_set_cq_moder(priv, priv->tx_cq[i]);
Eugenia Emantayev38463e22013-09-12 18:11:20 +030060 if (err)
61 return err;
62 }
Amir Vadai79c54b62012-12-02 03:49:22 +000063 }
64
65 if (priv->adaptive_rx_coal)
66 return 0;
67
68 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +020069 priv->rx_cq[i]->moder_cnt = priv->rx_frames;
70 priv->rx_cq[i]->moder_time = priv->rx_usecs;
Amir Vadai79c54b62012-12-02 03:49:22 +000071 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
Eugenia Emantayev38463e22013-09-12 18:11:20 +030072 if (priv->port_up) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +020073 err = mlx4_en_set_cq_moder(priv, priv->rx_cq[i]);
Eugenia Emantayev38463e22013-09-12 18:11:20 +030074 if (err)
75 return err;
76 }
Amir Vadai79c54b62012-12-02 03:49:22 +000077 }
78
79 return err;
80}
81
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070082static void
83mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
84{
85 struct mlx4_en_priv *priv = netdev_priv(dev);
86 struct mlx4_en_dev *mdev = priv->mdev;
87
Rick Jones612a94d2011-11-14 08:13:25 +000088 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
89 strlcpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")",
90 sizeof(drvinfo->version));
91 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
92 "%d.%d.%d",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070093 (u16) (mdev->dev->caps.fw_ver >> 32),
94 (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
95 (u16) (mdev->dev->caps.fw_ver & 0xffff));
Yishai Hadas872bf2f2015-01-25 16:59:35 +020096 strlcpy(drvinfo->bus_info, pci_name(mdev->dev->persist->pdev),
Rick Jones612a94d2011-11-14 08:13:25 +000097 sizeof(drvinfo->bus_info));
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070098}
99
Amir Vadai0fef9d02014-07-22 15:44:10 +0300100static const char mlx4_en_priv_flags[][ETH_GSTRING_LEN] = {
101 "blueflame",
Hadar Hen Zione38af4f2015-07-27 14:46:34 +0300102 "phv-bit"
Amir Vadai0fef9d02014-07-22 15:44:10 +0300103};
104
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700105static const char main_strings[][ETH_GSTRING_LEN] = {
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300106 /* main statistics */
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700107 "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
108 "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
109 "rx_length_errors", "rx_over_errors", "rx_crc_errors",
110 "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
111 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
112 "tx_heartbeat_errors", "tx_window_errors",
113
114 /* port statistics */
Yevgeny Petrilinfa37a952010-08-24 03:46:46 +0000115 "tso_packets",
Eric Dumazet9fab4262014-10-02 08:24:21 -0700116 "xmit_more",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700117 "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
Shani Michaelif8c64552014-11-09 13:51:53 +0200118 "rx_csum_good", "rx_csum_none", "rx_csum_complete", "tx_chksum_offload",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700119
Eran Ben Elishab42de4d2015-06-15 17:59:06 +0300120 /* pf statistics */
121 "pf_rx_packets",
122 "pf_rx_bytes",
123 "pf_tx_packets",
124 "pf_tx_bytes",
125
Matan Barak0b131562015-03-30 17:45:25 +0300126 /* priority flow control statistics rx */
127 "rx_pause_prio_0", "rx_pause_duration_prio_0",
128 "rx_pause_transition_prio_0",
129 "rx_pause_prio_1", "rx_pause_duration_prio_1",
130 "rx_pause_transition_prio_1",
131 "rx_pause_prio_2", "rx_pause_duration_prio_2",
132 "rx_pause_transition_prio_2",
133 "rx_pause_prio_3", "rx_pause_duration_prio_3",
134 "rx_pause_transition_prio_3",
135 "rx_pause_prio_4", "rx_pause_duration_prio_4",
136 "rx_pause_transition_prio_4",
137 "rx_pause_prio_5", "rx_pause_duration_prio_5",
138 "rx_pause_transition_prio_5",
139 "rx_pause_prio_6", "rx_pause_duration_prio_6",
140 "rx_pause_transition_prio_6",
141 "rx_pause_prio_7", "rx_pause_duration_prio_7",
142 "rx_pause_transition_prio_7",
143
144 /* flow control statistics rx */
145 "rx_pause", "rx_pause_duration", "rx_pause_transition",
146
147 /* priority flow control statistics tx */
148 "tx_pause_prio_0", "tx_pause_duration_prio_0",
149 "tx_pause_transition_prio_0",
150 "tx_pause_prio_1", "tx_pause_duration_prio_1",
151 "tx_pause_transition_prio_1",
152 "tx_pause_prio_2", "tx_pause_duration_prio_2",
153 "tx_pause_transition_prio_2",
154 "tx_pause_prio_3", "tx_pause_duration_prio_3",
155 "tx_pause_transition_prio_3",
156 "tx_pause_prio_4", "tx_pause_duration_prio_4",
157 "tx_pause_transition_prio_4",
158 "tx_pause_prio_5", "tx_pause_duration_prio_5",
159 "tx_pause_transition_prio_5",
160 "tx_pause_prio_6", "tx_pause_duration_prio_6",
161 "tx_pause_transition_prio_6",
162 "tx_pause_prio_7", "tx_pause_duration_prio_7",
163 "tx_pause_transition_prio_7",
164
165 /* flow control statistics tx */
166 "tx_pause", "tx_pause_duration", "tx_pause_transition",
167
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700168 /* packet statistics */
Eran Ben Elishaa3333b32015-03-30 17:45:26 +0300169 "rx_multicast_packets",
170 "rx_broadcast_packets",
171 "rx_jabbers",
172 "rx_in_range_length_error",
173 "rx_out_range_length_error",
174 "tx_multicast_packets",
175 "tx_broadcast_packets",
176 "rx_prio_0_packets", "rx_prio_0_bytes",
177 "rx_prio_1_packets", "rx_prio_1_bytes",
178 "rx_prio_2_packets", "rx_prio_2_bytes",
179 "rx_prio_3_packets", "rx_prio_3_bytes",
180 "rx_prio_4_packets", "rx_prio_4_bytes",
181 "rx_prio_5_packets", "rx_prio_5_bytes",
182 "rx_prio_6_packets", "rx_prio_6_bytes",
183 "rx_prio_7_packets", "rx_prio_7_bytes",
184 "rx_novlan_packets", "rx_novlan_bytes",
185 "tx_prio_0_packets", "tx_prio_0_bytes",
186 "tx_prio_1_packets", "tx_prio_1_bytes",
187 "tx_prio_2_packets", "tx_prio_2_bytes",
188 "tx_prio_3_packets", "tx_prio_3_bytes",
189 "tx_prio_4_packets", "tx_prio_4_bytes",
190 "tx_prio_5_packets", "tx_prio_5_bytes",
191 "tx_prio_6_packets", "tx_prio_6_bytes",
192 "tx_prio_7_packets", "tx_prio_7_bytes",
193 "tx_novlan_packets", "tx_novlan_bytes",
194
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700195};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700196
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000197static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= {
Masanari Iidafd9071e2012-04-13 04:33:20 +0000198 "Interrupt Test",
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000199 "Link Test",
200 "Speed Test",
201 "Register Test",
202 "Loopback Test",
203};
204
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700205static u32 mlx4_en_get_msglevel(struct net_device *dev)
206{
207 return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
208}
209
210static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
211{
212 ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
213}
214
215static void mlx4_en_get_wol(struct net_device *netdev,
216 struct ethtool_wolinfo *wol)
217{
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000218 struct mlx4_en_priv *priv = netdev_priv(netdev);
219 int err = 0;
220 u64 config = 0;
Oren Duer559a9f12011-11-26 19:55:15 +0000221 u64 mask;
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000222
Oren Duer559a9f12011-11-26 19:55:15 +0000223 if ((priv->port < 1) || (priv->port > 2)) {
224 en_err(priv, "Failed to get WoL information\n");
225 return;
226 }
227
228 mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 :
229 MLX4_DEV_CAP_FLAG_WOL_PORT2;
230
231 if (!(priv->mdev->dev->caps.flags & mask)) {
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000232 wol->supported = 0;
233 wol->wolopts = 0;
234 return;
235 }
236
237 err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
238 if (err) {
239 en_err(priv, "Failed to get WoL information\n");
240 return;
241 }
242
243 if (config & MLX4_EN_WOL_MAGIC)
244 wol->supported = WAKE_MAGIC;
245 else
246 wol->supported = 0;
247
248 if (config & MLX4_EN_WOL_ENABLED)
249 wol->wolopts = WAKE_MAGIC;
250 else
251 wol->wolopts = 0;
252}
253
254static int mlx4_en_set_wol(struct net_device *netdev,
255 struct ethtool_wolinfo *wol)
256{
257 struct mlx4_en_priv *priv = netdev_priv(netdev);
258 u64 config = 0;
259 int err = 0;
Oren Duer559a9f12011-11-26 19:55:15 +0000260 u64 mask;
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000261
Oren Duer559a9f12011-11-26 19:55:15 +0000262 if ((priv->port < 1) || (priv->port > 2))
263 return -EOPNOTSUPP;
264
265 mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 :
266 MLX4_DEV_CAP_FLAG_WOL_PORT2;
267
268 if (!(priv->mdev->dev->caps.flags & mask))
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000269 return -EOPNOTSUPP;
270
271 if (wol->supported & ~WAKE_MAGIC)
272 return -EINVAL;
273
274 err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
275 if (err) {
276 en_err(priv, "Failed to get WoL info, unable to modify\n");
277 return err;
278 }
279
280 if (wol->wolopts & WAKE_MAGIC) {
281 config |= MLX4_EN_WOL_DO_MODIFY | MLX4_EN_WOL_ENABLED |
282 MLX4_EN_WOL_MAGIC;
283 } else {
284 config &= ~(MLX4_EN_WOL_ENABLED | MLX4_EN_WOL_MAGIC);
285 config |= MLX4_EN_WOL_DO_MODIFY;
286 }
287
288 err = mlx4_wol_write(priv->mdev->dev, config, priv->port);
289 if (err)
290 en_err(priv, "Failed to set WoL information\n");
291
292 return err;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700293}
294
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300295struct bitmap_iterator {
296 unsigned long *stats_bitmap;
297 unsigned int count;
298 unsigned int iterator;
299 bool advance_array; /* if set, force no increments */
300};
301
302static inline void bitmap_iterator_init(struct bitmap_iterator *h,
303 unsigned long *stats_bitmap,
304 int count)
305{
306 h->iterator = 0;
307 h->advance_array = !bitmap_empty(stats_bitmap, count);
308 h->count = h->advance_array ? bitmap_weight(stats_bitmap, count)
309 : count;
310 h->stats_bitmap = stats_bitmap;
311}
312
313static inline int bitmap_iterator_test(struct bitmap_iterator *h)
314{
315 return !h->advance_array ? 1 : test_bit(h->iterator, h->stats_bitmap);
316}
317
318static inline int bitmap_iterator_inc(struct bitmap_iterator *h)
319{
320 return h->iterator++;
321}
322
323static inline unsigned int
324bitmap_iterator_count(struct bitmap_iterator *h)
325{
326 return h->count;
327}
328
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700329static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
330{
331 struct mlx4_en_priv *priv = netdev_priv(dev);
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300332 struct bitmap_iterator it;
333
Eran Ben Elisha3da8a362015-03-30 17:45:24 +0300334 bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700335
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000336 switch (sset) {
337 case ETH_SS_STATS:
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300338 return bitmap_iterator_count(&it) +
Amir Vadai85018412013-06-18 16:18:28 +0300339 (priv->tx_ring_num * 2) +
Amir Vadai85018412013-06-18 16:18:28 +0300340 (priv->rx_ring_num * 2);
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000341 case ETH_SS_TEST:
Or Gerlitzccf86322011-07-07 19:19:29 +0000342 return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags
343 & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2;
Amir Vadai0fef9d02014-07-22 15:44:10 +0300344 case ETH_SS_PRIV_FLAGS:
345 return ARRAY_SIZE(mlx4_en_priv_flags);
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000346 default:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700347 return -EOPNOTSUPP;
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000348 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700349}
350
351static void mlx4_en_get_ethtool_stats(struct net_device *dev,
352 struct ethtool_stats *stats, uint64_t *data)
353{
354 struct mlx4_en_priv *priv = netdev_priv(dev);
355 int index = 0;
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300356 int i;
357 struct bitmap_iterator it;
358
Eran Ben Elisha3da8a362015-03-30 17:45:24 +0300359 bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700360
361 spin_lock_bh(&priv->stats_lock);
362
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300363 for (i = 0; i < NUM_MAIN_STATS; i++, bitmap_iterator_inc(&it))
364 if (bitmap_iterator_test(&it))
365 data[index++] = ((unsigned long *)&priv->stats)[i];
366
367 for (i = 0; i < NUM_PORT_STATS; i++, bitmap_iterator_inc(&it))
368 if (bitmap_iterator_test(&it))
369 data[index++] = ((unsigned long *)&priv->port_stats)[i];
370
Eran Ben Elishab42de4d2015-06-15 17:59:06 +0300371 for (i = 0; i < NUM_PF_STATS; i++, bitmap_iterator_inc(&it))
372 if (bitmap_iterator_test(&it))
373 data[index++] =
374 ((unsigned long *)&priv->pf_stats)[i];
375
Matan Barak0b131562015-03-30 17:45:25 +0300376 for (i = 0; i < NUM_FLOW_PRIORITY_STATS_RX;
377 i++, bitmap_iterator_inc(&it))
378 if (bitmap_iterator_test(&it))
379 data[index++] =
380 ((u64 *)&priv->rx_priority_flowstats)[i];
381
382 for (i = 0; i < NUM_FLOW_STATS_RX; i++, bitmap_iterator_inc(&it))
383 if (bitmap_iterator_test(&it))
384 data[index++] = ((u64 *)&priv->rx_flowstats)[i];
385
386 for (i = 0; i < NUM_FLOW_PRIORITY_STATS_TX;
387 i++, bitmap_iterator_inc(&it))
388 if (bitmap_iterator_test(&it))
389 data[index++] =
390 ((u64 *)&priv->tx_priority_flowstats)[i];
391
392 for (i = 0; i < NUM_FLOW_STATS_TX; i++, bitmap_iterator_inc(&it))
393 if (bitmap_iterator_test(&it))
394 data[index++] = ((u64 *)&priv->tx_flowstats)[i];
395
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300396 for (i = 0; i < NUM_PKT_STATS; i++, bitmap_iterator_inc(&it))
397 if (bitmap_iterator_test(&it))
398 data[index++] = ((unsigned long *)&priv->pkstats)[i];
399
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700400 for (i = 0; i < priv->tx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +0200401 data[index++] = priv->tx_ring[i]->packets;
402 data[index++] = priv->tx_ring[i]->bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700403 }
404 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +0200405 data[index++] = priv->rx_ring[i]->packets;
406 data[index++] = priv->rx_ring[i]->bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700407 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700408 spin_unlock_bh(&priv->stats_lock);
409
410}
411
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000412static void mlx4_en_self_test(struct net_device *dev,
413 struct ethtool_test *etest, u64 *buf)
414{
415 mlx4_en_ex_selftest(dev, &etest->flags, buf);
416}
417
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700418static void mlx4_en_get_strings(struct net_device *dev,
419 uint32_t stringset, uint8_t *data)
420{
421 struct mlx4_en_priv *priv = netdev_priv(dev);
422 int index = 0;
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300423 int i, strings = 0;
424 struct bitmap_iterator it;
425
Eran Ben Elisha3da8a362015-03-30 17:45:24 +0300426 bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700427
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000428 switch (stringset) {
429 case ETH_SS_TEST:
430 for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++)
431 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
Or Gerlitzccf86322011-07-07 19:19:29 +0000432 if (priv->mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UC_LOOPBACK)
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000433 for (; i < MLX4_EN_NUM_SELF_TEST; i++)
434 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
435 break;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700436
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000437 case ETH_SS_STATS:
438 /* Add main counters */
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300439 for (i = 0; i < NUM_MAIN_STATS; i++, strings++,
440 bitmap_iterator_inc(&it))
441 if (bitmap_iterator_test(&it))
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000442 strcpy(data + (index++) * ETH_GSTRING_LEN,
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300443 main_strings[strings]);
444
445 for (i = 0; i < NUM_PORT_STATS; i++, strings++,
446 bitmap_iterator_inc(&it))
447 if (bitmap_iterator_test(&it))
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000448 strcpy(data + (index++) * ETH_GSTRING_LEN,
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300449 main_strings[strings]);
450
Eran Ben Elishab42de4d2015-06-15 17:59:06 +0300451 for (i = 0; i < NUM_PF_STATS; i++, strings++,
452 bitmap_iterator_inc(&it))
453 if (bitmap_iterator_test(&it))
454 strcpy(data + (index++) * ETH_GSTRING_LEN,
455 main_strings[strings]);
456
Matan Barak0b131562015-03-30 17:45:25 +0300457 for (i = 0; i < NUM_FLOW_STATS; i++, strings++,
458 bitmap_iterator_inc(&it))
459 if (bitmap_iterator_test(&it))
460 strcpy(data + (index++) * ETH_GSTRING_LEN,
461 main_strings[strings]);
462
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300463 for (i = 0; i < NUM_PKT_STATS; i++, strings++,
464 bitmap_iterator_inc(&it))
465 if (bitmap_iterator_test(&it))
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000466 strcpy(data + (index++) * ETH_GSTRING_LEN,
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300467 main_strings[strings]);
468
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000469 for (i = 0; i < priv->tx_ring_num; i++) {
470 sprintf(data + (index++) * ETH_GSTRING_LEN,
471 "tx%d_packets", i);
472 sprintf(data + (index++) * ETH_GSTRING_LEN,
473 "tx%d_bytes", i);
474 }
475 for (i = 0; i < priv->rx_ring_num; i++) {
476 sprintf(data + (index++) * ETH_GSTRING_LEN,
477 "rx%d_packets", i);
478 sprintf(data + (index++) * ETH_GSTRING_LEN,
479 "rx%d_bytes", i);
480 }
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000481 break;
Amir Vadai0fef9d02014-07-22 15:44:10 +0300482 case ETH_SS_PRIV_FLAGS:
483 for (i = 0; i < ARRAY_SIZE(mlx4_en_priv_flags); i++)
484 strcpy(data + i * ETH_GSTRING_LEN,
485 mlx4_en_priv_flags[i]);
486 break;
487
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000488 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700489}
490
Saeed Mahameed2c762672014-10-27 11:37:40 +0200491static u32 mlx4_en_autoneg_get(struct net_device *dev)
492{
493 struct mlx4_en_priv *priv = netdev_priv(dev);
494 struct mlx4_en_dev *mdev = priv->mdev;
495 u32 autoneg = AUTONEG_DISABLE;
496
497 if ((mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_BACKPL_AN_REP) &&
498 (priv->port_state.flags & MLX4_EN_PORT_ANE))
499 autoneg = AUTONEG_ENABLE;
500
501 return autoneg;
502}
503
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800504static void ptys2ethtool_update_supported_port(unsigned long *mask,
505 struct mlx4_ptys_reg *ptys_reg)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200506{
507 u32 eth_proto = be32_to_cpu(ptys_reg->eth_proto_cap);
508
509 if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_T)
510 | MLX4_PROT_MASK(MLX4_1000BASE_T)
511 | MLX4_PROT_MASK(MLX4_100BASE_TX))) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800512 __set_bit(ETHTOOL_LINK_MODE_TP_BIT, mask);
513 } else if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_CR)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200514 | MLX4_PROT_MASK(MLX4_10GBASE_SR)
515 | MLX4_PROT_MASK(MLX4_56GBASE_SR4)
516 | MLX4_PROT_MASK(MLX4_40GBASE_CR4)
517 | MLX4_PROT_MASK(MLX4_40GBASE_SR4)
518 | MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII))) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800519 __set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, mask);
520 } else if (eth_proto & (MLX4_PROT_MASK(MLX4_56GBASE_KR4)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200521 | MLX4_PROT_MASK(MLX4_40GBASE_KR4)
522 | MLX4_PROT_MASK(MLX4_20GBASE_KR2)
523 | MLX4_PROT_MASK(MLX4_10GBASE_KR)
524 | MLX4_PROT_MASK(MLX4_10GBASE_KX4)
525 | MLX4_PROT_MASK(MLX4_1000BASE_KX))) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800526 __set_bit(ETHTOOL_LINK_MODE_Backplane_BIT, mask);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200527 }
Saeed Mahameed2c762672014-10-27 11:37:40 +0200528}
529
530static u32 ptys_get_active_port(struct mlx4_ptys_reg *ptys_reg)
531{
532 u32 eth_proto = be32_to_cpu(ptys_reg->eth_proto_oper);
533
534 if (!eth_proto) /* link down */
535 eth_proto = be32_to_cpu(ptys_reg->eth_proto_cap);
536
537 if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_T)
538 | MLX4_PROT_MASK(MLX4_1000BASE_T)
539 | MLX4_PROT_MASK(MLX4_100BASE_TX))) {
540 return PORT_TP;
541 }
542
543 if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_SR)
544 | MLX4_PROT_MASK(MLX4_56GBASE_SR4)
545 | MLX4_PROT_MASK(MLX4_40GBASE_SR4)
546 | MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII))) {
547 return PORT_FIBRE;
548 }
549
550 if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_CR)
551 | MLX4_PROT_MASK(MLX4_56GBASE_CR4)
552 | MLX4_PROT_MASK(MLX4_40GBASE_CR4))) {
553 return PORT_DA;
554 }
555
556 if (eth_proto & (MLX4_PROT_MASK(MLX4_56GBASE_KR4)
557 | MLX4_PROT_MASK(MLX4_40GBASE_KR4)
558 | MLX4_PROT_MASK(MLX4_20GBASE_KR2)
559 | MLX4_PROT_MASK(MLX4_10GBASE_KR)
560 | MLX4_PROT_MASK(MLX4_10GBASE_KX4)
561 | MLX4_PROT_MASK(MLX4_1000BASE_KX))) {
562 return PORT_NONE;
563 }
564 return PORT_OTHER;
565}
566
567#define MLX4_LINK_MODES_SZ \
568 (FIELD_SIZEOF(struct mlx4_ptys_reg, eth_proto_cap) * 8)
569
570enum ethtool_report {
571 SUPPORTED = 0,
572 ADVERTISED = 1,
Saeed Mahameed2c762672014-10-27 11:37:40 +0200573};
574
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800575struct ptys2ethtool_config {
576 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
577 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertised);
578 u32 speed;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200579};
580
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800581static unsigned long *ptys2ethtool_link_mode(struct ptys2ethtool_config *cfg,
582 enum ethtool_report report)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200583{
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800584 switch (report) {
585 case SUPPORTED:
586 return cfg->supported;
587 case ADVERTISED:
588 return cfg->advertised;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200589 }
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800590 return NULL;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200591}
592
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800593#define MLX4_BUILD_PTYS2ETHTOOL_CONFIG(reg_, speed_, ...) \
594 ({ \
595 struct ptys2ethtool_config *cfg; \
596 const unsigned int modes[] = { __VA_ARGS__ }; \
597 unsigned int i; \
598 cfg = &ptys2ethtool_map[reg_]; \
599 cfg->speed = speed_; \
600 bitmap_zero(cfg->supported, \
601 __ETHTOOL_LINK_MODE_MASK_NBITS); \
602 bitmap_zero(cfg->advertised, \
603 __ETHTOOL_LINK_MODE_MASK_NBITS); \
604 for (i = 0 ; i < ARRAY_SIZE(modes) ; ++i) { \
605 __set_bit(modes[i], cfg->supported); \
606 __set_bit(modes[i], cfg->advertised); \
607 } \
608 })
609
610/* Translates mlx4 link mode to equivalent ethtool Link modes/speed */
611static struct ptys2ethtool_config ptys2ethtool_map[MLX4_LINK_MODES_SZ];
612
613void __init mlx4_en_init_ptys2ethtool_map(void)
614{
615 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_100BASE_TX, SPEED_100,
616 ETHTOOL_LINK_MODE_100baseT_Full_BIT);
617 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_T, SPEED_1000,
618 ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
619 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_CX_SGMII, SPEED_1000,
620 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT);
621 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_KX, SPEED_1000,
622 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT);
623 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_T, SPEED_10000,
624 ETHTOOL_LINK_MODE_10000baseT_Full_BIT);
625 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CX4, SPEED_10000,
626 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT);
627 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KX4, SPEED_10000,
628 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT);
629 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KR, SPEED_10000,
630 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
631 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CR, SPEED_10000,
632 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
633 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_SR, SPEED_10000,
634 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
635 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_20GBASE_KR2, SPEED_20000,
636 ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT,
637 ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT);
638 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_CR4, SPEED_40000,
639 ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT);
640 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_KR4, SPEED_40000,
641 ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT);
642 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_SR4, SPEED_40000,
643 ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT);
644 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_KR4, SPEED_56000,
645 ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT);
646 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_CR4, SPEED_56000,
647 ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT);
648 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_SR4, SPEED_56000,
649 ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT);
650};
651
652static void ptys2ethtool_update_link_modes(unsigned long *link_modes,
653 u32 eth_proto,
654 enum ethtool_report report)
655{
656 int i;
657 for (i = 0; i < MLX4_LINK_MODES_SZ; i++) {
658 if (eth_proto & MLX4_PROT_MASK(i))
659 bitmap_or(link_modes, link_modes,
660 ptys2ethtool_link_mode(&ptys2ethtool_map[i],
661 report),
662 __ETHTOOL_LINK_MODE_MASK_NBITS);
663 }
664}
665
666static u32 ethtool2ptys_link_modes(const unsigned long *link_modes,
667 enum ethtool_report report)
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200668{
669 int i;
670 u32 ptys_modes = 0;
671
672 for (i = 0; i < MLX4_LINK_MODES_SZ; i++) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800673 if (bitmap_intersects(
674 ptys2ethtool_link_mode(&ptys2ethtool_map[i],
675 report),
676 link_modes,
677 __ETHTOOL_LINK_MODE_MASK_NBITS))
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200678 ptys_modes |= 1 << i;
679 }
680 return ptys_modes;
681}
682
683/* Convert actual speed (SPEED_XXX) to ptys link modes */
684static u32 speed2ptys_link_modes(u32 speed)
685{
686 int i;
687 u32 ptys_modes = 0;
688
689 for (i = 0; i < MLX4_LINK_MODES_SZ; i++) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800690 if (ptys2ethtool_map[i].speed == speed)
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200691 ptys_modes |= 1 << i;
692 }
693 return ptys_modes;
694}
695
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800696static int
697ethtool_get_ptys_link_ksettings(struct net_device *dev,
698 struct ethtool_link_ksettings *link_ksettings)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200699{
700 struct mlx4_en_priv *priv = netdev_priv(dev);
701 struct mlx4_ptys_reg ptys_reg;
702 u32 eth_proto;
703 int ret;
704
705 memset(&ptys_reg, 0, sizeof(ptys_reg));
706 ptys_reg.local_port = priv->port;
707 ptys_reg.proto_mask = MLX4_PTYS_EN;
708 ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev,
709 MLX4_ACCESS_REG_QUERY, &ptys_reg);
710 if (ret) {
711 en_warn(priv, "Failed to run mlx4_ACCESS_PTYS_REG status(%x)",
712 ret);
713 return ret;
714 }
715 en_dbg(DRV, priv, "ptys_reg.proto_mask %x\n",
716 ptys_reg.proto_mask);
717 en_dbg(DRV, priv, "ptys_reg.eth_proto_cap %x\n",
718 be32_to_cpu(ptys_reg.eth_proto_cap));
719 en_dbg(DRV, priv, "ptys_reg.eth_proto_admin %x\n",
720 be32_to_cpu(ptys_reg.eth_proto_admin));
721 en_dbg(DRV, priv, "ptys_reg.eth_proto_oper %x\n",
722 be32_to_cpu(ptys_reg.eth_proto_oper));
723 en_dbg(DRV, priv, "ptys_reg.eth_proto_lp_adv %x\n",
724 be32_to_cpu(ptys_reg.eth_proto_lp_adv));
725
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800726 /* reset supported/advertising masks */
727 ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
728 ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200729
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800730 ptys2ethtool_update_supported_port(link_ksettings->link_modes.supported,
731 &ptys_reg);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200732
733 eth_proto = be32_to_cpu(ptys_reg.eth_proto_cap);
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800734 ptys2ethtool_update_link_modes(link_ksettings->link_modes.supported,
735 eth_proto, SUPPORTED);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200736
737 eth_proto = be32_to_cpu(ptys_reg.eth_proto_admin);
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800738 ptys2ethtool_update_link_modes(link_ksettings->link_modes.advertising,
739 eth_proto, ADVERTISED);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200740
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800741 ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
742 Pause);
743 ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
744 Asym_Pause);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200745
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800746 if (priv->prof->tx_pause)
747 ethtool_link_ksettings_add_link_mode(link_ksettings,
748 advertising, Pause);
749 if (priv->prof->tx_pause ^ priv->prof->rx_pause)
750 ethtool_link_ksettings_add_link_mode(link_ksettings,
751 advertising, Asym_Pause);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200752
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800753 link_ksettings->base.port = ptys_get_active_port(&ptys_reg);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200754
755 if (mlx4_en_autoneg_get(dev)) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800756 ethtool_link_ksettings_add_link_mode(link_ksettings,
757 supported, Autoneg);
758 ethtool_link_ksettings_add_link_mode(link_ksettings,
759 advertising, Autoneg);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200760 }
761
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800762 link_ksettings->base.autoneg
763 = (priv->port_state.flags & MLX4_EN_PORT_ANC) ?
Saeed Mahameed2c762672014-10-27 11:37:40 +0200764 AUTONEG_ENABLE : AUTONEG_DISABLE;
765
766 eth_proto = be32_to_cpu(ptys_reg.eth_proto_lp_adv);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200767
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800768 ethtool_link_ksettings_zero_link_mode(link_ksettings, lp_advertising);
769 ptys2ethtool_update_link_modes(
770 link_ksettings->link_modes.lp_advertising,
771 eth_proto, ADVERTISED);
772 if (priv->port_state.flags & MLX4_EN_PORT_ANC)
773 ethtool_link_ksettings_add_link_mode(link_ksettings,
774 lp_advertising, Autoneg);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200775
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800776 link_ksettings->base.phy_address = 0;
777 link_ksettings->base.mdio_support = 0;
778 link_ksettings->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
779 link_ksettings->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200780
781 return ret;
782}
783
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800784static void
785ethtool_get_default_link_ksettings(
786 struct net_device *dev, struct ethtool_link_ksettings *link_ksettings)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700787{
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000788 struct mlx4_en_priv *priv = netdev_priv(dev);
789 int trans_type;
790
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800791 link_ksettings->base.autoneg = AUTONEG_DISABLE;
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000792
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800793 ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
794 ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
795 10000baseT_Full);
796
797 ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
798 ethtool_link_ksettings_add_link_mode(link_ksettings, advertising,
799 10000baseT_Full);
800
801 trans_type = priv->port_state.transceiver;
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000802 if (trans_type > 0 && trans_type <= 0xC) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800803 link_ksettings->base.port = PORT_FIBRE;
804 ethtool_link_ksettings_add_link_mode(link_ksettings,
805 supported, FIBRE);
806 ethtool_link_ksettings_add_link_mode(link_ksettings,
807 advertising, FIBRE);
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000808 } else if (trans_type == 0x80 || trans_type == 0) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800809 link_ksettings->base.port = PORT_TP;
810 ethtool_link_ksettings_add_link_mode(link_ksettings,
811 supported, TP);
812 ethtool_link_ksettings_add_link_mode(link_ksettings,
813 advertising, TP);
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000814 } else {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800815 link_ksettings->base.port = -1;
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000816 }
Saeed Mahameed2c762672014-10-27 11:37:40 +0200817}
818
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800819static int
820mlx4_en_get_link_ksettings(struct net_device *dev,
821 struct ethtool_link_ksettings *link_ksettings)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200822{
823 struct mlx4_en_priv *priv = netdev_priv(dev);
824 int ret = -EINVAL;
825
826 if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
827 return -ENOMEM;
828
829 en_dbg(DRV, priv, "query port state.flags ANC(%x) ANE(%x)\n",
830 priv->port_state.flags & MLX4_EN_PORT_ANC,
831 priv->port_state.flags & MLX4_EN_PORT_ANE);
832
833 if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL)
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800834 ret = ethtool_get_ptys_link_ksettings(dev, link_ksettings);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200835 if (ret) /* ETH PROT CRTL is not supported or PTYS CMD failed */
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800836 ethtool_get_default_link_ksettings(dev, link_ksettings);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200837
838 if (netif_carrier_ok(dev)) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800839 link_ksettings->base.speed = priv->port_state.link_speed;
840 link_ksettings->base.duplex = DUPLEX_FULL;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200841 } else {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800842 link_ksettings->base.speed = SPEED_UNKNOWN;
843 link_ksettings->base.duplex = DUPLEX_UNKNOWN;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200844 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700845 return 0;
846}
847
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200848/* Calculate PTYS admin according ethtool speed (SPEED_XXX) */
849static __be32 speed_set_ptys_admin(struct mlx4_en_priv *priv, u32 speed,
850 __be32 proto_cap)
851{
852 __be32 proto_admin = 0;
853
854 if (!speed) { /* Speed = 0 ==> Reset Link modes */
855 proto_admin = proto_cap;
856 en_info(priv, "Speed was set to 0, Reset advertised Link Modes to default (%x)\n",
857 be32_to_cpu(proto_cap));
858 } else {
859 u32 ptys_link_modes = speed2ptys_link_modes(speed);
860
861 proto_admin = cpu_to_be32(ptys_link_modes) & proto_cap;
862 en_info(priv, "Setting Speed to %d\n", speed);
863 }
864 return proto_admin;
865}
866
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800867static int
868mlx4_en_set_link_ksettings(struct net_device *dev,
869 const struct ethtool_link_ksettings *link_ksettings)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700870{
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200871 struct mlx4_en_priv *priv = netdev_priv(dev);
872 struct mlx4_ptys_reg ptys_reg;
873 __be32 proto_admin;
874 int ret;
875
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800876 u32 ptys_adv = ethtool2ptys_link_modes(
877 link_ksettings->link_modes.advertising, ADVERTISED);
878 const int speed = link_ksettings->base.speed;
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200879
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800880 en_dbg(DRV, priv,
881 "Set Speed=%d adv={%*pbl} autoneg=%d duplex=%d\n",
882 speed, __ETHTOOL_LINK_MODE_MASK_NBITS,
883 link_ksettings->link_modes.advertising,
884 link_ksettings->base.autoneg,
885 link_ksettings->base.duplex);
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200886
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800887 if (!(priv->mdev->dev->caps.flags2 &
888 MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL) ||
889 (link_ksettings->base.duplex == DUPLEX_HALF))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700890 return -EINVAL;
891
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200892 memset(&ptys_reg, 0, sizeof(ptys_reg));
893 ptys_reg.local_port = priv->port;
894 ptys_reg.proto_mask = MLX4_PTYS_EN;
895 ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev,
896 MLX4_ACCESS_REG_QUERY, &ptys_reg);
897 if (ret) {
898 en_warn(priv, "Failed to QUERY mlx4_ACCESS_PTYS_REG status(%x)\n",
899 ret);
900 return 0;
901 }
902
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800903 proto_admin = link_ksettings->base.autoneg == AUTONEG_ENABLE ?
Saeed Mahameed5a228c02015-01-27 15:58:06 +0200904 cpu_to_be32(ptys_adv) :
905 speed_set_ptys_admin(priv, speed,
906 ptys_reg.eth_proto_cap);
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200907
908 proto_admin &= ptys_reg.eth_proto_cap;
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200909 if (!proto_admin) {
910 en_warn(priv, "Not supported link mode(s) requested, check supported link modes.\n");
911 return -EINVAL; /* nothing to change due to bad input */
912 }
913
Saeed Mahameed5a228c02015-01-27 15:58:06 +0200914 if (proto_admin == ptys_reg.eth_proto_admin)
915 return 0; /* Nothing to change */
916
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200917 en_dbg(DRV, priv, "mlx4_ACCESS_PTYS_REG SET: ptys_reg.eth_proto_admin = 0x%x\n",
918 be32_to_cpu(proto_admin));
919
920 ptys_reg.eth_proto_admin = proto_admin;
921 ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev, MLX4_ACCESS_REG_WRITE,
922 &ptys_reg);
923 if (ret) {
924 en_warn(priv, "Failed to write mlx4_ACCESS_PTYS_REG eth_proto_admin(0x%x) status(0x%x)",
925 be32_to_cpu(ptys_reg.eth_proto_admin), ret);
926 return ret;
927 }
928
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200929 mutex_lock(&priv->mdev->state_lock);
930 if (priv->port_up) {
Saeed Mahameed5a228c02015-01-27 15:58:06 +0200931 en_warn(priv, "Port link mode changed, restarting port...\n");
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200932 mlx4_en_stop_port(dev, 1);
933 if (mlx4_en_start_port(dev))
934 en_err(priv, "Failed restarting port %d\n", priv->port);
935 }
936 mutex_unlock(&priv->mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700937 return 0;
938}
939
940static int mlx4_en_get_coalesce(struct net_device *dev,
941 struct ethtool_coalesce *coal)
942{
943 struct mlx4_en_priv *priv = netdev_priv(dev);
944
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000945 coal->tx_coalesce_usecs = priv->tx_usecs;
946 coal->tx_max_coalesced_frames = priv->tx_frames;
Amir Vadaifbc6daf2014-07-08 11:28:12 +0300947 coal->tx_max_coalesced_frames_irq = priv->tx_work_limit;
948
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700949 coal->rx_coalesce_usecs = priv->rx_usecs;
950 coal->rx_max_coalesced_frames = priv->rx_frames;
951
952 coal->pkt_rate_low = priv->pkt_rate_low;
953 coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
954 coal->pkt_rate_high = priv->pkt_rate_high;
955 coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
956 coal->rate_sample_interval = priv->sample_interval;
957 coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
Amir Vadaifbc6daf2014-07-08 11:28:12 +0300958
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700959 return 0;
960}
961
962static int mlx4_en_set_coalesce(struct net_device *dev,
963 struct ethtool_coalesce *coal)
964{
965 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700966
Amir Vadaifbc6daf2014-07-08 11:28:12 +0300967 if (!coal->tx_max_coalesced_frames_irq)
968 return -EINVAL;
969
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700970 priv->rx_frames = (coal->rx_max_coalesced_frames ==
971 MLX4_EN_AUTO_CONF) ?
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +0000972 MLX4_EN_RX_COAL_TARGET :
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700973 coal->rx_max_coalesced_frames;
974 priv->rx_usecs = (coal->rx_coalesce_usecs ==
975 MLX4_EN_AUTO_CONF) ?
976 MLX4_EN_RX_COAL_TIME :
977 coal->rx_coalesce_usecs;
978
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000979 /* Setting TX coalescing parameters */
980 if (coal->tx_coalesce_usecs != priv->tx_usecs ||
981 coal->tx_max_coalesced_frames != priv->tx_frames) {
982 priv->tx_usecs = coal->tx_coalesce_usecs;
983 priv->tx_frames = coal->tx_max_coalesced_frames;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000984 }
985
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700986 /* Set adaptive coalescing params */
987 priv->pkt_rate_low = coal->pkt_rate_low;
988 priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
989 priv->pkt_rate_high = coal->pkt_rate_high;
990 priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
991 priv->sample_interval = coal->rate_sample_interval;
992 priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
Amir Vadaifbc6daf2014-07-08 11:28:12 +0300993 priv->tx_work_limit = coal->tx_max_coalesced_frames_irq;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700994
Amir Vadai79c54b62012-12-02 03:49:22 +0000995 return mlx4_en_moderation_update(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700996}
997
998static int mlx4_en_set_pauseparam(struct net_device *dev,
999 struct ethtool_pauseparam *pause)
1000{
1001 struct mlx4_en_priv *priv = netdev_priv(dev);
1002 struct mlx4_en_dev *mdev = priv->mdev;
1003 int err;
1004
Ivan Vecera278d4362014-09-08 18:46:53 +02001005 if (pause->autoneg)
1006 return -EINVAL;
1007
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001008 priv->prof->tx_pause = pause->tx_pause != 0;
1009 priv->prof->rx_pause = pause->rx_pause != 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001010 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1011 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001012 priv->prof->tx_pause,
1013 priv->prof->tx_ppp,
1014 priv->prof->rx_pause,
1015 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001016 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001017 en_err(priv, "Failed setting pause params\n");
Matan Barak0b131562015-03-30 17:45:25 +03001018 else
1019 mlx4_en_update_pfc_stats_bitmap(mdev->dev, &priv->stats_bitmap,
1020 priv->prof->rx_ppp,
1021 priv->prof->rx_pause,
1022 priv->prof->tx_ppp,
1023 priv->prof->tx_pause);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001024
1025 return err;
1026}
1027
1028static void mlx4_en_get_pauseparam(struct net_device *dev,
1029 struct ethtool_pauseparam *pause)
1030{
1031 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001032
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001033 pause->tx_pause = priv->prof->tx_pause;
1034 pause->rx_pause = priv->prof->rx_pause;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001035}
1036
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001037static int mlx4_en_set_ringparam(struct net_device *dev,
1038 struct ethtool_ringparam *param)
1039{
1040 struct mlx4_en_priv *priv = netdev_priv(dev);
1041 struct mlx4_en_dev *mdev = priv->mdev;
1042 u32 rx_size, tx_size;
1043 int port_up = 0;
1044 int err = 0;
1045
1046 if (param->rx_jumbo_pending || param->rx_mini_pending)
1047 return -EINVAL;
1048
1049 rx_size = roundup_pow_of_two(param->rx_pending);
1050 rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -08001051 rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001052 tx_size = roundup_pow_of_two(param->tx_pending);
1053 tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -08001054 tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001055
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001056 if (rx_size == (priv->port_up ? priv->rx_ring[0]->actual_size :
1057 priv->rx_ring[0]->size) &&
1058 tx_size == priv->tx_ring[0]->size)
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001059 return 0;
1060
1061 mutex_lock(&mdev->state_lock);
1062 if (priv->port_up) {
1063 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +00001064 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001065 }
1066
Alexander Gullerfe0af032011-10-09 05:26:46 +00001067 mlx4_en_free_resources(priv);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001068
1069 priv->prof->tx_ring_size = tx_size;
1070 priv->prof->rx_ring_size = rx_size;
1071
1072 err = mlx4_en_alloc_resources(priv);
1073 if (err) {
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001074 en_err(priv, "Failed reallocating port resources\n");
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001075 goto out;
1076 }
1077 if (port_up) {
1078 err = mlx4_en_start_port(dev);
1079 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001080 en_err(priv, "Failed starting port\n");
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001081 }
1082
Amir Vadai79c54b62012-12-02 03:49:22 +00001083 err = mlx4_en_moderation_update(priv);
Alexander Guller6b4d8d92011-10-09 05:38:23 +00001084
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001085out:
1086 mutex_unlock(&mdev->state_lock);
1087 return err;
1088}
1089
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001090static void mlx4_en_get_ringparam(struct net_device *dev,
1091 struct ethtool_ringparam *param)
1092{
1093 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001094
1095 memset(param, 0, sizeof(*param));
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -08001096 param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
1097 param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
Yevgeny Petrilinbc081ce2010-08-24 03:46:34 +00001098 param->rx_pending = priv->port_up ?
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001099 priv->rx_ring[0]->actual_size : priv->rx_ring[0]->size;
1100 param->tx_pending = priv->tx_ring[0]->size;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001101}
1102
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001103static u32 mlx4_en_get_rxfh_indir_size(struct net_device *dev)
1104{
1105 struct mlx4_en_priv *priv = netdev_priv(dev);
1106
1107 return priv->rx_ring_num;
1108}
1109
Eric Dumazetb9d1ab72014-11-16 06:23:16 -08001110static u32 mlx4_en_get_rxfh_key_size(struct net_device *netdev)
1111{
1112 return MLX4_EN_RSS_KEY_SIZE;
1113}
1114
Eyal Perry947cbb02014-12-02 18:12:11 +02001115static int mlx4_en_check_rxfh_func(struct net_device *dev, u8 hfunc)
1116{
1117 struct mlx4_en_priv *priv = netdev_priv(dev);
1118
1119 /* check if requested function is supported by the device */
Amir Vadaib3706902015-04-27 13:40:56 +03001120 if (hfunc == ETH_RSS_HASH_TOP) {
1121 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP))
1122 return -EINVAL;
1123 if (!(dev->features & NETIF_F_RXHASH))
1124 en_warn(priv, "Toeplitz hash function should be used in conjunction with RX hashing for optimal performance\n");
1125 return 0;
1126 } else if (hfunc == ETH_RSS_HASH_XOR) {
1127 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR))
1128 return -EINVAL;
1129 if (dev->features & NETIF_F_RXHASH)
1130 en_warn(priv, "Enabling both XOR Hash function and RX Hashing can limit RPS functionality\n");
1131 return 0;
1132 }
Eyal Perry947cbb02014-12-02 18:12:11 +02001133
Amir Vadaib3706902015-04-27 13:40:56 +03001134 return -EINVAL;
Eyal Perry947cbb02014-12-02 18:12:11 +02001135}
1136
Eyal Perry892311f2014-12-02 18:12:10 +02001137static int mlx4_en_get_rxfh(struct net_device *dev, u32 *ring_index, u8 *key,
1138 u8 *hfunc)
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001139{
1140 struct mlx4_en_priv *priv = netdev_priv(dev);
1141 struct mlx4_en_rss_map *rss_map = &priv->rss_map;
1142 int rss_rings;
1143 size_t n = priv->rx_ring_num;
1144 int err = 0;
1145
1146 rss_rings = priv->prof->rss_rings ?: priv->rx_ring_num;
Amir Vadaid5ec8992014-10-27 11:37:47 +02001147 rss_rings = 1 << ilog2(rss_rings);
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001148
1149 while (n--) {
Eyal Perry892311f2014-12-02 18:12:10 +02001150 if (!ring_index)
1151 break;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001152 ring_index[n] = rss_map->qps[n % rss_rings].qpn -
1153 rss_map->base_qpn;
1154 }
Eric Dumazetb9d1ab72014-11-16 06:23:16 -08001155 if (key)
Eric Dumazetbd635c32014-11-22 17:24:19 -08001156 memcpy(key, priv->rss_key, MLX4_EN_RSS_KEY_SIZE);
Eyal Perry892311f2014-12-02 18:12:10 +02001157 if (hfunc)
Eyal Perry947cbb02014-12-02 18:12:11 +02001158 *hfunc = priv->rss_hash_fn;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001159 return err;
1160}
1161
Ben Hutchingsfe62d002014-05-15 01:25:27 +01001162static int mlx4_en_set_rxfh(struct net_device *dev, const u32 *ring_index,
Eyal Perry892311f2014-12-02 18:12:10 +02001163 const u8 *key, const u8 hfunc)
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001164{
1165 struct mlx4_en_priv *priv = netdev_priv(dev);
1166 struct mlx4_en_dev *mdev = priv->mdev;
1167 int port_up = 0;
1168 int err = 0;
1169 int i;
1170 int rss_rings = 0;
1171
1172 /* Calculate RSS table size and make sure flows are spread evenly
1173 * between rings
1174 */
1175 for (i = 0; i < priv->rx_ring_num; i++) {
Eric Dumazetbd635c32014-11-22 17:24:19 -08001176 if (!ring_index)
1177 continue;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001178 if (i > 0 && !ring_index[i] && !rss_rings)
1179 rss_rings = i;
1180
1181 if (ring_index[i] != (i % (rss_rings ?: priv->rx_ring_num)))
1182 return -EINVAL;
1183 }
1184
1185 if (!rss_rings)
1186 rss_rings = priv->rx_ring_num;
1187
1188 /* RSS table size must be an order of 2 */
1189 if (!is_power_of_2(rss_rings))
1190 return -EINVAL;
1191
Eyal Perry947cbb02014-12-02 18:12:11 +02001192 if (hfunc != ETH_RSS_HASH_NO_CHANGE) {
1193 err = mlx4_en_check_rxfh_func(dev, hfunc);
1194 if (err)
1195 return err;
1196 }
1197
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001198 mutex_lock(&mdev->state_lock);
1199 if (priv->port_up) {
1200 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +00001201 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001202 }
1203
Eric Dumazetbd635c32014-11-22 17:24:19 -08001204 if (ring_index)
1205 priv->prof->rss_rings = rss_rings;
1206 if (key)
1207 memcpy(priv->rss_key, key, MLX4_EN_RSS_KEY_SIZE);
Amir Vadaib3706902015-04-27 13:40:56 +03001208 if (hfunc != ETH_RSS_HASH_NO_CHANGE)
1209 priv->rss_hash_fn = hfunc;
Eyal Perry947cbb02014-12-02 18:12:11 +02001210
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001211 if (port_up) {
1212 err = mlx4_en_start_port(dev);
1213 if (err)
1214 en_err(priv, "Failed starting port\n");
1215 }
1216
1217 mutex_unlock(&mdev->state_lock);
1218 return err;
1219}
1220
Hadar Hen Zion82067282012-07-05 04:03:49 +00001221#define all_zeros_or_all_ones(field) \
1222 ((field) == 0 || (field) == (__force typeof(field))-1)
1223
1224static int mlx4_en_validate_flow(struct net_device *dev,
1225 struct ethtool_rxnfc *cmd)
1226{
1227 struct ethtool_usrip4_spec *l3_mask;
1228 struct ethtool_tcpip4_spec *l4_mask;
1229 struct ethhdr *eth_mask;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001230
1231 if (cmd->fs.location >= MAX_NUM_OF_FS_RULES)
1232 return -EINVAL;
1233
Yan Burman520dfe32012-12-12 02:13:19 +00001234 if (cmd->fs.flow_type & FLOW_MAC_EXT) {
1235 /* dest mac mask must be ff:ff:ff:ff:ff:ff */
1236 if (!is_broadcast_ether_addr(cmd->fs.m_ext.h_dest))
1237 return -EINVAL;
1238 }
1239
1240 switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
Hadar Hen Zion82067282012-07-05 04:03:49 +00001241 case TCP_V4_FLOW:
1242 case UDP_V4_FLOW:
1243 if (cmd->fs.m_u.tcp_ip4_spec.tos)
1244 return -EINVAL;
1245 l4_mask = &cmd->fs.m_u.tcp_ip4_spec;
1246 /* don't allow mask which isn't all 0 or 1 */
1247 if (!all_zeros_or_all_ones(l4_mask->ip4src) ||
1248 !all_zeros_or_all_ones(l4_mask->ip4dst) ||
1249 !all_zeros_or_all_ones(l4_mask->psrc) ||
1250 !all_zeros_or_all_ones(l4_mask->pdst))
1251 return -EINVAL;
1252 break;
1253 case IP_USER_FLOW:
1254 l3_mask = &cmd->fs.m_u.usr_ip4_spec;
1255 if (l3_mask->l4_4_bytes || l3_mask->tos || l3_mask->proto ||
1256 cmd->fs.h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 ||
1257 (!l3_mask->ip4src && !l3_mask->ip4dst) ||
1258 !all_zeros_or_all_ones(l3_mask->ip4src) ||
1259 !all_zeros_or_all_ones(l3_mask->ip4dst))
1260 return -EINVAL;
1261 break;
1262 case ETHER_FLOW:
1263 eth_mask = &cmd->fs.m_u.ether_spec;
1264 /* source mac mask must not be set */
Yan Burmanc402b942012-12-12 02:13:18 +00001265 if (!is_zero_ether_addr(eth_mask->h_source))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001266 return -EINVAL;
1267
1268 /* dest mac mask must be ff:ff:ff:ff:ff:ff */
Yan Burmanc402b942012-12-12 02:13:18 +00001269 if (!is_broadcast_ether_addr(eth_mask->h_dest))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001270 return -EINVAL;
1271
1272 if (!all_zeros_or_all_ones(eth_mask->h_proto))
1273 return -EINVAL;
1274 break;
1275 default:
1276 return -EINVAL;
1277 }
1278
1279 if ((cmd->fs.flow_type & FLOW_EXT)) {
1280 if (cmd->fs.m_ext.vlan_etype ||
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001281 !((cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) ==
1282 0 ||
1283 (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) ==
1284 cpu_to_be16(VLAN_VID_MASK)))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001285 return -EINVAL;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001286
Hadar Hen Zion69d71262013-01-30 23:07:05 +00001287 if (cmd->fs.m_ext.vlan_tci) {
1288 if (be16_to_cpu(cmd->fs.h_ext.vlan_tci) >= VLAN_N_VID)
1289 return -EINVAL;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001290
Hadar Hen Zion69d71262013-01-30 23:07:05 +00001291 }
Hadar Hen Zion82067282012-07-05 04:03:49 +00001292 }
1293
1294 return 0;
1295}
1296
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001297static int mlx4_en_ethtool_add_mac_rule(struct ethtool_rxnfc *cmd,
1298 struct list_head *rule_list_h,
1299 struct mlx4_spec_list *spec_l2,
1300 unsigned char *mac)
Hadar Hen Zion82067282012-07-05 04:03:49 +00001301{
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001302 int err = 0;
1303 __be64 mac_msk = cpu_to_be64(MLX4_MAC_MASK << 16);
1304
1305 spec_l2->id = MLX4_NET_TRANS_RULE_ID_ETH;
1306 memcpy(spec_l2->eth.dst_mac_msk, &mac_msk, ETH_ALEN);
1307 memcpy(spec_l2->eth.dst_mac, mac, ETH_ALEN);
1308
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001309 if ((cmd->fs.flow_type & FLOW_EXT) &&
1310 (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK))) {
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001311 spec_l2->eth.vlan_id = cmd->fs.h_ext.vlan_tci;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001312 spec_l2->eth.vlan_id_msk = cpu_to_be16(VLAN_VID_MASK);
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001313 }
1314
1315 list_add_tail(&spec_l2->list, rule_list_h);
1316
1317 return err;
1318}
1319
1320static int mlx4_en_ethtool_add_mac_rule_by_ipv4(struct mlx4_en_priv *priv,
1321 struct ethtool_rxnfc *cmd,
1322 struct list_head *rule_list_h,
1323 struct mlx4_spec_list *spec_l2,
1324 __be32 ipv4_dst)
1325{
Hadar Hen Zionf9d96862013-02-04 03:01:21 +00001326#ifdef CONFIG_INET
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001327 unsigned char mac[ETH_ALEN];
1328
1329 if (!ipv4_is_multicast(ipv4_dst)) {
Yan Burman6bbb6d92013-02-07 02:25:20 +00001330 if (cmd->fs.flow_type & FLOW_MAC_EXT)
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001331 memcpy(&mac, cmd->fs.h_ext.h_dest, ETH_ALEN);
Yan Burman6bbb6d92013-02-07 02:25:20 +00001332 else
1333 memcpy(&mac, priv->dev->dev_addr, ETH_ALEN);
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001334 } else {
1335 ip_eth_mc_map(ipv4_dst, mac);
1336 }
1337
1338 return mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2, &mac[0]);
Hadar Hen Zionf9d96862013-02-04 03:01:21 +00001339#else
1340 return -EINVAL;
1341#endif
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001342}
1343
1344static int add_ip_rule(struct mlx4_en_priv *priv,
1345 struct ethtool_rxnfc *cmd,
1346 struct list_head *list_h)
1347{
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001348 int err;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001349 struct mlx4_spec_list *spec_l2 = NULL;
1350 struct mlx4_spec_list *spec_l3 = NULL;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001351 struct ethtool_usrip4_spec *l3_mask = &cmd->fs.m_u.usr_ip4_spec;
1352
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001353 spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL);
1354 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
1355 if (!spec_l2 || !spec_l3) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001356 err = -ENOMEM;
1357 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001358 }
1359
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001360 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h, spec_l2,
1361 cmd->fs.h_u.
1362 usr_ip4_spec.ip4dst);
1363 if (err)
1364 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001365 spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4;
1366 spec_l3->ipv4.src_ip = cmd->fs.h_u.usr_ip4_spec.ip4src;
1367 if (l3_mask->ip4src)
1368 spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK;
1369 spec_l3->ipv4.dst_ip = cmd->fs.h_u.usr_ip4_spec.ip4dst;
1370 if (l3_mask->ip4dst)
1371 spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK;
1372 list_add_tail(&spec_l3->list, list_h);
1373
1374 return 0;
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001375
1376free_spec:
1377 kfree(spec_l2);
1378 kfree(spec_l3);
1379 return err;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001380}
1381
1382static int add_tcp_udp_rule(struct mlx4_en_priv *priv,
1383 struct ethtool_rxnfc *cmd,
1384 struct list_head *list_h, int proto)
1385{
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001386 int err;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001387 struct mlx4_spec_list *spec_l2 = NULL;
1388 struct mlx4_spec_list *spec_l3 = NULL;
1389 struct mlx4_spec_list *spec_l4 = NULL;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001390 struct ethtool_tcpip4_spec *l4_mask = &cmd->fs.m_u.tcp_ip4_spec;
1391
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001392 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
1393 spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL);
1394 spec_l4 = kzalloc(sizeof(*spec_l4), GFP_KERNEL);
1395 if (!spec_l2 || !spec_l3 || !spec_l4) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001396 err = -ENOMEM;
1397 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001398 }
1399
1400 spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4;
1401
1402 if (proto == TCP_V4_FLOW) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001403 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h,
1404 spec_l2,
1405 cmd->fs.h_u.
1406 tcp_ip4_spec.ip4dst);
1407 if (err)
1408 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001409 spec_l4->id = MLX4_NET_TRANS_RULE_ID_TCP;
1410 spec_l3->ipv4.src_ip = cmd->fs.h_u.tcp_ip4_spec.ip4src;
1411 spec_l3->ipv4.dst_ip = cmd->fs.h_u.tcp_ip4_spec.ip4dst;
1412 spec_l4->tcp_udp.src_port = cmd->fs.h_u.tcp_ip4_spec.psrc;
1413 spec_l4->tcp_udp.dst_port = cmd->fs.h_u.tcp_ip4_spec.pdst;
1414 } else {
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001415 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h,
1416 spec_l2,
1417 cmd->fs.h_u.
1418 udp_ip4_spec.ip4dst);
1419 if (err)
1420 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001421 spec_l4->id = MLX4_NET_TRANS_RULE_ID_UDP;
1422 spec_l3->ipv4.src_ip = cmd->fs.h_u.udp_ip4_spec.ip4src;
1423 spec_l3->ipv4.dst_ip = cmd->fs.h_u.udp_ip4_spec.ip4dst;
1424 spec_l4->tcp_udp.src_port = cmd->fs.h_u.udp_ip4_spec.psrc;
1425 spec_l4->tcp_udp.dst_port = cmd->fs.h_u.udp_ip4_spec.pdst;
1426 }
1427
1428 if (l4_mask->ip4src)
1429 spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK;
1430 if (l4_mask->ip4dst)
1431 spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK;
1432
1433 if (l4_mask->psrc)
1434 spec_l4->tcp_udp.src_port_msk = EN_ETHTOOL_SHORT_MASK;
1435 if (l4_mask->pdst)
1436 spec_l4->tcp_udp.dst_port_msk = EN_ETHTOOL_SHORT_MASK;
1437
1438 list_add_tail(&spec_l3->list, list_h);
1439 list_add_tail(&spec_l4->list, list_h);
1440
1441 return 0;
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001442
1443free_spec:
1444 kfree(spec_l2);
1445 kfree(spec_l3);
1446 kfree(spec_l4);
1447 return err;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001448}
1449
1450static int mlx4_en_ethtool_to_net_trans_rule(struct net_device *dev,
1451 struct ethtool_rxnfc *cmd,
1452 struct list_head *rule_list_h)
1453{
1454 int err;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001455 struct ethhdr *eth_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001456 struct mlx4_spec_list *spec_l2;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001457 struct mlx4_en_priv *priv = netdev_priv(dev);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001458
1459 err = mlx4_en_validate_flow(dev, cmd);
1460 if (err)
1461 return err;
1462
Yan Burman520dfe32012-12-12 02:13:19 +00001463 switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
Hadar Hen Zion82067282012-07-05 04:03:49 +00001464 case ETHER_FLOW:
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001465 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
1466 if (!spec_l2)
1467 return -ENOMEM;
1468
Hadar Hen Zion82067282012-07-05 04:03:49 +00001469 eth_spec = &cmd->fs.h_u.ether_spec;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001470 mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2,
1471 &eth_spec->h_dest[0]);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001472 spec_l2->eth.ether_type = eth_spec->h_proto;
1473 if (eth_spec->h_proto)
1474 spec_l2->eth.ether_type_enable = 1;
1475 break;
1476 case IP_USER_FLOW:
1477 err = add_ip_rule(priv, cmd, rule_list_h);
1478 break;
1479 case TCP_V4_FLOW:
1480 err = add_tcp_udp_rule(priv, cmd, rule_list_h, TCP_V4_FLOW);
1481 break;
1482 case UDP_V4_FLOW:
1483 err = add_tcp_udp_rule(priv, cmd, rule_list_h, UDP_V4_FLOW);
1484 break;
1485 }
1486
1487 return err;
1488}
1489
1490static int mlx4_en_flow_replace(struct net_device *dev,
1491 struct ethtool_rxnfc *cmd)
1492{
1493 int err;
1494 struct mlx4_en_priv *priv = netdev_priv(dev);
1495 struct ethtool_flow_id *loc_rule;
1496 struct mlx4_spec_list *spec, *tmp_spec;
1497 u32 qpn;
1498 u64 reg_id;
1499
1500 struct mlx4_net_trans_rule rule = {
1501 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
1502 .exclusive = 0,
1503 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001504 .promisc_mode = MLX4_FS_REGULAR,
Hadar Hen Zion82067282012-07-05 04:03:49 +00001505 };
1506
1507 rule.port = priv->port;
1508 rule.priority = MLX4_DOMAIN_ETHTOOL | cmd->fs.location;
1509 INIT_LIST_HEAD(&rule.list);
1510
1511 /* Allow direct QP attaches if the EN_ETHTOOL_QP_ATTACH flag is set */
1512 if (cmd->fs.ring_cookie == RX_CLS_FLOW_DISC)
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001513 qpn = priv->drop_qp.qpn;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001514 else if (cmd->fs.ring_cookie & EN_ETHTOOL_QP_ATTACH) {
1515 qpn = cmd->fs.ring_cookie & (EN_ETHTOOL_QP_ATTACH - 1);
1516 } else {
1517 if (cmd->fs.ring_cookie >= priv->rx_ring_num) {
Joe Perches1a91de22014-05-07 12:52:57 -07001518 en_warn(priv, "rxnfc: RX ring (%llu) doesn't exist\n",
Hadar Hen Zion82067282012-07-05 04:03:49 +00001519 cmd->fs.ring_cookie);
1520 return -EINVAL;
1521 }
1522 qpn = priv->rss_map.qps[cmd->fs.ring_cookie].qpn;
1523 if (!qpn) {
Joe Perches1a91de22014-05-07 12:52:57 -07001524 en_warn(priv, "rxnfc: RX ring (%llu) is inactive\n",
Hadar Hen Zion82067282012-07-05 04:03:49 +00001525 cmd->fs.ring_cookie);
1526 return -EINVAL;
1527 }
1528 }
1529 rule.qpn = qpn;
1530 err = mlx4_en_ethtool_to_net_trans_rule(dev, cmd, &rule.list);
1531 if (err)
1532 goto out_free_list;
1533
1534 loc_rule = &priv->ethtool_rules[cmd->fs.location];
1535 if (loc_rule->id) {
1536 err = mlx4_flow_detach(priv->mdev->dev, loc_rule->id);
1537 if (err) {
1538 en_err(priv, "Fail to detach network rule at location %d. registration id = %llx\n",
1539 cmd->fs.location, loc_rule->id);
1540 goto out_free_list;
1541 }
1542 loc_rule->id = 0;
1543 memset(&loc_rule->flow_spec, 0,
1544 sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001545 list_del(&loc_rule->list);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001546 }
1547 err = mlx4_flow_attach(priv->mdev->dev, &rule, &reg_id);
1548 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001549 en_err(priv, "Fail to attach network rule at location %d\n",
Hadar Hen Zion82067282012-07-05 04:03:49 +00001550 cmd->fs.location);
1551 goto out_free_list;
1552 }
1553 loc_rule->id = reg_id;
1554 memcpy(&loc_rule->flow_spec, &cmd->fs,
1555 sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001556 list_add_tail(&loc_rule->list, &priv->ethtool_list);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001557
1558out_free_list:
1559 list_for_each_entry_safe(spec, tmp_spec, &rule.list, list) {
1560 list_del(&spec->list);
1561 kfree(spec);
1562 }
1563 return err;
1564}
1565
1566static int mlx4_en_flow_detach(struct net_device *dev,
1567 struct ethtool_rxnfc *cmd)
1568{
1569 int err = 0;
1570 struct ethtool_flow_id *rule;
1571 struct mlx4_en_priv *priv = netdev_priv(dev);
1572
1573 if (cmd->fs.location >= MAX_NUM_OF_FS_RULES)
1574 return -EINVAL;
1575
1576 rule = &priv->ethtool_rules[cmd->fs.location];
1577 if (!rule->id) {
1578 err = -ENOENT;
1579 goto out;
1580 }
1581
1582 err = mlx4_flow_detach(priv->mdev->dev, rule->id);
1583 if (err) {
1584 en_err(priv, "Fail to detach network rule at location %d. registration id = 0x%llx\n",
1585 cmd->fs.location, rule->id);
1586 goto out;
1587 }
1588 rule->id = 0;
1589 memset(&rule->flow_spec, 0, sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001590 list_del(&rule->list);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001591out:
1592 return err;
1593
1594}
1595
1596static int mlx4_en_get_flow(struct net_device *dev, struct ethtool_rxnfc *cmd,
1597 int loc)
1598{
1599 int err = 0;
1600 struct ethtool_flow_id *rule;
1601 struct mlx4_en_priv *priv = netdev_priv(dev);
1602
1603 if (loc < 0 || loc >= MAX_NUM_OF_FS_RULES)
1604 return -EINVAL;
1605
1606 rule = &priv->ethtool_rules[loc];
1607 if (rule->id)
1608 memcpy(&cmd->fs, &rule->flow_spec,
1609 sizeof(struct ethtool_rx_flow_spec));
1610 else
1611 err = -ENOENT;
1612
1613 return err;
1614}
1615
1616static int mlx4_en_get_num_flows(struct mlx4_en_priv *priv)
1617{
1618
1619 int i, res = 0;
1620 for (i = 0; i < MAX_NUM_OF_FS_RULES; i++) {
1621 if (priv->ethtool_rules[i].id)
1622 res++;
1623 }
1624 return res;
1625
1626}
1627
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001628static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
1629 u32 *rule_locs)
1630{
1631 struct mlx4_en_priv *priv = netdev_priv(dev);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001632 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001633 int err = 0;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001634 int i = 0, priority = 0;
1635
1636 if ((cmd->cmd == ETHTOOL_GRXCLSRLCNT ||
1637 cmd->cmd == ETHTOOL_GRXCLSRULE ||
1638 cmd->cmd == ETHTOOL_GRXCLSRLALL) &&
Hadar Hen Zion280fce12013-01-30 23:07:07 +00001639 (mdev->dev->caps.steering_mode !=
1640 MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001641 return -EINVAL;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001642
1643 switch (cmd->cmd) {
1644 case ETHTOOL_GRXRINGS:
1645 cmd->data = priv->rx_ring_num;
1646 break;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001647 case ETHTOOL_GRXCLSRLCNT:
1648 cmd->rule_cnt = mlx4_en_get_num_flows(priv);
1649 break;
1650 case ETHTOOL_GRXCLSRULE:
1651 err = mlx4_en_get_flow(dev, cmd, cmd->fs.location);
1652 break;
1653 case ETHTOOL_GRXCLSRLALL:
1654 while ((!err || err == -ENOENT) && priority < cmd->rule_cnt) {
1655 err = mlx4_en_get_flow(dev, cmd, i);
1656 if (!err)
1657 rule_locs[priority++] = i;
1658 i++;
1659 }
1660 err = 0;
1661 break;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001662 default:
1663 err = -EOPNOTSUPP;
1664 break;
1665 }
1666
1667 return err;
1668}
1669
Hadar Hen Zion82067282012-07-05 04:03:49 +00001670static int mlx4_en_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
1671{
1672 int err = 0;
1673 struct mlx4_en_priv *priv = netdev_priv(dev);
1674 struct mlx4_en_dev *mdev = priv->mdev;
1675
Hadar Hen Zion280fce12013-01-30 23:07:07 +00001676 if (mdev->dev->caps.steering_mode !=
1677 MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up)
Hadar Hen Zion82067282012-07-05 04:03:49 +00001678 return -EINVAL;
1679
1680 switch (cmd->cmd) {
1681 case ETHTOOL_SRXCLSRLINS:
1682 err = mlx4_en_flow_replace(dev, cmd);
1683 break;
1684 case ETHTOOL_SRXCLSRLDEL:
1685 err = mlx4_en_flow_detach(dev, cmd);
1686 break;
1687 default:
1688 en_warn(priv, "Unsupported ethtool command. (%d)\n", cmd->cmd);
1689 return -EINVAL;
1690 }
1691
1692 return err;
1693}
1694
Amir Vadaid3179662012-12-02 03:49:23 +00001695static void mlx4_en_get_channels(struct net_device *dev,
1696 struct ethtool_channels *channel)
1697{
1698 struct mlx4_en_priv *priv = netdev_priv(dev);
1699
1700 memset(channel, 0, sizeof(*channel));
1701
1702 channel->max_rx = MAX_RX_RINGS;
1703 channel->max_tx = MLX4_EN_MAX_TX_RING_P_UP;
1704
1705 channel->rx_count = priv->rx_ring_num;
1706 channel->tx_count = priv->tx_ring_num / MLX4_EN_NUM_UP;
1707}
1708
1709static int mlx4_en_set_channels(struct net_device *dev,
1710 struct ethtool_channels *channel)
1711{
1712 struct mlx4_en_priv *priv = netdev_priv(dev);
1713 struct mlx4_en_dev *mdev = priv->mdev;
Christian Engelmayerda26a622014-05-17 23:52:03 +02001714 int port_up = 0;
Amir Vadaid3179662012-12-02 03:49:23 +00001715 int err = 0;
1716
1717 if (channel->other_count || channel->combined_count ||
1718 channel->tx_count > MLX4_EN_MAX_TX_RING_P_UP ||
1719 channel->rx_count > MAX_RX_RINGS ||
1720 !channel->tx_count || !channel->rx_count)
1721 return -EINVAL;
1722
1723 mutex_lock(&mdev->state_lock);
1724 if (priv->port_up) {
1725 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +00001726 mlx4_en_stop_port(dev, 1);
Amir Vadaid3179662012-12-02 03:49:23 +00001727 }
1728
1729 mlx4_en_free_resources(priv);
1730
1731 priv->num_tx_rings_p_up = channel->tx_count;
1732 priv->tx_ring_num = channel->tx_count * MLX4_EN_NUM_UP;
1733 priv->rx_ring_num = channel->rx_count;
1734
1735 err = mlx4_en_alloc_resources(priv);
1736 if (err) {
1737 en_err(priv, "Failed reallocating port resources\n");
1738 goto out;
1739 }
1740
1741 netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
1742 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
1743
Ido Shamayf5b63452014-05-14 12:15:11 +03001744 if (dev->num_tc)
1745 mlx4_en_setup_tc(dev, MLX4_EN_NUM_UP);
Amir Vadaid3179662012-12-02 03:49:23 +00001746
1747 en_warn(priv, "Using %d TX rings\n", priv->tx_ring_num);
1748 en_warn(priv, "Using %d RX rings\n", priv->rx_ring_num);
1749
1750 if (port_up) {
1751 err = mlx4_en_start_port(dev);
1752 if (err)
1753 en_err(priv, "Failed starting port\n");
1754 }
1755
1756 err = mlx4_en_moderation_update(priv);
1757
1758out:
1759 mutex_unlock(&mdev->state_lock);
1760 return err;
1761}
1762
Amir Vadaiec693d42013-04-23 06:06:49 +00001763static int mlx4_en_get_ts_info(struct net_device *dev,
1764 struct ethtool_ts_info *info)
1765{
1766 struct mlx4_en_priv *priv = netdev_priv(dev);
1767 struct mlx4_en_dev *mdev = priv->mdev;
1768 int ret;
1769
1770 ret = ethtool_op_get_ts_info(dev, info);
1771 if (ret)
1772 return ret;
1773
1774 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) {
1775 info->so_timestamping |=
1776 SOF_TIMESTAMPING_TX_HARDWARE |
1777 SOF_TIMESTAMPING_RX_HARDWARE |
1778 SOF_TIMESTAMPING_RAW_HARDWARE;
1779
1780 info->tx_types =
1781 (1 << HWTSTAMP_TX_OFF) |
1782 (1 << HWTSTAMP_TX_ON);
1783
1784 info->rx_filters =
1785 (1 << HWTSTAMP_FILTER_NONE) |
1786 (1 << HWTSTAMP_FILTER_ALL);
Shawn Bohrerad7d4ea2013-12-31 11:39:39 -06001787
1788 if (mdev->ptp_clock)
1789 info->phc_index = ptp_clock_index(mdev->ptp_clock);
Amir Vadaiec693d42013-04-23 06:06:49 +00001790 }
1791
1792 return ret;
1793}
1794
Fengguang Wu3f6148e2014-07-24 09:11:46 +03001795static int mlx4_en_set_priv_flags(struct net_device *dev, u32 flags)
Amir Vadai0fef9d02014-07-22 15:44:10 +03001796{
1797 struct mlx4_en_priv *priv = netdev_priv(dev);
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03001798 struct mlx4_en_dev *mdev = priv->mdev;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001799 bool bf_enabled_new = !!(flags & MLX4_EN_PRIV_FLAGS_BLUEFLAME);
1800 bool bf_enabled_old = !!(priv->pflags & MLX4_EN_PRIV_FLAGS_BLUEFLAME);
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03001801 bool phv_enabled_new = !!(flags & MLX4_EN_PRIV_FLAGS_PHV);
1802 bool phv_enabled_old = !!(priv->pflags & MLX4_EN_PRIV_FLAGS_PHV);
Amir Vadai0fef9d02014-07-22 15:44:10 +03001803 int i;
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03001804 int ret = 0;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001805
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001806 if (bf_enabled_new != bf_enabled_old) {
1807 if (bf_enabled_new) {
1808 bool bf_supported = true;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001809
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001810 for (i = 0; i < priv->tx_ring_num; i++)
1811 bf_supported &= priv->tx_ring[i]->bf_alloced;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001812
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001813 if (!bf_supported) {
1814 en_err(priv, "BlueFlame is not supported\n");
1815 return -EINVAL;
1816 }
Amir Vadai0fef9d02014-07-22 15:44:10 +03001817
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001818 priv->pflags |= MLX4_EN_PRIV_FLAGS_BLUEFLAME;
1819 } else {
1820 priv->pflags &= ~MLX4_EN_PRIV_FLAGS_BLUEFLAME;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001821 }
1822
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001823 for (i = 0; i < priv->tx_ring_num; i++)
1824 priv->tx_ring[i]->bf_enabled = bf_enabled_new;
1825
1826 en_info(priv, "BlueFlame %s\n",
1827 bf_enabled_new ? "Enabled" : "Disabled");
Amir Vadai0fef9d02014-07-22 15:44:10 +03001828 }
1829
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03001830 if (phv_enabled_new != phv_enabled_old) {
1831 ret = set_phv_bit(mdev->dev, priv->port, (int)phv_enabled_new);
1832 if (ret)
1833 return ret;
1834 else if (phv_enabled_new)
1835 priv->pflags |= MLX4_EN_PRIV_FLAGS_PHV;
1836 else
1837 priv->pflags &= ~MLX4_EN_PRIV_FLAGS_PHV;
1838 en_info(priv, "PHV bit %s\n",
1839 phv_enabled_new ? "Enabled" : "Disabled");
1840 }
Amir Vadai0fef9d02014-07-22 15:44:10 +03001841 return 0;
1842}
1843
Fengguang Wu3f6148e2014-07-24 09:11:46 +03001844static u32 mlx4_en_get_priv_flags(struct net_device *dev)
Amir Vadai0fef9d02014-07-22 15:44:10 +03001845{
1846 struct mlx4_en_priv *priv = netdev_priv(dev);
1847
1848 return priv->pflags;
1849}
1850
Eric Dumazet1556b872014-10-05 12:35:22 +03001851static int mlx4_en_get_tunable(struct net_device *dev,
1852 const struct ethtool_tunable *tuna,
1853 void *data)
1854{
1855 const struct mlx4_en_priv *priv = netdev_priv(dev);
1856 int ret = 0;
1857
1858 switch (tuna->id) {
1859 case ETHTOOL_TX_COPYBREAK:
1860 *(u32 *)data = priv->prof->inline_thold;
1861 break;
1862 default:
1863 ret = -EINVAL;
1864 break;
1865 }
1866
1867 return ret;
1868}
1869
1870static int mlx4_en_set_tunable(struct net_device *dev,
1871 const struct ethtool_tunable *tuna,
1872 const void *data)
1873{
1874 struct mlx4_en_priv *priv = netdev_priv(dev);
1875 int val, ret = 0;
1876
1877 switch (tuna->id) {
1878 case ETHTOOL_TX_COPYBREAK:
1879 val = *(u32 *)data;
1880 if (val < MIN_PKT_LEN || val > MAX_INLINE)
1881 ret = -EINVAL;
1882 else
1883 priv->prof->inline_thold = val;
1884 break;
1885 default:
1886 ret = -EINVAL;
1887 break;
1888 }
1889
1890 return ret;
1891}
1892
Saeed Mahameed7202da82014-10-27 11:37:36 +02001893static int mlx4_en_get_module_info(struct net_device *dev,
1894 struct ethtool_modinfo *modinfo)
1895{
1896 struct mlx4_en_priv *priv = netdev_priv(dev);
1897 struct mlx4_en_dev *mdev = priv->mdev;
1898 int ret;
1899 u8 data[4];
1900
1901 /* Read first 2 bytes to get Module & REV ID */
1902 ret = mlx4_get_module_info(mdev->dev, priv->port,
1903 0/*offset*/, 2/*size*/, data);
1904 if (ret < 2)
1905 return -EIO;
1906
1907 switch (data[0] /* identifier */) {
1908 case MLX4_MODULE_ID_QSFP:
1909 modinfo->type = ETH_MODULE_SFF_8436;
1910 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1911 break;
1912 case MLX4_MODULE_ID_QSFP_PLUS:
1913 if (data[1] >= 0x3) { /* revision id */
1914 modinfo->type = ETH_MODULE_SFF_8636;
1915 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1916 } else {
1917 modinfo->type = ETH_MODULE_SFF_8436;
1918 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1919 }
1920 break;
1921 case MLX4_MODULE_ID_QSFP28:
1922 modinfo->type = ETH_MODULE_SFF_8636;
1923 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1924 break;
1925 case MLX4_MODULE_ID_SFP:
1926 modinfo->type = ETH_MODULE_SFF_8472;
1927 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1928 break;
1929 default:
1930 return -ENOSYS;
1931 }
1932
1933 return 0;
1934}
1935
1936static int mlx4_en_get_module_eeprom(struct net_device *dev,
1937 struct ethtool_eeprom *ee,
1938 u8 *data)
1939{
1940 struct mlx4_en_priv *priv = netdev_priv(dev);
1941 struct mlx4_en_dev *mdev = priv->mdev;
1942 int offset = ee->offset;
1943 int i = 0, ret;
1944
1945 if (ee->len == 0)
1946 return -EINVAL;
1947
1948 memset(data, 0, ee->len);
1949
1950 while (i < ee->len) {
1951 en_dbg(DRV, priv,
1952 "mlx4_get_module_info i(%d) offset(%d) len(%d)\n",
1953 i, offset, ee->len - i);
1954
1955 ret = mlx4_get_module_info(mdev->dev, priv->port,
1956 offset, ee->len - i, data + i);
1957
1958 if (!ret) /* Done reading */
1959 return 0;
1960
1961 if (ret < 0) {
1962 en_err(priv,
1963 "mlx4_get_module_info i(%d) offset(%d) bytes_to_read(%d) - FAILED (0x%x)\n",
1964 i, offset, ee->len - i, ret);
1965 return 0;
1966 }
1967
1968 i += ret;
1969 offset += ret;
1970 }
1971 return 0;
1972}
Amir Vadai0fef9d02014-07-22 15:44:10 +03001973
Ido Shamay51af33c2015-04-02 16:31:20 +03001974static int mlx4_en_set_phys_id(struct net_device *dev,
1975 enum ethtool_phys_id_state state)
1976{
1977 int err;
1978 u16 beacon_duration;
1979 struct mlx4_en_priv *priv = netdev_priv(dev);
1980 struct mlx4_en_dev *mdev = priv->mdev;
1981
1982 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PORT_BEACON))
1983 return -EOPNOTSUPP;
1984
1985 switch (state) {
1986 case ETHTOOL_ID_ACTIVE:
1987 beacon_duration = PORT_BEACON_MAX_LIMIT;
1988 break;
1989 case ETHTOOL_ID_INACTIVE:
1990 beacon_duration = 0;
1991 break;
1992 default:
1993 return -EOPNOTSUPP;
1994 }
1995
1996 err = mlx4_SET_PORT_BEACON(mdev->dev, priv->port, beacon_duration);
1997 return err;
1998}
1999
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002000const struct ethtool_ops mlx4_en_ethtool_ops = {
2001 .get_drvinfo = mlx4_en_get_drvinfo,
David Decotigny3d8f7cc2016-02-24 10:58:12 -08002002 .get_link_ksettings = mlx4_en_get_link_ksettings,
2003 .set_link_ksettings = mlx4_en_set_link_ksettings,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002004 .get_link = ethtool_op_get_link,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002005 .get_strings = mlx4_en_get_strings,
2006 .get_sset_count = mlx4_en_get_sset_count,
2007 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +00002008 .self_test = mlx4_en_self_test,
Ido Shamay51af33c2015-04-02 16:31:20 +03002009 .set_phys_id = mlx4_en_set_phys_id,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002010 .get_wol = mlx4_en_get_wol,
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +00002011 .set_wol = mlx4_en_set_wol,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002012 .get_msglevel = mlx4_en_get_msglevel,
2013 .set_msglevel = mlx4_en_set_msglevel,
2014 .get_coalesce = mlx4_en_get_coalesce,
2015 .set_coalesce = mlx4_en_set_coalesce,
2016 .get_pauseparam = mlx4_en_get_pauseparam,
2017 .set_pauseparam = mlx4_en_set_pauseparam,
2018 .get_ringparam = mlx4_en_get_ringparam,
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08002019 .set_ringparam = mlx4_en_set_ringparam,
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00002020 .get_rxnfc = mlx4_en_get_rxnfc,
Hadar Hen Zion82067282012-07-05 04:03:49 +00002021 .set_rxnfc = mlx4_en_set_rxnfc,
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00002022 .get_rxfh_indir_size = mlx4_en_get_rxfh_indir_size,
Eric Dumazetb9d1ab72014-11-16 06:23:16 -08002023 .get_rxfh_key_size = mlx4_en_get_rxfh_key_size,
Ben Hutchingsfe62d002014-05-15 01:25:27 +01002024 .get_rxfh = mlx4_en_get_rxfh,
2025 .set_rxfh = mlx4_en_set_rxfh,
Amir Vadaid3179662012-12-02 03:49:23 +00002026 .get_channels = mlx4_en_get_channels,
2027 .set_channels = mlx4_en_set_channels,
Amir Vadaiec693d42013-04-23 06:06:49 +00002028 .get_ts_info = mlx4_en_get_ts_info,
Amir Vadai0fef9d02014-07-22 15:44:10 +03002029 .set_priv_flags = mlx4_en_set_priv_flags,
2030 .get_priv_flags = mlx4_en_get_priv_flags,
Eric Dumazet1556b872014-10-05 12:35:22 +03002031 .get_tunable = mlx4_en_get_tunable,
2032 .set_tunable = mlx4_en_set_tunable,
Saeed Mahameed7202da82014-10-27 11:37:36 +02002033 .get_module_info = mlx4_en_get_module_info,
2034 .get_module_eeprom = mlx4_en_get_module_eeprom
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002035};
2036
2037
2038
2039
2040