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

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

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/sfc/falcon/ethtool.c
Extension
.c
Size
40726 bytes
Lines
1364
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_sw_stat_desc {
	const char *name;
	enum {
		EF4_ETHTOOL_STAT_SOURCE_nic,
		EF4_ETHTOOL_STAT_SOURCE_channel,
		EF4_ETHTOOL_STAT_SOURCE_tx_queue
	} source;
	unsigned offset;
	u64(*get_stat) (void *field); /* Reader function */
};

/* Initialiser for a struct ef4_sw_stat_desc with type-checking */
#define EF4_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
				get_stat_function) {			\
	.name = #stat_name,						\
	.source = EF4_ETHTOOL_STAT_SOURCE_##source_name,		\
	.offset = ((((field_type *) 0) ==				\
		      &((struct ef4_##source_name *)0)->field) ?	\
		    offsetof(struct ef4_##source_name, field) :		\
		    offsetof(struct ef4_##source_name, field)),		\
	.get_stat = get_stat_function,					\
}

static u64 ef4_get_uint_stat(void *field)
{
	return *(unsigned int *)field;
}

static u64 ef4_get_atomic_stat(void *field)
{
	return atomic_read((atomic_t *) field);
}

#define EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field)		\
	EF4_ETHTOOL_STAT(field, nic, field,			\
			 atomic_t, ef4_get_atomic_stat)

#define EF4_ETHTOOL_UINT_CHANNEL_STAT(field)			\
	EF4_ETHTOOL_STAT(field, channel, n_##field,		\
			 unsigned int, ef4_get_uint_stat)

#define EF4_ETHTOOL_UINT_TXQ_STAT(field)			\
	EF4_ETHTOOL_STAT(tx_##field, tx_queue, field,		\
			 unsigned int, ef4_get_uint_stat)

static const struct ef4_sw_stat_desc ef4_sw_stat_desc[] = {
	EF4_ETHTOOL_UINT_TXQ_STAT(merge_events),
	EF4_ETHTOOL_UINT_TXQ_STAT(pushes),
	EF4_ETHTOOL_UINT_TXQ_STAT(cb_packets),
	EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
};

#define EF4_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(ef4_sw_stat_desc)

#define EF4_ETHTOOL_EEPROM_MAGIC 0xEFAB

/**************************************************************************
 *
 * Ethtool operations
 *
 **************************************************************************
 */

/* Identify device by flashing LEDs */
static int ef4_ethtool_phys_id(struct net_device *net_dev,
			       enum ethtool_phys_id_state state)
{
	struct ef4_nic *efx = netdev_priv(net_dev);
	enum ef4_led_mode mode = EF4_LED_DEFAULT;

	switch (state) {
	case ETHTOOL_ID_ON:
		mode = EF4_LED_ON;
		break;
	case ETHTOOL_ID_OFF:
		mode = EF4_LED_OFF;
		break;
	case ETHTOOL_ID_INACTIVE:
		mode = EF4_LED_DEFAULT;
		break;
	case ETHTOOL_ID_ACTIVE:
		return 1;	/* cycle on/off once per second */
	}

Annotation

Implementation Notes