drivers/net/phy/mdio_bus.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/mdio_bus.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/mdio_bus.c- Extension
.c- Size
- 16321 bytes
- Lines
- 628
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/errno.hlinux/ethtool.hlinux/init.hlinux/io.hlinux/kernel.hlinux/mii.hlinux/mm.hlinux/module.hlinux/phy.hlinux/slab.hlinux/spinlock.hlinux/string.hlinux/uaccess.hlinux/unistd.htrace/events/mdio.h
Detected Declarations
function Copyrightfunction mdiobus_is_registered_devicefunction mdiobus_stats_acctfunction __mdiobus_readfunction __mdiobus_writefunction __mdiobus_modify_changedfunction __mdiobus_c45_readfunction __mdiobus_c45_writefunction __mdiobus_c45_modify_changedfunction mutex_lock_nestedfunction mdiobus_readfunction mdiobus_c45_readfunction mutex_lock_nestedfunction mutex_lock_nestedfunction mdiobus_writefunction mdiobus_c45_writefunction mutex_lock_nestedfunction __mdiobus_modifyfunction mdiobus_modifyfunction mdiobus_c45_modifyfunction mdiobus_modify_changedfunction mdiobus_c45_modify_changedexport mdiobus_get_phyexport mdiobus_is_registered_deviceexport __mdiobus_readexport __mdiobus_writeexport __mdiobus_modify_changedexport __mdiobus_c45_readexport __mdiobus_c45_writeexport mdiobus_read_nestedexport mdiobus_readexport mdiobus_c45_readexport mdiobus_c45_read_nestedexport mdiobus_write_nestedexport mdiobus_writeexport mdiobus_c45_writeexport mdiobus_c45_write_nestedexport __mdiobus_modifyexport mdiobus_modifyexport mdiobus_c45_modifyexport mdiobus_modify_changedexport mdiobus_c45_modify_changed
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/* MDIO Bus interface
*
* Author: Andy Fleming
*
* Copyright (c) 2004 Freescale Semiconductor, Inc.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/ethtool.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/mii.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/phy.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/unistd.h>
#define CREATE_TRACE_POINTS
#include <trace/events/mdio.h>
static struct mdio_device *mdiobus_find_device(struct mii_bus *bus, int addr)
{
bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map);
if (WARN_ONCE(!addr_valid, "addr %d out of range\n", addr))
return NULL;
return bus->mdio_map[addr];
}
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
{
struct mdio_device *mdiodev;
mdiodev = mdiobus_find_device(bus, addr);
if (!mdiodev)
return NULL;
if (!(mdiodev->flags & MDIO_DEVICE_FLAG_PHY))
return NULL;
return container_of(mdiodev, struct phy_device, mdio);
}
EXPORT_SYMBOL(mdiobus_get_phy);
bool mdiobus_is_registered_device(struct mii_bus *bus, int addr)
{
return mdiobus_find_device(bus, addr) != NULL;
}
EXPORT_SYMBOL(mdiobus_is_registered_device);
static void mdiobus_stats_acct(struct mdio_bus_stats *stats, bool op, int ret)
{
preempt_disable();
u64_stats_update_begin(&stats->syncp);
u64_stats_inc(&stats->transfers);
if (ret < 0) {
u64_stats_inc(&stats->errors);
goto out;
}
if (op)
u64_stats_inc(&stats->reads);
else
u64_stats_inc(&stats->writes);
out:
u64_stats_update_end(&stats->syncp);
preempt_enable();
}
/**
* __mdiobus_read - Unlocked version of the mdiobus_read function
* @bus: the mii_bus struct
* @addr: the phy address
* @regnum: register number to read
*
* Return: The register value if successful, negative error code on failure
*
* Read a MDIO bus register. Caller must hold the mdio bus lock.
*
Annotation
- Immediate include surface: `linux/device.h`, `linux/errno.h`, `linux/ethtool.h`, `linux/init.h`, `linux/io.h`, `linux/kernel.h`, `linux/mii.h`, `linux/mm.h`.
- Detected declarations: `function Copyright`, `function mdiobus_is_registered_device`, `function mdiobus_stats_acct`, `function __mdiobus_read`, `function __mdiobus_write`, `function __mdiobus_modify_changed`, `function __mdiobus_c45_read`, `function __mdiobus_c45_write`, `function __mdiobus_c45_modify_changed`, `function mutex_lock_nested`.
- 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.