blob: ae5fdc2df65412afce4e72b8384c9c4b3302c56e [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{
Tariq Toukan67f8b1d2016-11-02 17:12:24 +020052 int i, t;
Amir Vadai79c54b62012-12-02 03:49:22 +000053 int err = 0;
54
Tariq Toukan67f8b1d2016-11-02 17:12:24 +020055 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 Emantayev38463e22013-09-12 18:11:20 +030065 }
Amir Vadai79c54b62012-12-02 03:49:22 +000066 }
67
68 if (priv->adaptive_rx_coal)
69 return 0;
70
71 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +020072 priv->rx_cq[i]->moder_cnt = priv->rx_frames;
73 priv->rx_cq[i]->moder_time = priv->rx_usecs;
Amir Vadai79c54b62012-12-02 03:49:22 +000074 priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
Eugenia Emantayev38463e22013-09-12 18:11:20 +030075 if (priv->port_up) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +020076 err = mlx4_en_set_cq_moder(priv, priv->rx_cq[i]);
Eugenia Emantayev38463e22013-09-12 18:11:20 +030077 if (err)
78 return err;
79 }
Amir Vadai79c54b62012-12-02 03:49:22 +000080 }
81
82 return err;
83}
84
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -070085static void
86mlx4_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 Jones612a94d2011-11-14 08:13:25 +000091 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 Petrilinc27a02c2008-10-22 15:47:49 -070096 (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 Hadas872bf2f2015-01-25 16:59:35 +020099 strlcpy(drvinfo->bus_info, pci_name(mdev->dev->persist->pdev),
Rick Jones612a94d2011-11-14 08:13:25 +0000100 sizeof(drvinfo->bus_info));
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700101}
102
Amir Vadai0fef9d02014-07-22 15:44:10 +0300103static const char mlx4_en_priv_flags[][ETH_GSTRING_LEN] = {
104 "blueflame",
Hadar Hen Zione38af4f2015-07-27 14:46:34 +0300105 "phv-bit"
Amir Vadai0fef9d02014-07-22 15:44:10 +0300106};
107
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700108static const char main_strings[][ETH_GSTRING_LEN] = {
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300109 /* main statistics */
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700110 "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 Petrilinfa37a952010-08-24 03:46:46 +0000118 "tso_packets",
Eric Dumazet9fab4262014-10-02 08:24:21 -0700119 "xmit_more",
Eric Dumazet7d7bfc62017-03-08 08:17:14 -0800120 "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_pages",
Shani Michaelif8c64552014-11-09 13:51:53 +0200121 "rx_csum_good", "rx_csum_none", "rx_csum_complete", "tx_chksum_offload",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700122
Eran Ben Elishab42de4d2015-06-15 17:59:06 +0300123 /* pf statistics */
124 "pf_rx_packets",
125 "pf_rx_bytes",
126 "pf_tx_packets",
127 "pf_tx_bytes",
128
Matan Barak0b131562015-03-30 17:45:25 +0300129 /* 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 Petrilinc27a02c2008-10-22 15:47:49 -0700171 /* packet statistics */
Eran Ben Elishaa3333b32015-03-30 17:45:26 +0300172 "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 Toukan15fca2c2016-11-02 17:12:25 +0200198 /* xdp statistics */
199 "rx_xdp_drop",
200 "rx_xdp_tx",
201 "rx_xdp_tx_full",
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700202};
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700203
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000204static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= {
Masanari Iidafd9071e2012-04-13 04:33:20 +0000205 "Interrupt Test",
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000206 "Link Test",
207 "Speed Test",
208 "Register Test",
209 "Loopback Test",
210};
211
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700212static u32 mlx4_en_get_msglevel(struct net_device *dev)
213{
214 return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
215}
216
217static 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
222static void mlx4_en_get_wol(struct net_device *netdev,
223 struct ethtool_wolinfo *wol)
224{
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000225 struct mlx4_en_priv *priv = netdev_priv(netdev);
226 int err = 0;
227 u64 config = 0;
Oren Duer559a9f12011-11-26 19:55:15 +0000228 u64 mask;
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000229
Oren Duer559a9f12011-11-26 19:55:15 +0000230 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 Petrilin14c07b12011-03-22 22:37:59 +0000239 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
261static 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 Duer559a9f12011-11-26 19:55:15 +0000267 u64 mask;
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +0000268
Oren Duer559a9f12011-11-26 19:55:15 +0000269 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 Petrilin14c07b12011-03-22 22:37:59 +0000276 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 Petrilinc27a02c2008-10-22 15:47:49 -0700300}
301
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300302struct 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
309static 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
320static 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
325static inline int bitmap_iterator_inc(struct bitmap_iterator *h)
326{
327 return h->iterator++;
328}
329
330static inline unsigned int
331bitmap_iterator_count(struct bitmap_iterator *h)
332{
333 return h->count;
334}
335
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700336static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
337{
338 struct mlx4_en_priv *priv = netdev_priv(dev);
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300339 struct bitmap_iterator it;
340
Eran Ben Elisha3da8a362015-03-30 17:45:24 +0300341 bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700342
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000343 switch (sset) {
344 case ETH_SS_STATS:
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300345 return bitmap_iterator_count(&it) +
Tariq Toukan67f8b1d2016-11-02 17:12:24 +0200346 (priv->tx_ring_num[TX] * 2) +
Tariq Toukan15fca2c2016-11-02 17:12:25 +0200347 (priv->rx_ring_num * (3 + NUM_XDP_STATS));
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000348 case ETH_SS_TEST:
Or Gerlitzccf86322011-07-07 19:19:29 +0000349 return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags
350 & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2;
Amir Vadai0fef9d02014-07-22 15:44:10 +0300351 case ETH_SS_PRIV_FLAGS:
352 return ARRAY_SIZE(mlx4_en_priv_flags);
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000353 default:
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700354 return -EOPNOTSUPP;
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000355 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700356}
357
358static 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 Elisha6fcd2732015-03-30 17:45:23 +0300363 int i;
364 struct bitmap_iterator it;
365
Eran Ben Elisha3da8a362015-03-30 17:45:24 +0300366 bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700367
368 spin_lock_bh(&priv->stats_lock);
369
Eric Dumazet40931b82016-11-25 07:46:20 -0800370 mlx4_en_fold_software_stats(dev);
371
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300372 for (i = 0; i < NUM_MAIN_STATS; i++, bitmap_iterator_inc(&it))
373 if (bitmap_iterator_test(&it))
Eric Dumazetf73a6f42016-05-25 09:50:39 -0700374 data[index++] = ((unsigned long *)&dev->stats)[i];
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300375
376 for (i = 0; i < NUM_PORT_STATS; i++, bitmap_iterator_inc(&it))
377 if (bitmap_iterator_test(&it))
378 data[index++] = ((unsigned long *)&priv->port_stats)[i];
379
Eran Ben Elishab42de4d2015-06-15 17:59:06 +0300380 for (i = 0; i < NUM_PF_STATS; i++, bitmap_iterator_inc(&it))
381 if (bitmap_iterator_test(&it))
382 data[index++] =
383 ((unsigned long *)&priv->pf_stats)[i];
384
Matan Barak0b131562015-03-30 17:45:25 +0300385 for (i = 0; i < NUM_FLOW_PRIORITY_STATS_RX;
386 i++, bitmap_iterator_inc(&it))
387 if (bitmap_iterator_test(&it))
388 data[index++] =
389 ((u64 *)&priv->rx_priority_flowstats)[i];
390
391 for (i = 0; i < NUM_FLOW_STATS_RX; i++, bitmap_iterator_inc(&it))
392 if (bitmap_iterator_test(&it))
393 data[index++] = ((u64 *)&priv->rx_flowstats)[i];
394
395 for (i = 0; i < NUM_FLOW_PRIORITY_STATS_TX;
396 i++, bitmap_iterator_inc(&it))
397 if (bitmap_iterator_test(&it))
398 data[index++] =
399 ((u64 *)&priv->tx_priority_flowstats)[i];
400
401 for (i = 0; i < NUM_FLOW_STATS_TX; i++, bitmap_iterator_inc(&it))
402 if (bitmap_iterator_test(&it))
403 data[index++] = ((u64 *)&priv->tx_flowstats)[i];
404
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300405 for (i = 0; i < NUM_PKT_STATS; i++, bitmap_iterator_inc(&it))
406 if (bitmap_iterator_test(&it))
407 data[index++] = ((unsigned long *)&priv->pkstats)[i];
408
Tariq Toukan15fca2c2016-11-02 17:12:25 +0200409 for (i = 0; i < NUM_XDP_STATS; i++, bitmap_iterator_inc(&it))
410 if (bitmap_iterator_test(&it))
411 data[index++] = ((unsigned long *)&priv->xdp_stats)[i];
412
Tariq Toukan67f8b1d2016-11-02 17:12:24 +0200413 for (i = 0; i < priv->tx_ring_num[TX]; i++) {
414 data[index++] = priv->tx_ring[TX][i]->packets;
415 data[index++] = priv->tx_ring[TX][i]->bytes;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700416 }
417 for (i = 0; i < priv->rx_ring_num; i++) {
Eugenia Emantayev41d942d2013-11-07 12:19:52 +0200418 data[index++] = priv->rx_ring[i]->packets;
419 data[index++] = priv->rx_ring[i]->bytes;
Eran Ben Elishad21ed3a2016-04-20 16:01:18 +0300420 data[index++] = priv->rx_ring[i]->dropped;
Tariq Toukan15fca2c2016-11-02 17:12:25 +0200421 data[index++] = priv->rx_ring[i]->xdp_drop;
422 data[index++] = priv->rx_ring[i]->xdp_tx;
423 data[index++] = priv->rx_ring[i]->xdp_tx_full;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700424 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700425 spin_unlock_bh(&priv->stats_lock);
426
427}
428
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000429static void mlx4_en_self_test(struct net_device *dev,
430 struct ethtool_test *etest, u64 *buf)
431{
432 mlx4_en_ex_selftest(dev, &etest->flags, buf);
433}
434
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700435static void mlx4_en_get_strings(struct net_device *dev,
436 uint32_t stringset, uint8_t *data)
437{
438 struct mlx4_en_priv *priv = netdev_priv(dev);
439 int index = 0;
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300440 int i, strings = 0;
441 struct bitmap_iterator it;
442
Eran Ben Elisha3da8a362015-03-30 17:45:24 +0300443 bitmap_iterator_init(&it, priv->stats_bitmap.bitmap, NUM_ALL_STATS);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700444
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000445 switch (stringset) {
446 case ETH_SS_TEST:
447 for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++)
448 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
Or Gerlitzccf86322011-07-07 19:19:29 +0000449 if (priv->mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UC_LOOPBACK)
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000450 for (; i < MLX4_EN_NUM_SELF_TEST; i++)
451 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
452 break;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700453
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000454 case ETH_SS_STATS:
455 /* Add main counters */
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300456 for (i = 0; i < NUM_MAIN_STATS; i++, strings++,
457 bitmap_iterator_inc(&it))
458 if (bitmap_iterator_test(&it))
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000459 strcpy(data + (index++) * ETH_GSTRING_LEN,
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300460 main_strings[strings]);
461
462 for (i = 0; i < NUM_PORT_STATS; i++, strings++,
463 bitmap_iterator_inc(&it))
464 if (bitmap_iterator_test(&it))
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000465 strcpy(data + (index++) * ETH_GSTRING_LEN,
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300466 main_strings[strings]);
467
Eran Ben Elishab42de4d2015-06-15 17:59:06 +0300468 for (i = 0; i < NUM_PF_STATS; i++, strings++,
469 bitmap_iterator_inc(&it))
470 if (bitmap_iterator_test(&it))
471 strcpy(data + (index++) * ETH_GSTRING_LEN,
472 main_strings[strings]);
473
Matan Barak0b131562015-03-30 17:45:25 +0300474 for (i = 0; i < NUM_FLOW_STATS; i++, strings++,
475 bitmap_iterator_inc(&it))
476 if (bitmap_iterator_test(&it))
477 strcpy(data + (index++) * ETH_GSTRING_LEN,
478 main_strings[strings]);
479
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300480 for (i = 0; i < NUM_PKT_STATS; i++, strings++,
481 bitmap_iterator_inc(&it))
482 if (bitmap_iterator_test(&it))
Eugenia Emantayev93ece0c2012-01-19 09:45:05 +0000483 strcpy(data + (index++) * ETH_GSTRING_LEN,
Eran Ben Elisha6fcd2732015-03-30 17:45:23 +0300484 main_strings[strings]);
485
Tariq Toukan15fca2c2016-11-02 17:12:25 +0200486 for (i = 0; i < NUM_XDP_STATS; i++, strings++,
487 bitmap_iterator_inc(&it))
488 if (bitmap_iterator_test(&it))
489 strcpy(data + (index++) * ETH_GSTRING_LEN,
490 main_strings[strings]);
491
Tariq Toukan67f8b1d2016-11-02 17:12:24 +0200492 for (i = 0; i < priv->tx_ring_num[TX]; i++) {
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000493 sprintf(data + (index++) * ETH_GSTRING_LEN,
494 "tx%d_packets", i);
495 sprintf(data + (index++) * ETH_GSTRING_LEN,
496 "tx%d_bytes", i);
497 }
498 for (i = 0; i < priv->rx_ring_num; i++) {
499 sprintf(data + (index++) * ETH_GSTRING_LEN,
500 "rx%d_packets", i);
501 sprintf(data + (index++) * ETH_GSTRING_LEN,
502 "rx%d_bytes", i);
Eran Ben Elishad21ed3a2016-04-20 16:01:18 +0300503 sprintf(data + (index++) * ETH_GSTRING_LEN,
504 "rx%d_dropped", i);
Tariq Toukan15fca2c2016-11-02 17:12:25 +0200505 sprintf(data + (index++) * ETH_GSTRING_LEN,
506 "rx%d_xdp_drop", i);
507 sprintf(data + (index++) * ETH_GSTRING_LEN,
508 "rx%d_xdp_tx", i);
509 sprintf(data + (index++) * ETH_GSTRING_LEN,
510 "rx%d_xdp_tx_full", i);
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000511 }
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000512 break;
Amir Vadai0fef9d02014-07-22 15:44:10 +0300513 case ETH_SS_PRIV_FLAGS:
514 for (i = 0; i < ARRAY_SIZE(mlx4_en_priv_flags); i++)
515 strcpy(data + i * ETH_GSTRING_LEN,
516 mlx4_en_priv_flags[i]);
517 break;
518
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +0000519 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700520}
521
Saeed Mahameed2c762672014-10-27 11:37:40 +0200522static u32 mlx4_en_autoneg_get(struct net_device *dev)
523{
524 struct mlx4_en_priv *priv = netdev_priv(dev);
525 struct mlx4_en_dev *mdev = priv->mdev;
526 u32 autoneg = AUTONEG_DISABLE;
527
528 if ((mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_BACKPL_AN_REP) &&
529 (priv->port_state.flags & MLX4_EN_PORT_ANE))
530 autoneg = AUTONEG_ENABLE;
531
532 return autoneg;
533}
534
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800535static void ptys2ethtool_update_supported_port(unsigned long *mask,
536 struct mlx4_ptys_reg *ptys_reg)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200537{
538 u32 eth_proto = be32_to_cpu(ptys_reg->eth_proto_cap);
539
540 if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_T)
541 | MLX4_PROT_MASK(MLX4_1000BASE_T)
542 | MLX4_PROT_MASK(MLX4_100BASE_TX))) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800543 __set_bit(ETHTOOL_LINK_MODE_TP_BIT, mask);
544 } else if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_CR)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200545 | MLX4_PROT_MASK(MLX4_10GBASE_SR)
546 | MLX4_PROT_MASK(MLX4_56GBASE_SR4)
547 | MLX4_PROT_MASK(MLX4_40GBASE_CR4)
548 | MLX4_PROT_MASK(MLX4_40GBASE_SR4)
549 | MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII))) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800550 __set_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, mask);
551 } else if (eth_proto & (MLX4_PROT_MASK(MLX4_56GBASE_KR4)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200552 | MLX4_PROT_MASK(MLX4_40GBASE_KR4)
553 | MLX4_PROT_MASK(MLX4_20GBASE_KR2)
554 | MLX4_PROT_MASK(MLX4_10GBASE_KR)
555 | MLX4_PROT_MASK(MLX4_10GBASE_KX4)
556 | MLX4_PROT_MASK(MLX4_1000BASE_KX))) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800557 __set_bit(ETHTOOL_LINK_MODE_Backplane_BIT, mask);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200558 }
Saeed Mahameed2c762672014-10-27 11:37:40 +0200559}
560
561static u32 ptys_get_active_port(struct mlx4_ptys_reg *ptys_reg)
562{
563 u32 eth_proto = be32_to_cpu(ptys_reg->eth_proto_oper);
564
565 if (!eth_proto) /* link down */
566 eth_proto = be32_to_cpu(ptys_reg->eth_proto_cap);
567
568 if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_T)
569 | MLX4_PROT_MASK(MLX4_1000BASE_T)
570 | MLX4_PROT_MASK(MLX4_100BASE_TX))) {
571 return PORT_TP;
572 }
573
574 if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_SR)
575 | MLX4_PROT_MASK(MLX4_56GBASE_SR4)
576 | MLX4_PROT_MASK(MLX4_40GBASE_SR4)
577 | MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII))) {
578 return PORT_FIBRE;
579 }
580
581 if (eth_proto & (MLX4_PROT_MASK(MLX4_10GBASE_CR)
582 | MLX4_PROT_MASK(MLX4_56GBASE_CR4)
583 | MLX4_PROT_MASK(MLX4_40GBASE_CR4))) {
584 return PORT_DA;
585 }
586
587 if (eth_proto & (MLX4_PROT_MASK(MLX4_56GBASE_KR4)
588 | MLX4_PROT_MASK(MLX4_40GBASE_KR4)
589 | MLX4_PROT_MASK(MLX4_20GBASE_KR2)
590 | MLX4_PROT_MASK(MLX4_10GBASE_KR)
591 | MLX4_PROT_MASK(MLX4_10GBASE_KX4)
592 | MLX4_PROT_MASK(MLX4_1000BASE_KX))) {
593 return PORT_NONE;
594 }
595 return PORT_OTHER;
596}
597
598#define MLX4_LINK_MODES_SZ \
599 (FIELD_SIZEOF(struct mlx4_ptys_reg, eth_proto_cap) * 8)
600
601enum ethtool_report {
602 SUPPORTED = 0,
603 ADVERTISED = 1,
Saeed Mahameed2c762672014-10-27 11:37:40 +0200604};
605
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800606struct ptys2ethtool_config {
607 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
608 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertised);
609 u32 speed;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200610};
611
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800612static unsigned long *ptys2ethtool_link_mode(struct ptys2ethtool_config *cfg,
613 enum ethtool_report report)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200614{
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800615 switch (report) {
616 case SUPPORTED:
617 return cfg->supported;
618 case ADVERTISED:
619 return cfg->advertised;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200620 }
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800621 return NULL;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200622}
623
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800624#define MLX4_BUILD_PTYS2ETHTOOL_CONFIG(reg_, speed_, ...) \
625 ({ \
626 struct ptys2ethtool_config *cfg; \
627 const unsigned int modes[] = { __VA_ARGS__ }; \
628 unsigned int i; \
629 cfg = &ptys2ethtool_map[reg_]; \
630 cfg->speed = speed_; \
631 bitmap_zero(cfg->supported, \
632 __ETHTOOL_LINK_MODE_MASK_NBITS); \
633 bitmap_zero(cfg->advertised, \
634 __ETHTOOL_LINK_MODE_MASK_NBITS); \
635 for (i = 0 ; i < ARRAY_SIZE(modes) ; ++i) { \
636 __set_bit(modes[i], cfg->supported); \
637 __set_bit(modes[i], cfg->advertised); \
638 } \
639 })
640
641/* Translates mlx4 link mode to equivalent ethtool Link modes/speed */
642static struct ptys2ethtool_config ptys2ethtool_map[MLX4_LINK_MODES_SZ];
643
644void __init mlx4_en_init_ptys2ethtool_map(void)
645{
646 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_100BASE_TX, SPEED_100,
647 ETHTOOL_LINK_MODE_100baseT_Full_BIT);
648 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_T, SPEED_1000,
649 ETHTOOL_LINK_MODE_1000baseT_Full_BIT);
650 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_CX_SGMII, SPEED_1000,
651 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT);
652 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_1000BASE_KX, SPEED_1000,
653 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT);
654 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_T, SPEED_10000,
655 ETHTOOL_LINK_MODE_10000baseT_Full_BIT);
656 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CX4, SPEED_10000,
657 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT);
658 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KX4, SPEED_10000,
659 ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT);
660 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_KR, SPEED_10000,
661 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
662 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_CR, SPEED_10000,
663 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
664 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_10GBASE_SR, SPEED_10000,
665 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT);
666 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_20GBASE_KR2, SPEED_20000,
667 ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT,
668 ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT);
669 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_CR4, SPEED_40000,
670 ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT);
671 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_KR4, SPEED_40000,
672 ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT);
673 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_40GBASE_SR4, SPEED_40000,
674 ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT);
675 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_KR4, SPEED_56000,
676 ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT);
677 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_CR4, SPEED_56000,
678 ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT);
679 MLX4_BUILD_PTYS2ETHTOOL_CONFIG(MLX4_56GBASE_SR4, SPEED_56000,
680 ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT);
681};
682
683static void ptys2ethtool_update_link_modes(unsigned long *link_modes,
684 u32 eth_proto,
685 enum ethtool_report report)
686{
687 int i;
688 for (i = 0; i < MLX4_LINK_MODES_SZ; i++) {
689 if (eth_proto & MLX4_PROT_MASK(i))
690 bitmap_or(link_modes, link_modes,
691 ptys2ethtool_link_mode(&ptys2ethtool_map[i],
692 report),
693 __ETHTOOL_LINK_MODE_MASK_NBITS);
694 }
695}
696
697static u32 ethtool2ptys_link_modes(const unsigned long *link_modes,
698 enum ethtool_report report)
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200699{
700 int i;
701 u32 ptys_modes = 0;
702
703 for (i = 0; i < MLX4_LINK_MODES_SZ; i++) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800704 if (bitmap_intersects(
705 ptys2ethtool_link_mode(&ptys2ethtool_map[i],
706 report),
707 link_modes,
708 __ETHTOOL_LINK_MODE_MASK_NBITS))
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200709 ptys_modes |= 1 << i;
710 }
711 return ptys_modes;
712}
713
714/* Convert actual speed (SPEED_XXX) to ptys link modes */
715static u32 speed2ptys_link_modes(u32 speed)
716{
717 int i;
718 u32 ptys_modes = 0;
719
720 for (i = 0; i < MLX4_LINK_MODES_SZ; i++) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800721 if (ptys2ethtool_map[i].speed == speed)
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200722 ptys_modes |= 1 << i;
723 }
724 return ptys_modes;
725}
726
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800727static int
728ethtool_get_ptys_link_ksettings(struct net_device *dev,
729 struct ethtool_link_ksettings *link_ksettings)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200730{
731 struct mlx4_en_priv *priv = netdev_priv(dev);
732 struct mlx4_ptys_reg ptys_reg;
733 u32 eth_proto;
734 int ret;
735
736 memset(&ptys_reg, 0, sizeof(ptys_reg));
737 ptys_reg.local_port = priv->port;
738 ptys_reg.proto_mask = MLX4_PTYS_EN;
739 ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev,
740 MLX4_ACCESS_REG_QUERY, &ptys_reg);
741 if (ret) {
742 en_warn(priv, "Failed to run mlx4_ACCESS_PTYS_REG status(%x)",
743 ret);
744 return ret;
745 }
746 en_dbg(DRV, priv, "ptys_reg.proto_mask %x\n",
747 ptys_reg.proto_mask);
748 en_dbg(DRV, priv, "ptys_reg.eth_proto_cap %x\n",
749 be32_to_cpu(ptys_reg.eth_proto_cap));
750 en_dbg(DRV, priv, "ptys_reg.eth_proto_admin %x\n",
751 be32_to_cpu(ptys_reg.eth_proto_admin));
752 en_dbg(DRV, priv, "ptys_reg.eth_proto_oper %x\n",
753 be32_to_cpu(ptys_reg.eth_proto_oper));
754 en_dbg(DRV, priv, "ptys_reg.eth_proto_lp_adv %x\n",
755 be32_to_cpu(ptys_reg.eth_proto_lp_adv));
756
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800757 /* reset supported/advertising masks */
758 ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
759 ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200760
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800761 ptys2ethtool_update_supported_port(link_ksettings->link_modes.supported,
762 &ptys_reg);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200763
764 eth_proto = be32_to_cpu(ptys_reg.eth_proto_cap);
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800765 ptys2ethtool_update_link_modes(link_ksettings->link_modes.supported,
766 eth_proto, SUPPORTED);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200767
768 eth_proto = be32_to_cpu(ptys_reg.eth_proto_admin);
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800769 ptys2ethtool_update_link_modes(link_ksettings->link_modes.advertising,
770 eth_proto, ADVERTISED);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200771
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800772 ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
773 Pause);
774 ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
775 Asym_Pause);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200776
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800777 if (priv->prof->tx_pause)
778 ethtool_link_ksettings_add_link_mode(link_ksettings,
779 advertising, Pause);
780 if (priv->prof->tx_pause ^ priv->prof->rx_pause)
781 ethtool_link_ksettings_add_link_mode(link_ksettings,
782 advertising, Asym_Pause);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200783
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800784 link_ksettings->base.port = ptys_get_active_port(&ptys_reg);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200785
786 if (mlx4_en_autoneg_get(dev)) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800787 ethtool_link_ksettings_add_link_mode(link_ksettings,
788 supported, Autoneg);
789 ethtool_link_ksettings_add_link_mode(link_ksettings,
790 advertising, Autoneg);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200791 }
792
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800793 link_ksettings->base.autoneg
794 = (priv->port_state.flags & MLX4_EN_PORT_ANC) ?
Saeed Mahameed2c762672014-10-27 11:37:40 +0200795 AUTONEG_ENABLE : AUTONEG_DISABLE;
796
797 eth_proto = be32_to_cpu(ptys_reg.eth_proto_lp_adv);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200798
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800799 ethtool_link_ksettings_zero_link_mode(link_ksettings, lp_advertising);
800 ptys2ethtool_update_link_modes(
801 link_ksettings->link_modes.lp_advertising,
802 eth_proto, ADVERTISED);
803 if (priv->port_state.flags & MLX4_EN_PORT_ANC)
804 ethtool_link_ksettings_add_link_mode(link_ksettings,
805 lp_advertising, Autoneg);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200806
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800807 link_ksettings->base.phy_address = 0;
808 link_ksettings->base.mdio_support = 0;
809 link_ksettings->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
810 link_ksettings->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200811
812 return ret;
813}
814
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800815static void
816ethtool_get_default_link_ksettings(
817 struct net_device *dev, struct ethtool_link_ksettings *link_ksettings)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700818{
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000819 struct mlx4_en_priv *priv = netdev_priv(dev);
820 int trans_type;
821
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800822 link_ksettings->base.autoneg = AUTONEG_DISABLE;
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000823
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800824 ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
825 ethtool_link_ksettings_add_link_mode(link_ksettings, supported,
826 10000baseT_Full);
827
828 ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
829 ethtool_link_ksettings_add_link_mode(link_ksettings, advertising,
830 10000baseT_Full);
831
832 trans_type = priv->port_state.transceiver;
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000833 if (trans_type > 0 && trans_type <= 0xC) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800834 link_ksettings->base.port = PORT_FIBRE;
835 ethtool_link_ksettings_add_link_mode(link_ksettings,
836 supported, FIBRE);
837 ethtool_link_ksettings_add_link_mode(link_ksettings,
838 advertising, FIBRE);
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000839 } else if (trans_type == 0x80 || trans_type == 0) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800840 link_ksettings->base.port = PORT_TP;
841 ethtool_link_ksettings_add_link_mode(link_ksettings,
842 supported, TP);
843 ethtool_link_ksettings_add_link_mode(link_ksettings,
844 advertising, TP);
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000845 } else {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800846 link_ksettings->base.port = -1;
Yevgeny Petrilin76995172010-08-24 03:46:23 +0000847 }
Saeed Mahameed2c762672014-10-27 11:37:40 +0200848}
849
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800850static int
851mlx4_en_get_link_ksettings(struct net_device *dev,
852 struct ethtool_link_ksettings *link_ksettings)
Saeed Mahameed2c762672014-10-27 11:37:40 +0200853{
854 struct mlx4_en_priv *priv = netdev_priv(dev);
855 int ret = -EINVAL;
856
857 if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
858 return -ENOMEM;
859
860 en_dbg(DRV, priv, "query port state.flags ANC(%x) ANE(%x)\n",
861 priv->port_state.flags & MLX4_EN_PORT_ANC,
862 priv->port_state.flags & MLX4_EN_PORT_ANE);
863
864 if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL)
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800865 ret = ethtool_get_ptys_link_ksettings(dev, link_ksettings);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200866 if (ret) /* ETH PROT CRTL is not supported or PTYS CMD failed */
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800867 ethtool_get_default_link_ksettings(dev, link_ksettings);
Saeed Mahameed2c762672014-10-27 11:37:40 +0200868
869 if (netif_carrier_ok(dev)) {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800870 link_ksettings->base.speed = priv->port_state.link_speed;
871 link_ksettings->base.duplex = DUPLEX_FULL;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200872 } else {
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800873 link_ksettings->base.speed = SPEED_UNKNOWN;
874 link_ksettings->base.duplex = DUPLEX_UNKNOWN;
Saeed Mahameed2c762672014-10-27 11:37:40 +0200875 }
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700876 return 0;
877}
878
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200879/* Calculate PTYS admin according ethtool speed (SPEED_XXX) */
880static __be32 speed_set_ptys_admin(struct mlx4_en_priv *priv, u32 speed,
881 __be32 proto_cap)
882{
883 __be32 proto_admin = 0;
884
885 if (!speed) { /* Speed = 0 ==> Reset Link modes */
886 proto_admin = proto_cap;
887 en_info(priv, "Speed was set to 0, Reset advertised Link Modes to default (%x)\n",
888 be32_to_cpu(proto_cap));
889 } else {
890 u32 ptys_link_modes = speed2ptys_link_modes(speed);
891
892 proto_admin = cpu_to_be32(ptys_link_modes) & proto_cap;
893 en_info(priv, "Setting Speed to %d\n", speed);
894 }
895 return proto_admin;
896}
897
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800898static int
899mlx4_en_set_link_ksettings(struct net_device *dev,
900 const struct ethtool_link_ksettings *link_ksettings)
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700901{
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200902 struct mlx4_en_priv *priv = netdev_priv(dev);
903 struct mlx4_ptys_reg ptys_reg;
904 __be32 proto_admin;
Ariel Levkovich297e1cf2017-01-29 18:56:17 +0200905 u8 cur_autoneg;
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200906 int ret;
907
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800908 u32 ptys_adv = ethtool2ptys_link_modes(
909 link_ksettings->link_modes.advertising, ADVERTISED);
910 const int speed = link_ksettings->base.speed;
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200911
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800912 en_dbg(DRV, priv,
913 "Set Speed=%d adv={%*pbl} autoneg=%d duplex=%d\n",
914 speed, __ETHTOOL_LINK_MODE_MASK_NBITS,
915 link_ksettings->link_modes.advertising,
916 link_ksettings->base.autoneg,
917 link_ksettings->base.duplex);
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200918
David Decotigny3d8f7cc2016-02-24 10:58:12 -0800919 if (!(priv->mdev->dev->caps.flags2 &
920 MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL) ||
921 (link_ksettings->base.duplex == DUPLEX_HALF))
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700922 return -EINVAL;
923
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200924 memset(&ptys_reg, 0, sizeof(ptys_reg));
925 ptys_reg.local_port = priv->port;
926 ptys_reg.proto_mask = MLX4_PTYS_EN;
927 ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev,
928 MLX4_ACCESS_REG_QUERY, &ptys_reg);
929 if (ret) {
930 en_warn(priv, "Failed to QUERY mlx4_ACCESS_PTYS_REG status(%x)\n",
931 ret);
932 return 0;
933 }
934
Ariel Levkovich297e1cf2017-01-29 18:56:17 +0200935 cur_autoneg = ptys_reg.flags & MLX4_PTYS_AN_DISABLE_ADMIN ?
936 AUTONEG_DISABLE : AUTONEG_ENABLE;
937
938 if (link_ksettings->base.autoneg == AUTONEG_DISABLE) {
939 proto_admin = speed_set_ptys_admin(priv, speed,
940 ptys_reg.eth_proto_cap);
941 if ((be32_to_cpu(proto_admin) &
942 (MLX4_PROT_MASK(MLX4_1000BASE_CX_SGMII) |
943 MLX4_PROT_MASK(MLX4_1000BASE_KX))) &&
944 (ptys_reg.flags & MLX4_PTYS_AN_DISABLE_CAP))
945 ptys_reg.flags |= MLX4_PTYS_AN_DISABLE_ADMIN;
946 } else {
947 proto_admin = cpu_to_be32(ptys_adv);
948 ptys_reg.flags &= ~MLX4_PTYS_AN_DISABLE_ADMIN;
949 }
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200950
951 proto_admin &= ptys_reg.eth_proto_cap;
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200952 if (!proto_admin) {
953 en_warn(priv, "Not supported link mode(s) requested, check supported link modes.\n");
954 return -EINVAL; /* nothing to change due to bad input */
955 }
956
Ariel Levkovich297e1cf2017-01-29 18:56:17 +0200957 if ((proto_admin == ptys_reg.eth_proto_admin) &&
958 ((ptys_reg.flags & MLX4_PTYS_AN_DISABLE_CAP) &&
959 (link_ksettings->base.autoneg == cur_autoneg)))
Saeed Mahameed5a228c02015-01-27 15:58:06 +0200960 return 0; /* Nothing to change */
961
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200962 en_dbg(DRV, priv, "mlx4_ACCESS_PTYS_REG SET: ptys_reg.eth_proto_admin = 0x%x\n",
963 be32_to_cpu(proto_admin));
964
965 ptys_reg.eth_proto_admin = proto_admin;
966 ret = mlx4_ACCESS_PTYS_REG(priv->mdev->dev, MLX4_ACCESS_REG_WRITE,
967 &ptys_reg);
968 if (ret) {
969 en_warn(priv, "Failed to write mlx4_ACCESS_PTYS_REG eth_proto_admin(0x%x) status(0x%x)",
970 be32_to_cpu(ptys_reg.eth_proto_admin), ret);
971 return ret;
972 }
973
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200974 mutex_lock(&priv->mdev->state_lock);
975 if (priv->port_up) {
Saeed Mahameed5a228c02015-01-27 15:58:06 +0200976 en_warn(priv, "Port link mode changed, restarting port...\n");
Saeed Mahameedd48b3ab2014-10-27 11:37:41 +0200977 mlx4_en_stop_port(dev, 1);
978 if (mlx4_en_start_port(dev))
979 en_err(priv, "Failed restarting port %d\n", priv->port);
980 }
981 mutex_unlock(&priv->mdev->state_lock);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700982 return 0;
983}
984
985static int mlx4_en_get_coalesce(struct net_device *dev,
986 struct ethtool_coalesce *coal)
987{
988 struct mlx4_en_priv *priv = netdev_priv(dev);
989
Yevgeny Petrilina19a8482012-04-23 02:18:33 +0000990 coal->tx_coalesce_usecs = priv->tx_usecs;
991 coal->tx_max_coalesced_frames = priv->tx_frames;
Amir Vadaifbc6daf2014-07-08 11:28:12 +0300992 coal->tx_max_coalesced_frames_irq = priv->tx_work_limit;
993
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -0700994 coal->rx_coalesce_usecs = priv->rx_usecs;
995 coal->rx_max_coalesced_frames = priv->rx_frames;
996
997 coal->pkt_rate_low = priv->pkt_rate_low;
998 coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
999 coal->pkt_rate_high = priv->pkt_rate_high;
1000 coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
1001 coal->rate_sample_interval = priv->sample_interval;
1002 coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
Amir Vadaifbc6daf2014-07-08 11:28:12 +03001003
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001004 return 0;
1005}
1006
1007static int mlx4_en_set_coalesce(struct net_device *dev,
1008 struct ethtool_coalesce *coal)
1009{
1010 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001011
Amir Vadaifbc6daf2014-07-08 11:28:12 +03001012 if (!coal->tx_max_coalesced_frames_irq)
1013 return -EINVAL;
1014
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001015 priv->rx_frames = (coal->rx_max_coalesced_frames ==
1016 MLX4_EN_AUTO_CONF) ?
Yevgeny Petrilin3db36fb2009-06-01 23:23:13 +00001017 MLX4_EN_RX_COAL_TARGET :
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001018 coal->rx_max_coalesced_frames;
1019 priv->rx_usecs = (coal->rx_coalesce_usecs ==
1020 MLX4_EN_AUTO_CONF) ?
1021 MLX4_EN_RX_COAL_TIME :
1022 coal->rx_coalesce_usecs;
1023
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001024 /* Setting TX coalescing parameters */
1025 if (coal->tx_coalesce_usecs != priv->tx_usecs ||
1026 coal->tx_max_coalesced_frames != priv->tx_frames) {
1027 priv->tx_usecs = coal->tx_coalesce_usecs;
1028 priv->tx_frames = coal->tx_max_coalesced_frames;
Yevgeny Petrilina19a8482012-04-23 02:18:33 +00001029 }
1030
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001031 /* Set adaptive coalescing params */
1032 priv->pkt_rate_low = coal->pkt_rate_low;
1033 priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
1034 priv->pkt_rate_high = coal->pkt_rate_high;
1035 priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
1036 priv->sample_interval = coal->rate_sample_interval;
1037 priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
Amir Vadaifbc6daf2014-07-08 11:28:12 +03001038 priv->tx_work_limit = coal->tx_max_coalesced_frames_irq;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001039
Amir Vadai79c54b62012-12-02 03:49:22 +00001040 return mlx4_en_moderation_update(priv);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001041}
1042
1043static int mlx4_en_set_pauseparam(struct net_device *dev,
1044 struct ethtool_pauseparam *pause)
1045{
1046 struct mlx4_en_priv *priv = netdev_priv(dev);
1047 struct mlx4_en_dev *mdev = priv->mdev;
1048 int err;
1049
Ivan Vecera278d4362014-09-08 18:46:53 +02001050 if (pause->autoneg)
1051 return -EINVAL;
1052
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001053 priv->prof->tx_pause = pause->tx_pause != 0;
1054 priv->prof->rx_pause = pause->rx_pause != 0;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001055 err = mlx4_SET_PORT_general(mdev->dev, priv->port,
1056 priv->rx_skb_size + ETH_FCS_LEN,
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001057 priv->prof->tx_pause,
1058 priv->prof->tx_ppp,
1059 priv->prof->rx_pause,
1060 priv->prof->rx_ppp);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001061 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001062 en_err(priv, "Failed setting pause params\n");
Matan Barak0b131562015-03-30 17:45:25 +03001063 else
1064 mlx4_en_update_pfc_stats_bitmap(mdev->dev, &priv->stats_bitmap,
1065 priv->prof->rx_ppp,
1066 priv->prof->rx_pause,
1067 priv->prof->tx_ppp,
1068 priv->prof->tx_pause);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001069
1070 return err;
1071}
1072
1073static void mlx4_en_get_pauseparam(struct net_device *dev,
1074 struct ethtool_pauseparam *pause)
1075{
1076 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001077
Yevgeny Petrilind53b93f2008-11-05 04:48:36 +00001078 pause->tx_pause = priv->prof->tx_pause;
1079 pause->rx_pause = priv->prof->rx_pause;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001080}
1081
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001082static int mlx4_en_set_ringparam(struct net_device *dev,
1083 struct ethtool_ringparam *param)
1084{
1085 struct mlx4_en_priv *priv = netdev_priv(dev);
1086 struct mlx4_en_dev *mdev = priv->mdev;
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001087 struct mlx4_en_port_profile new_prof;
1088 struct mlx4_en_priv *tmp;
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001089 u32 rx_size, tx_size;
1090 int port_up = 0;
1091 int err = 0;
1092
1093 if (param->rx_jumbo_pending || param->rx_mini_pending)
1094 return -EINVAL;
1095
1096 rx_size = roundup_pow_of_two(param->rx_pending);
1097 rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -08001098 rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001099 tx_size = roundup_pow_of_two(param->tx_pending);
1100 tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -08001101 tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001102
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001103 if (rx_size == (priv->port_up ? priv->rx_ring[0]->actual_size :
1104 priv->rx_ring[0]->size) &&
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001105 tx_size == priv->tx_ring[TX][0]->size)
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001106 return 0;
1107
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001108 tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
1109 if (!tmp)
1110 return -ENOMEM;
1111
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001112 mutex_lock(&mdev->state_lock);
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001113 memcpy(&new_prof, priv->prof, sizeof(struct mlx4_en_port_profile));
1114 new_prof.tx_ring_size = tx_size;
1115 new_prof.rx_ring_size = rx_size;
Martin KaFai Lau770f8222017-01-31 22:35:33 -08001116 err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof, true);
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001117 if (err)
1118 goto out;
1119
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001120 if (priv->port_up) {
1121 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +00001122 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001123 }
1124
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001125 mlx4_en_safe_replace_resources(priv, tmp);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001126
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001127 if (port_up) {
1128 err = mlx4_en_start_port(dev);
1129 if (err)
Yevgeny Petrilin453a6082009-06-01 20:27:13 +00001130 en_err(priv, "Failed starting port\n");
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001131 }
1132
Amir Vadai79c54b62012-12-02 03:49:22 +00001133 err = mlx4_en_moderation_update(priv);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001134out:
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001135 kfree(tmp);
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08001136 mutex_unlock(&mdev->state_lock);
1137 return err;
1138}
1139
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001140static void mlx4_en_get_ringparam(struct net_device *dev,
1141 struct ethtool_ringparam *param)
1142{
1143 struct mlx4_en_priv *priv = netdev_priv(dev);
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001144
1145 memset(param, 0, sizeof(*param));
Yevgeny Petrilinbd531e32009-01-08 10:57:37 -08001146 param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
1147 param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
Yevgeny Petrilinbc081ce2010-08-24 03:46:34 +00001148 param->rx_pending = priv->port_up ?
Eugenia Emantayev41d942d2013-11-07 12:19:52 +02001149 priv->rx_ring[0]->actual_size : priv->rx_ring[0]->size;
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001150 param->tx_pending = priv->tx_ring[TX][0]->size;
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07001151}
1152
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001153static u32 mlx4_en_get_rxfh_indir_size(struct net_device *dev)
1154{
1155 struct mlx4_en_priv *priv = netdev_priv(dev);
1156
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001157 return rounddown_pow_of_two(priv->rx_ring_num);
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001158}
1159
Eric Dumazetb9d1ab72014-11-16 06:23:16 -08001160static u32 mlx4_en_get_rxfh_key_size(struct net_device *netdev)
1161{
1162 return MLX4_EN_RSS_KEY_SIZE;
1163}
1164
Eyal Perry947cbb02014-12-02 18:12:11 +02001165static int mlx4_en_check_rxfh_func(struct net_device *dev, u8 hfunc)
1166{
1167 struct mlx4_en_priv *priv = netdev_priv(dev);
1168
1169 /* check if requested function is supported by the device */
Amir Vadaib3706902015-04-27 13:40:56 +03001170 if (hfunc == ETH_RSS_HASH_TOP) {
1171 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_TOP))
1172 return -EINVAL;
1173 if (!(dev->features & NETIF_F_RXHASH))
1174 en_warn(priv, "Toeplitz hash function should be used in conjunction with RX hashing for optimal performance\n");
1175 return 0;
1176 } else if (hfunc == ETH_RSS_HASH_XOR) {
1177 if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RSS_XOR))
1178 return -EINVAL;
1179 if (dev->features & NETIF_F_RXHASH)
1180 en_warn(priv, "Enabling both XOR Hash function and RX Hashing can limit RPS functionality\n");
1181 return 0;
1182 }
Eyal Perry947cbb02014-12-02 18:12:11 +02001183
Amir Vadaib3706902015-04-27 13:40:56 +03001184 return -EINVAL;
Eyal Perry947cbb02014-12-02 18:12:11 +02001185}
1186
Eyal Perry892311f2014-12-02 18:12:10 +02001187static int mlx4_en_get_rxfh(struct net_device *dev, u32 *ring_index, u8 *key,
1188 u8 *hfunc)
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001189{
1190 struct mlx4_en_priv *priv = netdev_priv(dev);
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001191 u32 n = mlx4_en_get_rxfh_indir_size(dev);
1192 u32 i, rss_rings;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001193 int err = 0;
1194
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001195 rss_rings = priv->prof->rss_rings ?: n;
1196 rss_rings = rounddown_pow_of_two(rss_rings);
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001197
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001198 for (i = 0; i < n; i++) {
Eyal Perry892311f2014-12-02 18:12:10 +02001199 if (!ring_index)
1200 break;
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001201 ring_index[i] = i % rss_rings;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001202 }
Eric Dumazetb9d1ab72014-11-16 06:23:16 -08001203 if (key)
Eric Dumazetbd635c32014-11-22 17:24:19 -08001204 memcpy(key, priv->rss_key, MLX4_EN_RSS_KEY_SIZE);
Eyal Perry892311f2014-12-02 18:12:10 +02001205 if (hfunc)
Eyal Perry947cbb02014-12-02 18:12:11 +02001206 *hfunc = priv->rss_hash_fn;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001207 return err;
1208}
1209
Ben Hutchingsfe62d002014-05-15 01:25:27 +01001210static int mlx4_en_set_rxfh(struct net_device *dev, const u32 *ring_index,
Eyal Perry892311f2014-12-02 18:12:10 +02001211 const u8 *key, const u8 hfunc)
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001212{
1213 struct mlx4_en_priv *priv = netdev_priv(dev);
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001214 u32 n = mlx4_en_get_rxfh_indir_size(dev);
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001215 struct mlx4_en_dev *mdev = priv->mdev;
1216 int port_up = 0;
1217 int err = 0;
1218 int i;
1219 int rss_rings = 0;
1220
1221 /* Calculate RSS table size and make sure flows are spread evenly
1222 * between rings
1223 */
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001224 for (i = 0; i < n; i++) {
Eric Dumazetbd635c32014-11-22 17:24:19 -08001225 if (!ring_index)
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001226 break;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001227 if (i > 0 && !ring_index[i] && !rss_rings)
1228 rss_rings = i;
1229
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001230 if (ring_index[i] != (i % (rss_rings ?: n)))
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001231 return -EINVAL;
1232 }
1233
1234 if (!rss_rings)
Eric Dumazetf7d3c1c2016-06-07 21:24:18 -07001235 rss_rings = n;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001236
1237 /* RSS table size must be an order of 2 */
1238 if (!is_power_of_2(rss_rings))
1239 return -EINVAL;
1240
Eyal Perry947cbb02014-12-02 18:12:11 +02001241 if (hfunc != ETH_RSS_HASH_NO_CHANGE) {
1242 err = mlx4_en_check_rxfh_func(dev, hfunc);
1243 if (err)
1244 return err;
1245 }
1246
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001247 mutex_lock(&mdev->state_lock);
1248 if (priv->port_up) {
1249 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +00001250 mlx4_en_stop_port(dev, 1);
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001251 }
1252
Eric Dumazetbd635c32014-11-22 17:24:19 -08001253 if (ring_index)
1254 priv->prof->rss_rings = rss_rings;
1255 if (key)
1256 memcpy(priv->rss_key, key, MLX4_EN_RSS_KEY_SIZE);
Amir Vadaib3706902015-04-27 13:40:56 +03001257 if (hfunc != ETH_RSS_HASH_NO_CHANGE)
1258 priv->rss_hash_fn = hfunc;
Eyal Perry947cbb02014-12-02 18:12:11 +02001259
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001260 if (port_up) {
1261 err = mlx4_en_start_port(dev);
1262 if (err)
1263 en_err(priv, "Failed starting port\n");
1264 }
1265
1266 mutex_unlock(&mdev->state_lock);
1267 return err;
1268}
1269
Hadar Hen Zion82067282012-07-05 04:03:49 +00001270#define all_zeros_or_all_ones(field) \
1271 ((field) == 0 || (field) == (__force typeof(field))-1)
1272
1273static int mlx4_en_validate_flow(struct net_device *dev,
1274 struct ethtool_rxnfc *cmd)
1275{
1276 struct ethtool_usrip4_spec *l3_mask;
1277 struct ethtool_tcpip4_spec *l4_mask;
1278 struct ethhdr *eth_mask;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001279
1280 if (cmd->fs.location >= MAX_NUM_OF_FS_RULES)
1281 return -EINVAL;
1282
Yan Burman520dfe32012-12-12 02:13:19 +00001283 if (cmd->fs.flow_type & FLOW_MAC_EXT) {
1284 /* dest mac mask must be ff:ff:ff:ff:ff:ff */
1285 if (!is_broadcast_ether_addr(cmd->fs.m_ext.h_dest))
1286 return -EINVAL;
1287 }
1288
1289 switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
Hadar Hen Zion82067282012-07-05 04:03:49 +00001290 case TCP_V4_FLOW:
1291 case UDP_V4_FLOW:
1292 if (cmd->fs.m_u.tcp_ip4_spec.tos)
1293 return -EINVAL;
1294 l4_mask = &cmd->fs.m_u.tcp_ip4_spec;
1295 /* don't allow mask which isn't all 0 or 1 */
1296 if (!all_zeros_or_all_ones(l4_mask->ip4src) ||
1297 !all_zeros_or_all_ones(l4_mask->ip4dst) ||
1298 !all_zeros_or_all_ones(l4_mask->psrc) ||
1299 !all_zeros_or_all_ones(l4_mask->pdst))
1300 return -EINVAL;
1301 break;
1302 case IP_USER_FLOW:
1303 l3_mask = &cmd->fs.m_u.usr_ip4_spec;
1304 if (l3_mask->l4_4_bytes || l3_mask->tos || l3_mask->proto ||
1305 cmd->fs.h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 ||
1306 (!l3_mask->ip4src && !l3_mask->ip4dst) ||
1307 !all_zeros_or_all_ones(l3_mask->ip4src) ||
1308 !all_zeros_or_all_ones(l3_mask->ip4dst))
1309 return -EINVAL;
1310 break;
1311 case ETHER_FLOW:
1312 eth_mask = &cmd->fs.m_u.ether_spec;
1313 /* source mac mask must not be set */
Yan Burmanc402b942012-12-12 02:13:18 +00001314 if (!is_zero_ether_addr(eth_mask->h_source))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001315 return -EINVAL;
1316
1317 /* dest mac mask must be ff:ff:ff:ff:ff:ff */
Yan Burmanc402b942012-12-12 02:13:18 +00001318 if (!is_broadcast_ether_addr(eth_mask->h_dest))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001319 return -EINVAL;
1320
1321 if (!all_zeros_or_all_ones(eth_mask->h_proto))
1322 return -EINVAL;
1323 break;
1324 default:
1325 return -EINVAL;
1326 }
1327
1328 if ((cmd->fs.flow_type & FLOW_EXT)) {
1329 if (cmd->fs.m_ext.vlan_etype ||
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001330 !((cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) ==
1331 0 ||
1332 (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) ==
1333 cpu_to_be16(VLAN_VID_MASK)))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001334 return -EINVAL;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001335
Hadar Hen Zion69d71262013-01-30 23:07:05 +00001336 if (cmd->fs.m_ext.vlan_tci) {
1337 if (be16_to_cpu(cmd->fs.h_ext.vlan_tci) >= VLAN_N_VID)
1338 return -EINVAL;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001339
Hadar Hen Zion69d71262013-01-30 23:07:05 +00001340 }
Hadar Hen Zion82067282012-07-05 04:03:49 +00001341 }
1342
1343 return 0;
1344}
1345
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001346static int mlx4_en_ethtool_add_mac_rule(struct ethtool_rxnfc *cmd,
1347 struct list_head *rule_list_h,
1348 struct mlx4_spec_list *spec_l2,
1349 unsigned char *mac)
Hadar Hen Zion82067282012-07-05 04:03:49 +00001350{
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001351 int err = 0;
1352 __be64 mac_msk = cpu_to_be64(MLX4_MAC_MASK << 16);
1353
1354 spec_l2->id = MLX4_NET_TRANS_RULE_ID_ETH;
1355 memcpy(spec_l2->eth.dst_mac_msk, &mac_msk, ETH_ALEN);
1356 memcpy(spec_l2->eth.dst_mac, mac, ETH_ALEN);
1357
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001358 if ((cmd->fs.flow_type & FLOW_EXT) &&
1359 (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK))) {
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001360 spec_l2->eth.vlan_id = cmd->fs.h_ext.vlan_tci;
Hadar Hen Zion8258bd22013-01-30 23:07:06 +00001361 spec_l2->eth.vlan_id_msk = cpu_to_be16(VLAN_VID_MASK);
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001362 }
1363
1364 list_add_tail(&spec_l2->list, rule_list_h);
1365
1366 return err;
1367}
1368
1369static int mlx4_en_ethtool_add_mac_rule_by_ipv4(struct mlx4_en_priv *priv,
1370 struct ethtool_rxnfc *cmd,
1371 struct list_head *rule_list_h,
1372 struct mlx4_spec_list *spec_l2,
1373 __be32 ipv4_dst)
1374{
Hadar Hen Zionf9d96862013-02-04 03:01:21 +00001375#ifdef CONFIG_INET
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001376 unsigned char mac[ETH_ALEN];
1377
1378 if (!ipv4_is_multicast(ipv4_dst)) {
Yan Burman6bbb6d92013-02-07 02:25:20 +00001379 if (cmd->fs.flow_type & FLOW_MAC_EXT)
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001380 memcpy(&mac, cmd->fs.h_ext.h_dest, ETH_ALEN);
Yan Burman6bbb6d92013-02-07 02:25:20 +00001381 else
1382 memcpy(&mac, priv->dev->dev_addr, ETH_ALEN);
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001383 } else {
1384 ip_eth_mc_map(ipv4_dst, mac);
1385 }
1386
1387 return mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2, &mac[0]);
Hadar Hen Zionf9d96862013-02-04 03:01:21 +00001388#else
1389 return -EINVAL;
1390#endif
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001391}
1392
1393static int add_ip_rule(struct mlx4_en_priv *priv,
1394 struct ethtool_rxnfc *cmd,
1395 struct list_head *list_h)
1396{
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001397 int err;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001398 struct mlx4_spec_list *spec_l2 = NULL;
1399 struct mlx4_spec_list *spec_l3 = NULL;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001400 struct ethtool_usrip4_spec *l3_mask = &cmd->fs.m_u.usr_ip4_spec;
1401
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001402 spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL);
1403 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
1404 if (!spec_l2 || !spec_l3) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001405 err = -ENOMEM;
1406 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001407 }
1408
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001409 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h, spec_l2,
1410 cmd->fs.h_u.
1411 usr_ip4_spec.ip4dst);
1412 if (err)
1413 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001414 spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4;
1415 spec_l3->ipv4.src_ip = cmd->fs.h_u.usr_ip4_spec.ip4src;
1416 if (l3_mask->ip4src)
1417 spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK;
1418 spec_l3->ipv4.dst_ip = cmd->fs.h_u.usr_ip4_spec.ip4dst;
1419 if (l3_mask->ip4dst)
1420 spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK;
1421 list_add_tail(&spec_l3->list, list_h);
1422
1423 return 0;
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001424
1425free_spec:
1426 kfree(spec_l2);
1427 kfree(spec_l3);
1428 return err;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001429}
1430
1431static int add_tcp_udp_rule(struct mlx4_en_priv *priv,
1432 struct ethtool_rxnfc *cmd,
1433 struct list_head *list_h, int proto)
1434{
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001435 int err;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001436 struct mlx4_spec_list *spec_l2 = NULL;
1437 struct mlx4_spec_list *spec_l3 = NULL;
1438 struct mlx4_spec_list *spec_l4 = NULL;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001439 struct ethtool_tcpip4_spec *l4_mask = &cmd->fs.m_u.tcp_ip4_spec;
1440
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001441 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
1442 spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL);
1443 spec_l4 = kzalloc(sizeof(*spec_l4), GFP_KERNEL);
1444 if (!spec_l2 || !spec_l3 || !spec_l4) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001445 err = -ENOMEM;
1446 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001447 }
1448
1449 spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4;
1450
1451 if (proto == TCP_V4_FLOW) {
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001452 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h,
1453 spec_l2,
1454 cmd->fs.h_u.
1455 tcp_ip4_spec.ip4dst);
1456 if (err)
1457 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001458 spec_l4->id = MLX4_NET_TRANS_RULE_ID_TCP;
1459 spec_l3->ipv4.src_ip = cmd->fs.h_u.tcp_ip4_spec.ip4src;
1460 spec_l3->ipv4.dst_ip = cmd->fs.h_u.tcp_ip4_spec.ip4dst;
1461 spec_l4->tcp_udp.src_port = cmd->fs.h_u.tcp_ip4_spec.psrc;
1462 spec_l4->tcp_udp.dst_port = cmd->fs.h_u.tcp_ip4_spec.pdst;
1463 } else {
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001464 err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h,
1465 spec_l2,
1466 cmd->fs.h_u.
1467 udp_ip4_spec.ip4dst);
1468 if (err)
1469 goto free_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001470 spec_l4->id = MLX4_NET_TRANS_RULE_ID_UDP;
1471 spec_l3->ipv4.src_ip = cmd->fs.h_u.udp_ip4_spec.ip4src;
1472 spec_l3->ipv4.dst_ip = cmd->fs.h_u.udp_ip4_spec.ip4dst;
1473 spec_l4->tcp_udp.src_port = cmd->fs.h_u.udp_ip4_spec.psrc;
1474 spec_l4->tcp_udp.dst_port = cmd->fs.h_u.udp_ip4_spec.pdst;
1475 }
1476
1477 if (l4_mask->ip4src)
1478 spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK;
1479 if (l4_mask->ip4dst)
1480 spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK;
1481
1482 if (l4_mask->psrc)
1483 spec_l4->tcp_udp.src_port_msk = EN_ETHTOOL_SHORT_MASK;
1484 if (l4_mask->pdst)
1485 spec_l4->tcp_udp.dst_port_msk = EN_ETHTOOL_SHORT_MASK;
1486
1487 list_add_tail(&spec_l3->list, list_h);
1488 list_add_tail(&spec_l4->list, list_h);
1489
1490 return 0;
Hadar Hen Zion377d9732013-02-04 03:01:20 +00001491
1492free_spec:
1493 kfree(spec_l2);
1494 kfree(spec_l3);
1495 kfree(spec_l4);
1496 return err;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001497}
1498
1499static int mlx4_en_ethtool_to_net_trans_rule(struct net_device *dev,
1500 struct ethtool_rxnfc *cmd,
1501 struct list_head *rule_list_h)
1502{
1503 int err;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001504 struct ethhdr *eth_spec;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001505 struct mlx4_spec_list *spec_l2;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001506 struct mlx4_en_priv *priv = netdev_priv(dev);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001507
1508 err = mlx4_en_validate_flow(dev, cmd);
1509 if (err)
1510 return err;
1511
Yan Burman520dfe32012-12-12 02:13:19 +00001512 switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
Hadar Hen Zion82067282012-07-05 04:03:49 +00001513 case ETHER_FLOW:
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001514 spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
1515 if (!spec_l2)
1516 return -ENOMEM;
1517
Hadar Hen Zion82067282012-07-05 04:03:49 +00001518 eth_spec = &cmd->fs.h_u.ether_spec;
Hadar Hen Zionf90a3672013-01-30 23:07:04 +00001519 mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2,
1520 &eth_spec->h_dest[0]);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001521 spec_l2->eth.ether_type = eth_spec->h_proto;
1522 if (eth_spec->h_proto)
1523 spec_l2->eth.ether_type_enable = 1;
1524 break;
1525 case IP_USER_FLOW:
1526 err = add_ip_rule(priv, cmd, rule_list_h);
1527 break;
1528 case TCP_V4_FLOW:
1529 err = add_tcp_udp_rule(priv, cmd, rule_list_h, TCP_V4_FLOW);
1530 break;
1531 case UDP_V4_FLOW:
1532 err = add_tcp_udp_rule(priv, cmd, rule_list_h, UDP_V4_FLOW);
1533 break;
1534 }
1535
1536 return err;
1537}
1538
1539static int mlx4_en_flow_replace(struct net_device *dev,
1540 struct ethtool_rxnfc *cmd)
1541{
1542 int err;
1543 struct mlx4_en_priv *priv = netdev_priv(dev);
1544 struct ethtool_flow_id *loc_rule;
1545 struct mlx4_spec_list *spec, *tmp_spec;
1546 u32 qpn;
1547 u64 reg_id;
1548
1549 struct mlx4_net_trans_rule rule = {
1550 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
1551 .exclusive = 0,
1552 .allow_loopback = 1,
Hadar Hen Zionf9162532013-04-24 13:58:45 +00001553 .promisc_mode = MLX4_FS_REGULAR,
Hadar Hen Zion82067282012-07-05 04:03:49 +00001554 };
1555
1556 rule.port = priv->port;
1557 rule.priority = MLX4_DOMAIN_ETHTOOL | cmd->fs.location;
1558 INIT_LIST_HEAD(&rule.list);
1559
1560 /* Allow direct QP attaches if the EN_ETHTOOL_QP_ATTACH flag is set */
1561 if (cmd->fs.ring_cookie == RX_CLS_FLOW_DISC)
Hadar Hen Zioncabdc8ee2012-07-05 04:03:50 +00001562 qpn = priv->drop_qp.qpn;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001563 else if (cmd->fs.ring_cookie & EN_ETHTOOL_QP_ATTACH) {
1564 qpn = cmd->fs.ring_cookie & (EN_ETHTOOL_QP_ATTACH - 1);
Talat Batheesh89c55762017-05-09 14:45:23 +03001565 if (qpn < priv->rss_map.base_qpn ||
1566 qpn >= priv->rss_map.base_qpn + priv->rx_ring_num) {
1567 en_warn(priv, "rxnfc: QP (0x%x) doesn't exist\n", qpn);
1568 return -EINVAL;
1569 }
Hadar Hen Zion82067282012-07-05 04:03:49 +00001570 } else {
1571 if (cmd->fs.ring_cookie >= priv->rx_ring_num) {
Joe Perches1a91de22014-05-07 12:52:57 -07001572 en_warn(priv, "rxnfc: RX ring (%llu) doesn't exist\n",
Hadar Hen Zion82067282012-07-05 04:03:49 +00001573 cmd->fs.ring_cookie);
1574 return -EINVAL;
1575 }
1576 qpn = priv->rss_map.qps[cmd->fs.ring_cookie].qpn;
1577 if (!qpn) {
Joe Perches1a91de22014-05-07 12:52:57 -07001578 en_warn(priv, "rxnfc: RX ring (%llu) is inactive\n",
Hadar Hen Zion82067282012-07-05 04:03:49 +00001579 cmd->fs.ring_cookie);
1580 return -EINVAL;
1581 }
1582 }
1583 rule.qpn = qpn;
1584 err = mlx4_en_ethtool_to_net_trans_rule(dev, cmd, &rule.list);
1585 if (err)
1586 goto out_free_list;
1587
1588 loc_rule = &priv->ethtool_rules[cmd->fs.location];
1589 if (loc_rule->id) {
1590 err = mlx4_flow_detach(priv->mdev->dev, loc_rule->id);
1591 if (err) {
1592 en_err(priv, "Fail to detach network rule at location %d. registration id = %llx\n",
1593 cmd->fs.location, loc_rule->id);
1594 goto out_free_list;
1595 }
1596 loc_rule->id = 0;
1597 memset(&loc_rule->flow_spec, 0,
1598 sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001599 list_del(&loc_rule->list);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001600 }
1601 err = mlx4_flow_attach(priv->mdev->dev, &rule, &reg_id);
1602 if (err) {
Joe Perches1a91de22014-05-07 12:52:57 -07001603 en_err(priv, "Fail to attach network rule at location %d\n",
Hadar Hen Zion82067282012-07-05 04:03:49 +00001604 cmd->fs.location);
1605 goto out_free_list;
1606 }
1607 loc_rule->id = reg_id;
1608 memcpy(&loc_rule->flow_spec, &cmd->fs,
1609 sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001610 list_add_tail(&loc_rule->list, &priv->ethtool_list);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001611
1612out_free_list:
1613 list_for_each_entry_safe(spec, tmp_spec, &rule.list, list) {
1614 list_del(&spec->list);
1615 kfree(spec);
1616 }
1617 return err;
1618}
1619
1620static int mlx4_en_flow_detach(struct net_device *dev,
1621 struct ethtool_rxnfc *cmd)
1622{
1623 int err = 0;
1624 struct ethtool_flow_id *rule;
1625 struct mlx4_en_priv *priv = netdev_priv(dev);
1626
1627 if (cmd->fs.location >= MAX_NUM_OF_FS_RULES)
1628 return -EINVAL;
1629
1630 rule = &priv->ethtool_rules[cmd->fs.location];
1631 if (!rule->id) {
1632 err = -ENOENT;
1633 goto out;
1634 }
1635
1636 err = mlx4_flow_detach(priv->mdev->dev, rule->id);
1637 if (err) {
1638 en_err(priv, "Fail to detach network rule at location %d. registration id = 0x%llx\n",
1639 cmd->fs.location, rule->id);
1640 goto out;
1641 }
1642 rule->id = 0;
1643 memset(&rule->flow_spec, 0, sizeof(struct ethtool_rx_flow_spec));
Hadar Hen Zion0d256c02013-01-30 23:07:08 +00001644 list_del(&rule->list);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001645out:
1646 return err;
1647
1648}
1649
1650static int mlx4_en_get_flow(struct net_device *dev, struct ethtool_rxnfc *cmd,
1651 int loc)
1652{
1653 int err = 0;
1654 struct ethtool_flow_id *rule;
1655 struct mlx4_en_priv *priv = netdev_priv(dev);
1656
1657 if (loc < 0 || loc >= MAX_NUM_OF_FS_RULES)
1658 return -EINVAL;
1659
1660 rule = &priv->ethtool_rules[loc];
1661 if (rule->id)
1662 memcpy(&cmd->fs, &rule->flow_spec,
1663 sizeof(struct ethtool_rx_flow_spec));
1664 else
1665 err = -ENOENT;
1666
1667 return err;
1668}
1669
1670static int mlx4_en_get_num_flows(struct mlx4_en_priv *priv)
1671{
1672
1673 int i, res = 0;
1674 for (i = 0; i < MAX_NUM_OF_FS_RULES; i++) {
1675 if (priv->ethtool_rules[i].id)
1676 res++;
1677 }
1678 return res;
1679
1680}
1681
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001682static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
1683 u32 *rule_locs)
1684{
1685 struct mlx4_en_priv *priv = netdev_priv(dev);
Hadar Hen Zion82067282012-07-05 04:03:49 +00001686 struct mlx4_en_dev *mdev = priv->mdev;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001687 int err = 0;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001688 int i = 0, priority = 0;
1689
1690 if ((cmd->cmd == ETHTOOL_GRXCLSRLCNT ||
1691 cmd->cmd == ETHTOOL_GRXCLSRULE ||
1692 cmd->cmd == ETHTOOL_GRXCLSRLALL) &&
Hadar Hen Zion280fce12013-01-30 23:07:07 +00001693 (mdev->dev->caps.steering_mode !=
1694 MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up))
Hadar Hen Zion82067282012-07-05 04:03:49 +00001695 return -EINVAL;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001696
1697 switch (cmd->cmd) {
1698 case ETHTOOL_GRXRINGS:
1699 cmd->data = priv->rx_ring_num;
1700 break;
Hadar Hen Zion82067282012-07-05 04:03:49 +00001701 case ETHTOOL_GRXCLSRLCNT:
1702 cmd->rule_cnt = mlx4_en_get_num_flows(priv);
1703 break;
1704 case ETHTOOL_GRXCLSRULE:
1705 err = mlx4_en_get_flow(dev, cmd, cmd->fs.location);
1706 break;
1707 case ETHTOOL_GRXCLSRLALL:
1708 while ((!err || err == -ENOENT) && priority < cmd->rule_cnt) {
1709 err = mlx4_en_get_flow(dev, cmd, i);
1710 if (!err)
1711 rule_locs[priority++] = i;
1712 i++;
1713 }
1714 err = 0;
1715 break;
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00001716 default:
1717 err = -EOPNOTSUPP;
1718 break;
1719 }
1720
1721 return err;
1722}
1723
Hadar Hen Zion82067282012-07-05 04:03:49 +00001724static int mlx4_en_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
1725{
1726 int err = 0;
1727 struct mlx4_en_priv *priv = netdev_priv(dev);
1728 struct mlx4_en_dev *mdev = priv->mdev;
1729
Hadar Hen Zion280fce12013-01-30 23:07:07 +00001730 if (mdev->dev->caps.steering_mode !=
1731 MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up)
Hadar Hen Zion82067282012-07-05 04:03:49 +00001732 return -EINVAL;
1733
1734 switch (cmd->cmd) {
1735 case ETHTOOL_SRXCLSRLINS:
1736 err = mlx4_en_flow_replace(dev, cmd);
1737 break;
1738 case ETHTOOL_SRXCLSRLDEL:
1739 err = mlx4_en_flow_detach(dev, cmd);
1740 break;
1741 default:
1742 en_warn(priv, "Unsupported ethtool command. (%d)\n", cmd->cmd);
1743 return -EINVAL;
1744 }
1745
1746 return err;
1747}
1748
Amir Vadaid3179662012-12-02 03:49:23 +00001749static void mlx4_en_get_channels(struct net_device *dev,
1750 struct ethtool_channels *channel)
1751{
1752 struct mlx4_en_priv *priv = netdev_priv(dev);
1753
Amir Vadaid3179662012-12-02 03:49:23 +00001754 channel->max_rx = MAX_RX_RINGS;
1755 channel->max_tx = MLX4_EN_MAX_TX_RING_P_UP;
1756
1757 channel->rx_count = priv->rx_ring_num;
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001758 channel->tx_count = priv->tx_ring_num[TX] / MLX4_EN_NUM_UP;
Amir Vadaid3179662012-12-02 03:49:23 +00001759}
1760
1761static int mlx4_en_set_channels(struct net_device *dev,
1762 struct ethtool_channels *channel)
1763{
1764 struct mlx4_en_priv *priv = netdev_priv(dev);
1765 struct mlx4_en_dev *mdev = priv->mdev;
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001766 struct mlx4_en_port_profile new_prof;
1767 struct mlx4_en_priv *tmp;
Christian Engelmayerda26a622014-05-17 23:52:03 +02001768 int port_up = 0;
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001769 int xdp_count;
Amir Vadaid3179662012-12-02 03:49:23 +00001770 int err = 0;
1771
Eran Ben Elishae91ef712017-01-17 19:19:18 +02001772 if (!channel->tx_count || !channel->rx_count)
Amir Vadaid3179662012-12-02 03:49:23 +00001773 return -EINVAL;
1774
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001775 tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
1776 if (!tmp)
1777 return -ENOMEM;
1778
Amir Vadaid3179662012-12-02 03:49:23 +00001779 mutex_lock(&mdev->state_lock);
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001780 xdp_count = priv->tx_ring_num[TX_XDP] ? channel->rx_count : 0;
1781 if (channel->tx_count * MLX4_EN_NUM_UP + xdp_count > MAX_TX_RINGS) {
1782 err = -EINVAL;
1783 en_err(priv,
1784 "Total number of TX and XDP rings (%d) exceeds the maximum supported (%d)\n",
1785 channel->tx_count * MLX4_EN_NUM_UP + xdp_count,
1786 MAX_TX_RINGS);
1787 goto out;
1788 }
1789
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001790 memcpy(&new_prof, priv->prof, sizeof(struct mlx4_en_port_profile));
1791 new_prof.num_tx_rings_p_up = channel->tx_count;
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001792 new_prof.tx_ring_num[TX] = channel->tx_count * MLX4_EN_NUM_UP;
1793 new_prof.tx_ring_num[TX_XDP] = xdp_count;
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001794 new_prof.rx_ring_num = channel->rx_count;
1795
Martin KaFai Lau770f8222017-01-31 22:35:33 -08001796 err = mlx4_en_try_alloc_resources(priv, tmp, &new_prof, true);
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001797 if (err)
1798 goto out;
1799
Amir Vadaid3179662012-12-02 03:49:23 +00001800 if (priv->port_up) {
1801 port_up = 1;
Amir Vadai3484aac2013-01-30 23:07:11 +00001802 mlx4_en_stop_port(dev, 1);
Amir Vadaid3179662012-12-02 03:49:23 +00001803 }
1804
Eugenia Emantayevec25bc02016-07-18 18:35:12 +03001805 mlx4_en_safe_replace_resources(priv, tmp);
Amir Vadaid3179662012-12-02 03:49:23 +00001806
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001807 netif_set_real_num_tx_queues(dev, priv->tx_ring_num[TX]);
Amir Vadaid3179662012-12-02 03:49:23 +00001808 netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
1809
Alaa Hleihel4b5e5b72017-01-29 18:56:16 +02001810 if (netdev_get_num_tc(dev))
Ido Shamayf5b63452014-05-14 12:15:11 +03001811 mlx4_en_setup_tc(dev, MLX4_EN_NUM_UP);
Amir Vadaid3179662012-12-02 03:49:23 +00001812
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001813 en_warn(priv, "Using %d TX rings\n", priv->tx_ring_num[TX]);
Amir Vadaid3179662012-12-02 03:49:23 +00001814 en_warn(priv, "Using %d RX rings\n", priv->rx_ring_num);
1815
1816 if (port_up) {
1817 err = mlx4_en_start_port(dev);
1818 if (err)
1819 en_err(priv, "Failed starting port\n");
1820 }
1821
1822 err = mlx4_en_moderation_update(priv);
Amir Vadaid3179662012-12-02 03:49:23 +00001823out:
1824 mutex_unlock(&mdev->state_lock);
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001825 kfree(tmp);
Amir Vadaid3179662012-12-02 03:49:23 +00001826 return err;
1827}
1828
Amir Vadaiec693d42013-04-23 06:06:49 +00001829static int mlx4_en_get_ts_info(struct net_device *dev,
1830 struct ethtool_ts_info *info)
1831{
1832 struct mlx4_en_priv *priv = netdev_priv(dev);
1833 struct mlx4_en_dev *mdev = priv->mdev;
1834 int ret;
1835
1836 ret = ethtool_op_get_ts_info(dev, info);
1837 if (ret)
1838 return ret;
1839
1840 if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) {
1841 info->so_timestamping |=
1842 SOF_TIMESTAMPING_TX_HARDWARE |
1843 SOF_TIMESTAMPING_RX_HARDWARE |
1844 SOF_TIMESTAMPING_RAW_HARDWARE;
1845
1846 info->tx_types =
1847 (1 << HWTSTAMP_TX_OFF) |
1848 (1 << HWTSTAMP_TX_ON);
1849
1850 info->rx_filters =
1851 (1 << HWTSTAMP_FILTER_NONE) |
1852 (1 << HWTSTAMP_FILTER_ALL);
Shawn Bohrerad7d4ea2013-12-31 11:39:39 -06001853
1854 if (mdev->ptp_clock)
1855 info->phc_index = ptp_clock_index(mdev->ptp_clock);
Amir Vadaiec693d42013-04-23 06:06:49 +00001856 }
1857
1858 return ret;
1859}
1860
Fengguang Wu3f6148e2014-07-24 09:11:46 +03001861static int mlx4_en_set_priv_flags(struct net_device *dev, u32 flags)
Amir Vadai0fef9d02014-07-22 15:44:10 +03001862{
1863 struct mlx4_en_priv *priv = netdev_priv(dev);
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03001864 struct mlx4_en_dev *mdev = priv->mdev;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001865 bool bf_enabled_new = !!(flags & MLX4_EN_PRIV_FLAGS_BLUEFLAME);
1866 bool bf_enabled_old = !!(priv->pflags & MLX4_EN_PRIV_FLAGS_BLUEFLAME);
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03001867 bool phv_enabled_new = !!(flags & MLX4_EN_PRIV_FLAGS_PHV);
1868 bool phv_enabled_old = !!(priv->pflags & MLX4_EN_PRIV_FLAGS_PHV);
Amir Vadai0fef9d02014-07-22 15:44:10 +03001869 int i;
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03001870 int ret = 0;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001871
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001872 if (bf_enabled_new != bf_enabled_old) {
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001873 int t;
1874
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001875 if (bf_enabled_new) {
1876 bool bf_supported = true;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001877
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001878 for (t = 0; t < MLX4_EN_NUM_TX_TYPES; t++)
1879 for (i = 0; i < priv->tx_ring_num[t]; i++)
1880 bf_supported &=
1881 priv->tx_ring[t][i]->bf_alloced;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001882
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001883 if (!bf_supported) {
1884 en_err(priv, "BlueFlame is not supported\n");
1885 return -EINVAL;
1886 }
Amir Vadai0fef9d02014-07-22 15:44:10 +03001887
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001888 priv->pflags |= MLX4_EN_PRIV_FLAGS_BLUEFLAME;
1889 } else {
1890 priv->pflags &= ~MLX4_EN_PRIV_FLAGS_BLUEFLAME;
Amir Vadai0fef9d02014-07-22 15:44:10 +03001891 }
1892
Tariq Toukan67f8b1d2016-11-02 17:12:24 +02001893 for (t = 0; t < MLX4_EN_NUM_TX_TYPES; t++)
1894 for (i = 0; i < priv->tx_ring_num[t]; i++)
1895 priv->tx_ring[t][i]->bf_enabled =
1896 bf_enabled_new;
Hadar Hen Zion7c509a42015-07-27 14:46:32 +03001897
1898 en_info(priv, "BlueFlame %s\n",
1899 bf_enabled_new ? "Enabled" : "Disabled");
Amir Vadai0fef9d02014-07-22 15:44:10 +03001900 }
1901
Hadar Hen Zione38af4f2015-07-27 14:46:34 +03001902 if (phv_enabled_new != phv_enabled_old) {
1903 ret = set_phv_bit(mdev->dev, priv->port, (int)phv_enabled_new);
1904 if (ret)
1905 return ret;
1906 else if (phv_enabled_new)
1907 priv->pflags |= MLX4_EN_PRIV_FLAGS_PHV;
1908 else
1909 priv->pflags &= ~MLX4_EN_PRIV_FLAGS_PHV;
1910 en_info(priv, "PHV bit %s\n",
1911 phv_enabled_new ? "Enabled" : "Disabled");
1912 }
Amir Vadai0fef9d02014-07-22 15:44:10 +03001913 return 0;
1914}
1915
Fengguang Wu3f6148e2014-07-24 09:11:46 +03001916static u32 mlx4_en_get_priv_flags(struct net_device *dev)
Amir Vadai0fef9d02014-07-22 15:44:10 +03001917{
1918 struct mlx4_en_priv *priv = netdev_priv(dev);
1919
1920 return priv->pflags;
1921}
1922
Eric Dumazet1556b872014-10-05 12:35:22 +03001923static int mlx4_en_get_tunable(struct net_device *dev,
1924 const struct ethtool_tunable *tuna,
1925 void *data)
1926{
1927 const struct mlx4_en_priv *priv = netdev_priv(dev);
1928 int ret = 0;
1929
1930 switch (tuna->id) {
1931 case ETHTOOL_TX_COPYBREAK:
1932 *(u32 *)data = priv->prof->inline_thold;
1933 break;
1934 default:
1935 ret = -EINVAL;
1936 break;
1937 }
1938
1939 return ret;
1940}
1941
1942static int mlx4_en_set_tunable(struct net_device *dev,
1943 const struct ethtool_tunable *tuna,
1944 const void *data)
1945{
1946 struct mlx4_en_priv *priv = netdev_priv(dev);
1947 int val, ret = 0;
1948
1949 switch (tuna->id) {
1950 case ETHTOOL_TX_COPYBREAK:
1951 val = *(u32 *)data;
1952 if (val < MIN_PKT_LEN || val > MAX_INLINE)
1953 ret = -EINVAL;
1954 else
1955 priv->prof->inline_thold = val;
1956 break;
1957 default:
1958 ret = -EINVAL;
1959 break;
1960 }
1961
1962 return ret;
1963}
1964
Saeed Mahameed7202da82014-10-27 11:37:36 +02001965static int mlx4_en_get_module_info(struct net_device *dev,
1966 struct ethtool_modinfo *modinfo)
1967{
1968 struct mlx4_en_priv *priv = netdev_priv(dev);
1969 struct mlx4_en_dev *mdev = priv->mdev;
1970 int ret;
1971 u8 data[4];
1972
1973 /* Read first 2 bytes to get Module & REV ID */
1974 ret = mlx4_get_module_info(mdev->dev, priv->port,
1975 0/*offset*/, 2/*size*/, data);
1976 if (ret < 2)
1977 return -EIO;
1978
1979 switch (data[0] /* identifier */) {
1980 case MLX4_MODULE_ID_QSFP:
1981 modinfo->type = ETH_MODULE_SFF_8436;
1982 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1983 break;
1984 case MLX4_MODULE_ID_QSFP_PLUS:
1985 if (data[1] >= 0x3) { /* revision id */
1986 modinfo->type = ETH_MODULE_SFF_8636;
1987 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1988 } else {
1989 modinfo->type = ETH_MODULE_SFF_8436;
1990 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1991 }
1992 break;
1993 case MLX4_MODULE_ID_QSFP28:
1994 modinfo->type = ETH_MODULE_SFF_8636;
1995 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1996 break;
1997 case MLX4_MODULE_ID_SFP:
1998 modinfo->type = ETH_MODULE_SFF_8472;
1999 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
2000 break;
2001 default:
Tariq Toukan72b8eaa2017-01-29 18:56:13 +02002002 return -EINVAL;
Saeed Mahameed7202da82014-10-27 11:37:36 +02002003 }
2004
2005 return 0;
2006}
2007
2008static int mlx4_en_get_module_eeprom(struct net_device *dev,
2009 struct ethtool_eeprom *ee,
2010 u8 *data)
2011{
2012 struct mlx4_en_priv *priv = netdev_priv(dev);
2013 struct mlx4_en_dev *mdev = priv->mdev;
2014 int offset = ee->offset;
2015 int i = 0, ret;
2016
2017 if (ee->len == 0)
2018 return -EINVAL;
2019
2020 memset(data, 0, ee->len);
2021
2022 while (i < ee->len) {
2023 en_dbg(DRV, priv,
2024 "mlx4_get_module_info i(%d) offset(%d) len(%d)\n",
2025 i, offset, ee->len - i);
2026
2027 ret = mlx4_get_module_info(mdev->dev, priv->port,
2028 offset, ee->len - i, data + i);
2029
2030 if (!ret) /* Done reading */
2031 return 0;
2032
2033 if (ret < 0) {
2034 en_err(priv,
2035 "mlx4_get_module_info i(%d) offset(%d) bytes_to_read(%d) - FAILED (0x%x)\n",
2036 i, offset, ee->len - i, ret);
2037 return 0;
2038 }
2039
2040 i += ret;
2041 offset += ret;
2042 }
2043 return 0;
2044}
Amir Vadai0fef9d02014-07-22 15:44:10 +03002045
Ido Shamay51af33c2015-04-02 16:31:20 +03002046static int mlx4_en_set_phys_id(struct net_device *dev,
2047 enum ethtool_phys_id_state state)
2048{
2049 int err;
2050 u16 beacon_duration;
2051 struct mlx4_en_priv *priv = netdev_priv(dev);
2052 struct mlx4_en_dev *mdev = priv->mdev;
2053
2054 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PORT_BEACON))
2055 return -EOPNOTSUPP;
2056
2057 switch (state) {
2058 case ETHTOOL_ID_ACTIVE:
2059 beacon_duration = PORT_BEACON_MAX_LIMIT;
2060 break;
2061 case ETHTOOL_ID_INACTIVE:
2062 beacon_duration = 0;
2063 break;
2064 default:
2065 return -EOPNOTSUPP;
2066 }
2067
2068 err = mlx4_SET_PORT_BEACON(mdev->dev, priv->port, beacon_duration);
2069 return err;
2070}
2071
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002072const struct ethtool_ops mlx4_en_ethtool_ops = {
2073 .get_drvinfo = mlx4_en_get_drvinfo,
David Decotigny3d8f7cc2016-02-24 10:58:12 -08002074 .get_link_ksettings = mlx4_en_get_link_ksettings,
2075 .set_link_ksettings = mlx4_en_set_link_ksettings,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002076 .get_link = ethtool_op_get_link,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002077 .get_strings = mlx4_en_get_strings,
2078 .get_sset_count = mlx4_en_get_sset_count,
2079 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +00002080 .self_test = mlx4_en_self_test,
Ido Shamay51af33c2015-04-02 16:31:20 +03002081 .set_phys_id = mlx4_en_set_phys_id,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002082 .get_wol = mlx4_en_get_wol,
Yevgeny Petrilin14c07b12011-03-22 22:37:59 +00002083 .set_wol = mlx4_en_set_wol,
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002084 .get_msglevel = mlx4_en_get_msglevel,
2085 .set_msglevel = mlx4_en_set_msglevel,
2086 .get_coalesce = mlx4_en_get_coalesce,
2087 .set_coalesce = mlx4_en_set_coalesce,
2088 .get_pauseparam = mlx4_en_get_pauseparam,
2089 .set_pauseparam = mlx4_en_set_pauseparam,
2090 .get_ringparam = mlx4_en_get_ringparam,
Yevgeny Petrilin18cc42a2008-12-29 18:39:20 -08002091 .set_ringparam = mlx4_en_set_ringparam,
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00002092 .get_rxnfc = mlx4_en_get_rxnfc,
Hadar Hen Zion82067282012-07-05 04:03:49 +00002093 .set_rxnfc = mlx4_en_set_rxnfc,
Yevgeny Petrilin93d3e362012-01-17 22:54:55 +00002094 .get_rxfh_indir_size = mlx4_en_get_rxfh_indir_size,
Eric Dumazetb9d1ab72014-11-16 06:23:16 -08002095 .get_rxfh_key_size = mlx4_en_get_rxfh_key_size,
Ben Hutchingsfe62d002014-05-15 01:25:27 +01002096 .get_rxfh = mlx4_en_get_rxfh,
2097 .set_rxfh = mlx4_en_set_rxfh,
Amir Vadaid3179662012-12-02 03:49:23 +00002098 .get_channels = mlx4_en_get_channels,
2099 .set_channels = mlx4_en_set_channels,
Amir Vadaiec693d42013-04-23 06:06:49 +00002100 .get_ts_info = mlx4_en_get_ts_info,
Amir Vadai0fef9d02014-07-22 15:44:10 +03002101 .set_priv_flags = mlx4_en_set_priv_flags,
2102 .get_priv_flags = mlx4_en_get_priv_flags,
Eric Dumazet1556b872014-10-05 12:35:22 +03002103 .get_tunable = mlx4_en_get_tunable,
2104 .set_tunable = mlx4_en_set_tunable,
Saeed Mahameed7202da82014-10-27 11:37:36 +02002105 .get_module_info = mlx4_en_get_module_info,
2106 .get_module_eeprom = mlx4_en_get_module_eeprom
Yevgeny Petrilinc27a02c2008-10-22 15:47:49 -07002107};
2108
2109
2110
2111
2112