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