drivers/net/dsa/dsa_loop.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/dsa_loop.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/dsa_loop.c- Extension
.c- Size
- 12295 bytes
- Lines
- 517
- 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/platform_device.hlinux/netdevice.hlinux/phy.hlinux/phy_fixed.hlinux/export.hlinux/ethtool.hlinux/workqueue.hlinux/module.hlinux/if_bridge.hlinux/if_vlan.hlinux/types.hnet/dsa.h
Detected Declarations
struct dsa_loop_vlanstruct dsa_loop_mib_entrystruct dsa_loop_portstruct dsa_loop_privstruct dsa_loop_pdataenum dsa_loop_mib_countersenum dsa_loop_devlink_resource_idfunction dsa_loop_devlink_vtu_getfunction dsa_loop_setup_devlink_resourcesfunction dsa_loop_get_protocolfunction dsa_loop_setupfunction dsa_loop_teardownfunction dsa_loop_get_sset_countfunction dsa_loop_get_stringsfunction dsa_loop_get_ethtool_statsfunction dsa_loop_phy_readfunction dsa_loop_phy_writefunction dsa_loop_port_bridge_joinfunction dsa_loop_port_bridge_leavefunction dsa_loop_port_stp_state_setfunction dsa_loop_port_vlan_filteringfunction dsa_loop_port_vlan_addfunction dsa_loop_port_vlan_delfunction dsa_loop_port_change_mtufunction dsa_loop_port_max_mtufunction dsa_loop_phylink_get_capsfunction dsa_loop_drv_probefunction dsa_loop_drv_removefunction dsa_loop_drv_shutdownfunction dsa_loop_bus_matchfunction dsa_loop_phydevs_unregisterfunction dsa_loop_create_switch_mdiodevfunction dsa_loop_initfunction dsa_loop_exitmodule init dsa_loop_init
Annotated Snippet
const struct device_driver *drv)
{
return drv == &dsa_loop_drv.mdiodrv.driver;
}
static void dsa_loop_phydevs_unregister(void)
{
for (int i = 0; i < NUM_FIXED_PHYS; i++) {
if (!IS_ERR(phydevs[i]))
fixed_phy_unregister(phydevs[i]);
}
}
static int __init dsa_loop_create_switch_mdiodev(void)
{
static struct dsa_loop_pdata dsa_loop_pdata = {
.cd = {
.port_names[0] = "lan1",
.port_names[1] = "lan2",
.port_names[2] = "lan3",
.port_names[3] = "lan4",
.port_names[DSA_LOOP_CPU_PORT] = "cpu",
},
.name = "DSA mockup driver",
.enabled_ports = 0x1f,
.netdev = "eth0",
};
struct mii_bus *bus;
int ret = -ENODEV;
bus = mdio_find_bus("fixed-0");
if (WARN_ON(!bus))
return ret;
switch_mdiodev = mdio_device_create(bus, 31);
if (IS_ERR(switch_mdiodev))
goto out;
switch_mdiodev->bus_match = dsa_loop_bus_match;
switch_mdiodev->dev.platform_data = &dsa_loop_pdata;
ret = mdio_device_register(switch_mdiodev);
if (ret)
mdio_device_free(switch_mdiodev);
out:
put_device(&bus->dev);
return ret;
}
static int __init dsa_loop_init(void)
{
unsigned int i;
int ret;
ret = dsa_loop_create_switch_mdiodev();
if (ret)
return ret;
for (i = 0; i < NUM_FIXED_PHYS; i++)
phydevs[i] = fixed_phy_register_100fd();
ret = mdio_driver_register(&dsa_loop_drv);
if (ret) {
dsa_loop_phydevs_unregister();
mdio_device_remove(switch_mdiodev);
mdio_device_free(switch_mdiodev);
}
return ret;
}
module_init(dsa_loop_init);
static void __exit dsa_loop_exit(void)
{
mdio_driver_unregister(&dsa_loop_drv);
dsa_loop_phydevs_unregister();
mdio_device_remove(switch_mdiodev);
mdio_device_free(switch_mdiodev);
}
module_exit(dsa_loop_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Florian Fainelli");
MODULE_DESCRIPTION("DSA loopback driver");
Annotation
- Immediate include surface: `linux/platform_device.h`, `linux/netdevice.h`, `linux/phy.h`, `linux/phy_fixed.h`, `linux/export.h`, `linux/ethtool.h`, `linux/workqueue.h`, `linux/module.h`.
- Detected declarations: `struct dsa_loop_vlan`, `struct dsa_loop_mib_entry`, `struct dsa_loop_port`, `struct dsa_loop_priv`, `struct dsa_loop_pdata`, `enum dsa_loop_mib_counters`, `enum dsa_loop_devlink_resource_id`, `function dsa_loop_devlink_vtu_get`, `function dsa_loop_setup_devlink_resources`, `function dsa_loop_get_protocol`.
- 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.