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