drivers/net/mdio/mdio-bcm-unimac.c
Source file repositories/reference/linux-study-clean/drivers/net/mdio/mdio-bcm-unimac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mdio/mdio-bcm-unimac.c- Extension
.c- Size
- 9284 bytes
- Lines
- 367
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/clk.hlinux/delay.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of.hlinux/of_mdio.hlinux/of_platform.hlinux/phy.hlinux/platform_data/mdio-bcm-unimac.hlinux/platform_device.hlinux/sched.h
Detected Declarations
struct unimac_mdio_privfunction unimac_mdio_readlfunction unimac_mdio_writelfunction unimac_mdio_startfunction unimac_mdio_pollfunction unimac_mdio_readfunction unimac_mdio_writefunction phy_get_devicefunction for_each_available_child_of_nodefunction unimac_mdio_clk_setfunction unimac_mdio_probefunction unimac_mdio_removefunction unimac_mdio_resume
Annotated Snippet
struct unimac_mdio_priv {
struct mii_bus *mii_bus;
void __iomem *base;
int (*wait_func) (void *wait_func_data);
void *wait_func_data;
struct clk *clk;
u32 clk_freq;
};
static inline u32 unimac_mdio_readl(struct unimac_mdio_priv *priv, u32 offset)
{
/* MIPS chips strapped for BE will automagically configure the
* peripheral registers for CPU-native byte order.
*/
if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
return __raw_readl(priv->base + offset);
else
return readl_relaxed(priv->base + offset);
}
static inline void unimac_mdio_writel(struct unimac_mdio_priv *priv, u32 val,
u32 offset)
{
if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
__raw_writel(val, priv->base + offset);
else
writel_relaxed(val, priv->base + offset);
}
static inline void unimac_mdio_start(struct unimac_mdio_priv *priv)
{
u32 reg;
reg = unimac_mdio_readl(priv, MDIO_CMD);
reg |= MDIO_START_BUSY;
unimac_mdio_writel(priv, reg, MDIO_CMD);
}
static int unimac_mdio_poll(void *wait_func_data)
{
struct unimac_mdio_priv *priv = wait_func_data;
u32 val;
/*
* C22 transactions should take ~25 usec, will need to adjust
* if C45 support is added.
*/
udelay(30);
return read_poll_timeout(unimac_mdio_readl, val, !(val & MDIO_START_BUSY),
2000, 100000, false, priv, MDIO_CMD);
}
static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)
{
struct unimac_mdio_priv *priv = bus->priv;
int ret;
u32 cmd;
ret = clk_prepare_enable(priv->clk);
if (ret)
return ret;
/* Prepare the read operation */
cmd = MDIO_RD | (phy_id << MDIO_PMD_SHIFT) | (reg << MDIO_REG_SHIFT);
unimac_mdio_writel(priv, cmd, MDIO_CMD);
/* Start MDIO transaction */
unimac_mdio_start(priv);
ret = priv->wait_func(priv->wait_func_data);
if (ret)
goto out;
cmd = unimac_mdio_readl(priv, MDIO_CMD);
/* Some broken devices are known not to release the line during
* turn-around, e.g: Broadcom BCM53125 external switches, so check for
* that condition here and ignore the MDIO controller read failure
* indication.
*/
if (!(bus->phy_ignore_ta_mask & 1 << phy_id) && (cmd & MDIO_READ_FAIL)) {
ret = -EIO;
goto out;
}
ret = cmd & 0xffff;
out:
clk_disable_unprepare(priv->clk);
return ret;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/of_mdio.h`, `linux/of_platform.h`.
- Detected declarations: `struct unimac_mdio_priv`, `function unimac_mdio_readl`, `function unimac_mdio_writel`, `function unimac_mdio_start`, `function unimac_mdio_poll`, `function unimac_mdio_read`, `function unimac_mdio_write`, `function phy_get_device`, `function for_each_available_child_of_node`, `function unimac_mdio_clk_set`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
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.