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.
29 * - All IRQs may be disabled on a CPU for a *long* time by e.g. a
31 * - The PREEMPT_RT patches mostly deal with this, but also allow a
39 * Loopback test packet structure
41 * The self-test should stress every RSS vector, and unfortunately
45 char pad[2]; /* Ensures ip is 4-byte aligned */
57 /* Loopback test source MAC address */
63 "Hello world! This is an Efx loopback test in progress!";
68 [EFX_INT_MODE_MSIX] = "MSI-X",
73 STRING_TABLE_LOOKUP(efx->interrupt_mode, efx_siena_interrupt_mode)
76 * struct efx_loopback_state - persistent state during a loopback selftest
78 * @packet_count: Number of packets being used in this test
109 tests->phy_alive = rc ? -1 : 1; in efx_test_phy_alive()
118 if (efx->type->test_nvram) { in efx_test_nvram()
119 rc = efx->type->test_nvram(efx); in efx_test_nvram()
120 if (rc == -EPERM) in efx_test_nvram()
123 tests->nvram = rc ? -1 : 1; in efx_test_nvram()
135 /* Test generation and receipt of interrupts */
143 netif_dbg(efx, drv, efx->net_dev, "testing interrupts\n"); in efx_test_interrupts()
144 tests->interrupt = -1; in efx_test_interrupts()
147 if (rc == -ENOTSUPP) { in efx_test_interrupts()
148 netif_dbg(efx, drv, efx->net_dev, in efx_test_interrupts()
150 tests->interrupt = 0; in efx_test_interrupts()
157 /* Wait for arrival of test interrupt. */ in efx_test_interrupts()
158 netif_dbg(efx, drv, efx->net_dev, "waiting for test interrupt\n"); in efx_test_interrupts()
167 netif_err(efx, drv, efx->net_dev, "timed out waiting for interrupt\n"); in efx_test_interrupts()
168 return -ETIMEDOUT; in efx_test_interrupts()
171 netif_dbg(efx, drv, efx->net_dev, "%s test interrupt seen on CPU%d\n", in efx_test_interrupts()
173 tests->interrupt = 1; in efx_test_interrupts()
177 /* Test generation and receipt of interrupting events */
189 read_ptr[channel->channel] = channel->eventq_read_ptr; in efx_test_eventq_irq()
190 set_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
191 set_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
206 if (channel->eventq_read_ptr != in efx_test_eventq_irq()
207 read_ptr[channel->channel]) { in efx_test_eventq_irq()
208 set_bit(channel->channel, &napi_ran); in efx_test_eventq_irq()
209 clear_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
210 clear_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
213 clear_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
215 clear_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
224 bool dma_seen = !test_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
225 bool int_seen = !test_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
227 tests->eventq_dma[channel->channel] = dma_seen ? 1 : -1; in efx_test_eventq_irq()
228 tests->eventq_int[channel->channel] = int_seen ? 1 : -1; in efx_test_eventq_irq()
231 netif_dbg(efx, drv, efx->net_dev, in efx_test_eventq_irq()
233 channel->channel, in efx_test_eventq_irq()
234 test_bit(channel->channel, &napi_ran) ? in efx_test_eventq_irq()
240 netif_err(efx, drv, efx->net_dev, in efx_test_eventq_irq()
242 channel->channel); in efx_test_eventq_irq()
244 netif_err(efx, drv, efx->net_dev, in efx_test_eventq_irq()
246 "during event queue test\n", in efx_test_eventq_irq()
247 channel->channel); in efx_test_eventq_irq()
249 netif_err(efx, drv, efx->net_dev, in efx_test_eventq_irq()
252 channel->channel); in efx_test_eventq_irq()
256 return (dma_pend || int_pend) ? -ETIMEDOUT : 0; in efx_test_eventq_irq()
264 mutex_lock(&efx->mac_lock); in efx_test_phy()
265 rc = efx_siena_mcdi_phy_run_tests(efx, tests->phy_ext, flags); in efx_test_phy()
266 mutex_unlock(&efx->mac_lock); in efx_test_phy()
267 if (rc == -EPERM) in efx_test_phy()
270 netif_info(efx, drv, efx->net_dev, in efx_test_phy()
278 * Loopback testing
279 * NB Only one loopback test can be executing concurrently.
283 /* Loopback test RX callback
284 * This is called for each received packet during loopback testing.
289 struct efx_loopback_state *state = efx->loopback_selftest; in efx_siena_loopback_rx_packet()
296 if ((state == NULL) || state->flush) in efx_siena_loopback_rx_packet()
299 payload = &state->payload; in efx_siena_loopback_rx_packet()
303 received.ip.saddr = payload->ip.saddr; in efx_siena_loopback_rx_packet()
304 if (state->offload_csum) in efx_siena_loopback_rx_packet()
305 received.ip.check = payload->ip.check; in efx_siena_loopback_rx_packet()
309 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
310 "saw runt RX packet (length %d) in %s loopback " in efx_siena_loopback_rx_packet()
311 "test\n", pkt_len, LOOPBACK_MODE(efx)); in efx_siena_loopback_rx_packet()
316 if (memcmp(&received.header, &payload->header, ETH_HLEN) != 0) { in efx_siena_loopback_rx_packet()
317 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
318 "saw non-loopback RX packet in %s loopback test\n", in efx_siena_loopback_rx_packet()
325 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
327 "%s loopback test\n", pkt_len, in efx_siena_loopback_rx_packet()
333 if (memcmp(&received.ip, &payload->ip, sizeof(payload->ip)) != 0) { in efx_siena_loopback_rx_packet()
334 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
335 "saw corrupted IP header in %s loopback test\n", in efx_siena_loopback_rx_packet()
341 if (memcmp(&received.msg, &payload->msg, sizeof(received.msg)) != 0) { in efx_siena_loopback_rx_packet()
342 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
343 "saw corrupted RX packet in %s loopback test\n", in efx_siena_loopback_rx_packet()
349 if (received.iteration != payload->iteration) { in efx_siena_loopback_rx_packet()
350 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
352 "%s loopback test\n", ntohs(received.iteration), in efx_siena_loopback_rx_packet()
353 ntohs(payload->iteration), LOOPBACK_MODE(efx)); in efx_siena_loopback_rx_packet()
358 netif_vdbg(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
359 "got loopback RX in %s loopback test\n", LOOPBACK_MODE(efx)); in efx_siena_loopback_rx_packet()
361 atomic_inc(&state->rx_good); in efx_siena_loopback_rx_packet()
366 if (atomic_read(&state->rx_bad) == 0) { in efx_siena_loopback_rx_packet()
367 netif_err(efx, drv, efx->net_dev, "received packet:\n"); in efx_siena_loopback_rx_packet()
370 netif_err(efx, drv, efx->net_dev, "expected packet:\n"); in efx_siena_loopback_rx_packet()
372 &state->payload.packet, EFX_LOOPBACK_PAYLOAD_LEN, in efx_siena_loopback_rx_packet()
376 atomic_inc(&state->rx_bad); in efx_siena_loopback_rx_packet()
382 struct efx_loopback_state *state = efx->loopback_selftest; in efx_iterate_state()
383 struct net_device *net_dev = efx->net_dev; in efx_iterate_state()
384 struct efx_loopback_payload *payload = &state->payload; in efx_iterate_state()
387 ether_addr_copy((u8 *)&payload->header.h_dest, net_dev->dev_addr); in efx_iterate_state()
388 ether_addr_copy((u8 *)&payload->header.h_source, payload_source); in efx_iterate_state()
389 payload->header.h_proto = htons(ETH_P_IP); in efx_iterate_state()
392 payload->ip.daddr = htonl(INADDR_LOOPBACK); in efx_iterate_state()
393 payload->ip.ihl = 5; in efx_iterate_state()
394 payload->ip.check = (__force __sum16) htons(0xdead); in efx_iterate_state()
395 payload->ip.tot_len = htons(sizeof(*payload) - in efx_iterate_state()
397 payload->ip.version = IPVERSION; in efx_iterate_state()
398 payload->ip.protocol = IPPROTO_UDP; in efx_iterate_state()
401 payload->udp.source = 0; in efx_iterate_state()
402 payload->udp.len = htons(sizeof(*payload) - in efx_iterate_state()
404 payload->udp.check = 0; /* checksum ignored */ in efx_iterate_state()
407 payload->iteration = htons(ntohs(payload->iteration) + 1); in efx_iterate_state()
408 memcpy(&payload->msg, payload_msg, sizeof(payload_msg)); in efx_iterate_state()
411 atomic_set(&state->rx_good, 0); in efx_iterate_state()
412 atomic_set(&state->rx_bad, 0); in efx_iterate_state()
418 struct efx_nic *efx = tx_queue->efx; in efx_begin_loopback()
419 struct efx_loopback_state *state = efx->loopback_selftest; in efx_begin_loopback()
426 for (i = 0; i < state->packet_count; i++) { in efx_begin_loopback()
429 skb = alloc_skb(sizeof(state->payload), GFP_KERNEL); in efx_begin_loopback()
431 return -ENOMEM; in efx_begin_loopback()
432 state->skbs[i] = skb; in efx_begin_loopback()
437 payload = skb_put(skb, sizeof(state->payload)); in efx_begin_loopback()
438 memcpy(payload, &state->payload, sizeof(state->payload)); in efx_begin_loopback()
439 payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); in efx_begin_loopback()
449 netif_tx_lock_bh(efx->net_dev); in efx_begin_loopback()
451 netif_tx_unlock_bh(efx->net_dev); in efx_begin_loopback()
454 netif_err(efx, drv, efx->net_dev, in efx_begin_loopback()
456 "%d in %s loopback test\n", tx_queue->label, in efx_begin_loopback()
457 i + 1, state->packet_count, in efx_begin_loopback()
462 return -EPIPE; in efx_begin_loopback()
471 struct efx_loopback_state *state = efx->loopback_selftest; in efx_poll_loopback()
473 return atomic_read(&state->rx_good) == state->packet_count; in efx_poll_loopback()
479 struct efx_nic *efx = tx_queue->efx; in efx_end_loopback()
480 struct efx_loopback_state *state = efx->loopback_selftest; in efx_end_loopback()
485 netif_tx_lock_bh(efx->net_dev); in efx_end_loopback()
489 for (i = 0; i < state->packet_count; i++) { in efx_end_loopback()
490 skb = state->skbs[i]; in efx_end_loopback()
496 netif_tx_unlock_bh(efx->net_dev); in efx_end_loopback()
499 rx_good = atomic_read(&state->rx_good); in efx_end_loopback()
500 rx_bad = atomic_read(&state->rx_bad); in efx_end_loopback()
501 if (tx_done != state->packet_count) { in efx_end_loopback()
505 netif_err(efx, drv, efx->net_dev, in efx_end_loopback()
507 "TX completion events in %s loopback test\n", in efx_end_loopback()
508 tx_queue->label, tx_done, state->packet_count, in efx_end_loopback()
510 rc = -ETIMEDOUT; in efx_end_loopback()
515 if (rx_good != state->packet_count) { in efx_end_loopback()
516 netif_dbg(efx, drv, efx->net_dev, in efx_end_loopback()
518 "received packets in %s loopback test\n", in efx_end_loopback()
519 tx_queue->label, rx_good, state->packet_count, in efx_end_loopback()
521 rc = -ETIMEDOUT; in efx_end_loopback()
525 /* Update loopback test structure */ in efx_end_loopback()
526 lb_tests->tx_sent[tx_queue->label] += state->packet_count; in efx_end_loopback()
527 lb_tests->tx_done[tx_queue->label] += tx_done; in efx_end_loopback()
528 lb_tests->rx_good += rx_good; in efx_end_loopback()
529 lb_tests->rx_bad += rx_bad; in efx_end_loopback()
538 struct efx_nic *efx = tx_queue->efx; in efx_test_loopback()
539 struct efx_loopback_state *state = efx->loopback_selftest; in efx_test_loopback()
544 state->packet_count = efx->txq_entries / 3; in efx_test_loopback()
545 state->packet_count = min(1 << (i << 2), state->packet_count); in efx_test_loopback()
546 state->skbs = kcalloc(state->packet_count, in efx_test_loopback()
547 sizeof(state->skbs[0]), GFP_KERNEL); in efx_test_loopback()
548 if (!state->skbs) in efx_test_loopback()
549 return -ENOMEM; in efx_test_loopback()
550 state->flush = false; in efx_test_loopback()
552 netif_dbg(efx, drv, efx->net_dev, in efx_test_loopback()
553 "TX queue %d (hw %d) testing %s loopback with %d packets\n", in efx_test_loopback()
554 tx_queue->label, tx_queue->queue, LOOPBACK_MODE(efx), in efx_test_loopback()
555 state->packet_count); in efx_test_loopback()
569 kfree(state->skbs); in efx_test_loopback()
572 /* Wait a while to ensure there are no packets in efx_test_loopback()
579 netif_dbg(efx, drv, efx->net_dev, in efx_test_loopback()
580 "TX queue %d passed %s loopback test with a burst length " in efx_test_loopback()
581 "of %d packets\n", tx_queue->label, LOOPBACK_MODE(efx), in efx_test_loopback()
582 state->packet_count); in efx_test_loopback()
593 struct efx_link_state *link_state = &efx->link_state; in efx_wait_for_link()
600 if (efx->type->monitor != NULL) { in efx_wait_for_link()
601 mutex_lock(&efx->mac_lock); in efx_wait_for_link()
602 efx->type->monitor(efx); in efx_wait_for_link()
603 mutex_unlock(&efx->mac_lock); in efx_wait_for_link()
606 mutex_lock(&efx->mac_lock); in efx_wait_for_link()
607 link_up = link_state->up; in efx_wait_for_link()
609 link_up = !efx->type->check_mac_fault(efx); in efx_wait_for_link()
610 mutex_unlock(&efx->mac_lock); in efx_wait_for_link()
620 return -ETIMEDOUT; in efx_wait_for_link()
629 efx_get_channel(efx, efx->tx_channel_offset); in efx_test_loopbacks()
638 return -ENOMEM; in efx_test_loopbacks()
639 BUG_ON(efx->loopback_selftest); in efx_test_loopbacks()
640 state->flush = true; in efx_test_loopbacks()
641 efx->loopback_selftest = state; in efx_test_loopbacks()
643 /* Test all supported loopback modes */ in efx_test_loopbacks()
648 /* Move the port into the specified loopback mode. */ in efx_test_loopbacks()
649 state->flush = true; in efx_test_loopbacks()
650 mutex_lock(&efx->mac_lock); in efx_test_loopbacks()
651 efx->loopback_mode = mode; in efx_test_loopbacks()
653 mutex_unlock(&efx->mac_lock); in efx_test_loopbacks()
655 netif_err(efx, drv, efx->net_dev, in efx_test_loopbacks()
656 "unable to move into %s loopback\n", in efx_test_loopbacks()
663 netif_err(efx, drv, efx->net_dev, in efx_test_loopbacks()
664 "loopback %s never came up\n", in efx_test_loopbacks()
669 /* Test all enabled types of TX queue */ in efx_test_loopbacks()
671 state->offload_csum = (tx_queue->type & in efx_test_loopbacks()
674 &tests->loopback[mode]); in efx_test_loopbacks()
681 /* Remove the flush. The caller will remove the loopback setting */ in efx_test_loopbacks()
682 state->flush = true; in efx_test_loopbacks()
683 efx->loopback_selftest = NULL; in efx_test_loopbacks()
687 if (rc == -EPERM) in efx_test_loopbacks()
702 enum efx_loopback_mode loopback_mode = efx->loopback_mode; in efx_siena_selftest()
703 int phy_mode = efx->phy_mode; in efx_siena_selftest()
708 /* Online (i.e. non-disruptive) testing in efx_siena_selftest()
734 * This checks MAC and PHY loopback on the specified port. */ in efx_siena_selftest()
737 * loopback test and the watchdog timeout doesn't fire. in efx_siena_selftest()
741 if (efx->type->test_chip) { in efx_siena_selftest()
742 rc_reset = efx->type->test_chip(efx, tests); in efx_siena_selftest()
744 netif_err(efx, hw, efx->net_dev, in efx_siena_selftest()
745 "Unable to recover from chip test\n"); in efx_siena_selftest()
750 if ((tests->memory < 0 || tests->registers < 0) && !rc_test) in efx_siena_selftest()
751 rc_test = -EIO; in efx_siena_selftest()
754 /* Ensure that the phy is powered and out of loopback in efx_siena_selftest()
755 * for the bist and loopback tests */ in efx_siena_selftest()
756 mutex_lock(&efx->mac_lock); in efx_siena_selftest()
757 efx->phy_mode &= ~PHY_MODE_LOW_POWER; in efx_siena_selftest()
758 efx->loopback_mode = LOOPBACK_NONE; in efx_siena_selftest()
760 mutex_unlock(&efx->mac_lock); in efx_siena_selftest()
766 rc = efx_test_loopbacks(efx, tests, efx->loopback_modes); in efx_siena_selftest()
771 mutex_lock(&efx->mac_lock); in efx_siena_selftest()
772 efx->phy_mode = phy_mode; in efx_siena_selftest()
773 efx->loopback_mode = loopback_mode; in efx_siena_selftest()
775 mutex_unlock(&efx->mac_lock); in efx_siena_selftest()
788 schedule_delayed_work(&efx->selftest_work, IRQ_TIMEOUT); in efx_siena_selftest_async_start()
793 cancel_delayed_work_sync(&efx->selftest_work); in efx_siena_selftest_async_cancel()
806 netif_err(efx, ifup, efx->net_dev, in efx_siena_selftest_async_work()
808 channel->channel); in efx_siena_selftest_async_work()
810 netif_dbg(efx, ifup, efx->net_dev, in efx_siena_selftest_async_work()
812 channel->channel, cpu); in efx_siena_selftest_async_work()
818 INIT_DELAYED_WORK(&efx->selftest_work, efx_siena_selftest_async_work); in efx_siena_selftest_async_init()