34 #include <linux/kernel.h>
35 #include <linux/ethtool.h>
36 #include <linux/netdevice.h>
42 #define EN_ETHTOOL_QP_ATTACH (1ull << 63)
43 #define EN_ETHTOOL_SHORT_MASK cpu_to_be16(0xffff)
44 #define EN_ETHTOOL_WORD_MASK cpu_to_be32(0xffffffff)
57 (
u16) (mdev->
dev->caps.fw_ver >> 32),
58 (
u16) ((mdev->
dev->caps.fw_ver >> 16) & 0xffff),
59 (
u16) (mdev->
dev->caps.fw_ver & 0xffff));
68 "rx_packets",
"tx_packets",
"rx_bytes",
"tx_bytes",
"rx_errors",
69 "tx_errors",
"rx_dropped",
"tx_dropped",
"multicast",
"collisions",
70 "rx_length_errors",
"rx_over_errors",
"rx_crc_errors",
71 "rx_frame_errors",
"rx_fifo_errors",
"rx_missed_errors",
72 "tx_aborted_errors",
"tx_carrier_errors",
"tx_fifo_errors",
73 "tx_heartbeat_errors",
"tx_window_errors",
77 "queue_stopped",
"wake_queue",
"tx_timeout",
"rx_alloc_failed",
78 "rx_csum_good",
"rx_csum_none",
"tx_chksum_offload",
81 "broadcast",
"rx_prio_0",
"rx_prio_1",
"rx_prio_2",
"rx_prio_3",
82 "rx_prio_4",
"rx_prio_5",
"rx_prio_6",
"rx_prio_7",
"tx_prio_0",
83 "tx_prio_1",
"tx_prio_2",
"tx_prio_3",
"tx_prio_4",
"tx_prio_5",
84 "tx_prio_6",
"tx_prio_7",
86 #define NUM_MAIN_STATS 21
87 #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
99 return ((
struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
107 static void mlx4_en_get_wol(
struct net_device *netdev,
115 if ((priv->
port < 1) || (priv->
port > 2)) {
116 en_err(priv,
"Failed to get WoL information\n");
123 if (!(priv->
mdev->dev->caps.flags & mask)) {
131 en_err(priv,
"Failed to get WoL information\n");
146 static int mlx4_en_set_wol(
struct net_device *netdev,
154 if ((priv->
port < 1) || (priv->
port > 2))
160 if (!(priv->
mdev->dev->caps.flags & mask))
168 en_err(priv,
"Failed to get WoL info, unable to modify\n");
182 en_err(priv,
"Failed to set WoL information\n");
187 static int mlx4_en_get_sset_count(
struct net_device *dev,
int sset)
204 static void mlx4_en_get_ethtool_stats(
struct net_device *dev,
216 ((
unsigned long *) &priv->
stats)[
i];
222 ((
unsigned long *) &priv->
pkstats)[
i];
227 ((
unsigned long *) &priv->
stats)[
i];
238 data[index++] = priv->
tx_ring[
i].packets;
239 data[index++] = priv->
tx_ring[
i].bytes;
242 data[index++] = priv->
rx_ring[
i].packets;
243 data[index++] = priv->
rx_ring[
i].bytes;
249 static void mlx4_en_self_test(
struct net_device *dev,
255 static void mlx4_en_get_strings(
struct net_device *dev,
268 strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
275 strcpy(data + (index++) * ETH_GSTRING_LEN,
278 strcpy(data + (index++) * ETH_GSTRING_LEN,
282 strcpy(data + (index++) * ETH_GSTRING_LEN,
290 (index++) * ETH_GSTRING_LEN,
297 sprintf(data + (index++) * ETH_GSTRING_LEN,
299 sprintf(data + (index++) * ETH_GSTRING_LEN,
303 sprintf(data + (index++) * ETH_GSTRING_LEN,
305 sprintf(data + (index++) * ETH_GSTRING_LEN,
325 if (netif_carrier_ok(dev)) {
326 ethtool_cmd_speed_set(cmd, priv->
port_state.link_speed);
329 ethtool_cmd_speed_set(cmd, -1);
333 if (trans_type > 0 && trans_type <= 0xC) {
338 }
else if (trans_type == 0x80 || trans_type == 0) {
361 static int mlx4_en_get_coalesce(
struct net_device *dev,
380 static int mlx4_en_set_coalesce(
struct net_device *dev,
404 en_warn(priv,
"Failed changing moderation "
405 "for TX cq %d\n", i);
431 static int mlx4_en_set_pauseparam(
struct net_device *dev,
442 priv->
prof->tx_pause,
444 priv->
prof->rx_pause,
447 en_err(priv,
"Failed setting pause params\n");
452 static void mlx4_en_get_pauseparam(
struct net_device *dev,
461 static int mlx4_en_set_ringparam(
struct net_device *dev,
466 u32 rx_size, tx_size;
483 tx_size == priv->
tx_ring[0].size)
494 priv->
prof->tx_ring_size = tx_size;
495 priv->
prof->rx_ring_size = rx_size;
499 en_err(priv,
"Failed reallocating port resources\n");
505 en_err(priv,
"Failed starting port\n");
522 static void mlx4_en_get_ringparam(
struct net_device *dev,
527 memset(param, 0,
sizeof(*param));
535 static u32 mlx4_en_get_rxfh_indir_size(
struct net_device *dev)
542 static int mlx4_en_get_rxfh_indir(
struct net_device *dev,
u32 *ring_index)
553 ring_index[
n] = rss_map->
qps[n % rss_rings].qpn -
560 static int mlx4_en_set_rxfh_indir(
struct net_device *dev,
561 const u32 *ring_index)
574 if (i > 0 && !ring_index[i] && !rss_rings)
577 if (ring_index[i] != (i % (rss_rings ?: priv->
rx_ring_num)))
594 priv->
prof->rss_rings = rss_rings;
599 en_err(priv,
"Failed starting port\n");
606 #define all_zeros_or_all_ones(field) \
607 ((field) == 0 || (field) == (__force typeof(field))-1)
609 static int mlx4_en_validate_flow(
struct net_device *dev,
615 u64 full_mac = ~0ull;
624 if (cmd->
fs.m_u.tcp_ip4_spec.tos)
626 l4_mask = &cmd->
fs.m_u.tcp_ip4_spec;
635 l3_mask = &cmd->
fs.m_u.usr_ip4_spec;
644 eth_mask = &cmd->
fs.m_u.ether_spec;
661 if (cmd->
fs.m_ext.vlan_etype ||
662 !(cmd->
fs.m_ext.vlan_tci == 0 ||
677 spec_l3 = kzalloc(
sizeof *spec_l3,
GFP_KERNEL);
679 en_err(priv,
"Fail to alloc ethtool rule.\n");
684 spec_l3->
ipv4.src_ip = cmd->
fs.h_u.usr_ip4_spec.ip4src;
687 spec_l3->
ipv4.dst_ip = cmd->
fs.h_u.usr_ip4_spec.ip4dst;
703 spec_l3 = kzalloc(
sizeof *spec_l3,
GFP_KERNEL);
704 spec_l4 = kzalloc(
sizeof *spec_l4,
GFP_KERNEL);
705 if (!spec_l4 || !spec_l3) {
706 en_err(priv,
"Fail to alloc ethtool rule.\n");
716 spec_l3->
ipv4.src_ip = cmd->
fs.h_u.tcp_ip4_spec.ip4src;
717 spec_l3->
ipv4.dst_ip = cmd->
fs.h_u.tcp_ip4_spec.ip4dst;
718 spec_l4->
tcp_udp.src_port = cmd->
fs.h_u.tcp_ip4_spec.psrc;
719 spec_l4->
tcp_udp.dst_port = cmd->
fs.h_u.tcp_ip4_spec.pdst;
722 spec_l3->
ipv4.src_ip = cmd->
fs.h_u.udp_ip4_spec.ip4src;
723 spec_l3->
ipv4.dst_ip = cmd->
fs.h_u.udp_ip4_spec.ip4dst;
724 spec_l4->
tcp_udp.src_port = cmd->
fs.h_u.udp_ip4_spec.psrc;
725 spec_l4->
tcp_udp.dst_port = cmd->
fs.h_u.udp_ip4_spec.pdst;
744 static int mlx4_en_ethtool_to_net_trans_rule(
struct net_device *dev,
756 err = mlx4_en_validate_flow(dev, cmd);
760 spec_l2 = kzalloc(
sizeof *spec_l2,
GFP_KERNEL);
772 if ((cmd->
fs.flow_type &
FLOW_EXT) && cmd->
fs.m_ext.vlan_tci) {
773 spec_l2->
eth.vlan_id = cmd->
fs.h_ext.vlan_tci;
781 eth_spec = &cmd->
fs.h_u.ether_spec;
785 spec_l2->
eth.ether_type_enable = 1;
788 err = add_ip_rule(priv, cmd, rule_list_h);
791 err = add_tcp_udp_rule(priv, cmd, rule_list_h,
TCP_V4_FLOW);
794 err = add_tcp_udp_rule(priv, cmd, rule_list_h,
UDP_V4_FLOW);
801 static int mlx4_en_flow_replace(
struct net_device *dev,
820 INIT_LIST_HEAD(&rule.
list);
829 en_warn(priv,
"rxnfc: RX ring (%llu) doesn't exist.\n",
830 cmd->
fs.ring_cookie);
833 qpn = priv->
rss_map.qps[cmd->
fs.ring_cookie].qpn;
835 en_warn(priv,
"rxnfc: RX ring (%llu) is inactive.\n",
836 cmd->
fs.ring_cookie);
841 err = mlx4_en_ethtool_to_net_trans_rule(dev, cmd, &rule.
list);
849 en_err(priv,
"Fail to detach network rule at location %d. registration id = %llx\n",
850 cmd->
fs.location, loc_rule->
id);
859 en_err(priv,
"Fail to attach network rule at location %d.\n",
863 loc_rule->
id = reg_id;
875 static int mlx4_en_flow_detach(
struct net_device *dev,
893 en_err(priv,
"Fail to detach network rule at location %d. registration id = 0x%llx\n",
894 cmd->
fs.location, rule->
id);
924 static int mlx4_en_get_num_flows(
struct mlx4_en_priv *priv)
955 cmd->
rule_cnt = mlx4_en_get_num_flows(priv);
958 err = mlx4_en_get_flow(dev, cmd, cmd->
fs.location);
961 while ((!err || err == -
ENOENT) && priority < cmd->rule_cnt) {
962 err = mlx4_en_get_flow(dev, cmd, i);
988 err = mlx4_en_flow_replace(dev, cmd);
991 err = mlx4_en_flow_detach(dev, cmd);
994 en_warn(priv,
"Unsupported ethtool command. (%d)\n", cmd->
cmd);
1002 .get_drvinfo = mlx4_en_get_drvinfo,
1003 .get_settings = mlx4_en_get_settings,
1004 .set_settings = mlx4_en_set_settings,
1006 .get_strings = mlx4_en_get_strings,
1007 .get_sset_count = mlx4_en_get_sset_count,
1008 .get_ethtool_stats = mlx4_en_get_ethtool_stats,
1009 .self_test = mlx4_en_self_test,
1010 .get_wol = mlx4_en_get_wol,
1011 .set_wol = mlx4_en_set_wol,
1012 .get_msglevel = mlx4_en_get_msglevel,
1013 .set_msglevel = mlx4_en_set_msglevel,
1014 .get_coalesce = mlx4_en_get_coalesce,
1015 .set_coalesce = mlx4_en_set_coalesce,
1016 .get_pauseparam = mlx4_en_get_pauseparam,
1017 .set_pauseparam = mlx4_en_set_pauseparam,
1018 .get_ringparam = mlx4_en_get_ringparam,
1019 .set_ringparam = mlx4_en_set_ringparam,
1020 .get_rxnfc = mlx4_en_get_rxnfc,
1021 .set_rxnfc = mlx4_en_set_rxnfc,
1022 .get_rxfh_indir_size = mlx4_en_get_rxfh_indir_size,
1023 .get_rxfh_indir = mlx4_en_get_rxfh_indir,
1024 .set_rxfh_indir = mlx4_en_set_rxfh_indir,