Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
| 3 | * Copyright 2005-2006 Fen Systems Ltd. |
| 4 | * Copyright 2006-2008 Solarflare Communications Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published |
| 8 | * by the Free Software Foundation, incorporated herein by reference. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/netdevice.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/kernel_stat.h> |
| 15 | #include <linux/pci.h> |
| 16 | #include <linux/ethtool.h> |
| 17 | #include <linux/ip.h> |
| 18 | #include <linux/in.h> |
| 19 | #include <linux/udp.h> |
| 20 | #include <linux/rtnetlink.h> |
| 21 | #include <asm/io.h> |
| 22 | #include "net_driver.h" |
| 23 | #include "ethtool.h" |
| 24 | #include "efx.h" |
| 25 | #include "falcon.h" |
| 26 | #include "selftest.h" |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 27 | #include "workarounds.h" |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 28 | #include "spi.h" |
Ben Hutchings | 12d00ca | 2009-10-23 08:30:46 +0000 | [diff] [blame] | 29 | #include "io.h" |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 30 | #include "mdio_10g.h" |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * Loopback test packet structure |
| 34 | * |
| 35 | * The self-test should stress every RSS vector, and unfortunately |
| 36 | * Falcon only performs RSS on TCP/UDP packets. |
| 37 | */ |
| 38 | struct efx_loopback_payload { |
| 39 | struct ethhdr header; |
| 40 | struct iphdr ip; |
| 41 | struct udphdr udp; |
| 42 | __be16 iteration; |
| 43 | const char msg[64]; |
| 44 | } __attribute__ ((packed)); |
| 45 | |
| 46 | /* Loopback test source MAC address */ |
| 47 | static const unsigned char payload_source[ETH_ALEN] = { |
| 48 | 0x00, 0x0f, 0x53, 0x1b, 0x1b, 0x1b, |
| 49 | }; |
| 50 | |
| 51 | static const char *payload_msg = |
| 52 | "Hello world! This is an Efx loopback test in progress!"; |
| 53 | |
| 54 | /** |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 55 | * efx_loopback_state - persistent state during a loopback selftest |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 56 | * @flush: Drop all packets in efx_loopback_rx_packet |
| 57 | * @packet_count: Number of packets being used in this test |
| 58 | * @skbs: An array of skbs transmitted |
| 59 | * @rx_good: RX good packet count |
| 60 | * @rx_bad: RX bad packet count |
| 61 | * @payload: Payload used in tests |
| 62 | */ |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 63 | struct efx_loopback_state { |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 64 | bool flush; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 65 | int packet_count; |
| 66 | struct sk_buff **skbs; |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 67 | |
| 68 | /* Checksums are being offloaded */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 69 | bool offload_csum; |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 70 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 71 | atomic_t rx_good; |
| 72 | atomic_t rx_bad; |
| 73 | struct efx_loopback_payload payload; |
| 74 | }; |
| 75 | |
| 76 | /************************************************************************** |
| 77 | * |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 78 | * MII, NVRAM and register tests |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 79 | * |
| 80 | **************************************************************************/ |
| 81 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 82 | static int efx_test_mdio(struct efx_nic *efx, struct efx_self_tests *tests) |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 83 | { |
| 84 | int rc = 0; |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 85 | int devad = __ffs(efx->mdio.mmds); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 86 | u16 physid1, physid2; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 87 | |
| 88 | if (efx->phy_type == PHY_TYPE_NONE) |
| 89 | return 0; |
| 90 | |
| 91 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 92 | tests->mdio = -1; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 93 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 94 | physid1 = efx_mdio_read(efx, devad, MDIO_DEVID1); |
| 95 | physid2 = efx_mdio_read(efx, devad, MDIO_DEVID2); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 96 | |
| 97 | if ((physid1 == 0x0000) || (physid1 == 0xffff) || |
| 98 | (physid2 == 0x0000) || (physid2 == 0xffff)) { |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 99 | EFX_ERR(efx, "no MDIO PHY present with ID %d\n", |
| 100 | efx->mdio.prtad); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 101 | rc = -EINVAL; |
| 102 | goto out; |
| 103 | } |
| 104 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 105 | if (EFX_IS10G(efx)) { |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 106 | rc = efx_mdio_check_mmds(efx, efx->phy_op->mmds, 0); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 107 | if (rc) |
| 108 | goto out; |
| 109 | } |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 110 | |
| 111 | out: |
| 112 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 113 | tests->mdio = rc ? -1 : 1; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 114 | return rc; |
| 115 | } |
| 116 | |
| 117 | static int efx_test_nvram(struct efx_nic *efx, struct efx_self_tests *tests) |
| 118 | { |
| 119 | int rc; |
| 120 | |
| 121 | rc = falcon_read_nvram(efx, NULL); |
| 122 | tests->nvram = rc ? -1 : 1; |
| 123 | return rc; |
| 124 | } |
| 125 | |
| 126 | static int efx_test_chip(struct efx_nic *efx, struct efx_self_tests *tests) |
| 127 | { |
| 128 | int rc; |
| 129 | |
| 130 | /* Not supported on A-series silicon */ |
| 131 | if (falcon_rev(efx) < FALCON_REV_B0) |
| 132 | return 0; |
| 133 | |
| 134 | rc = falcon_test_registers(efx); |
| 135 | tests->registers = rc ? -1 : 1; |
| 136 | return rc; |
| 137 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 138 | |
| 139 | /************************************************************************** |
| 140 | * |
| 141 | * Interrupt and event queue testing |
| 142 | * |
| 143 | **************************************************************************/ |
| 144 | |
| 145 | /* Test generation and receipt of interrupts */ |
| 146 | static int efx_test_interrupts(struct efx_nic *efx, |
| 147 | struct efx_self_tests *tests) |
| 148 | { |
| 149 | struct efx_channel *channel; |
| 150 | |
| 151 | EFX_LOG(efx, "testing interrupts\n"); |
| 152 | tests->interrupt = -1; |
| 153 | |
| 154 | /* Reset interrupt flag */ |
| 155 | efx->last_irq_cpu = -1; |
| 156 | smp_wmb(); |
| 157 | |
| 158 | /* ACK each interrupting event queue. Receiving an interrupt due to |
| 159 | * traffic before a test event is raised is considered a pass */ |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 160 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 161 | if (channel->work_pending) |
| 162 | efx_process_channel_now(channel); |
| 163 | if (efx->last_irq_cpu >= 0) |
| 164 | goto success; |
| 165 | } |
| 166 | |
| 167 | falcon_generate_interrupt(efx); |
| 168 | |
| 169 | /* Wait for arrival of test interrupt. */ |
| 170 | EFX_LOG(efx, "waiting for test interrupt\n"); |
| 171 | schedule_timeout_uninterruptible(HZ / 10); |
| 172 | if (efx->last_irq_cpu >= 0) |
| 173 | goto success; |
| 174 | |
| 175 | EFX_ERR(efx, "timed out waiting for interrupt\n"); |
| 176 | return -ETIMEDOUT; |
| 177 | |
| 178 | success: |
| 179 | EFX_LOG(efx, "test interrupt (mode %d) seen on CPU%d\n", |
| 180 | efx->interrupt_mode, efx->last_irq_cpu); |
| 181 | tests->interrupt = 1; |
| 182 | return 0; |
| 183 | } |
| 184 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 185 | /* Test generation and receipt of interrupting events */ |
| 186 | static int efx_test_eventq_irq(struct efx_channel *channel, |
| 187 | struct efx_self_tests *tests) |
| 188 | { |
| 189 | unsigned int magic, count; |
| 190 | |
| 191 | /* Channel specific code, limited to 20 bits */ |
| 192 | magic = (0x00010150 + channel->channel); |
| 193 | EFX_LOG(channel->efx, "channel %d testing event queue with code %x\n", |
| 194 | channel->channel, magic); |
| 195 | |
| 196 | tests->eventq_dma[channel->channel] = -1; |
| 197 | tests->eventq_int[channel->channel] = -1; |
| 198 | tests->eventq_poll[channel->channel] = -1; |
| 199 | |
| 200 | /* Reset flag and zero magic word */ |
| 201 | channel->efx->last_irq_cpu = -1; |
| 202 | channel->eventq_magic = 0; |
| 203 | smp_wmb(); |
| 204 | |
| 205 | falcon_generate_test_event(channel, magic); |
| 206 | |
| 207 | /* Wait for arrival of interrupt */ |
| 208 | count = 0; |
| 209 | do { |
| 210 | schedule_timeout_uninterruptible(HZ / 100); |
| 211 | |
| 212 | if (channel->work_pending) |
| 213 | efx_process_channel_now(channel); |
| 214 | |
| 215 | if (channel->eventq_magic == magic) |
| 216 | goto eventq_ok; |
| 217 | } while (++count < 2); |
| 218 | |
| 219 | EFX_ERR(channel->efx, "channel %d timed out waiting for event queue\n", |
| 220 | channel->channel); |
| 221 | |
| 222 | /* See if interrupt arrived */ |
| 223 | if (channel->efx->last_irq_cpu >= 0) { |
| 224 | EFX_ERR(channel->efx, "channel %d saw interrupt on CPU%d " |
| 225 | "during event queue test\n", channel->channel, |
| 226 | raw_smp_processor_id()); |
| 227 | tests->eventq_int[channel->channel] = 1; |
| 228 | } |
| 229 | |
| 230 | /* Check to see if event was received even if interrupt wasn't */ |
| 231 | efx_process_channel_now(channel); |
| 232 | if (channel->eventq_magic == magic) { |
| 233 | EFX_ERR(channel->efx, "channel %d event was generated, but " |
| 234 | "failed to trigger an interrupt\n", channel->channel); |
| 235 | tests->eventq_dma[channel->channel] = 1; |
| 236 | } |
| 237 | |
| 238 | return -ETIMEDOUT; |
| 239 | eventq_ok: |
| 240 | EFX_LOG(channel->efx, "channel %d event queue passed\n", |
| 241 | channel->channel); |
| 242 | tests->eventq_dma[channel->channel] = 1; |
| 243 | tests->eventq_int[channel->channel] = 1; |
| 244 | tests->eventq_poll[channel->channel] = 1; |
| 245 | return 0; |
| 246 | } |
| 247 | |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 248 | static int efx_test_phy(struct efx_nic *efx, struct efx_self_tests *tests, |
| 249 | unsigned flags) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 250 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 251 | int rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 252 | |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 253 | if (!efx->phy_op->run_tests) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 254 | return 0; |
| 255 | |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 256 | EFX_BUG_ON_PARANOID(efx->phy_op->num_tests == 0 || |
| 257 | efx->phy_op->num_tests > EFX_MAX_PHY_TESTS); |
| 258 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 259 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 260 | rc = efx->phy_op->run_tests(efx, tests->phy, flags); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 261 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 262 | return rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /************************************************************************** |
| 266 | * |
| 267 | * Loopback testing |
| 268 | * NB Only one loopback test can be executing concurrently. |
| 269 | * |
| 270 | **************************************************************************/ |
| 271 | |
| 272 | /* Loopback test RX callback |
| 273 | * This is called for each received packet during loopback testing. |
| 274 | */ |
| 275 | void efx_loopback_rx_packet(struct efx_nic *efx, |
| 276 | const char *buf_ptr, int pkt_len) |
| 277 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 278 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 279 | struct efx_loopback_payload *received; |
| 280 | struct efx_loopback_payload *payload; |
| 281 | |
| 282 | BUG_ON(!buf_ptr); |
| 283 | |
| 284 | /* If we are just flushing, then drop the packet */ |
| 285 | if ((state == NULL) || state->flush) |
| 286 | return; |
| 287 | |
| 288 | payload = &state->payload; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 289 | |
Ben Hutchings | d3208b5 | 2008-05-16 21:20:00 +0100 | [diff] [blame] | 290 | received = (struct efx_loopback_payload *) buf_ptr; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 291 | received->ip.saddr = payload->ip.saddr; |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 292 | if (state->offload_csum) |
| 293 | received->ip.check = payload->ip.check; |
| 294 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 295 | /* Check that header exists */ |
| 296 | if (pkt_len < sizeof(received->header)) { |
| 297 | EFX_ERR(efx, "saw runt RX packet (length %d) in %s loopback " |
| 298 | "test\n", pkt_len, LOOPBACK_MODE(efx)); |
| 299 | goto err; |
| 300 | } |
| 301 | |
| 302 | /* Check that the ethernet header exists */ |
| 303 | if (memcmp(&received->header, &payload->header, ETH_HLEN) != 0) { |
| 304 | EFX_ERR(efx, "saw non-loopback RX packet in %s loopback test\n", |
| 305 | LOOPBACK_MODE(efx)); |
| 306 | goto err; |
| 307 | } |
| 308 | |
| 309 | /* Check packet length */ |
| 310 | if (pkt_len != sizeof(*payload)) { |
| 311 | EFX_ERR(efx, "saw incorrect RX packet length %d (wanted %d) in " |
| 312 | "%s loopback test\n", pkt_len, (int)sizeof(*payload), |
| 313 | LOOPBACK_MODE(efx)); |
| 314 | goto err; |
| 315 | } |
| 316 | |
| 317 | /* Check that IP header matches */ |
| 318 | if (memcmp(&received->ip, &payload->ip, sizeof(payload->ip)) != 0) { |
| 319 | EFX_ERR(efx, "saw corrupted IP header in %s loopback test\n", |
| 320 | LOOPBACK_MODE(efx)); |
| 321 | goto err; |
| 322 | } |
| 323 | |
| 324 | /* Check that msg and padding matches */ |
| 325 | if (memcmp(&received->msg, &payload->msg, sizeof(received->msg)) != 0) { |
| 326 | EFX_ERR(efx, "saw corrupted RX packet in %s loopback test\n", |
| 327 | LOOPBACK_MODE(efx)); |
| 328 | goto err; |
| 329 | } |
| 330 | |
| 331 | /* Check that iteration matches */ |
| 332 | if (received->iteration != payload->iteration) { |
| 333 | EFX_ERR(efx, "saw RX packet from iteration %d (wanted %d) in " |
| 334 | "%s loopback test\n", ntohs(received->iteration), |
| 335 | ntohs(payload->iteration), LOOPBACK_MODE(efx)); |
| 336 | goto err; |
| 337 | } |
| 338 | |
| 339 | /* Increase correct RX count */ |
| 340 | EFX_TRACE(efx, "got loopback RX in %s loopback test\n", |
| 341 | LOOPBACK_MODE(efx)); |
| 342 | |
| 343 | atomic_inc(&state->rx_good); |
| 344 | return; |
| 345 | |
| 346 | err: |
| 347 | #ifdef EFX_ENABLE_DEBUG |
| 348 | if (atomic_read(&state->rx_bad) == 0) { |
| 349 | EFX_ERR(efx, "received packet:\n"); |
| 350 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1, |
| 351 | buf_ptr, pkt_len, 0); |
| 352 | EFX_ERR(efx, "expected packet:\n"); |
| 353 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1, |
| 354 | &state->payload, sizeof(state->payload), 0); |
| 355 | } |
| 356 | #endif |
| 357 | atomic_inc(&state->rx_bad); |
| 358 | } |
| 359 | |
| 360 | /* Initialise an efx_selftest_state for a new iteration */ |
| 361 | static void efx_iterate_state(struct efx_nic *efx) |
| 362 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 363 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 364 | struct net_device *net_dev = efx->net_dev; |
| 365 | struct efx_loopback_payload *payload = &state->payload; |
| 366 | |
| 367 | /* Initialise the layerII header */ |
| 368 | memcpy(&payload->header.h_dest, net_dev->dev_addr, ETH_ALEN); |
| 369 | memcpy(&payload->header.h_source, &payload_source, ETH_ALEN); |
| 370 | payload->header.h_proto = htons(ETH_P_IP); |
| 371 | |
| 372 | /* saddr set later and used as incrementing count */ |
| 373 | payload->ip.daddr = htonl(INADDR_LOOPBACK); |
| 374 | payload->ip.ihl = 5; |
| 375 | payload->ip.check = htons(0xdead); |
| 376 | payload->ip.tot_len = htons(sizeof(*payload) - sizeof(struct ethhdr)); |
| 377 | payload->ip.version = IPVERSION; |
| 378 | payload->ip.protocol = IPPROTO_UDP; |
| 379 | |
| 380 | /* Initialise udp header */ |
| 381 | payload->udp.source = 0; |
| 382 | payload->udp.len = htons(sizeof(*payload) - sizeof(struct ethhdr) - |
| 383 | sizeof(struct iphdr)); |
| 384 | payload->udp.check = 0; /* checksum ignored */ |
| 385 | |
| 386 | /* Fill out payload */ |
| 387 | payload->iteration = htons(ntohs(payload->iteration) + 1); |
| 388 | memcpy(&payload->msg, payload_msg, sizeof(payload_msg)); |
| 389 | |
| 390 | /* Fill out remaining state members */ |
| 391 | atomic_set(&state->rx_good, 0); |
| 392 | atomic_set(&state->rx_bad, 0); |
| 393 | smp_wmb(); |
| 394 | } |
| 395 | |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 396 | static int efx_begin_loopback(struct efx_tx_queue *tx_queue) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 397 | { |
| 398 | struct efx_nic *efx = tx_queue->efx; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 399 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 400 | struct efx_loopback_payload *payload; |
| 401 | struct sk_buff *skb; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 402 | int i; |
| 403 | netdev_tx_t rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 404 | |
| 405 | /* Transmit N copies of buffer */ |
| 406 | for (i = 0; i < state->packet_count; i++) { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 407 | /* Allocate an skb, holding an extra reference for |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 408 | * transmit completion counting */ |
| 409 | skb = alloc_skb(sizeof(state->payload), GFP_KERNEL); |
| 410 | if (!skb) |
| 411 | return -ENOMEM; |
| 412 | state->skbs[i] = skb; |
| 413 | skb_get(skb); |
| 414 | |
| 415 | /* Copy the payload in, incrementing the source address to |
| 416 | * exercise the rss vectors */ |
| 417 | payload = ((struct efx_loopback_payload *) |
| 418 | skb_put(skb, sizeof(state->payload))); |
| 419 | memcpy(payload, &state->payload, sizeof(state->payload)); |
| 420 | payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); |
| 421 | |
| 422 | /* Ensure everything we've written is visible to the |
| 423 | * interrupt handler. */ |
| 424 | smp_wmb(); |
| 425 | |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 426 | if (efx_dev_registered(efx)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 427 | netif_tx_lock_bh(efx->net_dev); |
| 428 | rc = efx_xmit(efx, tx_queue, skb); |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 429 | if (efx_dev_registered(efx)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 430 | netif_tx_unlock_bh(efx->net_dev); |
| 431 | |
| 432 | if (rc != NETDEV_TX_OK) { |
| 433 | EFX_ERR(efx, "TX queue %d could not transmit packet %d " |
| 434 | "of %d in %s loopback test\n", tx_queue->queue, |
| 435 | i + 1, state->packet_count, LOOPBACK_MODE(efx)); |
| 436 | |
| 437 | /* Defer cleaning up the other skbs for the caller */ |
| 438 | kfree_skb(skb); |
| 439 | return -EPIPE; |
| 440 | } |
Eric Dumazet | 2867975 | 2009-05-27 19:26:37 +0000 | [diff] [blame] | 441 | efx->net_dev->trans_start = jiffies; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 447 | static int efx_poll_loopback(struct efx_nic *efx) |
| 448 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 449 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 450 | struct efx_channel *channel; |
| 451 | |
| 452 | /* NAPI polling is not enabled, so process channels |
| 453 | * synchronously */ |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 454 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 455 | if (channel->work_pending) |
| 456 | efx_process_channel_now(channel); |
| 457 | } |
| 458 | return atomic_read(&state->rx_good) == state->packet_count; |
| 459 | } |
| 460 | |
| 461 | static int efx_end_loopback(struct efx_tx_queue *tx_queue, |
| 462 | struct efx_loopback_self_tests *lb_tests) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 463 | { |
| 464 | struct efx_nic *efx = tx_queue->efx; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 465 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 466 | struct sk_buff *skb; |
| 467 | int tx_done = 0, rx_good, rx_bad; |
| 468 | int i, rc = 0; |
| 469 | |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 470 | if (efx_dev_registered(efx)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 471 | netif_tx_lock_bh(efx->net_dev); |
| 472 | |
| 473 | /* Count the number of tx completions, and decrement the refcnt. Any |
| 474 | * skbs not already completed will be free'd when the queue is flushed */ |
| 475 | for (i=0; i < state->packet_count; i++) { |
| 476 | skb = state->skbs[i]; |
| 477 | if (skb && !skb_shared(skb)) |
| 478 | ++tx_done; |
| 479 | dev_kfree_skb_any(skb); |
| 480 | } |
| 481 | |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 482 | if (efx_dev_registered(efx)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 483 | netif_tx_unlock_bh(efx->net_dev); |
| 484 | |
| 485 | /* Check TX completion and received packet counts */ |
| 486 | rx_good = atomic_read(&state->rx_good); |
| 487 | rx_bad = atomic_read(&state->rx_bad); |
| 488 | if (tx_done != state->packet_count) { |
| 489 | /* Don't free the skbs; they will be picked up on TX |
| 490 | * overflow or channel teardown. |
| 491 | */ |
| 492 | EFX_ERR(efx, "TX queue %d saw only %d out of an expected %d " |
| 493 | "TX completion events in %s loopback test\n", |
| 494 | tx_queue->queue, tx_done, state->packet_count, |
| 495 | LOOPBACK_MODE(efx)); |
| 496 | rc = -ETIMEDOUT; |
| 497 | /* Allow to fall through so we see the RX errors as well */ |
| 498 | } |
| 499 | |
| 500 | /* We may always be up to a flush away from our desired packet total */ |
| 501 | if (rx_good != state->packet_count) { |
| 502 | EFX_LOG(efx, "TX queue %d saw only %d out of an expected %d " |
| 503 | "received packets in %s loopback test\n", |
| 504 | tx_queue->queue, rx_good, state->packet_count, |
| 505 | LOOPBACK_MODE(efx)); |
| 506 | rc = -ETIMEDOUT; |
| 507 | /* Fall through */ |
| 508 | } |
| 509 | |
| 510 | /* Update loopback test structure */ |
| 511 | lb_tests->tx_sent[tx_queue->queue] += state->packet_count; |
| 512 | lb_tests->tx_done[tx_queue->queue] += tx_done; |
| 513 | lb_tests->rx_good += rx_good; |
| 514 | lb_tests->rx_bad += rx_bad; |
| 515 | |
| 516 | return rc; |
| 517 | } |
| 518 | |
| 519 | static int |
| 520 | efx_test_loopback(struct efx_tx_queue *tx_queue, |
| 521 | struct efx_loopback_self_tests *lb_tests) |
| 522 | { |
| 523 | struct efx_nic *efx = tx_queue->efx; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 524 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 525 | int i, begin_rc, end_rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 526 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 527 | for (i = 0; i < 3; i++) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 528 | /* Determine how many packets to send */ |
Ben Hutchings | 3ffeabd | 2009-10-23 08:30:58 +0000 | [diff] [blame] | 529 | state->packet_count = EFX_TXQ_SIZE / 3; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 530 | state->packet_count = min(1 << (i << 2), state->packet_count); |
| 531 | state->skbs = kzalloc(sizeof(state->skbs[0]) * |
| 532 | state->packet_count, GFP_KERNEL); |
Ben Hutchings | 9b7bfc4 | 2008-05-16 21:20:20 +0100 | [diff] [blame] | 533 | if (!state->skbs) |
| 534 | return -ENOMEM; |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 535 | state->flush = false; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 536 | |
| 537 | EFX_LOG(efx, "TX queue %d testing %s loopback with %d " |
| 538 | "packets\n", tx_queue->queue, LOOPBACK_MODE(efx), |
| 539 | state->packet_count); |
| 540 | |
| 541 | efx_iterate_state(efx); |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 542 | begin_rc = efx_begin_loopback(tx_queue); |
| 543 | |
| 544 | /* This will normally complete very quickly, but be |
| 545 | * prepared to wait up to 100 ms. */ |
| 546 | msleep(1); |
| 547 | if (!efx_poll_loopback(efx)) { |
| 548 | msleep(100); |
| 549 | efx_poll_loopback(efx); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 550 | } |
| 551 | |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 552 | end_rc = efx_end_loopback(tx_queue, lb_tests); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 553 | kfree(state->skbs); |
| 554 | |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 555 | if (begin_rc || end_rc) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 556 | /* Wait a while to ensure there are no packets |
| 557 | * floating around after a failure. */ |
| 558 | schedule_timeout_uninterruptible(HZ / 10); |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 559 | return begin_rc ? begin_rc : end_rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
| 563 | EFX_LOG(efx, "TX queue %d passed %s loopback test with a burst length " |
| 564 | "of %d packets\n", tx_queue->queue, LOOPBACK_MODE(efx), |
| 565 | state->packet_count); |
| 566 | |
Ben Hutchings | a0c2c19 | 2008-09-01 12:45:08 +0100 | [diff] [blame] | 567 | return 0; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Ben Hutchings | a5692e4 | 2008-12-26 13:46:38 -0800 | [diff] [blame] | 570 | static int efx_test_loopbacks(struct efx_nic *efx, struct efx_self_tests *tests, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 571 | unsigned int loopback_modes) |
| 572 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 573 | enum efx_loopback_mode mode; |
| 574 | struct efx_loopback_state *state; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 575 | struct efx_tx_queue *tx_queue; |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 576 | bool link_up; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 577 | int count, rc = 0; |
Ben Hutchings | f8ea0b6 | 2008-09-01 12:46:28 +0100 | [diff] [blame] | 578 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 579 | /* Set the port loopback_selftest member. From this point on |
| 580 | * all received packets will be dropped. Mark the state as |
| 581 | * "flushing" so all inflight packets are dropped */ |
| 582 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 583 | if (state == NULL) |
| 584 | return -ENOMEM; |
| 585 | BUG_ON(efx->loopback_selftest); |
| 586 | state->flush = true; |
| 587 | efx->loopback_selftest = state; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 588 | |
| 589 | /* Test all supported loopback modes */ |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 590 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 591 | if (!(loopback_modes & (1 << mode))) |
| 592 | continue; |
| 593 | |
| 594 | /* Move the port into the specified loopback mode. */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 595 | state->flush = true; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 596 | efx->loopback_mode = mode; |
| 597 | efx_reconfigure_port(efx); |
| 598 | |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 599 | /* Wait for the PHY to signal the link is up. Interrupts |
| 600 | * are enabled for PHY's using LASI, otherwise we poll() |
| 601 | * quickly */ |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 602 | count = 0; |
| 603 | do { |
| 604 | struct efx_channel *channel = &efx->channel[0]; |
| 605 | |
Ben Hutchings | 766ca0f | 2008-12-12 21:59:24 -0800 | [diff] [blame] | 606 | efx->phy_op->poll(efx); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 607 | schedule_timeout_uninterruptible(HZ / 10); |
| 608 | if (channel->work_pending) |
| 609 | efx_process_channel_now(channel); |
| 610 | /* Wait for PHY events to be processed */ |
| 611 | flush_workqueue(efx->workqueue); |
| 612 | rmb(); |
| 613 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 614 | /* We need both the phy and xaui links to be ok. |
| 615 | * rather than relying on the falcon_xmac irq/poll |
| 616 | * regime, just poll xaui directly */ |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame^] | 617 | link_up = efx->link_state.up; |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 618 | if (link_up && EFX_IS10G(efx) && |
| 619 | !falcon_xaui_link_ok(efx)) |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 620 | link_up = false; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 621 | |
| 622 | } while ((++count < 20) && !link_up); |
| 623 | |
| 624 | /* The link should now be up. If it isn't, there is no point |
| 625 | * in attempting a loopback test */ |
| 626 | if (!link_up) { |
| 627 | EFX_ERR(efx, "loopback %s never came up\n", |
| 628 | LOOPBACK_MODE(efx)); |
| 629 | rc = -EIO; |
| 630 | goto out; |
| 631 | } |
| 632 | |
| 633 | EFX_LOG(efx, "link came up in %s loopback in %d iterations\n", |
| 634 | LOOPBACK_MODE(efx), count); |
| 635 | |
| 636 | /* Test every TX queue */ |
| 637 | efx_for_each_tx_queue(tx_queue, efx) { |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 638 | state->offload_csum = (tx_queue->queue == |
| 639 | EFX_TX_QUEUE_OFFLOAD_CSUM); |
Ben Hutchings | f8ea0b6 | 2008-09-01 12:46:28 +0100 | [diff] [blame] | 640 | rc = efx_test_loopback(tx_queue, |
| 641 | &tests->loopback[mode]); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 642 | if (rc) |
| 643 | goto out; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | out: |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 648 | /* Remove the flush. The caller will remove the loopback setting */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 649 | state->flush = true; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 650 | efx->loopback_selftest = NULL; |
| 651 | wmb(); |
| 652 | kfree(state); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 653 | |
| 654 | return rc; |
| 655 | } |
| 656 | |
| 657 | /************************************************************************** |
| 658 | * |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 659 | * Entry point |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 660 | * |
| 661 | *************************************************************************/ |
| 662 | |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 663 | int efx_selftest(struct efx_nic *efx, struct efx_self_tests *tests, |
| 664 | unsigned flags) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 665 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 666 | enum efx_loopback_mode loopback_mode = efx->loopback_mode; |
| 667 | int phy_mode = efx->phy_mode; |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 668 | enum reset_type reset_method = RESET_TYPE_INVISIBLE; |
Ben Hutchings | a5692e4 | 2008-12-26 13:46:38 -0800 | [diff] [blame] | 669 | struct ethtool_cmd ecmd; |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 670 | struct efx_channel *channel; |
| 671 | int rc_test = 0, rc_reset = 0, rc; |
| 672 | |
| 673 | /* Online (i.e. non-disruptive) testing |
| 674 | * This checks interrupt generation, event delivery and PHY presence. */ |
| 675 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 676 | rc = efx_test_mdio(efx, tests); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 677 | if (rc && !rc_test) |
| 678 | rc_test = rc; |
| 679 | |
| 680 | rc = efx_test_nvram(efx, tests); |
| 681 | if (rc && !rc_test) |
| 682 | rc_test = rc; |
| 683 | |
| 684 | rc = efx_test_interrupts(efx, tests); |
| 685 | if (rc && !rc_test) |
| 686 | rc_test = rc; |
| 687 | |
| 688 | efx_for_each_channel(channel, efx) { |
| 689 | rc = efx_test_eventq_irq(channel, tests); |
| 690 | if (rc && !rc_test) |
| 691 | rc_test = rc; |
| 692 | } |
| 693 | |
| 694 | if (rc_test) |
| 695 | return rc_test; |
| 696 | |
| 697 | if (!(flags & ETH_TEST_FL_OFFLINE)) |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 698 | return efx_test_phy(efx, tests, flags); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 699 | |
| 700 | /* Offline (i.e. disruptive) testing |
| 701 | * This checks MAC and PHY loopback on the specified port. */ |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 702 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 703 | /* force the carrier state off so the kernel doesn't transmit during |
| 704 | * the loopback test, and the watchdog timeout doesn't fire. Also put |
| 705 | * falcon into loopback for the register test. |
| 706 | */ |
| 707 | mutex_lock(&efx->mac_lock); |
| 708 | efx->port_inhibited = true; |
Ben Hutchings | 6f158d5 | 2008-12-12 22:00:49 -0800 | [diff] [blame] | 709 | if (efx->loopback_modes) { |
| 710 | /* We need the 312 clock from the PHY to test the XMAC |
| 711 | * registers, so move into XGMII loopback if available */ |
| 712 | if (efx->loopback_modes & (1 << LOOPBACK_XGMII)) |
| 713 | efx->loopback_mode = LOOPBACK_XGMII; |
| 714 | else |
| 715 | efx->loopback_mode = __ffs(efx->loopback_modes); |
| 716 | } |
| 717 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 718 | __efx_reconfigure_port(efx); |
| 719 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 720 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 721 | /* free up all consumers of SRAM (including all the queues) */ |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 722 | efx_reset_down(efx, reset_method, &ecmd); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 723 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 724 | rc = efx_test_chip(efx, tests); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 725 | if (rc && !rc_test) |
| 726 | rc_test = rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 727 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 728 | /* reset the chip to recover from the register test */ |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 729 | rc_reset = falcon_reset_hw(efx, reset_method); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 730 | |
Ben Hutchings | a5692e4 | 2008-12-26 13:46:38 -0800 | [diff] [blame] | 731 | /* Ensure that the phy is powered and out of loopback |
| 732 | * for the bist and loopback tests */ |
| 733 | efx->phy_mode &= ~PHY_MODE_LOW_POWER; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 734 | efx->loopback_mode = LOOPBACK_NONE; |
| 735 | |
Steve Hodgson | 4b98828 | 2009-01-29 17:50:51 +0000 | [diff] [blame] | 736 | rc = efx_reset_up(efx, reset_method, &ecmd, rc_reset == 0); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 737 | if (rc && !rc_reset) |
| 738 | rc_reset = rc; |
| 739 | |
| 740 | if (rc_reset) { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 741 | EFX_ERR(efx, "Unable to recover from chip test\n"); |
| 742 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 743 | return rc_reset; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 746 | rc = efx_test_phy(efx, tests, flags); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 747 | if (rc && !rc_test) |
| 748 | rc_test = rc; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 749 | |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 750 | rc = efx_test_loopbacks(efx, tests, efx->loopback_modes); |
| 751 | if (rc && !rc_test) |
| 752 | rc_test = rc; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 753 | |
| 754 | /* restore the PHY to the previous state */ |
| 755 | efx->loopback_mode = loopback_mode; |
| 756 | efx->phy_mode = phy_mode; |
| 757 | efx->port_inhibited = false; |
| 758 | efx_ethtool_set_settings(efx->net_dev, &ecmd); |
| 759 | |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 760 | return rc_test; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 761 | } |
| 762 | |