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