drivers/net/phy/bcm-phy-lib.c
Source file repositories/reference/linux-study-clean/drivers/net/phy/bcm-phy-lib.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/phy/bcm-phy-lib.c- Extension
.c- Size
- 29963 bytes
- Lines
- 1195
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
bcm-phy-lib.hlinux/bitfield.hlinux/brcmphy.hlinux/etherdevice.hlinux/export.hlinux/mdio.hlinux/module.hlinux/phy.hlinux/ethtool.hlinux/ethtool_netlink.hlinux/netdevice.h
Detected Declarations
struct bcm_phy_hw_statfunction Copyrightfunction bcm_phy_write_expfunction __bcm_phy_read_expfunction bcm_phy_read_expfunction __bcm_phy_modify_expfunction bcm_phy_modify_expfunction bcm54xx_auxctl_readfunction bcm54xx_auxctl_writefunction bcm_phy_write_miscfunction bcm_phy_read_miscfunction bcm_phy_ack_intrfunction bcm_phy_config_intrfunction bcm_phy_handle_interruptfunction bcm_phy_read_shadowfunction bcm_phy_write_shadowfunction __bcm_phy_read_rdbfunction bcm_phy_read_rdbfunction __bcm_phy_write_rdbfunction bcm_phy_write_rdbfunction __bcm_phy_modify_rdbfunction bcm_phy_modify_rdbfunction bcm_phy_enable_apdfunction bcm_phy_set_eeefunction bcm_phy_downshift_getfunction bcm_phy_downshift_setfunction bcm_phy_get_sset_countfunction bcm_phy_get_stringsfunction bcm_phy_get_statfunction bcm_phy_get_statsfunction bcm_phy_update_stats_shadowfunction bcm_phy_r_rc_cal_resetfunction bcm_phy_28nm_a0b0_afe_config_initfunction bcm_phy_enable_jumbofunction __bcm_phy_enable_rdb_accessfunction __bcm_phy_enable_legacy_accessfunction _bcm_phy_cable_test_startfunction bcm_phy_cable_test_report_transfunction bcm_phy_distance_validfunction bcm_phy_report_lengthfunction _bcm_phy_cable_test_get_statusfunction bcm_setup_lre_forcedfunction bcm_linkmode_adv_to_lre_adv_tfunction bcm_phy_cable_test_startfunction bcm_phy_cable_test_get_statusfunction bcm_phy_cable_test_start_rdbfunction bcm_phy_cable_test_get_status_rdbfunction bcm_phy_set_wol
Annotated Snippet
struct bcm_phy_hw_stat {
const char *string;
int devad;
u16 reg;
u8 shift;
u8 bits;
};
/* Counters freeze at either 0xffff or 0xff, better than nothing */
static const struct bcm_phy_hw_stat bcm_phy_hw_stats[] = {
{ "phy_receive_errors", -1, MII_BRCM_CORE_BASE12, 0, 16 },
{ "phy_serdes_ber_errors", -1, MII_BRCM_CORE_BASE13, 8, 8 },
{ "phy_false_carrier_sense_errors", -1, MII_BRCM_CORE_BASE13, 0, 8 },
{ "phy_local_rcvr_nok", -1, MII_BRCM_CORE_BASE14, 8, 8 },
{ "phy_remote_rcv_nok", -1, MII_BRCM_CORE_BASE14, 0, 8 },
{ "phy_lpi_count", MDIO_MMD_AN, BRCM_CL45VEN_EEE_LPI_CNT, 0, 16 },
};
int bcm_phy_get_sset_count(struct phy_device *phydev)
{
return ARRAY_SIZE(bcm_phy_hw_stats);
}
EXPORT_SYMBOL_GPL(bcm_phy_get_sset_count);
void bcm_phy_get_strings(struct phy_device *phydev, u8 *data)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(bcm_phy_hw_stats); i++)
ethtool_puts(&data, bcm_phy_hw_stats[i].string);
}
EXPORT_SYMBOL_GPL(bcm_phy_get_strings);
/* Caller is supposed to provide appropriate storage for the library code to
* access the shadow copy
*/
static u64 bcm_phy_get_stat(struct phy_device *phydev, u64 *shadow,
unsigned int i)
{
struct bcm_phy_hw_stat stat = bcm_phy_hw_stats[i];
int val;
u64 ret;
if (stat.devad < 0)
val = phy_read(phydev, stat.reg);
else
val = phy_read_mmd(phydev, stat.devad, stat.reg);
if (val < 0) {
ret = U64_MAX;
} else {
val >>= stat.shift;
val = val & ((1 << stat.bits) - 1);
shadow[i] += val;
ret = shadow[i];
}
return ret;
}
void bcm_phy_get_stats(struct phy_device *phydev, u64 *shadow,
struct ethtool_stats *stats, u64 *data)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(bcm_phy_hw_stats); i++)
data[i] = bcm_phy_get_stat(phydev, shadow, i);
}
EXPORT_SYMBOL_GPL(bcm_phy_get_stats);
void bcm_phy_update_stats_shadow(struct phy_device *phydev, u64 *shadow)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(bcm_phy_hw_stats); i++)
bcm_phy_get_stat(phydev, shadow, i);
}
EXPORT_SYMBOL_GPL(bcm_phy_update_stats_shadow);
void bcm_phy_r_rc_cal_reset(struct phy_device *phydev)
{
/* Reset R_CAL/RC_CAL Engine */
bcm_phy_write_exp_sel(phydev, 0x00b0, 0x0010);
/* Disable Reset R_AL/RC_CAL Engine */
bcm_phy_write_exp_sel(phydev, 0x00b0, 0x0000);
}
EXPORT_SYMBOL_GPL(bcm_phy_r_rc_cal_reset);
int bcm_phy_28nm_a0b0_afe_config_init(struct phy_device *phydev)
{
Annotation
- Immediate include surface: `bcm-phy-lib.h`, `linux/bitfield.h`, `linux/brcmphy.h`, `linux/etherdevice.h`, `linux/export.h`, `linux/mdio.h`, `linux/module.h`, `linux/phy.h`.
- Detected declarations: `struct bcm_phy_hw_stat`, `function Copyright`, `function bcm_phy_write_exp`, `function __bcm_phy_read_exp`, `function bcm_phy_read_exp`, `function __bcm_phy_modify_exp`, `function bcm_phy_modify_exp`, `function bcm54xx_auxctl_read`, `function bcm54xx_auxctl_write`, `function bcm_phy_write_misc`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.