drivers/net/phy/mdio_bus_provider.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/mdio_bus_provider.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/mdio_bus_provider.c- Extension
.c- Size
- 21463 bytes
- Lines
- 762
- 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.
- 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/delay.hlinux/device.hlinux/errno.hlinux/etherdevice.hlinux/ethtool.hlinux/gpio/consumer.hlinux/init.hlinux/io.hlinux/kernel.hlinux/micrel_phy.hlinux/mii.hlinux/mm.hlinux/netdevice.hlinux/of_device.hlinux/of_mdio.hlinux/phy.hlinux/slab.hlinux/string.hlinux/uaccess.hlinux/unistd.hphylib-internal.h
Detected Declarations
struct mdio_bus_stat_attrfunction Copyrightfunction mdio_bus_get_statfunction mdio_bus_stat_field_showfunction mdio_bus_device_stat_field_showfunction mdio_bus_matchfunction mdio_ueventfunction of_mdiobus_find_phyfunction for_each_available_child_of_nodefunction of_mdiobus_link_mdiodevfunction mdiobus_scan_bus_c22function mdiobus_scan_bus_c45function mdiobus_prevent_c45_scanfunction mdiobus_for_each_phyfunction mdiobus_registerfunction mdiobus_unregisterfunction mdiobus_freefunction of_mdiobus_registerexport mdiobus_alloc_sizeexport mdiobus_scan_c22export __mdiobus_registerexport mdiobus_unregisterexport mdiobus_freeexport mdio_find_busexport of_mdio_find_bus
Annotated Snippet
static int mdio_bus_match(struct device *dev, const struct device_driver *drv)
{
const struct mdio_driver *mdiodrv = to_mdio_driver(drv);
struct mdio_device *mdio = to_mdio_device(dev);
/* Both the driver and device must type-match */
if (!(mdiodrv->mdiodrv.flags & MDIO_DEVICE_IS_PHY) !=
!(mdio->flags & MDIO_DEVICE_FLAG_PHY))
return 0;
if (of_driver_match_device(dev, drv))
return 1;
if (mdio->bus_match)
return mdio->bus_match(dev, drv);
return 0;
}
static int mdio_uevent(const struct device *dev, struct kobj_uevent_env *env)
{
int rc;
/* Some devices have extra OF data and an OF-style MODALIAS */
rc = of_device_uevent_modalias(dev, env);
if (rc != -ENODEV)
return rc;
return 0;
}
static const struct attribute *const mdio_bus_device_statistics_attrs[] = {
&dev_attr_mdio_bus_device_transfers.attr.attr,
&dev_attr_mdio_bus_device_errors.attr.attr,
&dev_attr_mdio_bus_device_writes.attr.attr,
&dev_attr_mdio_bus_device_reads.attr.attr,
NULL,
};
static const struct attribute_group mdio_bus_device_statistics_group = {
.name = "statistics",
.attrs_const = mdio_bus_device_statistics_attrs,
};
__ATTRIBUTE_GROUPS(mdio_bus_device_statistics);
const struct bus_type mdio_bus_type = {
.name = "mdio_bus",
.dev_groups = mdio_bus_device_statistics_groups,
.match = mdio_bus_match,
.uevent = mdio_uevent,
};
/**
* mdiobus_alloc_size - allocate a mii_bus structure
* @size: extra amount of memory to allocate for private storage.
* If non-zero, then bus->priv is points to that memory.
*
* Description: called by a bus driver to allocate an mii_bus
* structure to fill in.
*/
struct mii_bus *mdiobus_alloc_size(size_t size)
{
struct mii_bus *bus;
size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN);
size_t alloc_size;
int i;
/* If we alloc extra space, it should be aligned */
if (size)
alloc_size = aligned_size + size;
else
alloc_size = sizeof(*bus);
bus = kzalloc(alloc_size, GFP_KERNEL);
if (!bus)
return NULL;
bus->state = MDIOBUS_ALLOCATED;
if (size)
bus->priv = (void *)bus + aligned_size;
/* Initialise the interrupts to polling and 64-bit seqcounts */
for (i = 0; i < PHY_MAX_ADDR; i++) {
bus->irq[i] = PHY_POLL;
u64_stats_init(&bus->stats[i].syncp);
}
return bus;
}
EXPORT_SYMBOL(mdiobus_alloc_size);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/device.h`, `linux/errno.h`, `linux/etherdevice.h`, `linux/ethtool.h`, `linux/gpio/consumer.h`, `linux/init.h`, `linux/io.h`.
- Detected declarations: `struct mdio_bus_stat_attr`, `function Copyright`, `function mdio_bus_get_stat`, `function mdio_bus_stat_field_show`, `function mdio_bus_device_stat_field_show`, `function mdio_bus_match`, `function mdio_uevent`, `function of_mdiobus_find_phy`, `function for_each_available_child_of_node`, `function of_mdiobus_link_mdiodev`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern 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.