drivers/net/ethernet/mediatek/mtk_eth_soc.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mediatek/mtk_eth_soc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mediatek/mtk_eth_soc.c- Extension
.c- Size
- 144003 bytes
- Lines
- 5676
- 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.
- 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/of.hlinux/of_mdio.hlinux/of_net.hlinux/of_address.hlinux/mfd/syscon.hlinux/platform_device.hlinux/regmap.hlinux/clk.hlinux/pm_runtime.hlinux/if_vlan.hlinux/reset.hlinux/tcp.hlinux/interrupt.hlinux/pinctrl/devinfo.hlinux/phylink.hlinux/pcs/pcs-mtk-lynxi.hlinux/jhash.hlinux/bitfield.hnet/dsa.hnet/dst_metadata.hnet/page_pool/helpers.hlinux/genalloc.hmtk_eth_soc.hmtk_wed.h
Detected Declarations
struct mtk_poll_statefunction offsetoffunction mtk_w32function mtk_r32function mtk_m32function mtk_mdio_busy_waitfunction _mtk_mdio_write_c22function _mtk_mdio_write_c45function _mtk_mdio_read_c22function _mtk_mdio_read_c45function mtk_mdio_write_c22function mtk_mdio_write_c45function mtk_mdio_read_c22function mtk_mdio_read_c45function mt7621_gmac0_rgmii_adjustfunction mtk_gmac0_rgmii_adjustfunction mtk_setup_bridge_switchfunction mtk_mac_preparefunction mtk_mac_configfunction phy_interface_mode_is_8023zfunction mtk_mac_finishfunction mtk_mac_link_downfunction mtk_set_queue_speedfunction mtk_gdm_mac_link_upfunction mtk_xgdm_mac_link_upfunction mtk_mac_link_upfunction mtk_mac_disable_tx_lpifunction mtk_mac_enable_tx_lpifunction rt5350_mac_configfunction mtk_mdio_configfunction mtk_mdio_initfunction mtk_mdio_cleanupfunction mtk_tx_irq_disablefunction mtk_tx_irq_enablefunction mtk_rx_irq_disablefunction mtk_rx_irq_enablefunction mtk_set_mac_addressfunction mtk_stats_update_macfunction mtk_stats_updatefunction mtk_get_stats64function mtk_max_frag_sizefunction mtk_max_buf_sizefunction mtk_rx_get_descfunction mtk_dma_ring_freefunction mtk_init_fq_dmafunction txd_to_idxfunction mtk_tx_unmapfunction setup_tx_buf
Annotated Snippet
static const struct net_device_ops mtk_netdev_ops = {
.ndo_uninit = mtk_uninit,
.ndo_open = mtk_open,
.ndo_stop = mtk_stop,
.ndo_start_xmit = mtk_start_xmit,
.ndo_set_mac_address = mtk_set_mac_address,
.ndo_validate_addr = eth_validate_addr,
.ndo_eth_ioctl = mtk_do_ioctl,
.ndo_change_mtu = mtk_change_mtu,
.ndo_tx_timeout = mtk_tx_timeout,
.ndo_get_stats64 = mtk_get_stats64,
.ndo_fix_features = mtk_fix_features,
.ndo_set_features = mtk_set_features,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = mtk_poll_controller,
#endif
.ndo_setup_tc = mtk_eth_setup_tc,
.ndo_bpf = mtk_xdp,
.ndo_xdp_xmit = mtk_xdp_xmit,
.ndo_select_queue = mtk_select_queue,
};
static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
{
const struct phylink_mac_ops *mac_ops = &mtk_phylink_ops;
const __be32 *_id = of_get_property(np, "reg", NULL);
phy_interface_t phy_mode;
struct phylink *phylink;
struct mtk_mac *mac;
int id, err;
int txqs = 1;
u32 val;
if (!_id) {
dev_err(eth->dev, "missing mac id\n");
return -EINVAL;
}
id = be32_to_cpup(_id);
if (id >= MTK_MAX_DEVS) {
dev_err(eth->dev, "%d is not a valid mac id\n", id);
return -EINVAL;
}
if (eth->netdev[id]) {
dev_err(eth->dev, "duplicate mac id found: %d\n", id);
return -EINVAL;
}
if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
txqs = MTK_QDMA_NUM_QUEUES;
eth->netdev[id] = alloc_etherdev_mqs(sizeof(*mac), txqs, 1);
if (!eth->netdev[id]) {
dev_err(eth->dev, "alloc_etherdev failed\n");
return -ENOMEM;
}
mac = netdev_priv(eth->netdev[id]);
eth->mac[id] = mac;
mac->id = id;
mac->hw = eth;
mac->of_node = np;
err = of_get_ethdev_address(mac->of_node, eth->netdev[id]);
if (err == -EPROBE_DEFER)
return err;
if (err) {
/* If the mac address is invalid, use random mac address */
eth_hw_addr_random(eth->netdev[id]);
dev_err(eth->dev, "generated random MAC address %pM\n",
eth->netdev[id]->dev_addr);
}
memset(mac->hwlro_ip, 0, sizeof(mac->hwlro_ip));
mac->hwlro_ip_cnt = 0;
mac->hw_stats = devm_kzalloc(eth->dev,
sizeof(*mac->hw_stats),
GFP_KERNEL);
if (!mac->hw_stats) {
dev_err(eth->dev, "failed to allocate counter memory\n");
err = -ENOMEM;
goto free_netdev;
}
spin_lock_init(&mac->hw_stats->stats_lock);
u64_stats_init(&mac->hw_stats->syncp);
if (mtk_is_netsys_v3_or_greater(eth))
mac->hw_stats->reg_offset = id * 0x80;
Annotation
- Immediate include surface: `linux/of.h`, `linux/of_mdio.h`, `linux/of_net.h`, `linux/of_address.h`, `linux/mfd/syscon.h`, `linux/platform_device.h`, `linux/regmap.h`, `linux/clk.h`.
- Detected declarations: `struct mtk_poll_state`, `function offsetof`, `function mtk_w32`, `function mtk_r32`, `function mtk_m32`, `function mtk_mdio_busy_wait`, `function _mtk_mdio_write_c22`, `function _mtk_mdio_write_c45`, `function _mtk_mdio_read_c22`, `function _mtk_mdio_read_c45`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.