drivers/net/mdio/mdio-mux.c
Source file repositories/reference/linux-study-clean/drivers/net/mdio/mdio-mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mdio/mdio-mux.c- Extension
.c- Size
- 6191 bytes
- Lines
- 271
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/device.hlinux/mdio-mux.hlinux/module.hlinux/of_mdio.hlinux/phy.hlinux/platform_device.h
Detected Declarations
struct mdio_mux_child_busstruct mdio_mux_parent_busstruct mdio_mux_child_busfunction mdio_mux_readfunction mdio_mux_read_c45function mdio_mux_writefunction mdio_mux_write_c45function mdio_mux_uninit_childrenfunction mdio_mux_initfunction mdio_mux_uninitexport mdio_mux_initexport mdio_mux_uninit
Annotated Snippet
struct mdio_mux_parent_bus {
struct mii_bus *mii_bus;
int current_child;
int parent_id;
void *switch_data;
int (*switch_fn)(int current_child, int desired_child, void *data);
/* List of our children linked through their next fields. */
struct mdio_mux_child_bus *children;
};
struct mdio_mux_child_bus {
struct mii_bus *mii_bus;
struct mdio_mux_parent_bus *parent;
struct mdio_mux_child_bus *next;
int bus_number;
};
/*
* The parent bus' lock is used to order access to the switch_fn.
*/
static int mdio_mux_read(struct mii_bus *bus, int phy_id, int regnum)
{
struct mdio_mux_child_bus *cb = bus->priv;
struct mdio_mux_parent_bus *pb = cb->parent;
int r;
mutex_lock_nested(&pb->mii_bus->mdio_lock, MDIO_MUTEX_MUX);
r = pb->switch_fn(pb->current_child, cb->bus_number, pb->switch_data);
if (r)
goto out;
pb->current_child = cb->bus_number;
r = pb->mii_bus->read(pb->mii_bus, phy_id, regnum);
out:
mutex_unlock(&pb->mii_bus->mdio_lock);
return r;
}
static int mdio_mux_read_c45(struct mii_bus *bus, int phy_id, int dev_addr,
int regnum)
{
struct mdio_mux_child_bus *cb = bus->priv;
struct mdio_mux_parent_bus *pb = cb->parent;
int r;
mutex_lock_nested(&pb->mii_bus->mdio_lock, MDIO_MUTEX_MUX);
r = pb->switch_fn(pb->current_child, cb->bus_number, pb->switch_data);
if (r)
goto out;
pb->current_child = cb->bus_number;
r = pb->mii_bus->read_c45(pb->mii_bus, phy_id, dev_addr, regnum);
out:
mutex_unlock(&pb->mii_bus->mdio_lock);
return r;
}
/*
* The parent bus' lock is used to order access to the switch_fn.
*/
static int mdio_mux_write(struct mii_bus *bus, int phy_id,
int regnum, u16 val)
{
struct mdio_mux_child_bus *cb = bus->priv;
struct mdio_mux_parent_bus *pb = cb->parent;
int r;
mutex_lock_nested(&pb->mii_bus->mdio_lock, MDIO_MUTEX_MUX);
r = pb->switch_fn(pb->current_child, cb->bus_number, pb->switch_data);
if (r)
goto out;
pb->current_child = cb->bus_number;
r = pb->mii_bus->write(pb->mii_bus, phy_id, regnum, val);
out:
mutex_unlock(&pb->mii_bus->mdio_lock);
return r;
}
static int mdio_mux_write_c45(struct mii_bus *bus, int phy_id, int dev_addr,
int regnum, u16 val)
{
Annotation
- Immediate include surface: `linux/device.h`, `linux/mdio-mux.h`, `linux/module.h`, `linux/of_mdio.h`, `linux/phy.h`, `linux/platform_device.h`.
- Detected declarations: `struct mdio_mux_child_bus`, `struct mdio_mux_parent_bus`, `struct mdio_mux_child_bus`, `function mdio_mux_read`, `function mdio_mux_read_c45`, `function mdio_mux_write`, `function mdio_mux_write_c45`, `function mdio_mux_uninit_children`, `function mdio_mux_init`, `function mdio_mux_uninit`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.