drivers/net/ethernet/marvell/mvmdio.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/marvell/mvmdio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/marvell/mvmdio.c- Extension
.c- Size
- 11924 bytes
- Lines
- 461
- 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.
- 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/acpi.hlinux/acpi_mdio.hlinux/clk.hlinux/delay.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/of_mdio.hlinux/phy.hlinux/platform_device.hlinux/sched.hlinux/wait.h
Detected Declarations
struct orion_mdio_devstruct orion_mdio_opsenum orion_mdio_bus_typefunction orion_mdio_wait_readyfunction orion_mdio_smi_is_donefunction orion_mdio_smi_readfunction orion_mdio_smi_writefunction orion_mdio_xsmi_is_donefunction orion_mdio_xsmi_read_c45function orion_mdio_xsmi_write_c45function orion_mdio_xsmi_set_mdc_freqfunction orion_mdio_err_irqfunction orion_mdio_probefunction resource_sizefunction orion_mdio_remove
Annotated Snippet
struct orion_mdio_dev {
void __iomem *regs;
struct clk *clk[4];
/*
* If we have access to the error interrupt pin (which is
* somewhat misnamed as it not only reflects internal errors
* but also reflects SMI completion), use that to wait for
* SMI access completion instead of polling the SMI busy bit.
*/
int err_interrupt;
wait_queue_head_t smi_busy_wait;
};
enum orion_mdio_bus_type {
BUS_TYPE_SMI,
BUS_TYPE_XSMI
};
struct orion_mdio_ops {
int (*is_done)(struct orion_mdio_dev *);
};
/* Wait for the SMI unit to be ready for another operation
*/
static int orion_mdio_wait_ready(const struct orion_mdio_ops *ops,
struct mii_bus *bus)
{
struct orion_mdio_dev *dev = bus->priv;
unsigned long timeout;
int done;
if (dev->err_interrupt <= 0) {
if (!read_poll_timeout_atomic(ops->is_done, done, done, 2,
MVMDIO_SMI_TIMEOUT, false, dev))
return 0;
} else {
/* wait_event_timeout does not guarantee a delay of at
* least one whole jiffy, so timeout must be no less
* than two.
*/
timeout = max(usecs_to_jiffies(MVMDIO_SMI_TIMEOUT), 2);
if (wait_event_timeout(dev->smi_busy_wait,
ops->is_done(dev), timeout))
return 0;
}
dev_err(bus->parent, "Timeout: SMI busy for too long\n");
return -ETIMEDOUT;
}
static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev)
{
return !(readl(dev->regs) & MVMDIO_SMI_BUSY);
}
static const struct orion_mdio_ops orion_mdio_smi_ops = {
.is_done = orion_mdio_smi_is_done,
};
static int orion_mdio_smi_read(struct mii_bus *bus, int mii_id,
int regnum)
{
struct orion_mdio_dev *dev = bus->priv;
u32 val;
int ret;
ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus);
if (ret < 0)
return ret;
writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) |
(regnum << MVMDIO_SMI_PHY_REG_SHIFT) |
MVMDIO_SMI_READ_OPERATION),
dev->regs);
ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus);
if (ret < 0)
return ret;
val = readl(dev->regs);
if (!(val & MVMDIO_SMI_READ_VALID)) {
dev_err(bus->parent, "SMI bus read not valid\n");
return -ENODEV;
}
return val & GENMASK(15, 0);
}
static int orion_mdio_smi_write(struct mii_bus *bus, int mii_id,
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/acpi_mdio.h`, `linux/clk.h`, `linux/delay.h`, `linux/interrupt.h`, `linux/io.h`, `linux/iopoll.h`, `linux/kernel.h`.
- Detected declarations: `struct orion_mdio_dev`, `struct orion_mdio_ops`, `enum orion_mdio_bus_type`, `function orion_mdio_wait_ready`, `function orion_mdio_smi_is_done`, `function orion_mdio_smi_read`, `function orion_mdio_smi_write`, `function orion_mdio_xsmi_is_done`, `function orion_mdio_xsmi_read_c45`, `function orion_mdio_xsmi_write_c45`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- 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.