drivers/net/ethernet/sfc/falcon/selftest.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/sfc/falcon/selftest.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/sfc/falcon/selftest.c
Extension
.c
Size
22704 bytes
Lines
816
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ef4_loopback_payload {
	char pad[2]; /* Ensures ip is 4-byte aligned */
	struct_group_attr(packet, __packed,
		struct ethhdr header;
		struct iphdr ip;
		struct udphdr udp;
		__be16 iteration;
		char msg[64];
	);
} __packed __aligned(4);
#define EF4_LOOPBACK_PAYLOAD_LEN	\
		sizeof_field(struct ef4_loopback_payload, packet)

/* Loopback test source MAC address */
static const u8 payload_source[ETH_ALEN] __aligned(2) = {
	0x00, 0x0f, 0x53, 0x1b, 0x1b, 0x1b,
};

static const char payload_msg[] =
	"Hello world! This is an Efx loopback test in progress!";

/* Interrupt mode names */
static const unsigned int ef4_interrupt_mode_max = EF4_INT_MODE_MAX;
static const char *const ef4_interrupt_mode_names[] = {
	[EF4_INT_MODE_MSIX]   = "MSI-X",
	[EF4_INT_MODE_MSI]    = "MSI",
	[EF4_INT_MODE_LEGACY] = "legacy",
};
#define INT_MODE(efx) \
	STRING_TABLE_LOOKUP(efx->interrupt_mode, ef4_interrupt_mode)

/**
 * struct ef4_loopback_state - persistent state during a loopback selftest
 * @flush:		Drop all packets in ef4_loopback_rx_packet
 * @packet_count:	Number of packets being used in this test
 * @skbs:		An array of skbs transmitted
 * @offload_csum:	Checksums are being offloaded
 * @rx_good:		RX good packet count
 * @rx_bad:		RX bad packet count
 * @payload:		Payload used in tests
 */
struct ef4_loopback_state {
	bool flush;
	int packet_count;
	struct sk_buff **skbs;
	bool offload_csum;
	atomic_t rx_good;
	atomic_t rx_bad;
	struct ef4_loopback_payload payload;
};

/* How long to wait for all the packets to arrive (in ms) */
#define LOOPBACK_TIMEOUT_MS 1000

/**************************************************************************
 *
 * MII, NVRAM and register tests
 *
 **************************************************************************/

static int ef4_test_phy_alive(struct ef4_nic *efx, struct ef4_self_tests *tests)
{
	int rc = 0;

	if (efx->phy_op->test_alive) {
		rc = efx->phy_op->test_alive(efx);
		tests->phy_alive = rc ? -1 : 1;
	}

	return rc;
}

static int ef4_test_nvram(struct ef4_nic *efx, struct ef4_self_tests *tests)
{
	int rc = 0;

	if (efx->type->test_nvram) {
		rc = efx->type->test_nvram(efx);
		if (rc == -EPERM)
			rc = 0;
		else
			tests->nvram = rc ? -1 : 1;
	}

	return rc;
}

/**************************************************************************
 *
 * Interrupt and event queue testing

Annotation

Implementation Notes