drivers/net/ethernet/airoha/airoha_eth.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/airoha/airoha_eth.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/airoha/airoha_eth.c
Extension
.c
Size
101394 bytes
Lines
3716
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct net_device_ops airoha_netdev_ops = {
	.ndo_init		= airoha_dev_init,
	.ndo_open		= airoha_dev_open,
	.ndo_stop		= airoha_dev_stop,
	.ndo_change_mtu		= airoha_dev_change_mtu,
	.ndo_select_queue	= airoha_dev_select_queue,
	.ndo_start_xmit		= airoha_dev_xmit,
	.ndo_get_stats64        = airoha_dev_get_stats64,
	.ndo_set_mac_address	= airoha_dev_set_macaddr,
	.ndo_setup_tc		= airoha_dev_tc_setup,
};

static const struct ethtool_ops airoha_ethtool_ops = {
	.get_drvinfo		= airoha_ethtool_get_drvinfo,
	.get_eth_mac_stats      = airoha_ethtool_get_mac_stats,
	.get_rmon_stats		= airoha_ethtool_get_rmon_stats,
	.get_link_ksettings	= phy_ethtool_get_link_ksettings,
	.get_link		= ethtool_op_get_link,
};

static int airoha_metadata_dst_alloc(struct airoha_gdm_port *port)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(port->dsa_meta); i++) {
		struct metadata_dst *md_dst;

		md_dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
					    GFP_KERNEL);
		if (!md_dst)
			return -ENOMEM;

		md_dst->u.port_info.port_id = i;
		port->dsa_meta[i] = md_dst;
	}

	return 0;
}

static void airoha_metadata_dst_free(struct airoha_gdm_port *port)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(port->dsa_meta); i++) {
		if (!port->dsa_meta[i])
			continue;

		dst_release(&port->dsa_meta[i]->dst);
	}
}

bool airoha_is_valid_gdm_dev(struct airoha_eth *eth,
			     struct airoha_gdm_dev *dev)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
		struct airoha_gdm_port *port = eth->ports[i];
		int j;

		if (!port)
			continue;

		for (j = 0; j < ARRAY_SIZE(port->devs); j++) {
			if (port->devs[j] == dev)
				return true;
		}
	}

	return false;
}

static int airoha_alloc_gdm_device(struct airoha_eth *eth,
				   struct airoha_gdm_port *port,
				   int nbq, struct device_node *np)
{
	struct net_device *netdev;
	struct airoha_gdm_dev *dev;
	u8 index;
	int err;

	netdev = devm_alloc_etherdev_mqs(eth->dev, sizeof(*dev),
					 AIROHA_NUM_NETDEV_TX_RINGS,
					 AIROHA_NUM_RX_RING);
	if (!netdev) {
		dev_err(eth->dev, "alloc_etherdev failed\n");
		return -ENOMEM;
	}

	netdev->netdev_ops = &airoha_netdev_ops;

Annotation

Implementation Notes