Skip to content

Commit d605d66

Browse files
Kamal Heibdavem330
authored andcommitted
net/mlx5e: Add support for ethtool self diagnostics test
The self diagnostics test implementaion include the following features: 1. Link Test: Check that link is in up state. 2. Speed Test: Check that link was negotiated correctly. 3. Health Test: Check the device health. Signed-off-by: Kamal Heib <kamalh@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0eca995 commit d605d66

File tree

4 files changed

+139
-2
lines changed

4 files changed

+139
-2
lines changed

drivers/net/ethernet/mellanox/mlx5/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ mlx5_core-y := main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \
88
mlx5_core-$(CONFIG_MLX5_CORE_EN) += wq.o eswitch.o eswitch_offloads.o \
99
en_main.o en_common.o en_fs.o en_ethtool.o en_tx.o \
1010
en_rx.o en_rx_am.o en_txrx.o en_clock.o vxlan.o \
11-
en_tc.o en_arfs.o en_rep.o en_fs_ethtool.o
11+
en_tc.o en_arfs.o en_rep.o en_fs_ethtool.o en_selftest.o
1212

1313
mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o

drivers/net/ethernet/mellanox/mlx5/core/en.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ struct mlx5e_umr_wqe {
167167
struct mlx5_wqe_data_seg data;
168168
};
169169

170+
extern const char mlx5e_self_tests[][ETH_GSTRING_LEN];
171+
170172
static const char mlx5e_priv_flags[][ETH_GSTRING_LEN] = {
171173
"rx_cqe_moder",
172174
};
@@ -754,6 +756,9 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
754756
void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
755757
void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
756758
void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
759+
int mlx5e_self_test_num(struct mlx5e_priv *priv);
760+
void mlx5e_self_test(struct net_device *ndev, struct ethtool_test *etest,
761+
u64 *buf);
757762
int mlx5e_ethtool_get_flow(struct mlx5e_priv *priv, struct ethtool_rxnfc *info,
758763
int location);
759764
int mlx5e_ethtool_get_all_flows(struct mlx5e_priv *priv,

drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ static int mlx5e_get_sset_count(struct net_device *dev, int sset)
180180

181181
case ETH_SS_PRIV_FLAGS:
182182
return ARRAY_SIZE(mlx5e_priv_flags);
183+
case ETH_SS_TEST:
184+
return mlx5e_self_test_num(priv);
183185
/* fallthrough */
184186
default:
185187
return -EOPNOTSUPP;
@@ -286,6 +288,9 @@ static void mlx5e_get_strings(struct net_device *dev,
286288
break;
287289

288290
case ETH_SS_TEST:
291+
for (i = 0; i < mlx5e_self_test_num(priv); i++)
292+
strcpy(data + i * ETH_GSTRING_LEN,
293+
mlx5e_self_tests[i]);
289294
break;
290295

291296
case ETH_SS_STATS:
@@ -1573,5 +1578,6 @@ const struct ethtool_ops mlx5e_ethtool_ops = {
15731578
.get_module_info = mlx5e_get_module_info,
15741579
.get_module_eeprom = mlx5e_get_module_eeprom,
15751580
.get_priv_flags = mlx5e_get_priv_flags,
1576-
.set_priv_flags = mlx5e_set_priv_flags
1581+
.set_priv_flags = mlx5e_set_priv_flags,
1582+
.self_test = mlx5e_self_test,
15771583
};
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (c) 2016, Mellanox Technologies, Ltd. 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+
#include "en.h"
34+
35+
enum {
36+
MLX5E_ST_LINK_STATE,
37+
MLX5E_ST_LINK_SPEED,
38+
MLX5E_ST_HEALTH_INFO,
39+
MLX5E_ST_NUM,
40+
};
41+
42+
const char mlx5e_self_tests[MLX5E_ST_NUM][ETH_GSTRING_LEN] = {
43+
"Link Test",
44+
"Speed Test",
45+
"Health Test",
46+
};
47+
48+
int mlx5e_self_test_num(struct mlx5e_priv *priv)
49+
{
50+
return ARRAY_SIZE(mlx5e_self_tests);
51+
}
52+
53+
static int mlx5e_test_health_info(struct mlx5e_priv *priv)
54+
{
55+
struct mlx5_core_health *health = &priv->mdev->priv.health;
56+
57+
return health->sick ? 1 : 0;
58+
}
59+
60+
static int mlx5e_test_link_state(struct mlx5e_priv *priv)
61+
{
62+
u8 port_state;
63+
64+
if (!netif_carrier_ok(priv->netdev))
65+
return 1;
66+
67+
port_state = mlx5_query_vport_state(priv->mdev, MLX5_QUERY_VPORT_STATE_IN_OP_MOD_VNIC_VPORT, 0);
68+
return port_state == VPORT_STATE_UP ? 0 : 1;
69+
}
70+
71+
static int mlx5e_test_link_speed(struct mlx5e_priv *priv)
72+
{
73+
u32 out[MLX5_ST_SZ_DW(ptys_reg)];
74+
u32 eth_proto_oper;
75+
int i;
76+
77+
if (!netif_carrier_ok(priv->netdev))
78+
return 1;
79+
80+
if (mlx5_query_port_ptys(priv->mdev, out, sizeof(out), MLX5_PTYS_EN, 1))
81+
return 1;
82+
83+
eth_proto_oper = MLX5_GET(ptys_reg, out, eth_proto_oper);
84+
for (i = 0; i < MLX5E_LINK_MODES_NUMBER; i++) {
85+
if (eth_proto_oper & MLX5E_PROT_MASK(i))
86+
return 0;
87+
}
88+
return 1;
89+
}
90+
91+
static int (*mlx5e_st_func[MLX5E_ST_NUM])(struct mlx5e_priv *) = {
92+
mlx5e_test_link_state,
93+
mlx5e_test_link_speed,
94+
mlx5e_test_health_info,
95+
};
96+
97+
void mlx5e_self_test(struct net_device *ndev, struct ethtool_test *etest,
98+
u64 *buf)
99+
{
100+
struct mlx5e_priv *priv = netdev_priv(ndev);
101+
int i;
102+
103+
memset(buf, 0, sizeof(u64) * MLX5E_ST_NUM);
104+
105+
mutex_lock(&priv->state_lock);
106+
netdev_info(ndev, "Self test begin..\n");
107+
108+
for (i = 0; i < MLX5E_ST_NUM; i++) {
109+
netdev_info(ndev, "\t[%d] %s start..\n",
110+
i, mlx5e_self_tests[i]);
111+
buf[i] = mlx5e_st_func[i](priv);
112+
netdev_info(ndev, "\t[%d] %s end: result(%lld)\n",
113+
i, mlx5e_self_tests[i], buf[i]);
114+
}
115+
116+
mutex_unlock(&priv->state_lock);
117+
118+
for (i = 0; i < MLX5E_ST_NUM; i++) {
119+
if (buf[i]) {
120+
etest->flags |= ETH_TEST_FL_FAILED;
121+
break;
122+
}
123+
}
124+
netdev_info(ndev, "Self test out: status flags(0x%x)\n",
125+
etest->flags);
126+
}

0 commit comments

Comments
 (0)