drivers/net/ethernet/hisilicon/hns_mdio.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/hisilicon/hns_mdio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/hisilicon/hns_mdio.c- Extension
.c- Size
- 15942 bytes
- Lines
- 653
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/acpi.hlinux/errno.hlinux/etherdevice.hlinux/init.hlinux/kernel.hlinux/mfd/syscon.hlinux/module.hlinux/mutex.hlinux/netdevice.hlinux/of_address.hlinux/of.hlinux/of_mdio.hlinux/of_platform.hlinux/phy.hlinux/platform_device.hlinux/regmap.h
Detected Declarations
struct hns_mdio_sc_regstruct hns_mdio_deviceenum mdio_st_clauseenum mdio_c22_op_seqenum mdio_c45_op_seqfunction mdio_write_regfunction mdio_read_regfunction mdio_set_reg_fieldfunction mdio_get_reg_fieldfunction mdio_get_reg_fieldfunction hns_mdio_wait_readyfunction hns_mdio_cmd_writefunction hns_mdio_write_c22function hns_mdio_write_c45function hns_mdio_read_c22function hns_mdio_read_c45function hns_mdio_resetfunction hns_mdio_probefunction hns_mdio_remove
Annotated Snippet
struct hns_mdio_sc_reg {
u16 mdio_clk_en;
u16 mdio_clk_dis;
u16 mdio_reset_req;
u16 mdio_reset_dreq;
u16 mdio_clk_st;
u16 mdio_reset_st;
};
struct hns_mdio_device {
u8 __iomem *vbase; /* mdio reg base address */
struct regmap *subctrl_vbase;
struct hns_mdio_sc_reg sc_reg;
};
/* mdio reg */
#define MDIO_COMMAND_REG 0x0
#define MDIO_ADDR_REG 0x4
#define MDIO_WDATA_REG 0x8
#define MDIO_RDATA_REG 0xc
#define MDIO_STA_REG 0x10
/* cfg phy bit map */
#define MDIO_CMD_DEVAD_M 0x1f
#define MDIO_CMD_DEVAD_S 0
#define MDIO_CMD_PRTAD_M 0x1f
#define MDIO_CMD_PRTAD_S 5
#define MDIO_CMD_OP_S 10
#define MDIO_CMD_ST_S 12
#define MDIO_CMD_START_B 14
#define MDIO_ADDR_DATA_M 0xffff
#define MDIO_ADDR_DATA_S 0
#define MDIO_WDATA_DATA_M 0xffff
#define MDIO_WDATA_DATA_S 0
#define MDIO_RDATA_DATA_M 0xffff
#define MDIO_RDATA_DATA_S 0
#define MDIO_STATE_STA_B 0
enum mdio_st_clause {
MDIO_ST_CLAUSE_45 = 0,
MDIO_ST_CLAUSE_22
};
enum mdio_c22_op_seq {
MDIO_C22_WRITE = 1,
MDIO_C22_READ = 2
};
enum mdio_c45_op_seq {
MDIO_C45_WRITE_ADDR = 0,
MDIO_C45_WRITE_DATA,
MDIO_C45_READ_INCREMENT,
MDIO_C45_READ
};
/* peri subctrl reg */
#define MDIO_SC_CLK_EN 0x338
#define MDIO_SC_CLK_DIS 0x33C
#define MDIO_SC_RESET_REQ 0xA38
#define MDIO_SC_RESET_DREQ 0xA3C
#define MDIO_SC_CLK_ST 0x531C
#define MDIO_SC_RESET_ST 0x5A1C
static void mdio_write_reg(u8 __iomem *base, u32 reg, u32 value)
{
writel_relaxed(value, base + reg);
}
#define MDIO_WRITE_REG(a, reg, value) \
mdio_write_reg((a)->vbase, (reg), (value))
static u32 mdio_read_reg(u8 __iomem *base, u32 reg)
{
return readl_relaxed(base + reg);
}
#define mdio_set_field(origin, mask, shift, val) \
do { \
(origin) &= (~((mask) << (shift))); \
(origin) |= (((val) & (mask)) << (shift)); \
} while (0)
#define mdio_get_field(origin, mask, shift) (((origin) >> (shift)) & (mask))
static void mdio_set_reg_field(u8 __iomem *base, u32 reg, u32 mask, u32 shift,
u32 val)
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/errno.h`, `linux/etherdevice.h`, `linux/init.h`, `linux/kernel.h`, `linux/mfd/syscon.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct hns_mdio_sc_reg`, `struct hns_mdio_device`, `enum mdio_st_clause`, `enum mdio_c22_op_seq`, `enum mdio_c45_op_seq`, `function mdio_write_reg`, `function mdio_read_reg`, `function mdio_set_reg_field`, `function mdio_get_reg_field`, `function mdio_get_reg_field`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source 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.