Lines Matching +full:wait +full:- +full:state
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
41 * The self-test should stress every RSS vector, and unfortunately
63 [EFX_INT_MODE_MSIX] = "MSI-X",
68 STRING_TABLE_LOOKUP(efx->interrupt_mode, efx_siena_interrupt_mode)
71 * struct efx_loopback_state - persistent state during a loopback selftest
90 /* How long to wait for all the packets to arrive (in ms) */
104 tests->phy_alive = rc ? -1 : 1; in efx_test_phy_alive()
113 if (efx->type->test_nvram) { in efx_test_nvram()
114 rc = efx->type->test_nvram(efx); in efx_test_nvram()
115 if (rc == -EPERM) in efx_test_nvram()
118 tests->nvram = rc ? -1 : 1; in efx_test_nvram()
134 unsigned long timeout, wait; in efx_test_interrupts() local
138 netif_dbg(efx, drv, efx->net_dev, "testing interrupts\n"); in efx_test_interrupts()
139 tests->interrupt = -1; in efx_test_interrupts()
142 if (rc == -ENOTSUPP) { in efx_test_interrupts()
143 netif_dbg(efx, drv, efx->net_dev, in efx_test_interrupts()
145 tests->interrupt = 0; in efx_test_interrupts()
150 wait = 1; in efx_test_interrupts()
152 /* Wait for arrival of test interrupt. */ in efx_test_interrupts()
153 netif_dbg(efx, drv, efx->net_dev, "waiting for test interrupt\n"); in efx_test_interrupts()
155 schedule_timeout_uninterruptible(wait); in efx_test_interrupts()
159 wait *= 2; in efx_test_interrupts()
162 netif_err(efx, drv, efx->net_dev, "timed out waiting for interrupt\n"); in efx_test_interrupts()
163 return -ETIMEDOUT; in efx_test_interrupts()
166 netif_dbg(efx, drv, efx->net_dev, "%s test interrupt seen on CPU%d\n", in efx_test_interrupts()
168 tests->interrupt = 1; in efx_test_interrupts()
179 unsigned long timeout, wait; in efx_test_eventq_irq() local
184 read_ptr[channel->channel] = channel->eventq_read_ptr; in efx_test_eventq_irq()
185 set_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
186 set_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
191 wait = 1; in efx_test_eventq_irq()
193 /* Wait for arrival of interrupts. NAPI processing may or may in efx_test_eventq_irq()
197 schedule_timeout_uninterruptible(wait); in efx_test_eventq_irq()
201 if (channel->eventq_read_ptr != in efx_test_eventq_irq()
202 read_ptr[channel->channel]) { in efx_test_eventq_irq()
203 set_bit(channel->channel, &napi_ran); in efx_test_eventq_irq()
204 clear_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
205 clear_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
208 clear_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
210 clear_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
215 wait *= 2; in efx_test_eventq_irq()
219 bool dma_seen = !test_bit(channel->channel, &dma_pend); in efx_test_eventq_irq()
220 bool int_seen = !test_bit(channel->channel, &int_pend); in efx_test_eventq_irq()
222 tests->eventq_dma[channel->channel] = dma_seen ? 1 : -1; in efx_test_eventq_irq()
223 tests->eventq_int[channel->channel] = int_seen ? 1 : -1; in efx_test_eventq_irq()
226 netif_dbg(efx, drv, efx->net_dev, in efx_test_eventq_irq()
228 channel->channel, in efx_test_eventq_irq()
229 test_bit(channel->channel, &napi_ran) ? in efx_test_eventq_irq()
235 netif_err(efx, drv, efx->net_dev, in efx_test_eventq_irq()
237 channel->channel); in efx_test_eventq_irq()
239 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()
247 channel->channel); in efx_test_eventq_irq()
251 return (dma_pend || int_pend) ? -ETIMEDOUT : 0; in efx_test_eventq_irq()
259 mutex_lock(&efx->mac_lock); in efx_test_phy()
260 rc = efx_siena_mcdi_phy_run_tests(efx, tests->phy_ext, flags); in efx_test_phy()
261 mutex_unlock(&efx->mac_lock); in efx_test_phy()
262 if (rc == -EPERM) in efx_test_phy()
265 netif_info(efx, drv, efx->net_dev, in efx_test_phy()
284 struct efx_loopback_state *state = efx->loopback_selftest; in efx_siena_loopback_rx_packet() local
291 if ((state == NULL) || state->flush) in efx_siena_loopback_rx_packet()
294 payload = &state->payload; in efx_siena_loopback_rx_packet()
297 received->ip.saddr = payload->ip.saddr; in efx_siena_loopback_rx_packet()
298 if (state->offload_csum) in efx_siena_loopback_rx_packet()
299 received->ip.check = payload->ip.check; in efx_siena_loopback_rx_packet()
302 if (pkt_len < sizeof(received->header)) { in efx_siena_loopback_rx_packet()
303 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
310 if (memcmp(&received->header, &payload->header, ETH_HLEN) != 0) { in efx_siena_loopback_rx_packet()
311 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
312 "saw non-loopback RX packet in %s loopback test\n", in efx_siena_loopback_rx_packet()
319 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
327 if (memcmp(&received->ip, &payload->ip, sizeof(payload->ip)) != 0) { in efx_siena_loopback_rx_packet()
328 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
335 if (memcmp(&received->msg, &payload->msg, sizeof(received->msg)) != 0) { in efx_siena_loopback_rx_packet()
336 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
343 if (received->iteration != payload->iteration) { in efx_siena_loopback_rx_packet()
344 netif_err(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
346 "%s loopback test\n", ntohs(received->iteration), in efx_siena_loopback_rx_packet()
347 ntohs(payload->iteration), LOOPBACK_MODE(efx)); in efx_siena_loopback_rx_packet()
352 netif_vdbg(efx, drv, efx->net_dev, in efx_siena_loopback_rx_packet()
355 atomic_inc(&state->rx_good); in efx_siena_loopback_rx_packet()
360 if (atomic_read(&state->rx_bad) == 0) { in efx_siena_loopback_rx_packet()
361 netif_err(efx, drv, efx->net_dev, "received packet:\n"); in efx_siena_loopback_rx_packet()
364 netif_err(efx, drv, efx->net_dev, "expected packet:\n"); in efx_siena_loopback_rx_packet()
366 &state->payload, sizeof(state->payload), 0); in efx_siena_loopback_rx_packet()
369 atomic_inc(&state->rx_bad); in efx_siena_loopback_rx_packet()
375 struct efx_loopback_state *state = efx->loopback_selftest; in efx_iterate_state() local
376 struct net_device *net_dev = efx->net_dev; in efx_iterate_state()
377 struct efx_loopback_payload *payload = &state->payload; in efx_iterate_state()
380 ether_addr_copy((u8 *)&payload->header.h_dest, net_dev->dev_addr); in efx_iterate_state()
381 ether_addr_copy((u8 *)&payload->header.h_source, payload_source); in efx_iterate_state()
382 payload->header.h_proto = htons(ETH_P_IP); in efx_iterate_state()
385 payload->ip.daddr = htonl(INADDR_LOOPBACK); in efx_iterate_state()
386 payload->ip.ihl = 5; in efx_iterate_state()
387 payload->ip.check = (__force __sum16) htons(0xdead); in efx_iterate_state()
388 payload->ip.tot_len = htons(sizeof(*payload) - sizeof(struct ethhdr)); in efx_iterate_state()
389 payload->ip.version = IPVERSION; in efx_iterate_state()
390 payload->ip.protocol = IPPROTO_UDP; in efx_iterate_state()
393 payload->udp.source = 0; in efx_iterate_state()
394 payload->udp.len = htons(sizeof(*payload) - sizeof(struct ethhdr) - in efx_iterate_state()
396 payload->udp.check = 0; /* checksum ignored */ in efx_iterate_state()
399 payload->iteration = htons(ntohs(payload->iteration) + 1); in efx_iterate_state()
400 memcpy(&payload->msg, payload_msg, sizeof(payload_msg)); in efx_iterate_state()
402 /* Fill out remaining state members */ in efx_iterate_state()
403 atomic_set(&state->rx_good, 0); in efx_iterate_state()
404 atomic_set(&state->rx_bad, 0); in efx_iterate_state()
410 struct efx_nic *efx = tx_queue->efx; in efx_begin_loopback()
411 struct efx_loopback_state *state = efx->loopback_selftest; in efx_begin_loopback() local
418 for (i = 0; i < state->packet_count; i++) { in efx_begin_loopback()
421 skb = alloc_skb(sizeof(state->payload), GFP_KERNEL); in efx_begin_loopback()
423 return -ENOMEM; in efx_begin_loopback()
424 state->skbs[i] = skb; in efx_begin_loopback()
429 payload = skb_put(skb, sizeof(state->payload)); in efx_begin_loopback()
430 memcpy(payload, &state->payload, sizeof(state->payload)); in efx_begin_loopback()
431 payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2)); in efx_begin_loopback()
437 netif_tx_lock_bh(efx->net_dev); in efx_begin_loopback()
439 netif_tx_unlock_bh(efx->net_dev); in efx_begin_loopback()
442 netif_err(efx, drv, efx->net_dev, in efx_begin_loopback()
444 "%d in %s loopback test\n", tx_queue->label, in efx_begin_loopback()
445 i + 1, state->packet_count, in efx_begin_loopback()
450 return -EPIPE; in efx_begin_loopback()
459 struct efx_loopback_state *state = efx->loopback_selftest; in efx_poll_loopback() local
461 return atomic_read(&state->rx_good) == state->packet_count; in efx_poll_loopback()
467 struct efx_nic *efx = tx_queue->efx; in efx_end_loopback()
468 struct efx_loopback_state *state = efx->loopback_selftest; in efx_end_loopback() local
473 netif_tx_lock_bh(efx->net_dev); in efx_end_loopback()
477 for (i = 0; i < state->packet_count; i++) { in efx_end_loopback()
478 skb = state->skbs[i]; in efx_end_loopback()
484 netif_tx_unlock_bh(efx->net_dev); in efx_end_loopback()
487 rx_good = atomic_read(&state->rx_good); in efx_end_loopback()
488 rx_bad = atomic_read(&state->rx_bad); in efx_end_loopback()
489 if (tx_done != state->packet_count) { in efx_end_loopback()
493 netif_err(efx, drv, efx->net_dev, in efx_end_loopback()
496 tx_queue->label, tx_done, state->packet_count, in efx_end_loopback()
498 rc = -ETIMEDOUT; in efx_end_loopback()
503 if (rx_good != state->packet_count) { in efx_end_loopback()
504 netif_dbg(efx, drv, efx->net_dev, in efx_end_loopback()
507 tx_queue->label, rx_good, state->packet_count, in efx_end_loopback()
509 rc = -ETIMEDOUT; in efx_end_loopback()
514 lb_tests->tx_sent[tx_queue->label] += state->packet_count; in efx_end_loopback()
515 lb_tests->tx_done[tx_queue->label] += tx_done; in efx_end_loopback()
516 lb_tests->rx_good += rx_good; in efx_end_loopback()
517 lb_tests->rx_bad += rx_bad; in efx_end_loopback()
526 struct efx_nic *efx = tx_queue->efx; in efx_test_loopback()
527 struct efx_loopback_state *state = efx->loopback_selftest; in efx_test_loopback() local
532 state->packet_count = efx->txq_entries / 3; in efx_test_loopback()
533 state->packet_count = min(1 << (i << 2), state->packet_count); in efx_test_loopback()
534 state->skbs = kcalloc(state->packet_count, in efx_test_loopback()
535 sizeof(state->skbs[0]), GFP_KERNEL); in efx_test_loopback()
536 if (!state->skbs) in efx_test_loopback()
537 return -ENOMEM; in efx_test_loopback()
538 state->flush = false; in efx_test_loopback()
540 netif_dbg(efx, drv, efx->net_dev, in efx_test_loopback()
542 tx_queue->label, tx_queue->queue, LOOPBACK_MODE(efx), in efx_test_loopback()
543 state->packet_count); in efx_test_loopback()
549 * prepared to wait much longer. */ in efx_test_loopback()
557 kfree(state->skbs); in efx_test_loopback()
560 /* Wait a while to ensure there are no packets in efx_test_loopback()
567 netif_dbg(efx, drv, efx->net_dev, in efx_test_loopback()
569 "of %d packets\n", tx_queue->label, LOOPBACK_MODE(efx), in efx_test_loopback()
570 state->packet_count); in efx_test_loopback()
575 /* Wait for link up. On Falcon, we would prefer to rely on efx_monitor, but
577 * to delay and retry. Therefore, it's safer to just poll directly. Wait
581 struct efx_link_state *link_state = &efx->link_state; in efx_wait_for_link()
588 if (efx->type->monitor != NULL) { in efx_wait_for_link()
589 mutex_lock(&efx->mac_lock); in efx_wait_for_link()
590 efx->type->monitor(efx); in efx_wait_for_link()
591 mutex_unlock(&efx->mac_lock); in efx_wait_for_link()
594 mutex_lock(&efx->mac_lock); in efx_wait_for_link()
595 link_up = link_state->up; in efx_wait_for_link()
597 link_up = !efx->type->check_mac_fault(efx); in efx_wait_for_link()
598 mutex_unlock(&efx->mac_lock); in efx_wait_for_link()
608 return -ETIMEDOUT; in efx_wait_for_link()
615 struct efx_loopback_state *state; in efx_test_loopbacks() local
617 efx_get_channel(efx, efx->tx_channel_offset); in efx_test_loopbacks()
622 * all received packets will be dropped. Mark the state as in efx_test_loopbacks()
624 state = kzalloc(sizeof(*state), GFP_KERNEL); in efx_test_loopbacks()
625 if (state == NULL) in efx_test_loopbacks()
626 return -ENOMEM; in efx_test_loopbacks()
627 BUG_ON(efx->loopback_selftest); in efx_test_loopbacks()
628 state->flush = true; in efx_test_loopbacks()
629 efx->loopback_selftest = state; in efx_test_loopbacks()
637 state->flush = true; in efx_test_loopbacks()
638 mutex_lock(&efx->mac_lock); in efx_test_loopbacks()
639 efx->loopback_mode = mode; in efx_test_loopbacks()
641 mutex_unlock(&efx->mac_lock); in efx_test_loopbacks()
643 netif_err(efx, drv, efx->net_dev, in efx_test_loopbacks()
651 netif_err(efx, drv, efx->net_dev, in efx_test_loopbacks()
659 state->offload_csum = (tx_queue->type & in efx_test_loopbacks()
662 &tests->loopback[mode]); in efx_test_loopbacks()
670 state->flush = true; in efx_test_loopbacks()
671 efx->loopback_selftest = NULL; in efx_test_loopbacks()
673 kfree(state); in efx_test_loopbacks()
675 if (rc == -EPERM) in efx_test_loopbacks()
690 enum efx_loopback_mode loopback_mode = efx->loopback_mode; in efx_siena_selftest()
691 int phy_mode = efx->phy_mode; in efx_siena_selftest()
696 /* Online (i.e. non-disruptive) testing in efx_siena_selftest()
729 if (efx->type->test_chip) { in efx_siena_selftest()
730 rc_reset = efx->type->test_chip(efx, tests); in efx_siena_selftest()
732 netif_err(efx, hw, efx->net_dev, in efx_siena_selftest()
738 if ((tests->memory < 0 || tests->registers < 0) && !rc_test) in efx_siena_selftest()
739 rc_test = -EIO; in efx_siena_selftest()
744 mutex_lock(&efx->mac_lock); in efx_siena_selftest()
745 efx->phy_mode &= ~PHY_MODE_LOW_POWER; in efx_siena_selftest()
746 efx->loopback_mode = LOOPBACK_NONE; in efx_siena_selftest()
748 mutex_unlock(&efx->mac_lock); in efx_siena_selftest()
754 rc = efx_test_loopbacks(efx, tests, efx->loopback_modes); in efx_siena_selftest()
758 /* restore the PHY to the previous state */ in efx_siena_selftest()
759 mutex_lock(&efx->mac_lock); in efx_siena_selftest()
760 efx->phy_mode = phy_mode; in efx_siena_selftest()
761 efx->loopback_mode = loopback_mode; in efx_siena_selftest()
763 mutex_unlock(&efx->mac_lock); in efx_siena_selftest()
776 schedule_delayed_work(&efx->selftest_work, IRQ_TIMEOUT); in efx_siena_selftest_async_start()
781 cancel_delayed_work_sync(&efx->selftest_work); in efx_siena_selftest_async_cancel()
794 netif_err(efx, ifup, efx->net_dev, in efx_siena_selftest_async_work()
796 channel->channel); in efx_siena_selftest_async_work()
798 netif_dbg(efx, ifup, efx->net_dev, in efx_siena_selftest_async_work()
800 channel->channel, cpu); in efx_siena_selftest_async_work()
806 INIT_DELAYED_WORK(&efx->selftest_work, efx_siena_selftest_async_work); in efx_siena_selftest_async_init()