drivers/net/dsa/netc/netc_ethtool.c

Source file repositories/reference/linux-study-clean/drivers/net/dsa/netc/netc_ethtool.c

File Facts

System
Linux kernel
Corpus path
drivers/net/dsa/netc/netc_ethtool.c
Extension
.c
Size
9064 bytes
Lines
292
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

// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
/*
 * NXP NETC switch driver
 * Copyright 2025-2026 NXP
 */

#include <linux/ethtool_netlink.h>

#include "netc_switch.h"

static const struct ethtool_rmon_hist_range netc_rmon_ranges[] = {
	{   64,   64 },
	{   65,  127 },
	{  128,  255 },
	{  256,  511 },
	{  512, 1023 },
	{ 1024, 1522 },
	{ 1523, NETC_MAX_FRAME_LEN },
	{ }
};

static const struct netc_port_stat netc_port_counters[] = {
	{ NETC_PTGSLACR,	"port gate late arrival frames" },
	{ NETC_PSDFTCR,	"port SDF transmit frames" },
	{ NETC_PSDFDDCR,	"port SDF drop duplicate frames" },
	{ NETC_PRXDCR,		"port rx discard frames" },
	{ NETC_PRXDCRRR,	"port rx discard read-reset" },
	{ NETC_PRXDCRR0,	"port rx discard reason 0" },
	{ NETC_PRXDCRR1,	"port rx discard reason 1" },
	{ NETC_PTXDCR,		"port tx discard frames" },
	{ NETC_BPDCR,		"bridge port discard frames" },
};

static const struct netc_port_stat netc_emac_counters[] = {
	{ NETC_PM_ROCT(0),	"eMAC rx octets" },
	{ NETC_PM_RVLAN(0),	"eMAC rx VLAN frames" },
	{ NETC_PM_RERR(0),	"eMAC rx frame errors" },
	{ NETC_PM_RUCA(0),	"eMAC rx unicast frames" },
	{ NETC_PM_RDRP(0),	"eMAC rx dropped packets" },
	{ NETC_PM_RPKT(0),	"eMAC rx packets" },
	{ NETC_PM_TOCT(0),	"eMAC tx octets" },
	{ NETC_PM_TVLAN(0),	"eMAC tx VLAN frames" },
	{ NETC_PM_TFCS(0),	"eMAC tx FCS errors" },
	{ NETC_PM_TUCA(0),	"eMAC tx unicast frames" },
	{ NETC_PM_TPKT(0),	"eMAC tx packets" },
	{ NETC_PM_TUND(0),	"eMAC tx undersized packets" },
	{ NETC_PM_TIOCT(0),	"eMAC tx invalid octets" },
};

static const struct netc_port_stat netc_pmac_counters[] = {
	{ NETC_PM_ROCT(1),	"pMAC rx octets" },
	{ NETC_PM_RVLAN(1),	"pMAC rx VLAN frames" },
	{ NETC_PM_RERR(1),	"pMAC rx frame errors" },
	{ NETC_PM_RUCA(1),	"pMAC rx unicast frames" },
	{ NETC_PM_RDRP(1),	"pMAC rx dropped packets" },
	{ NETC_PM_RPKT(1),	"pMAC rx packets" },
	{ NETC_PM_TOCT(1),	"pMAC tx octets" },
	{ NETC_PM_TVLAN(1),	"pMAC tx VLAN frames" },
	{ NETC_PM_TFCS(1),	"pMAC tx FCS errors" },
	{ NETC_PM_TUCA(1),	"pMAC tx unicast frames" },
	{ NETC_PM_TPKT(1),	"pMAC tx packets" },
	{ NETC_PM_TUND(1),	"pMAC tx undersized packets" },
	{ NETC_PM_TIOCT(1),	"pMAC tx invalid octets" },
};

static void netc_port_pause_stats(struct netc_port *np, int mac,
				  struct ethtool_pause_stats *stats)
{
	if (mac && !np->caps.pmac)
		return;

	stats->tx_pause_frames = netc_port_rd64(np, NETC_PM_TXPF(mac));
	stats->rx_pause_frames = netc_port_rd64(np, NETC_PM_RXPF(mac));
}

void netc_port_get_pause_stats(struct dsa_switch *ds, int port,
			       struct ethtool_pause_stats *pause_stats)
{
	struct netc_port *np = NETC_PORT(ds, port);
	struct net_device *ndev;

	switch (pause_stats->src) {
	case ETHTOOL_MAC_STATS_SRC_EMAC:
		netc_port_pause_stats(np, 0, pause_stats);
		break;
	case ETHTOOL_MAC_STATS_SRC_PMAC:
		netc_port_pause_stats(np, 1, pause_stats);
		break;
	case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
		ndev = dsa_to_port(ds, port)->user;

Annotation

Implementation Notes