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.
44 char pad[2]; /* Ensures ip is 4-byte aligned */
56 /* Loopback test source MAC address */
62 "Hello world! This is an Efx loopback test in progress!";
67 [EFX_INT_MODE_MSIX] = "MSI-X",
72 STRING_TABLE_LOOKUP(efx->interrupt_mode, efx_interrupt_mode)
75 * struct efx_loopback_state - persistent state during a loopback selftest
77 * @packet_count: Number of packets being used in this test
108 tests->phy_alive = rc ? -1 : 1; in efx_test_phy_alive()
117 if (efx->type->test_nvram) { in efx_test_nvram()
118 rc = efx->type->test_nvram(efx); in efx_test_nvram()
119 if (rc == -EPERM) in efx_test_nvram()
122 tests->nvram = rc ? -1 : 1; in efx_test_nvram()
134 /* Test generation and receipt of interrupts */
142 netif_dbg(efx, drv, efx->net_dev, "testing interrupts\n"); in efx_test_interrupts()
143 tests->interrupt = -1; in efx_test_interrupts()
146 if (rc == -ENOTSUPP) { in efx_test_interrupts()
147 netif_dbg(efx, drv, efx->net_dev, in efx_test_interrupts()
149 tests->interrupt = 0; in efx_test_interrupts()
156 /* Wait for arrival of test interrupt. */ in efx_test_interrupts()
157 netif_dbg(efx, drv, efx->net_dev, "waiting for test interrupt\n"); in efx_test_interrupts()
166 netif_err(efx, drv, efx->net_dev, "timed out waiting for interrupt\n"); in efx_test_interrupts()
167 return -ETIMEDOUT; in efx_test_interrupts()
170 netif_dbg(efx, drv, efx->net_dev, "%s test interrupt seen on CPU%d\n", in efx_test_interrupts()
172 tests->interrupt = 1; in efx_test_interrupts()
176 /* Test generation and receipt of interrupting events */
188 read_ptr[channel->channel] = channel->eventq_read_ptr; in efx_test_eventq_irq()
189 set_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
190 set_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
205 if (channel->eventq_read_ptr != in efx_test_eventq_irq()
206 read_ptr[channel->channel]) { in efx_test_eventq_irq()
207 set_bit(channel->channel, &napi_ran); in efx_test_eventq_irq()
208 clear_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
209 clear_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
212 clear_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
214 clear_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
223 bool dma_seen = !test_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
224 bool int_seen = !test_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
226 tests->eventq_dma[channel->channel] = dma_seen ? 1 : -1; in efx_test_eventq_irq()
227 tests->eventq_int[channel->channel] = int_seen ? 1 : -1; in efx_test_eventq_irq()
230 netif_dbg(efx, drv, efx->net_dev, in efx_test_eventq_irq()
232 channel->channel, in efx_test_eventq_irq()
233 test_bit(channel->channel, &napi_ran) ? in efx_test_eventq_irq()
239 netif_err(efx, drv, efx->net_dev, in efx_test_eventq_irq()
241 channel->channel); in efx_test_eventq_irq()
243 netif_err(efx, drv, efx->net_dev, in efx_test_eventq_irq()
245 "during event queue test\n", in efx_test_eventq_irq()
246 channel->channel); in efx_test_eventq_irq()
248 netif_err(efx, drv, efx->net_dev, in efx_test_eventq_irq()
251 channel->channel); in efx_test_eventq_irq()
255 return (dma_pend || int_pend) ? -ETIMEDOUT : 0; in efx_test_eventq_irq()
263 mutex_lock(&efx->mac_lock); in efx_test_phy()
264 rc = efx_mcdi_phy_run_tests(efx, tests->phy_ext, flags); in efx_test_phy()
265 mutex_unlock(&efx->mac_lock); in efx_test_phy()
266 if (rc == -EPERM) in efx_test_phy()
269 netif_info(efx, drv, efx->net_dev, in efx_test_phy()
277 * Loopback testing
278 * NB Only one loopback test can be executing concurrently.
282 /* Loopback test RX callback
283 * This is called for each received packet during loopback testing.
288 struct efx_loopback_state *state = efx->loopback_selftest; in efx_loopback_rx_packet()
295 if ((state == NULL) || state->flush) in efx_loopback_rx_packet()
298 payload = &state->payload; in efx_loopback_rx_packet()
302 received.ip.saddr = payload->ip.saddr; in efx_loopback_rx_packet()
303 if (state->offload_csum) in efx_loopback_rx_packet()
304 received.ip.check = payload->ip.check; in efx_loopback_rx_packet()
308 netif_err(efx, drv, efx->net_dev, in efx_loopback_rx_packet()
309 "saw runt RX packet (length %d) in %s loopback " in efx_loopback_rx_packet()
310 "test\n", pkt_len, LOOPBACK_MODE(efx)); in efx_loopback_rx_packet()
315 if (memcmp(&received.header, &payload->header, ETH_HLEN) != 0) { in efx_loopback_rx_packet()
316 netif_err(efx, drv, efx->net_dev, in efx_loopback_rx_packet()
317 "saw non-loopback RX packet in %s loopback test\n", in efx_loopback_rx_packet()
324 netif_err(efx, drv, efx->net_dev, in efx_loopback_rx_packet()
326 "%s loopback test\n", pkt_len, in efx_loopback_rx_packet()
332 if (memcmp(&received.ip, &payload->ip, sizeof(payload->ip)) != 0) { in efx_loopback_rx_packet()
333 netif_err(efx, drv, efx->net_dev, in efx_loopback_rx_packet()
334 "saw corrupted IP header in %s loopback test\n", in efx_loopback_rx_packet()
340 if (memcmp(&received.msg, &payload->msg, sizeof(received.msg)) != 0) { in efx_loopback_rx_packet()
341 netif_err(efx, drv, efx->net_dev, in efx_loopback_rx_packet()
342 "saw corrupted RX packet in %s loopback test\n", in efx_loopback_rx_packet()
348 if (received.iteration != payload->iteration) { in efx_loopback_rx_packet()
349 netif_err(efx, drv, efx->net_dev, in efx_loopback_rx_packet()
351 "%s loopback test\n", ntohs(received.iteration), in efx_loopback_rx_packet()
352 ntohs(payload->iteration), LOOPBACK_MODE(efx)); in efx_loopback_rx_packet()
357 netif_vdbg(efx, drv, efx->net_dev, in efx_loopback_rx_packet()
358 "got loopback RX in %s loopback test\n", LOOPBACK_MODE(efx)); in efx_loopback_rx_packet()
360 atomic_inc(&state->rx_good); in efx_loopback_rx_packet()
365 if (atomic_read(&state->rx_bad) == 0) { in efx_loopback_rx_packet()
366 netif_err(efx, drv, efx->net_dev, "received packet:\n"); in efx_loopback_rx_packet()
369 netif_err(efx, drv, efx->net_dev, "expected packet:\n"); in efx_loopback_rx_packet()
371 &state->payload.packet, EFX_LOOPBACK_PAYLOAD_LEN, in efx_loopback_rx_packet()
375 atomic_inc(&state->rx_bad); in efx_loopback_rx_packet()
381 struct efx_loopback_state *state = efx->loopback_selftest; in efx_iterate_state()
382 struct net_device *net_dev = efx->net_dev; in efx_iterate_state()
383 struct efx_loopback_payload *payload = &state->payload; in efx_iterate_state()
386 ether_addr_copy((u8 *)&payload->header.h_dest, net_dev->dev_addr); in efx_iterate_state()
387 ether_addr_copy((u8 *)&payload->header.h_source, payload_source); in efx_iterate_state()
388 payload->header.h_proto = htons(ETH_P_IP); in efx_iterate_state()
391 payload->ip.daddr = htonl(INADDR_LOOPBACK); in efx_iterate_state()
392 payload->ip.ihl = 5; in efx_iterate_state()
393 payload->ip.check = (__force __sum16) htons(0xdead); in efx_iterate_state()
394 payload->ip.tot_len = htons(sizeof(*payload) - in efx_iterate_state()
396 payload->ip.version = IPVERSION; in efx_iterate_state()
397 payload->ip.protocol = IPPROTO_UDP; in efx_iterate_state()
400 payload->udp.source = 0; in efx_iterate_state()
401 payload->udp.len = htons(sizeof(*payload) - in efx_iterate_state()
403 payload->udp.check = 0; /* checksum ignored */ in efx_iterate_state()
406 payload->iteration = htons(ntohs(payload->iteration) + 1); in efx_iterate_state()
407 memcpy(&payload->msg, payload_msg, sizeof(payload_msg)); in efx_iterate_state()
410 atomic_set(&state->rx_good, 0); in efx_iterate_state()
411 atomic_set(&state->rx_bad, 0); in efx_iterate_state()
417 struct efx_nic *efx = tx_queue->efx; in efx_begin_loopback()
418 struct efx_loopback_state *state = efx->loopback_selftest; in efx_begin_loopback()
425 for (i = 0; i < state->packet_count; i++) { in efx_begin_loopback()
428 skb = alloc_skb(sizeof(state->payload), GFP_KERNEL); in efx_begin_loopback()
430 return -ENOMEM; in efx_begin_loopback()
431 state->skbs[i] = skb; in efx_begin_loopback()
436 payload = skb_put(skb, sizeof(state->payload)); in efx_begin_loopback()
437 memcpy(payload, &state->payload, sizeof(state->payload)); in efx_begin_loopback()
438 payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); in efx_begin_loopback()
448 netif_tx_lock_bh(efx->net_dev); in efx_begin_loopback()
450 netif_tx_unlock_bh(efx->net_dev); in efx_begin_loopback()
453 netif_err(efx, drv, efx->net_dev, in efx_begin_loopback()
455 "%d in %s loopback test\n", tx_queue->label, in efx_begin_loopback()
456 i + 1, state->packet_count, in efx_begin_loopback()
461 return -EPIPE; in efx_begin_loopback()
470 struct efx_loopback_state *state = efx->loopback_selftest; in efx_poll_loopback()
472 return atomic_read(&state->rx_good) == state->packet_count; in efx_poll_loopback()
478 struct efx_nic *efx = tx_queue->efx; in efx_end_loopback()
479 struct efx_loopback_state *state = efx->loopback_selftest; in efx_end_loopback()
484 netif_tx_lock_bh(efx->net_dev); in efx_end_loopback()
488 for (i = 0; i < state->packet_count; i++) { in efx_end_loopback()
489 skb = state->skbs[i]; in efx_end_loopback()
495 netif_tx_unlock_bh(efx->net_dev); in efx_end_loopback()
498 rx_good = atomic_read(&state->rx_good); in efx_end_loopback()
499 rx_bad = atomic_read(&state->rx_bad); in efx_end_loopback()
500 if (tx_done != state->packet_count) { in efx_end_loopback()
504 netif_err(efx, drv, efx->net_dev, in efx_end_loopback()
506 "TX completion events in %s loopback test\n", in efx_end_loopback()
507 tx_queue->label, tx_done, state->packet_count, in efx_end_loopback()
509 rc = -ETIMEDOUT; in efx_end_loopback()
514 if (rx_good != state->packet_count) { in efx_end_loopback()
515 netif_dbg(efx, drv, efx->net_dev, in efx_end_loopback()
517 "received packets in %s loopback test\n", in efx_end_loopback()
518 tx_queue->label, rx_good, state->packet_count, in efx_end_loopback()
520 rc = -ETIMEDOUT; in efx_end_loopback()
524 /* Update loopback test structure */ in efx_end_loopback()
525 lb_tests->tx_sent[tx_queue->label] += state->packet_count; in efx_end_loopback()
526 lb_tests->tx_done[tx_queue->label] += tx_done; in efx_end_loopback()
527 lb_tests->rx_good += rx_good; in efx_end_loopback()
528 lb_tests->rx_bad += rx_bad; in efx_end_loopback()
537 struct efx_nic *efx = tx_queue->efx; in efx_test_loopback()
538 struct efx_loopback_state *state = efx->loopback_selftest; in efx_test_loopback()
543 state->packet_count = efx->txq_entries / 3; in efx_test_loopback()
544 state->packet_count = min(1 << (i << 2), state->packet_count); in efx_test_loopback()
545 state->skbs = kcalloc(state->packet_count, in efx_test_loopback()
546 sizeof(state->skbs[0]), GFP_KERNEL); in efx_test_loopback()
547 if (!state->skbs) in efx_test_loopback()
548 return -ENOMEM; in efx_test_loopback()
549 state->flush = false; in efx_test_loopback()
551 netif_dbg(efx, drv, efx->net_dev, in efx_test_loopback()
552 "TX queue %d (hw %d) testing %s loopback with %d packets\n", in efx_test_loopback()
553 tx_queue->label, tx_queue->queue, LOOPBACK_MODE(efx), in efx_test_loopback()
554 state->packet_count); in efx_test_loopback()
568 kfree(state->skbs); in efx_test_loopback()
571 /* Wait a while to ensure there are no packets in efx_test_loopback()
578 netif_dbg(efx, drv, efx->net_dev, in efx_test_loopback()
579 "TX queue %d passed %s loopback test with a burst length " in efx_test_loopback()
580 "of %d packets\n", tx_queue->label, LOOPBACK_MODE(efx), in efx_test_loopback()
581 state->packet_count); in efx_test_loopback()
588 struct efx_link_state *link_state = &efx->link_state; in efx_wait_for_link()
595 if (efx->type->monitor != NULL) { in efx_wait_for_link()
596 mutex_lock(&efx->mac_lock); in efx_wait_for_link()
597 efx->type->monitor(efx); in efx_wait_for_link()
598 mutex_unlock(&efx->mac_lock); in efx_wait_for_link()
601 mutex_lock(&efx->mac_lock); in efx_wait_for_link()
602 link_up = link_state->up; in efx_wait_for_link()
604 link_up = !efx->type->check_mac_fault(efx); in efx_wait_for_link()
605 mutex_unlock(&efx->mac_lock); in efx_wait_for_link()
615 return -ETIMEDOUT; in efx_wait_for_link()
624 efx_get_channel(efx, efx->tx_channel_offset); in efx_test_loopbacks()
633 return -ENOMEM; in efx_test_loopbacks()
634 BUG_ON(efx->loopback_selftest); in efx_test_loopbacks()
635 state->flush = true; in efx_test_loopbacks()
636 efx->loopback_selftest = state; in efx_test_loopbacks()
638 /* Test all supported loopback modes */ in efx_test_loopbacks()
643 /* Move the port into the specified loopback mode. */ in efx_test_loopbacks()
644 state->flush = true; in efx_test_loopbacks()
645 mutex_lock(&efx->mac_lock); in efx_test_loopbacks()
646 efx->loopback_mode = mode; in efx_test_loopbacks()
648 mutex_unlock(&efx->mac_lock); in efx_test_loopbacks()
650 netif_err(efx, drv, efx->net_dev, in efx_test_loopbacks()
651 "unable to move into %s loopback\n", in efx_test_loopbacks()
658 netif_err(efx, drv, efx->net_dev, in efx_test_loopbacks()
659 "loopback %s never came up\n", in efx_test_loopbacks()
664 /* Test all enabled types of TX queue */ in efx_test_loopbacks()
666 state->offload_csum = (tx_queue->type & in efx_test_loopbacks()
669 &tests->loopback[mode]); in efx_test_loopbacks()
676 /* Remove the flush. The caller will remove the loopback setting */ in efx_test_loopbacks()
677 state->flush = true; in efx_test_loopbacks()
678 efx->loopback_selftest = NULL; in efx_test_loopbacks()
682 if (rc == -EPERM) in efx_test_loopbacks()
697 enum efx_loopback_mode loopback_mode = efx->loopback_mode; in efx_selftest()
698 int phy_mode = efx->phy_mode; in efx_selftest()
703 /* Online (i.e. non-disruptive) testing in efx_selftest()
729 * This checks MAC and PHY loopback on the specified port. */ in efx_selftest()
732 * loopback test and the watchdog timeout doesn't fire. in efx_selftest()
736 if (efx->type->test_chip) { in efx_selftest()
737 rc_reset = efx->type->test_chip(efx, tests); in efx_selftest()
739 netif_err(efx, hw, efx->net_dev, in efx_selftest()
740 "Unable to recover from chip test\n"); in efx_selftest()
745 if ((tests->memory < 0 || tests->registers < 0) && !rc_test) in efx_selftest()
746 rc_test = -EIO; in efx_selftest()
749 /* Ensure that the phy is powered and out of loopback in efx_selftest()
750 * for the bist and loopback tests */ in efx_selftest()
751 mutex_lock(&efx->mac_lock); in efx_selftest()
752 efx->phy_mode &= ~PHY_MODE_LOW_POWER; in efx_selftest()
753 efx->loopback_mode = LOOPBACK_NONE; in efx_selftest()
755 mutex_unlock(&efx->mac_lock); in efx_selftest()
761 rc = efx_test_loopbacks(efx, tests, efx->loopback_modes); in efx_selftest()
766 mutex_lock(&efx->mac_lock); in efx_selftest()
767 efx->phy_mode = phy_mode; in efx_selftest()
768 efx->loopback_mode = loopback_mode; in efx_selftest()
770 mutex_unlock(&efx->mac_lock); in efx_selftest()
783 schedule_delayed_work(&efx->selftest_work, IRQ_TIMEOUT); in efx_selftest_async_start()
788 cancel_delayed_work_sync(&efx->selftest_work); in efx_selftest_async_cancel()
801 netif_err(efx, ifup, efx->net_dev, in efx_selftest_async_work()
803 channel->channel); in efx_selftest_async_work()
805 netif_dbg(efx, ifup, efx->net_dev, in efx_selftest_async_work()
807 channel->channel, cpu); in efx_selftest_async_work()
813 INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work); in efx_selftest_async_init()