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]; |
Eric Dumazet | ba2d358 | 2010-06-02 18:10:09 +0000 | [diff] [blame] | 41 | } __packed; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 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 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 126 | netif_dbg(efx, drv, efx->net_dev, "testing interrupts\n"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 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. */ |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 145 | netif_dbg(efx, drv, efx->net_dev, "waiting for test interrupt\n"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 146 | schedule_timeout_uninterruptible(HZ / 10); |
| 147 | if (efx->last_irq_cpu >= 0) |
| 148 | goto success; |
| 149 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 150 | netif_err(efx, drv, efx->net_dev, "timed out waiting for interrupt\n"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 151 | return -ETIMEDOUT; |
| 152 | |
| 153 | success: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 154 | netif_dbg(efx, drv, efx->net_dev, "%s test interrupt seen on CPU%d\n", |
| 155 | INT_MODE(efx), |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 156 | efx->last_irq_cpu); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 157 | tests->interrupt = 1; |
| 158 | return 0; |
| 159 | } |
| 160 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 161 | /* Test generation and receipt of interrupting events */ |
| 162 | static int efx_test_eventq_irq(struct efx_channel *channel, |
| 163 | struct efx_self_tests *tests) |
| 164 | { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 165 | struct efx_nic *efx = channel->efx; |
Steve Hodgson | d730dc5 | 2010-06-01 11:19:09 +0000 | [diff] [blame] | 166 | unsigned int magic_count, count; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 167 | |
| 168 | tests->eventq_dma[channel->channel] = -1; |
| 169 | tests->eventq_int[channel->channel] = -1; |
| 170 | tests->eventq_poll[channel->channel] = -1; |
| 171 | |
Steve Hodgson | d730dc5 | 2010-06-01 11:19:09 +0000 | [diff] [blame] | 172 | magic_count = channel->magic_count; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 173 | channel->efx->last_irq_cpu = -1; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 174 | smp_wmb(); |
| 175 | |
Steve Hodgson | d730dc5 | 2010-06-01 11:19:09 +0000 | [diff] [blame] | 176 | efx_nic_generate_test_event(channel); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 177 | |
| 178 | /* Wait for arrival of interrupt */ |
| 179 | count = 0; |
| 180 | do { |
| 181 | schedule_timeout_uninterruptible(HZ / 100); |
| 182 | |
| 183 | if (channel->work_pending) |
| 184 | efx_process_channel_now(channel); |
| 185 | |
Steve Hodgson | d730dc5 | 2010-06-01 11:19:09 +0000 | [diff] [blame] | 186 | if (channel->magic_count != magic_count) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 187 | goto eventq_ok; |
| 188 | } while (++count < 2); |
| 189 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 190 | netif_err(efx, drv, efx->net_dev, |
| 191 | "channel %d timed out waiting for event queue\n", |
| 192 | channel->channel); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 193 | |
| 194 | /* See if interrupt arrived */ |
| 195 | if (channel->efx->last_irq_cpu >= 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 196 | netif_err(efx, drv, efx->net_dev, |
| 197 | "channel %d saw interrupt on CPU%d " |
| 198 | "during event queue test\n", channel->channel, |
| 199 | raw_smp_processor_id()); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 200 | tests->eventq_int[channel->channel] = 1; |
| 201 | } |
| 202 | |
| 203 | /* Check to see if event was received even if interrupt wasn't */ |
| 204 | efx_process_channel_now(channel); |
Steve Hodgson | d730dc5 | 2010-06-01 11:19:09 +0000 | [diff] [blame] | 205 | if (channel->magic_count != magic_count) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 206 | netif_err(efx, drv, efx->net_dev, |
| 207 | "channel %d event was generated, but " |
| 208 | "failed to trigger an interrupt\n", channel->channel); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 209 | tests->eventq_dma[channel->channel] = 1; |
| 210 | } |
| 211 | |
| 212 | return -ETIMEDOUT; |
| 213 | eventq_ok: |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 214 | netif_dbg(efx, drv, efx->net_dev, "channel %d event queue passed\n", |
| 215 | channel->channel); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 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)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 268 | netif_err(efx, drv, efx->net_dev, |
| 269 | "saw runt RX packet (length %d) in %s loopback " |
| 270 | "test\n", pkt_len, LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 271 | goto err; |
| 272 | } |
| 273 | |
| 274 | /* Check that the ethernet header exists */ |
| 275 | if (memcmp(&received->header, &payload->header, ETH_HLEN) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 276 | netif_err(efx, drv, efx->net_dev, |
| 277 | "saw non-loopback RX packet in %s loopback test\n", |
| 278 | LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 279 | goto err; |
| 280 | } |
| 281 | |
| 282 | /* Check packet length */ |
| 283 | if (pkt_len != sizeof(*payload)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 284 | netif_err(efx, drv, efx->net_dev, |
| 285 | "saw incorrect RX packet length %d (wanted %d) in " |
| 286 | "%s loopback test\n", pkt_len, (int)sizeof(*payload), |
| 287 | LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 288 | goto err; |
| 289 | } |
| 290 | |
| 291 | /* Check that IP header matches */ |
| 292 | if (memcmp(&received->ip, &payload->ip, sizeof(payload->ip)) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 293 | netif_err(efx, drv, efx->net_dev, |
| 294 | "saw corrupted IP header in %s loopback test\n", |
| 295 | LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 296 | goto err; |
| 297 | } |
| 298 | |
| 299 | /* Check that msg and padding matches */ |
| 300 | if (memcmp(&received->msg, &payload->msg, sizeof(received->msg)) != 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 301 | netif_err(efx, drv, efx->net_dev, |
| 302 | "saw corrupted RX packet in %s loopback test\n", |
| 303 | LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 304 | goto err; |
| 305 | } |
| 306 | |
| 307 | /* Check that iteration matches */ |
| 308 | if (received->iteration != payload->iteration) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 309 | netif_err(efx, drv, efx->net_dev, |
| 310 | "saw RX packet from iteration %d (wanted %d) in " |
| 311 | "%s loopback test\n", ntohs(received->iteration), |
| 312 | ntohs(payload->iteration), LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 313 | goto err; |
| 314 | } |
| 315 | |
| 316 | /* Increase correct RX count */ |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 317 | netif_vdbg(efx, drv, efx->net_dev, |
| 318 | "got loopback RX in %s loopback test\n", LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 319 | |
| 320 | atomic_inc(&state->rx_good); |
| 321 | return; |
| 322 | |
| 323 | err: |
| 324 | #ifdef EFX_ENABLE_DEBUG |
| 325 | if (atomic_read(&state->rx_bad) == 0) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 326 | netif_err(efx, drv, efx->net_dev, "received packet:\n"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 327 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1, |
| 328 | buf_ptr, pkt_len, 0); |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 329 | netif_err(efx, drv, efx->net_dev, "expected packet:\n"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 330 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1, |
| 331 | &state->payload, sizeof(state->payload), 0); |
| 332 | } |
| 333 | #endif |
| 334 | atomic_inc(&state->rx_bad); |
| 335 | } |
| 336 | |
| 337 | /* Initialise an efx_selftest_state for a new iteration */ |
| 338 | static void efx_iterate_state(struct efx_nic *efx) |
| 339 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 340 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 341 | struct net_device *net_dev = efx->net_dev; |
| 342 | struct efx_loopback_payload *payload = &state->payload; |
| 343 | |
| 344 | /* Initialise the layerII header */ |
| 345 | memcpy(&payload->header.h_dest, net_dev->dev_addr, ETH_ALEN); |
| 346 | memcpy(&payload->header.h_source, &payload_source, ETH_ALEN); |
| 347 | payload->header.h_proto = htons(ETH_P_IP); |
| 348 | |
| 349 | /* saddr set later and used as incrementing count */ |
| 350 | payload->ip.daddr = htonl(INADDR_LOOPBACK); |
| 351 | payload->ip.ihl = 5; |
| 352 | payload->ip.check = htons(0xdead); |
| 353 | payload->ip.tot_len = htons(sizeof(*payload) - sizeof(struct ethhdr)); |
| 354 | payload->ip.version = IPVERSION; |
| 355 | payload->ip.protocol = IPPROTO_UDP; |
| 356 | |
| 357 | /* Initialise udp header */ |
| 358 | payload->udp.source = 0; |
| 359 | payload->udp.len = htons(sizeof(*payload) - sizeof(struct ethhdr) - |
| 360 | sizeof(struct iphdr)); |
| 361 | payload->udp.check = 0; /* checksum ignored */ |
| 362 | |
| 363 | /* Fill out payload */ |
| 364 | payload->iteration = htons(ntohs(payload->iteration) + 1); |
| 365 | memcpy(&payload->msg, payload_msg, sizeof(payload_msg)); |
| 366 | |
| 367 | /* Fill out remaining state members */ |
| 368 | atomic_set(&state->rx_good, 0); |
| 369 | atomic_set(&state->rx_bad, 0); |
| 370 | smp_wmb(); |
| 371 | } |
| 372 | |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 373 | static int efx_begin_loopback(struct efx_tx_queue *tx_queue) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 374 | { |
| 375 | struct efx_nic *efx = tx_queue->efx; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 376 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 377 | struct efx_loopback_payload *payload; |
| 378 | struct sk_buff *skb; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 379 | int i; |
| 380 | netdev_tx_t rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 381 | |
| 382 | /* Transmit N copies of buffer */ |
| 383 | for (i = 0; i < state->packet_count; i++) { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 384 | /* Allocate an skb, holding an extra reference for |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 385 | * transmit completion counting */ |
| 386 | skb = alloc_skb(sizeof(state->payload), GFP_KERNEL); |
| 387 | if (!skb) |
| 388 | return -ENOMEM; |
| 389 | state->skbs[i] = skb; |
| 390 | skb_get(skb); |
| 391 | |
| 392 | /* Copy the payload in, incrementing the source address to |
| 393 | * exercise the rss vectors */ |
| 394 | payload = ((struct efx_loopback_payload *) |
| 395 | skb_put(skb, sizeof(state->payload))); |
| 396 | memcpy(payload, &state->payload, sizeof(state->payload)); |
| 397 | payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); |
| 398 | |
| 399 | /* Ensure everything we've written is visible to the |
| 400 | * interrupt handler. */ |
| 401 | smp_wmb(); |
| 402 | |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 403 | if (efx_dev_registered(efx)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 404 | netif_tx_lock_bh(efx->net_dev); |
Ben Hutchings | 497f5ba | 2009-11-23 16:07:05 +0000 | [diff] [blame] | 405 | rc = efx_enqueue_skb(tx_queue, skb); |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 406 | if (efx_dev_registered(efx)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 407 | netif_tx_unlock_bh(efx->net_dev); |
| 408 | |
| 409 | if (rc != NETDEV_TX_OK) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 410 | netif_err(efx, drv, efx->net_dev, |
| 411 | "TX queue %d could not transmit packet %d of " |
| 412 | "%d in %s loopback test\n", tx_queue->queue, |
| 413 | i + 1, state->packet_count, |
| 414 | LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 415 | |
| 416 | /* Defer cleaning up the other skbs for the caller */ |
| 417 | kfree_skb(skb); |
| 418 | return -EPIPE; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 425 | static int efx_poll_loopback(struct efx_nic *efx) |
| 426 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 427 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 428 | struct efx_channel *channel; |
| 429 | |
| 430 | /* NAPI polling is not enabled, so process channels |
| 431 | * synchronously */ |
Ben Hutchings | 64ee312 | 2008-09-01 12:47:38 +0100 | [diff] [blame] | 432 | efx_for_each_channel(channel, efx) { |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 433 | if (channel->work_pending) |
| 434 | efx_process_channel_now(channel); |
| 435 | } |
| 436 | return atomic_read(&state->rx_good) == state->packet_count; |
| 437 | } |
| 438 | |
| 439 | static int efx_end_loopback(struct efx_tx_queue *tx_queue, |
| 440 | struct efx_loopback_self_tests *lb_tests) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 441 | { |
| 442 | struct efx_nic *efx = tx_queue->efx; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 443 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 444 | struct sk_buff *skb; |
| 445 | int tx_done = 0, rx_good, rx_bad; |
| 446 | int i, rc = 0; |
| 447 | |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 448 | if (efx_dev_registered(efx)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 449 | netif_tx_lock_bh(efx->net_dev); |
| 450 | |
| 451 | /* Count the number of tx completions, and decrement the refcnt. Any |
| 452 | * skbs not already completed will be free'd when the queue is flushed */ |
| 453 | for (i=0; i < state->packet_count; i++) { |
| 454 | skb = state->skbs[i]; |
| 455 | if (skb && !skb_shared(skb)) |
| 456 | ++tx_done; |
| 457 | dev_kfree_skb_any(skb); |
| 458 | } |
| 459 | |
Ben Hutchings | 5566861 | 2008-05-16 21:16:10 +0100 | [diff] [blame] | 460 | if (efx_dev_registered(efx)) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 461 | netif_tx_unlock_bh(efx->net_dev); |
| 462 | |
| 463 | /* Check TX completion and received packet counts */ |
| 464 | rx_good = atomic_read(&state->rx_good); |
| 465 | rx_bad = atomic_read(&state->rx_bad); |
| 466 | if (tx_done != state->packet_count) { |
| 467 | /* Don't free the skbs; they will be picked up on TX |
| 468 | * overflow or channel teardown. |
| 469 | */ |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 470 | netif_err(efx, drv, efx->net_dev, |
| 471 | "TX queue %d saw only %d out of an expected %d " |
| 472 | "TX completion events in %s loopback test\n", |
| 473 | tx_queue->queue, tx_done, state->packet_count, |
| 474 | LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 475 | rc = -ETIMEDOUT; |
| 476 | /* Allow to fall through so we see the RX errors as well */ |
| 477 | } |
| 478 | |
| 479 | /* We may always be up to a flush away from our desired packet total */ |
| 480 | if (rx_good != state->packet_count) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 481 | netif_dbg(efx, drv, efx->net_dev, |
| 482 | "TX queue %d saw only %d out of an expected %d " |
| 483 | "received packets in %s loopback test\n", |
| 484 | tx_queue->queue, rx_good, state->packet_count, |
| 485 | LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 486 | rc = -ETIMEDOUT; |
| 487 | /* Fall through */ |
| 488 | } |
| 489 | |
| 490 | /* Update loopback test structure */ |
| 491 | lb_tests->tx_sent[tx_queue->queue] += state->packet_count; |
| 492 | lb_tests->tx_done[tx_queue->queue] += tx_done; |
| 493 | lb_tests->rx_good += rx_good; |
| 494 | lb_tests->rx_bad += rx_bad; |
| 495 | |
| 496 | return rc; |
| 497 | } |
| 498 | |
| 499 | static int |
| 500 | efx_test_loopback(struct efx_tx_queue *tx_queue, |
| 501 | struct efx_loopback_self_tests *lb_tests) |
| 502 | { |
| 503 | struct efx_nic *efx = tx_queue->efx; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 504 | struct efx_loopback_state *state = efx->loopback_selftest; |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 505 | int i, begin_rc, end_rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 506 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 507 | for (i = 0; i < 3; i++) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 508 | /* Determine how many packets to send */ |
Ben Hutchings | 3ffeabd | 2009-10-23 08:30:58 +0000 | [diff] [blame] | 509 | state->packet_count = EFX_TXQ_SIZE / 3; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 510 | state->packet_count = min(1 << (i << 2), state->packet_count); |
| 511 | state->skbs = kzalloc(sizeof(state->skbs[0]) * |
| 512 | state->packet_count, GFP_KERNEL); |
Ben Hutchings | 9b7bfc4 | 2008-05-16 21:20:20 +0100 | [diff] [blame] | 513 | if (!state->skbs) |
| 514 | return -ENOMEM; |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 515 | state->flush = false; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 516 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 517 | netif_dbg(efx, drv, efx->net_dev, |
| 518 | "TX queue %d testing %s loopback with %d packets\n", |
| 519 | tx_queue->queue, LOOPBACK_MODE(efx), |
| 520 | state->packet_count); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 521 | |
| 522 | efx_iterate_state(efx); |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 523 | begin_rc = efx_begin_loopback(tx_queue); |
| 524 | |
| 525 | /* This will normally complete very quickly, but be |
| 526 | * prepared to wait up to 100 ms. */ |
| 527 | msleep(1); |
| 528 | if (!efx_poll_loopback(efx)) { |
| 529 | msleep(100); |
| 530 | efx_poll_loopback(efx); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 533 | end_rc = efx_end_loopback(tx_queue, lb_tests); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 534 | kfree(state->skbs); |
| 535 | |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 536 | if (begin_rc || end_rc) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 537 | /* Wait a while to ensure there are no packets |
| 538 | * floating around after a failure. */ |
| 539 | schedule_timeout_uninterruptible(HZ / 10); |
Ben Hutchings | b9aafb0 | 2008-09-01 12:46:33 +0100 | [diff] [blame] | 540 | return begin_rc ? begin_rc : end_rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 544 | netif_dbg(efx, drv, efx->net_dev, |
| 545 | "TX queue %d passed %s loopback test with a burst length " |
| 546 | "of %d packets\n", tx_queue->queue, LOOPBACK_MODE(efx), |
| 547 | state->packet_count); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 548 | |
Ben Hutchings | a0c2c19 | 2008-09-01 12:45:08 +0100 | [diff] [blame] | 549 | return 0; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 550 | } |
| 551 | |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 552 | /* Wait for link up. On Falcon, we would prefer to rely on efx_monitor, but |
| 553 | * any contention on the mac lock (via e.g. efx_mac_mcast_work) causes it |
| 554 | * to delay and retry. Therefore, it's safer to just poll directly. Wait |
| 555 | * for link up and any faults to dissipate. */ |
| 556 | static int efx_wait_for_link(struct efx_nic *efx) |
| 557 | { |
| 558 | struct efx_link_state *link_state = &efx->link_state; |
Steve Hodgson | 901d3fe | 2010-06-01 11:18:28 +0000 | [diff] [blame] | 559 | int count, link_up_count = 0; |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 560 | bool link_up; |
| 561 | |
| 562 | for (count = 0; count < 40; count++) { |
| 563 | schedule_timeout_uninterruptible(HZ / 10); |
| 564 | |
| 565 | if (efx->type->monitor != NULL) { |
| 566 | mutex_lock(&efx->mac_lock); |
| 567 | efx->type->monitor(efx); |
| 568 | mutex_unlock(&efx->mac_lock); |
| 569 | } else { |
| 570 | struct efx_channel *channel = &efx->channel[0]; |
| 571 | if (channel->work_pending) |
| 572 | efx_process_channel_now(channel); |
| 573 | } |
| 574 | |
| 575 | mutex_lock(&efx->mac_lock); |
| 576 | link_up = link_state->up; |
| 577 | if (link_up) |
| 578 | link_up = !efx->mac_op->check_fault(efx); |
| 579 | mutex_unlock(&efx->mac_lock); |
| 580 | |
Steve Hodgson | 901d3fe | 2010-06-01 11:18:28 +0000 | [diff] [blame] | 581 | if (link_up) { |
| 582 | if (++link_up_count == 2) |
| 583 | return 0; |
| 584 | } else { |
| 585 | link_up_count = 0; |
| 586 | } |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | return -ETIMEDOUT; |
| 590 | } |
| 591 | |
Ben Hutchings | a5692e4 | 2008-12-26 13:46:38 -0800 | [diff] [blame] | 592 | 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] | 593 | unsigned int loopback_modes) |
| 594 | { |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 595 | enum efx_loopback_mode mode; |
| 596 | struct efx_loopback_state *state; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 597 | struct efx_tx_queue *tx_queue; |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 598 | int rc = 0; |
Ben Hutchings | f8ea0b6 | 2008-09-01 12:46:28 +0100 | [diff] [blame] | 599 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 600 | /* Set the port loopback_selftest member. From this point on |
| 601 | * all received packets will be dropped. Mark the state as |
| 602 | * "flushing" so all inflight packets are dropped */ |
| 603 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 604 | if (state == NULL) |
| 605 | return -ENOMEM; |
| 606 | BUG_ON(efx->loopback_selftest); |
| 607 | state->flush = true; |
| 608 | efx->loopback_selftest = state; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 609 | |
| 610 | /* Test all supported loopback modes */ |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 611 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 612 | if (!(loopback_modes & (1 << mode))) |
| 613 | continue; |
| 614 | |
| 615 | /* Move the port into the specified loopback mode. */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 616 | state->flush = true; |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 617 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 618 | efx->loopback_mode = mode; |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 619 | rc = __efx_reconfigure_port(efx); |
| 620 | mutex_unlock(&efx->mac_lock); |
| 621 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 622 | netif_err(efx, drv, efx->net_dev, |
| 623 | "unable to move into %s loopback\n", |
| 624 | LOOPBACK_MODE(efx)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 625 | goto out; |
| 626 | } |
| 627 | |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 628 | rc = efx_wait_for_link(efx); |
| 629 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 630 | netif_err(efx, drv, efx->net_dev, |
| 631 | "loopback %s never came up\n", |
| 632 | LOOPBACK_MODE(efx)); |
Steve Hodgson | 78c1f0a | 2009-11-29 03:43:00 +0000 | [diff] [blame] | 633 | goto out; |
| 634 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 635 | |
Ben Hutchings | 5298c37 | 2010-04-28 09:30:30 +0000 | [diff] [blame] | 636 | /* Test both types of TX queue */ |
| 637 | efx_for_each_channel_tx_queue(tx_queue, &efx->channel[0]) { |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 638 | state->offload_csum = (tx_queue->queue & |
| 639 | EFX_TXQ_TYPE_OFFLOAD); |
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 | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 669 | struct efx_channel *channel; |
| 670 | int rc_test = 0, rc_reset = 0, rc; |
| 671 | |
| 672 | /* Online (i.e. non-disruptive) testing |
| 673 | * This checks interrupt generation, event delivery and PHY presence. */ |
| 674 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 675 | rc = efx_test_phy_alive(efx, tests); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 676 | if (rc && !rc_test) |
| 677 | rc_test = rc; |
| 678 | |
| 679 | rc = efx_test_nvram(efx, tests); |
| 680 | if (rc && !rc_test) |
| 681 | rc_test = rc; |
| 682 | |
| 683 | rc = efx_test_interrupts(efx, tests); |
| 684 | if (rc && !rc_test) |
| 685 | rc_test = rc; |
| 686 | |
| 687 | efx_for_each_channel(channel, efx) { |
| 688 | rc = efx_test_eventq_irq(channel, tests); |
| 689 | if (rc && !rc_test) |
| 690 | rc_test = rc; |
| 691 | } |
| 692 | |
| 693 | if (rc_test) |
| 694 | return rc_test; |
| 695 | |
| 696 | if (!(flags & ETH_TEST_FL_OFFLINE)) |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 697 | return efx_test_phy(efx, tests, flags); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 698 | |
| 699 | /* Offline (i.e. disruptive) testing |
| 700 | * This checks MAC and PHY loopback on the specified port. */ |
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 | /* force the carrier state off so the kernel doesn't transmit during |
| 703 | * the loopback test, and the watchdog timeout doesn't fire. Also put |
| 704 | * falcon into loopback for the register test. |
| 705 | */ |
| 706 | mutex_lock(&efx->mac_lock); |
| 707 | efx->port_inhibited = true; |
Ben Hutchings | 6f158d5 | 2008-12-12 22:00:49 -0800 | [diff] [blame] | 708 | if (efx->loopback_modes) { |
| 709 | /* We need the 312 clock from the PHY to test the XMAC |
| 710 | * registers, so move into XGMII loopback if available */ |
| 711 | if (efx->loopback_modes & (1 << LOOPBACK_XGMII)) |
| 712 | efx->loopback_mode = LOOPBACK_XGMII; |
| 713 | else |
| 714 | efx->loopback_mode = __ffs(efx->loopback_modes); |
| 715 | } |
| 716 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 717 | __efx_reconfigure_port(efx); |
| 718 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 719 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 720 | /* free up all consumers of SRAM (including all the queues) */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 721 | efx_reset_down(efx, reset_method); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 722 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 723 | rc = efx_test_chip(efx, tests); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 724 | if (rc && !rc_test) |
| 725 | rc_test = rc; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 726 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 727 | /* reset the chip to recover from the register test */ |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 728 | rc_reset = efx->type->reset(efx, reset_method); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 729 | |
Ben Hutchings | a5692e4 | 2008-12-26 13:46:38 -0800 | [diff] [blame] | 730 | /* Ensure that the phy is powered and out of loopback |
| 731 | * for the bist and loopback tests */ |
| 732 | efx->phy_mode &= ~PHY_MODE_LOW_POWER; |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 733 | efx->loopback_mode = LOOPBACK_NONE; |
| 734 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 735 | rc = efx_reset_up(efx, reset_method, rc_reset == 0); |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 736 | if (rc && !rc_reset) |
| 737 | rc_reset = rc; |
| 738 | |
| 739 | if (rc_reset) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame^] | 740 | netif_err(efx, drv, efx->net_dev, |
| 741 | "Unable to recover from chip test\n"); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 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 */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 755 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 756 | efx->phy_mode = phy_mode; |
| 757 | efx->port_inhibited = false; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 758 | efx->loopback_mode = loopback_mode; |
| 759 | __efx_reconfigure_port(efx); |
| 760 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 761 | |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 762 | return rc_test; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 763 | } |
| 764 | |