drivers/net/ethernet/moxa/moxart_ether.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/moxa/moxart_ether.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/moxa/moxart_ether.c- Extension
.c- Size
- 15437 bytes
- Lines
- 590
- 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/module.hlinux/netdevice.hlinux/etherdevice.hlinux/skbuff.hlinux/dma-mapping.hlinux/ethtool.hlinux/platform_device.hlinux/interrupt.hlinux/irq.hlinux/of_address.hlinux/of_irq.hlinux/crc32.hlinux/crc32c.hlinux/circ_buf.hmoxart_ether.h
Detected Declarations
function Copyrightfunction moxart_desc_readfunction moxart_emac_writefunction moxart_update_mac_addressfunction moxart_set_mac_addressfunction moxart_mac_free_memoryfunction moxart_mac_resetfunction moxart_mac_enablefunction moxart_mac_setup_desc_ringfunction moxart_mac_openfunction moxart_mac_stopfunction moxart_rx_pollfunction moxart_tx_queue_spacefunction moxart_tx_finishedfunction moxart_mac_interruptfunction moxart_mac_start_xmitfunction moxart_mac_setmulticastfunction netdev_for_each_mc_addrfunction moxart_mac_set_rx_modefunction moxart_mac_probefunction moxart_remove
Annotated Snippet
static const struct net_device_ops moxart_netdev_ops = {
.ndo_open = moxart_mac_open,
.ndo_stop = moxart_mac_stop,
.ndo_start_xmit = moxart_mac_start_xmit,
.ndo_set_rx_mode = moxart_mac_set_rx_mode,
.ndo_set_mac_address = moxart_set_mac_address,
.ndo_validate_addr = eth_validate_addr,
};
static int moxart_mac_probe(struct platform_device *pdev)
{
struct device *p_dev = &pdev->dev;
struct device_node *node = p_dev->of_node;
struct net_device *ndev;
struct moxart_mac_priv_t *priv;
struct resource *res;
unsigned int irq;
int ret;
ndev = alloc_etherdev(sizeof(struct moxart_mac_priv_t));
if (!ndev)
return -ENOMEM;
irq = irq_of_parse_and_map(node, 0);
if (irq <= 0) {
netdev_err(ndev, "irq_of_parse_and_map failed\n");
ret = -EINVAL;
goto irq_map_fail;
}
priv = netdev_priv(ndev);
priv->ndev = ndev;
priv->pdev = pdev;
priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(priv->base)) {
ret = PTR_ERR(priv->base);
goto init_fail;
}
ndev->base_addr = res->start;
ret = platform_get_ethdev_address(p_dev, ndev);
if (ret == -EPROBE_DEFER)
goto init_fail;
if (ret)
eth_hw_addr_random(ndev);
moxart_update_mac_address(ndev);
spin_lock_init(&priv->txlock);
priv->tx_buf_size = TX_BUF_SIZE;
priv->rx_buf_size = RX_BUF_SIZE;
priv->tx_desc_base = dma_alloc_coherent(p_dev, TX_REG_DESC_SIZE *
TX_DESC_NUM, &priv->tx_base,
GFP_DMA | GFP_KERNEL);
if (!priv->tx_desc_base) {
ret = -ENOMEM;
goto init_fail;
}
priv->rx_desc_base = dma_alloc_coherent(p_dev, RX_REG_DESC_SIZE *
RX_DESC_NUM, &priv->rx_base,
GFP_DMA | GFP_KERNEL);
if (!priv->rx_desc_base) {
ret = -ENOMEM;
goto init_fail;
}
priv->tx_buf_base = kmalloc_array(priv->tx_buf_size, TX_DESC_NUM,
GFP_KERNEL);
if (!priv->tx_buf_base) {
ret = -ENOMEM;
goto init_fail;
}
priv->rx_buf_base = kmalloc_array(priv->rx_buf_size, RX_DESC_NUM,
GFP_KERNEL);
if (!priv->rx_buf_base) {
ret = -ENOMEM;
goto init_fail;
}
platform_set_drvdata(pdev, ndev);
ret = devm_request_irq(p_dev, irq, moxart_mac_interrupt, 0,
pdev->name, ndev);
if (ret) {
netdev_err(ndev, "devm_request_irq failed\n");
goto init_fail;
Annotation
- Immediate include surface: `linux/module.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/skbuff.h`, `linux/dma-mapping.h`, `linux/ethtool.h`, `linux/platform_device.h`, `linux/interrupt.h`.
- Detected declarations: `function Copyright`, `function moxart_desc_read`, `function moxart_emac_write`, `function moxart_update_mac_address`, `function moxart_set_mac_address`, `function moxart_mac_free_memory`, `function moxart_mac_reset`, `function moxart_mac_enable`, `function moxart_mac_setup_desc_ring`, `function moxart_mac_open`.
- 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.