]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/ethernet/mellanox/mlx4/en_selftest.c
Merge remote-tracking branches 'asoc/topic/inntel', 'asoc/topic/input', 'asoc/topic...
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ethernet / mellanox / mlx4 / en_selftest.c
CommitLineData
e7c1c2c4
YP
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/delay.h>
38#include <linux/mlx4/driver.h>
39
40#include "mlx4_en.h"
41
42
43static int mlx4_en_test_registers(struct mlx4_en_priv *priv)
44{
45 return mlx4_cmd(priv->mdev->dev, 0, 0, 0, MLX4_CMD_HW_HEALTH_CHECK,
f9baff50 46 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
e7c1c2c4
YP
47}
48
49static int mlx4_en_test_loopback_xmit(struct mlx4_en_priv *priv)
50{
51 struct sk_buff *skb;
52 struct ethhdr *ethh;
53 unsigned char *packet;
54 unsigned int packet_size = MLX4_LOOPBACK_TEST_PAYLOAD;
55 unsigned int i;
56 int err;
57
58
59 /* build the pkt before xmit */
60 skb = netdev_alloc_skb(priv->dev, MLX4_LOOPBACK_TEST_PAYLOAD + ETH_HLEN + NET_IP_ALIGN);
720a43ef 61 if (!skb)
e7c1c2c4 62 return -ENOMEM;
720a43ef 63
e7c1c2c4
YP
64 skb_reserve(skb, NET_IP_ALIGN);
65
66 ethh = (struct ethhdr *)skb_put(skb, sizeof(struct ethhdr));
67 packet = (unsigned char *)skb_put(skb, packet_size);
68 memcpy(ethh->h_dest, priv->dev->dev_addr, ETH_ALEN);
c7bf7169 69 eth_zero_addr(ethh->h_source);
e7c1c2c4
YP
70 ethh->h_proto = htons(ETH_P_ARP);
71 skb_set_mac_header(skb, 0);
72 for (i = 0; i < packet_size; ++i) /* fill our packet */
73 packet[i] = (unsigned char)(i & 0xff);
74
75 /* xmit the pkt */
76 err = mlx4_en_xmit(skb, priv->dev);
77 return err;
78}
79
80static int mlx4_en_test_loopback(struct mlx4_en_priv *priv)
81{
82 u32 loopback_ok = 0;
83 int i;
1037ebbb 84 bool gro_enabled;
e7c1c2c4
YP
85
86 priv->loopback_ok = 0;
87 priv->validate_loopback = 1;
1037ebbb 88 gro_enabled = priv->dev->features & NETIF_F_GRO;
e7c1c2c4 89
79aeaccd 90 mlx4_en_update_loopback_state(priv->dev, priv->dev->features);
1037ebbb 91 priv->dev->features &= ~NETIF_F_GRO;
79aeaccd 92
e7c1c2c4
YP
93 /* xmit */
94 if (mlx4_en_test_loopback_xmit(priv)) {
95 en_err(priv, "Transmitting loopback packet failed\n");
96 goto mlx4_en_test_loopback_exit;
97 }
98
99 /* polling for result */
100 for (i = 0; i < MLX4_EN_LOOPBACK_RETRIES; ++i) {
101 msleep(MLX4_EN_LOOPBACK_TIMEOUT);
102 if (priv->loopback_ok) {
103 loopback_ok = 1;
104 break;
105 }
106 }
107 if (!loopback_ok)
108 en_err(priv, "Loopback packet didn't arrive\n");
109
110mlx4_en_test_loopback_exit:
111
112 priv->validate_loopback = 0;
1037ebbb
IS
113
114 if (gro_enabled)
115 priv->dev->features |= NETIF_F_GRO;
116
79aeaccd 117 mlx4_en_update_loopback_state(priv->dev, priv->dev->features);
807540ba 118 return !loopback_ok;
e7c1c2c4
YP
119}
120
6f2e0d2c
EE
121static int mlx4_en_test_interrupts(struct mlx4_en_priv *priv)
122{
123 struct mlx4_en_dev *mdev = priv->mdev;
124 int err = 0;
125 int i = 0;
126
127 err = mlx4_test_async(mdev->dev);
128 /* When not in MSI_X or slave, test only async */
129 if (!(mdev->dev->flags & MLX4_FLAG_MSI_X) || mlx4_is_slave(mdev->dev))
130 return err;
131
132 /* A loop over all completion vectors of current port,
133 * for each vector check whether it works by mapping command
134 * completions to that vector and performing a NOP command
135 */
136 for (i = 0; i < priv->rx_ring_num; i++) {
137 err = mlx4_test_interrupt(mdev->dev, priv->rx_cq[i]->vector);
138 if (err)
139 break;
140 }
141
142 return err;
143}
e7c1c2c4
YP
144
145static int mlx4_en_test_link(struct mlx4_en_priv *priv)
146{
147 if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
148 return -ENOMEM;
149 if (priv->port_state.link_state == 1)
150 return 0;
151 else
152 return 1;
153}
154
155static int mlx4_en_test_speed(struct mlx4_en_priv *priv)
156{
157
158 if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
159 return -ENOMEM;
160
dcf972a3
SM
161 /* The device supports 100M, 1G, 10G, 20G, 40G and 56G speed */
162 if (priv->port_state.link_speed != SPEED_100 &&
163 priv->port_state.link_speed != SPEED_1000 &&
164 priv->port_state.link_speed != SPEED_10000 &&
165 priv->port_state.link_speed != SPEED_20000 &&
166 priv->port_state.link_speed != SPEED_40000 &&
167 priv->port_state.link_speed != SPEED_56000)
e7c1c2c4 168 return priv->port_state.link_speed;
dcf972a3 169
e7c1c2c4
YP
170 return 0;
171}
172
173
174void mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf)
175{
176 struct mlx4_en_priv *priv = netdev_priv(dev);
e7c1c2c4
YP
177 int i, carrier_ok;
178
179 memset(buf, 0, sizeof(u64) * MLX4_EN_NUM_SELF_TEST);
180
181 if (*flags & ETH_TEST_FL_OFFLINE) {
182 /* disable the interface */
183 carrier_ok = netif_carrier_ok(dev);
184
185 netif_carrier_off(dev);
25985edc 186 /* Wait until all tx queues are empty.
e7c1c2c4
YP
187 * there should not be any additional incoming traffic
188 * since we turned the carrier off */
189 msleep(200);
e7c1c2c4 190
ccf86321
OG
191 if (priv->mdev->dev->caps.flags &
192 MLX4_DEV_CAP_FLAG_UC_LOOPBACK) {
e7c1c2c4 193 buf[3] = mlx4_en_test_registers(priv);
4359db1e
EE
194 if (priv->port_up)
195 buf[4] = mlx4_en_test_loopback(priv);
e7c1c2c4
YP
196 }
197
198 if (carrier_ok)
199 netif_carrier_on(dev);
200
201 }
6f2e0d2c 202 buf[0] = mlx4_en_test_interrupts(priv);
e7c1c2c4
YP
203 buf[1] = mlx4_en_test_link(priv);
204 buf[2] = mlx4_en_test_speed(priv);
205
206 for (i = 0; i < MLX4_EN_NUM_SELF_TEST; i++) {
207 if (buf[i])
208 *flags |= ETH_TEST_FL_FAILED;
209 }
210}