drivers/net/ethernet/cadence/macb_main.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/cadence/macb_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/cadence/macb_main.c- Extension
.c- Size
- 167626 bytes
- Lines
- 6238
- 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/circ_buf.hlinux/clk-provider.hlinux/clk.hlinux/crc32.hlinux/delay.hlinux/dma-mapping.hlinux/etherdevice.hlinux/firmware/xlnx-zynqmp.hlinux/inetdevice.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/ip.hlinux/kernel.hlinux/module.hlinux/moduleparam.hlinux/netdevice.hlinux/of.hlinux/of_mdio.hlinux/of_net.hlinux/phy/phy.hlinux/phylink.hlinux/platform_device.hlinux/pm_runtime.hlinux/ptp_classify.hlinux/reset.hlinux/slab.hlinux/tcp.hlinux/types.hlinux/udp.hlinux/gcd.h
Detected Declarations
struct sifive_fu540_macb_mgmtfunction MACB_BITfunction macb_adj_dma_desc_idxfunction macb_tx_ring_wrapfunction macb_tx_dmafunction macb_rx_ring_wrapfunction hw_readl_nativefunction hw_writel_nativefunction hw_readlfunction hw_writelfunction hw_is_native_iofunction hw_is_gemfunction macb_set_hwaddrfunction macb_get_hwaddrfunction macb_mdio_wait_for_idlefunction macb_mdio_read_c22function macb_mdio_read_c45function macb_mdio_write_c22function macb_mdio_write_c45function macb_init_buffersfunction macb_set_tx_clkfunction macb_usx_pcs_link_upfunction macb_usx_pcs_get_statefunction macb_usx_pcs_configfunction macb_pcs_inband_capsfunction macb_pcs_get_statefunction macb_pcs_an_restartfunction macb_tx_lpi_setfunction macb_tx_all_queues_idlefunction macb_tx_lpi_work_fnfunction macb_tx_lpi_schedulefunction macb_tx_lpi_wakefunction macb_mac_disable_tx_lpifunction macb_mac_enable_tx_lpifunction macb_mac_configfunction macb_mac_link_downfunction gem_shuffle_tx_one_ringfunction gem_shuffle_tx_ringsfunction macb_mac_link_upfunction macb_phy_handle_existsfunction macb_phylink_connectfunction macb_get_pcs_fixed_statefunction macb_mii_probefunction macb_mdiobus_registerfunction macb_mii_initfunction macb_update_statsfunction macb_halt_txfunction macb_tx_unmap
Annotated Snippet
static const struct net_device_ops macb_netdev_ops = {
.ndo_open = macb_open,
.ndo_stop = macb_close,
.ndo_start_xmit = macb_start_xmit,
.ndo_set_rx_mode = macb_set_rx_mode,
.ndo_get_stats64 = macb_get_stats,
.ndo_eth_ioctl = macb_ioctl,
.ndo_validate_addr = eth_validate_addr,
.ndo_change_mtu = macb_change_mtu,
.ndo_set_mac_address = macb_set_mac_addr,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = macb_poll_controller,
#endif
.ndo_set_features = macb_set_features,
.ndo_features_check = macb_features_check,
.ndo_hwtstamp_set = macb_hwtstamp_set,
.ndo_hwtstamp_get = macb_hwtstamp_get,
.ndo_setup_tc = macb_setup_tc,
};
/* Configure peripheral capabilities according to device tree
* and integration options used
*/
static void macb_configure_caps(struct macb *bp,
const struct macb_config *dt_conf)
{
u32 dcfg;
bp->caps = dt_conf->caps;
if (!dt_conf->usrio)
bp->caps |= MACB_CAPS_USRIO_DISABLED;
if (hw_is_gem(bp->regs, bp->native_io)) {
bp->caps |= MACB_CAPS_MACB_IS_GEM;
dcfg = gem_readl(bp, DCFG1);
if (GEM_BFEXT(IRQCOR, dcfg) == 0)
bp->caps |= MACB_CAPS_ISR_CLEAR_ON_WRITE;
if (GEM_BFEXT(NO_PCS, dcfg) == 0)
bp->caps |= MACB_CAPS_PCS;
if (!(dcfg & GEM_BIT(USERIO)))
bp->caps |= MACB_CAPS_USRIO_DISABLED;
dcfg = gem_readl(bp, DCFG12);
if (GEM_BFEXT(HIGH_SPEED, dcfg) == 1)
bp->caps |= MACB_CAPS_HIGH_SPEED;
dcfg = gem_readl(bp, DCFG2);
if ((dcfg & (GEM_BIT(RX_PKT_BUFF) | GEM_BIT(TX_PKT_BUFF))) == 0)
bp->caps |= MACB_CAPS_FIFO_MODE;
if (GEM_BFEXT(PBUF_RSC, gem_readl(bp, DCFG6)))
bp->caps |= MACB_CAPS_RSC;
if (gem_has_ptp(bp)) {
if (!GEM_BFEXT(TSU, gem_readl(bp, DCFG5)))
dev_err(&bp->pdev->dev,
"GEM doesn't support hardware ptp.\n");
else {
#ifdef CONFIG_MACB_USE_HWSTAMP
bp->caps |= MACB_CAPS_DMA_PTP;
bp->ptp_info = &gem_ptp_info;
#endif
}
}
}
dev_dbg(&bp->pdev->dev, "Cadence caps 0x%08x\n", bp->caps);
}
static int macb_probe_queues(struct device *dev, void __iomem *mem, bool native_io)
{
/* BIT(0) is never set but queue 0 always exists. */
unsigned int queue_mask = 0x1;
/* Use hw_is_gem() as MACB_CAPS_MACB_IS_GEM is not yet positioned. */
if (hw_is_gem(mem, native_io)) {
if (native_io)
queue_mask |= __raw_readl(mem + GEM_DCFG6) & 0xFF;
else
queue_mask |= readl_relaxed(mem + GEM_DCFG6) & 0xFF;
if (fls(queue_mask) != ffz(queue_mask)) {
dev_err(dev, "queue mask %#x has a hole\n", queue_mask);
return -EINVAL;
}
}
return hweight32(queue_mask);
}
static void macb_clks_disable(struct clk *pclk, struct clk *hclk, struct clk *tx_clk,
struct clk *rx_clk, struct clk *tsu_clk)
Annotation
- Immediate include surface: `linux/circ_buf.h`, `linux/clk-provider.h`, `linux/clk.h`, `linux/crc32.h`, `linux/delay.h`, `linux/dma-mapping.h`, `linux/etherdevice.h`, `linux/firmware/xlnx-zynqmp.h`.
- Detected declarations: `struct sifive_fu540_macb_mgmt`, `function MACB_BIT`, `function macb_adj_dma_desc_idx`, `function macb_tx_ring_wrap`, `function macb_tx_dma`, `function macb_rx_ring_wrap`, `function hw_readl_native`, `function hw_writel_native`, `function hw_readl`, `function hw_writel`.
- 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.