11 #include <linux/netdevice.h>
12 #include <linux/module.h>
15 #include <linux/pci.h>
16 #include <linux/ethtool.h>
19 #include <linux/udp.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/slab.h>
36 #define IRQ_TIMEOUT HZ
53 static const unsigned char payload_source[
ETH_ALEN] = {
54 0x00, 0x0f, 0x53, 0x1b, 0x1b, 0x1b,
57 static const char payload_msg[] =
58 "Hello world! This is an Efx loopback test in progress!";
62 static const char *
const efx_interrupt_mode_names[] = {
67 #define INT_MODE(efx) \
68 STRING_TABLE_LOOKUP(efx->interrupt_mode, efx_interrupt_mode)
91 #define LOOPBACK_TIMEOUT_MS 1000
103 if (efx->
phy_op->test_alive) {
104 rc = efx->
phy_op->test_alive(efx);
115 if (efx->
type->test_nvram) {
116 rc = efx->
type->test_nvram(efx);
117 tests->
nvram = rc ? -1 : 1;
130 static int efx_test_interrupts(
struct efx_nic *efx,
147 cpu = efx_nic_irq_test_irq_cpu(efx);
164 static int efx_test_eventq_irq(
struct efx_nic *efx,
169 unsigned long napi_ran = 0, dma_pend = 0, int_pend = 0;
170 unsigned long timeout,
wait;
200 if (efx_nic_event_test_irq_cpu(channel) >= 0)
208 }
while ((dma_pend || int_pend) &&
time_before(jiffies, timeout));
217 if (dma_seen && int_seen) {
219 "channel %d event queue passed (with%s NAPI)\n",
228 "channel %d timed out waiting for event queue\n",
232 "channel %d saw interrupt "
233 "during event queue test\n",
237 "channel %d event was generated, but "
238 "failed to trigger an interrupt\n",
243 return (dma_pend || int_pend) ? -
ETIMEDOUT : 0;
251 if (!efx->
phy_op->run_tests)
286 received->
ip.saddr = payload->
ip.saddr;
288 received->
ip.check = payload->
ip.check;
291 if (pkt_len <
sizeof(received->
header)) {
293 "saw runt RX packet (length %d) in %s loopback "
301 "saw non-loopback RX packet in %s loopback test\n",
307 if (pkt_len !=
sizeof(*payload)) {
309 "saw incorrect RX packet length %d (wanted %d) in "
310 "%s loopback test\n", pkt_len, (
int)
sizeof(*payload),
316 if (
memcmp(&received->
ip, &payload->
ip,
sizeof(payload->
ip)) != 0) {
318 "saw corrupted IP header in %s loopback test\n",
324 if (
memcmp(&received->
msg, &payload->
msg,
sizeof(received->
msg)) != 0) {
326 "saw corrupted RX packet in %s loopback test\n",
334 "saw RX packet from iteration %d (wanted %d) in "
342 "got loopback RX in %s loopback test\n",
LOOPBACK_MODE(efx));
352 buf_ptr, pkt_len, 0);
362 static void efx_iterate_state(
struct efx_nic *efx)
376 payload->
ip.check =
htons(0xdead);
377 payload->
ip.tot_len =
htons(
sizeof(*payload) -
sizeof(
struct ethhdr));
382 payload->
udp.source = 0;
383 payload->
udp.len =
htons(
sizeof(*payload) -
sizeof(
struct ethhdr) -
384 sizeof(
struct iphdr));
385 payload->
udp.check = 0;
389 memcpy(&payload->
msg, payload_msg,
sizeof(payload_msg));
399 struct efx_nic *efx = tx_queue->efx;
427 netif_tx_lock_bh(efx->
net_dev);
429 netif_tx_unlock_bh(efx->
net_dev);
433 "TX queue %d could not transmit packet %d of "
434 "%d in %s loopback test\n", tx_queue->
queue,
447 static int efx_poll_loopback(
struct efx_nic *efx)
461 static int efx_end_loopback(
struct efx_tx_queue *tx_queue,
464 struct efx_nic *efx = tx_queue->efx;
467 int tx_done = 0, rx_good, rx_bad;
470 netif_tx_lock_bh(efx->
net_dev);
475 skb = state->
skbs[
i];
476 if (skb && !skb_shared(skb))
481 netif_tx_unlock_bh(efx->
net_dev);
491 "TX queue %d saw only %d out of an expected %d "
492 "TX completion events in %s loopback test\n",
502 "TX queue %d saw only %d out of an expected %d "
503 "received packets in %s loopback test\n",
514 lb_tests->
rx_bad += rx_bad;
523 struct efx_nic *efx = tx_queue->efx;
525 int i, begin_rc, end_rc;
527 for (i = 0; i < 3; i++) {
535 state->
flush =
false;
538 "TX queue %d testing %s loopback with %d packets\n",
542 efx_iterate_state(efx);
543 begin_rc = efx_begin_loopback(tx_queue);
548 if (!efx_poll_loopback(efx)) {
550 efx_poll_loopback(efx);
553 end_rc = efx_end_loopback(tx_queue, lb_tests);
556 if (begin_rc || end_rc) {
560 return begin_rc ? begin_rc : end_rc;
565 "TX queue %d passed %s loopback test with a burst length "
576 static int efx_wait_for_link(
struct efx_nic *efx)
579 int count, link_up_count = 0;
582 for (count = 0; count < 40; count++) {
587 efx->
type->monitor(efx);
590 struct efx_channel *channel = efx_get_channel(efx, 0);
596 link_up = link_state->
up;
598 link_up = !efx->
type->check_mac_fault(efx);
602 if (++link_up_count == 2)
613 unsigned int loopback_modes)
634 if (!(loopback_modes & (1 << mode)))
645 "unable to move into %s loopback\n",
650 rc = efx_wait_for_link(efx);
653 "loopback %s never came up\n",
662 rc = efx_test_loopback(tx_queue,
690 int rc_test = 0, rc_reset,
rc;
697 rc = efx_test_phy_alive(efx, tests);
701 rc = efx_test_nvram(efx, tests);
705 rc = efx_test_interrupts(efx, tests);
709 rc = efx_test_eventq_irq(efx, tests);
717 return efx_test_phy(efx, tests, flags);
727 if (efx->
type->test_chip) {
728 rc_reset = efx->
type->test_chip(efx, tests);
731 "Unable to recover from chip test\n");
748 rc = efx_test_phy(efx, tests, flags);
790 cpu = efx_nic_event_test_irq_cpu(channel);
793 "channel %d failed to trigger an interrupt\n",
797 "channel %d triggered interrupt on CPU %d\n",