2 * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
34 #include <linux/kernel.h>
35 #include <linux/ethtool.h>
36 #include <linux/netdevice.h>
37 #include <linux/mlx4/driver.h>
44 #define EN_ETHTOOL_QP_ATTACH (1ull << 63)
45 #define EN_ETHTOOL_SHORT_MASK cpu_to_be16(0xffff)
46 #define EN_ETHTOOL_WORD_MASK cpu_to_be32(0xffffffff)
48 static int mlx4_en_moderation_update(struct mlx4_en_priv
*priv
)
53 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
54 priv
->tx_cq
[i
].moder_cnt
= priv
->tx_frames
;
55 priv
->tx_cq
[i
].moder_time
= priv
->tx_usecs
;
56 err
= mlx4_en_set_cq_moder(priv
, &priv
->tx_cq
[i
]);
61 if (priv
->adaptive_rx_coal
)
64 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
65 priv
->rx_cq
[i
].moder_cnt
= priv
->rx_frames
;
66 priv
->rx_cq
[i
].moder_time
= priv
->rx_usecs
;
67 priv
->last_moder_time
[i
] = MLX4_EN_AUTO_CONF
;
68 err
= mlx4_en_set_cq_moder(priv
, &priv
->rx_cq
[i
]);
77 mlx4_en_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*drvinfo
)
79 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
80 struct mlx4_en_dev
*mdev
= priv
->mdev
;
82 strlcpy(drvinfo
->driver
, DRV_NAME
, sizeof(drvinfo
->driver
));
83 strlcpy(drvinfo
->version
, DRV_VERSION
" (" DRV_RELDATE
")",
84 sizeof(drvinfo
->version
));
85 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
),
87 (u16
) (mdev
->dev
->caps
.fw_ver
>> 32),
88 (u16
) ((mdev
->dev
->caps
.fw_ver
>> 16) & 0xffff),
89 (u16
) (mdev
->dev
->caps
.fw_ver
& 0xffff));
90 strlcpy(drvinfo
->bus_info
, pci_name(mdev
->dev
->pdev
),
91 sizeof(drvinfo
->bus_info
));
93 drvinfo
->regdump_len
= 0;
94 drvinfo
->eedump_len
= 0;
97 static const char main_strings
[][ETH_GSTRING_LEN
] = {
98 "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
99 "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
100 "rx_length_errors", "rx_over_errors", "rx_crc_errors",
101 "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
102 "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
103 "tx_heartbeat_errors", "tx_window_errors",
105 /* port statistics */
107 "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
108 "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
110 /* packet statistics */
111 "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
112 "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
113 "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
114 "tx_prio_6", "tx_prio_7",
116 #define NUM_MAIN_STATS 21
117 #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
119 static const char mlx4_en_test_names
[][ETH_GSTRING_LEN
]= {
127 static u32
mlx4_en_get_msglevel(struct net_device
*dev
)
129 return ((struct mlx4_en_priv
*) netdev_priv(dev
))->msg_enable
;
132 static void mlx4_en_set_msglevel(struct net_device
*dev
, u32 val
)
134 ((struct mlx4_en_priv
*) netdev_priv(dev
))->msg_enable
= val
;
137 static void mlx4_en_get_wol(struct net_device
*netdev
,
138 struct ethtool_wolinfo
*wol
)
140 struct mlx4_en_priv
*priv
= netdev_priv(netdev
);
145 if ((priv
->port
< 1) || (priv
->port
> 2)) {
146 en_err(priv
, "Failed to get WoL information\n");
150 mask
= (priv
->port
== 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1
:
151 MLX4_DEV_CAP_FLAG_WOL_PORT2
;
153 if (!(priv
->mdev
->dev
->caps
.flags
& mask
)) {
159 err
= mlx4_wol_read(priv
->mdev
->dev
, &config
, priv
->port
);
161 en_err(priv
, "Failed to get WoL information\n");
165 if (config
& MLX4_EN_WOL_MAGIC
)
166 wol
->supported
= WAKE_MAGIC
;
170 if (config
& MLX4_EN_WOL_ENABLED
)
171 wol
->wolopts
= WAKE_MAGIC
;
176 static int mlx4_en_set_wol(struct net_device
*netdev
,
177 struct ethtool_wolinfo
*wol
)
179 struct mlx4_en_priv
*priv
= netdev_priv(netdev
);
184 if ((priv
->port
< 1) || (priv
->port
> 2))
187 mask
= (priv
->port
== 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1
:
188 MLX4_DEV_CAP_FLAG_WOL_PORT2
;
190 if (!(priv
->mdev
->dev
->caps
.flags
& mask
))
193 if (wol
->supported
& ~WAKE_MAGIC
)
196 err
= mlx4_wol_read(priv
->mdev
->dev
, &config
, priv
->port
);
198 en_err(priv
, "Failed to get WoL info, unable to modify\n");
202 if (wol
->wolopts
& WAKE_MAGIC
) {
203 config
|= MLX4_EN_WOL_DO_MODIFY
| MLX4_EN_WOL_ENABLED
|
206 config
&= ~(MLX4_EN_WOL_ENABLED
| MLX4_EN_WOL_MAGIC
);
207 config
|= MLX4_EN_WOL_DO_MODIFY
;
210 err
= mlx4_wol_write(priv
->mdev
->dev
, config
, priv
->port
);
212 en_err(priv
, "Failed to set WoL information\n");
217 static int mlx4_en_get_sset_count(struct net_device
*dev
, int sset
)
219 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
220 int bit_count
= hweight64(priv
->stats_bitmap
);
224 return (priv
->stats_bitmap
? bit_count
: NUM_ALL_STATS
) +
225 (priv
->tx_ring_num
+ priv
->rx_ring_num
) * 2;
227 return MLX4_EN_NUM_SELF_TEST
- !(priv
->mdev
->dev
->caps
.flags
228 & MLX4_DEV_CAP_FLAG_UC_LOOPBACK
) * 2;
234 static void mlx4_en_get_ethtool_stats(struct net_device
*dev
,
235 struct ethtool_stats
*stats
, uint64_t *data
)
237 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
241 spin_lock_bh(&priv
->stats_lock
);
243 if (!(priv
->stats_bitmap
)) {
244 for (i
= 0; i
< NUM_MAIN_STATS
; i
++)
246 ((unsigned long *) &priv
->stats
)[i
];
247 for (i
= 0; i
< NUM_PORT_STATS
; i
++)
249 ((unsigned long *) &priv
->port_stats
)[i
];
250 for (i
= 0; i
< NUM_PKT_STATS
; i
++)
252 ((unsigned long *) &priv
->pkstats
)[i
];
254 for (i
= 0; i
< NUM_MAIN_STATS
; i
++) {
255 if ((priv
->stats_bitmap
>> j
) & 1)
257 ((unsigned long *) &priv
->stats
)[i
];
260 for (i
= 0; i
< NUM_PORT_STATS
; i
++) {
261 if ((priv
->stats_bitmap
>> j
) & 1)
263 ((unsigned long *) &priv
->port_stats
)[i
];
267 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
268 data
[index
++] = priv
->tx_ring
[i
].packets
;
269 data
[index
++] = priv
->tx_ring
[i
].bytes
;
271 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
272 data
[index
++] = priv
->rx_ring
[i
].packets
;
273 data
[index
++] = priv
->rx_ring
[i
].bytes
;
275 spin_unlock_bh(&priv
->stats_lock
);
279 static void mlx4_en_self_test(struct net_device
*dev
,
280 struct ethtool_test
*etest
, u64
*buf
)
282 mlx4_en_ex_selftest(dev
, &etest
->flags
, buf
);
285 static void mlx4_en_get_strings(struct net_device
*dev
,
286 uint32_t stringset
, uint8_t *data
)
288 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
294 for (i
= 0; i
< MLX4_EN_NUM_SELF_TEST
- 2; i
++)
295 strcpy(data
+ i
* ETH_GSTRING_LEN
, mlx4_en_test_names
[i
]);
296 if (priv
->mdev
->dev
->caps
.flags
& MLX4_DEV_CAP_FLAG_UC_LOOPBACK
)
297 for (; i
< MLX4_EN_NUM_SELF_TEST
; i
++)
298 strcpy(data
+ i
* ETH_GSTRING_LEN
, mlx4_en_test_names
[i
]);
302 /* Add main counters */
303 if (!priv
->stats_bitmap
) {
304 for (i
= 0; i
< NUM_MAIN_STATS
; i
++)
305 strcpy(data
+ (index
++) * ETH_GSTRING_LEN
,
307 for (i
= 0; i
< NUM_PORT_STATS
; i
++)
308 strcpy(data
+ (index
++) * ETH_GSTRING_LEN
,
311 for (i
= 0; i
< NUM_PKT_STATS
; i
++)
312 strcpy(data
+ (index
++) * ETH_GSTRING_LEN
,
317 for (i
= 0; i
< NUM_MAIN_STATS
+ NUM_PORT_STATS
; i
++) {
318 if ((priv
->stats_bitmap
>> i
) & 1) {
320 (index
++) * ETH_GSTRING_LEN
,
323 if (!(priv
->stats_bitmap
>> i
))
326 for (i
= 0; i
< priv
->tx_ring_num
; i
++) {
327 sprintf(data
+ (index
++) * ETH_GSTRING_LEN
,
329 sprintf(data
+ (index
++) * ETH_GSTRING_LEN
,
332 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
333 sprintf(data
+ (index
++) * ETH_GSTRING_LEN
,
335 sprintf(data
+ (index
++) * ETH_GSTRING_LEN
,
342 static int mlx4_en_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
344 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
347 cmd
->autoneg
= AUTONEG_DISABLE
;
348 cmd
->supported
= SUPPORTED_10000baseT_Full
;
349 cmd
->advertising
= ADVERTISED_10000baseT_Full
;
351 if (mlx4_en_QUERY_PORT(priv
->mdev
, priv
->port
))
354 trans_type
= priv
->port_state
.transciver
;
355 if (netif_carrier_ok(dev
)) {
356 ethtool_cmd_speed_set(cmd
, priv
->port_state
.link_speed
);
357 cmd
->duplex
= DUPLEX_FULL
;
359 ethtool_cmd_speed_set(cmd
, -1);
363 if (trans_type
> 0 && trans_type
<= 0xC) {
364 cmd
->port
= PORT_FIBRE
;
365 cmd
->transceiver
= XCVR_EXTERNAL
;
366 cmd
->supported
|= SUPPORTED_FIBRE
;
367 cmd
->advertising
|= ADVERTISED_FIBRE
;
368 } else if (trans_type
== 0x80 || trans_type
== 0) {
370 cmd
->transceiver
= XCVR_INTERNAL
;
371 cmd
->supported
|= SUPPORTED_TP
;
372 cmd
->advertising
|= ADVERTISED_TP
;
375 cmd
->transceiver
= -1;
380 static int mlx4_en_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
382 if ((cmd
->autoneg
== AUTONEG_ENABLE
) ||
383 (ethtool_cmd_speed(cmd
) != SPEED_10000
) ||
384 (cmd
->duplex
!= DUPLEX_FULL
))
387 /* Nothing to change */
391 static int mlx4_en_get_coalesce(struct net_device
*dev
,
392 struct ethtool_coalesce
*coal
)
394 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
396 coal
->tx_coalesce_usecs
= priv
->tx_usecs
;
397 coal
->tx_max_coalesced_frames
= priv
->tx_frames
;
398 coal
->rx_coalesce_usecs
= priv
->rx_usecs
;
399 coal
->rx_max_coalesced_frames
= priv
->rx_frames
;
401 coal
->pkt_rate_low
= priv
->pkt_rate_low
;
402 coal
->rx_coalesce_usecs_low
= priv
->rx_usecs_low
;
403 coal
->pkt_rate_high
= priv
->pkt_rate_high
;
404 coal
->rx_coalesce_usecs_high
= priv
->rx_usecs_high
;
405 coal
->rate_sample_interval
= priv
->sample_interval
;
406 coal
->use_adaptive_rx_coalesce
= priv
->adaptive_rx_coal
;
410 static int mlx4_en_set_coalesce(struct net_device
*dev
,
411 struct ethtool_coalesce
*coal
)
413 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
415 priv
->rx_frames
= (coal
->rx_max_coalesced_frames
==
417 MLX4_EN_RX_COAL_TARGET
:
418 coal
->rx_max_coalesced_frames
;
419 priv
->rx_usecs
= (coal
->rx_coalesce_usecs
==
421 MLX4_EN_RX_COAL_TIME
:
422 coal
->rx_coalesce_usecs
;
424 /* Setting TX coalescing parameters */
425 if (coal
->tx_coalesce_usecs
!= priv
->tx_usecs
||
426 coal
->tx_max_coalesced_frames
!= priv
->tx_frames
) {
427 priv
->tx_usecs
= coal
->tx_coalesce_usecs
;
428 priv
->tx_frames
= coal
->tx_max_coalesced_frames
;
431 /* Set adaptive coalescing params */
432 priv
->pkt_rate_low
= coal
->pkt_rate_low
;
433 priv
->rx_usecs_low
= coal
->rx_coalesce_usecs_low
;
434 priv
->pkt_rate_high
= coal
->pkt_rate_high
;
435 priv
->rx_usecs_high
= coal
->rx_coalesce_usecs_high
;
436 priv
->sample_interval
= coal
->rate_sample_interval
;
437 priv
->adaptive_rx_coal
= coal
->use_adaptive_rx_coalesce
;
439 return mlx4_en_moderation_update(priv
);
442 static int mlx4_en_set_pauseparam(struct net_device
*dev
,
443 struct ethtool_pauseparam
*pause
)
445 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
446 struct mlx4_en_dev
*mdev
= priv
->mdev
;
449 priv
->prof
->tx_pause
= pause
->tx_pause
!= 0;
450 priv
->prof
->rx_pause
= pause
->rx_pause
!= 0;
451 err
= mlx4_SET_PORT_general(mdev
->dev
, priv
->port
,
452 priv
->rx_skb_size
+ ETH_FCS_LEN
,
453 priv
->prof
->tx_pause
,
455 priv
->prof
->rx_pause
,
458 en_err(priv
, "Failed setting pause params\n");
463 static void mlx4_en_get_pauseparam(struct net_device
*dev
,
464 struct ethtool_pauseparam
*pause
)
466 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
468 pause
->tx_pause
= priv
->prof
->tx_pause
;
469 pause
->rx_pause
= priv
->prof
->rx_pause
;
472 static int mlx4_en_set_ringparam(struct net_device
*dev
,
473 struct ethtool_ringparam
*param
)
475 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
476 struct mlx4_en_dev
*mdev
= priv
->mdev
;
477 u32 rx_size
, tx_size
;
481 if (param
->rx_jumbo_pending
|| param
->rx_mini_pending
)
484 rx_size
= roundup_pow_of_two(param
->rx_pending
);
485 rx_size
= max_t(u32
, rx_size
, MLX4_EN_MIN_RX_SIZE
);
486 rx_size
= min_t(u32
, rx_size
, MLX4_EN_MAX_RX_SIZE
);
487 tx_size
= roundup_pow_of_two(param
->tx_pending
);
488 tx_size
= max_t(u32
, tx_size
, MLX4_EN_MIN_TX_SIZE
);
489 tx_size
= min_t(u32
, tx_size
, MLX4_EN_MAX_TX_SIZE
);
491 if (rx_size
== (priv
->port_up
? priv
->rx_ring
[0].actual_size
:
492 priv
->rx_ring
[0].size
) &&
493 tx_size
== priv
->tx_ring
[0].size
)
496 mutex_lock(&mdev
->state_lock
);
499 mlx4_en_stop_port(dev
, 1);
502 mlx4_en_free_resources(priv
);
504 priv
->prof
->tx_ring_size
= tx_size
;
505 priv
->prof
->rx_ring_size
= rx_size
;
507 err
= mlx4_en_alloc_resources(priv
);
509 en_err(priv
, "Failed reallocating port resources\n");
513 err
= mlx4_en_start_port(dev
);
515 en_err(priv
, "Failed starting port\n");
518 err
= mlx4_en_moderation_update(priv
);
521 mutex_unlock(&mdev
->state_lock
);
525 static void mlx4_en_get_ringparam(struct net_device
*dev
,
526 struct ethtool_ringparam
*param
)
528 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
530 memset(param
, 0, sizeof(*param
));
531 param
->rx_max_pending
= MLX4_EN_MAX_RX_SIZE
;
532 param
->tx_max_pending
= MLX4_EN_MAX_TX_SIZE
;
533 param
->rx_pending
= priv
->port_up
?
534 priv
->rx_ring
[0].actual_size
: priv
->rx_ring
[0].size
;
535 param
->tx_pending
= priv
->tx_ring
[0].size
;
538 static u32
mlx4_en_get_rxfh_indir_size(struct net_device
*dev
)
540 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
542 return priv
->rx_ring_num
;
545 static int mlx4_en_get_rxfh_indir(struct net_device
*dev
, u32
*ring_index
)
547 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
548 struct mlx4_en_rss_map
*rss_map
= &priv
->rss_map
;
550 size_t n
= priv
->rx_ring_num
;
553 rss_rings
= priv
->prof
->rss_rings
?: priv
->rx_ring_num
;
556 ring_index
[n
] = rss_map
->qps
[n
% rss_rings
].qpn
-
563 static int mlx4_en_set_rxfh_indir(struct net_device
*dev
,
564 const u32
*ring_index
)
566 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
567 struct mlx4_en_dev
*mdev
= priv
->mdev
;
573 /* Calculate RSS table size and make sure flows are spread evenly
576 for (i
= 0; i
< priv
->rx_ring_num
; i
++) {
577 if (i
> 0 && !ring_index
[i
] && !rss_rings
)
580 if (ring_index
[i
] != (i
% (rss_rings
?: priv
->rx_ring_num
)))
585 rss_rings
= priv
->rx_ring_num
;
587 /* RSS table size must be an order of 2 */
588 if (!is_power_of_2(rss_rings
))
591 mutex_lock(&mdev
->state_lock
);
594 mlx4_en_stop_port(dev
, 1);
597 priv
->prof
->rss_rings
= rss_rings
;
600 err
= mlx4_en_start_port(dev
);
602 en_err(priv
, "Failed starting port\n");
605 mutex_unlock(&mdev
->state_lock
);
609 #define all_zeros_or_all_ones(field) \
610 ((field) == 0 || (field) == (__force typeof(field))-1)
612 static int mlx4_en_validate_flow(struct net_device
*dev
,
613 struct ethtool_rxnfc
*cmd
)
615 struct ethtool_usrip4_spec
*l3_mask
;
616 struct ethtool_tcpip4_spec
*l4_mask
;
617 struct ethhdr
*eth_mask
;
619 if (cmd
->fs
.location
>= MAX_NUM_OF_FS_RULES
)
622 if (cmd
->fs
.flow_type
& FLOW_MAC_EXT
) {
623 /* dest mac mask must be ff:ff:ff:ff:ff:ff */
624 if (!is_broadcast_ether_addr(cmd
->fs
.m_ext
.h_dest
))
628 switch (cmd
->fs
.flow_type
& ~(FLOW_EXT
| FLOW_MAC_EXT
)) {
631 if (cmd
->fs
.m_u
.tcp_ip4_spec
.tos
)
633 l4_mask
= &cmd
->fs
.m_u
.tcp_ip4_spec
;
634 /* don't allow mask which isn't all 0 or 1 */
635 if (!all_zeros_or_all_ones(l4_mask
->ip4src
) ||
636 !all_zeros_or_all_ones(l4_mask
->ip4dst
) ||
637 !all_zeros_or_all_ones(l4_mask
->psrc
) ||
638 !all_zeros_or_all_ones(l4_mask
->pdst
))
642 l3_mask
= &cmd
->fs
.m_u
.usr_ip4_spec
;
643 if (l3_mask
->l4_4_bytes
|| l3_mask
->tos
|| l3_mask
->proto
||
644 cmd
->fs
.h_u
.usr_ip4_spec
.ip_ver
!= ETH_RX_NFC_IP4
||
645 (!l3_mask
->ip4src
&& !l3_mask
->ip4dst
) ||
646 !all_zeros_or_all_ones(l3_mask
->ip4src
) ||
647 !all_zeros_or_all_ones(l3_mask
->ip4dst
))
651 eth_mask
= &cmd
->fs
.m_u
.ether_spec
;
652 /* source mac mask must not be set */
653 if (!is_zero_ether_addr(eth_mask
->h_source
))
656 /* dest mac mask must be ff:ff:ff:ff:ff:ff */
657 if (!is_broadcast_ether_addr(eth_mask
->h_dest
))
660 if (!all_zeros_or_all_ones(eth_mask
->h_proto
))
667 if ((cmd
->fs
.flow_type
& FLOW_EXT
)) {
668 if (cmd
->fs
.m_ext
.vlan_etype
||
669 !((cmd
->fs
.m_ext
.vlan_tci
& cpu_to_be16(VLAN_VID_MASK
)) ==
671 (cmd
->fs
.m_ext
.vlan_tci
& cpu_to_be16(VLAN_VID_MASK
)) ==
672 cpu_to_be16(VLAN_VID_MASK
)))
675 if (cmd
->fs
.m_ext
.vlan_tci
) {
676 if (be16_to_cpu(cmd
->fs
.h_ext
.vlan_tci
) >= VLAN_N_VID
)
685 static int mlx4_en_ethtool_add_mac_rule(struct ethtool_rxnfc
*cmd
,
686 struct list_head
*rule_list_h
,
687 struct mlx4_spec_list
*spec_l2
,
691 __be64 mac_msk
= cpu_to_be64(MLX4_MAC_MASK
<< 16);
693 spec_l2
->id
= MLX4_NET_TRANS_RULE_ID_ETH
;
694 memcpy(spec_l2
->eth
.dst_mac_msk
, &mac_msk
, ETH_ALEN
);
695 memcpy(spec_l2
->eth
.dst_mac
, mac
, ETH_ALEN
);
697 if ((cmd
->fs
.flow_type
& FLOW_EXT
) &&
698 (cmd
->fs
.m_ext
.vlan_tci
& cpu_to_be16(VLAN_VID_MASK
))) {
699 spec_l2
->eth
.vlan_id
= cmd
->fs
.h_ext
.vlan_tci
;
700 spec_l2
->eth
.vlan_id_msk
= cpu_to_be16(VLAN_VID_MASK
);
703 list_add_tail(&spec_l2
->list
, rule_list_h
);
708 static int mlx4_en_ethtool_add_mac_rule_by_ipv4(struct mlx4_en_priv
*priv
,
709 struct ethtool_rxnfc
*cmd
,
710 struct list_head
*rule_list_h
,
711 struct mlx4_spec_list
*spec_l2
,
715 unsigned char mac
[ETH_ALEN
];
717 if (!ipv4_is_multicast(ipv4_dst
)) {
718 if (cmd
->fs
.flow_type
& FLOW_MAC_EXT
)
719 memcpy(&mac
, cmd
->fs
.h_ext
.h_dest
, ETH_ALEN
);
721 memcpy(&mac
, priv
->dev
->dev_addr
, ETH_ALEN
);
723 ip_eth_mc_map(ipv4_dst
, mac
);
726 return mlx4_en_ethtool_add_mac_rule(cmd
, rule_list_h
, spec_l2
, &mac
[0]);
732 static int add_ip_rule(struct mlx4_en_priv
*priv
,
733 struct ethtool_rxnfc
*cmd
,
734 struct list_head
*list_h
)
737 struct mlx4_spec_list
*spec_l2
= NULL
;
738 struct mlx4_spec_list
*spec_l3
= NULL
;
739 struct ethtool_usrip4_spec
*l3_mask
= &cmd
->fs
.m_u
.usr_ip4_spec
;
741 spec_l3
= kzalloc(sizeof(*spec_l3
), GFP_KERNEL
);
742 spec_l2
= kzalloc(sizeof(*spec_l2
), GFP_KERNEL
);
743 if (!spec_l2
|| !spec_l3
) {
748 err
= mlx4_en_ethtool_add_mac_rule_by_ipv4(priv
, cmd
, list_h
, spec_l2
,
750 usr_ip4_spec
.ip4dst
);
753 spec_l3
->id
= MLX4_NET_TRANS_RULE_ID_IPV4
;
754 spec_l3
->ipv4
.src_ip
= cmd
->fs
.h_u
.usr_ip4_spec
.ip4src
;
756 spec_l3
->ipv4
.src_ip_msk
= EN_ETHTOOL_WORD_MASK
;
757 spec_l3
->ipv4
.dst_ip
= cmd
->fs
.h_u
.usr_ip4_spec
.ip4dst
;
759 spec_l3
->ipv4
.dst_ip_msk
= EN_ETHTOOL_WORD_MASK
;
760 list_add_tail(&spec_l3
->list
, list_h
);
770 static int add_tcp_udp_rule(struct mlx4_en_priv
*priv
,
771 struct ethtool_rxnfc
*cmd
,
772 struct list_head
*list_h
, int proto
)
775 struct mlx4_spec_list
*spec_l2
= NULL
;
776 struct mlx4_spec_list
*spec_l3
= NULL
;
777 struct mlx4_spec_list
*spec_l4
= NULL
;
778 struct ethtool_tcpip4_spec
*l4_mask
= &cmd
->fs
.m_u
.tcp_ip4_spec
;
780 spec_l2
= kzalloc(sizeof(*spec_l2
), GFP_KERNEL
);
781 spec_l3
= kzalloc(sizeof(*spec_l3
), GFP_KERNEL
);
782 spec_l4
= kzalloc(sizeof(*spec_l4
), GFP_KERNEL
);
783 if (!spec_l2
|| !spec_l3
|| !spec_l4
) {
788 spec_l3
->id
= MLX4_NET_TRANS_RULE_ID_IPV4
;
790 if (proto
== TCP_V4_FLOW
) {
791 err
= mlx4_en_ethtool_add_mac_rule_by_ipv4(priv
, cmd
, list_h
,
794 tcp_ip4_spec
.ip4dst
);
797 spec_l4
->id
= MLX4_NET_TRANS_RULE_ID_TCP
;
798 spec_l3
->ipv4
.src_ip
= cmd
->fs
.h_u
.tcp_ip4_spec
.ip4src
;
799 spec_l3
->ipv4
.dst_ip
= cmd
->fs
.h_u
.tcp_ip4_spec
.ip4dst
;
800 spec_l4
->tcp_udp
.src_port
= cmd
->fs
.h_u
.tcp_ip4_spec
.psrc
;
801 spec_l4
->tcp_udp
.dst_port
= cmd
->fs
.h_u
.tcp_ip4_spec
.pdst
;
803 err
= mlx4_en_ethtool_add_mac_rule_by_ipv4(priv
, cmd
, list_h
,
806 udp_ip4_spec
.ip4dst
);
809 spec_l4
->id
= MLX4_NET_TRANS_RULE_ID_UDP
;
810 spec_l3
->ipv4
.src_ip
= cmd
->fs
.h_u
.udp_ip4_spec
.ip4src
;
811 spec_l3
->ipv4
.dst_ip
= cmd
->fs
.h_u
.udp_ip4_spec
.ip4dst
;
812 spec_l4
->tcp_udp
.src_port
= cmd
->fs
.h_u
.udp_ip4_spec
.psrc
;
813 spec_l4
->tcp_udp
.dst_port
= cmd
->fs
.h_u
.udp_ip4_spec
.pdst
;
817 spec_l3
->ipv4
.src_ip_msk
= EN_ETHTOOL_WORD_MASK
;
819 spec_l3
->ipv4
.dst_ip_msk
= EN_ETHTOOL_WORD_MASK
;
822 spec_l4
->tcp_udp
.src_port_msk
= EN_ETHTOOL_SHORT_MASK
;
824 spec_l4
->tcp_udp
.dst_port_msk
= EN_ETHTOOL_SHORT_MASK
;
826 list_add_tail(&spec_l3
->list
, list_h
);
827 list_add_tail(&spec_l4
->list
, list_h
);
838 static int mlx4_en_ethtool_to_net_trans_rule(struct net_device
*dev
,
839 struct ethtool_rxnfc
*cmd
,
840 struct list_head
*rule_list_h
)
843 struct ethhdr
*eth_spec
;
844 struct mlx4_spec_list
*spec_l2
;
845 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
847 err
= mlx4_en_validate_flow(dev
, cmd
);
851 switch (cmd
->fs
.flow_type
& ~(FLOW_EXT
| FLOW_MAC_EXT
)) {
853 spec_l2
= kzalloc(sizeof(*spec_l2
), GFP_KERNEL
);
857 eth_spec
= &cmd
->fs
.h_u
.ether_spec
;
858 mlx4_en_ethtool_add_mac_rule(cmd
, rule_list_h
, spec_l2
,
859 ð_spec
->h_dest
[0]);
860 spec_l2
->eth
.ether_type
= eth_spec
->h_proto
;
861 if (eth_spec
->h_proto
)
862 spec_l2
->eth
.ether_type_enable
= 1;
865 err
= add_ip_rule(priv
, cmd
, rule_list_h
);
868 err
= add_tcp_udp_rule(priv
, cmd
, rule_list_h
, TCP_V4_FLOW
);
871 err
= add_tcp_udp_rule(priv
, cmd
, rule_list_h
, UDP_V4_FLOW
);
878 static int mlx4_en_flow_replace(struct net_device
*dev
,
879 struct ethtool_rxnfc
*cmd
)
882 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
883 struct ethtool_flow_id
*loc_rule
;
884 struct mlx4_spec_list
*spec
, *tmp_spec
;
888 struct mlx4_net_trans_rule rule
= {
889 .queue_mode
= MLX4_NET_TRANS_Q_FIFO
,
892 .promisc_mode
= MLX4_FS_REGULAR
,
895 rule
.port
= priv
->port
;
896 rule
.priority
= MLX4_DOMAIN_ETHTOOL
| cmd
->fs
.location
;
897 INIT_LIST_HEAD(&rule
.list
);
899 /* Allow direct QP attaches if the EN_ETHTOOL_QP_ATTACH flag is set */
900 if (cmd
->fs
.ring_cookie
== RX_CLS_FLOW_DISC
)
901 qpn
= priv
->drop_qp
.qpn
;
902 else if (cmd
->fs
.ring_cookie
& EN_ETHTOOL_QP_ATTACH
) {
903 qpn
= cmd
->fs
.ring_cookie
& (EN_ETHTOOL_QP_ATTACH
- 1);
905 if (cmd
->fs
.ring_cookie
>= priv
->rx_ring_num
) {
906 en_warn(priv
, "rxnfc: RX ring (%llu) doesn't exist.\n",
907 cmd
->fs
.ring_cookie
);
910 qpn
= priv
->rss_map
.qps
[cmd
->fs
.ring_cookie
].qpn
;
912 en_warn(priv
, "rxnfc: RX ring (%llu) is inactive.\n",
913 cmd
->fs
.ring_cookie
);
918 err
= mlx4_en_ethtool_to_net_trans_rule(dev
, cmd
, &rule
.list
);
922 loc_rule
= &priv
->ethtool_rules
[cmd
->fs
.location
];
924 err
= mlx4_flow_detach(priv
->mdev
->dev
, loc_rule
->id
);
926 en_err(priv
, "Fail to detach network rule at location %d. registration id = %llx\n",
927 cmd
->fs
.location
, loc_rule
->id
);
931 memset(&loc_rule
->flow_spec
, 0,
932 sizeof(struct ethtool_rx_flow_spec
));
933 list_del(&loc_rule
->list
);
935 err
= mlx4_flow_attach(priv
->mdev
->dev
, &rule
, ®_id
);
937 en_err(priv
, "Fail to attach network rule at location %d.\n",
941 loc_rule
->id
= reg_id
;
942 memcpy(&loc_rule
->flow_spec
, &cmd
->fs
,
943 sizeof(struct ethtool_rx_flow_spec
));
944 list_add_tail(&loc_rule
->list
, &priv
->ethtool_list
);
947 list_for_each_entry_safe(spec
, tmp_spec
, &rule
.list
, list
) {
948 list_del(&spec
->list
);
954 static int mlx4_en_flow_detach(struct net_device
*dev
,
955 struct ethtool_rxnfc
*cmd
)
958 struct ethtool_flow_id
*rule
;
959 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
961 if (cmd
->fs
.location
>= MAX_NUM_OF_FS_RULES
)
964 rule
= &priv
->ethtool_rules
[cmd
->fs
.location
];
970 err
= mlx4_flow_detach(priv
->mdev
->dev
, rule
->id
);
972 en_err(priv
, "Fail to detach network rule at location %d. registration id = 0x%llx\n",
973 cmd
->fs
.location
, rule
->id
);
977 memset(&rule
->flow_spec
, 0, sizeof(struct ethtool_rx_flow_spec
));
978 list_del(&rule
->list
);
984 static int mlx4_en_get_flow(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
,
988 struct ethtool_flow_id
*rule
;
989 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
991 if (loc
< 0 || loc
>= MAX_NUM_OF_FS_RULES
)
994 rule
= &priv
->ethtool_rules
[loc
];
996 memcpy(&cmd
->fs
, &rule
->flow_spec
,
997 sizeof(struct ethtool_rx_flow_spec
));
1004 static int mlx4_en_get_num_flows(struct mlx4_en_priv
*priv
)
1008 for (i
= 0; i
< MAX_NUM_OF_FS_RULES
; i
++) {
1009 if (priv
->ethtool_rules
[i
].id
)
1016 static int mlx4_en_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
,
1019 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1020 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1022 int i
= 0, priority
= 0;
1024 if ((cmd
->cmd
== ETHTOOL_GRXCLSRLCNT
||
1025 cmd
->cmd
== ETHTOOL_GRXCLSRULE
||
1026 cmd
->cmd
== ETHTOOL_GRXCLSRLALL
) &&
1027 (mdev
->dev
->caps
.steering_mode
!=
1028 MLX4_STEERING_MODE_DEVICE_MANAGED
|| !priv
->port_up
))
1032 case ETHTOOL_GRXRINGS
:
1033 cmd
->data
= priv
->rx_ring_num
;
1035 case ETHTOOL_GRXCLSRLCNT
:
1036 cmd
->rule_cnt
= mlx4_en_get_num_flows(priv
);
1038 case ETHTOOL_GRXCLSRULE
:
1039 err
= mlx4_en_get_flow(dev
, cmd
, cmd
->fs
.location
);
1041 case ETHTOOL_GRXCLSRLALL
:
1042 while ((!err
|| err
== -ENOENT
) && priority
< cmd
->rule_cnt
) {
1043 err
= mlx4_en_get_flow(dev
, cmd
, i
);
1045 rule_locs
[priority
++] = i
;
1058 static int mlx4_en_set_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
)
1061 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1062 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1064 if (mdev
->dev
->caps
.steering_mode
!=
1065 MLX4_STEERING_MODE_DEVICE_MANAGED
|| !priv
->port_up
)
1069 case ETHTOOL_SRXCLSRLINS
:
1070 err
= mlx4_en_flow_replace(dev
, cmd
);
1072 case ETHTOOL_SRXCLSRLDEL
:
1073 err
= mlx4_en_flow_detach(dev
, cmd
);
1076 en_warn(priv
, "Unsupported ethtool command. (%d)\n", cmd
->cmd
);
1083 static void mlx4_en_get_channels(struct net_device
*dev
,
1084 struct ethtool_channels
*channel
)
1086 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1088 memset(channel
, 0, sizeof(*channel
));
1090 channel
->max_rx
= MAX_RX_RINGS
;
1091 channel
->max_tx
= MLX4_EN_MAX_TX_RING_P_UP
;
1093 channel
->rx_count
= priv
->rx_ring_num
;
1094 channel
->tx_count
= priv
->tx_ring_num
/ MLX4_EN_NUM_UP
;
1097 static int mlx4_en_set_channels(struct net_device
*dev
,
1098 struct ethtool_channels
*channel
)
1100 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1101 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1105 if (channel
->other_count
|| channel
->combined_count
||
1106 channel
->tx_count
> MLX4_EN_MAX_TX_RING_P_UP
||
1107 channel
->rx_count
> MAX_RX_RINGS
||
1108 !channel
->tx_count
|| !channel
->rx_count
)
1111 mutex_lock(&mdev
->state_lock
);
1112 if (priv
->port_up
) {
1114 mlx4_en_stop_port(dev
, 1);
1117 mlx4_en_free_resources(priv
);
1119 priv
->num_tx_rings_p_up
= channel
->tx_count
;
1120 priv
->tx_ring_num
= channel
->tx_count
* MLX4_EN_NUM_UP
;
1121 priv
->rx_ring_num
= channel
->rx_count
;
1123 err
= mlx4_en_alloc_resources(priv
);
1125 en_err(priv
, "Failed reallocating port resources\n");
1129 netif_set_real_num_tx_queues(dev
, priv
->tx_ring_num
);
1130 netif_set_real_num_rx_queues(dev
, priv
->rx_ring_num
);
1132 mlx4_en_setup_tc(dev
, MLX4_EN_NUM_UP
);
1134 en_warn(priv
, "Using %d TX rings\n", priv
->tx_ring_num
);
1135 en_warn(priv
, "Using %d RX rings\n", priv
->rx_ring_num
);
1138 err
= mlx4_en_start_port(dev
);
1140 en_err(priv
, "Failed starting port\n");
1143 err
= mlx4_en_moderation_update(priv
);
1146 mutex_unlock(&mdev
->state_lock
);
1150 static int mlx4_en_get_ts_info(struct net_device
*dev
,
1151 struct ethtool_ts_info
*info
)
1153 struct mlx4_en_priv
*priv
= netdev_priv(dev
);
1154 struct mlx4_en_dev
*mdev
= priv
->mdev
;
1157 ret
= ethtool_op_get_ts_info(dev
, info
);
1161 if (mdev
->dev
->caps
.flags2
& MLX4_DEV_CAP_FLAG2_TS
) {
1162 info
->so_timestamping
|=
1163 SOF_TIMESTAMPING_TX_HARDWARE
|
1164 SOF_TIMESTAMPING_RX_HARDWARE
|
1165 SOF_TIMESTAMPING_RAW_HARDWARE
;
1168 (1 << HWTSTAMP_TX_OFF
) |
1169 (1 << HWTSTAMP_TX_ON
);
1172 (1 << HWTSTAMP_FILTER_NONE
) |
1173 (1 << HWTSTAMP_FILTER_ALL
);
1179 const struct ethtool_ops mlx4_en_ethtool_ops
= {
1180 .get_drvinfo
= mlx4_en_get_drvinfo
,
1181 .get_settings
= mlx4_en_get_settings
,
1182 .set_settings
= mlx4_en_set_settings
,
1183 .get_link
= ethtool_op_get_link
,
1184 .get_strings
= mlx4_en_get_strings
,
1185 .get_sset_count
= mlx4_en_get_sset_count
,
1186 .get_ethtool_stats
= mlx4_en_get_ethtool_stats
,
1187 .self_test
= mlx4_en_self_test
,
1188 .get_wol
= mlx4_en_get_wol
,
1189 .set_wol
= mlx4_en_set_wol
,
1190 .get_msglevel
= mlx4_en_get_msglevel
,
1191 .set_msglevel
= mlx4_en_set_msglevel
,
1192 .get_coalesce
= mlx4_en_get_coalesce
,
1193 .set_coalesce
= mlx4_en_set_coalesce
,
1194 .get_pauseparam
= mlx4_en_get_pauseparam
,
1195 .set_pauseparam
= mlx4_en_set_pauseparam
,
1196 .get_ringparam
= mlx4_en_get_ringparam
,
1197 .set_ringparam
= mlx4_en_set_ringparam
,
1198 .get_rxnfc
= mlx4_en_get_rxnfc
,
1199 .set_rxnfc
= mlx4_en_set_rxnfc
,
1200 .get_rxfh_indir_size
= mlx4_en_get_rxfh_indir_size
,
1201 .get_rxfh_indir
= mlx4_en_get_rxfh_indir
,
1202 .set_rxfh_indir
= mlx4_en_set_rxfh_indir
,
1203 .get_channels
= mlx4_en_get_channels
,
1204 .set_channels
= mlx4_en_set_channels
,
1205 .get_ts_info
= mlx4_en_get_ts_info
,