drivers/net/phy/swphy.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/swphy.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/swphy.c- Extension
.c- Size
- 3792 bytes
- Lines
- 176
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/mii.hlinux/phy.hlinux/phy_fixed.hswphy.h
Detected Declarations
struct swmii_regsfunction swphy_decode_speedfunction swphy_validate_statefunction swphy_read_regexport swphy_validate_stateexport swphy_read_reg
Annotated Snippet
struct swmii_regs {
u16 bmsr;
u16 lpa;
u16 lpagb;
u16 estat;
};
enum {
SWMII_SPEED_10 = 0,
SWMII_SPEED_100,
SWMII_SPEED_1000,
SWMII_DUPLEX_HALF = 0,
SWMII_DUPLEX_FULL,
};
/*
* These two tables get bitwise-anded together to produce the final result.
* This means the speed table must contain both duplex settings, and the
* duplex table must contain all speed settings.
*/
static const struct swmii_regs speed[] = {
[SWMII_SPEED_10] = {
.lpa = LPA_10FULL | LPA_10HALF,
},
[SWMII_SPEED_100] = {
.bmsr = BMSR_100FULL | BMSR_100HALF,
.lpa = LPA_100FULL | LPA_100HALF,
},
[SWMII_SPEED_1000] = {
.bmsr = BMSR_ESTATEN,
.lpagb = LPA_1000FULL | LPA_1000HALF,
.estat = ESTATUS_1000_TFULL | ESTATUS_1000_THALF,
},
};
static const struct swmii_regs duplex[] = {
[SWMII_DUPLEX_HALF] = {
.bmsr = BMSR_ESTATEN | BMSR_100HALF,
.lpa = LPA_10HALF | LPA_100HALF,
.lpagb = LPA_1000HALF,
.estat = ESTATUS_1000_THALF,
},
[SWMII_DUPLEX_FULL] = {
.bmsr = BMSR_ESTATEN | BMSR_100FULL,
.lpa = LPA_10FULL | LPA_100FULL,
.lpagb = LPA_1000FULL,
.estat = ESTATUS_1000_TFULL,
},
};
static int swphy_decode_speed(int speed)
{
switch (speed) {
case 1000:
return SWMII_SPEED_1000;
case 100:
return SWMII_SPEED_100;
case 10:
return SWMII_SPEED_10;
default:
return -EINVAL;
}
}
/**
* swphy_validate_state - validate the software phy status
* @state: software phy status
*
* This checks that we can represent the state stored in @state can be
* represented in the emulated MII registers. Returns 0 if it can,
* otherwise returns -EINVAL.
*/
int swphy_validate_state(const struct fixed_phy_status *state)
{
int err;
if (state->link) {
err = swphy_decode_speed(state->speed);
if (err < 0) {
pr_warn("swphy: unknown speed\n");
return -EINVAL;
}
}
return 0;
}
EXPORT_SYMBOL_GPL(swphy_validate_state);
/**
* swphy_read_reg - return a MII register from the fixed phy state
* @reg: MII register
Annotation
- Immediate include surface: `linux/export.h`, `linux/mii.h`, `linux/phy.h`, `linux/phy_fixed.h`, `swphy.h`.
- Detected declarations: `struct swmii_regs`, `function swphy_decode_speed`, `function swphy_validate_state`, `function swphy_read_reg`, `export swphy_validate_state`, `export swphy_read_reg`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration 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.