drivers/net/ethernet/mediatek/mtk_star_emac.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mediatek/mtk_star_emac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mediatek/mtk_star_emac.c- Extension
.c- Size
- 47481 bytes
- Lines
- 1762
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/clk.hlinux/compiler.hlinux/dma-mapping.hlinux/etherdevice.hlinux/kernel.hlinux/mfd/syscon.hlinux/mii.hlinux/module.hlinux/netdevice.hlinux/of.hlinux/of_mdio.hlinux/of_net.hlinux/platform_device.hlinux/pm.hlinux/regmap.hlinux/skbuff.hlinux/spinlock.h
Detected Declarations
struct mtk_star_ring_descstruct mtk_star_ring_desc_datastruct mtk_star_ringstruct mtk_star_compatstruct mtk_star_privfunction mtk_star_ring_initfunction mtk_star_ring_pop_tailfunction mtk_star_ring_push_headfunction mtk_star_ring_push_head_rxfunction mtk_star_ring_push_head_txfunction mtk_star_tx_ring_availfunction mtk_star_dma_map_rxfunction mtk_star_dma_unmap_rxfunction mtk_star_dma_map_txfunction mtk_star_dma_unmap_txfunction mtk_star_nic_disable_pdfunction mtk_star_enable_dma_irqfunction mtk_star_disable_dma_irqfunction mtk_star_intr_enablefunction mtk_star_intr_disablefunction mtk_star_intr_ack_allfunction mtk_star_dma_initfunction mtk_star_dma_startfunction mtk_star_dma_stopfunction mtk_star_dma_disablefunction mtk_star_dma_resume_rxfunction mtk_star_dma_resume_txfunction mtk_star_set_mac_addrfunction mtk_star_reset_countersfunction mtk_star_update_statfunction mtk_star_update_statsfunction mtk_star_prepare_rx_skbsfunction mtk_star_ring_free_skbsfunction mtk_star_free_rx_skbsfunction mtk_star_free_tx_skbsfunction mtk_star_handle_irqfunction mtk_star_hash_wait_cmd_startfunction mtk_star_hash_wait_okfunction mtk_star_set_hashbitfunction mtk_star_reset_hash_tablefunction mtk_star_phy_configfunction mtk_star_adjust_linkfunction mtk_star_init_configfunction mtk_star_enablefunction mtk_star_disablefunction mtk_star_netdev_openfunction mtk_star_netdev_stopfunction mtk_star_netdev_ioctl
Annotated Snippet
static const struct net_device_ops mtk_star_netdev_ops = {
.ndo_open = mtk_star_netdev_open,
.ndo_stop = mtk_star_netdev_stop,
.ndo_start_xmit = mtk_star_netdev_start_xmit,
.ndo_get_stats64 = mtk_star_netdev_get_stats64,
.ndo_set_rx_mode = mtk_star_set_rx_mode,
.ndo_eth_ioctl = mtk_star_netdev_ioctl,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
};
static void mtk_star_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{
strscpy(info->driver, MTK_STAR_DRVNAME, sizeof(info->driver));
}
/* TODO Add ethtool stats. */
static const struct ethtool_ops mtk_star_ethtool_ops = {
.get_drvinfo = mtk_star_get_drvinfo,
.get_link = ethtool_op_get_link,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
};
static int mtk_star_rx(struct mtk_star_priv *priv, int budget)
{
struct mtk_star_ring *ring = &priv->rx_ring;
struct device *dev = mtk_star_get_dev(priv);
struct mtk_star_ring_desc_data desc_data;
struct net_device *ndev = priv->ndev;
struct sk_buff *curr_skb, *new_skb;
dma_addr_t new_dma_addr;
int ret, count = 0;
while (count < budget) {
ret = mtk_star_ring_pop_tail(ring, &desc_data);
if (ret)
return -1;
curr_skb = desc_data.skb;
if ((desc_data.flags & MTK_STAR_DESC_BIT_RX_CRCE) ||
(desc_data.flags & MTK_STAR_DESC_BIT_RX_OSIZE)) {
/* Error packet -> drop and reuse skb. */
new_skb = curr_skb;
goto push_new_skb;
}
/* Prepare new skb before receiving the current one.
* Reuse the current skb if we fail at any point.
*/
new_skb = mtk_star_alloc_skb(ndev);
if (!new_skb) {
ndev->stats.rx_dropped++;
new_skb = curr_skb;
goto push_new_skb;
}
new_dma_addr = mtk_star_dma_map_rx(priv, new_skb);
if (dma_mapping_error(dev, new_dma_addr)) {
ndev->stats.rx_dropped++;
dev_kfree_skb(new_skb);
new_skb = curr_skb;
netdev_err(ndev, "DMA mapping error of RX descriptor\n");
goto push_new_skb;
}
/* We can't fail anymore at this point:
* it's safe to unmap the skb.
*/
mtk_star_dma_unmap_rx(priv, &desc_data);
skb_put(desc_data.skb, desc_data.len);
desc_data.skb->ip_summed = CHECKSUM_NONE;
desc_data.skb->protocol = eth_type_trans(desc_data.skb, ndev);
desc_data.skb->dev = ndev;
netif_receive_skb(desc_data.skb);
/* update dma_addr for new skb */
desc_data.dma_addr = new_dma_addr;
push_new_skb:
count++;
desc_data.len = skb_tailroom(new_skb);
desc_data.skb = new_skb;
mtk_star_ring_push_head_rx(ring, &desc_data);
}
Annotation
- Immediate include surface: `linux/bits.h`, `linux/clk.h`, `linux/compiler.h`, `linux/dma-mapping.h`, `linux/etherdevice.h`, `linux/kernel.h`, `linux/mfd/syscon.h`, `linux/mii.h`.
- Detected declarations: `struct mtk_star_ring_desc`, `struct mtk_star_ring_desc_data`, `struct mtk_star_ring`, `struct mtk_star_compat`, `struct mtk_star_priv`, `function mtk_star_ring_init`, `function mtk_star_ring_pop_tail`, `function mtk_star_ring_push_head`, `function mtk_star_ring_push_head_rx`, `function mtk_star_ring_push_head_tx`.
- 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.