Lines Matching +full:no +full:- +full:loopback +full:- +full:test
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright 2005-2006 Fen Systems Ltd.
5 * Copyright 2006-2012 Solarflare Communications Inc.
26 * - All IRQs may be disabled on a CPU for a *long* time by e.g. a
28 * - The PREEMPT_RT patches mostly deal with this, but also allow a
36 * Loopback test packet structure
38 * The self-test should stress every RSS vector, and unfortunately
42 char pad[2]; /* Ensures ip is 4-byte aligned */
54 /* Loopback test source MAC address */
60 "Hello world! This is an Efx loopback test in progress!";
65 [EF4_INT_MODE_MSIX] = "MSI-X",
70 STRING_TABLE_LOOKUP(efx->interrupt_mode, ef4_interrupt_mode)
73 * struct ef4_loopback_state - persistent state during a loopback selftest
75 * @packet_count: Number of packets being used in this test
105 if (efx->phy_op->test_alive) { in ef4_test_phy_alive()
106 rc = efx->phy_op->test_alive(efx); in ef4_test_phy_alive()
107 tests->phy_alive = rc ? -1 : 1; in ef4_test_phy_alive()
117 if (efx->type->test_nvram) { in ef4_test_nvram()
118 rc = efx->type->test_nvram(efx); in ef4_test_nvram()
119 if (rc == -EPERM) in ef4_test_nvram()
122 tests->nvram = rc ? -1 : 1; in ef4_test_nvram()
134 /* Test generation and receipt of interrupts */
142 netif_dbg(efx, drv, efx->net_dev, "testing interrupts\n"); in ef4_test_interrupts()
143 tests->interrupt = -1; in ef4_test_interrupts()
146 if (rc == -ENOTSUPP) { in ef4_test_interrupts()
147 netif_dbg(efx, drv, efx->net_dev, in ef4_test_interrupts()
149 tests->interrupt = 0; in ef4_test_interrupts()
156 /* Wait for arrival of test interrupt. */ in ef4_test_interrupts()
157 netif_dbg(efx, drv, efx->net_dev, "waiting for test interrupt\n"); in ef4_test_interrupts()
166 netif_err(efx, drv, efx->net_dev, "timed out waiting for interrupt\n"); in ef4_test_interrupts()
167 return -ETIMEDOUT; in ef4_test_interrupts()
170 netif_dbg(efx, drv, efx->net_dev, "%s test interrupt seen on CPU%d\n", in ef4_test_interrupts()
172 tests->interrupt = 1; in ef4_test_interrupts()
176 /* Test generation and receipt of interrupting events */
188 read_ptr[channel->channel] = channel->eventq_read_ptr; in ef4_test_eventq_irq()
189 set_bit(channel->channel, &dma_pend); in ef4_test_eventq_irq()
190 set_bit(channel->channel, &int_pend); in ef4_test_eventq_irq()
205 if (channel->eventq_read_ptr != in ef4_test_eventq_irq()
206 read_ptr[channel->channel]) { in ef4_test_eventq_irq()
207 set_bit(channel->channel, &napi_ran); in ef4_test_eventq_irq()
208 clear_bit(channel->channel, &dma_pend); in ef4_test_eventq_irq()
209 clear_bit(channel->channel, &int_pend); in ef4_test_eventq_irq()
212 clear_bit(channel->channel, &dma_pend); in ef4_test_eventq_irq()
214 clear_bit(channel->channel, &int_pend); in ef4_test_eventq_irq()
223 bool dma_seen = !test_bit(channel->channel, &dma_pend); in ef4_test_eventq_irq()
224 bool int_seen = !test_bit(channel->channel, &int_pend); in ef4_test_eventq_irq()
226 tests->eventq_dma[channel->channel] = dma_seen ? 1 : -1; in ef4_test_eventq_irq()
227 tests->eventq_int[channel->channel] = int_seen ? 1 : -1; in ef4_test_eventq_irq()
230 netif_dbg(efx, drv, efx->net_dev, in ef4_test_eventq_irq()
232 channel->channel, in ef4_test_eventq_irq()
233 test_bit(channel->channel, &napi_ran) ? in ef4_test_eventq_irq()
239 netif_err(efx, drv, efx->net_dev, in ef4_test_eventq_irq()
241 channel->channel); in ef4_test_eventq_irq()
243 netif_err(efx, drv, efx->net_dev, in ef4_test_eventq_irq()
245 "during event queue test\n", in ef4_test_eventq_irq()
246 channel->channel); in ef4_test_eventq_irq()
248 netif_err(efx, drv, efx->net_dev, in ef4_test_eventq_irq()
251 channel->channel); in ef4_test_eventq_irq()
255 return (dma_pend || int_pend) ? -ETIMEDOUT : 0; in ef4_test_eventq_irq()
263 if (!efx->phy_op->run_tests) in ef4_test_phy()
266 mutex_lock(&efx->mac_lock); in ef4_test_phy()
267 rc = efx->phy_op->run_tests(efx, tests->phy_ext, flags); in ef4_test_phy()
268 mutex_unlock(&efx->mac_lock); in ef4_test_phy()
269 if (rc == -EPERM) in ef4_test_phy()
272 netif_info(efx, drv, efx->net_dev, in ef4_test_phy()
280 * Loopback testing
281 * NB Only one loopback test can be executing concurrently.
285 /* Loopback test RX callback
286 * This is called for each received packet during loopback testing.
291 struct ef4_loopback_state *state = efx->loopback_selftest; in ef4_loopback_rx_packet()
298 if ((state == NULL) || state->flush) in ef4_loopback_rx_packet()
301 payload = &state->payload; in ef4_loopback_rx_packet()
305 received.ip.saddr = payload->ip.saddr; in ef4_loopback_rx_packet()
306 if (state->offload_csum) in ef4_loopback_rx_packet()
307 received.ip.check = payload->ip.check; in ef4_loopback_rx_packet()
311 netif_err(efx, drv, efx->net_dev, in ef4_loopback_rx_packet()
312 "saw runt RX packet (length %d) in %s loopback " in ef4_loopback_rx_packet()
313 "test\n", pkt_len, LOOPBACK_MODE(efx)); in ef4_loopback_rx_packet()
318 if (memcmp(&received.header, &payload->header, ETH_HLEN) != 0) { in ef4_loopback_rx_packet()
319 netif_err(efx, drv, efx->net_dev, in ef4_loopback_rx_packet()
320 "saw non-loopback RX packet in %s loopback test\n", in ef4_loopback_rx_packet()
327 netif_err(efx, drv, efx->net_dev, in ef4_loopback_rx_packet()
329 "%s loopback test\n", pkt_len, in ef4_loopback_rx_packet()
335 if (memcmp(&received.ip, &payload->ip, sizeof(payload->ip)) != 0) { in ef4_loopback_rx_packet()
336 netif_err(efx, drv, efx->net_dev, in ef4_loopback_rx_packet()
337 "saw corrupted IP header in %s loopback test\n", in ef4_loopback_rx_packet()
343 if (memcmp(&received.msg, &payload->msg, sizeof(received.msg)) != 0) { in ef4_loopback_rx_packet()
344 netif_err(efx, drv, efx->net_dev, in ef4_loopback_rx_packet()
345 "saw corrupted RX packet in %s loopback test\n", in ef4_loopback_rx_packet()
351 if (received.iteration != payload->iteration) { in ef4_loopback_rx_packet()
352 netif_err(efx, drv, efx->net_dev, in ef4_loopback_rx_packet()
354 "%s loopback test\n", ntohs(received.iteration), in ef4_loopback_rx_packet()
355 ntohs(payload->iteration), LOOPBACK_MODE(efx)); in ef4_loopback_rx_packet()
360 netif_vdbg(efx, drv, efx->net_dev, in ef4_loopback_rx_packet()
361 "got loopback RX in %s loopback test\n", LOOPBACK_MODE(efx)); in ef4_loopback_rx_packet()
363 atomic_inc(&state->rx_good); in ef4_loopback_rx_packet()
368 if (atomic_read(&state->rx_bad) == 0) { in ef4_loopback_rx_packet()
369 netif_err(efx, drv, efx->net_dev, "received packet:\n"); in ef4_loopback_rx_packet()
372 netif_err(efx, drv, efx->net_dev, "expected packet:\n"); in ef4_loopback_rx_packet()
374 &state->payload.packet, EF4_LOOPBACK_PAYLOAD_LEN, in ef4_loopback_rx_packet()
378 atomic_inc(&state->rx_bad); in ef4_loopback_rx_packet()
384 struct ef4_loopback_state *state = efx->loopback_selftest; in ef4_iterate_state()
385 struct net_device *net_dev = efx->net_dev; in ef4_iterate_state()
386 struct ef4_loopback_payload *payload = &state->payload; in ef4_iterate_state()
389 ether_addr_copy((u8 *)&payload->header.h_dest, net_dev->dev_addr); in ef4_iterate_state()
390 ether_addr_copy((u8 *)&payload->header.h_source, payload_source); in ef4_iterate_state()
391 payload->header.h_proto = htons(ETH_P_IP); in ef4_iterate_state()
394 payload->ip.daddr = htonl(INADDR_LOOPBACK); in ef4_iterate_state()
395 payload->ip.ihl = 5; in ef4_iterate_state()
396 payload->ip.check = (__force __sum16) htons(0xdead); in ef4_iterate_state()
397 payload->ip.tot_len = htons(sizeof(*payload) - in ef4_iterate_state()
399 payload->ip.version = IPVERSION; in ef4_iterate_state()
400 payload->ip.protocol = IPPROTO_UDP; in ef4_iterate_state()
403 payload->udp.source = 0; in ef4_iterate_state()
404 payload->udp.len = htons(sizeof(*payload) - in ef4_iterate_state()
406 payload->udp.check = 0; /* checksum ignored */ in ef4_iterate_state()
409 payload->iteration = htons(ntohs(payload->iteration) + 1); in ef4_iterate_state()
410 memcpy(&payload->msg, payload_msg, sizeof(payload_msg)); in ef4_iterate_state()
413 atomic_set(&state->rx_good, 0); in ef4_iterate_state()
414 atomic_set(&state->rx_bad, 0); in ef4_iterate_state()
420 struct ef4_nic *efx = tx_queue->efx; in ef4_begin_loopback()
421 struct ef4_loopback_state *state = efx->loopback_selftest; in ef4_begin_loopback()
428 for (i = 0; i < state->packet_count; i++) { in ef4_begin_loopback()
431 skb = alloc_skb(sizeof(state->payload), GFP_KERNEL); in ef4_begin_loopback()
433 return -ENOMEM; in ef4_begin_loopback()
434 state->skbs[i] = skb; in ef4_begin_loopback()
439 payload = skb_put(skb, sizeof(state->payload)); in ef4_begin_loopback()
440 memcpy(payload, &state->payload, sizeof(state->payload)); in ef4_begin_loopback()
441 payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); in ef4_begin_loopback()
451 netif_tx_lock_bh(efx->net_dev); in ef4_begin_loopback()
453 netif_tx_unlock_bh(efx->net_dev); in ef4_begin_loopback()
456 netif_err(efx, drv, efx->net_dev, in ef4_begin_loopback()
458 "%d in %s loopback test\n", tx_queue->queue, in ef4_begin_loopback()
459 i + 1, state->packet_count, in ef4_begin_loopback()
464 return -EPIPE; in ef4_begin_loopback()
473 struct ef4_loopback_state *state = efx->loopback_selftest; in ef4_poll_loopback()
475 return atomic_read(&state->rx_good) == state->packet_count; in ef4_poll_loopback()
481 struct ef4_nic *efx = tx_queue->efx; in ef4_end_loopback()
482 struct ef4_loopback_state *state = efx->loopback_selftest; in ef4_end_loopback()
487 netif_tx_lock_bh(efx->net_dev); in ef4_end_loopback()
491 for (i = 0; i < state->packet_count; i++) { in ef4_end_loopback()
492 skb = state->skbs[i]; in ef4_end_loopback()
498 netif_tx_unlock_bh(efx->net_dev); in ef4_end_loopback()
501 rx_good = atomic_read(&state->rx_good); in ef4_end_loopback()
502 rx_bad = atomic_read(&state->rx_bad); in ef4_end_loopback()
503 if (tx_done != state->packet_count) { in ef4_end_loopback()
507 netif_err(efx, drv, efx->net_dev, in ef4_end_loopback()
509 "TX completion events in %s loopback test\n", in ef4_end_loopback()
510 tx_queue->queue, tx_done, state->packet_count, in ef4_end_loopback()
512 rc = -ETIMEDOUT; in ef4_end_loopback()
517 if (rx_good != state->packet_count) { in ef4_end_loopback()
518 netif_dbg(efx, drv, efx->net_dev, in ef4_end_loopback()
520 "received packets in %s loopback test\n", in ef4_end_loopback()
521 tx_queue->queue, rx_good, state->packet_count, in ef4_end_loopback()
523 rc = -ETIMEDOUT; in ef4_end_loopback()
527 /* Update loopback test structure */ in ef4_end_loopback()
528 lb_tests->tx_sent[tx_queue->queue] += state->packet_count; in ef4_end_loopback()
529 lb_tests->tx_done[tx_queue->queue] += tx_done; in ef4_end_loopback()
530 lb_tests->rx_good += rx_good; in ef4_end_loopback()
531 lb_tests->rx_bad += rx_bad; in ef4_end_loopback()
540 struct ef4_nic *efx = tx_queue->efx; in ef4_test_loopback()
541 struct ef4_loopback_state *state = efx->loopback_selftest; in ef4_test_loopback()
546 state->packet_count = efx->txq_entries / 3; in ef4_test_loopback()
547 state->packet_count = min(1 << (i << 2), state->packet_count); in ef4_test_loopback()
548 state->skbs = kcalloc(state->packet_count, in ef4_test_loopback()
549 sizeof(state->skbs[0]), GFP_KERNEL); in ef4_test_loopback()
550 if (!state->skbs) in ef4_test_loopback()
551 return -ENOMEM; in ef4_test_loopback()
552 state->flush = false; in ef4_test_loopback()
554 netif_dbg(efx, drv, efx->net_dev, in ef4_test_loopback()
555 "TX queue %d testing %s loopback with %d packets\n", in ef4_test_loopback()
556 tx_queue->queue, LOOPBACK_MODE(efx), in ef4_test_loopback()
557 state->packet_count); in ef4_test_loopback()
571 kfree(state->skbs); in ef4_test_loopback()
574 /* Wait a while to ensure there are no packets in ef4_test_loopback()
581 netif_dbg(efx, drv, efx->net_dev, in ef4_test_loopback()
582 "TX queue %d passed %s loopback test with a burst length " in ef4_test_loopback()
583 "of %d packets\n", tx_queue->queue, LOOPBACK_MODE(efx), in ef4_test_loopback()
584 state->packet_count); in ef4_test_loopback()
595 struct ef4_link_state *link_state = &efx->link_state; in ef4_wait_for_link()
602 if (efx->type->monitor != NULL) { in ef4_wait_for_link()
603 mutex_lock(&efx->mac_lock); in ef4_wait_for_link()
604 efx->type->monitor(efx); in ef4_wait_for_link()
605 mutex_unlock(&efx->mac_lock); in ef4_wait_for_link()
608 mutex_lock(&efx->mac_lock); in ef4_wait_for_link()
609 link_up = link_state->up; in ef4_wait_for_link()
611 link_up = !efx->type->check_mac_fault(efx); in ef4_wait_for_link()
612 mutex_unlock(&efx->mac_lock); in ef4_wait_for_link()
622 return -ETIMEDOUT; in ef4_wait_for_link()
631 ef4_get_channel(efx, efx->tx_channel_offset); in ef4_test_loopbacks()
640 return -ENOMEM; in ef4_test_loopbacks()
641 BUG_ON(efx->loopback_selftest); in ef4_test_loopbacks()
642 state->flush = true; in ef4_test_loopbacks()
643 efx->loopback_selftest = state; in ef4_test_loopbacks()
645 /* Test all supported loopback modes */ in ef4_test_loopbacks()
650 /* Move the port into the specified loopback mode. */ in ef4_test_loopbacks()
651 state->flush = true; in ef4_test_loopbacks()
652 mutex_lock(&efx->mac_lock); in ef4_test_loopbacks()
653 efx->loopback_mode = mode; in ef4_test_loopbacks()
655 mutex_unlock(&efx->mac_lock); in ef4_test_loopbacks()
657 netif_err(efx, drv, efx->net_dev, in ef4_test_loopbacks()
658 "unable to move into %s loopback\n", in ef4_test_loopbacks()
665 netif_err(efx, drv, efx->net_dev, in ef4_test_loopbacks()
666 "loopback %s never came up\n", in ef4_test_loopbacks()
671 /* Test all enabled types of TX queue */ in ef4_test_loopbacks()
673 state->offload_csum = (tx_queue->queue & in ef4_test_loopbacks()
676 &tests->loopback[mode]); in ef4_test_loopbacks()
683 /* Remove the flush. The caller will remove the loopback setting */ in ef4_test_loopbacks()
684 state->flush = true; in ef4_test_loopbacks()
685 efx->loopback_selftest = NULL; in ef4_test_loopbacks()
689 if (rc == -EPERM) in ef4_test_loopbacks()
704 enum ef4_loopback_mode loopback_mode = efx->loopback_mode; in ef4_selftest()
705 int phy_mode = efx->phy_mode; in ef4_selftest()
710 /* Online (i.e. non-disruptive) testing in ef4_selftest()
736 * This checks MAC and PHY loopback on the specified port. */ in ef4_selftest()
739 * loopback test and the watchdog timeout doesn't fire. in ef4_selftest()
743 if (efx->type->test_chip) { in ef4_selftest()
744 rc_reset = efx->type->test_chip(efx, tests); in ef4_selftest()
746 netif_err(efx, hw, efx->net_dev, in ef4_selftest()
747 "Unable to recover from chip test\n"); in ef4_selftest()
752 if ((tests->memory < 0 || tests->registers < 0) && !rc_test) in ef4_selftest()
753 rc_test = -EIO; in ef4_selftest()
756 /* Ensure that the phy is powered and out of loopback in ef4_selftest()
757 * for the bist and loopback tests */ in ef4_selftest()
758 mutex_lock(&efx->mac_lock); in ef4_selftest()
759 efx->phy_mode &= ~PHY_MODE_LOW_POWER; in ef4_selftest()
760 efx->loopback_mode = LOOPBACK_NONE; in ef4_selftest()
762 mutex_unlock(&efx->mac_lock); in ef4_selftest()
768 rc = ef4_test_loopbacks(efx, tests, efx->loopback_modes); in ef4_selftest()
773 mutex_lock(&efx->mac_lock); in ef4_selftest()
774 efx->phy_mode = phy_mode; in ef4_selftest()
775 efx->loopback_mode = loopback_mode; in ef4_selftest()
777 mutex_unlock(&efx->mac_lock); in ef4_selftest()
779 netif_device_attach(efx->net_dev); in ef4_selftest()
790 schedule_delayed_work(&efx->selftest_work, IRQ_TIMEOUT); in ef4_selftest_async_start()
795 cancel_delayed_work_sync(&efx->selftest_work); in ef4_selftest_async_cancel()
808 netif_err(efx, ifup, efx->net_dev, in ef4_selftest_async_work()
810 channel->channel); in ef4_selftest_async_work()
812 netif_dbg(efx, ifup, efx->net_dev, in ef4_selftest_async_work()
814 channel->channel, cpu); in ef4_selftest_async_work()