|
| 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