drivers/net/ethernet/spacemit/k1_emac.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/spacemit/k1_emac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/spacemit/k1_emac.c- Extension
.c- Size
- 51949 bytes
- Lines
- 2087
- 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/bitfield.hlinux/clk.hlinux/delay.hlinux/dma-mapping.hlinux/etherdevice.hlinux/ethtool.hlinux/if_vlan.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/kernel.hlinux/mfd/syscon.hlinux/module.hlinux/of.hlinux/of_irq.hlinux/of_mdio.hlinux/of_net.hlinux/phy.hlinux/platform_device.hlinux/pm_runtime.hlinux/pm.hlinux/regmap.hlinux/reset.hlinux/rtnetlink.hlinux/timer.hlinux/types.hk1_emac.h
Detected Declarations
struct desc_bufstruct emac_tx_desc_bufferstruct emac_rx_desc_bufferstruct emac_desc_ringstruct emac_privfunction emac_wrfunction emac_rdfunction emac_phy_interface_configfunction emac_set_mac_addr_regfunction emac_set_mac_addrfunction emac_reset_hwfunction emac_init_hwfunction emac_dma_start_transmitfunction emac_enable_interruptfunction emac_disable_interruptfunction emac_tx_availfunction emac_tx_coal_timer_reschedfunction emac_tx_coal_timerfunction emac_tx_should_interruptfunction emac_free_tx_buffunction emac_clean_tx_desc_ringfunction emac_clean_rx_desc_ringfunction emac_alloc_tx_resourcesfunction emac_alloc_rx_resourcesfunction emac_free_tx_resourcesfunction emac_free_rx_resourcesfunction emac_tx_clean_descfunction emac_rx_frame_goodfunction emac_alloc_rx_desc_buffersfunction emac_rx_clean_descfunction emac_rx_pollfunction emac_tx_map_fragfunction emac_tx_mem_mapfunction emac_start_xmitfunction emac_set_mac_addressfunction emac_mac_multicast_filter_clearfunction emac_ether_addr_hashfunction emac_set_rx_modefunction netdev_for_each_mc_addrfunction emac_change_mtufunction emac_tx_timeoutfunction emac_mii_readfunction emac_mii_writefunction emac_mdio_initfunction emac_read_stat_cntfunction emac_tx_read_stat_cntfunction emac_rx_read_stat_cntfunction emac_update_counter
Annotated Snippet
static const struct net_device_ops emac_netdev_ops = {
.ndo_open = emac_open,
.ndo_stop = emac_stop,
.ndo_start_xmit = emac_start_xmit,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = emac_set_mac_address,
.ndo_eth_ioctl = phy_do_ioctl_running,
.ndo_change_mtu = emac_change_mtu,
.ndo_tx_timeout = emac_tx_timeout,
.ndo_set_rx_mode = emac_set_rx_mode,
.ndo_get_stats64 = emac_get_stats64,
};
/* Currently we always use 15.6 ps/step for the delay line */
static u32 delay_ps_to_unit(u32 ps)
{
return DIV_ROUND_CLOSEST(ps * 10, 156);
}
static u32 delay_unit_to_ps(u32 unit)
{
return DIV_ROUND_CLOSEST(unit * 156, 10);
}
#define EMAC_MAX_DELAY_UNIT FIELD_MAX(EMAC_TX_DLINE_CODE_MASK)
/* Minus one just to be safe from rounding errors */
#define EMAC_MAX_DELAY_PS (delay_unit_to_ps(EMAC_MAX_DELAY_UNIT - 1))
static int emac_config_dt(struct platform_device *pdev, struct emac_priv *priv)
{
struct device_node *np = pdev->dev.of_node;
struct device *dev = &pdev->dev;
u8 mac_addr[ETH_ALEN] = { 0 };
int ret;
priv->iobase = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(priv->iobase))
return dev_err_probe(dev, PTR_ERR(priv->iobase),
"ioremap failed\n");
priv->regmap_apmu =
syscon_regmap_lookup_by_phandle_args(np, "spacemit,apmu", 1,
&priv->regmap_apmu_offset);
if (IS_ERR(priv->regmap_apmu))
return dev_err_probe(dev, PTR_ERR(priv->regmap_apmu),
"failed to get syscon\n");
priv->irq = platform_get_irq(pdev, 0);
if (priv->irq < 0)
return priv->irq;
ret = of_get_mac_address(np, mac_addr);
if (ret) {
if (ret == -EPROBE_DEFER)
return dev_err_probe(dev, ret,
"Can't get MAC address\n");
dev_info(&pdev->dev, "Using random MAC address\n");
eth_hw_addr_random(priv->ndev);
} else {
eth_hw_addr_set(priv->ndev, mac_addr);
}
priv->tx_delay = 0;
priv->rx_delay = 0;
of_property_read_u32(np, "tx-internal-delay-ps", &priv->tx_delay);
of_property_read_u32(np, "rx-internal-delay-ps", &priv->rx_delay);
if (priv->tx_delay > EMAC_MAX_DELAY_PS) {
dev_err(&pdev->dev,
"tx-internal-delay-ps too large: max %d, got %d",
EMAC_MAX_DELAY_PS, priv->tx_delay);
return -EINVAL;
}
if (priv->rx_delay > EMAC_MAX_DELAY_PS) {
dev_err(&pdev->dev,
"rx-internal-delay-ps too large: max %d, got %d",
EMAC_MAX_DELAY_PS, priv->rx_delay);
return -EINVAL;
}
priv->tx_delay = delay_ps_to_unit(priv->tx_delay);
priv->rx_delay = delay_ps_to_unit(priv->rx_delay);
return 0;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/delay.h`, `linux/dma-mapping.h`, `linux/etherdevice.h`, `linux/ethtool.h`, `linux/if_vlan.h`, `linux/interrupt.h`.
- Detected declarations: `struct desc_buf`, `struct emac_tx_desc_buffer`, `struct emac_rx_desc_buffer`, `struct emac_desc_ring`, `struct emac_priv`, `function emac_wr`, `function emac_rd`, `function emac_phy_interface_config`, `function emac_set_mac_addr_reg`, `function emac_set_mac_addr`.
- 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.