^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for Solarflare network controllers and boards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 2005-2006 Fen Systems Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2006-2012 Solarflare Communications Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "net_driver.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "efx.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "efx_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "efx_channels.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "nic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "mcdi_port_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "selftest.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "workarounds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* IRQ latency can be enormous because:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * - All IRQs may be disabled on a CPU for a *long* time by e.g. a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * slow serial console or an old IDE driver doing error recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * - The PREEMPT_RT patches mostly deal with this, but also allow a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * tasklet or normal task to be given higher priority than our IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * threads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Try to avoid blaming the hardware for this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define IRQ_TIMEOUT HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Loopback test packet structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * The self-test should stress every RSS vector, and unfortunately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Falcon only performs RSS on TCP/UDP packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct efx_loopback_payload {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct ethhdr header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct iphdr ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct udphdr udp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) __be16 iteration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) char msg[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* Loopback test source MAC address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static const u8 payload_source[ETH_ALEN] __aligned(2) = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 0x00, 0x0f, 0x53, 0x1b, 0x1b, 0x1b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static const char payload_msg[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) "Hello world! This is an Efx loopback test in progress!";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* Interrupt mode names */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static const unsigned int efx_interrupt_mode_max = EFX_INT_MODE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static const char *const efx_interrupt_mode_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) [EFX_INT_MODE_MSIX] = "MSI-X",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) [EFX_INT_MODE_MSI] = "MSI",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) [EFX_INT_MODE_LEGACY] = "legacy",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define INT_MODE(efx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) STRING_TABLE_LOOKUP(efx->interrupt_mode, efx_interrupt_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * struct efx_loopback_state - persistent state during a loopback selftest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * @flush: Drop all packets in efx_loopback_rx_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @packet_count: Number of packets being used in this test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @skbs: An array of skbs transmitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @offload_csum: Checksums are being offloaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @rx_good: RX good packet count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * @rx_bad: RX bad packet count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * @payload: Payload used in tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct efx_loopback_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) bool flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int packet_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct sk_buff **skbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) bool offload_csum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) atomic_t rx_good;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) atomic_t rx_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct efx_loopback_payload payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* How long to wait for all the packets to arrive (in ms) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define LOOPBACK_TIMEOUT_MS 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * MII, NVRAM and register tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static int efx_test_phy_alive(struct efx_nic *efx, struct efx_self_tests *tests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rc = efx_mcdi_phy_test_alive(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) tests->phy_alive = rc ? -1 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int efx_test_nvram(struct efx_nic *efx, struct efx_self_tests *tests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (efx->type->test_nvram) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) rc = efx->type->test_nvram(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (rc == -EPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) tests->nvram = rc ? -1 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * Interrupt and event queue testing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* Test generation and receipt of interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int efx_test_interrupts(struct efx_nic *efx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct efx_self_tests *tests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned long timeout, wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) netif_dbg(efx, drv, efx->net_dev, "testing interrupts\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) tests->interrupt = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) rc = efx_nic_irq_test_start(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (rc == -ENOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) netif_dbg(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) "direct interrupt testing not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) tests->interrupt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) timeout = jiffies + IRQ_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) wait = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /* Wait for arrival of test interrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) netif_dbg(efx, drv, efx->net_dev, "waiting for test interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) schedule_timeout_uninterruptible(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) cpu = efx_nic_irq_test_irq_cpu(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (cpu >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) goto success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) wait *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) } while (time_before(jiffies, timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) netif_err(efx, drv, efx->net_dev, "timed out waiting for interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) success:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) netif_dbg(efx, drv, efx->net_dev, "%s test interrupt seen on CPU%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) INT_MODE(efx), cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) tests->interrupt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* Test generation and receipt of interrupting events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static int efx_test_eventq_irq(struct efx_nic *efx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct efx_self_tests *tests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct efx_channel *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) unsigned int read_ptr[EFX_MAX_CHANNELS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned long napi_ran = 0, dma_pend = 0, int_pend = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) unsigned long timeout, wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) BUILD_BUG_ON(EFX_MAX_CHANNELS > BITS_PER_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) efx_for_each_channel(channel, efx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) read_ptr[channel->channel] = channel->eventq_read_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) set_bit(channel->channel, &dma_pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) set_bit(channel->channel, &int_pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) efx_nic_event_test_start(channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) timeout = jiffies + IRQ_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) wait = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Wait for arrival of interrupts. NAPI processing may or may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * not complete in time, but we can cope in any case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) schedule_timeout_uninterruptible(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) efx_for_each_channel(channel, efx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) efx_stop_eventq(channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (channel->eventq_read_ptr !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) read_ptr[channel->channel]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) set_bit(channel->channel, &napi_ran);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) clear_bit(channel->channel, &dma_pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) clear_bit(channel->channel, &int_pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (efx_nic_event_present(channel))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) clear_bit(channel->channel, &dma_pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (efx_nic_event_test_irq_cpu(channel) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) clear_bit(channel->channel, &int_pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) efx_start_eventq(channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) wait *= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) } while ((dma_pend || int_pend) && time_before(jiffies, timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) efx_for_each_channel(channel, efx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) bool dma_seen = !test_bit(channel->channel, &dma_pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) bool int_seen = !test_bit(channel->channel, &int_pend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) tests->eventq_dma[channel->channel] = dma_seen ? 1 : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) tests->eventq_int[channel->channel] = int_seen ? 1 : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (dma_seen && int_seen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) netif_dbg(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) "channel %d event queue passed (with%s NAPI)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) channel->channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) test_bit(channel->channel, &napi_ran) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) "" : "out");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* Report failure and whether either interrupt or DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * worked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) "channel %d timed out waiting for event queue\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) channel->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (int_seen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) "channel %d saw interrupt "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) "during event queue test\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) channel->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (dma_seen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) "channel %d event was generated, but "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) "failed to trigger an interrupt\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) channel->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return (dma_pend || int_pend) ? -ETIMEDOUT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int efx_test_phy(struct efx_nic *efx, struct efx_self_tests *tests,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) unsigned flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) mutex_lock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) rc = efx_mcdi_phy_run_tests(efx, tests->phy_ext, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (rc == -EPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) netif_info(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) "%s phy selftest\n", rc ? "Failed" : "Passed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * Loopback testing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * NB Only one loopback test can be executing concurrently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) **************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Loopback test RX callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * This is called for each received packet during loopback testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) void efx_loopback_rx_packet(struct efx_nic *efx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) const char *buf_ptr, int pkt_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct efx_loopback_state *state = efx->loopback_selftest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct efx_loopback_payload *received;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct efx_loopback_payload *payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) BUG_ON(!buf_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* If we are just flushing, then drop the packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if ((state == NULL) || state->flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) payload = &state->payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) received = (struct efx_loopback_payload *) buf_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) received->ip.saddr = payload->ip.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (state->offload_csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) received->ip.check = payload->ip.check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* Check that header exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (pkt_len < sizeof(received->header)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) "saw runt RX packet (length %d) in %s loopback "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) "test\n", pkt_len, LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* Check that the ethernet header exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (memcmp(&received->header, &payload->header, ETH_HLEN) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) "saw non-loopback RX packet in %s loopback test\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* Check packet length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (pkt_len != sizeof(*payload)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) "saw incorrect RX packet length %d (wanted %d) in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) "%s loopback test\n", pkt_len, (int)sizeof(*payload),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* Check that IP header matches */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (memcmp(&received->ip, &payload->ip, sizeof(payload->ip)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) "saw corrupted IP header in %s loopback test\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /* Check that msg and padding matches */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (memcmp(&received->msg, &payload->msg, sizeof(received->msg)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) "saw corrupted RX packet in %s loopback test\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* Check that iteration matches */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (received->iteration != payload->iteration) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) "saw RX packet from iteration %d (wanted %d) in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) "%s loopback test\n", ntohs(received->iteration),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) ntohs(payload->iteration), LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* Increase correct RX count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) netif_vdbg(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) "got loopback RX in %s loopback test\n", LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) atomic_inc(&state->rx_good);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (atomic_read(&state->rx_bad) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) netif_err(efx, drv, efx->net_dev, "received packet:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) buf_ptr, pkt_len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) netif_err(efx, drv, efx->net_dev, "expected packet:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) &state->payload, sizeof(state->payload), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) atomic_inc(&state->rx_bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* Initialise an efx_selftest_state for a new iteration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static void efx_iterate_state(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct efx_loopback_state *state = efx->loopback_selftest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct net_device *net_dev = efx->net_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct efx_loopback_payload *payload = &state->payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /* Initialise the layerII header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ether_addr_copy((u8 *)&payload->header.h_dest, net_dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ether_addr_copy((u8 *)&payload->header.h_source, payload_source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) payload->header.h_proto = htons(ETH_P_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* saddr set later and used as incrementing count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) payload->ip.daddr = htonl(INADDR_LOOPBACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) payload->ip.ihl = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) payload->ip.check = (__force __sum16) htons(0xdead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) payload->ip.tot_len = htons(sizeof(*payload) - sizeof(struct ethhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) payload->ip.version = IPVERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) payload->ip.protocol = IPPROTO_UDP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* Initialise udp header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) payload->udp.source = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) payload->udp.len = htons(sizeof(*payload) - sizeof(struct ethhdr) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) sizeof(struct iphdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) payload->udp.check = 0; /* checksum ignored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /* Fill out payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) payload->iteration = htons(ntohs(payload->iteration) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) memcpy(&payload->msg, payload_msg, sizeof(payload_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* Fill out remaining state members */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) atomic_set(&state->rx_good, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) atomic_set(&state->rx_bad, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct efx_nic *efx = tx_queue->efx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct efx_loopback_state *state = efx->loopback_selftest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct efx_loopback_payload *payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) netdev_tx_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /* Transmit N copies of buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) for (i = 0; i < state->packet_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* Allocate an skb, holding an extra reference for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * transmit completion counting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) skb = alloc_skb(sizeof(state->payload), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) state->skbs[i] = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) skb_get(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* Copy the payload in, incrementing the source address to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * exercise the rss vectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) payload = skb_put(skb, sizeof(state->payload));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) memcpy(payload, &state->payload, sizeof(state->payload));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* Ensure everything we've written is visible to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * interrupt handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) netif_tx_lock_bh(efx->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) rc = efx_enqueue_skb(tx_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) netif_tx_unlock_bh(efx->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (rc != NETDEV_TX_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) "TX queue %d could not transmit packet %d of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) "%d in %s loopback test\n", tx_queue->label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) i + 1, state->packet_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* Defer cleaning up the other skbs for the caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static int efx_poll_loopback(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) struct efx_loopback_state *state = efx->loopback_selftest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return atomic_read(&state->rx_good) == state->packet_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static int efx_end_loopback(struct efx_tx_queue *tx_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) struct efx_loopback_self_tests *lb_tests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct efx_nic *efx = tx_queue->efx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct efx_loopback_state *state = efx->loopback_selftest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) int tx_done = 0, rx_good, rx_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) int i, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) netif_tx_lock_bh(efx->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) /* Count the number of tx completions, and decrement the refcnt. Any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * skbs not already completed will be free'd when the queue is flushed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) for (i = 0; i < state->packet_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) skb = state->skbs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (skb && !skb_shared(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) ++tx_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) netif_tx_unlock_bh(efx->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) /* Check TX completion and received packet counts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) rx_good = atomic_read(&state->rx_good);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) rx_bad = atomic_read(&state->rx_bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (tx_done != state->packet_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* Don't free the skbs; they will be picked up on TX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * overflow or channel teardown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) "TX queue %d saw only %d out of an expected %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) "TX completion events in %s loopback test\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) tx_queue->label, tx_done, state->packet_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) rc = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) /* Allow to fall through so we see the RX errors as well */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /* We may always be up to a flush away from our desired packet total */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (rx_good != state->packet_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) netif_dbg(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) "TX queue %d saw only %d out of an expected %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) "received packets in %s loopback test\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) tx_queue->label, rx_good, state->packet_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) rc = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) /* Fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /* Update loopback test structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) lb_tests->tx_sent[tx_queue->label] += state->packet_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) lb_tests->tx_done[tx_queue->label] += tx_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) lb_tests->rx_good += rx_good;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) lb_tests->rx_bad += rx_bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) efx_test_loopback(struct efx_tx_queue *tx_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct efx_loopback_self_tests *lb_tests)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct efx_nic *efx = tx_queue->efx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct efx_loopback_state *state = efx->loopback_selftest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int i, begin_rc, end_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /* Determine how many packets to send */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) state->packet_count = efx->txq_entries / 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) state->packet_count = min(1 << (i << 2), state->packet_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) state->skbs = kcalloc(state->packet_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) sizeof(state->skbs[0]), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (!state->skbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) state->flush = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) netif_dbg(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) "TX queue %d (hw %d) testing %s loopback with %d packets\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) tx_queue->label, tx_queue->queue, LOOPBACK_MODE(efx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) state->packet_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) efx_iterate_state(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) begin_rc = efx_begin_loopback(tx_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /* This will normally complete very quickly, but be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * prepared to wait much longer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (!efx_poll_loopback(efx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) msleep(LOOPBACK_TIMEOUT_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) efx_poll_loopback(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) end_rc = efx_end_loopback(tx_queue, lb_tests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) kfree(state->skbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (begin_rc || end_rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /* Wait a while to ensure there are no packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * floating around after a failure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) schedule_timeout_uninterruptible(HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return begin_rc ? begin_rc : end_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) netif_dbg(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) "TX queue %d passed %s loopback test with a burst length "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) "of %d packets\n", tx_queue->label, LOOPBACK_MODE(efx),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) state->packet_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /* Wait for link up. On Falcon, we would prefer to rely on efx_monitor, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * any contention on the mac lock (via e.g. efx_mac_mcast_work) causes it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * to delay and retry. Therefore, it's safer to just poll directly. Wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * for link up and any faults to dissipate. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static int efx_wait_for_link(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct efx_link_state *link_state = &efx->link_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) int count, link_up_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) bool link_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) for (count = 0; count < 40; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) schedule_timeout_uninterruptible(HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (efx->type->monitor != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) mutex_lock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) efx->type->monitor(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) mutex_lock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) link_up = link_state->up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (link_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) link_up = !efx->type->check_mac_fault(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (link_up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (++link_up_count == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) link_up_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) static int efx_test_loopbacks(struct efx_nic *efx, struct efx_self_tests *tests,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) unsigned int loopback_modes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) enum efx_loopback_mode mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct efx_loopback_state *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) struct efx_channel *channel =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) efx_get_channel(efx, efx->tx_channel_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct efx_tx_queue *tx_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) /* Set the port loopback_selftest member. From this point on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) * all received packets will be dropped. Mark the state as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) * "flushing" so all inflight packets are dropped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) state = kzalloc(sizeof(*state), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (state == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) BUG_ON(efx->loopback_selftest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) state->flush = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) efx->loopback_selftest = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /* Test all supported loopback modes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (!(loopback_modes & (1 << mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* Move the port into the specified loopback mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) state->flush = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) mutex_lock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) efx->loopback_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) rc = __efx_reconfigure_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) "unable to move into %s loopback\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) rc = efx_wait_for_link(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) netif_err(efx, drv, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) "loopback %s never came up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) LOOPBACK_MODE(efx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) /* Test all enabled types of TX queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) efx_for_each_channel_tx_queue(tx_queue, channel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) state->offload_csum = (tx_queue->type &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) EFX_TXQ_TYPE_OUTER_CSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) rc = efx_test_loopback(tx_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) &tests->loopback[mode]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) /* Remove the flush. The caller will remove the loopback setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) state->flush = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) efx->loopback_selftest = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) kfree(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (rc == -EPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /**************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) * Entry point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) int efx_selftest(struct efx_nic *efx, struct efx_self_tests *tests,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) unsigned flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) enum efx_loopback_mode loopback_mode = efx->loopback_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) int phy_mode = efx->phy_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) int rc_test = 0, rc_reset, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) efx_selftest_async_cancel(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) /* Online (i.e. non-disruptive) testing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * This checks interrupt generation, event delivery and PHY presence. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) rc = efx_test_phy_alive(efx, tests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (rc && !rc_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) rc_test = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) rc = efx_test_nvram(efx, tests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (rc && !rc_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) rc_test = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) rc = efx_test_interrupts(efx, tests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (rc && !rc_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) rc_test = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) rc = efx_test_eventq_irq(efx, tests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (rc && !rc_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) rc_test = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (rc_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return rc_test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (!(flags & ETH_TEST_FL_OFFLINE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) return efx_test_phy(efx, tests, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) /* Offline (i.e. disruptive) testing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * This checks MAC and PHY loopback on the specified port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /* Detach the device so the kernel doesn't transmit during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * loopback test and the watchdog timeout doesn't fire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) efx_device_detach_sync(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (efx->type->test_chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) rc_reset = efx->type->test_chip(efx, tests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (rc_reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) netif_err(efx, hw, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) "Unable to recover from chip test\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) efx_schedule_reset(efx, RESET_TYPE_DISABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return rc_reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if ((tests->memory < 0 || tests->registers < 0) && !rc_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) rc_test = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) /* Ensure that the phy is powered and out of loopback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) * for the bist and loopback tests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) mutex_lock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) efx->phy_mode &= ~PHY_MODE_LOW_POWER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) efx->loopback_mode = LOOPBACK_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) __efx_reconfigure_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) rc = efx_test_phy(efx, tests, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (rc && !rc_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) rc_test = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) rc = efx_test_loopbacks(efx, tests, efx->loopback_modes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (rc && !rc_test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) rc_test = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) /* restore the PHY to the previous state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) mutex_lock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) efx->phy_mode = phy_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) efx->loopback_mode = loopback_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) __efx_reconfigure_port(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) mutex_unlock(&efx->mac_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) efx_device_attach_if_not_resetting(efx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) return rc_test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) void efx_selftest_async_start(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) struct efx_channel *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) efx_for_each_channel(channel, efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) efx_nic_event_test_start(channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) schedule_delayed_work(&efx->selftest_work, IRQ_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) void efx_selftest_async_cancel(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) cancel_delayed_work_sync(&efx->selftest_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static void efx_selftest_async_work(struct work_struct *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) struct efx_nic *efx = container_of(data, struct efx_nic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) selftest_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) struct efx_channel *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) efx_for_each_channel(channel, efx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) cpu = efx_nic_event_test_irq_cpu(channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) if (cpu < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) netif_err(efx, ifup, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) "channel %d failed to trigger an interrupt\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) channel->channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) netif_dbg(efx, ifup, efx->net_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) "channel %d triggered interrupt on CPU %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) channel->channel, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) void efx_selftest_async_init(struct efx_nic *efx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }